blob: 04455738507024449f2a277b29bf63b0e5558452 [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"
Tony Barbour300a6082015-04-07 13:44:53 -060038
Mark Lobodzinski3780e142015-05-14 15:08:13 -050039#define GLM_FORCE_RADIANS
40#include "glm/glm.hpp"
41#include <glm/gtc/matrix_transform.hpp>
42
Dustin Gravesffa90fa2016-05-06 11:20:38 -060043#define PARAMETER_VALIDATION_TESTS 1
Tobin Ehlis0788f522015-05-26 16:11:58 -060044#define MEM_TRACKER_TESTS 1
45#define OBJ_TRACKER_TESTS 1
46#define DRAW_STATE_TESTS 1
47#define THREADING_TESTS 1
Chris Forbes9f7ff632015-05-25 11:13:08 +120048#define SHADER_CHECKER_TESTS 1
Mark Lobodzinski209b5292015-09-17 09:44:05 -060049#define DEVICE_LIMITS_TESTS 1
Tobin Ehliscde08892015-09-22 10:11:37 -060050#define IMAGE_TESTS 1
Tobin Ehlis0788f522015-05-26 16:11:58 -060051
Mark Lobodzinski3780e142015-05-14 15:08:13 -050052//--------------------------------------------------------------------------------------
53// Mesh and VertexFormat Data
54//--------------------------------------------------------------------------------------
Karl Schultz6addd812016-02-02 17:17:23 -070055struct Vertex {
56 float posX, posY, posZ, posW; // Position data
57 float r, g, b, a; // Color
Mark Lobodzinski3780e142015-05-14 15:08:13 -050058};
59
Karl Schultz6addd812016-02-02 17:17:23 -070060#define XYZ1(_x_, _y_, _z_) (_x_), (_y_), (_z_), 1.f
Mark Lobodzinski3780e142015-05-14 15:08:13 -050061
62typedef enum _BsoFailSelect {
Karl Schultz6addd812016-02-02 17:17:23 -070063 BsoFailNone = 0x00000000,
64 BsoFailLineWidth = 0x00000001,
65 BsoFailDepthBias = 0x00000002,
66 BsoFailViewport = 0x00000004,
67 BsoFailScissor = 0x00000008,
68 BsoFailBlend = 0x00000010,
69 BsoFailDepthBounds = 0x00000020,
70 BsoFailStencilReadMask = 0x00000040,
71 BsoFailStencilWriteMask = 0x00000080,
72 BsoFailStencilReference = 0x00000100,
Mark Muellerd4914412016-06-13 17:52:06 -060073 BsoFailCmdClearAttachments = 0x00000200,
Tobin Ehlis379ba3b2016-07-19 11:22:29 -060074 BsoFailIndexBuffer = 0x00000400,
Mark Lobodzinski3780e142015-05-14 15:08:13 -050075} BsoFailSelect;
76
77struct vktriangle_vs_uniform {
78 // Must start with MVP
Karl Schultz6addd812016-02-02 17:17:23 -070079 float mvp[4][4];
80 float position[3][4];
81 float color[3][4];
Mark Lobodzinski3780e142015-05-14 15:08:13 -050082};
83
Mark Lobodzinskice751c62016-09-08 10:45:35 -060084static const char bindStateVertShaderText[] = "#version 450\n"
85 "vec2 vertices[3];\n"
86 "out gl_PerVertex {\n"
87 " vec4 gl_Position;\n"
88 "};\n"
89 "void main() {\n"
90 " vertices[0] = vec2(-1.0, -1.0);\n"
91 " vertices[1] = vec2( 1.0, -1.0);\n"
92 " vertices[2] = vec2( 0.0, 1.0);\n"
93 " gl_Position = vec4(vertices[gl_VertexIndex % 3], 0.0, 1.0);\n"
94 "}\n";
Mark Lobodzinski3780e142015-05-14 15:08:13 -050095
Mark Lobodzinskice751c62016-09-08 10:45:35 -060096static const char bindStateFragShaderText[] = "#version 450\n"
97 "\n"
98 "layout(location = 0) out vec4 uFragColor;\n"
99 "void main(){\n"
100 " uFragColor = vec4(0,1,0,1);\n"
101 "}\n";
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500102
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600103static VKAPI_ATTR VkBool32 VKAPI_CALL myDbgFunc(VkFlags msgFlags, VkDebugReportObjectTypeEXT objType, uint64_t srcObject,
104 size_t location, int32_t msgCode, const char *pLayerPrefix, const char *pMsg,
105 void *pUserData);
Mark Lobodzinski7a588452016-08-03 14:04:26 -0600106
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600107// ********************************************************
108// ErrorMonitor Usage:
109//
110// Call SetDesiredFailureMsg with a string to be compared against all
111// encountered log messages. Passing NULL will match all log messages.
112// logMsg will return true for skipCall only if msg is matched or NULL.
113//
114// Call DesiredMsgFound to determine if the desired failure message
115// was encountered.
116
Tony Barbour300a6082015-04-07 13:44:53 -0600117class ErrorMonitor {
Karl Schultz6addd812016-02-02 17:17:23 -0700118 public:
119 ErrorMonitor() {
Mike Stroyan4268d1f2015-07-13 14:45:35 -0600120 test_platform_thread_create_mutex(&m_mutex);
121 test_platform_thread_lock_mutex(&m_mutex);
Chris Forbes17756132016-09-16 14:36:39 +1200122 m_msgFlags = VK_DEBUG_REPORT_ERROR_BIT_EXT;
Karl Schultz6addd812016-02-02 17:17:23 -0700123 m_bailout = NULL;
Chris Forbes17756132016-09-16 14:36:39 +1200124 m_desiredMsgSet = false;
Mike Stroyan4268d1f2015-07-13 14:45:35 -0600125 test_platform_thread_unlock_mutex(&m_mutex);
Tony Barbour300a6082015-04-07 13:44:53 -0600126 }
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600127
Dustin Graves48458142016-04-29 16:11:55 -0600128 ~ErrorMonitor() { test_platform_thread_delete_mutex(&m_mutex); }
129
Karl Schultz6addd812016-02-02 17:17:23 -0700130 void SetDesiredFailureMsg(VkFlags msgFlags, const char *msgString) {
Chris Forbes8f36a8a2016-04-07 13:21:07 +1200131 // also discard all collected messages to this point
Mike Stroyan4268d1f2015-07-13 14:45:35 -0600132 test_platform_thread_lock_mutex(&m_mutex);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600133 m_failureMsg.clear();
134 m_otherMsgs.clear();
135 m_desiredMsg = msgString;
Karl Schultz6addd812016-02-02 17:17:23 -0700136 m_msgFound = VK_FALSE;
137 m_msgFlags = msgFlags;
Chris Forbes17756132016-09-16 14:36:39 +1200138 m_desiredMsgSet = true;
Mike Stroyan4268d1f2015-07-13 14:45:35 -0600139 test_platform_thread_unlock_mutex(&m_mutex);
Tony Barbour300a6082015-04-07 13:44:53 -0600140 }
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600141
Mark Lobodzinski7a588452016-08-03 14:04:26 -0600142 VkBool32 CheckForDesiredMsg(const char *msgString) {
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600143 VkBool32 result = VK_FALSE;
Mike Stroyan4268d1f2015-07-13 14:45:35 -0600144 test_platform_thread_lock_mutex(&m_mutex);
Mike Stroyanaccf7692015-05-12 16:00:45 -0600145 if (m_bailout != NULL) {
146 *m_bailout = true;
147 }
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600148 string errorString(msgString);
Chris Forbes17756132016-09-16 14:36:39 +1200149 if (m_desiredMsgSet && errorString.find(m_desiredMsg) != string::npos) {
Mark Lobodzinski7a588452016-08-03 14:04:26 -0600150 if (m_msgFound) { // If multiple matches, don't lose all but the last!
151 m_otherMsgs.push_back(m_failureMsg);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600152 }
Mark Lobodzinski7a588452016-08-03 14:04:26 -0600153 m_failureMsg = errorString;
154 m_msgFound = VK_TRUE;
155 result = VK_TRUE;
156 } else {
Chris Forbes5b9442b2016-09-13 16:49:57 +1200157 printf("Unexpected: %s\n", msgString);
Mark Lobodzinski7a588452016-08-03 14:04:26 -0600158 m_otherMsgs.push_back(errorString);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600159 }
Mike Stroyan4268d1f2015-07-13 14:45:35 -0600160 test_platform_thread_unlock_mutex(&m_mutex);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600161 return result;
Mike Stroyanaccf7692015-05-12 16:00:45 -0600162 }
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600163
Karl Schultz6addd812016-02-02 17:17:23 -0700164 vector<string> GetOtherFailureMsgs(void) { return m_otherMsgs; }
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600165
Karl Schultz6addd812016-02-02 17:17:23 -0700166 string GetFailureMsg(void) { return m_failureMsg; }
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600167
Mark Lobodzinski7a588452016-08-03 14:04:26 -0600168 VkDebugReportFlagsEXT GetMessageFlags(void) { return m_msgFlags; }
169
Karl Schultz6addd812016-02-02 17:17:23 -0700170 VkBool32 DesiredMsgFound(void) { return m_msgFound; }
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600171
Karl Schultz6addd812016-02-02 17:17:23 -0700172 void SetBailout(bool *bailout) { m_bailout = bailout; }
Tony Barbour300a6082015-04-07 13:44:53 -0600173
Karl Schultz6addd812016-02-02 17:17:23 -0700174 void DumpFailureMsgs(void) {
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600175 vector<string> otherMsgs = GetOtherFailureMsgs();
176 cout << "Other error messages logged for this test were:" << endl;
177 for (auto iter = otherMsgs.begin(); iter != otherMsgs.end(); iter++) {
178 cout << " " << *iter << endl;
179 }
180 }
181
Mark Lobodzinski7a588452016-08-03 14:04:26 -0600182 // Helpers
Chris Forbes8f36a8a2016-04-07 13:21:07 +1200183
Mark Lobodzinski7a588452016-08-03 14:04:26 -0600184 // ExpectSuccess now takes an optional argument allowing a custom combination of debug flags
185 void ExpectSuccess(VkDebugReportFlagsEXT message_flag_mask = VK_DEBUG_REPORT_ERROR_BIT_EXT) {
186 m_msgFlags = message_flag_mask;
187 // Match ANY message matching specified type
188 SetDesiredFailureMsg(message_flag_mask, "");
Chris Forbes8f36a8a2016-04-07 13:21:07 +1200189 }
190
191 void VerifyFound() {
192 // Not seeing the desired message is a failure. /Before/ throwing, dump
193 // any other messages.
194 if (!DesiredMsgFound()) {
195 DumpFailureMsgs();
196 FAIL() << "Did not receive expected error '" << m_desiredMsg << "'";
197 }
198 }
199
200 void VerifyNotFound() {
201 // ExpectSuccess() configured us to match anything. Any error is a
202 // failure.
203 if (DesiredMsgFound()) {
204 DumpFailureMsgs();
205 FAIL() << "Expected to succeed but got error: " << GetFailureMsg();
206 }
207 }
208
Karl Schultz6addd812016-02-02 17:17:23 -0700209 private:
210 VkFlags m_msgFlags;
211 string m_desiredMsg;
212 string m_failureMsg;
213 vector<string> m_otherMsgs;
Mike Stroyan4268d1f2015-07-13 14:45:35 -0600214 test_platform_thread_mutex m_mutex;
Karl Schultz6addd812016-02-02 17:17:23 -0700215 bool *m_bailout;
216 VkBool32 m_msgFound;
Chris Forbes17756132016-09-16 14:36:39 +1200217 bool m_desiredMsgSet;
Tony Barbour300a6082015-04-07 13:44:53 -0600218};
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500219
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600220static VKAPI_ATTR VkBool32 VKAPI_CALL myDbgFunc(VkFlags msgFlags, VkDebugReportObjectTypeEXT objType, uint64_t srcObject,
221 size_t location, int32_t msgCode, const char *pLayerPrefix, const char *pMsg,
222 void *pUserData) {
Mark Lobodzinski7a588452016-08-03 14:04:26 -0600223 ErrorMonitor *errMonitor = (ErrorMonitor *)pUserData;
224 if (msgFlags & errMonitor->GetMessageFlags()) {
225 return errMonitor->CheckForDesiredMsg(pMsg);
Tony Barbour0b4d9562015-04-09 10:48:04 -0600226 }
Courtney Goeltzenleuchter06640832015-09-04 13:52:24 -0600227 return false;
Tony Barbour300a6082015-04-07 13:44:53 -0600228}
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500229
Karl Schultz6addd812016-02-02 17:17:23 -0700230class VkLayerTest : public VkRenderFramework {
231 public:
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800232 VkResult BeginCommandBuffer(VkCommandBufferObj &commandBuffer);
233 VkResult EndCommandBuffer(VkCommandBufferObj &commandBuffer);
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600234 void VKTriangleTest(const char *vertShaderText, const char *fragShaderText, BsoFailSelect failMask);
235 void GenericDrawPreparation(VkCommandBufferObj *commandBuffer, VkPipelineObj &pipelineobj, VkDescriptorSetObj &descriptorSet,
Karl Schultz6addd812016-02-02 17:17:23 -0700236 BsoFailSelect failMask);
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600237 void GenericDrawPreparation(VkPipelineObj &pipelineobj, VkDescriptorSetObj &descriptorSet, BsoFailSelect failMask) {
238 GenericDrawPreparation(m_commandBuffer, pipelineobj, descriptorSet, failMask);
Karl Schultz6addd812016-02-02 17:17:23 -0700239 }
Tony Barbour300a6082015-04-07 13:44:53 -0600240
Tony Barbourfe3351b2015-07-28 10:17:20 -0600241 /* Convenience functions that use built-in command buffer */
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600242 VkResult BeginCommandBuffer() { return BeginCommandBuffer(*m_commandBuffer); }
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800243 VkResult EndCommandBuffer() { return EndCommandBuffer(*m_commandBuffer); }
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600244 void Draw(uint32_t vertexCount, uint32_t instanceCount, uint32_t firstVertex, uint32_t firstInstance) {
245 m_commandBuffer->Draw(vertexCount, instanceCount, firstVertex, firstInstance);
Karl Schultz6addd812016-02-02 17:17:23 -0700246 }
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600247 void DrawIndexed(uint32_t indexCount, uint32_t instanceCount, uint32_t firstIndex, int32_t vertexOffset,
Karl Schultz6addd812016-02-02 17:17:23 -0700248 uint32_t firstInstance) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600249 m_commandBuffer->DrawIndexed(indexCount, instanceCount, firstIndex, vertexOffset, firstInstance);
Karl Schultz6addd812016-02-02 17:17:23 -0700250 }
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600251 void QueueCommandBuffer(bool checkSuccess = true) { m_commandBuffer->QueueCommandBuffer(checkSuccess); }
252 void QueueCommandBuffer(const VkFence &fence) { m_commandBuffer->QueueCommandBuffer(fence); }
253 void BindVertexBuffer(VkConstantBufferObj *vertexBuffer, VkDeviceSize offset, uint32_t binding) {
Karl Schultz6addd812016-02-02 17:17:23 -0700254 m_commandBuffer->BindVertexBuffer(vertexBuffer, offset, binding);
255 }
256 void BindIndexBuffer(VkIndexBufferObj *indexBuffer, VkDeviceSize offset) {
257 m_commandBuffer->BindIndexBuffer(indexBuffer, offset);
258 }
259
260 protected:
261 ErrorMonitor *m_errorMonitor;
Ian Elliott2c1daf52016-05-12 09:41:46 -0600262 bool m_enableWSI;
Tony Barbour300a6082015-04-07 13:44:53 -0600263
264 virtual void SetUp() {
Courtney Goeltzenleuchtercd69eee2015-07-06 09:10:47 -0600265 std::vector<const char *> instance_layer_names;
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -0600266 std::vector<const char *> instance_extension_names;
267 std::vector<const char *> device_extension_names;
Tony Barbour3fdff9e2015-04-23 12:55:36 -0600268
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -0700269 instance_extension_names.push_back(VK_EXT_DEBUG_REPORT_EXTENSION_NAME);
Courtney Goeltzenleuchterc2b06fe2015-06-16 15:59:11 -0600270 /*
271 * Since CreateDbgMsgCallback is an instance level extension call
272 * any extension / layer that utilizes that feature also needs
273 * to be enabled at create instance time.
274 */
Karl Schultz6addd812016-02-02 17:17:23 -0700275 // Use Threading layer first to protect others from
276 // ThreadCommandBufferCollision test
Courtney Goeltzenleuchter76885322016-02-06 17:11:22 -0700277 instance_layer_names.push_back("VK_LAYER_GOOGLE_threading");
Tobin Ehlis24aab042016-03-24 10:54:18 -0600278 instance_layer_names.push_back("VK_LAYER_LUNARG_parameter_validation");
Michael Lentine03107b42015-12-11 10:49:51 -0800279 instance_layer_names.push_back("VK_LAYER_LUNARG_object_tracker");
Tobin Ehlisc96f8062016-03-09 16:12:48 -0700280 instance_layer_names.push_back("VK_LAYER_LUNARG_core_validation");
Michael Lentine03107b42015-12-11 10:49:51 -0800281 instance_layer_names.push_back("VK_LAYER_LUNARG_image");
Ian Elliotte48a1382016-04-28 14:22:58 -0600282 instance_layer_names.push_back("VK_LAYER_LUNARG_swapchain");
Dustin Graveseaa78cd2016-01-26 16:30:22 -0700283 instance_layer_names.push_back("VK_LAYER_GOOGLE_unique_objects");
Courtney Goeltzenleuchterd971b612015-06-17 20:51:59 -0600284
Ian Elliott2c1daf52016-05-12 09:41:46 -0600285 if (m_enableWSI) {
286 instance_extension_names.push_back(VK_KHR_SURFACE_EXTENSION_NAME);
287 device_extension_names.push_back(VK_KHR_SWAPCHAIN_EXTENSION_NAME);
288#ifdef NEED_TO_TEST_THIS_ON_PLATFORM
289#if defined(VK_USE_PLATFORM_ANDROID_KHR)
290 instance_extension_names.push_back(VK_KHR_ANDROID_SURFACE_EXTENSION_NAME);
291#endif // VK_USE_PLATFORM_ANDROID_KHR
292#if defined(VK_USE_PLATFORM_MIR_KHR)
293 instance_extension_names.push_back(VK_KHR_MIR_SURFACE_EXTENSION_NAME);
294#endif // VK_USE_PLATFORM_MIR_KHR
295#if defined(VK_USE_PLATFORM_WAYLAND_KHR)
296 instance_extension_names.push_back(VK_KHR_WAYLAND_SURFACE_EXTENSION_NAME);
297#endif // VK_USE_PLATFORM_WAYLAND_KHR
298#if defined(VK_USE_PLATFORM_WIN32_KHR)
299 instance_extension_names.push_back(VK_KHR_WIN32_SURFACE_EXTENSION_NAME);
300#endif // VK_USE_PLATFORM_WIN32_KHR
301#endif // NEED_TO_TEST_THIS_ON_PLATFORM
302#if defined(VK_USE_PLATFORM_XCB_KHR)
303 instance_extension_names.push_back(VK_KHR_XCB_SURFACE_EXTENSION_NAME);
304#elif defined(VK_USE_PLATFORM_XLIB_KHR)
305 instance_extension_names.push_back(VK_KHR_XLIB_SURFACE_EXTENSION_NAME);
306#endif // VK_USE_PLATFORM_XLIB_KHR
307 }
308
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600309 this->app_info.sType = VK_STRUCTURE_TYPE_APPLICATION_INFO;
Tony Barbour300a6082015-04-07 13:44:53 -0600310 this->app_info.pNext = NULL;
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800311 this->app_info.pApplicationName = "layer_tests";
312 this->app_info.applicationVersion = 1;
Tony Barbour300a6082015-04-07 13:44:53 -0600313 this->app_info.pEngineName = "unittest";
314 this->app_info.engineVersion = 1;
Jon Ashburnc5012ff2016-03-22 13:57:46 -0600315 this->app_info.apiVersion = VK_API_VERSION_1_0;
Tony Barbour300a6082015-04-07 13:44:53 -0600316
Tony Barbour15524c32015-04-29 17:34:29 -0600317 m_errorMonitor = new ErrorMonitor;
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600318 InitFramework(instance_layer_names, instance_extension_names, device_extension_names, myDbgFunc, m_errorMonitor);
Tony Barbour300a6082015-04-07 13:44:53 -0600319 }
320
321 virtual void TearDown() {
322 // Clean up resources before we reset
Tony Barbour300a6082015-04-07 13:44:53 -0600323 ShutdownFramework();
Tony Barbour0b4d9562015-04-09 10:48:04 -0600324 delete m_errorMonitor;
Tony Barbour300a6082015-04-07 13:44:53 -0600325 }
Ian Elliott2c1daf52016-05-12 09:41:46 -0600326
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600327 VkLayerTest() { m_enableWSI = false; }
Tony Barbour300a6082015-04-07 13:44:53 -0600328};
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500329
Karl Schultz6addd812016-02-02 17:17:23 -0700330VkResult VkLayerTest::BeginCommandBuffer(VkCommandBufferObj &commandBuffer) {
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600331 VkResult result;
Tony Barbour300a6082015-04-07 13:44:53 -0600332
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800333 result = commandBuffer.BeginCommandBuffer();
Tony Barbour300a6082015-04-07 13:44:53 -0600334
335 /*
336 * For render test all drawing happens in a single render pass
337 * on a single command buffer.
338 */
Chris Forbes76a5eeb2015-06-16 14:05:59 +1200339 if (VK_SUCCESS == result && renderPass()) {
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800340 commandBuffer.BeginRenderPass(renderPassBeginInfo());
Tony Barbour300a6082015-04-07 13:44:53 -0600341 }
342
343 return result;
344}
345
Karl Schultz6addd812016-02-02 17:17:23 -0700346VkResult VkLayerTest::EndCommandBuffer(VkCommandBufferObj &commandBuffer) {
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600347 VkResult result;
Tony Barbour300a6082015-04-07 13:44:53 -0600348
Chris Forbes76a5eeb2015-06-16 14:05:59 +1200349 if (renderPass()) {
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800350 commandBuffer.EndRenderPass();
Chris Forbes76a5eeb2015-06-16 14:05:59 +1200351 }
Tony Barbour300a6082015-04-07 13:44:53 -0600352
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800353 result = commandBuffer.EndCommandBuffer();
Tony Barbour300a6082015-04-07 13:44:53 -0600354
355 return result;
356}
357
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600358void VkLayerTest::VKTriangleTest(const char *vertShaderText, const char *fragShaderText, BsoFailSelect failMask) {
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500359 // Create identity matrix
360 int i;
361 struct vktriangle_vs_uniform data;
362
363 glm::mat4 Projection = glm::mat4(1.0f);
Karl Schultz6addd812016-02-02 17:17:23 -0700364 glm::mat4 View = glm::mat4(1.0f);
365 glm::mat4 Model = glm::mat4(1.0f);
366 glm::mat4 MVP = Projection * View * Model;
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500367 const int matrixSize = sizeof(MVP);
Karl Schultz6addd812016-02-02 17:17:23 -0700368 const int bufSize = sizeof(vktriangle_vs_uniform) / sizeof(float);
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500369
370 memcpy(&data.mvp, &MVP[0][0], matrixSize);
371
Karl Schultz6addd812016-02-02 17:17:23 -0700372 static const Vertex tri_data[] = {
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600373 {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 -0500374 };
375
Karl Schultz6addd812016-02-02 17:17:23 -0700376 for (i = 0; i < 3; i++) {
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500377 data.position[i][0] = tri_data[i].posX;
378 data.position[i][1] = tri_data[i].posY;
379 data.position[i][2] = tri_data[i].posZ;
380 data.position[i][3] = tri_data[i].posW;
Karl Schultz6addd812016-02-02 17:17:23 -0700381 data.color[i][0] = tri_data[i].r;
382 data.color[i][1] = tri_data[i].g;
383 data.color[i][2] = tri_data[i].b;
384 data.color[i][3] = tri_data[i].a;
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500385 }
386
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500387 ASSERT_NO_FATAL_FAILURE(InitViewport());
388
Chris Forbesbcfaadd2016-09-16 14:13:53 +1200389 VkConstantBufferObj constantBuffer(m_device, bufSize * 2, sizeof(float), (const void *)&data,
390 VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT);
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500391
Karl Schultz6addd812016-02-02 17:17:23 -0700392 VkShaderObj vs(m_device, vertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600393 VkShaderObj ps(m_device, fragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500394
395 VkPipelineObj pipelineobj(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +0800396 pipelineobj.AddColorAttachment();
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500397 pipelineobj.AddShader(&vs);
398 pipelineobj.AddShader(&ps);
Courtney Goeltzenleuchter507ba972015-09-30 16:16:57 -0600399 if (failMask & BsoFailLineWidth) {
400 pipelineobj.MakeDynamic(VK_DYNAMIC_STATE_LINE_WIDTH);
Tobin Ehlis7a1d2352016-03-28 11:18:19 -0600401 VkPipelineInputAssemblyStateCreateInfo ia_state = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600402 ia_state.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
Tobin Ehlis7a1d2352016-03-28 11:18:19 -0600403 ia_state.topology = VK_PRIMITIVE_TOPOLOGY_LINE_LIST;
404 pipelineobj.SetInputAssembly(&ia_state);
Courtney Goeltzenleuchter507ba972015-09-30 16:16:57 -0600405 }
406 if (failMask & BsoFailDepthBias) {
407 pipelineobj.MakeDynamic(VK_DYNAMIC_STATE_DEPTH_BIAS);
Tobin Ehlis7a1d2352016-03-28 11:18:19 -0600408 VkPipelineRasterizationStateCreateInfo rs_state = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600409 rs_state.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
Tobin Ehlis7a1d2352016-03-28 11:18:19 -0600410 rs_state.depthBiasEnable = VK_TRUE;
Mark Young7394fdd2016-03-31 14:56:43 -0600411 rs_state.lineWidth = 1.0f;
Tobin Ehlis7a1d2352016-03-28 11:18:19 -0600412 pipelineobj.SetRasterization(&rs_state);
Courtney Goeltzenleuchter507ba972015-09-30 16:16:57 -0600413 }
Karl Schultz6addd812016-02-02 17:17:23 -0700414 // Viewport and scissors must stay in synch or other errors will occur than
415 // the ones we want
Courtney Goeltzenleuchter507ba972015-09-30 16:16:57 -0600416 if (failMask & BsoFailViewport) {
417 pipelineobj.MakeDynamic(VK_DYNAMIC_STATE_VIEWPORT);
418 }
419 if (failMask & BsoFailScissor) {
420 pipelineobj.MakeDynamic(VK_DYNAMIC_STATE_SCISSOR);
421 }
422 if (failMask & BsoFailBlend) {
423 pipelineobj.MakeDynamic(VK_DYNAMIC_STATE_BLEND_CONSTANTS);
Tobin Ehlis7a1d2352016-03-28 11:18:19 -0600424 VkPipelineColorBlendAttachmentState att_state = {};
425 att_state.dstAlphaBlendFactor = VK_BLEND_FACTOR_CONSTANT_COLOR;
426 att_state.blendEnable = VK_TRUE;
427 pipelineobj.AddColorAttachment(0, &att_state);
Courtney Goeltzenleuchter507ba972015-09-30 16:16:57 -0600428 }
429 if (failMask & BsoFailDepthBounds) {
430 pipelineobj.MakeDynamic(VK_DYNAMIC_STATE_DEPTH_BOUNDS);
431 }
432 if (failMask & BsoFailStencilReadMask) {
433 pipelineobj.MakeDynamic(VK_DYNAMIC_STATE_STENCIL_COMPARE_MASK);
434 }
435 if (failMask & BsoFailStencilWriteMask) {
436 pipelineobj.MakeDynamic(VK_DYNAMIC_STATE_STENCIL_WRITE_MASK);
437 }
438 if (failMask & BsoFailStencilReference) {
439 pipelineobj.MakeDynamic(VK_DYNAMIC_STATE_STENCIL_REFERENCE);
440 }
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500441
442 VkDescriptorSetObj descriptorSet(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600443 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, constantBuffer);
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500444
445 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barbourfe3351b2015-07-28 10:17:20 -0600446 ASSERT_VK_SUCCESS(BeginCommandBuffer());
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500447
Tony Barbourfe3351b2015-07-28 10:17:20 -0600448 GenericDrawPreparation(pipelineobj, descriptorSet, failMask);
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500449
450 // render triangle
Tobin Ehlis379ba3b2016-07-19 11:22:29 -0600451 if (failMask & BsoFailIndexBuffer) {
452 // Use DrawIndexed w/o an index buffer bound
453 DrawIndexed(3, 1, 0, 0, 0);
454 } else {
455 Draw(3, 1, 0, 0);
456 }
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500457
Mark Muellerd4914412016-06-13 17:52:06 -0600458 if (failMask & BsoFailCmdClearAttachments) {
459 VkClearAttachment color_attachment = {};
460 color_attachment.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
461 color_attachment.colorAttachment = 1; // Someone who knew what they were doing would use 0 for the index;
462 VkClearRect clear_rect = {{{0, 0}, {static_cast<uint32_t>(m_width), static_cast<uint32_t>(m_height)}}, 0, 0};
463
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600464 vkCmdClearAttachments(m_commandBuffer->GetBufferHandle(), 1, &color_attachment, 1, &clear_rect);
Mark Muellerd4914412016-06-13 17:52:06 -0600465 }
466
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500467 // finalize recording of the command buffer
Tony Barbourfe3351b2015-07-28 10:17:20 -0600468 EndCommandBuffer();
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500469
Tony Barbourfe3351b2015-07-28 10:17:20 -0600470 QueueCommandBuffer();
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500471}
472
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600473void VkLayerTest::GenericDrawPreparation(VkCommandBufferObj *commandBuffer, VkPipelineObj &pipelineobj,
474 VkDescriptorSetObj &descriptorSet, BsoFailSelect failMask) {
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500475 if (m_depthStencil->Initialized()) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600476 commandBuffer->ClearAllBuffers(m_clear_color, m_depth_clear_color, m_stencil_clear_color, m_depthStencil);
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500477 } else {
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600478 commandBuffer->ClearAllBuffers(m_clear_color, m_depth_clear_color, m_stencil_clear_color, NULL);
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500479 }
480
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800481 commandBuffer->PrepareAttachments();
Karl Schultz6addd812016-02-02 17:17:23 -0700482 // Make sure depthWriteEnable is set so that Depth fail test will work
483 // correctly
484 // Make sure stencilTestEnable is set so that Stencil fail test will work
485 // correctly
Tony Barboureb254902015-07-15 12:50:33 -0600486 VkStencilOpState stencil = {};
Chia-I Wu1b99bb22015-10-27 19:25:11 +0800487 stencil.failOp = VK_STENCIL_OP_KEEP;
488 stencil.passOp = VK_STENCIL_OP_KEEP;
489 stencil.depthFailOp = VK_STENCIL_OP_KEEP;
490 stencil.compareOp = VK_COMPARE_OP_NEVER;
Tony Barboureb254902015-07-15 12:50:33 -0600491
492 VkPipelineDepthStencilStateCreateInfo ds_ci = {};
493 ds_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_DEPTH_STENCIL_STATE_CREATE_INFO;
Courtney Goeltzenleuchter507ba972015-09-30 16:16:57 -0600494 ds_ci.pNext = NULL;
495 ds_ci.depthTestEnable = VK_FALSE;
496 ds_ci.depthWriteEnable = VK_TRUE;
497 ds_ci.depthCompareOp = VK_COMPARE_OP_NEVER;
498 ds_ci.depthBoundsTestEnable = VK_FALSE;
Tobin Ehlis7a1d2352016-03-28 11:18:19 -0600499 if (failMask & BsoFailDepthBounds) {
500 ds_ci.depthBoundsTestEnable = VK_TRUE;
Tobin Ehlis21c88352016-05-26 06:15:45 -0600501 ds_ci.maxDepthBounds = 0.0f;
502 ds_ci.minDepthBounds = 0.0f;
Tobin Ehlis7a1d2352016-03-28 11:18:19 -0600503 }
Courtney Goeltzenleuchter507ba972015-09-30 16:16:57 -0600504 ds_ci.stencilTestEnable = VK_TRUE;
505 ds_ci.front = stencil;
506 ds_ci.back = stencil;
Tony Barboureb254902015-07-15 12:50:33 -0600507
Tobin Ehlis4bf96d12015-06-25 11:58:41 -0600508 pipelineobj.SetDepthStencil(&ds_ci);
Tobin Ehlisd332f282015-10-02 11:00:56 -0600509 pipelineobj.SetViewport(m_viewports);
510 pipelineobj.SetScissor(m_scissors);
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800511 descriptorSet.CreateVKDescriptorSet(commandBuffer);
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600512 VkResult err = pipelineobj.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Cody Northrop29a08f22015-08-27 10:20:35 -0600513 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800514 commandBuffer->BindPipeline(pipelineobj);
515 commandBuffer->BindDescriptorSet(descriptorSet);
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500516}
517
Ian Elliott2c1daf52016-05-12 09:41:46 -0600518class VkWsiEnabledLayerTest : public VkLayerTest {
519 public:
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600520 protected:
521 VkWsiEnabledLayerTest() { m_enableWSI = true; }
Ian Elliott2c1daf52016-05-12 09:41:46 -0600522};
523
Mark Muellerdfe37552016-07-07 14:47:42 -0600524class VkBufferTest {
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600525 public:
Mark Muellerdfe37552016-07-07 14:47:42 -0600526 enum eTestEnFlags {
527 eDoubleDelete,
528 eInvalidDeviceOffset,
529 eInvalidMemoryOffset,
530 eBindNullBuffer,
531 eFreeInvalidHandle,
Mark Mueller4042b652016-09-05 22:52:21 -0600532 eNone,
Mark Muellerdfe37552016-07-07 14:47:42 -0600533 };
534
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600535 enum eTestConditions { eOffsetAlignment = 1 };
Mark Muellerdfe37552016-07-07 14:47:42 -0600536
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600537 static bool GetTestConditionValid(VkDeviceObj *aVulkanDevice, eTestEnFlags aTestFlag, VkBufferUsageFlags aBufferUsage = 0) {
538 if (eInvalidDeviceOffset != aTestFlag && eInvalidMemoryOffset != aTestFlag) {
Mark Muellerdfe37552016-07-07 14:47:42 -0600539 return true;
540 }
541 VkDeviceSize offset_limit = 0;
542 if (eInvalidMemoryOffset == aTestFlag) {
543 VkBuffer vulkanBuffer;
544 VkBufferCreateInfo buffer_create_info = {};
545 buffer_create_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
546 buffer_create_info.size = 32;
547 buffer_create_info.usage = aBufferUsage;
548
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600549 vkCreateBuffer(aVulkanDevice->device(), &buffer_create_info, nullptr, &vulkanBuffer);
Mark Mueller4042b652016-09-05 22:52:21 -0600550 VkMemoryRequirements memory_reqs = {};
Mark Muellerdfe37552016-07-07 14:47:42 -0600551
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600552 vkGetBufferMemoryRequirements(aVulkanDevice->device(), vulkanBuffer, &memory_reqs);
Mark Muellerdfe37552016-07-07 14:47:42 -0600553 vkDestroyBuffer(aVulkanDevice->device(), vulkanBuffer, nullptr);
554 offset_limit = memory_reqs.alignment;
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600555 } else if ((VK_BUFFER_USAGE_UNIFORM_TEXEL_BUFFER_BIT | VK_BUFFER_USAGE_STORAGE_TEXEL_BUFFER_BIT) & aBufferUsage) {
556 offset_limit = aVulkanDevice->props.limits.minTexelBufferOffsetAlignment;
Mark Muellerdfe37552016-07-07 14:47:42 -0600557 } else if (VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT & aBufferUsage) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600558 offset_limit = aVulkanDevice->props.limits.minUniformBufferOffsetAlignment;
Mark Muellerdfe37552016-07-07 14:47:42 -0600559 } else if (VK_BUFFER_USAGE_STORAGE_BUFFER_BIT & aBufferUsage) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600560 offset_limit = aVulkanDevice->props.limits.minStorageBufferOffsetAlignment;
Mark Muellerdfe37552016-07-07 14:47:42 -0600561 }
562 if (eOffsetAlignment < offset_limit) {
563 return true;
564 }
565 return false;
566 }
567
568 // A constructor which performs validation tests within construction.
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600569 VkBufferTest(VkDeviceObj *aVulkanDevice, VkBufferUsageFlags aBufferUsage, eTestEnFlags aTestFlag = eNone)
570 : AllocateCurrent(false), BoundCurrent(false), CreateCurrent(false), VulkanDevice(aVulkanDevice->device()) {
Mark Muellerdfe37552016-07-07 14:47:42 -0600571
572 if (eBindNullBuffer == aTestFlag) {
573 VulkanMemory = 0;
574 vkBindBufferMemory(VulkanDevice, VulkanBuffer, VulkanMemory, 0);
575 } else {
576 VkBufferCreateInfo buffer_create_info = {};
577 buffer_create_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
578 buffer_create_info.size = 32;
579 buffer_create_info.usage = aBufferUsage;
580
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600581 vkCreateBuffer(VulkanDevice, &buffer_create_info, nullptr, &VulkanBuffer);
Mark Muellerdfe37552016-07-07 14:47:42 -0600582
583 CreateCurrent = true;
584
585 VkMemoryRequirements memory_requirements;
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600586 vkGetBufferMemoryRequirements(VulkanDevice, VulkanBuffer, &memory_requirements);
Mark Muellerdfe37552016-07-07 14:47:42 -0600587
588 VkMemoryAllocateInfo memory_allocate_info = {};
589 memory_allocate_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
590 memory_allocate_info.allocationSize = memory_requirements.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600591 bool pass = aVulkanDevice->phy().set_memory_type(memory_requirements.memoryTypeBits, &memory_allocate_info,
592 VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT);
Mark Muellerdfe37552016-07-07 14:47:42 -0600593 if (!pass) {
594 vkDestroyBuffer(VulkanDevice, VulkanBuffer, nullptr);
595 return;
596 }
597
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600598 vkAllocateMemory(VulkanDevice, &memory_allocate_info, NULL, &VulkanMemory);
Mark Muellerdfe37552016-07-07 14:47:42 -0600599 AllocateCurrent = true;
600 // NB: 1 is intentionally an invalid offset value
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600601 const bool offset_en = eInvalidDeviceOffset == aTestFlag || eInvalidMemoryOffset == aTestFlag;
602 vkBindBufferMemory(VulkanDevice, VulkanBuffer, VulkanMemory, offset_en ? eOffsetAlignment : 0);
Mark Muellerdfe37552016-07-07 14:47:42 -0600603 BoundCurrent = true;
604
605 InvalidDeleteEn = (eFreeInvalidHandle == aTestFlag);
606 }
607 }
608
609 ~VkBufferTest() {
610 if (CreateCurrent) {
611 vkDestroyBuffer(VulkanDevice, VulkanBuffer, nullptr);
612 }
613 if (AllocateCurrent) {
614 if (InvalidDeleteEn) {
615 union {
616 VkDeviceMemory device_memory;
617 unsigned long long index_access;
618 } bad_index;
619
620 bad_index.device_memory = VulkanMemory;
621 bad_index.index_access++;
622
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600623 vkFreeMemory(VulkanDevice, bad_index.device_memory, nullptr);
Mark Muellerdfe37552016-07-07 14:47:42 -0600624 }
625 vkFreeMemory(VulkanDevice, VulkanMemory, nullptr);
626 }
627 }
628
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600629 bool GetBufferCurrent() { return AllocateCurrent && BoundCurrent && CreateCurrent; }
Mark Muellerdfe37552016-07-07 14:47:42 -0600630
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600631 const VkBuffer &GetBuffer() { return VulkanBuffer; }
Mark Muellerdfe37552016-07-07 14:47:42 -0600632
633 void TestDoubleDestroy() {
634 // Destroy the buffer but leave the flag set, which will cause
635 // the buffer to be destroyed again in the destructor.
636 vkDestroyBuffer(VulkanDevice, VulkanBuffer, nullptr);
637 }
638
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600639 protected:
Mark Muellerdfe37552016-07-07 14:47:42 -0600640 bool AllocateCurrent;
641 bool BoundCurrent;
642 bool CreateCurrent;
643 bool InvalidDeleteEn;
644
645 VkBuffer VulkanBuffer;
646 VkDevice VulkanDevice;
647 VkDeviceMemory VulkanMemory;
Mark Muellerdfe37552016-07-07 14:47:42 -0600648};
649
650class VkVerticesObj {
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600651 public:
652 VkVerticesObj(VkDeviceObj *aVulkanDevice, unsigned aAttributeCount, unsigned aBindingCount, unsigned aByteStride,
Mark Muellerdfe37552016-07-07 14:47:42 -0600653 VkDeviceSize aVertexCount, const float *aVerticies)
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600654 : BoundCurrent(false), AttributeCount(aAttributeCount), BindingCount(aBindingCount), BindId(BindIdGenerator),
Mark Muellerdfe37552016-07-07 14:47:42 -0600655 PipelineVertexInputStateCreateInfo(),
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600656 VulkanMemoryBuffer(aVulkanDevice, 1, static_cast<int>(aByteStride * aVertexCount),
657 reinterpret_cast<const void *>(aVerticies), VK_BUFFER_USAGE_VERTEX_BUFFER_BIT) {
Mark Muellerdfe37552016-07-07 14:47:42 -0600658 BindIdGenerator++; // NB: This can wrap w/misuse
659
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600660 VertexInputAttributeDescription = new VkVertexInputAttributeDescription[AttributeCount];
661 VertexInputBindingDescription = new VkVertexInputBindingDescription[BindingCount];
Mark Muellerdfe37552016-07-07 14:47:42 -0600662
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600663 PipelineVertexInputStateCreateInfo.pVertexAttributeDescriptions = VertexInputAttributeDescription;
664 PipelineVertexInputStateCreateInfo.vertexAttributeDescriptionCount = AttributeCount;
665 PipelineVertexInputStateCreateInfo.pVertexBindingDescriptions = VertexInputBindingDescription;
666 PipelineVertexInputStateCreateInfo.vertexBindingDescriptionCount = BindingCount;
667 PipelineVertexInputStateCreateInfo.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
Mark Muellerdfe37552016-07-07 14:47:42 -0600668
669 unsigned i = 0;
670 do {
671 VertexInputAttributeDescription[i].binding = BindId;
672 VertexInputAttributeDescription[i].location = i;
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600673 VertexInputAttributeDescription[i].format = VK_FORMAT_R32G32B32_SFLOAT;
674 VertexInputAttributeDescription[i].offset = sizeof(float) * aByteStride;
Mark Muellerdfe37552016-07-07 14:47:42 -0600675 i++;
676 } while (AttributeCount < i);
677
678 i = 0;
679 do {
680 VertexInputBindingDescription[i].binding = BindId;
681 VertexInputBindingDescription[i].stride = aByteStride;
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600682 VertexInputBindingDescription[i].inputRate = VK_VERTEX_INPUT_RATE_VERTEX;
Mark Muellerdfe37552016-07-07 14:47:42 -0600683 i++;
684 } while (BindingCount < i);
685 }
686
687 ~VkVerticesObj() {
688 if (VertexInputAttributeDescription) {
689 delete[] VertexInputAttributeDescription;
690 }
691 if (VertexInputBindingDescription) {
692 delete[] VertexInputBindingDescription;
693 }
694 }
695
696 bool AddVertexInputToPipe(VkPipelineObj &aPipelineObj) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600697 aPipelineObj.AddVertexInputAttribs(VertexInputAttributeDescription, AttributeCount);
698 aPipelineObj.AddVertexInputBindings(VertexInputBindingDescription, BindingCount);
Mark Muellerdfe37552016-07-07 14:47:42 -0600699 return true;
700 }
701
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600702 void BindVertexBuffers(VkCommandBuffer aCommandBuffer, unsigned aOffsetCount = 0, VkDeviceSize *aOffsetList = nullptr) {
Mark Muellerdfe37552016-07-07 14:47:42 -0600703 VkDeviceSize *offsetList;
704 unsigned offsetCount;
705
706 if (aOffsetCount) {
707 offsetList = aOffsetList;
708 offsetCount = aOffsetCount;
709 } else {
710 offsetList = new VkDeviceSize[1]();
711 offsetCount = 1;
712 }
713
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600714 vkCmdBindVertexBuffers(aCommandBuffer, BindId, offsetCount, &VulkanMemoryBuffer.handle(), offsetList);
Mark Muellerdfe37552016-07-07 14:47:42 -0600715 BoundCurrent = true;
716
717 if (!aOffsetCount) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600718 delete[] offsetList;
Mark Muellerdfe37552016-07-07 14:47:42 -0600719 }
720 }
721
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600722 protected:
Mark Muellerdfe37552016-07-07 14:47:42 -0600723 static uint32_t BindIdGenerator;
724
725 bool BoundCurrent;
726 unsigned AttributeCount;
727 unsigned BindingCount;
728 uint32_t BindId;
729
730 VkPipelineVertexInputStateCreateInfo PipelineVertexInputStateCreateInfo;
731 VkVertexInputAttributeDescription *VertexInputAttributeDescription;
732 VkVertexInputBindingDescription *VertexInputBindingDescription;
733 VkConstantBufferObj VulkanMemoryBuffer;
734};
735
736uint32_t VkVerticesObj::BindIdGenerator;
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500737// ********************************************************************************************************************
738// ********************************************************************************************************************
739// ********************************************************************************************************************
740// ********************************************************************************************************************
Dustin Gravesffa90fa2016-05-06 11:20:38 -0600741#if PARAMETER_VALIDATION_TESTS
742TEST_F(VkLayerTest, RequiredParameter) {
743 TEST_DESCRIPTION("Specify VK_NULL_HANDLE, NULL, and 0 for required handle, "
744 "pointer, array, and array count parameters");
745
746 ASSERT_NO_FATAL_FAILURE(InitState());
747
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600748 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "required parameter pFeatures specified as NULL");
Dustin Gravesffa90fa2016-05-06 11:20:38 -0600749 // Specify NULL for a pointer to a handle
750 // Expected to trigger an error with
751 // parameter_validation::validate_required_pointer
752 vkGetPhysicalDeviceFeatures(gpu(), NULL);
753 m_errorMonitor->VerifyFound();
754
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600755 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
756 "required parameter pQueueFamilyPropertyCount specified as NULL");
Dustin Gravesffa90fa2016-05-06 11:20:38 -0600757 // Specify NULL for pointer to array count
758 // Expected to trigger an error with parameter_validation::validate_array
Dustin Gravesa4bb8c12016-05-16 17:22:51 -0600759 vkGetPhysicalDeviceQueueFamilyProperties(gpu(), NULL, NULL);
Dustin Gravesffa90fa2016-05-06 11:20:38 -0600760 m_errorMonitor->VerifyFound();
761
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600762 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "parameter viewportCount must be greater than 0");
Dustin Gravesffa90fa2016-05-06 11:20:38 -0600763 // Specify 0 for a required array count
764 // Expected to trigger an error with parameter_validation::validate_array
765 VkViewport view_port = {};
766 m_commandBuffer->SetViewport(0, 0, &view_port);
767 m_errorMonitor->VerifyFound();
768
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600769 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "required parameter pViewports specified as NULL");
Dustin Gravesffa90fa2016-05-06 11:20:38 -0600770 // Specify NULL for a required array
771 // Expected to trigger an error with parameter_validation::validate_array
772 m_commandBuffer->SetViewport(0, 1, NULL);
773 m_errorMonitor->VerifyFound();
774
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600775 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "required parameter memory specified as VK_NULL_HANDLE");
Dustin Gravesffa90fa2016-05-06 11:20:38 -0600776 // Specify VK_NULL_HANDLE for a required handle
777 // Expected to trigger an error with
778 // parameter_validation::validate_required_handle
779 vkUnmapMemory(device(), VK_NULL_HANDLE);
780 m_errorMonitor->VerifyFound();
781
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600782 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
783 "required parameter pFences[0] specified as VK_NULL_HANDLE");
Dustin Gravesffa90fa2016-05-06 11:20:38 -0600784 // Specify VK_NULL_HANDLE for a required handle array entry
785 // Expected to trigger an error with
786 // parameter_validation::validate_required_handle_array
787 VkFence fence = VK_NULL_HANDLE;
788 vkResetFences(device(), 1, &fence);
789 m_errorMonitor->VerifyFound();
790
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600791 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "required parameter pAllocateInfo specified as NULL");
Dustin Gravesffa90fa2016-05-06 11:20:38 -0600792 // Specify NULL for a required struct pointer
793 // Expected to trigger an error with
794 // parameter_validation::validate_struct_type
795 VkDeviceMemory memory = VK_NULL_HANDLE;
796 vkAllocateMemory(device(), NULL, NULL, &memory);
797 m_errorMonitor->VerifyFound();
798
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600799 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "value of faceMask must not be 0");
Dustin Gravesffa90fa2016-05-06 11:20:38 -0600800 // Specify 0 for a required VkFlags parameter
801 // Expected to trigger an error with parameter_validation::validate_flags
802 m_commandBuffer->SetStencilReference(0, 0);
803 m_errorMonitor->VerifyFound();
804
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600805 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 -0600806 // Specify 0 for a required VkFlags array entry
807 // Expected to trigger an error with
808 // parameter_validation::validate_flags_array
809 VkSemaphore semaphore = VK_NULL_HANDLE;
810 VkPipelineStageFlags stageFlags = 0;
811 VkSubmitInfo submitInfo = {};
812 submitInfo.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
813 submitInfo.waitSemaphoreCount = 1;
814 submitInfo.pWaitSemaphores = &semaphore;
815 submitInfo.pWaitDstStageMask = &stageFlags;
816 vkQueueSubmit(m_device->m_queue, 1, &submitInfo, VK_NULL_HANDLE);
817 m_errorMonitor->VerifyFound();
818}
Dustin Gravesc99cf5a2016-05-09 14:40:29 -0600819
Dustin Gravesfce74c02016-05-10 11:42:58 -0600820TEST_F(VkLayerTest, ReservedParameter) {
821 TEST_DESCRIPTION("Specify a non-zero value for a reserved parameter");
822
823 ASSERT_NO_FATAL_FAILURE(InitState());
824
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600825 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " must be 0");
Dustin Gravesfce74c02016-05-10 11:42:58 -0600826 // Specify 0 for a reserved VkFlags parameter
827 // Expected to trigger an error with
828 // parameter_validation::validate_reserved_flags
829 VkEvent event_handle = VK_NULL_HANDLE;
830 VkEventCreateInfo event_info = {};
831 event_info.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO;
832 event_info.flags = 1;
833 vkCreateEvent(device(), &event_info, NULL, &event_handle);
834 m_errorMonitor->VerifyFound();
835}
836
Dustin Gravesc99cf5a2016-05-09 14:40:29 -0600837TEST_F(VkLayerTest, InvalidStructSType) {
838 TEST_DESCRIPTION("Specify an invalid VkStructureType for a Vulkan "
839 "structure's sType field");
840
841 ASSERT_NO_FATAL_FAILURE(InitState());
842
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600843 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "parameter pAllocateInfo->sType must be");
Dustin Gravesc99cf5a2016-05-09 14:40:29 -0600844 // Zero struct memory, effectively setting sType to
845 // VK_STRUCTURE_TYPE_APPLICATION_INFO
846 // Expected to trigger an error with
847 // parameter_validation::validate_struct_type
848 VkMemoryAllocateInfo alloc_info = {};
849 VkDeviceMemory memory = VK_NULL_HANDLE;
850 vkAllocateMemory(device(), &alloc_info, NULL, &memory);
851 m_errorMonitor->VerifyFound();
852
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600853 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "parameter pSubmits[0].sType must be");
Dustin Gravesc99cf5a2016-05-09 14:40:29 -0600854 // Zero struct memory, effectively setting sType to
855 // VK_STRUCTURE_TYPE_APPLICATION_INFO
856 // Expected to trigger an error with
857 // parameter_validation::validate_struct_type_array
858 VkSubmitInfo submit_info = {};
859 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
860 m_errorMonitor->VerifyFound();
861}
862
863TEST_F(VkLayerTest, InvalidStructPNext) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600864 TEST_DESCRIPTION("Specify an invalid value for a Vulkan structure's pNext field");
Dustin Gravesc99cf5a2016-05-09 14:40:29 -0600865
866 ASSERT_NO_FATAL_FAILURE(InitState());
867
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600868 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT, "value of pCreateInfo->pNext must be NULL");
Dustin Gravesc99cf5a2016-05-09 14:40:29 -0600869 // Set VkMemoryAllocateInfo::pNext to a non-NULL value, when pNext must be
Karl Schultz38b50992016-07-11 16:09:09 -0600870 // NULL.
871 // Need to pick a function that has no allowed pNext structure types.
872 // Expected to trigger an error with
873 // parameter_validation::validate_struct_pnext
874 VkEvent event = VK_NULL_HANDLE;
Karl Schultz70db3902016-07-11 16:22:10 -0600875 VkEventCreateInfo event_alloc_info = {};
Karl Schultz38b50992016-07-11 16:09:09 -0600876 // Zero-initialization will provide the correct sType
877 VkApplicationInfo app_info = {};
878 event_alloc_info.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO;
879 event_alloc_info.pNext = &app_info;
880 vkCreateEvent(device(), &event_alloc_info, NULL, &event);
881 m_errorMonitor->VerifyFound();
882
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600883 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT,
884 " chain includes a structure with unexpected VkStructureType ");
Karl Schultz38b50992016-07-11 16:09:09 -0600885 // Set VkMemoryAllocateInfo::pNext to a non-NULL value, but use
886 // a function that has allowed pNext structure types and specify
887 // a structure type that is not allowed.
Dustin Gravesc99cf5a2016-05-09 14:40:29 -0600888 // Expected to trigger an error with
889 // parameter_validation::validate_struct_pnext
890 VkDeviceMemory memory = VK_NULL_HANDLE;
Dustin Graves47b6cba2016-05-10 17:34:38 -0600891 VkMemoryAllocateInfo memory_alloc_info = {};
892 memory_alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
893 memory_alloc_info.pNext = &app_info;
894 vkAllocateMemory(device(), &memory_alloc_info, NULL, &memory);
Dustin Gravesc99cf5a2016-05-09 14:40:29 -0600895 m_errorMonitor->VerifyFound();
896
Dustin Gravesfd1c8fe2016-07-15 11:40:20 -0600897 // Positive test to check parameter_validation and unique_objects support
898 // for NV_dedicated_allocation
899 uint32_t extension_count = 0;
900 bool supports_nv_dedicated_allocation = false;
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600901 VkResult err = vkEnumerateDeviceExtensionProperties(gpu(), nullptr, &extension_count, nullptr);
Dustin Gravesfd1c8fe2016-07-15 11:40:20 -0600902 ASSERT_VK_SUCCESS(err);
903
904 if (extension_count > 0) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600905 std::vector<VkExtensionProperties> available_extensions(extension_count);
Dustin Gravesfd1c8fe2016-07-15 11:40:20 -0600906
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600907 err = vkEnumerateDeviceExtensionProperties(gpu(), nullptr, &extension_count, &available_extensions[0]);
Dustin Gravesfd1c8fe2016-07-15 11:40:20 -0600908 ASSERT_VK_SUCCESS(err);
909
910 for (const auto &extension_props : available_extensions) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600911 if (strcmp(extension_props.extensionName, VK_NV_DEDICATED_ALLOCATION_EXTENSION_NAME) == 0) {
Dustin Gravesfd1c8fe2016-07-15 11:40:20 -0600912 supports_nv_dedicated_allocation = true;
913 }
914 }
915 }
916
917 if (supports_nv_dedicated_allocation) {
918 m_errorMonitor->ExpectSuccess();
919
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600920 VkDedicatedAllocationBufferCreateInfoNV dedicated_buffer_create_info = {};
921 dedicated_buffer_create_info.sType = VK_STRUCTURE_TYPE_DEDICATED_ALLOCATION_BUFFER_CREATE_INFO_NV;
Dustin Gravesfd1c8fe2016-07-15 11:40:20 -0600922 dedicated_buffer_create_info.pNext = nullptr;
923 dedicated_buffer_create_info.dedicatedAllocation = VK_TRUE;
924
925 uint32_t queue_family_index = 0;
926 VkBufferCreateInfo buffer_create_info = {};
927 buffer_create_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
928 buffer_create_info.pNext = &dedicated_buffer_create_info;
929 buffer_create_info.size = 1024;
930 buffer_create_info.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
931 buffer_create_info.queueFamilyIndexCount = 1;
932 buffer_create_info.pQueueFamilyIndices = &queue_family_index;
933
934 VkBuffer buffer;
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600935 VkResult err = vkCreateBuffer(m_device->device(), &buffer_create_info, NULL, &buffer);
Dustin Gravesfd1c8fe2016-07-15 11:40:20 -0600936 ASSERT_VK_SUCCESS(err);
937
938 VkMemoryRequirements memory_reqs;
939 vkGetBufferMemoryRequirements(m_device->device(), buffer, &memory_reqs);
940
941 VkDedicatedAllocationMemoryAllocateInfoNV dedicated_memory_info = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600942 dedicated_memory_info.sType = VK_STRUCTURE_TYPE_DEDICATED_ALLOCATION_MEMORY_ALLOCATE_INFO_NV;
Dustin Gravesfd1c8fe2016-07-15 11:40:20 -0600943 dedicated_memory_info.pNext = nullptr;
944 dedicated_memory_info.buffer = buffer;
945 dedicated_memory_info.image = VK_NULL_HANDLE;
946
947 VkMemoryAllocateInfo memory_info = {};
948 memory_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
949 memory_info.pNext = &dedicated_memory_info;
950 memory_info.allocationSize = memory_reqs.size;
951
952 bool pass;
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600953 pass = m_device->phy().set_memory_type(memory_reqs.memoryTypeBits, &memory_info, 0);
Dustin Gravesfd1c8fe2016-07-15 11:40:20 -0600954 ASSERT_TRUE(pass);
955
956 VkDeviceMemory buffer_memory;
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600957 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &buffer_memory);
Dustin Gravesfd1c8fe2016-07-15 11:40:20 -0600958 ASSERT_VK_SUCCESS(err);
959
960 err = vkBindBufferMemory(m_device->device(), buffer, buffer_memory, 0);
961 ASSERT_VK_SUCCESS(err);
962
963 vkDestroyBuffer(m_device->device(), buffer, NULL);
964 vkFreeMemory(m_device->device(), buffer_memory, NULL);
965
966 m_errorMonitor->VerifyNotFound();
967 }
Dustin Gravesc99cf5a2016-05-09 14:40:29 -0600968}
Dustin Graves5d33d532016-05-09 16:21:12 -0600969
970TEST_F(VkLayerTest, UnrecognizedValue) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600971 TEST_DESCRIPTION("Specify unrecognized Vulkan enumeration, flags, and VkBool32 values");
Dustin Graves5d33d532016-05-09 16:21:12 -0600972
973 ASSERT_NO_FATAL_FAILURE(InitState());
974
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600975 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "does not fall within the begin..end "
976 "range of the core VkFormat "
977 "enumeration tokens");
Dustin Graves5d33d532016-05-09 16:21:12 -0600978 // Specify an invalid VkFormat value
979 // Expected to trigger an error with
980 // parameter_validation::validate_ranged_enum
981 VkFormatProperties format_properties;
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600982 vkGetPhysicalDeviceFormatProperties(gpu(), static_cast<VkFormat>(8000), &format_properties);
Dustin Graves5d33d532016-05-09 16:21:12 -0600983 m_errorMonitor->VerifyFound();
984
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600985 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 -0600986 // Specify an invalid VkFlags bitmask value
987 // Expected to trigger an error with parameter_validation::validate_flags
988 VkImageFormatProperties image_format_properties;
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600989 vkGetPhysicalDeviceImageFormatProperties(gpu(), VK_FORMAT_R8G8B8A8_UNORM, VK_IMAGE_TYPE_2D, VK_IMAGE_TILING_OPTIMAL,
990 static_cast<VkImageUsageFlags>(1 << 25), 0, &image_format_properties);
Dustin Graves5d33d532016-05-09 16:21:12 -0600991 m_errorMonitor->VerifyFound();
992
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600993 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 -0600994 // Specify an invalid VkFlags array entry
995 // Expected to trigger an error with
996 // parameter_validation::validate_flags_array
997 VkSemaphore semaphore = VK_NULL_HANDLE;
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600998 VkPipelineStageFlags stage_flags = static_cast<VkPipelineStageFlags>(1 << 25);
Dustin Graves5d33d532016-05-09 16:21:12 -0600999 VkSubmitInfo submit_info = {};
1000 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
1001 submit_info.waitSemaphoreCount = 1;
1002 submit_info.pWaitSemaphores = &semaphore;
1003 submit_info.pWaitDstStageMask = &stage_flags;
1004 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
1005 m_errorMonitor->VerifyFound();
1006
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001007 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT, "is neither VK_TRUE nor VK_FALSE");
Dustin Graves5d33d532016-05-09 16:21:12 -06001008 // Specify an invalid VkBool32 value
1009 // Expected to trigger a warning with
1010 // parameter_validation::validate_bool32
1011 VkSampler sampler = VK_NULL_HANDLE;
1012 VkSamplerCreateInfo sampler_info = {};
1013 sampler_info.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
1014 sampler_info.pNext = NULL;
1015 sampler_info.magFilter = VK_FILTER_NEAREST;
1016 sampler_info.minFilter = VK_FILTER_NEAREST;
1017 sampler_info.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
1018 sampler_info.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
1019 sampler_info.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
1020 sampler_info.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
1021 sampler_info.mipLodBias = 1.0;
1022 sampler_info.maxAnisotropy = 1;
1023 sampler_info.compareEnable = VK_FALSE;
1024 sampler_info.compareOp = VK_COMPARE_OP_NEVER;
1025 sampler_info.minLod = 1.0;
1026 sampler_info.maxLod = 1.0;
1027 sampler_info.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
1028 sampler_info.unnormalizedCoordinates = VK_FALSE;
1029 // Not VK_TRUE or VK_FALSE
1030 sampler_info.anisotropyEnable = 3;
1031 vkCreateSampler(m_device->device(), &sampler_info, NULL, &sampler);
1032 m_errorMonitor->VerifyFound();
1033}
Dustin Gravesfce74c02016-05-10 11:42:58 -06001034
1035TEST_F(VkLayerTest, FailedReturnValue) {
1036 TEST_DESCRIPTION("Check for a message describing a VkResult failure code");
1037
1038 ASSERT_NO_FATAL_FAILURE(InitState());
1039
Dustin Graves13c1e2b2016-05-16 15:31:02 -06001040 // Find an unsupported image format
1041 VkFormat unsupported = VK_FORMAT_UNDEFINED;
1042 for (int f = VK_FORMAT_BEGIN_RANGE; f <= VK_FORMAT_END_RANGE; f++) {
1043 VkFormat format = static_cast<VkFormat>(f);
1044 VkFormatProperties fProps = m_device->format_properties(format);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001045 if (format != VK_FORMAT_UNDEFINED && fProps.linearTilingFeatures == 0 && fProps.optimalTilingFeatures == 0) {
Dustin Graves13c1e2b2016-05-16 15:31:02 -06001046 unsupported = format;
1047 break;
1048 }
1049 }
1050
1051 if (unsupported != VK_FORMAT_UNDEFINED) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001052 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT,
1053 "the requested format is not supported on this device");
Dustin Graves13c1e2b2016-05-16 15:31:02 -06001054 // Specify an unsupported VkFormat value to generate a
1055 // VK_ERROR_FORMAT_NOT_SUPPORTED return code
1056 // Expected to trigger a warning from
1057 // parameter_validation::validate_result
1058 VkImageFormatProperties image_format_properties;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001059 VkResult err = vkGetPhysicalDeviceImageFormatProperties(gpu(), unsupported, VK_IMAGE_TYPE_2D, VK_IMAGE_TILING_OPTIMAL,
1060 VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT, 0, &image_format_properties);
Dustin Graves13c1e2b2016-05-16 15:31:02 -06001061 ASSERT_TRUE(err == VK_ERROR_FORMAT_NOT_SUPPORTED);
1062 m_errorMonitor->VerifyFound();
1063 }
Dustin Gravesfce74c02016-05-10 11:42:58 -06001064}
Mark Lobodzinskie090fef2016-06-09 17:04:56 -06001065
1066TEST_F(VkLayerTest, UpdateBufferAlignment) {
1067 TEST_DESCRIPTION("Check alignment parameters for vkCmdUpdateBuffer");
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001068 uint32_t updateData[] = {1, 2, 3, 4, 5, 6, 7, 8};
Mark Lobodzinskie090fef2016-06-09 17:04:56 -06001069
1070 ASSERT_NO_FATAL_FAILURE(InitState());
1071
1072 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
1073 vk_testing::Buffer buffer;
1074 buffer.init_as_dst(*m_device, (VkDeviceSize)20, reqs);
1075
1076 BeginCommandBuffer();
1077 // Introduce failure by using dstOffset that is not multiple of 4
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001078 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " is not a multiple of 4");
Mark Lobodzinskie090fef2016-06-09 17:04:56 -06001079 m_commandBuffer->UpdateBuffer(buffer.handle(), 1, 4, updateData);
1080 m_errorMonitor->VerifyFound();
1081
1082 // Introduce failure by using dataSize that is not multiple of 4
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001083 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " is not a multiple of 4");
Mark Lobodzinskie090fef2016-06-09 17:04:56 -06001084 m_commandBuffer->UpdateBuffer(buffer.handle(), 0, 6, updateData);
1085 m_errorMonitor->VerifyFound();
1086
1087 // Introduce failure by using dataSize that is < 0
1088 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001089 "must be greater than zero and less than or equal to 65536");
Mark Lobodzinskie090fef2016-06-09 17:04:56 -06001090 m_commandBuffer->UpdateBuffer(buffer.handle(), 0, -44, updateData);
1091 m_errorMonitor->VerifyFound();
1092
1093 // Introduce failure by using dataSize that is > 65536
1094 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001095 "must be greater than zero and less than or equal to 65536");
Mark Lobodzinskie090fef2016-06-09 17:04:56 -06001096 m_commandBuffer->UpdateBuffer(buffer.handle(), 0, 80000, updateData);
1097 m_errorMonitor->VerifyFound();
1098
1099 EndCommandBuffer();
1100}
1101
1102TEST_F(VkLayerTest, FillBufferAlignment) {
1103 TEST_DESCRIPTION("Check alignment parameters for vkCmdFillBuffer");
1104
1105 ASSERT_NO_FATAL_FAILURE(InitState());
1106
1107 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
1108 vk_testing::Buffer buffer;
1109 buffer.init_as_dst(*m_device, (VkDeviceSize)20, reqs);
1110
1111 BeginCommandBuffer();
1112
1113 // Introduce failure by using dstOffset that is not multiple of 4
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001114 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " is not a multiple of 4");
Mark Lobodzinskie090fef2016-06-09 17:04:56 -06001115 m_commandBuffer->FillBuffer(buffer.handle(), 1, 4, 0x11111111);
1116 m_errorMonitor->VerifyFound();
1117
1118 // Introduce failure by using size that is not multiple of 4
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001119 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " is not a multiple of 4");
Mark Lobodzinskie090fef2016-06-09 17:04:56 -06001120 m_commandBuffer->FillBuffer(buffer.handle(), 0, 6, 0x11111111);
1121 m_errorMonitor->VerifyFound();
1122
1123 // Introduce failure by using size that is zero
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001124 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "must be greater than zero");
Mark Lobodzinskie090fef2016-06-09 17:04:56 -06001125 m_commandBuffer->FillBuffer(buffer.handle(), 0, 0, 0x11111111);
1126 m_errorMonitor->VerifyFound();
1127
1128 EndCommandBuffer();
1129}
Dustin Graves40f35822016-06-23 11:12:53 -06001130
1131// This is a positive test. No failures are expected.
1132TEST_F(VkLayerTest, IgnoreUnrelatedDescriptor) {
1133 TEST_DESCRIPTION("Ensure that the vkUpdateDescriptorSet validation code "
1134 "is ignoring VkWriteDescriptorSet members that are not "
1135 "related to the descriptor type specified by "
1136 "VkWriteDescriptorSet::descriptorType. Correct "
1137 "validation behavior will result in the test running to "
1138 "completion without validation errors.");
1139
Dustin Graves5e2d8fc2016-07-07 16:18:49 -06001140 const uintptr_t invalid_ptr = 0xcdcdcdcd;
1141
Dustin Graves40f35822016-06-23 11:12:53 -06001142 ASSERT_NO_FATAL_FAILURE(InitState());
1143
1144 // Image Case
1145 {
1146 m_errorMonitor->ExpectSuccess();
1147
1148 VkImage image;
1149 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
1150 const int32_t tex_width = 32;
1151 const int32_t tex_height = 32;
1152 VkImageCreateInfo image_create_info = {};
1153 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
1154 image_create_info.pNext = NULL;
1155 image_create_info.imageType = VK_IMAGE_TYPE_2D;
1156 image_create_info.format = tex_format;
1157 image_create_info.extent.width = tex_width;
1158 image_create_info.extent.height = tex_height;
1159 image_create_info.extent.depth = 1;
1160 image_create_info.mipLevels = 1;
1161 image_create_info.arrayLayers = 1;
1162 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
Tobin Ehlis51cde412016-07-11 16:08:30 -06001163 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
Dustin Graves40f35822016-06-23 11:12:53 -06001164 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
1165 image_create_info.flags = 0;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001166 VkResult err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
Dustin Graves40f35822016-06-23 11:12:53 -06001167 ASSERT_VK_SUCCESS(err);
1168
1169 VkMemoryRequirements memory_reqs;
1170 VkDeviceMemory image_memory;
1171 bool pass;
1172 VkMemoryAllocateInfo memory_info = {};
1173 memory_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
1174 memory_info.pNext = NULL;
1175 memory_info.allocationSize = 0;
1176 memory_info.memoryTypeIndex = 0;
1177 vkGetImageMemoryRequirements(m_device->device(), image, &memory_reqs);
1178 memory_info.allocationSize = memory_reqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001179 pass = m_device->phy().set_memory_type(memory_reqs.memoryTypeBits, &memory_info, 0);
Dustin Graves40f35822016-06-23 11:12:53 -06001180 ASSERT_TRUE(pass);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001181 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &image_memory);
Dustin Graves40f35822016-06-23 11:12:53 -06001182 ASSERT_VK_SUCCESS(err);
1183 err = vkBindImageMemory(m_device->device(), image, image_memory, 0);
1184 ASSERT_VK_SUCCESS(err);
1185
1186 VkImageViewCreateInfo image_view_create_info = {};
1187 image_view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
1188 image_view_create_info.image = image;
1189 image_view_create_info.viewType = VK_IMAGE_VIEW_TYPE_2D;
1190 image_view_create_info.format = tex_format;
1191 image_view_create_info.subresourceRange.layerCount = 1;
1192 image_view_create_info.subresourceRange.baseMipLevel = 0;
1193 image_view_create_info.subresourceRange.levelCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001194 image_view_create_info.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Dustin Graves40f35822016-06-23 11:12:53 -06001195
1196 VkImageView view;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001197 err = vkCreateImageView(m_device->device(), &image_view_create_info, NULL, &view);
Dustin Graves40f35822016-06-23 11:12:53 -06001198 ASSERT_VK_SUCCESS(err);
1199
1200 VkDescriptorPoolSize ds_type_count = {};
1201 ds_type_count.type = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE;
1202 ds_type_count.descriptorCount = 1;
1203
1204 VkDescriptorPoolCreateInfo ds_pool_ci = {};
1205 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
1206 ds_pool_ci.pNext = NULL;
1207 ds_pool_ci.maxSets = 1;
1208 ds_pool_ci.poolSizeCount = 1;
1209 ds_pool_ci.pPoolSizes = &ds_type_count;
1210
1211 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001212 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Dustin Graves40f35822016-06-23 11:12:53 -06001213 ASSERT_VK_SUCCESS(err);
1214
1215 VkDescriptorSetLayoutBinding dsl_binding = {};
1216 dsl_binding.binding = 0;
1217 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE;
1218 dsl_binding.descriptorCount = 1;
1219 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
1220 dsl_binding.pImmutableSamplers = NULL;
1221
1222 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001223 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
Dustin Graves40f35822016-06-23 11:12:53 -06001224 ds_layout_ci.pNext = NULL;
1225 ds_layout_ci.bindingCount = 1;
1226 ds_layout_ci.pBindings = &dsl_binding;
1227 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001228 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Dustin Graves40f35822016-06-23 11:12:53 -06001229 ASSERT_VK_SUCCESS(err);
1230
1231 VkDescriptorSet descriptor_set;
1232 VkDescriptorSetAllocateInfo alloc_info = {};
1233 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
1234 alloc_info.descriptorSetCount = 1;
1235 alloc_info.descriptorPool = ds_pool;
1236 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001237 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
Dustin Graves40f35822016-06-23 11:12:53 -06001238 ASSERT_VK_SUCCESS(err);
1239
1240 VkDescriptorImageInfo image_info = {};
1241 image_info.imageView = view;
1242 image_info.imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
1243
1244 VkWriteDescriptorSet descriptor_write;
1245 memset(&descriptor_write, 0, sizeof(descriptor_write));
1246 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
1247 descriptor_write.dstSet = descriptor_set;
1248 descriptor_write.dstBinding = 0;
1249 descriptor_write.descriptorCount = 1;
1250 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE;
1251 descriptor_write.pImageInfo = &image_info;
1252
1253 // Set pBufferInfo and pTexelBufferView to invalid values, which should
1254 // be
1255 // ignored for descriptorType == VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE.
1256 // This will most likely produce a crash if the parameter_validation
1257 // layer
1258 // does not correctly ignore pBufferInfo.
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001259 descriptor_write.pBufferInfo = reinterpret_cast<const VkDescriptorBufferInfo *>(invalid_ptr);
1260 descriptor_write.pTexelBufferView = reinterpret_cast<const VkBufferView *>(invalid_ptr);
Dustin Graves40f35822016-06-23 11:12:53 -06001261
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001262 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
Dustin Graves40f35822016-06-23 11:12:53 -06001263
1264 m_errorMonitor->VerifyNotFound();
1265
Dustin Graves40f35822016-06-23 11:12:53 -06001266 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
1267 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
1268 vkDestroyImageView(m_device->device(), view, NULL);
1269 vkDestroyImage(m_device->device(), image, NULL);
1270 vkFreeMemory(m_device->device(), image_memory, NULL);
1271 }
1272
1273 // Buffer Case
1274 {
1275 m_errorMonitor->ExpectSuccess();
1276
1277 VkBuffer buffer;
1278 uint32_t queue_family_index = 0;
1279 VkBufferCreateInfo buffer_create_info = {};
1280 buffer_create_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
1281 buffer_create_info.size = 1024;
1282 buffer_create_info.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
1283 buffer_create_info.queueFamilyIndexCount = 1;
1284 buffer_create_info.pQueueFamilyIndices = &queue_family_index;
1285
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001286 VkResult err = vkCreateBuffer(m_device->device(), &buffer_create_info, NULL, &buffer);
Dustin Graves40f35822016-06-23 11:12:53 -06001287 ASSERT_VK_SUCCESS(err);
1288
1289 VkMemoryRequirements memory_reqs;
1290 VkDeviceMemory buffer_memory;
1291 bool pass;
1292 VkMemoryAllocateInfo memory_info = {};
1293 memory_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
1294 memory_info.pNext = NULL;
1295 memory_info.allocationSize = 0;
1296 memory_info.memoryTypeIndex = 0;
1297
1298 vkGetBufferMemoryRequirements(m_device->device(), buffer, &memory_reqs);
1299 memory_info.allocationSize = memory_reqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001300 pass = m_device->phy().set_memory_type(memory_reqs.memoryTypeBits, &memory_info, 0);
Dustin Graves40f35822016-06-23 11:12:53 -06001301 ASSERT_TRUE(pass);
1302
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001303 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &buffer_memory);
Dustin Graves40f35822016-06-23 11:12:53 -06001304 ASSERT_VK_SUCCESS(err);
1305 err = vkBindBufferMemory(m_device->device(), buffer, buffer_memory, 0);
1306 ASSERT_VK_SUCCESS(err);
1307
1308 VkDescriptorPoolSize ds_type_count = {};
1309 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
1310 ds_type_count.descriptorCount = 1;
1311
1312 VkDescriptorPoolCreateInfo ds_pool_ci = {};
1313 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
1314 ds_pool_ci.pNext = NULL;
1315 ds_pool_ci.maxSets = 1;
1316 ds_pool_ci.poolSizeCount = 1;
1317 ds_pool_ci.pPoolSizes = &ds_type_count;
1318
1319 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001320 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Dustin Graves40f35822016-06-23 11:12:53 -06001321 ASSERT_VK_SUCCESS(err);
1322
1323 VkDescriptorSetLayoutBinding dsl_binding = {};
1324 dsl_binding.binding = 0;
1325 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
1326 dsl_binding.descriptorCount = 1;
1327 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
1328 dsl_binding.pImmutableSamplers = NULL;
1329
1330 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001331 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
Dustin Graves40f35822016-06-23 11:12:53 -06001332 ds_layout_ci.pNext = NULL;
1333 ds_layout_ci.bindingCount = 1;
1334 ds_layout_ci.pBindings = &dsl_binding;
1335 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001336 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Dustin Graves40f35822016-06-23 11:12:53 -06001337 ASSERT_VK_SUCCESS(err);
1338
1339 VkDescriptorSet descriptor_set;
1340 VkDescriptorSetAllocateInfo alloc_info = {};
1341 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
1342 alloc_info.descriptorSetCount = 1;
1343 alloc_info.descriptorPool = ds_pool;
1344 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001345 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
Dustin Graves40f35822016-06-23 11:12:53 -06001346 ASSERT_VK_SUCCESS(err);
1347
1348 VkDescriptorBufferInfo buffer_info = {};
1349 buffer_info.buffer = buffer;
1350 buffer_info.offset = 0;
1351 buffer_info.range = 1024;
1352
1353 VkWriteDescriptorSet descriptor_write;
1354 memset(&descriptor_write, 0, sizeof(descriptor_write));
1355 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
1356 descriptor_write.dstSet = descriptor_set;
1357 descriptor_write.dstBinding = 0;
1358 descriptor_write.descriptorCount = 1;
1359 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
1360 descriptor_write.pBufferInfo = &buffer_info;
1361
1362 // Set pImageInfo and pTexelBufferView to invalid values, which should
1363 // be
1364 // ignored for descriptorType == VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER.
1365 // This will most likely produce a crash if the parameter_validation
1366 // layer
1367 // does not correctly ignore pImageInfo.
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001368 descriptor_write.pImageInfo = reinterpret_cast<const VkDescriptorImageInfo *>(invalid_ptr);
1369 descriptor_write.pTexelBufferView = reinterpret_cast<const VkBufferView *>(invalid_ptr);
Dustin Graves40f35822016-06-23 11:12:53 -06001370
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001371 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
Dustin Graves40f35822016-06-23 11:12:53 -06001372
1373 m_errorMonitor->VerifyNotFound();
1374
1375 vkFreeDescriptorSets(m_device->device(), ds_pool, 1, &descriptor_set);
1376 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
1377 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
1378 vkDestroyBuffer(m_device->device(), buffer, NULL);
1379 vkFreeMemory(m_device->device(), buffer_memory, NULL);
1380 }
1381
1382 // Texel Buffer Case
1383 {
1384 m_errorMonitor->ExpectSuccess();
1385
1386 VkBuffer buffer;
1387 uint32_t queue_family_index = 0;
1388 VkBufferCreateInfo buffer_create_info = {};
1389 buffer_create_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
1390 buffer_create_info.size = 1024;
1391 buffer_create_info.usage = VK_BUFFER_USAGE_STORAGE_TEXEL_BUFFER_BIT;
1392 buffer_create_info.queueFamilyIndexCount = 1;
1393 buffer_create_info.pQueueFamilyIndices = &queue_family_index;
1394
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001395 VkResult err = vkCreateBuffer(m_device->device(), &buffer_create_info, NULL, &buffer);
Dustin Graves40f35822016-06-23 11:12:53 -06001396 ASSERT_VK_SUCCESS(err);
1397
1398 VkMemoryRequirements memory_reqs;
1399 VkDeviceMemory buffer_memory;
1400 bool pass;
1401 VkMemoryAllocateInfo memory_info = {};
1402 memory_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
1403 memory_info.pNext = NULL;
1404 memory_info.allocationSize = 0;
1405 memory_info.memoryTypeIndex = 0;
1406
1407 vkGetBufferMemoryRequirements(m_device->device(), buffer, &memory_reqs);
1408 memory_info.allocationSize = memory_reqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001409 pass = m_device->phy().set_memory_type(memory_reqs.memoryTypeBits, &memory_info, 0);
Dustin Graves40f35822016-06-23 11:12:53 -06001410 ASSERT_TRUE(pass);
1411
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001412 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &buffer_memory);
Dustin Graves40f35822016-06-23 11:12:53 -06001413 ASSERT_VK_SUCCESS(err);
1414 err = vkBindBufferMemory(m_device->device(), buffer, buffer_memory, 0);
1415 ASSERT_VK_SUCCESS(err);
1416
1417 VkBufferViewCreateInfo buff_view_ci = {};
1418 buff_view_ci.sType = VK_STRUCTURE_TYPE_BUFFER_VIEW_CREATE_INFO;
1419 buff_view_ci.buffer = buffer;
1420 buff_view_ci.format = VK_FORMAT_R8_UNORM;
1421 buff_view_ci.range = VK_WHOLE_SIZE;
1422 VkBufferView buffer_view;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001423 err = vkCreateBufferView(m_device->device(), &buff_view_ci, NULL, &buffer_view);
Dustin Graves40f35822016-06-23 11:12:53 -06001424
1425 VkDescriptorPoolSize ds_type_count = {};
1426 ds_type_count.type = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
1427 ds_type_count.descriptorCount = 1;
1428
1429 VkDescriptorPoolCreateInfo ds_pool_ci = {};
1430 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
1431 ds_pool_ci.pNext = NULL;
1432 ds_pool_ci.maxSets = 1;
1433 ds_pool_ci.poolSizeCount = 1;
1434 ds_pool_ci.pPoolSizes = &ds_type_count;
1435
1436 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001437 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Dustin Graves40f35822016-06-23 11:12:53 -06001438 ASSERT_VK_SUCCESS(err);
1439
1440 VkDescriptorSetLayoutBinding dsl_binding = {};
1441 dsl_binding.binding = 0;
1442 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
1443 dsl_binding.descriptorCount = 1;
1444 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
1445 dsl_binding.pImmutableSamplers = NULL;
1446
1447 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001448 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
Dustin Graves40f35822016-06-23 11:12:53 -06001449 ds_layout_ci.pNext = NULL;
1450 ds_layout_ci.bindingCount = 1;
1451 ds_layout_ci.pBindings = &dsl_binding;
1452 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001453 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Dustin Graves40f35822016-06-23 11:12:53 -06001454 ASSERT_VK_SUCCESS(err);
1455
1456 VkDescriptorSet descriptor_set;
1457 VkDescriptorSetAllocateInfo alloc_info = {};
1458 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
1459 alloc_info.descriptorSetCount = 1;
1460 alloc_info.descriptorPool = ds_pool;
1461 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001462 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
Dustin Graves40f35822016-06-23 11:12:53 -06001463 ASSERT_VK_SUCCESS(err);
1464
1465 VkWriteDescriptorSet descriptor_write;
1466 memset(&descriptor_write, 0, sizeof(descriptor_write));
1467 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
1468 descriptor_write.dstSet = descriptor_set;
1469 descriptor_write.dstBinding = 0;
1470 descriptor_write.descriptorCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001471 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
Dustin Graves40f35822016-06-23 11:12:53 -06001472 descriptor_write.pTexelBufferView = &buffer_view;
1473
1474 // Set pImageInfo and pBufferInfo to invalid values, which should be
1475 // ignored for descriptorType ==
1476 // VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER.
1477 // This will most likely produce a crash if the parameter_validation
1478 // layer
1479 // does not correctly ignore pImageInfo and pBufferInfo.
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001480 descriptor_write.pImageInfo = reinterpret_cast<const VkDescriptorImageInfo *>(invalid_ptr);
1481 descriptor_write.pBufferInfo = reinterpret_cast<const VkDescriptorBufferInfo *>(invalid_ptr);
Dustin Graves40f35822016-06-23 11:12:53 -06001482
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001483 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
Dustin Graves40f35822016-06-23 11:12:53 -06001484
1485 m_errorMonitor->VerifyNotFound();
1486
1487 vkFreeDescriptorSets(m_device->device(), ds_pool, 1, &descriptor_set);
1488 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
1489 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
1490 vkDestroyBufferView(m_device->device(), buffer_view, NULL);
1491 vkDestroyBuffer(m_device->device(), buffer, NULL);
1492 vkFreeMemory(m_device->device(), buffer_memory, NULL);
1493 }
1494}
Cortd889ff92016-07-27 09:51:27 -07001495
1496TEST_F(VkLayerTest, PSOPolygonModeInvalid) {
1497 VkResult err;
1498
1499 TEST_DESCRIPTION("Attempt to use a non-solid polygon fill mode in a "
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001500 "pipeline when this feature is not enabled.");
Cortd889ff92016-07-27 09:51:27 -07001501
1502 ASSERT_NO_FATAL_FAILURE(InitState());
1503 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
1504
1505 std::vector<const char *> device_extension_names;
1506 auto features = m_device->phy().features();
1507 // Artificially disable support for non-solid fill modes
1508 features.fillModeNonSolid = false;
1509 // The sacrificial device object
1510 VkDeviceObj test_device(0, gpu(), device_extension_names, &features);
1511
1512 VkRenderpassObj render_pass(&test_device);
1513
1514 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
1515 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
1516 pipeline_layout_ci.setLayoutCount = 0;
1517 pipeline_layout_ci.pSetLayouts = NULL;
1518
1519 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001520 err = vkCreatePipelineLayout(test_device.device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Cortd889ff92016-07-27 09:51:27 -07001521 ASSERT_VK_SUCCESS(err);
1522
1523 VkPipelineRasterizationStateCreateInfo rs_ci = {};
1524 rs_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
1525 rs_ci.pNext = nullptr;
1526 rs_ci.lineWidth = 1.0f;
1527 rs_ci.rasterizerDiscardEnable = true;
1528
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001529 VkShaderObj vs(&test_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
1530 VkShaderObj fs(&test_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Cortd889ff92016-07-27 09:51:27 -07001531
Mark Lobodzinski5e644732016-08-15 16:51:19 -06001532 // Set polygonMode to unsupported value POINT, should fail
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001533 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
1534 "polygonMode cannot be VK_POLYGON_MODE_POINT or VK_POLYGON_MODE_LINE");
Cortd889ff92016-07-27 09:51:27 -07001535 {
1536 VkPipelineObj pipe(&test_device);
1537 pipe.AddShader(&vs);
1538 pipe.AddShader(&fs);
1539 pipe.AddColorAttachment();
1540 // Introduce failure by setting unsupported polygon mode
1541 rs_ci.polygonMode = VK_POLYGON_MODE_POINT;
1542 pipe.SetRasterization(&rs_ci);
1543 pipe.CreateVKPipeline(pipeline_layout, render_pass.handle());
1544 }
1545 m_errorMonitor->VerifyFound();
1546
1547 // Try again with polygonMode=LINE, should fail
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001548 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
1549 "polygonMode cannot be VK_POLYGON_MODE_POINT or VK_POLYGON_MODE_LINE");
Cortd889ff92016-07-27 09:51:27 -07001550 {
1551 VkPipelineObj pipe(&test_device);
1552 pipe.AddShader(&vs);
1553 pipe.AddShader(&fs);
1554 pipe.AddColorAttachment();
1555 // Introduce failure by setting unsupported polygon mode
1556 rs_ci.polygonMode = VK_POLYGON_MODE_LINE;
1557 pipe.SetRasterization(&rs_ci);
1558 pipe.CreateVKPipeline(pipeline_layout, render_pass.handle());
1559 }
1560 m_errorMonitor->VerifyFound();
1561
1562 // Try again with polygonMode=FILL. No error is expected
1563 m_errorMonitor->ExpectSuccess();
1564 {
1565 VkPipelineObj pipe(&test_device);
1566 pipe.AddShader(&vs);
1567 pipe.AddShader(&fs);
1568 pipe.AddColorAttachment();
1569 // Set polygonMode to a good value
1570 rs_ci.polygonMode = VK_POLYGON_MODE_FILL;
1571 pipe.SetRasterization(&rs_ci);
1572 pipe.CreateVKPipeline(pipeline_layout, render_pass.handle());
1573 }
1574 m_errorMonitor->VerifyNotFound();
1575
1576 vkDestroyPipelineLayout(test_device.device(), pipeline_layout, NULL);
1577}
1578
Dustin Gravesffa90fa2016-05-06 11:20:38 -06001579#endif // PARAMETER_VALIDATION_TESTS
1580
Tobin Ehlis0788f522015-05-26 16:11:58 -06001581#if MEM_TRACKER_TESTS
Tobin Ehlis8fab6562015-12-01 09:57:09 -07001582#if 0
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001583TEST_F(VkLayerTest, CallResetCommandBufferBeforeCompletion)
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001584{
1585 vk_testing::Fence testFence;
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001586 VkFenceCreateInfo fenceInfo = {};
1587 fenceInfo.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
1588 fenceInfo.pNext = NULL;
1589 fenceInfo.flags = 0;
1590
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07001591 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Resetting CB");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06001592
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001593 ASSERT_NO_FATAL_FAILURE(InitState());
Tony Barbourc1eb1a52015-07-20 13:00:10 -06001594
1595 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
1596 vk_testing::Buffer buffer;
1597 buffer.init_as_dst(*m_device, (VkDeviceSize)20, reqs);
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001598
Tony Barbourfe3351b2015-07-28 10:17:20 -06001599 BeginCommandBuffer();
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001600 m_commandBuffer->FillBuffer(buffer.handle(), 0, 4, 0x11111111);
Tony Barbourfe3351b2015-07-28 10:17:20 -06001601 EndCommandBuffer();
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001602
1603 testFence.init(*m_device, fenceInfo);
1604
1605 // Bypass framework since it does the waits automatically
1606 VkResult err = VK_SUCCESS;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06001607 VkSubmitInfo submit_info;
Chia-I Wuf9be13c2015-10-26 20:37:06 +08001608 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
1609 submit_info.pNext = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08001610 submit_info.waitSemaphoreCount = 0;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06001611 submit_info.pWaitSemaphores = NULL;
Jon Ashburn7f9716c2015-12-30 16:42:50 -07001612 submit_info.pWaitDstStageMask = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08001613 submit_info.commandBufferCount = 1;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001614 submit_info.pCommandBuffers = &m_commandBuffer->handle();
Chia-I Wud50a7d72015-10-26 20:48:51 +08001615 submit_info.signalSemaphoreCount = 0;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06001616 submit_info.pSignalSemaphores = NULL;
Courtney Goeltzenleuchter646b9072015-10-20 18:04:07 -06001617
1618 err = vkQueueSubmit( m_device->m_queue, 1, &submit_info, testFence.handle());
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001619 ASSERT_VK_SUCCESS( err );
1620
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001621 // Introduce failure by calling begin again before checking fence
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001622 vkResetCommandBuffer(m_commandBuffer->handle(), 0);
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001623
Chris Forbes8f36a8a2016-04-07 13:21:07 +12001624 m_errorMonitor->VerifyFound();
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001625}
1626
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001627TEST_F(VkLayerTest, CallBeginCommandBufferBeforeCompletion)
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001628{
1629 vk_testing::Fence testFence;
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001630 VkFenceCreateInfo fenceInfo = {};
1631 fenceInfo.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
1632 fenceInfo.pNext = NULL;
1633 fenceInfo.flags = 0;
1634
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07001635 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Calling vkBeginCommandBuffer() on active CB");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06001636
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001637 ASSERT_NO_FATAL_FAILURE(InitState());
1638 ASSERT_NO_FATAL_FAILURE(InitViewport());
1639 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
1640
Tony Barbourfe3351b2015-07-28 10:17:20 -06001641 BeginCommandBuffer();
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001642 m_commandBuffer->ClearAllBuffers(m_clear_color, m_depth_clear_color, m_stencil_clear_color, NULL);
Tony Barbourfe3351b2015-07-28 10:17:20 -06001643 EndCommandBuffer();
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001644
1645 testFence.init(*m_device, fenceInfo);
1646
1647 // Bypass framework since it does the waits automatically
1648 VkResult err = VK_SUCCESS;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06001649 VkSubmitInfo submit_info;
Chia-I Wuf9be13c2015-10-26 20:37:06 +08001650 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
1651 submit_info.pNext = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08001652 submit_info.waitSemaphoreCount = 0;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06001653 submit_info.pWaitSemaphores = NULL;
Jon Ashburn7f9716c2015-12-30 16:42:50 -07001654 submit_info.pWaitDstStageMask = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08001655 submit_info.commandBufferCount = 1;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001656 submit_info.pCommandBuffers = &m_commandBuffer->handle();
Chia-I Wud50a7d72015-10-26 20:48:51 +08001657 submit_info.signalSemaphoreCount = 0;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06001658 submit_info.pSignalSemaphores = NULL;
Courtney Goeltzenleuchter646b9072015-10-20 18:04:07 -06001659
1660 err = vkQueueSubmit( m_device->m_queue, 1, &submit_info, testFence.handle());
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001661 ASSERT_VK_SUCCESS( err );
1662
Jon Ashburnf19916e2016-01-11 13:12:43 -07001663 VkCommandBufferInheritanceInfo hinfo = {};
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001664 VkCommandBufferBeginInfo info = {};
1665 info.flags = VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT;
1666 info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
Mark Lobodzinski5fcc4212015-09-14 17:43:42 -06001667 info.renderPass = VK_NULL_HANDLE;
1668 info.subpass = 0;
1669 info.framebuffer = VK_NULL_HANDLE;
Chia-I Wub8d47ae2015-11-11 10:18:12 +08001670 info.occlusionQueryEnable = VK_FALSE;
1671 info.queryFlags = 0;
1672 info.pipelineStatistics = 0;
Mark Lobodzinski5fcc4212015-09-14 17:43:42 -06001673
1674 // Introduce failure by calling BCB again before checking fence
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001675 vkBeginCommandBuffer(m_commandBuffer->handle(), &info);
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001676
Chris Forbes8f36a8a2016-04-07 13:21:07 +12001677 m_errorMonitor->VerifyFound();
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001678}
Tobin Ehlis8fab6562015-12-01 09:57:09 -07001679#endif
Chris Forbes8f36a8a2016-04-07 13:21:07 +12001680
Mark Lobodzinski152fe252016-05-03 16:49:15 -06001681// This is a positive test. No failures are expected.
1682TEST_F(VkLayerTest, TestAliasedMemoryTracking) {
1683 VkResult err;
1684 bool pass;
1685
1686 TEST_DESCRIPTION("Create a buffer, allocate memory, bind memory, destroy "
1687 "the buffer, create an image, and bind the same memory to "
1688 "it");
1689
1690 m_errorMonitor->ExpectSuccess();
1691
1692 ASSERT_NO_FATAL_FAILURE(InitState());
1693
1694 VkBuffer buffer;
1695 VkImage image;
1696 VkDeviceMemory mem;
1697 VkMemoryRequirements mem_reqs;
1698
1699 VkBufferCreateInfo buf_info = {};
1700 buf_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
1701 buf_info.pNext = NULL;
1702 buf_info.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
1703 buf_info.size = 256;
1704 buf_info.queueFamilyIndexCount = 0;
1705 buf_info.pQueueFamilyIndices = NULL;
1706 buf_info.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
1707 buf_info.flags = 0;
1708 err = vkCreateBuffer(m_device->device(), &buf_info, NULL, &buffer);
1709 ASSERT_VK_SUCCESS(err);
1710
1711 vkGetBufferMemoryRequirements(m_device->device(), buffer, &mem_reqs);
1712
1713 VkMemoryAllocateInfo alloc_info = {};
1714 alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
1715 alloc_info.pNext = NULL;
1716 alloc_info.memoryTypeIndex = 0;
1717
1718 // Ensure memory is big enough for both bindings
1719 alloc_info.allocationSize = 0x10000;
1720
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001721 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 -06001722 if (!pass) {
1723 vkDestroyBuffer(m_device->device(), buffer, NULL);
1724 return;
1725 }
1726
1727 err = vkAllocateMemory(m_device->device(), &alloc_info, NULL, &mem);
1728 ASSERT_VK_SUCCESS(err);
1729
1730 uint8_t *pData;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001731 err = vkMapMemory(m_device->device(), mem, 0, mem_reqs.size, 0, (void **)&pData);
Mark Lobodzinski152fe252016-05-03 16:49:15 -06001732 ASSERT_VK_SUCCESS(err);
1733
Mark Lobodzinski2abefa92016-05-05 11:45:57 -06001734 memset(pData, 0xCADECADE, static_cast<size_t>(mem_reqs.size));
Mark Lobodzinski152fe252016-05-03 16:49:15 -06001735
1736 vkUnmapMemory(m_device->device(), mem);
1737
1738 err = vkBindBufferMemory(m_device->device(), buffer, mem, 0);
1739 ASSERT_VK_SUCCESS(err);
1740
1741 // NOW, destroy the buffer. Obviously, the resource no longer occupies this
1742 // memory. In fact, it was never used by the GPU.
1743 // Just be be sure, wait for idle.
1744 vkDestroyBuffer(m_device->device(), buffer, NULL);
1745 vkDeviceWaitIdle(m_device->device());
1746
1747 VkImageCreateInfo image_create_info = {};
1748 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
1749 image_create_info.pNext = NULL;
1750 image_create_info.imageType = VK_IMAGE_TYPE_2D;
1751 image_create_info.format = VK_FORMAT_R8G8B8A8_UNORM;
1752 image_create_info.extent.width = 64;
1753 image_create_info.extent.height = 64;
1754 image_create_info.extent.depth = 1;
1755 image_create_info.mipLevels = 1;
1756 image_create_info.arrayLayers = 1;
1757 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
1758 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
1759 image_create_info.initialLayout = VK_IMAGE_LAYOUT_PREINITIALIZED;
1760 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
1761 image_create_info.queueFamilyIndexCount = 0;
1762 image_create_info.pQueueFamilyIndices = NULL;
1763 image_create_info.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
1764 image_create_info.flags = 0;
1765
1766 VkMemoryAllocateInfo mem_alloc = {};
1767 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
1768 mem_alloc.pNext = NULL;
1769 mem_alloc.allocationSize = 0;
1770 mem_alloc.memoryTypeIndex = 0;
1771
1772 /* Create a mappable image. It will be the texture if linear images are ok
1773 * to be textures or it will be the staging image if they are not.
1774 */
1775 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
1776 ASSERT_VK_SUCCESS(err);
1777
1778 vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs);
1779
1780 mem_alloc.allocationSize = mem_reqs.size;
1781
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001782 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 -06001783 if (!pass) {
1784 vkDestroyImage(m_device->device(), image, NULL);
1785 return;
1786 }
1787
Tobin Ehlis077ded32016-05-12 17:39:13 -06001788 // VALIDATION FAILURE:
Mark Lobodzinski152fe252016-05-03 16:49:15 -06001789 err = vkBindImageMemory(m_device->device(), image, mem, 0);
1790 ASSERT_VK_SUCCESS(err);
1791
1792 m_errorMonitor->VerifyNotFound();
1793
Tony Barbourdf4c0042016-06-01 15:55:43 -06001794 vkFreeMemory(m_device->device(), mem, NULL);
Mark Lobodzinski152fe252016-05-03 16:49:15 -06001795 vkDestroyBuffer(m_device->device(), buffer, NULL);
1796 vkDestroyImage(m_device->device(), image, NULL);
1797}
1798
Tobin Ehlisf11be982016-05-11 13:52:53 -06001799TEST_F(VkLayerTest, InvalidMemoryAliasing) {
1800 TEST_DESCRIPTION("Create a buffer and image, allocate memory, and bind the "
1801 "buffer and image to memory such that they will alias.");
1802 VkResult err;
1803 bool pass;
1804 ASSERT_NO_FATAL_FAILURE(InitState());
1805
Tobin Ehlis077ded32016-05-12 17:39:13 -06001806 VkBuffer buffer, buffer2;
Tobin Ehlisf11be982016-05-11 13:52:53 -06001807 VkImage image;
1808 VkDeviceMemory mem; // buffer will be bound first
1809 VkDeviceMemory mem_img; // image bound first
Tobin Ehlis077ded32016-05-12 17:39:13 -06001810 VkMemoryRequirements buff_mem_reqs, img_mem_reqs;
Tobin Ehlisf11be982016-05-11 13:52:53 -06001811
1812 VkBufferCreateInfo buf_info = {};
1813 buf_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
1814 buf_info.pNext = NULL;
1815 buf_info.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
1816 buf_info.size = 256;
1817 buf_info.queueFamilyIndexCount = 0;
1818 buf_info.pQueueFamilyIndices = NULL;
1819 buf_info.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
1820 buf_info.flags = 0;
1821 err = vkCreateBuffer(m_device->device(), &buf_info, NULL, &buffer);
1822 ASSERT_VK_SUCCESS(err);
1823
Tobin Ehlis077ded32016-05-12 17:39:13 -06001824 vkGetBufferMemoryRequirements(m_device->device(), buffer, &buff_mem_reqs);
Tobin Ehlisf11be982016-05-11 13:52:53 -06001825
1826 VkImageCreateInfo image_create_info = {};
1827 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
1828 image_create_info.pNext = NULL;
1829 image_create_info.imageType = VK_IMAGE_TYPE_2D;
1830 image_create_info.format = VK_FORMAT_R8G8B8A8_UNORM;
1831 image_create_info.extent.width = 64;
1832 image_create_info.extent.height = 64;
1833 image_create_info.extent.depth = 1;
1834 image_create_info.mipLevels = 1;
1835 image_create_info.arrayLayers = 1;
1836 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
Tobin Ehlis12a4b5e2016-08-08 12:33:11 -06001837 // Image tiling must be optimal to trigger error when aliasing linear buffer
1838 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
Tobin Ehlisf11be982016-05-11 13:52:53 -06001839 image_create_info.initialLayout = VK_IMAGE_LAYOUT_PREINITIALIZED;
1840 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
1841 image_create_info.queueFamilyIndexCount = 0;
1842 image_create_info.pQueueFamilyIndices = NULL;
1843 image_create_info.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
1844 image_create_info.flags = 0;
1845
Tobin Ehlisf11be982016-05-11 13:52:53 -06001846 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
1847 ASSERT_VK_SUCCESS(err);
1848
Tobin Ehlis077ded32016-05-12 17:39:13 -06001849 vkGetImageMemoryRequirements(m_device->device(), image, &img_mem_reqs);
1850
1851 VkMemoryAllocateInfo alloc_info = {};
1852 alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
1853 alloc_info.pNext = NULL;
1854 alloc_info.memoryTypeIndex = 0;
1855 // Ensure memory is big enough for both bindings
1856 alloc_info.allocationSize = buff_mem_reqs.size + img_mem_reqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001857 pass = m_device->phy().set_memory_type(buff_mem_reqs.memoryTypeBits & img_mem_reqs.memoryTypeBits, &alloc_info,
1858 VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT);
Tobin Ehlisf11be982016-05-11 13:52:53 -06001859 if (!pass) {
Tobin Ehlis077ded32016-05-12 17:39:13 -06001860 vkDestroyBuffer(m_device->device(), buffer, NULL);
Tobin Ehlisf11be982016-05-11 13:52:53 -06001861 vkDestroyImage(m_device->device(), image, NULL);
1862 return;
1863 }
Tobin Ehlis077ded32016-05-12 17:39:13 -06001864 err = vkAllocateMemory(m_device->device(), &alloc_info, NULL, &mem);
1865 ASSERT_VK_SUCCESS(err);
1866 err = vkBindBufferMemory(m_device->device(), buffer, mem, 0);
1867 ASSERT_VK_SUCCESS(err);
1868
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001869 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " is aliased with linear buffer 0x");
Tobin Ehlis077ded32016-05-12 17:39:13 -06001870 // VALIDATION FAILURE due to image mapping overlapping buffer mapping
Tobin Ehlisf11be982016-05-11 13:52:53 -06001871 err = vkBindImageMemory(m_device->device(), image, mem, 0);
1872 m_errorMonitor->VerifyFound();
1873
1874 // Now correctly bind image to second mem allocation before incorrectly
Tobin Ehlis077ded32016-05-12 17:39:13 -06001875 // aliasing buffer2
1876 err = vkCreateBuffer(m_device->device(), &buf_info, NULL, &buffer2);
1877 ASSERT_VK_SUCCESS(err);
Tobin Ehlisf11be982016-05-11 13:52:53 -06001878 err = vkAllocateMemory(m_device->device(), &alloc_info, NULL, &mem_img);
1879 ASSERT_VK_SUCCESS(err);
1880 err = vkBindImageMemory(m_device->device(), image, mem_img, 0);
1881 ASSERT_VK_SUCCESS(err);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001882 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "is aliased with non-linear image 0x");
Tobin Ehlis077ded32016-05-12 17:39:13 -06001883 err = vkBindBufferMemory(m_device->device(), buffer2, mem_img, 0);
Tobin Ehlisf11be982016-05-11 13:52:53 -06001884 m_errorMonitor->VerifyFound();
1885
1886 vkDestroyBuffer(m_device->device(), buffer, NULL);
Tobin Ehlis077ded32016-05-12 17:39:13 -06001887 vkDestroyBuffer(m_device->device(), buffer2, NULL);
Tobin Ehlisf11be982016-05-11 13:52:53 -06001888 vkDestroyImage(m_device->device(), image, NULL);
1889 vkFreeMemory(m_device->device(), mem, NULL);
1890 vkFreeMemory(m_device->device(), mem_img, NULL);
1891}
1892
Tobin Ehlis35372522016-05-12 08:32:31 -06001893TEST_F(VkLayerTest, InvalidMemoryMapping) {
1894 TEST_DESCRIPTION("Attempt to map memory in a number of incorrect ways");
1895 VkResult err;
1896 bool pass;
1897 ASSERT_NO_FATAL_FAILURE(InitState());
1898
1899 VkBuffer buffer;
1900 VkDeviceMemory mem;
1901 VkMemoryRequirements mem_reqs;
1902
1903 VkBufferCreateInfo buf_info = {};
1904 buf_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
1905 buf_info.pNext = NULL;
1906 buf_info.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
1907 buf_info.size = 256;
1908 buf_info.queueFamilyIndexCount = 0;
1909 buf_info.pQueueFamilyIndices = NULL;
1910 buf_info.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
1911 buf_info.flags = 0;
1912 err = vkCreateBuffer(m_device->device(), &buf_info, NULL, &buffer);
1913 ASSERT_VK_SUCCESS(err);
1914
1915 vkGetBufferMemoryRequirements(m_device->device(), buffer, &mem_reqs);
1916 VkMemoryAllocateInfo alloc_info = {};
1917 alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
1918 alloc_info.pNext = NULL;
1919 alloc_info.memoryTypeIndex = 0;
1920
1921 // Ensure memory is big enough for both bindings
1922 static const VkDeviceSize allocation_size = 0x10000;
1923 alloc_info.allocationSize = allocation_size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001924 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 -06001925 if (!pass) {
1926 vkDestroyBuffer(m_device->device(), buffer, NULL);
1927 return;
1928 }
1929 err = vkAllocateMemory(m_device->device(), &alloc_info, NULL, &mem);
1930 ASSERT_VK_SUCCESS(err);
1931
1932 uint8_t *pData;
1933 // Attempt to map memory size 0 is invalid
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001934 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 -06001935 err = vkMapMemory(m_device->device(), mem, 0, 0, 0, (void **)&pData);
1936 m_errorMonitor->VerifyFound();
1937 // Map memory twice
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001938 err = vkMapMemory(m_device->device(), mem, 0, mem_reqs.size, 0, (void **)&pData);
Tobin Ehlis35372522016-05-12 08:32:31 -06001939 ASSERT_VK_SUCCESS(err);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001940 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
1941 "VkMapMemory: Attempting to map memory on an already-mapped object ");
1942 err = vkMapMemory(m_device->device(), mem, 0, mem_reqs.size, 0, (void **)&pData);
Tobin Ehlis35372522016-05-12 08:32:31 -06001943 m_errorMonitor->VerifyFound();
1944
1945 // Unmap the memory to avoid re-map error
1946 vkUnmapMemory(m_device->device(), mem);
1947 // overstep allocation with VK_WHOLE_SIZE
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001948 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
1949 " with size of VK_WHOLE_SIZE oversteps total array size 0x");
1950 err = vkMapMemory(m_device->device(), mem, allocation_size + 1, VK_WHOLE_SIZE, 0, (void **)&pData);
Tobin Ehlis35372522016-05-12 08:32:31 -06001951 m_errorMonitor->VerifyFound();
1952 // overstep allocation w/o VK_WHOLE_SIZE
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001953 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " oversteps total array size 0x");
1954 err = vkMapMemory(m_device->device(), mem, 1, allocation_size, 0, (void **)&pData);
Tobin Ehlis35372522016-05-12 08:32:31 -06001955 m_errorMonitor->VerifyFound();
1956 // Now error due to unmapping memory that's not mapped
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001957 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Unmapping Memory without memory being mapped: ");
Tobin Ehlis35372522016-05-12 08:32:31 -06001958 vkUnmapMemory(m_device->device(), mem);
1959 m_errorMonitor->VerifyFound();
1960 // Now map memory and cause errors due to flushing invalid ranges
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001961 err = vkMapMemory(m_device->device(), mem, 16, VK_WHOLE_SIZE, 0, (void **)&pData);
Tobin Ehlis35372522016-05-12 08:32:31 -06001962 ASSERT_VK_SUCCESS(err);
1963 VkMappedMemoryRange mmr = {};
Chris Forbes3aec0892016-06-13 10:29:26 +12001964 mmr.sType = VK_STRUCTURE_TYPE_MAPPED_MEMORY_RANGE;
Tobin Ehlis35372522016-05-12 08:32:31 -06001965 mmr.memory = mem;
1966 mmr.offset = 15; // Error b/c offset less than offset of mapped mem
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001967 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, ") is less than Memory Object's offset (");
Tobin Ehlis35372522016-05-12 08:32:31 -06001968 vkFlushMappedMemoryRanges(m_device->device(), 1, &mmr);
1969 m_errorMonitor->VerifyFound();
1970 // Now flush range that oversteps mapped range
1971 vkUnmapMemory(m_device->device(), mem);
1972 err = vkMapMemory(m_device->device(), mem, 0, 256, 0, (void **)&pData);
1973 ASSERT_VK_SUCCESS(err);
1974 mmr.offset = 16;
1975 mmr.size = 256; // flushing bounds (272) exceed mapped bounds (256)
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001976 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, ") exceeds the Memory Object's upper-bound (");
Tobin Ehlis35372522016-05-12 08:32:31 -06001977 vkFlushMappedMemoryRanges(m_device->device(), 1, &mmr);
1978 m_errorMonitor->VerifyFound();
1979
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001980 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &alloc_info, VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT,
1981 VK_MEMORY_PROPERTY_HOST_COHERENT_BIT);
Tobin Ehlis35372522016-05-12 08:32:31 -06001982 if (!pass) {
1983 vkFreeMemory(m_device->device(), mem, NULL);
1984 vkDestroyBuffer(m_device->device(), buffer, NULL);
1985 return;
1986 }
1987 // TODO : If we can get HOST_VISIBLE w/o HOST_COHERENT we can test cases of
1988 // MEMTRACK_INVALID_MAP in validateAndCopyNoncoherentMemoryToDriver()
1989
1990 vkDestroyBuffer(m_device->device(), buffer, NULL);
1991 vkFreeMemory(m_device->device(), mem, NULL);
1992}
1993
Mark Lobodzinski1f515922016-08-16 10:03:30 -06001994TEST_F(VkLayerTest, NonCoherentMemoryMapping) {
1995
1996 TEST_DESCRIPTION("Ensure that validations handling of non-coherent memory "
1997 "mapping while using VK_WHOLE_SIZE does not cause access "
1998 "violations");
1999 VkResult err;
2000 uint8_t *pData;
2001 ASSERT_NO_FATAL_FAILURE(InitState());
2002
2003 VkDeviceMemory mem;
2004 VkMemoryRequirements mem_reqs;
2005 mem_reqs.memoryTypeBits = 0xFFFFFFFF;
2006 VkMemoryAllocateInfo alloc_info = {};
2007 alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
2008 alloc_info.pNext = NULL;
2009 alloc_info.memoryTypeIndex = 0;
2010
2011 static const VkDeviceSize allocation_size = 0x1000;
2012 alloc_info.allocationSize = allocation_size;
2013
2014 // Find a memory configurations WITHOUT a COHERENT bit, otherwise exit
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002015 bool pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &alloc_info, VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT,
2016 VK_MEMORY_PROPERTY_HOST_COHERENT_BIT);
Mark Lobodzinski1f515922016-08-16 10:03:30 -06002017 if (!pass) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002018 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &alloc_info,
2019 VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT,
2020 VK_MEMORY_PROPERTY_HOST_COHERENT_BIT);
Mark Lobodzinski1f515922016-08-16 10:03:30 -06002021 if (!pass) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002022 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &alloc_info,
2023 VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT |
2024 VK_MEMORY_PROPERTY_HOST_CACHED_BIT,
2025 VK_MEMORY_PROPERTY_HOST_COHERENT_BIT);
Mark Lobodzinski1f515922016-08-16 10:03:30 -06002026 if (!pass) {
2027 return;
2028 }
2029 }
2030 }
2031
2032 err = vkAllocateMemory(m_device->device(), &alloc_info, NULL, &mem);
2033 ASSERT_VK_SUCCESS(err);
2034
2035 // Map/Flush/Invalidate using WHOLE_SIZE and zero offsets and entire
2036 // mapped range
2037 m_errorMonitor->ExpectSuccess();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002038 err = vkMapMemory(m_device->device(), mem, 0, VK_WHOLE_SIZE, 0, (void **)&pData);
Mark Lobodzinski1f515922016-08-16 10:03:30 -06002039 ASSERT_VK_SUCCESS(err);
2040 VkMappedMemoryRange mmr = {};
2041 mmr.sType = VK_STRUCTURE_TYPE_MAPPED_MEMORY_RANGE;
2042 mmr.memory = mem;
2043 mmr.offset = 0;
2044 mmr.size = VK_WHOLE_SIZE;
2045 err = vkFlushMappedMemoryRanges(m_device->device(), 1, &mmr);
2046 ASSERT_VK_SUCCESS(err);
2047 err = vkInvalidateMappedMemoryRanges(m_device->device(), 1, &mmr);
2048 ASSERT_VK_SUCCESS(err);
2049 m_errorMonitor->VerifyNotFound();
2050 vkUnmapMemory(m_device->device(), mem);
2051
2052 // Map/Flush/Invalidate using WHOLE_SIZE and a prime offset and entire
2053 // mapped range
2054 m_errorMonitor->ExpectSuccess();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002055 err = vkMapMemory(m_device->device(), mem, 13, VK_WHOLE_SIZE, 0, (void **)&pData);
Mark Lobodzinski1f515922016-08-16 10:03:30 -06002056 ASSERT_VK_SUCCESS(err);
2057 mmr.sType = VK_STRUCTURE_TYPE_MAPPED_MEMORY_RANGE;
2058 mmr.memory = mem;
2059 mmr.offset = 13;
2060 mmr.size = VK_WHOLE_SIZE;
2061 err = vkFlushMappedMemoryRanges(m_device->device(), 1, &mmr);
2062 ASSERT_VK_SUCCESS(err);
2063 err = vkInvalidateMappedMemoryRanges(m_device->device(), 1, &mmr);
2064 ASSERT_VK_SUCCESS(err);
2065 m_errorMonitor->VerifyNotFound();
2066 vkUnmapMemory(m_device->device(), mem);
2067
2068 // Map with prime offset and size
2069 // Flush/Invalidate subrange of mapped area with prime offset and size
2070 m_errorMonitor->ExpectSuccess();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002071 err = vkMapMemory(m_device->device(), mem, allocation_size - 137, 109, 0, (void **)&pData);
Mark Lobodzinski1f515922016-08-16 10:03:30 -06002072 ASSERT_VK_SUCCESS(err);
2073 mmr.sType = VK_STRUCTURE_TYPE_MAPPED_MEMORY_RANGE;
2074 mmr.memory = mem;
2075 mmr.offset = allocation_size - 107;
2076 mmr.size = 61;
2077 err = vkFlushMappedMemoryRanges(m_device->device(), 1, &mmr);
2078 ASSERT_VK_SUCCESS(err);
2079 err = vkInvalidateMappedMemoryRanges(m_device->device(), 1, &mmr);
2080 ASSERT_VK_SUCCESS(err);
2081 m_errorMonitor->VerifyNotFound();
2082 vkUnmapMemory(m_device->device(), mem);
2083
2084 vkFreeMemory(m_device->device(), mem, NULL);
2085}
2086
Ian Elliott1c32c772016-04-28 14:47:13 -06002087TEST_F(VkLayerTest, EnableWsiBeforeUse) {
2088 VkResult err;
2089 bool pass;
2090
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002091 // FIXME: After we turn on this code for non-Linux platforms, uncomment the
2092 // following declaration (which is temporarily being moved below):
2093 // VkSurfaceKHR surface = VK_NULL_HANDLE;
Ian Elliott1c32c772016-04-28 14:47:13 -06002094 VkSwapchainKHR swapchain = VK_NULL_HANDLE;
2095 VkSwapchainCreateInfoKHR swapchain_create_info = {};
2096 uint32_t swapchain_image_count = 0;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002097 // VkImage swapchain_images[1] = {VK_NULL_HANDLE};
Ian Elliott1c32c772016-04-28 14:47:13 -06002098 uint32_t image_index = 0;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002099 // VkPresentInfoKHR present_info = {};
Ian Elliott1c32c772016-04-28 14:47:13 -06002100
2101 ASSERT_NO_FATAL_FAILURE(InitState());
2102
Ian Elliott3f06ce52016-04-29 14:46:21 -06002103#ifdef NEED_TO_TEST_THIS_ON_PLATFORM
2104#if defined(VK_USE_PLATFORM_ANDROID_KHR)
2105 // Use the functions from the VK_KHR_android_surface extension without
2106 // enabling that extension:
2107
2108 // Create a surface:
2109 VkAndroidSurfaceCreateInfoKHR android_create_info = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002110 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
2111 err = vkCreateAndroidSurfaceKHR(instance(), &android_create_info, NULL, &surface);
Ian Elliott3f06ce52016-04-29 14:46:21 -06002112 pass = (err != VK_SUCCESS);
2113 ASSERT_TRUE(pass);
2114 m_errorMonitor->VerifyFound();
2115#endif // VK_USE_PLATFORM_ANDROID_KHR
2116
Ian Elliott3f06ce52016-04-29 14:46:21 -06002117#if defined(VK_USE_PLATFORM_MIR_KHR)
2118 // Use the functions from the VK_KHR_mir_surface extension without enabling
2119 // that extension:
2120
2121 // Create a surface:
2122 VkMirSurfaceCreateInfoKHR mir_create_info = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002123 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
Ian Elliott3f06ce52016-04-29 14:46:21 -06002124 err = vkCreateMirSurfaceKHR(instance(), &mir_create_info, NULL, &surface);
2125 pass = (err != VK_SUCCESS);
2126 ASSERT_TRUE(pass);
2127 m_errorMonitor->VerifyFound();
2128
2129 // Tell whether an mir_connection supports presentation:
2130 MirConnection *mir_connection = NULL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002131 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
2132 vkGetPhysicalDeviceMirPresentationSupportKHR(gpu(), 0, mir_connection, visual_id);
Ian Elliott3f06ce52016-04-29 14:46:21 -06002133 m_errorMonitor->VerifyFound();
2134#endif // VK_USE_PLATFORM_MIR_KHR
2135
Ian Elliott3f06ce52016-04-29 14:46:21 -06002136#if defined(VK_USE_PLATFORM_WAYLAND_KHR)
2137 // Use the functions from the VK_KHR_wayland_surface extension without
2138 // enabling that extension:
2139
2140 // Create a surface:
2141 VkWaylandSurfaceCreateInfoKHR wayland_create_info = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002142 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
2143 err = vkCreateWaylandSurfaceKHR(instance(), &wayland_create_info, NULL, &surface);
Ian Elliott3f06ce52016-04-29 14:46:21 -06002144 pass = (err != VK_SUCCESS);
2145 ASSERT_TRUE(pass);
2146 m_errorMonitor->VerifyFound();
2147
2148 // Tell whether an wayland_display supports presentation:
2149 struct wl_display wayland_display = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002150 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
2151 vkGetPhysicalDeviceWaylandPresentationSupportKHR(gpu(), 0, &wayland_display);
Ian Elliott3f06ce52016-04-29 14:46:21 -06002152 m_errorMonitor->VerifyFound();
2153#endif // VK_USE_PLATFORM_WAYLAND_KHR
Ian Elliott489eec02016-05-05 14:12:44 -06002154#endif // NEED_TO_TEST_THIS_ON_PLATFORM
Ian Elliott3f06ce52016-04-29 14:46:21 -06002155
Ian Elliott3f06ce52016-04-29 14:46:21 -06002156#if defined(VK_USE_PLATFORM_WIN32_KHR)
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002157 // FIXME: REMOVE THIS HERE, AND UNCOMMENT ABOVE, WHEN THIS TEST HAS BEEN PORTED
2158 // TO NON-LINUX PLATFORMS:
2159 VkSurfaceKHR surface = VK_NULL_HANDLE;
Ian Elliott3f06ce52016-04-29 14:46:21 -06002160 // Use the functions from the VK_KHR_win32_surface extension without
2161 // enabling that extension:
2162
2163 // Create a surface:
2164 VkWin32SurfaceCreateInfoKHR win32_create_info = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002165 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
2166 err = vkCreateWin32SurfaceKHR(instance(), &win32_create_info, NULL, &surface);
Ian Elliott3f06ce52016-04-29 14:46:21 -06002167 pass = (err != VK_SUCCESS);
2168 ASSERT_TRUE(pass);
2169 m_errorMonitor->VerifyFound();
2170
2171 // Tell whether win32 supports presentation:
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002172 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
Ian Elliott489eec02016-05-05 14:12:44 -06002173 vkGetPhysicalDeviceWin32PresentationSupportKHR(gpu(), 0);
Ian Elliott3f06ce52016-04-29 14:46:21 -06002174 m_errorMonitor->VerifyFound();
Ian Elliott489eec02016-05-05 14:12:44 -06002175// Set this (for now, until all platforms are supported and tested):
2176#define NEED_TO_TEST_THIS_ON_PLATFORM
2177#endif // VK_USE_PLATFORM_WIN32_KHR
Ian Elliott3f06ce52016-04-29 14:46:21 -06002178
Ian Elliott1c32c772016-04-28 14:47:13 -06002179#if defined(VK_USE_PLATFORM_XCB_KHR)
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002180 // FIXME: REMOVE THIS HERE, AND UNCOMMENT ABOVE, WHEN THIS TEST HAS BEEN PORTED
2181 // TO NON-LINUX PLATFORMS:
2182 VkSurfaceKHR surface = VK_NULL_HANDLE;
Ian Elliott1c32c772016-04-28 14:47:13 -06002183 // Use the functions from the VK_KHR_xcb_surface extension without enabling
2184 // that extension:
2185
2186 // Create a surface:
2187 VkXcbSurfaceCreateInfoKHR xcb_create_info = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002188 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
Ian Elliott1c32c772016-04-28 14:47:13 -06002189 err = vkCreateXcbSurfaceKHR(instance(), &xcb_create_info, NULL, &surface);
2190 pass = (err != VK_SUCCESS);
2191 ASSERT_TRUE(pass);
2192 m_errorMonitor->VerifyFound();
2193
2194 // Tell whether an xcb_visualid_t supports presentation:
Ian Elliott3f06ce52016-04-29 14:46:21 -06002195 xcb_connection_t *xcb_connection = NULL;
Ian Elliott1c32c772016-04-28 14:47:13 -06002196 xcb_visualid_t visual_id = 0;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002197 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
2198 vkGetPhysicalDeviceXcbPresentationSupportKHR(gpu(), 0, xcb_connection, visual_id);
Ian Elliott1c32c772016-04-28 14:47:13 -06002199 m_errorMonitor->VerifyFound();
Ian Elliott489eec02016-05-05 14:12:44 -06002200// Set this (for now, until all platforms are supported and tested):
2201#define NEED_TO_TEST_THIS_ON_PLATFORM
Ian Elliott1c32c772016-04-28 14:47:13 -06002202#endif // VK_USE_PLATFORM_XCB_KHR
2203
Ian Elliott12630812016-04-29 14:35:43 -06002204#if defined(VK_USE_PLATFORM_XLIB_KHR)
2205 // Use the functions from the VK_KHR_xlib_surface extension without enabling
2206 // that extension:
2207
2208 // Create a surface:
2209 VkXlibSurfaceCreateInfoKHR xlib_create_info = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002210 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
Ian Elliott12630812016-04-29 14:35:43 -06002211 err = vkCreateXlibSurfaceKHR(instance(), &xlib_create_info, NULL, &surface);
2212 pass = (err != VK_SUCCESS);
2213 ASSERT_TRUE(pass);
2214 m_errorMonitor->VerifyFound();
2215
2216 // Tell whether an Xlib VisualID supports presentation:
2217 Display *dpy = NULL;
2218 VisualID visual = 0;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002219 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
Ian Elliott12630812016-04-29 14:35:43 -06002220 vkGetPhysicalDeviceXlibPresentationSupportKHR(gpu(), 0, dpy, visual);
2221 m_errorMonitor->VerifyFound();
Ian Elliott489eec02016-05-05 14:12:44 -06002222// Set this (for now, until all platforms are supported and tested):
2223#define NEED_TO_TEST_THIS_ON_PLATFORM
Ian Elliott12630812016-04-29 14:35:43 -06002224#endif // VK_USE_PLATFORM_XLIB_KHR
2225
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002226// Use the functions from the VK_KHR_surface extension without enabling
2227// that extension:
Ian Elliott1c32c772016-04-28 14:47:13 -06002228
Ian Elliott489eec02016-05-05 14:12:44 -06002229#ifdef NEED_TO_TEST_THIS_ON_PLATFORM
Ian Elliott1c32c772016-04-28 14:47:13 -06002230 // Destroy a surface:
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002231 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
Ian Elliott1c32c772016-04-28 14:47:13 -06002232 vkDestroySurfaceKHR(instance(), surface, NULL);
2233 m_errorMonitor->VerifyFound();
2234
2235 // Check if surface supports presentation:
2236 VkBool32 supported = false;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002237 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
Ian Elliott1c32c772016-04-28 14:47:13 -06002238 err = vkGetPhysicalDeviceSurfaceSupportKHR(gpu(), 0, surface, &supported);
2239 pass = (err != VK_SUCCESS);
2240 ASSERT_TRUE(pass);
2241 m_errorMonitor->VerifyFound();
2242
2243 // Check surface capabilities:
2244 VkSurfaceCapabilitiesKHR capabilities = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002245 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
2246 err = vkGetPhysicalDeviceSurfaceCapabilitiesKHR(gpu(), surface, &capabilities);
Ian Elliott1c32c772016-04-28 14:47:13 -06002247 pass = (err != VK_SUCCESS);
2248 ASSERT_TRUE(pass);
2249 m_errorMonitor->VerifyFound();
2250
2251 // Check surface formats:
2252 uint32_t format_count = 0;
2253 VkSurfaceFormatKHR *formats = NULL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002254 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
2255 err = vkGetPhysicalDeviceSurfaceFormatsKHR(gpu(), surface, &format_count, formats);
Ian Elliott1c32c772016-04-28 14:47:13 -06002256 pass = (err != VK_SUCCESS);
2257 ASSERT_TRUE(pass);
2258 m_errorMonitor->VerifyFound();
2259
2260 // Check surface present modes:
2261 uint32_t present_mode_count = 0;
2262 VkSurfaceFormatKHR *present_modes = NULL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002263 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
2264 err = vkGetPhysicalDeviceSurfaceFormatsKHR(gpu(), surface, &present_mode_count, present_modes);
Ian Elliott1c32c772016-04-28 14:47:13 -06002265 pass = (err != VK_SUCCESS);
2266 ASSERT_TRUE(pass);
2267 m_errorMonitor->VerifyFound();
Ian Elliott489eec02016-05-05 14:12:44 -06002268#endif // NEED_TO_TEST_THIS_ON_PLATFORM
Ian Elliott1c32c772016-04-28 14:47:13 -06002269
Ian Elliott1c32c772016-04-28 14:47:13 -06002270 // Use the functions from the VK_KHR_swapchain extension without enabling
2271 // that extension:
2272
2273 // Create a swapchain:
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002274 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
Ian Elliott1c32c772016-04-28 14:47:13 -06002275 swapchain_create_info.sType = VK_STRUCTURE_TYPE_SWAPCHAIN_CREATE_INFO_KHR;
2276 swapchain_create_info.pNext = NULL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002277 err = vkCreateSwapchainKHR(m_device->device(), &swapchain_create_info, NULL, &swapchain);
Ian Elliott1c32c772016-04-28 14:47:13 -06002278 pass = (err != VK_SUCCESS);
2279 ASSERT_TRUE(pass);
2280 m_errorMonitor->VerifyFound();
2281
2282 // Get the images from the swapchain:
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002283 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
2284 err = vkGetSwapchainImagesKHR(m_device->device(), swapchain, &swapchain_image_count, NULL);
Ian Elliott1c32c772016-04-28 14:47:13 -06002285 pass = (err != VK_SUCCESS);
2286 ASSERT_TRUE(pass);
2287 m_errorMonitor->VerifyFound();
2288
Chris Forbeseb7d5502016-09-13 18:19:21 +12002289 // Add a fence to avoid (justifiable) error about not providing fence OR semaphore
2290 VkFenceCreateInfo fci = { VK_STRUCTURE_TYPE_FENCE_CREATE_INFO, nullptr, 0 };
2291 VkFence fence;
2292 err = vkCreateFence(m_device->device(), &fci, nullptr, &fence);
2293
Ian Elliott1c32c772016-04-28 14:47:13 -06002294 // Try to acquire an image:
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002295 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
Chris Forbeseb7d5502016-09-13 18:19:21 +12002296 err = vkAcquireNextImageKHR(m_device->device(), swapchain, 0, VK_NULL_HANDLE, fence, &image_index);
Ian Elliott1c32c772016-04-28 14:47:13 -06002297 pass = (err != VK_SUCCESS);
2298 ASSERT_TRUE(pass);
2299 m_errorMonitor->VerifyFound();
2300
Chris Forbeseb7d5502016-09-13 18:19:21 +12002301 vkDestroyFence(m_device->device(), fence, nullptr);
2302
Ian Elliott1c32c772016-04-28 14:47:13 -06002303 // Try to present an image:
Ian Elliott2c1daf52016-05-12 09:41:46 -06002304 //
2305 // NOTE: Currently can't test this because a real swapchain is needed (as
2306 // opposed to the fake one we created) in order for the layer to lookup the
2307 // VkDevice used to enable the extension:
Ian Elliott1c32c772016-04-28 14:47:13 -06002308
2309 // Destroy the swapchain:
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002310 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
Ian Elliott1c32c772016-04-28 14:47:13 -06002311 vkDestroySwapchainKHR(m_device->device(), swapchain, NULL);
2312 m_errorMonitor->VerifyFound();
2313}
2314
Ian Elliott2c1daf52016-05-12 09:41:46 -06002315TEST_F(VkWsiEnabledLayerTest, TestEnabledWsi) {
Ian Elliott2c1daf52016-05-12 09:41:46 -06002316
Dustin Graves6c6d8982016-05-17 10:09:21 -06002317#if defined(VK_USE_PLATFORM_XCB_KHR)
Ian Elliott2c1daf52016-05-12 09:41:46 -06002318 VkSurfaceKHR surface = VK_NULL_HANDLE;
Mark Lobodzinski085d27a2016-05-17 09:34:26 -06002319
Mark Lobodzinski085d27a2016-05-17 09:34:26 -06002320 VkResult err;
2321 bool pass;
Ian Elliott2c1daf52016-05-12 09:41:46 -06002322 VkSwapchainKHR swapchain = VK_NULL_HANDLE;
2323 VkSwapchainCreateInfoKHR swapchain_create_info = {};
Mark Lobodzinski085d27a2016-05-17 09:34:26 -06002324 // uint32_t swapchain_image_count = 0;
2325 // VkImage swapchain_images[1] = {VK_NULL_HANDLE};
2326 // uint32_t image_index = 0;
2327 // VkPresentInfoKHR present_info = {};
Ian Elliott2c1daf52016-05-12 09:41:46 -06002328
2329 ASSERT_NO_FATAL_FAILURE(InitState());
2330
2331 // Use the create function from one of the VK_KHR_*_surface extension in
2332 // order to create a surface, testing all known errors in the process,
2333 // before successfully creating a surface:
2334 // First, try to create a surface without a VkXcbSurfaceCreateInfoKHR:
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002335 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "required parameter pCreateInfo specified as NULL");
Ian Elliott2c1daf52016-05-12 09:41:46 -06002336 err = vkCreateXcbSurfaceKHR(instance(), NULL, NULL, &surface);
2337 pass = (err != VK_SUCCESS);
2338 ASSERT_TRUE(pass);
2339 m_errorMonitor->VerifyFound();
2340
2341 // Next, try to create a surface with the wrong
2342 // VkXcbSurfaceCreateInfoKHR::sType:
2343 VkXcbSurfaceCreateInfoKHR xcb_create_info = {};
2344 xcb_create_info.sType = VK_STRUCTURE_TYPE_APPLICATION_INFO;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002345 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "parameter pCreateInfo->sType must be");
Ian Elliott2c1daf52016-05-12 09:41:46 -06002346 err = vkCreateXcbSurfaceKHR(instance(), &xcb_create_info, NULL, &surface);
2347 pass = (err != VK_SUCCESS);
2348 ASSERT_TRUE(pass);
2349 m_errorMonitor->VerifyFound();
2350
Ian Elliott2c1daf52016-05-12 09:41:46 -06002351 // Create a native window, and then correctly create a surface:
2352 xcb_connection_t *connection;
2353 xcb_screen_t *screen;
2354 xcb_window_t xcb_window;
2355 xcb_intern_atom_reply_t *atom_wm_delete_window;
2356
2357 const xcb_setup_t *setup;
2358 xcb_screen_iterator_t iter;
2359 int scr;
2360 uint32_t value_mask, value_list[32];
2361 int width = 1;
2362 int height = 1;
2363
2364 connection = xcb_connect(NULL, &scr);
2365 ASSERT_TRUE(connection != NULL);
2366 setup = xcb_get_setup(connection);
2367 iter = xcb_setup_roots_iterator(setup);
2368 while (scr-- > 0)
2369 xcb_screen_next(&iter);
2370 screen = iter.data;
2371
2372 xcb_window = xcb_generate_id(connection);
2373
2374 value_mask = XCB_CW_BACK_PIXEL | XCB_CW_EVENT_MASK;
2375 value_list[0] = screen->black_pixel;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002376 value_list[1] = XCB_EVENT_MASK_KEY_RELEASE | XCB_EVENT_MASK_EXPOSURE | XCB_EVENT_MASK_STRUCTURE_NOTIFY;
Ian Elliott2c1daf52016-05-12 09:41:46 -06002377
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002378 xcb_create_window(connection, XCB_COPY_FROM_PARENT, xcb_window, screen->root, 0, 0, width, height, 0,
2379 XCB_WINDOW_CLASS_INPUT_OUTPUT, screen->root_visual, value_mask, value_list);
Ian Elliott2c1daf52016-05-12 09:41:46 -06002380
2381 /* Magic code that will send notification when window is destroyed */
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002382 xcb_intern_atom_cookie_t cookie = xcb_intern_atom(connection, 1, 12, "WM_PROTOCOLS");
2383 xcb_intern_atom_reply_t *reply = xcb_intern_atom_reply(connection, cookie, 0);
Ian Elliott2c1daf52016-05-12 09:41:46 -06002384
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002385 xcb_intern_atom_cookie_t cookie2 = xcb_intern_atom(connection, 0, 16, "WM_DELETE_WINDOW");
Mark Lobodzinski085d27a2016-05-17 09:34:26 -06002386 atom_wm_delete_window = xcb_intern_atom_reply(connection, cookie2, 0);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002387 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 -06002388 free(reply);
2389
2390 xcb_map_window(connection, xcb_window);
2391
2392 // Force the x/y coordinates to 100,100 results are identical in consecutive
2393 // runs
2394 const uint32_t coords[] = {100, 100};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002395 xcb_configure_window(connection, xcb_window, XCB_CONFIG_WINDOW_X | XCB_CONFIG_WINDOW_Y, coords);
Ian Elliott2c1daf52016-05-12 09:41:46 -06002396
Ian Elliott2c1daf52016-05-12 09:41:46 -06002397 // Finally, try to correctly create a surface:
2398 xcb_create_info.sType = VK_STRUCTURE_TYPE_XCB_SURFACE_CREATE_INFO_KHR;
2399 xcb_create_info.pNext = NULL;
2400 xcb_create_info.flags = 0;
2401 xcb_create_info.connection = connection;
2402 xcb_create_info.window = xcb_window;
2403 err = vkCreateXcbSurfaceKHR(instance(), &xcb_create_info, NULL, &surface);
2404 pass = (err == VK_SUCCESS);
2405 ASSERT_TRUE(pass);
2406
Ian Elliott2c1daf52016-05-12 09:41:46 -06002407 // Check if surface supports presentation:
2408
2409 // 1st, do so without having queried the queue families:
2410 VkBool32 supported = false;
2411 // TODO: Get the following error to come out:
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002412 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
2413 "called before calling the vkGetPhysicalDeviceQueueFamilyProperties "
2414 "function");
Ian Elliott2c1daf52016-05-12 09:41:46 -06002415 err = vkGetPhysicalDeviceSurfaceSupportKHR(gpu(), 0, surface, &supported);
2416 pass = (err != VK_SUCCESS);
Mark Lobodzinski085d27a2016-05-17 09:34:26 -06002417 // ASSERT_TRUE(pass);
2418 // m_errorMonitor->VerifyFound();
Ian Elliott2c1daf52016-05-12 09:41:46 -06002419
2420 // Next, query a queue family index that's too large:
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002421 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "called with a queueFamilyIndex that is too large");
2422 err = vkGetPhysicalDeviceSurfaceSupportKHR(gpu(), 100000, surface, &supported);
Ian Elliott2c1daf52016-05-12 09:41:46 -06002423 pass = (err != VK_SUCCESS);
2424 ASSERT_TRUE(pass);
2425 m_errorMonitor->VerifyFound();
2426
2427 // Finally, do so correctly:
Mark Lobodzinski085d27a2016-05-17 09:34:26 -06002428 // FIXME: THIS ISN'T CORRECT--MUST QUERY UNTIL WE FIND A QUEUE FAMILY THAT'S
2429 // SUPPORTED
Ian Elliott2c1daf52016-05-12 09:41:46 -06002430 err = vkGetPhysicalDeviceSurfaceSupportKHR(gpu(), 0, surface, &supported);
2431 pass = (err == VK_SUCCESS);
2432 ASSERT_TRUE(pass);
2433
Ian Elliott2c1daf52016-05-12 09:41:46 -06002434 // Before proceeding, try to create a swapchain without having called
2435 // vkGetPhysicalDeviceSurfaceCapabilitiesKHR():
2436 swapchain_create_info.sType = VK_STRUCTURE_TYPE_SWAPCHAIN_CREATE_INFO_KHR;
2437 swapchain_create_info.pNext = NULL;
2438 swapchain_create_info.flags = 0;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002439 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
2440 "called before calling vkGetPhysicalDeviceSurfaceCapabilitiesKHR().");
2441 err = vkCreateSwapchainKHR(m_device->device(), &swapchain_create_info, NULL, &swapchain);
Ian Elliott2c1daf52016-05-12 09:41:46 -06002442 pass = (err != VK_SUCCESS);
2443 ASSERT_TRUE(pass);
2444 m_errorMonitor->VerifyFound();
2445
Ian Elliott2c1daf52016-05-12 09:41:46 -06002446 // Get the surface capabilities:
2447 VkSurfaceCapabilitiesKHR surface_capabilities;
2448
2449 // Do so correctly (only error logged by this entrypoint is if the
2450 // extension isn't enabled):
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002451 err = vkGetPhysicalDeviceSurfaceCapabilitiesKHR(gpu(), surface, &surface_capabilities);
Ian Elliott2c1daf52016-05-12 09:41:46 -06002452 pass = (err == VK_SUCCESS);
2453 ASSERT_TRUE(pass);
2454
Ian Elliott2c1daf52016-05-12 09:41:46 -06002455 // Get the surface formats:
2456 uint32_t surface_format_count;
2457
2458 // First, try without a pointer to surface_format_count:
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002459 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "required parameter pSurfaceFormatCount "
2460 "specified as NULL");
Ian Elliott2c1daf52016-05-12 09:41:46 -06002461 vkGetPhysicalDeviceSurfaceFormatsKHR(gpu(), surface, NULL, NULL);
2462 pass = (err == VK_SUCCESS);
2463 ASSERT_TRUE(pass);
2464 m_errorMonitor->VerifyFound();
2465
2466 // Next, call with a non-NULL pSurfaceFormats, even though we haven't
2467 // correctly done a 1st try (to get the count):
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002468 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 -06002469 surface_format_count = 0;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002470 vkGetPhysicalDeviceSurfaceFormatsKHR(gpu(), surface, &surface_format_count, (VkSurfaceFormatKHR *)&surface_format_count);
Ian Elliott2c1daf52016-05-12 09:41:46 -06002471 pass = (err == VK_SUCCESS);
2472 ASSERT_TRUE(pass);
2473 m_errorMonitor->VerifyFound();
2474
2475 // Next, correctly do a 1st try (with a NULL pointer to surface_formats):
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002476 vkGetPhysicalDeviceSurfaceFormatsKHR(gpu(), surface, &surface_format_count, NULL);
Ian Elliott2c1daf52016-05-12 09:41:46 -06002477 pass = (err == VK_SUCCESS);
2478 ASSERT_TRUE(pass);
2479
2480 // Allocate memory for the correct number of VkSurfaceFormatKHR's:
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002481 VkSurfaceFormatKHR *surface_formats = (VkSurfaceFormatKHR *)malloc(surface_format_count * sizeof(VkSurfaceFormatKHR));
Ian Elliott2c1daf52016-05-12 09:41:46 -06002482
2483 // Next, do a 2nd try with surface_format_count being set too high:
2484 surface_format_count += 5;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002485 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "that is greater than the value");
2486 vkGetPhysicalDeviceSurfaceFormatsKHR(gpu(), surface, &surface_format_count, surface_formats);
Ian Elliott2c1daf52016-05-12 09:41:46 -06002487 pass = (err == VK_SUCCESS);
2488 ASSERT_TRUE(pass);
2489 m_errorMonitor->VerifyFound();
2490
2491 // Finally, do a correct 1st and 2nd try:
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002492 vkGetPhysicalDeviceSurfaceFormatsKHR(gpu(), surface, &surface_format_count, NULL);
Ian Elliott2c1daf52016-05-12 09:41:46 -06002493 pass = (err == VK_SUCCESS);
2494 ASSERT_TRUE(pass);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002495 vkGetPhysicalDeviceSurfaceFormatsKHR(gpu(), surface, &surface_format_count, surface_formats);
Ian Elliott2c1daf52016-05-12 09:41:46 -06002496 pass = (err == VK_SUCCESS);
2497 ASSERT_TRUE(pass);
2498
Ian Elliott2c1daf52016-05-12 09:41:46 -06002499 // Get the surface present modes:
2500 uint32_t surface_present_mode_count;
2501
2502 // First, try without a pointer to surface_format_count:
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002503 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "required parameter pPresentModeCount "
2504 "specified as NULL");
Mark Lobodzinskib02ea642016-08-17 13:03:57 -06002505
Ian Elliott2c1daf52016-05-12 09:41:46 -06002506 vkGetPhysicalDeviceSurfacePresentModesKHR(gpu(), surface, NULL, NULL);
2507 pass = (err == VK_SUCCESS);
2508 ASSERT_TRUE(pass);
2509 m_errorMonitor->VerifyFound();
2510
2511 // Next, call with a non-NULL VkPresentModeKHR, even though we haven't
2512 // correctly done a 1st try (to get the count):
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002513 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 -06002514 surface_present_mode_count = 0;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002515 vkGetPhysicalDeviceSurfacePresentModesKHR(gpu(), surface, &surface_present_mode_count,
2516 (VkPresentModeKHR *)&surface_present_mode_count);
Ian Elliott2c1daf52016-05-12 09:41:46 -06002517 pass = (err == VK_SUCCESS);
2518 ASSERT_TRUE(pass);
2519 m_errorMonitor->VerifyFound();
2520
2521 // Next, correctly do a 1st try (with a NULL pointer to surface_formats):
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002522 vkGetPhysicalDeviceSurfacePresentModesKHR(gpu(), surface, &surface_present_mode_count, NULL);
Ian Elliott2c1daf52016-05-12 09:41:46 -06002523 pass = (err == VK_SUCCESS);
2524 ASSERT_TRUE(pass);
2525
2526 // Allocate memory for the correct number of VkSurfaceFormatKHR's:
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002527 VkPresentModeKHR *surface_present_modes = (VkPresentModeKHR *)malloc(surface_present_mode_count * sizeof(VkPresentModeKHR));
Ian Elliott2c1daf52016-05-12 09:41:46 -06002528
2529 // Next, do a 2nd try with surface_format_count being set too high:
2530 surface_present_mode_count += 5;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002531 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "that is greater than the value");
2532 vkGetPhysicalDeviceSurfacePresentModesKHR(gpu(), surface, &surface_present_mode_count, surface_present_modes);
Ian Elliott2c1daf52016-05-12 09:41:46 -06002533 pass = (err == VK_SUCCESS);
2534 ASSERT_TRUE(pass);
2535 m_errorMonitor->VerifyFound();
2536
2537 // Finally, do a correct 1st and 2nd try:
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002538 vkGetPhysicalDeviceSurfacePresentModesKHR(gpu(), surface, &surface_present_mode_count, NULL);
Ian Elliott2c1daf52016-05-12 09:41:46 -06002539 pass = (err == VK_SUCCESS);
2540 ASSERT_TRUE(pass);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002541 vkGetPhysicalDeviceSurfacePresentModesKHR(gpu(), surface, &surface_present_mode_count, surface_present_modes);
Ian Elliott2c1daf52016-05-12 09:41:46 -06002542 pass = (err == VK_SUCCESS);
2543 ASSERT_TRUE(pass);
2544
Ian Elliott2c1daf52016-05-12 09:41:46 -06002545 // Create a swapchain:
2546
2547 // First, try without a pointer to swapchain_create_info:
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002548 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "required parameter pCreateInfo "
2549 "specified as NULL");
Mark Lobodzinskib02ea642016-08-17 13:03:57 -06002550
Ian Elliott2c1daf52016-05-12 09:41:46 -06002551 err = vkCreateSwapchainKHR(m_device->device(), NULL, NULL, &swapchain);
2552 pass = (err != VK_SUCCESS);
2553 ASSERT_TRUE(pass);
2554 m_errorMonitor->VerifyFound();
2555
2556 // Next, call with a non-NULL swapchain_create_info, that has the wrong
2557 // sType:
2558 swapchain_create_info.sType = VK_STRUCTURE_TYPE_APPLICATION_INFO;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002559 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "parameter pCreateInfo->sType must be");
Mark Lobodzinskib02ea642016-08-17 13:03:57 -06002560
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002561 err = vkCreateSwapchainKHR(m_device->device(), &swapchain_create_info, NULL, &swapchain);
Ian Elliott2c1daf52016-05-12 09:41:46 -06002562 pass = (err != VK_SUCCESS);
2563 ASSERT_TRUE(pass);
2564 m_errorMonitor->VerifyFound();
2565
2566 // Next, call with a NULL swapchain pointer:
2567 swapchain_create_info.sType = VK_STRUCTURE_TYPE_SWAPCHAIN_CREATE_INFO_KHR;
2568 swapchain_create_info.pNext = NULL;
2569 swapchain_create_info.flags = 0;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002570 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "required parameter pSwapchain "
2571 "specified as NULL");
Mark Lobodzinskib02ea642016-08-17 13:03:57 -06002572
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002573 err = vkCreateSwapchainKHR(m_device->device(), &swapchain_create_info, NULL, NULL);
Ian Elliott2c1daf52016-05-12 09:41:46 -06002574 pass = (err != VK_SUCCESS);
2575 ASSERT_TRUE(pass);
2576 m_errorMonitor->VerifyFound();
2577
Mark Lobodzinski085d27a2016-05-17 09:34:26 -06002578 // TODO: Enhance swapchain layer so that
2579 // swapchain_create_info.queueFamilyIndexCount is checked against something?
Ian Elliott2c1daf52016-05-12 09:41:46 -06002580
2581 // Next, call with a queue family index that's too large:
2582 uint32_t queueFamilyIndex[2] = {100000, 0};
2583 swapchain_create_info.imageSharingMode = VK_SHARING_MODE_CONCURRENT;
2584 swapchain_create_info.queueFamilyIndexCount = 2;
2585 swapchain_create_info.pQueueFamilyIndices = queueFamilyIndex;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002586 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "called with a queueFamilyIndex that is too large");
2587 err = vkCreateSwapchainKHR(m_device->device(), &swapchain_create_info, NULL, &swapchain);
Ian Elliott2c1daf52016-05-12 09:41:46 -06002588 pass = (err != VK_SUCCESS);
2589 ASSERT_TRUE(pass);
2590 m_errorMonitor->VerifyFound();
2591
2592 // Next, call a queueFamilyIndexCount that's too small for CONCURRENT:
2593 swapchain_create_info.imageSharingMode = VK_SHARING_MODE_CONCURRENT;
2594 swapchain_create_info.queueFamilyIndexCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002595 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
2596 "but with a bad value(s) for pCreateInfo->queueFamilyIndexCount or "
2597 "pCreateInfo->pQueueFamilyIndices).");
2598 err = vkCreateSwapchainKHR(m_device->device(), &swapchain_create_info, NULL, &swapchain);
Ian Elliott2c1daf52016-05-12 09:41:46 -06002599 pass = (err != VK_SUCCESS);
2600 ASSERT_TRUE(pass);
2601 m_errorMonitor->VerifyFound();
2602
2603 // Next, call with an invalid imageSharingMode:
2604 swapchain_create_info.imageSharingMode = VK_SHARING_MODE_MAX_ENUM;
2605 swapchain_create_info.queueFamilyIndexCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002606 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
2607 "called with a non-supported pCreateInfo->imageSharingMode (i.e.");
2608 err = vkCreateSwapchainKHR(m_device->device(), &swapchain_create_info, NULL, &swapchain);
Ian Elliott2c1daf52016-05-12 09:41:46 -06002609 pass = (err != VK_SUCCESS);
2610 ASSERT_TRUE(pass);
2611 m_errorMonitor->VerifyFound();
2612 // Fix for the future:
Mark Lobodzinski085d27a2016-05-17 09:34:26 -06002613 // FIXME: THIS ISN'T CORRECT--MUST QUERY UNTIL WE FIND A QUEUE FAMILY THAT'S
2614 // SUPPORTED
Ian Elliott2c1daf52016-05-12 09:41:46 -06002615 swapchain_create_info.queueFamilyIndexCount = 0;
2616 queueFamilyIndex[0] = 0;
2617 swapchain_create_info.imageSharingMode = VK_SHARING_MODE_EXCLUSIVE;
2618
Mark Lobodzinski085d27a2016-05-17 09:34:26 -06002619 // TODO: CONTINUE TESTING VALIDATION OF vkCreateSwapchainKHR() ...
Ian Elliott2c1daf52016-05-12 09:41:46 -06002620 // Get the images from a swapchain:
Ian Elliott2c1daf52016-05-12 09:41:46 -06002621 // Acquire an image from a swapchain:
Ian Elliott2c1daf52016-05-12 09:41:46 -06002622 // Present an image to a swapchain:
Ian Elliott2c1daf52016-05-12 09:41:46 -06002623 // Destroy the swapchain:
2624
Mark Lobodzinski085d27a2016-05-17 09:34:26 -06002625 // TODOs:
2626 //
2627 // - Try destroying the device without first destroying the swapchain
2628 //
2629 // - Try destroying the device without first destroying the surface
2630 //
2631 // - Try destroying the surface without first destroying the swapchain
Ian Elliott2c1daf52016-05-12 09:41:46 -06002632
2633 // Destroy the surface:
2634 vkDestroySurfaceKHR(instance(), surface, NULL);
2635
Ian Elliott2c1daf52016-05-12 09:41:46 -06002636 // Tear down the window:
2637 xcb_destroy_window(connection, xcb_window);
2638 xcb_disconnect(connection);
2639
2640#else // VK_USE_PLATFORM_XCB_KHR
Mark Lobodzinski085d27a2016-05-17 09:34:26 -06002641 return;
Ian Elliott2c1daf52016-05-12 09:41:46 -06002642#endif // VK_USE_PLATFORM_XCB_KHR
2643}
2644
Karl Schultz6addd812016-02-02 17:17:23 -07002645TEST_F(VkLayerTest, MapMemWithoutHostVisibleBit) {
2646 VkResult err;
2647 bool pass;
Mark Lobodzinski3780e142015-05-14 15:08:13 -05002648
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002649 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
2650 "Mapping Memory without VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06002651
Mark Lobodzinski3780e142015-05-14 15:08:13 -05002652 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinski3780e142015-05-14 15:08:13 -05002653
2654 // Create an image, allocate memory, free it, and then try to bind it
Karl Schultz6addd812016-02-02 17:17:23 -07002655 VkImage image;
2656 VkDeviceMemory mem;
2657 VkMemoryRequirements mem_reqs;
Mark Lobodzinski3780e142015-05-14 15:08:13 -05002658
Karl Schultz6addd812016-02-02 17:17:23 -07002659 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
2660 const int32_t tex_width = 32;
2661 const int32_t tex_height = 32;
Mark Lobodzinski3780e142015-05-14 15:08:13 -05002662
Tony Barboureb254902015-07-15 12:50:33 -06002663 VkImageCreateInfo image_create_info = {};
2664 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
Karl Schultz6addd812016-02-02 17:17:23 -07002665 image_create_info.pNext = NULL;
2666 image_create_info.imageType = VK_IMAGE_TYPE_2D;
2667 image_create_info.format = tex_format;
2668 image_create_info.extent.width = tex_width;
2669 image_create_info.extent.height = tex_height;
2670 image_create_info.extent.depth = 1;
2671 image_create_info.mipLevels = 1;
2672 image_create_info.arrayLayers = 1;
2673 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
2674 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
2675 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
2676 image_create_info.flags = 0;
Chris Forbese65e4d02016-09-13 17:39:18 +12002677 image_create_info.initialLayout = VK_IMAGE_LAYOUT_PREINITIALIZED;
Mark Lobodzinski5fcc4212015-09-14 17:43:42 -06002678
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002679 VkMemoryAllocateInfo mem_alloc = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08002680 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
Karl Schultz6addd812016-02-02 17:17:23 -07002681 mem_alloc.pNext = NULL;
2682 mem_alloc.allocationSize = 0;
Mark Lobodzinski3780e142015-05-14 15:08:13 -05002683
Chia-I Wuf7458c52015-10-26 21:10:41 +08002684 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
Mark Lobodzinski3780e142015-05-14 15:08:13 -05002685 ASSERT_VK_SUCCESS(err);
2686
Karl Schultz6addd812016-02-02 17:17:23 -07002687 vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs);
Mark Lobodzinski3780e142015-05-14 15:08:13 -05002688
Mark Lobodzinski23065352015-05-29 09:32:35 -05002689 mem_alloc.allocationSize = mem_reqs.size;
Mark Lobodzinski3780e142015-05-14 15:08:13 -05002690
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002691 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 -07002692 if (!pass) { // If we can't find any unmappable memory this test doesn't
2693 // make sense
Chia-I Wuf7458c52015-10-26 21:10:41 +08002694 vkDestroyImage(m_device->device(), image, NULL);
Tony Barbour02fdc7d2015-08-04 16:13:01 -06002695 return;
Mike Stroyand1c84a52015-08-18 14:40:24 -06002696 }
Mike Stroyan713b2d72015-08-04 10:49:29 -06002697
Mark Lobodzinski3780e142015-05-14 15:08:13 -05002698 // allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002699 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem);
Mark Lobodzinski3780e142015-05-14 15:08:13 -05002700 ASSERT_VK_SUCCESS(err);
2701
2702 // Try to bind free memory that has been freed
Tony Barbour67e99152015-07-10 14:10:27 -06002703 err = vkBindImageMemory(m_device->device(), image, mem, 0);
Mark Lobodzinski3780e142015-05-14 15:08:13 -05002704 ASSERT_VK_SUCCESS(err);
2705
2706 // Map memory as if to initialize the image
2707 void *mappedAddress = NULL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002708 err = vkMapMemory(m_device->device(), mem, 0, VK_WHOLE_SIZE, 0, &mappedAddress);
Mark Lobodzinski3780e142015-05-14 15:08:13 -05002709
Chris Forbes8f36a8a2016-04-07 13:21:07 +12002710 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06002711
Chia-I Wuf7458c52015-10-26 21:10:41 +08002712 vkDestroyImage(m_device->device(), image, NULL);
Tony Barbourdf4c0042016-06-01 15:55:43 -06002713 vkFreeMemory(m_device->device(), mem, NULL);
Mark Lobodzinski3780e142015-05-14 15:08:13 -05002714}
2715
Karl Schultz6addd812016-02-02 17:17:23 -07002716TEST_F(VkLayerTest, RebindMemory) {
2717 VkResult err;
2718 bool pass;
Mark Lobodzinski944aab12015-06-05 13:59:04 -05002719
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002720 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "which has already been bound to mem object");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06002721
Mark Lobodzinski944aab12015-06-05 13:59:04 -05002722 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinski944aab12015-06-05 13:59:04 -05002723
2724 // Create an image, allocate memory, free it, and then try to bind it
Karl Schultz6addd812016-02-02 17:17:23 -07002725 VkImage image;
2726 VkDeviceMemory mem1;
2727 VkDeviceMemory mem2;
2728 VkMemoryRequirements mem_reqs;
Mark Lobodzinski944aab12015-06-05 13:59:04 -05002729
Karl Schultz6addd812016-02-02 17:17:23 -07002730 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
2731 const int32_t tex_width = 32;
2732 const int32_t tex_height = 32;
Mark Lobodzinski944aab12015-06-05 13:59:04 -05002733
Tony Barboureb254902015-07-15 12:50:33 -06002734 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -07002735 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
2736 image_create_info.pNext = NULL;
2737 image_create_info.imageType = VK_IMAGE_TYPE_2D;
2738 image_create_info.format = tex_format;
2739 image_create_info.extent.width = tex_width;
2740 image_create_info.extent.height = tex_height;
2741 image_create_info.extent.depth = 1;
2742 image_create_info.mipLevels = 1;
2743 image_create_info.arrayLayers = 1;
2744 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
2745 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
2746 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
2747 image_create_info.flags = 0;
Mark Lobodzinski944aab12015-06-05 13:59:04 -05002748
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002749 VkMemoryAllocateInfo mem_alloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -07002750 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
2751 mem_alloc.pNext = NULL;
2752 mem_alloc.allocationSize = 0;
2753 mem_alloc.memoryTypeIndex = 0;
Tony Barboureb254902015-07-15 12:50:33 -06002754
Karl Schultz6addd812016-02-02 17:17:23 -07002755 // Introduce failure, do NOT set memProps to
2756 // VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT
Tony Barboureb254902015-07-15 12:50:33 -06002757 mem_alloc.memoryTypeIndex = 1;
Chia-I Wuf7458c52015-10-26 21:10:41 +08002758 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
Mark Lobodzinski944aab12015-06-05 13:59:04 -05002759 ASSERT_VK_SUCCESS(err);
2760
Karl Schultz6addd812016-02-02 17:17:23 -07002761 vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs);
Mark Lobodzinski944aab12015-06-05 13:59:04 -05002762
2763 mem_alloc.allocationSize = mem_reqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002764 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -06002765 ASSERT_TRUE(pass);
Mark Lobodzinski944aab12015-06-05 13:59:04 -05002766
2767 // allocate 2 memory objects
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002768 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem1);
Mark Lobodzinski944aab12015-06-05 13:59:04 -05002769 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002770 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem2);
Mark Lobodzinski944aab12015-06-05 13:59:04 -05002771 ASSERT_VK_SUCCESS(err);
2772
2773 // Bind first memory object to Image object
Tony Barbour67e99152015-07-10 14:10:27 -06002774 err = vkBindImageMemory(m_device->device(), image, mem1, 0);
Mark Lobodzinski944aab12015-06-05 13:59:04 -05002775 ASSERT_VK_SUCCESS(err);
2776
Karl Schultz6addd812016-02-02 17:17:23 -07002777 // Introduce validation failure, try to bind a different memory object to
2778 // the same image object
Tony Barbour67e99152015-07-10 14:10:27 -06002779 err = vkBindImageMemory(m_device->device(), image, mem2, 0);
Mark Lobodzinski944aab12015-06-05 13:59:04 -05002780
Chris Forbes8f36a8a2016-04-07 13:21:07 +12002781 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06002782
Chia-I Wuf7458c52015-10-26 21:10:41 +08002783 vkDestroyImage(m_device->device(), image, NULL);
2784 vkFreeMemory(m_device->device(), mem1, NULL);
2785 vkFreeMemory(m_device->device(), mem2, NULL);
Mark Lobodzinski944aab12015-06-05 13:59:04 -05002786}
Mark Lobodzinski3780e142015-05-14 15:08:13 -05002787
Karl Schultz6addd812016-02-02 17:17:23 -07002788TEST_F(VkLayerTest, SubmitSignaledFence) {
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06002789 vk_testing::Fence testFence;
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06002790
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002791 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "submitted in SIGNALED state. Fences "
2792 "must be reset before being submitted");
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06002793
2794 VkFenceCreateInfo fenceInfo = {};
Tony Barbour0b4d9562015-04-09 10:48:04 -06002795 fenceInfo.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
2796 fenceInfo.pNext = NULL;
2797 fenceInfo.flags = VK_FENCE_CREATE_SIGNALED_BIT;
Tony Barbour300a6082015-04-07 13:44:53 -06002798
Tony Barbour300a6082015-04-07 13:44:53 -06002799 ASSERT_NO_FATAL_FAILURE(InitState());
2800 ASSERT_NO_FATAL_FAILURE(InitViewport());
2801 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
2802
Tony Barbourfe3351b2015-07-28 10:17:20 -06002803 BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002804 m_commandBuffer->ClearAllBuffers(m_clear_color, m_depth_clear_color, m_stencil_clear_color, NULL);
Tony Barbourfe3351b2015-07-28 10:17:20 -06002805 EndCommandBuffer();
Tony Barbour300a6082015-04-07 13:44:53 -06002806
2807 testFence.init(*m_device, fenceInfo);
Mark Lobodzinski5fcc4212015-09-14 17:43:42 -06002808
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06002809 VkSubmitInfo submit_info;
Chia-I Wuf9be13c2015-10-26 20:37:06 +08002810 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
2811 submit_info.pNext = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08002812 submit_info.waitSemaphoreCount = 0;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06002813 submit_info.pWaitSemaphores = NULL;
Jon Ashburn7f9716c2015-12-30 16:42:50 -07002814 submit_info.pWaitDstStageMask = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08002815 submit_info.commandBufferCount = 1;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002816 submit_info.pCommandBuffers = &m_commandBuffer->handle();
Chia-I Wud50a7d72015-10-26 20:48:51 +08002817 submit_info.signalSemaphoreCount = 0;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06002818 submit_info.pSignalSemaphores = NULL;
Courtney Goeltzenleuchter646b9072015-10-20 18:04:07 -06002819
2820 vkQueueSubmit(m_device->m_queue, 1, &submit_info, testFence.handle());
Karl Schultz6addd812016-02-02 17:17:23 -07002821 vkQueueWaitIdle(m_device->m_queue);
Mark Lobodzinski5fcc4212015-09-14 17:43:42 -06002822
Chris Forbes8f36a8a2016-04-07 13:21:07 +12002823 m_errorMonitor->VerifyFound();
Tony Barbour0b4d9562015-04-09 10:48:04 -06002824}
Tobin Ehlisaff7ae92016-04-18 15:45:20 -06002825// This is a positive test. We used to expect error in this case but spec now
2826// allows it
Karl Schultz6addd812016-02-02 17:17:23 -07002827TEST_F(VkLayerTest, ResetUnsignaledFence) {
Tobin Ehlisaff7ae92016-04-18 15:45:20 -06002828 m_errorMonitor->ExpectSuccess();
Tony Barbour0b4d9562015-04-09 10:48:04 -06002829 vk_testing::Fence testFence;
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06002830 VkFenceCreateInfo fenceInfo = {};
Tony Barbour0b4d9562015-04-09 10:48:04 -06002831 fenceInfo.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
2832 fenceInfo.pNext = NULL;
2833
Tony Barbour0b4d9562015-04-09 10:48:04 -06002834 ASSERT_NO_FATAL_FAILURE(InitState());
2835 testFence.init(*m_device, fenceInfo);
Chia-I Wud9e8e822015-07-03 11:45:55 +08002836 VkFence fences[1] = {testFence.handle()};
Tobin Ehlisaff7ae92016-04-18 15:45:20 -06002837 VkResult result = vkResetFences(m_device->device(), 1, fences);
2838 ASSERT_VK_SUCCESS(result);
Tony Barbour300a6082015-04-07 13:44:53 -06002839
Tobin Ehlisaff7ae92016-04-18 15:45:20 -06002840 m_errorMonitor->VerifyNotFound();
Tony Barbour300a6082015-04-07 13:44:53 -06002841}
Tobin Ehlis56ab9022016-08-17 17:59:31 -06002842#if 0 // A few devices have issues with this test so disabling for now
Chris Forbese70b7d32016-06-15 15:49:12 +12002843TEST_F(VkLayerTest, LongFenceChain)
2844{
2845 m_errorMonitor->ExpectSuccess();
2846
2847 ASSERT_NO_FATAL_FAILURE(InitState());
2848 VkResult err;
2849
2850 std::vector<VkFence> fences;
2851
2852 const int chainLength = 32768;
2853
2854 for (int i = 0; i < chainLength; i++) {
2855 VkFenceCreateInfo fci = { VK_STRUCTURE_TYPE_FENCE_CREATE_INFO, nullptr, 0 };
2856 VkFence fence;
2857 err = vkCreateFence(m_device->device(), &fci, nullptr, &fence);
2858 ASSERT_VK_SUCCESS(err);
2859
2860 fences.push_back(fence);
2861
2862 VkSubmitInfo si = { VK_STRUCTURE_TYPE_SUBMIT_INFO, nullptr, 0, nullptr, nullptr,
2863 0, nullptr, 0, nullptr };
2864 err = vkQueueSubmit(m_device->m_queue, 1, &si, fence);
2865 ASSERT_VK_SUCCESS(err);
2866
2867 }
2868
2869 // BOOM, stack overflow.
2870 vkWaitForFences(m_device->device(), 1, &fences.back(), VK_TRUE, UINT64_MAX);
2871
2872 for (auto fence : fences)
2873 vkDestroyFence(m_device->device(), fence, nullptr);
2874
2875 m_errorMonitor->VerifyNotFound();
2876}
Tobin Ehlis56ab9022016-08-17 17:59:31 -06002877#endif
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002878TEST_F(VkLayerTest, CommandBufferSimultaneousUseSync) {
Chris Forbes18127d12016-06-08 16:52:28 +12002879 m_errorMonitor->ExpectSuccess();
2880
2881 ASSERT_NO_FATAL_FAILURE(InitState());
2882 VkResult err;
2883
2884 // Record (empty!) command buffer that can be submitted multiple times
2885 // simultaneously.
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002886 VkCommandBufferBeginInfo cbbi = {VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO, nullptr,
2887 VK_COMMAND_BUFFER_USAGE_SIMULTANEOUS_USE_BIT, nullptr};
Chris Forbes18127d12016-06-08 16:52:28 +12002888 m_commandBuffer->BeginCommandBuffer(&cbbi);
2889 m_commandBuffer->EndCommandBuffer();
2890
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002891 VkFenceCreateInfo fci = {VK_STRUCTURE_TYPE_FENCE_CREATE_INFO, nullptr, 0};
Chris Forbes18127d12016-06-08 16:52:28 +12002892 VkFence fence;
2893 err = vkCreateFence(m_device->device(), &fci, nullptr, &fence);
2894 ASSERT_VK_SUCCESS(err);
2895
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002896 VkSemaphoreCreateInfo sci = {VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO, nullptr, 0};
Chris Forbes18127d12016-06-08 16:52:28 +12002897 VkSemaphore s1, s2;
2898 err = vkCreateSemaphore(m_device->device(), &sci, nullptr, &s1);
2899 ASSERT_VK_SUCCESS(err);
2900 err = vkCreateSemaphore(m_device->device(), &sci, nullptr, &s2);
2901 ASSERT_VK_SUCCESS(err);
2902
2903 // Submit CB once signaling s1, with fence so we can roll forward to its retirement.
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002904 VkSubmitInfo si = {VK_STRUCTURE_TYPE_SUBMIT_INFO, nullptr, 0, nullptr, nullptr, 1, &m_commandBuffer->handle(), 1, &s1};
Chris Forbes18127d12016-06-08 16:52:28 +12002905 err = vkQueueSubmit(m_device->m_queue, 1, &si, fence);
2906 ASSERT_VK_SUCCESS(err);
2907
2908 // Submit CB again, signaling s2.
2909 si.pSignalSemaphores = &s2;
2910 err = vkQueueSubmit(m_device->m_queue, 1, &si, VK_NULL_HANDLE);
2911 ASSERT_VK_SUCCESS(err);
2912
2913 // Wait for fence.
2914 err = vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
2915 ASSERT_VK_SUCCESS(err);
2916
2917 // CB is still in flight from second submission, but semaphore s1 is no
2918 // longer in flight. delete it.
2919 vkDestroySemaphore(m_device->device(), s1, nullptr);
2920
2921 m_errorMonitor->VerifyNotFound();
2922
2923 // Force device idle and clean up remaining objects
2924 vkDeviceWaitIdle(m_device->device());
2925 vkDestroySemaphore(m_device->device(), s2, nullptr);
2926 vkDestroyFence(m_device->device(), fence, nullptr);
2927}
2928
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002929TEST_F(VkLayerTest, FenceCreateSignaledWaitHandling) {
Chris Forbes4e44c912016-06-16 10:20:00 +12002930 m_errorMonitor->ExpectSuccess();
2931
2932 ASSERT_NO_FATAL_FAILURE(InitState());
2933 VkResult err;
2934
2935 // A fence created signaled
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002936 VkFenceCreateInfo fci1 = {VK_STRUCTURE_TYPE_FENCE_CREATE_INFO, nullptr, VK_FENCE_CREATE_SIGNALED_BIT};
Chris Forbes4e44c912016-06-16 10:20:00 +12002937 VkFence f1;
2938 err = vkCreateFence(m_device->device(), &fci1, nullptr, &f1);
2939 ASSERT_VK_SUCCESS(err);
2940
2941 // A fence created not
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002942 VkFenceCreateInfo fci2 = {VK_STRUCTURE_TYPE_FENCE_CREATE_INFO, nullptr, 0};
Chris Forbes4e44c912016-06-16 10:20:00 +12002943 VkFence f2;
2944 err = vkCreateFence(m_device->device(), &fci2, nullptr, &f2);
2945 ASSERT_VK_SUCCESS(err);
2946
2947 // Submit the unsignaled fence
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002948 VkSubmitInfo si = {VK_STRUCTURE_TYPE_SUBMIT_INFO, nullptr, 0, nullptr, nullptr, 0, nullptr, 0, nullptr};
Chris Forbes4e44c912016-06-16 10:20:00 +12002949 err = vkQueueSubmit(m_device->m_queue, 1, &si, f2);
2950
2951 // Wait on both fences, with signaled first.
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002952 VkFence fences[] = {f1, f2};
Chris Forbes4e44c912016-06-16 10:20:00 +12002953 vkWaitForFences(m_device->device(), 2, fences, VK_TRUE, UINT64_MAX);
2954
2955 // Should have both retired!
2956 vkDestroyFence(m_device->device(), f1, nullptr);
2957 vkDestroyFence(m_device->device(), f2, nullptr);
2958
2959 m_errorMonitor->VerifyNotFound();
2960}
2961
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002962TEST_F(VkLayerTest, InvalidUsageBits) {
2963 TEST_DESCRIPTION("Specify wrong usage for image then create conflicting view of image "
2964 "Initialize buffer with wrong usage then perform copy expecting errors "
2965 "from both the image and the buffer (2 calls)");
2966 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Invalid usage flag for image ");
Tobin Ehlis41376e12015-07-03 08:45:14 -06002967
2968 ASSERT_NO_FATAL_FAILURE(InitState());
Tony Barbourf92621a2016-05-02 14:28:12 -06002969 VkImageObj image(m_device);
Tony Barbour75d79f02016-08-30 09:39:07 -06002970 // Initialize image with USAGE_TRANSIENT_ATTACHMENT
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002971 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 -06002972 ASSERT_TRUE(image.initialized());
Tobin Ehlis41376e12015-07-03 08:45:14 -06002973
Tony Barbourf92621a2016-05-02 14:28:12 -06002974 VkImageView dsv;
2975 VkImageViewCreateInfo dsvci = {};
2976 dsvci.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
2977 dsvci.image = image.handle();
2978 dsvci.viewType = VK_IMAGE_VIEW_TYPE_2D;
2979 dsvci.format = VK_FORMAT_D32_SFLOAT_S8_UINT;
2980 dsvci.subresourceRange.layerCount = 1;
2981 dsvci.subresourceRange.baseMipLevel = 0;
2982 dsvci.subresourceRange.levelCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002983 dsvci.subresourceRange.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT;
Tobin Ehlis41376e12015-07-03 08:45:14 -06002984
Tony Barbourf92621a2016-05-02 14:28:12 -06002985 // Create a view with depth / stencil aspect for image with different usage
2986 vkCreateImageView(m_device->device(), &dsvci, NULL, &dsv);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06002987
Chris Forbes8f36a8a2016-04-07 13:21:07 +12002988 m_errorMonitor->VerifyFound();
Tony Barbourf92621a2016-05-02 14:28:12 -06002989
2990 // Initialize buffer with TRANSFER_DST usage
2991 vk_testing::Buffer buffer;
2992 VkMemoryPropertyFlags reqs = 0;
2993 buffer.init_as_dst(*m_device, 128 * 128, reqs);
2994 VkBufferImageCopy region = {};
2995 region.bufferRowLength = 128;
2996 region.bufferImageHeight = 128;
2997 region.imageSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
2998 region.imageSubresource.layerCount = 1;
2999 region.imageExtent.height = 16;
3000 region.imageExtent.width = 16;
3001 region.imageExtent.depth = 1;
3002
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003003 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Invalid usage flag for buffer ");
Tony Barbourf92621a2016-05-02 14:28:12 -06003004 // Buffer usage not set to TRANSFER_SRC and image usage not set to
3005 // TRANSFER_DST
3006 BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003007 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer.handle(), image.handle(),
3008 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, &region);
Tony Barbourf92621a2016-05-02 14:28:12 -06003009 m_errorMonitor->VerifyFound();
3010
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003011 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Invalid usage flag for image ");
3012 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer.handle(), image.handle(),
3013 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, &region);
Tony Barbourf92621a2016-05-02 14:28:12 -06003014 m_errorMonitor->VerifyFound();
Tobin Ehlis41376e12015-07-03 08:45:14 -06003015}
Tony Barbour75d79f02016-08-30 09:39:07 -06003016
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003017TEST_F(VkLayerTest, ValidUsage) {
3018 TEST_DESCRIPTION("Verify that creating an image view from an image with valid usage "
3019 "doesn't generate validation errors");
Tony Barbour75d79f02016-08-30 09:39:07 -06003020
3021 ASSERT_NO_FATAL_FAILURE(InitState());
3022
3023 m_errorMonitor->ExpectSuccess();
3024 // Verify that we can create a view with usage INPUT_ATTACHMENT
3025 VkImageObj image(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003026 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 -06003027 ASSERT_TRUE(image.initialized());
3028 VkImageView imageView;
3029 VkImageViewCreateInfo ivci = {};
3030 ivci.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
3031 ivci.image = image.handle();
3032 ivci.viewType = VK_IMAGE_VIEW_TYPE_2D;
3033 ivci.format = VK_FORMAT_R8G8B8A8_UNORM;
3034 ivci.subresourceRange.layerCount = 1;
3035 ivci.subresourceRange.baseMipLevel = 0;
3036 ivci.subresourceRange.levelCount = 1;
3037 ivci.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
3038
3039 vkCreateImageView(m_device->device(), &ivci, NULL, &imageView);
3040 m_errorMonitor->VerifyNotFound();
3041 vkDestroyImageView(m_device->device(), imageView, NULL);
3042}
Mark Lobodzinski209b5292015-09-17 09:44:05 -06003043#endif // MEM_TRACKER_TESTS
3044
Tobin Ehlis4bf96d12015-06-25 11:58:41 -06003045#if OBJ_TRACKER_TESTS
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06003046
3047TEST_F(VkLayerTest, LeakAnObject) {
3048 VkResult err;
3049
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003050 TEST_DESCRIPTION("Create a fence and destroy its device without first destroying the fence.");
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06003051
3052 // Note that we have to create a new device since destroying the
3053 // framework's device causes Teardown() to fail and just calling Teardown
3054 // will destroy the errorMonitor.
3055
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003056 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "has not been destroyed.");
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06003057
3058 ASSERT_NO_FATAL_FAILURE(InitState());
3059
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003060 const std::vector<VkQueueFamilyProperties> queue_props = m_device->queue_props;
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06003061 std::vector<VkDeviceQueueCreateInfo> queue_info;
3062 queue_info.reserve(queue_props.size());
3063 std::vector<std::vector<float>> queue_priorities;
3064 for (uint32_t i = 0; i < (uint32_t)queue_props.size(); i++) {
3065 VkDeviceQueueCreateInfo qi = {};
3066 qi.sType = VK_STRUCTURE_TYPE_DEVICE_QUEUE_CREATE_INFO;
3067 qi.pNext = NULL;
3068 qi.queueFamilyIndex = i;
3069 qi.queueCount = queue_props[i].queueCount;
3070 queue_priorities.emplace_back(qi.queueCount, 0.0f);
3071 qi.pQueuePriorities = queue_priorities[i].data();
3072 queue_info.push_back(qi);
3073 }
3074
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06003075 std::vector<const char *> device_extension_names;
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06003076
3077 // The sacrificial device object
3078 VkDevice testDevice;
3079 VkDeviceCreateInfo device_create_info = {};
3080 auto features = m_device->phy().features();
3081 device_create_info.sType = VK_STRUCTURE_TYPE_DEVICE_CREATE_INFO;
3082 device_create_info.pNext = NULL;
3083 device_create_info.queueCreateInfoCount = queue_info.size();
3084 device_create_info.pQueueCreateInfos = queue_info.data();
Tony Barbour4c70d102016-08-08 16:06:56 -06003085 device_create_info.enabledLayerCount = 0;
3086 device_create_info.ppEnabledLayerNames = NULL;
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06003087 device_create_info.pEnabledFeatures = &features;
3088 err = vkCreateDevice(gpu(), &device_create_info, NULL, &testDevice);
3089 ASSERT_VK_SUCCESS(err);
3090
3091 VkFence fence;
3092 VkFenceCreateInfo fence_create_info = {};
3093 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
3094 fence_create_info.pNext = NULL;
3095 fence_create_info.flags = 0;
3096 err = vkCreateFence(testDevice, &fence_create_info, NULL, &fence);
3097 ASSERT_VK_SUCCESS(err);
3098
3099 // Induce failure by not calling vkDestroyFence
3100 vkDestroyDevice(testDevice, NULL);
3101 m_errorMonitor->VerifyFound();
3102}
3103
3104TEST_F(VkLayerTest, InvalidCommandPoolConsistency) {
3105
3106 TEST_DESCRIPTION("Allocate command buffers from one command pool and "
3107 "attempt to delete them from another.");
3108
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003109 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "FreeCommandBuffers is attempting to free Command Buffer");
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06003110
Cody Northropc31a84f2016-08-22 10:41:47 -06003111 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06003112 VkCommandPool command_pool_one;
3113 VkCommandPool command_pool_two;
3114
3115 VkCommandPoolCreateInfo pool_create_info{};
3116 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
3117 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
3118 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
3119
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003120 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool_one);
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06003121
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003122 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool_two);
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06003123
3124 VkCommandBuffer command_buffer[9];
3125 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003126 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06003127 command_buffer_allocate_info.commandPool = command_pool_one;
3128 command_buffer_allocate_info.commandBufferCount = 9;
3129 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003130 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, command_buffer);
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06003131
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003132 vkFreeCommandBuffers(m_device->device(), command_pool_two, 4, &command_buffer[3]);
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06003133
3134 m_errorMonitor->VerifyFound();
3135
3136 vkDestroyCommandPool(m_device->device(), command_pool_one, NULL);
3137 vkDestroyCommandPool(m_device->device(), command_pool_two, NULL);
3138}
3139
3140TEST_F(VkLayerTest, InvalidDescriptorPoolConsistency) {
3141 VkResult err;
3142
3143 TEST_DESCRIPTION("Allocate descriptor sets from one DS pool and "
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003144 "attempt to delete them from another.");
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06003145
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003146 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "FreeDescriptorSets is attempting to free descriptorSet");
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06003147
3148 ASSERT_NO_FATAL_FAILURE(InitState());
3149 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
3150
3151 VkDescriptorPoolSize ds_type_count = {};
3152 ds_type_count.type = VK_DESCRIPTOR_TYPE_SAMPLER;
3153 ds_type_count.descriptorCount = 1;
3154
3155 VkDescriptorPoolCreateInfo ds_pool_ci = {};
3156 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
3157 ds_pool_ci.pNext = NULL;
3158 ds_pool_ci.flags = 0;
3159 ds_pool_ci.maxSets = 1;
3160 ds_pool_ci.poolSizeCount = 1;
3161 ds_pool_ci.pPoolSizes = &ds_type_count;
3162
3163 VkDescriptorPool ds_pool_one;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003164 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool_one);
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06003165 ASSERT_VK_SUCCESS(err);
3166
3167 // Create a second descriptor pool
3168 VkDescriptorPool ds_pool_two;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003169 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool_two);
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06003170 ASSERT_VK_SUCCESS(err);
3171
3172 VkDescriptorSetLayoutBinding dsl_binding = {};
3173 dsl_binding.binding = 0;
3174 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
3175 dsl_binding.descriptorCount = 1;
3176 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
3177 dsl_binding.pImmutableSamplers = NULL;
3178
3179 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
3180 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
3181 ds_layout_ci.pNext = NULL;
3182 ds_layout_ci.bindingCount = 1;
3183 ds_layout_ci.pBindings = &dsl_binding;
3184
3185 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003186 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06003187 ASSERT_VK_SUCCESS(err);
3188
3189 VkDescriptorSet descriptorSet;
3190 VkDescriptorSetAllocateInfo alloc_info = {};
3191 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
3192 alloc_info.descriptorSetCount = 1;
3193 alloc_info.descriptorPool = ds_pool_one;
3194 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003195 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06003196 ASSERT_VK_SUCCESS(err);
3197
3198 err = vkFreeDescriptorSets(m_device->device(), ds_pool_two, 1, &descriptorSet);
3199
3200 m_errorMonitor->VerifyFound();
3201
3202 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
3203 vkDestroyDescriptorPool(m_device->device(), ds_pool_one, NULL);
3204 vkDestroyDescriptorPool(m_device->device(), ds_pool_two, NULL);
3205}
3206
3207TEST_F(VkLayerTest, CreateUnknownObject) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003208 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Invalid Image Object ");
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06003209
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003210 TEST_DESCRIPTION("Pass an invalid image object handle into a Vulkan API call.");
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06003211
3212 ASSERT_NO_FATAL_FAILURE(InitState());
3213
3214 // Pass bogus handle into GetImageMemoryRequirements
3215 VkMemoryRequirements mem_reqs;
3216 uint64_t fakeImageHandle = 0xCADECADE;
3217 VkImage fauxImage = reinterpret_cast<VkImage &>(fakeImageHandle);
3218
3219 vkGetImageMemoryRequirements(m_device->device(), fauxImage, &mem_reqs);
3220
3221 m_errorMonitor->VerifyFound();
3222}
3223
Karl Schultz6addd812016-02-02 17:17:23 -07003224TEST_F(VkLayerTest, PipelineNotBound) {
3225 VkResult err;
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06003226
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003227 TEST_DESCRIPTION("Pass in an invalid pipeline object handle into a Vulkan API call.");
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06003228
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003229 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Invalid Pipeline Object ");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06003230
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06003231 ASSERT_NO_FATAL_FAILURE(InitState());
3232 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06003233
Chia-I Wu1b99bb22015-10-27 19:25:11 +08003234 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07003235 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
3236 ds_type_count.descriptorCount = 1;
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06003237
3238 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07003239 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
3240 ds_pool_ci.pNext = NULL;
3241 ds_pool_ci.maxSets = 1;
3242 ds_pool_ci.poolSizeCount = 1;
3243 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06003244
3245 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003246 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06003247 ASSERT_VK_SUCCESS(err);
3248
3249 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07003250 dsl_binding.binding = 0;
3251 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
3252 dsl_binding.descriptorCount = 1;
3253 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
3254 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06003255
3256 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07003257 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
3258 ds_layout_ci.pNext = NULL;
3259 ds_layout_ci.bindingCount = 1;
3260 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06003261
3262 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003263 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06003264 ASSERT_VK_SUCCESS(err);
3265
3266 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08003267 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08003268 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07003269 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06003270 alloc_info.descriptorPool = ds_pool;
3271 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003272 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06003273 ASSERT_VK_SUCCESS(err);
3274
3275 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07003276 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
3277 pipeline_layout_ci.pNext = NULL;
3278 pipeline_layout_ci.setLayoutCount = 1;
3279 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06003280
3281 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003282 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06003283 ASSERT_VK_SUCCESS(err);
3284
Mark Youngad779052016-01-06 14:26:04 -07003285 VkPipeline badPipeline = (VkPipeline)((size_t)0xbaadb1be);
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06003286
3287 BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003288 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, badPipeline);
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06003289
Chris Forbes8f36a8a2016-04-07 13:21:07 +12003290 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06003291
Chia-I Wuf7458c52015-10-26 21:10:41 +08003292 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
3293 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
3294 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlisec598302015-09-15 15:02:17 -06003295}
Mike Stroyan80fc6c32016-06-20 15:42:29 -06003296
Mark Lobodzinskibc185762016-06-15 16:28:53 -06003297TEST_F(VkLayerTest, BindImageInvalidMemoryType) {
3298 VkResult err;
3299
3300 TEST_DESCRIPTION("Test validation check for an invalid memory type index "
3301 "during bind[Buffer|Image]Memory time");
3302
Mark Lobodzinskibc185762016-06-15 16:28:53 -06003303 ASSERT_NO_FATAL_FAILURE(InitState());
3304
3305 // Create an image, allocate memory, set a bad typeIndex and then try to
3306 // bind it
3307 VkImage image;
3308 VkDeviceMemory mem;
3309 VkMemoryRequirements mem_reqs;
3310 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
3311 const int32_t tex_width = 32;
3312 const int32_t tex_height = 32;
3313
3314 VkImageCreateInfo image_create_info = {};
3315 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
3316 image_create_info.pNext = NULL;
3317 image_create_info.imageType = VK_IMAGE_TYPE_2D;
3318 image_create_info.format = tex_format;
3319 image_create_info.extent.width = tex_width;
3320 image_create_info.extent.height = tex_height;
3321 image_create_info.extent.depth = 1;
3322 image_create_info.mipLevels = 1;
3323 image_create_info.arrayLayers = 1;
3324 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
3325 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
3326 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
3327 image_create_info.flags = 0;
3328
3329 VkMemoryAllocateInfo mem_alloc = {};
3330 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
3331 mem_alloc.pNext = NULL;
3332 mem_alloc.allocationSize = 0;
3333 mem_alloc.memoryTypeIndex = 0;
3334
3335 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
3336 ASSERT_VK_SUCCESS(err);
3337
3338 vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs);
3339 mem_alloc.allocationSize = mem_reqs.size;
Mike Stroyan80fc6c32016-06-20 15:42:29 -06003340
3341 // Introduce Failure, select invalid TypeIndex
3342 VkPhysicalDeviceMemoryProperties memory_info;
3343
3344 vkGetPhysicalDeviceMemoryProperties(gpu(), &memory_info);
3345 unsigned int i;
3346 for (i = 0; i < memory_info.memoryTypeCount; i++) {
3347 if ((mem_reqs.memoryTypeBits & (1 << i)) == 0) {
3348 mem_alloc.memoryTypeIndex = i;
3349 break;
3350 }
3351 }
3352 if (i >= memory_info.memoryTypeCount) {
3353 printf("No invalid memory type index could be found; skipped.\n");
3354 vkDestroyImage(m_device->device(), image, NULL);
3355 return;
3356 }
3357
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003358 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 -06003359
3360 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem);
3361 ASSERT_VK_SUCCESS(err);
3362
3363 err = vkBindImageMemory(m_device->device(), image, mem, 0);
3364 (void)err;
3365
3366 m_errorMonitor->VerifyFound();
3367
3368 vkDestroyImage(m_device->device(), image, NULL);
3369 vkFreeMemory(m_device->device(), mem, NULL);
3370}
Mike Stroyan80fc6c32016-06-20 15:42:29 -06003371
Karl Schultz6addd812016-02-02 17:17:23 -07003372TEST_F(VkLayerTest, BindInvalidMemory) {
3373 VkResult err;
3374 bool pass;
Tobin Ehlisec598302015-09-15 15:02:17 -06003375
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003376 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Invalid Device Memory Object ");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06003377
Tobin Ehlisec598302015-09-15 15:02:17 -06003378 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisec598302015-09-15 15:02:17 -06003379
3380 // Create an image, allocate memory, free it, and then try to bind it
Karl Schultz6addd812016-02-02 17:17:23 -07003381 VkImage image;
3382 VkDeviceMemory mem;
3383 VkMemoryRequirements mem_reqs;
Tobin Ehlisec598302015-09-15 15:02:17 -06003384
Karl Schultz6addd812016-02-02 17:17:23 -07003385 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
3386 const int32_t tex_width = 32;
3387 const int32_t tex_height = 32;
Tobin Ehlisec598302015-09-15 15:02:17 -06003388
3389 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -07003390 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
3391 image_create_info.pNext = NULL;
3392 image_create_info.imageType = VK_IMAGE_TYPE_2D;
3393 image_create_info.format = tex_format;
3394 image_create_info.extent.width = tex_width;
3395 image_create_info.extent.height = tex_height;
3396 image_create_info.extent.depth = 1;
3397 image_create_info.mipLevels = 1;
3398 image_create_info.arrayLayers = 1;
3399 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
3400 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
3401 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
3402 image_create_info.flags = 0;
Tobin Ehlisec598302015-09-15 15:02:17 -06003403
Chia-I Wu3432a0c2015-10-27 18:04:07 +08003404 VkMemoryAllocateInfo mem_alloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -07003405 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
3406 mem_alloc.pNext = NULL;
3407 mem_alloc.allocationSize = 0;
3408 mem_alloc.memoryTypeIndex = 0;
Tobin Ehlisec598302015-09-15 15:02:17 -06003409
Chia-I Wuf7458c52015-10-26 21:10:41 +08003410 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
Tobin Ehlisec598302015-09-15 15:02:17 -06003411 ASSERT_VK_SUCCESS(err);
3412
Karl Schultz6addd812016-02-02 17:17:23 -07003413 vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs);
Tobin Ehlisec598302015-09-15 15:02:17 -06003414
3415 mem_alloc.allocationSize = mem_reqs.size;
3416
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003417 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -06003418 ASSERT_TRUE(pass);
Tobin Ehlisec598302015-09-15 15:02:17 -06003419
3420 // allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +08003421 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem);
Tobin Ehlisec598302015-09-15 15:02:17 -06003422 ASSERT_VK_SUCCESS(err);
3423
3424 // Introduce validation failure, free memory before binding
Chia-I Wuf7458c52015-10-26 21:10:41 +08003425 vkFreeMemory(m_device->device(), mem, NULL);
Tobin Ehlisec598302015-09-15 15:02:17 -06003426
3427 // Try to bind free memory that has been freed
3428 err = vkBindImageMemory(m_device->device(), image, mem, 0);
3429 // This may very well return an error.
3430 (void)err;
3431
Chris Forbes8f36a8a2016-04-07 13:21:07 +12003432 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06003433
Chia-I Wuf7458c52015-10-26 21:10:41 +08003434 vkDestroyImage(m_device->device(), image, NULL);
Tobin Ehlisec598302015-09-15 15:02:17 -06003435}
3436
Karl Schultz6addd812016-02-02 17:17:23 -07003437TEST_F(VkLayerTest, BindMemoryToDestroyedObject) {
3438 VkResult err;
3439 bool pass;
Tobin Ehlisec598302015-09-15 15:02:17 -06003440
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003441 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Invalid Image Object ");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06003442
Tobin Ehlisec598302015-09-15 15:02:17 -06003443 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisec598302015-09-15 15:02:17 -06003444
Karl Schultz6addd812016-02-02 17:17:23 -07003445 // Create an image object, allocate memory, destroy the object and then try
3446 // to bind it
3447 VkImage image;
3448 VkDeviceMemory mem;
3449 VkMemoryRequirements mem_reqs;
Tobin Ehlisec598302015-09-15 15:02:17 -06003450
Karl Schultz6addd812016-02-02 17:17:23 -07003451 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
3452 const int32_t tex_width = 32;
3453 const int32_t tex_height = 32;
Tobin Ehlisec598302015-09-15 15:02:17 -06003454
3455 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -07003456 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
3457 image_create_info.pNext = NULL;
3458 image_create_info.imageType = VK_IMAGE_TYPE_2D;
3459 image_create_info.format = tex_format;
3460 image_create_info.extent.width = tex_width;
3461 image_create_info.extent.height = tex_height;
3462 image_create_info.extent.depth = 1;
3463 image_create_info.mipLevels = 1;
3464 image_create_info.arrayLayers = 1;
3465 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
3466 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
3467 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
3468 image_create_info.flags = 0;
Tobin Ehlisec598302015-09-15 15:02:17 -06003469
Chia-I Wu3432a0c2015-10-27 18:04:07 +08003470 VkMemoryAllocateInfo mem_alloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -07003471 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
3472 mem_alloc.pNext = NULL;
3473 mem_alloc.allocationSize = 0;
3474 mem_alloc.memoryTypeIndex = 0;
Tobin Ehlisec598302015-09-15 15:02:17 -06003475
Chia-I Wuf7458c52015-10-26 21:10:41 +08003476 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
Tobin Ehlisec598302015-09-15 15:02:17 -06003477 ASSERT_VK_SUCCESS(err);
3478
Karl Schultz6addd812016-02-02 17:17:23 -07003479 vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs);
Tobin Ehlisec598302015-09-15 15:02:17 -06003480
3481 mem_alloc.allocationSize = mem_reqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003482 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -06003483 ASSERT_TRUE(pass);
Tobin Ehlisec598302015-09-15 15:02:17 -06003484
3485 // Allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +08003486 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem);
Tobin Ehlisec598302015-09-15 15:02:17 -06003487 ASSERT_VK_SUCCESS(err);
3488
3489 // Introduce validation failure, destroy Image object before binding
Chia-I Wuf7458c52015-10-26 21:10:41 +08003490 vkDestroyImage(m_device->device(), image, NULL);
Tobin Ehlisec598302015-09-15 15:02:17 -06003491 ASSERT_VK_SUCCESS(err);
3492
3493 // Now Try to bind memory to this destroyed object
3494 err = vkBindImageMemory(m_device->device(), image, mem, 0);
3495 // This may very well return an error.
Karl Schultz6addd812016-02-02 17:17:23 -07003496 (void)err;
Tobin Ehlisec598302015-09-15 15:02:17 -06003497
Chris Forbes8f36a8a2016-04-07 13:21:07 +12003498 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06003499
Chia-I Wuf7458c52015-10-26 21:10:41 +08003500 vkFreeMemory(m_device->device(), mem, NULL);
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06003501}
Tobin Ehlisa1c28562015-10-23 16:00:08 -06003502
Mark Lobodzinski209b5292015-09-17 09:44:05 -06003503#endif // OBJ_TRACKER_TESTS
3504
Tobin Ehlis0788f522015-05-26 16:11:58 -06003505#if DRAW_STATE_TESTS
Mark Lobodzinskic808d442016-04-14 10:57:23 -06003506
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06003507TEST_F(VkLayerTest, ImageSampleCounts) {
3508
3509 TEST_DESCRIPTION("Use bad sample counts in image transfer calls to trigger "
3510 "validation errors.");
3511 ASSERT_NO_FATAL_FAILURE(InitState());
3512
3513 VkMemoryPropertyFlags reqs = 0;
3514 VkImageCreateInfo image_create_info = {};
3515 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
3516 image_create_info.pNext = NULL;
3517 image_create_info.imageType = VK_IMAGE_TYPE_2D;
3518 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
3519 image_create_info.extent.width = 256;
3520 image_create_info.extent.height = 256;
3521 image_create_info.extent.depth = 1;
3522 image_create_info.mipLevels = 1;
3523 image_create_info.arrayLayers = 1;
3524 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
3525 image_create_info.flags = 0;
3526
3527 VkImageBlit blit_region = {};
3528 blit_region.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
3529 blit_region.srcSubresource.baseArrayLayer = 0;
3530 blit_region.srcSubresource.layerCount = 1;
3531 blit_region.srcSubresource.mipLevel = 0;
3532 blit_region.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
3533 blit_region.dstSubresource.baseArrayLayer = 0;
3534 blit_region.dstSubresource.layerCount = 1;
3535 blit_region.dstSubresource.mipLevel = 0;
3536
3537 // Create two images, the source with sampleCount = 2, and attempt to blit
3538 // between them
3539 {
3540 image_create_info.samples = VK_SAMPLE_COUNT_2_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003541 image_create_info.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06003542 vk_testing::Image src_image;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003543 src_image.init(*m_device, (const VkImageCreateInfo &)image_create_info, reqs);
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06003544 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003545 image_create_info.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT;
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06003546 vk_testing::Image dst_image;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003547 dst_image.init(*m_device, (const VkImageCreateInfo &)image_create_info, reqs);
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06003548 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003549 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "was created with a sample count "
3550 "of VK_SAMPLE_COUNT_2_BIT but "
3551 "must be VK_SAMPLE_COUNT_1_BIT");
3552 vkCmdBlitImage(m_commandBuffer->GetBufferHandle(), src_image.handle(), VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
3553 dst_image.handle(), VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL, 1, &blit_region, VK_FILTER_NEAREST);
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06003554 m_errorMonitor->VerifyFound();
3555 m_commandBuffer->EndCommandBuffer();
3556 }
3557
3558 // Create two images, the dest with sampleCount = 4, and attempt to blit
3559 // between them
3560 {
3561 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003562 image_create_info.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06003563 vk_testing::Image src_image;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003564 src_image.init(*m_device, (const VkImageCreateInfo &)image_create_info, reqs);
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06003565 image_create_info.samples = VK_SAMPLE_COUNT_4_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003566 image_create_info.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT;
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06003567 vk_testing::Image dst_image;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003568 dst_image.init(*m_device, (const VkImageCreateInfo &)image_create_info, reqs);
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06003569 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003570 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "was created with a sample count "
3571 "of VK_SAMPLE_COUNT_4_BIT but "
3572 "must be VK_SAMPLE_COUNT_1_BIT");
3573 vkCmdBlitImage(m_commandBuffer->GetBufferHandle(), src_image.handle(), VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
3574 dst_image.handle(), VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL, 1, &blit_region, VK_FILTER_NEAREST);
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06003575 m_errorMonitor->VerifyFound();
3576 m_commandBuffer->EndCommandBuffer();
3577 }
3578
3579 VkBufferImageCopy copy_region = {};
3580 copy_region.bufferRowLength = 128;
3581 copy_region.bufferImageHeight = 128;
3582 copy_region.imageSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
3583 copy_region.imageSubresource.layerCount = 1;
3584 copy_region.imageExtent.height = 64;
3585 copy_region.imageExtent.width = 64;
3586 copy_region.imageExtent.depth = 1;
3587
3588 // Create src buffer and dst image with sampleCount = 4 and attempt to copy
3589 // buffer to image
3590 {
3591 vk_testing::Buffer src_buffer;
3592 VkMemoryPropertyFlags reqs = 0;
3593 src_buffer.init_as_src(*m_device, 128 * 128 * 4, reqs);
3594 image_create_info.samples = VK_SAMPLE_COUNT_8_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003595 image_create_info.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT;
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06003596 vk_testing::Image dst_image;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003597 dst_image.init(*m_device, (const VkImageCreateInfo &)image_create_info, reqs);
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06003598 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003599 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "was created with a sample count "
3600 "of VK_SAMPLE_COUNT_8_BIT but "
3601 "must be VK_SAMPLE_COUNT_1_BIT");
3602 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), src_buffer.handle(), dst_image.handle(),
3603 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, &copy_region);
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06003604 m_errorMonitor->VerifyFound();
3605 m_commandBuffer->EndCommandBuffer();
3606 }
3607
3608 // Create dst buffer and src image with sampleCount = 2 and attempt to copy
3609 // image to buffer
3610 {
3611 vk_testing::Buffer dst_buffer;
3612 dst_buffer.init_as_dst(*m_device, 128 * 128 * 4, reqs);
3613 image_create_info.samples = VK_SAMPLE_COUNT_2_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003614 image_create_info.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06003615 vk_testing::Image src_image;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003616 src_image.init(*m_device, (const VkImageCreateInfo &)image_create_info, reqs);
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06003617 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003618 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "was created with a sample count "
3619 "of VK_SAMPLE_COUNT_2_BIT but "
3620 "must be VK_SAMPLE_COUNT_1_BIT");
3621 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), src_image.handle(), VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL,
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06003622 dst_buffer.handle(), 1, &copy_region);
3623 m_errorMonitor->VerifyFound();
3624 m_commandBuffer->EndCommandBuffer();
3625 }
3626}
3627
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06003628TEST_F(VkLayerTest, DSImageTransferGranularityTests) {
3629 VkResult err;
3630 bool pass;
3631
3632 TEST_DESCRIPTION("Tests for validaiton of Queue Family property minImageTransferGranularity.");
3633 ASSERT_NO_FATAL_FAILURE(InitState());
3634
3635 // If w/d/h granularity is 1, test is not meaningful
3636 // TODO: When virtual device limits are available, create a set of limits for this test that
3637 // will always have a granularity of > 1 for w, h, and d
3638 auto index = m_device->graphics_queue_node_index_;
3639 auto queue_family_properties = m_device->phy().queue_properties();
3640
3641 if ((queue_family_properties[index].minImageTransferGranularity.depth < 4) ||
3642 (queue_family_properties[index].minImageTransferGranularity.width < 4) ||
3643 (queue_family_properties[index].minImageTransferGranularity.height < 4)) {
3644 return;
3645 }
3646
3647 // Create two images of different types and try to copy between them
3648 VkImage srcImage;
3649 VkImage dstImage;
3650 VkDeviceMemory srcMem;
3651 VkDeviceMemory destMem;
3652 VkMemoryRequirements memReqs;
3653
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06003654 VkImageCreateInfo image_create_info = {};
3655 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
3656 image_create_info.pNext = NULL;
3657 image_create_info.imageType = VK_IMAGE_TYPE_2D;
3658 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
3659 image_create_info.extent.width = 32;
3660 image_create_info.extent.height = 32;
3661 image_create_info.extent.depth = 1;
3662 image_create_info.mipLevels = 1;
3663 image_create_info.arrayLayers = 4;
3664 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
3665 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
3666 image_create_info.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT;
3667 image_create_info.flags = 0;
3668
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003669 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06003670 ASSERT_VK_SUCCESS(err);
3671
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003672 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06003673 ASSERT_VK_SUCCESS(err);
3674
3675 // Allocate memory
3676 VkMemoryAllocateInfo memAlloc = {};
3677 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
3678 memAlloc.pNext = NULL;
3679 memAlloc.allocationSize = 0;
3680 memAlloc.memoryTypeIndex = 0;
3681
3682 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
3683 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003684 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06003685 ASSERT_TRUE(pass);
3686 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
3687 ASSERT_VK_SUCCESS(err);
3688
3689 vkGetImageMemoryRequirements(m_device->device(), dstImage, &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_VK_SUCCESS(err);
3693 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
3694 ASSERT_VK_SUCCESS(err);
3695
3696 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
3697 ASSERT_VK_SUCCESS(err);
3698 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
3699 ASSERT_VK_SUCCESS(err);
3700
3701 BeginCommandBuffer();
3702 VkImageCopy copyRegion;
3703 copyRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
3704 copyRegion.srcSubresource.mipLevel = 0;
3705 copyRegion.srcSubresource.baseArrayLayer = 0;
3706 copyRegion.srcSubresource.layerCount = 1;
3707 copyRegion.srcOffset.x = 0;
3708 copyRegion.srcOffset.y = 0;
3709 copyRegion.srcOffset.z = 0;
3710 copyRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
3711 copyRegion.dstSubresource.mipLevel = 0;
3712 copyRegion.dstSubresource.baseArrayLayer = 0;
3713 copyRegion.dstSubresource.layerCount = 1;
3714 copyRegion.dstOffset.x = 0;
3715 copyRegion.dstOffset.y = 0;
3716 copyRegion.dstOffset.z = 0;
3717 copyRegion.extent.width = 1;
3718 copyRegion.extent.height = 1;
3719 copyRegion.extent.depth = 1;
3720
3721 // Introduce failure by setting srcOffset to a bad granularity value
3722 copyRegion.srcOffset.y = 3;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003723 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "queue family image transfer granularity");
3724 m_commandBuffer->CopyImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, VK_IMAGE_LAYOUT_GENERAL, 1, &copyRegion);
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06003725 m_errorMonitor->VerifyFound();
3726
3727 // Introduce failure by setting extent to a bad granularity value
3728 copyRegion.srcOffset.y = 0;
3729 copyRegion.extent.width = 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 // Now do some buffer/image copies
3735 vk_testing::Buffer buffer;
3736 VkMemoryPropertyFlags reqs = 0;
3737 buffer.init_as_dst(*m_device, 128 * 128, reqs);
3738 VkBufferImageCopy region = {};
3739 region.bufferOffset = 0;
3740 region.bufferRowLength = 3;
3741 region.bufferImageHeight = 128;
3742 region.imageSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
3743 region.imageSubresource.layerCount = 1;
3744 region.imageExtent.height = 16;
3745 region.imageExtent.width = 16;
3746 region.imageExtent.depth = 1;
3747 region.imageOffset.x = 0;
3748 region.imageOffset.y = 0;
3749 region.imageOffset.z = 0;
3750
3751 // Introduce failure by setting bufferRowLength to a bad granularity value
3752 region.bufferRowLength = 3;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003753 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "queue family image transfer granularity");
3754 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer.handle(), srcImage, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1,
3755 &region);
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06003756 m_errorMonitor->VerifyFound();
3757 region.bufferRowLength = 128;
3758
3759 // Introduce failure by setting bufferOffset to a bad granularity value
3760 region.bufferOffset = 3;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003761 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "queue family image transfer granularity");
3762 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), srcImage, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, buffer.handle(), 1,
3763 &region);
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06003764 m_errorMonitor->VerifyFound();
3765 region.bufferOffset = 0;
3766
3767 // Introduce failure by setting bufferImageHeight to a bad granularity value
3768 region.bufferImageHeight = 3;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003769 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "queue family image transfer granularity");
3770 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), srcImage, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, buffer.handle(), 1,
3771 &region);
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06003772 m_errorMonitor->VerifyFound();
3773 region.bufferImageHeight = 128;
3774
3775 // Introduce failure by setting imageExtent to a bad granularity value
3776 region.imageExtent.width = 3;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003777 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "queue family image transfer granularity");
3778 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), srcImage, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, buffer.handle(), 1,
3779 &region);
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06003780 m_errorMonitor->VerifyFound();
3781 region.imageExtent.width = 16;
3782
3783 // Introduce failure by setting imageOffset to a bad granularity value
3784 region.imageOffset.z = 3;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003785 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "queue family image transfer granularity");
3786 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer.handle(), srcImage, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1,
3787 &region);
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06003788 m_errorMonitor->VerifyFound();
3789
3790 EndCommandBuffer();
3791
3792 vkDestroyImage(m_device->device(), srcImage, NULL);
3793 vkDestroyImage(m_device->device(), dstImage, NULL);
3794 vkFreeMemory(m_device->device(), srcMem, NULL);
3795 vkFreeMemory(m_device->device(), destMem, NULL);
3796}
3797
Mark Lobodzinski570efc62016-08-09 16:43:19 -06003798TEST_F(VkLayerTest, MismatchedQueueFamiliesOnSubmit) {
Mark Lobodzinski570efc62016-08-09 16:43:19 -06003799 TEST_DESCRIPTION("Submit command buffer created using one queue family and "
3800 "attempt to submit them on a queue created in a different "
3801 "queue family.");
3802
Cody Northropc31a84f2016-08-22 10:41:47 -06003803 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinski570efc62016-08-09 16:43:19 -06003804 // This test is meaningless unless we have multiple queue families
3805 auto queue_family_properties = m_device->phy().queue_properties();
3806 if (queue_family_properties.size() < 2) {
3807 return;
3808 }
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003809 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " is being submitted on queue ");
Mark Lobodzinski570efc62016-08-09 16:43:19 -06003810 // Get safe index of another queue family
3811 uint32_t other_queue_family = (m_device->graphics_queue_node_index_ == 0) ? 1 : 0;
3812 ASSERT_NO_FATAL_FAILURE(InitState());
3813 // Create a second queue using a different queue family
3814 VkQueue other_queue;
3815 vkGetDeviceQueue(m_device->device(), other_queue_family, 0, &other_queue);
3816
3817 // Record an empty cmd buffer
3818 VkCommandBufferBeginInfo cmdBufBeginDesc = {};
3819 cmdBufBeginDesc.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
3820 vkBeginCommandBuffer(m_commandBuffer->handle(), &cmdBufBeginDesc);
3821 vkEndCommandBuffer(m_commandBuffer->handle());
3822
3823 // And submit on the wrong queue
3824 VkSubmitInfo submit_info = {};
3825 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
3826 submit_info.commandBufferCount = 1;
3827 submit_info.pCommandBuffers = &m_commandBuffer->handle();
Tobin Ehlisfd213ea2016-08-10 17:10:46 -06003828 vkQueueSubmit(other_queue, 1, &submit_info, VK_NULL_HANDLE);
Mark Lobodzinski570efc62016-08-09 16:43:19 -06003829
3830 m_errorMonitor->VerifyFound();
Mark Lobodzinski570efc62016-08-09 16:43:19 -06003831}
3832
Chris Forbes48a53902016-06-30 11:46:27 +12003833TEST_F(VkLayerTest, RenderPassInitialLayoutUndefined) {
3834 TEST_DESCRIPTION("Ensure that CmdBeginRenderPass with an attachment's "
3835 "initialLayout of VK_IMAGE_LAYOUT_UNDEFINED works when "
3836 "the command buffer has prior knowledge of that "
3837 "attachment's layout.");
3838
3839 m_errorMonitor->ExpectSuccess();
3840
3841 ASSERT_NO_FATAL_FAILURE(InitState());
3842
3843 // A renderpass with one color attachment.
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003844 VkAttachmentDescription attachment = {0,
3845 VK_FORMAT_R8G8B8A8_UNORM,
3846 VK_SAMPLE_COUNT_1_BIT,
3847 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
3848 VK_ATTACHMENT_STORE_OP_STORE,
3849 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
3850 VK_ATTACHMENT_STORE_OP_DONT_CARE,
3851 VK_IMAGE_LAYOUT_UNDEFINED,
3852 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL};
Chris Forbes48a53902016-06-30 11:46:27 +12003853
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003854 VkAttachmentReference att_ref = {0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL};
Chris Forbes48a53902016-06-30 11:46:27 +12003855
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003856 VkSubpassDescription subpass = {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 1, &att_ref, nullptr, nullptr, 0, nullptr};
Chris Forbes48a53902016-06-30 11:46:27 +12003857
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003858 VkRenderPassCreateInfo rpci = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 1, &attachment, 1, &subpass, 0, nullptr};
Chris Forbes48a53902016-06-30 11:46:27 +12003859
3860 VkRenderPass rp;
3861 VkResult err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
3862 ASSERT_VK_SUCCESS(err);
3863
3864 // A compatible framebuffer.
3865 VkImageObj image(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003866 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 +12003867 ASSERT_TRUE(image.initialized());
3868
3869 VkImageViewCreateInfo ivci = {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003870 VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO,
3871 nullptr,
3872 0,
3873 image.handle(),
3874 VK_IMAGE_VIEW_TYPE_2D,
3875 VK_FORMAT_R8G8B8A8_UNORM,
3876 {VK_COMPONENT_SWIZZLE_IDENTITY, VK_COMPONENT_SWIZZLE_IDENTITY, VK_COMPONENT_SWIZZLE_IDENTITY,
3877 VK_COMPONENT_SWIZZLE_IDENTITY},
3878 {VK_IMAGE_ASPECT_COLOR_BIT, 0, 1, 0, 1},
Chris Forbes48a53902016-06-30 11:46:27 +12003879 };
3880 VkImageView view;
3881 err = vkCreateImageView(m_device->device(), &ivci, nullptr, &view);
3882 ASSERT_VK_SUCCESS(err);
3883
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003884 VkFramebufferCreateInfo fci = {VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr, 0, rp, 1, &view, 32, 32, 1};
Chris Forbes48a53902016-06-30 11:46:27 +12003885 VkFramebuffer fb;
3886 err = vkCreateFramebuffer(m_device->device(), &fci, nullptr, &fb);
3887 ASSERT_VK_SUCCESS(err);
3888
3889 // Record a single command buffer which uses this renderpass twice. The
3890 // bug is triggered at the beginning of the second renderpass, when the
3891 // command buffer already has a layout recorded for the attachment.
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003892 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 +12003893 BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003894 vkCmdBeginRenderPass(m_commandBuffer->handle(), &rpbi, VK_SUBPASS_CONTENTS_INLINE);
Chris Forbes48a53902016-06-30 11:46:27 +12003895 vkCmdEndRenderPass(m_commandBuffer->handle());
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003896 vkCmdBeginRenderPass(m_commandBuffer->handle(), &rpbi, VK_SUBPASS_CONTENTS_INLINE);
Chris Forbes48a53902016-06-30 11:46:27 +12003897
3898 m_errorMonitor->VerifyNotFound();
3899
3900 vkCmdEndRenderPass(m_commandBuffer->handle());
3901 EndCommandBuffer();
3902
3903 vkDestroyFramebuffer(m_device->device(), fb, nullptr);
3904 vkDestroyRenderPass(m_device->device(), rp, nullptr);
3905 vkDestroyImageView(m_device->device(), view, nullptr);
3906}
3907
Tobin Ehlis75ac37b2016-07-29 10:55:41 -06003908TEST_F(VkLayerTest, FramebufferBindingDestroyCommandPool) {
3909 TEST_DESCRIPTION("This test should pass. Create a Framebuffer and "
3910 "command buffer, bind them together, then destroy "
3911 "command pool and framebuffer and verify there are no "
3912 "errors.");
3913
3914 m_errorMonitor->ExpectSuccess();
3915
3916 ASSERT_NO_FATAL_FAILURE(InitState());
3917
3918 // A renderpass with one color attachment.
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003919 VkAttachmentDescription attachment = {0,
3920 VK_FORMAT_R8G8B8A8_UNORM,
3921 VK_SAMPLE_COUNT_1_BIT,
3922 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
3923 VK_ATTACHMENT_STORE_OP_STORE,
3924 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
3925 VK_ATTACHMENT_STORE_OP_DONT_CARE,
3926 VK_IMAGE_LAYOUT_UNDEFINED,
3927 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL};
Tobin Ehlis75ac37b2016-07-29 10:55:41 -06003928
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003929 VkAttachmentReference att_ref = {0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL};
Tobin Ehlis75ac37b2016-07-29 10:55:41 -06003930
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003931 VkSubpassDescription subpass = {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 1, &att_ref, nullptr, nullptr, 0, nullptr};
Tobin Ehlis75ac37b2016-07-29 10:55:41 -06003932
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003933 VkRenderPassCreateInfo rpci = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 1, &attachment, 1, &subpass, 0, nullptr};
Tobin Ehlis75ac37b2016-07-29 10:55:41 -06003934
3935 VkRenderPass rp;
3936 VkResult err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
3937 ASSERT_VK_SUCCESS(err);
3938
3939 // A compatible framebuffer.
3940 VkImageObj image(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003941 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 -06003942 ASSERT_TRUE(image.initialized());
3943
3944 VkImageViewCreateInfo ivci = {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003945 VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO,
3946 nullptr,
3947 0,
3948 image.handle(),
3949 VK_IMAGE_VIEW_TYPE_2D,
3950 VK_FORMAT_R8G8B8A8_UNORM,
3951 {VK_COMPONENT_SWIZZLE_IDENTITY, VK_COMPONENT_SWIZZLE_IDENTITY, VK_COMPONENT_SWIZZLE_IDENTITY,
3952 VK_COMPONENT_SWIZZLE_IDENTITY},
3953 {VK_IMAGE_ASPECT_COLOR_BIT, 0, 1, 0, 1},
Tobin Ehlis75ac37b2016-07-29 10:55:41 -06003954 };
3955 VkImageView view;
3956 err = vkCreateImageView(m_device->device(), &ivci, nullptr, &view);
3957 ASSERT_VK_SUCCESS(err);
3958
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003959 VkFramebufferCreateInfo fci = {VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr, 0, rp, 1, &view, 32, 32, 1};
Tobin Ehlis75ac37b2016-07-29 10:55:41 -06003960 VkFramebuffer fb;
3961 err = vkCreateFramebuffer(m_device->device(), &fci, nullptr, &fb);
3962 ASSERT_VK_SUCCESS(err);
3963
3964 // Explicitly create a command buffer to bind the FB to so that we can then
3965 // destroy the command pool in order to implicitly free command buffer
3966 VkCommandPool command_pool;
3967 VkCommandPoolCreateInfo pool_create_info{};
3968 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
3969 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
3970 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003971 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
Tobin Ehlis75ac37b2016-07-29 10:55:41 -06003972
3973 VkCommandBuffer command_buffer;
3974 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003975 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
Tobin Ehlis75ac37b2016-07-29 10:55:41 -06003976 command_buffer_allocate_info.commandPool = command_pool;
3977 command_buffer_allocate_info.commandBufferCount = 1;
3978 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003979 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, &command_buffer);
Tobin Ehlis75ac37b2016-07-29 10:55:41 -06003980
3981 // Begin our cmd buffer with renderpass using our framebuffer
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003982 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 -06003983 VkCommandBufferBeginInfo begin_info{};
3984 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
3985 vkBeginCommandBuffer(command_buffer, &begin_info);
3986
3987 vkCmdBeginRenderPass(command_buffer, &rpbi, VK_SUBPASS_CONTENTS_INLINE);
3988 vkCmdEndRenderPass(command_buffer);
3989 vkEndCommandBuffer(command_buffer);
Mark Lobodzinski7d10a822016-08-03 14:08:40 -06003990 vkDestroyImageView(m_device->device(), view, nullptr);
Tobin Ehlis75ac37b2016-07-29 10:55:41 -06003991 // Destroy command pool to implicitly free command buffer
3992 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
3993 vkDestroyFramebuffer(m_device->device(), fb, nullptr);
3994 vkDestroyRenderPass(m_device->device(), rp, nullptr);
3995 m_errorMonitor->VerifyNotFound();
3996}
3997
Chris Forbes51bf7c92016-06-30 15:22:08 +12003998TEST_F(VkLayerTest, RenderPassSubpassZeroTransitionsApplied) {
3999 TEST_DESCRIPTION("Ensure that CmdBeginRenderPass applies the layout "
4000 "transitions for the first subpass");
4001
4002 m_errorMonitor->ExpectSuccess();
4003
4004 ASSERT_NO_FATAL_FAILURE(InitState());
4005
4006 // A renderpass with one color attachment.
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004007 VkAttachmentDescription attachment = {0,
4008 VK_FORMAT_R8G8B8A8_UNORM,
4009 VK_SAMPLE_COUNT_1_BIT,
4010 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
4011 VK_ATTACHMENT_STORE_OP_STORE,
4012 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
4013 VK_ATTACHMENT_STORE_OP_DONT_CARE,
4014 VK_IMAGE_LAYOUT_UNDEFINED,
4015 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL};
Chris Forbes51bf7c92016-06-30 15:22:08 +12004016
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004017 VkAttachmentReference att_ref = {0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL};
Chris Forbes51bf7c92016-06-30 15:22:08 +12004018
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004019 VkSubpassDescription subpass = {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 1, &att_ref, nullptr, nullptr, 0, nullptr};
Chris Forbes51bf7c92016-06-30 15:22:08 +12004020
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004021 VkSubpassDependency dep = {0,
4022 0,
4023 VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT,
4024 VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT,
4025 VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT,
4026 VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT,
4027 VK_DEPENDENCY_BY_REGION_BIT};
Chris Forbes51bf7c92016-06-30 15:22:08 +12004028
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004029 VkRenderPassCreateInfo rpci = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 1, &attachment, 1, &subpass, 1, &dep};
Chris Forbes51bf7c92016-06-30 15:22:08 +12004030
4031 VkResult err;
4032 VkRenderPass rp;
4033 err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
4034 ASSERT_VK_SUCCESS(err);
4035
4036 // A compatible framebuffer.
4037 VkImageObj image(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004038 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 +12004039 ASSERT_TRUE(image.initialized());
4040
4041 VkImageViewCreateInfo ivci = {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004042 VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO,
4043 nullptr,
4044 0,
4045 image.handle(),
4046 VK_IMAGE_VIEW_TYPE_2D,
4047 VK_FORMAT_R8G8B8A8_UNORM,
4048 {VK_COMPONENT_SWIZZLE_IDENTITY, VK_COMPONENT_SWIZZLE_IDENTITY, VK_COMPONENT_SWIZZLE_IDENTITY,
4049 VK_COMPONENT_SWIZZLE_IDENTITY},
4050 {VK_IMAGE_ASPECT_COLOR_BIT, 0, 1, 0, 1},
Chris Forbes51bf7c92016-06-30 15:22:08 +12004051 };
4052 VkImageView view;
4053 err = vkCreateImageView(m_device->device(), &ivci, nullptr, &view);
4054 ASSERT_VK_SUCCESS(err);
4055
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004056 VkFramebufferCreateInfo fci = {VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr, 0, rp, 1, &view, 32, 32, 1};
Chris Forbes51bf7c92016-06-30 15:22:08 +12004057 VkFramebuffer fb;
4058 err = vkCreateFramebuffer(m_device->device(), &fci, nullptr, &fb);
4059 ASSERT_VK_SUCCESS(err);
4060
4061 // Record a single command buffer which issues a pipeline barrier w/
4062 // image memory barrier for the attachment. This detects the previously
4063 // missing tracking of the subpass layout by throwing a validation error
4064 // if it doesn't occur.
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004065 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 +12004066 BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004067 vkCmdBeginRenderPass(m_commandBuffer->handle(), &rpbi, VK_SUBPASS_CONTENTS_INLINE);
Chris Forbes51bf7c92016-06-30 15:22:08 +12004068
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004069 VkImageMemoryBarrier imb = {VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER,
4070 nullptr,
4071 VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT,
4072 VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT,
4073 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
4074 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
4075 VK_QUEUE_FAMILY_IGNORED,
4076 VK_QUEUE_FAMILY_IGNORED,
4077 image.handle(),
4078 {VK_IMAGE_ASPECT_COLOR_BIT, 0, 1, 0, 1}};
4079 vkCmdPipelineBarrier(m_commandBuffer->handle(), VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT,
4080 VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT, VK_DEPENDENCY_BY_REGION_BIT, 0, nullptr, 0, nullptr, 1,
4081 &imb);
Chris Forbes51bf7c92016-06-30 15:22:08 +12004082
4083 vkCmdEndRenderPass(m_commandBuffer->handle());
4084 m_errorMonitor->VerifyNotFound();
4085 EndCommandBuffer();
4086
4087 vkDestroyFramebuffer(m_device->device(), fb, nullptr);
4088 vkDestroyRenderPass(m_device->device(), rp, nullptr);
4089 vkDestroyImageView(m_device->device(), view, nullptr);
4090}
4091
Mark Lobodzinski77a5d6f2016-08-05 09:38:18 -06004092TEST_F(VkLayerTest, DepthStencilLayoutTransitionForDepthOnlyImageview) {
4093 TEST_DESCRIPTION("Validate that when an imageView of a depth/stencil image "
4094 "is used as a depth/stencil framebuffer attachment, the "
4095 "aspectMask is ignored and both depth and stencil image "
4096 "subresources are used.");
4097
4098 VkFormatProperties format_properties;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004099 vkGetPhysicalDeviceFormatProperties(gpu(), VK_FORMAT_D32_SFLOAT_S8_UINT, &format_properties);
4100 if (!(format_properties.optimalTilingFeatures & VK_FORMAT_FEATURE_SAMPLED_IMAGE_BIT)) {
Mark Lobodzinski77a5d6f2016-08-05 09:38:18 -06004101 return;
4102 }
4103
4104 m_errorMonitor->ExpectSuccess();
4105
4106 ASSERT_NO_FATAL_FAILURE(InitState());
4107
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004108 VkAttachmentDescription attachment = {0,
4109 VK_FORMAT_D32_SFLOAT_S8_UINT,
4110 VK_SAMPLE_COUNT_1_BIT,
4111 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
4112 VK_ATTACHMENT_STORE_OP_STORE,
4113 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
4114 VK_ATTACHMENT_STORE_OP_DONT_CARE,
4115 VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL,
4116 VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL};
Mark Lobodzinski77a5d6f2016-08-05 09:38:18 -06004117
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004118 VkAttachmentReference att_ref = {0, VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL};
Mark Lobodzinski77a5d6f2016-08-05 09:38:18 -06004119
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004120 VkSubpassDescription subpass = {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 0, nullptr, nullptr, &att_ref, 0, nullptr};
Mark Lobodzinski77a5d6f2016-08-05 09:38:18 -06004121
4122 VkSubpassDependency dep = {0,
4123 0,
4124 VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT,
4125 VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT,
4126 VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT,
4127 VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT,
4128 VK_DEPENDENCY_BY_REGION_BIT};
4129
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004130 VkRenderPassCreateInfo rpci = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 1, &attachment, 1, &subpass, 1, &dep};
Mark Lobodzinski77a5d6f2016-08-05 09:38:18 -06004131
4132 VkResult err;
4133 VkRenderPass rp;
4134 err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
4135 ASSERT_VK_SUCCESS(err);
4136
4137 VkImageObj image(m_device);
4138 image.init_no_layout(32, 32, VK_FORMAT_D32_SFLOAT_S8_UINT,
4139 0x26, // usage
4140 VK_IMAGE_TILING_OPTIMAL, 0);
4141 ASSERT_TRUE(image.initialized());
4142 image.SetLayout(0x6, VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL);
4143
4144 VkImageViewCreateInfo ivci = {
4145 VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO,
4146 nullptr,
4147 0,
4148 image.handle(),
4149 VK_IMAGE_VIEW_TYPE_2D,
4150 VK_FORMAT_D32_SFLOAT_S8_UINT,
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004151 {VK_COMPONENT_SWIZZLE_R, VK_COMPONENT_SWIZZLE_G, VK_COMPONENT_SWIZZLE_B, VK_COMPONENT_SWIZZLE_A},
Mark Lobodzinski77a5d6f2016-08-05 09:38:18 -06004152 {0x2, 0, 1, 0, 1},
4153 };
4154 VkImageView view;
4155 err = vkCreateImageView(m_device->device(), &ivci, nullptr, &view);
4156 ASSERT_VK_SUCCESS(err);
4157
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004158 VkFramebufferCreateInfo fci = {VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr, 0, rp, 1, &view, 32, 32, 1};
Mark Lobodzinski77a5d6f2016-08-05 09:38:18 -06004159 VkFramebuffer fb;
4160 err = vkCreateFramebuffer(m_device->device(), &fci, nullptr, &fb);
4161 ASSERT_VK_SUCCESS(err);
4162
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004163 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 -06004164 BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004165 vkCmdBeginRenderPass(m_commandBuffer->handle(), &rpbi, VK_SUBPASS_CONTENTS_INLINE);
Mark Lobodzinski77a5d6f2016-08-05 09:38:18 -06004166
4167 VkImageMemoryBarrier imb = {};
4168 imb.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
4169 imb.pNext = nullptr;
4170 imb.srcAccessMask = VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_WRITE_BIT;
4171 imb.dstAccessMask = VK_ACCESS_SHADER_READ_BIT;
4172 imb.oldLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
4173 imb.newLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
4174 imb.srcQueueFamilyIndex = 0;
4175 imb.dstQueueFamilyIndex = 0;
4176 imb.image = image.handle();
4177 imb.subresourceRange.aspectMask = 0x6;
4178 imb.subresourceRange.baseMipLevel = 0;
4179 imb.subresourceRange.levelCount = 0x1;
4180 imb.subresourceRange.baseArrayLayer = 0;
4181 imb.subresourceRange.layerCount = 0x1;
4182
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004183 vkCmdPipelineBarrier(m_commandBuffer->handle(), VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT,
4184 VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT, VK_DEPENDENCY_BY_REGION_BIT, 0, nullptr, 0, nullptr, 1,
Mark Lobodzinski77a5d6f2016-08-05 09:38:18 -06004185 &imb);
4186
4187 vkCmdEndRenderPass(m_commandBuffer->handle());
4188 EndCommandBuffer();
4189 QueueCommandBuffer(false);
4190 m_errorMonitor->VerifyNotFound();
4191
4192 vkDestroyFramebuffer(m_device->device(), fb, nullptr);
4193 vkDestroyRenderPass(m_device->device(), rp, nullptr);
4194 vkDestroyImageView(m_device->device(), view, nullptr);
4195}
Tony Barbourd5f7b822016-08-02 15:39:33 -06004196
Tony Barbour4e919972016-08-09 13:27:40 -06004197TEST_F(VkLayerTest, RenderPassInvalidRenderArea) {
4198 TEST_DESCRIPTION("Generate INVALID_RENDER_AREA error by beginning renderpass"
4199 "with extent outside of framebuffer");
4200 ASSERT_NO_FATAL_FAILURE(InitState());
4201 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
4202
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004203 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Cannot execute a render pass with renderArea "
4204 "not within the bound of the framebuffer.");
Tony Barbour4e919972016-08-09 13:27:40 -06004205
4206 // Framebuffer for render target is 256x256, exceed that for INVALID_RENDER_AREA
4207 m_renderPassBeginInfo.renderArea.extent.width = 257;
4208 m_renderPassBeginInfo.renderArea.extent.height = 257;
4209 BeginCommandBuffer();
4210 m_errorMonitor->VerifyFound();
4211}
4212
4213TEST_F(VkLayerTest, DisabledIndependentBlend) {
4214 TEST_DESCRIPTION("Generate INDEPENDENT_BLEND by disabling independent "
4215 "blend and then specifying different blend states for two "
4216 "attachements");
Cody Northrop5703cc72016-08-19 09:57:10 -06004217 VkPhysicalDeviceFeatures features = {};
4218 features.independentBlend = VK_FALSE;
Cody Northropc31a84f2016-08-22 10:41:47 -06004219 ASSERT_NO_FATAL_FAILURE(InitState(&features));
Tony Barbour4e919972016-08-09 13:27:40 -06004220
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004221 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
4222 "Invalid Pipeline CreateInfo: If independent blend feature not "
4223 "enabled, all elements of pAttachments must be identical");
Tony Barbour4e919972016-08-09 13:27:40 -06004224
Cody Northropc31a84f2016-08-22 10:41:47 -06004225 VkDescriptorSetObj descriptorSet(m_device);
4226 descriptorSet.AppendDummy();
4227 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Tony Barbour4e919972016-08-09 13:27:40 -06004228
Cody Northropc31a84f2016-08-22 10:41:47 -06004229 VkPipelineObj pipeline(m_device);
4230 VkRenderpassObj renderpass(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004231 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
Cody Northropc31a84f2016-08-22 10:41:47 -06004232 pipeline.AddShader(&vs);
Cody Northrop5703cc72016-08-19 09:57:10 -06004233
Cody Northropc31a84f2016-08-22 10:41:47 -06004234 VkPipelineColorBlendAttachmentState att_state1 = {}, att_state2 = {};
4235 att_state1.dstAlphaBlendFactor = VK_BLEND_FACTOR_CONSTANT_COLOR;
4236 att_state1.blendEnable = VK_TRUE;
4237 att_state2.dstAlphaBlendFactor = VK_BLEND_FACTOR_CONSTANT_COLOR;
4238 att_state2.blendEnable = VK_FALSE;
4239 pipeline.AddColorAttachment(0, &att_state1);
4240 pipeline.AddColorAttachment(1, &att_state2);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004241 pipeline.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderpass.handle());
Cody Northropc31a84f2016-08-22 10:41:47 -06004242 m_errorMonitor->VerifyFound();
Tony Barbour4e919972016-08-09 13:27:40 -06004243}
4244
4245TEST_F(VkLayerTest, RenderPassDepthStencilAttachmentUnused) {
4246 TEST_DESCRIPTION("Specify no depth attachement in renderpass then specify "
4247 "depth attachments in subpass");
Cody Northropc31a84f2016-08-22 10:41:47 -06004248 ASSERT_NO_FATAL_FAILURE(InitState());
Tony Barbour4e919972016-08-09 13:27:40 -06004249
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004250 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
4251 "vkCreateRenderPass has no depth/stencil attachment, yet subpass");
Tony Barbour4e919972016-08-09 13:27:40 -06004252
4253 // Create a renderPass with a single color attachment
4254 VkAttachmentReference attach = {};
4255 attach.layout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
4256 VkSubpassDescription subpass = {};
4257 VkRenderPassCreateInfo rpci = {};
4258 rpci.subpassCount = 1;
4259 rpci.pSubpasses = &subpass;
4260 rpci.attachmentCount = 1;
4261 VkAttachmentDescription attach_desc = {};
4262 attach_desc.format = VK_FORMAT_B8G8R8A8_UNORM;
4263 attach_desc.samples = VK_SAMPLE_COUNT_1_BIT;
4264 rpci.pAttachments = &attach_desc;
4265 rpci.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
4266 VkRenderPass rp;
4267 subpass.pDepthStencilAttachment = &attach;
4268 subpass.pColorAttachments = NULL;
4269 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
4270 m_errorMonitor->VerifyFound();
4271}
4272
Chris Forbes6b3d3f42016-06-30 16:09:47 +12004273TEST_F(VkLayerTest, RenderPassTransitionsAttachmentUnused) {
4274 TEST_DESCRIPTION("Ensure that layout transitions work correctly without "
4275 "errors, when an attachment reference is "
4276 "VK_ATTACHMENT_UNUSED");
4277
4278 m_errorMonitor->ExpectSuccess();
4279
4280 ASSERT_NO_FATAL_FAILURE(InitState());
4281
4282 // A renderpass with no attachments
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004283 VkAttachmentReference att_ref = {VK_ATTACHMENT_UNUSED, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL};
Chris Forbes6b3d3f42016-06-30 16:09:47 +12004284
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004285 VkSubpassDescription subpass = {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 1, &att_ref, nullptr, nullptr, 0, nullptr};
Chris Forbes6b3d3f42016-06-30 16:09:47 +12004286
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004287 VkRenderPassCreateInfo rpci = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 0, nullptr, 1, &subpass, 0, nullptr};
Chris Forbes6b3d3f42016-06-30 16:09:47 +12004288
4289 VkRenderPass rp;
4290 VkResult err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
4291 ASSERT_VK_SUCCESS(err);
4292
4293 // A compatible framebuffer.
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004294 VkFramebufferCreateInfo fci = {VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr, 0, rp, 0, nullptr, 32, 32, 1};
Chris Forbes6b3d3f42016-06-30 16:09:47 +12004295 VkFramebuffer fb;
4296 err = vkCreateFramebuffer(m_device->device(), &fci, nullptr, &fb);
4297 ASSERT_VK_SUCCESS(err);
4298
4299 // Record a command buffer which just begins and ends the renderpass. The
4300 // bug manifests in BeginRenderPass.
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004301 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 +12004302 BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004303 vkCmdBeginRenderPass(m_commandBuffer->handle(), &rpbi, VK_SUBPASS_CONTENTS_INLINE);
Chris Forbes6b3d3f42016-06-30 16:09:47 +12004304 vkCmdEndRenderPass(m_commandBuffer->handle());
4305 m_errorMonitor->VerifyNotFound();
4306 EndCommandBuffer();
4307
4308 vkDestroyFramebuffer(m_device->device(), fb, nullptr);
4309 vkDestroyRenderPass(m_device->device(), rp, nullptr);
4310}
4311
Mark Lobodzinskice7eee72016-06-14 16:33:29 -06004312// This is a positive test. No errors are expected.
4313TEST_F(VkLayerTest, StencilLoadOp) {
4314 TEST_DESCRIPTION("Create a stencil-only attachment with a LOAD_OP set to "
4315 "CLEAR. stencil[Load|Store]Op used to be ignored.");
4316 VkResult result = VK_SUCCESS;
4317 VkImageFormatProperties formatProps;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004318 vkGetPhysicalDeviceImageFormatProperties(gpu(), VK_FORMAT_D24_UNORM_S8_UINT, VK_IMAGE_TYPE_2D, VK_IMAGE_TILING_OPTIMAL,
4319 VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_SRC_BIT, 0,
4320 &formatProps);
Mark Lobodzinskice7eee72016-06-14 16:33:29 -06004321 if (formatProps.maxExtent.width < 100 || formatProps.maxExtent.height < 100) {
4322 return;
4323 }
4324
4325 ASSERT_NO_FATAL_FAILURE(InitState());
4326 VkFormat depth_stencil_fmt = VK_FORMAT_D24_UNORM_S8_UINT;
4327 m_depthStencil->Init(m_device, 100, 100, depth_stencil_fmt,
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004328 VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_SRC_BIT);
Mark Lobodzinskice7eee72016-06-14 16:33:29 -06004329 VkAttachmentDescription att = {};
4330 VkAttachmentReference ref = {};
4331 att.format = depth_stencil_fmt;
Chris Forbes787b4532016-09-16 16:45:16 +12004332 att.samples = VK_SAMPLE_COUNT_1_BIT;
Mark Lobodzinskice7eee72016-06-14 16:33:29 -06004333 att.loadOp = VK_ATTACHMENT_LOAD_OP_DONT_CARE;
4334 att.storeOp = VK_ATTACHMENT_STORE_OP_DONT_CARE;
4335 att.stencilLoadOp = VK_ATTACHMENT_LOAD_OP_CLEAR;
4336 att.stencilStoreOp = VK_ATTACHMENT_STORE_OP_STORE;
4337 att.initialLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
4338 att.finalLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
4339
4340 VkClearValue clear;
4341 clear.depthStencil.depth = 1.0;
4342 clear.depthStencil.stencil = 0;
4343 ref.attachment = 0;
4344 ref.layout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
4345
4346 VkSubpassDescription subpass = {};
4347 subpass.pipelineBindPoint = VK_PIPELINE_BIND_POINT_GRAPHICS;
4348 subpass.flags = 0;
4349 subpass.inputAttachmentCount = 0;
4350 subpass.pInputAttachments = NULL;
4351 subpass.colorAttachmentCount = 0;
4352 subpass.pColorAttachments = NULL;
4353 subpass.pResolveAttachments = NULL;
4354 subpass.pDepthStencilAttachment = &ref;
4355 subpass.preserveAttachmentCount = 0;
4356 subpass.pPreserveAttachments = NULL;
4357
4358 VkRenderPass rp;
4359 VkRenderPassCreateInfo rp_info = {};
4360 rp_info.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
4361 rp_info.attachmentCount = 1;
4362 rp_info.pAttachments = &att;
4363 rp_info.subpassCount = 1;
4364 rp_info.pSubpasses = &subpass;
4365 result = vkCreateRenderPass(device(), &rp_info, NULL, &rp);
4366 ASSERT_VK_SUCCESS(result);
4367
4368 VkImageView *depthView = m_depthStencil->BindInfo();
4369 VkFramebufferCreateInfo fb_info = {};
4370 fb_info.sType = VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO;
4371 fb_info.pNext = NULL;
4372 fb_info.renderPass = rp;
4373 fb_info.attachmentCount = 1;
4374 fb_info.pAttachments = depthView;
4375 fb_info.width = 100;
4376 fb_info.height = 100;
4377 fb_info.layers = 1;
4378 VkFramebuffer fb;
4379 result = vkCreateFramebuffer(device(), &fb_info, NULL, &fb);
4380 ASSERT_VK_SUCCESS(result);
4381
Mark Lobodzinskice7eee72016-06-14 16:33:29 -06004382 VkRenderPassBeginInfo rpbinfo = {};
4383 rpbinfo.clearValueCount = 1;
4384 rpbinfo.pClearValues = &clear;
4385 rpbinfo.pNext = NULL;
4386 rpbinfo.renderPass = rp;
4387 rpbinfo.sType = VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO;
4388 rpbinfo.renderArea.extent.width = 100;
4389 rpbinfo.renderArea.extent.height = 100;
4390 rpbinfo.renderArea.offset.x = 0;
4391 rpbinfo.renderArea.offset.y = 0;
4392 rpbinfo.framebuffer = fb;
4393
4394 VkFence fence = {};
4395 VkFenceCreateInfo fence_ci = {};
4396 fence_ci.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
4397 fence_ci.pNext = nullptr;
4398 fence_ci.flags = 0;
4399 result = vkCreateFence(m_device->device(), &fence_ci, nullptr, &fence);
4400 ASSERT_VK_SUCCESS(result);
4401
Mark Lobodzinskice7eee72016-06-14 16:33:29 -06004402 m_commandBuffer->BeginCommandBuffer();
4403 m_commandBuffer->BeginRenderPass(rpbinfo);
4404 m_commandBuffer->EndRenderPass();
4405 m_commandBuffer->EndCommandBuffer();
4406 m_commandBuffer->QueueCommandBuffer(fence);
4407
4408 VkImageObj destImage(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004409 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 -06004410 VK_IMAGE_TILING_OPTIMAL, 0);
4411 VkImageMemoryBarrier barrier = {};
4412 VkImageSubresourceRange range;
4413 barrier.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004414 barrier.srcAccessMask = VK_ACCESS_TRANSFER_WRITE_BIT | VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_WRITE_BIT;
4415 barrier.dstAccessMask = VK_ACCESS_TRANSFER_READ_BIT | VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_READ_BIT;
Mark Lobodzinskice7eee72016-06-14 16:33:29 -06004416 barrier.oldLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
4417 barrier.newLayout = VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL;
4418 barrier.image = m_depthStencil->handle();
4419 range.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT;
4420 range.baseMipLevel = 0;
4421 range.levelCount = 1;
4422 range.baseArrayLayer = 0;
4423 range.layerCount = 1;
4424 barrier.subresourceRange = range;
4425 vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
4426 VkCommandBufferObj cmdbuf(m_device, m_commandPool);
4427 cmdbuf.BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004428 cmdbuf.PipelineBarrier(VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0, nullptr, 0, nullptr, 1,
4429 &barrier);
Mark Lobodzinskice7eee72016-06-14 16:33:29 -06004430 barrier.srcAccessMask = 0;
4431 barrier.oldLayout = VK_IMAGE_LAYOUT_UNDEFINED;
4432 barrier.newLayout = VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL;
4433 barrier.image = destImage.handle();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004434 barrier.dstAccessMask = VK_ACCESS_TRANSFER_WRITE_BIT | VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_WRITE_BIT;
4435 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 VkImageCopy cregion;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004438 cregion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT;
Mark Lobodzinskice7eee72016-06-14 16:33:29 -06004439 cregion.srcSubresource.mipLevel = 0;
4440 cregion.srcSubresource.baseArrayLayer = 0;
4441 cregion.srcSubresource.layerCount = 1;
4442 cregion.srcOffset.x = 0;
4443 cregion.srcOffset.y = 0;
4444 cregion.srcOffset.z = 0;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004445 cregion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT;
Mark Lobodzinskice7eee72016-06-14 16:33:29 -06004446 cregion.dstSubresource.mipLevel = 0;
4447 cregion.dstSubresource.baseArrayLayer = 0;
4448 cregion.dstSubresource.layerCount = 1;
4449 cregion.dstOffset.x = 0;
4450 cregion.dstOffset.y = 0;
4451 cregion.dstOffset.z = 0;
4452 cregion.extent.width = 100;
4453 cregion.extent.height = 100;
4454 cregion.extent.depth = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004455 cmdbuf.CopyImage(m_depthStencil->handle(), VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL, destImage.handle(),
Mark Lobodzinskice7eee72016-06-14 16:33:29 -06004456 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, &cregion);
4457 cmdbuf.EndCommandBuffer();
4458
4459 VkSubmitInfo submit_info;
4460 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
4461 submit_info.pNext = NULL;
4462 submit_info.waitSemaphoreCount = 0;
4463 submit_info.pWaitSemaphores = NULL;
4464 submit_info.pWaitDstStageMask = NULL;
4465 submit_info.commandBufferCount = 1;
4466 submit_info.pCommandBuffers = &cmdbuf.handle();
4467 submit_info.signalSemaphoreCount = 0;
4468 submit_info.pSignalSemaphores = NULL;
4469
4470 m_errorMonitor->ExpectSuccess();
4471 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
4472 m_errorMonitor->VerifyNotFound();
4473
Mark Lobodzinskid0440da2016-06-17 15:10:03 -06004474 vkQueueWaitIdle(m_device->m_queue);
Mark Lobodzinskice7eee72016-06-14 16:33:29 -06004475 vkDestroyFence(m_device->device(), fence, nullptr);
4476 vkDestroyRenderPass(m_device->device(), rp, nullptr);
4477 vkDestroyFramebuffer(m_device->device(), fb, nullptr);
4478}
4479
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06004480TEST_F(VkLayerTest, UnusedPreserveAttachment) {
4481 TEST_DESCRIPTION("Create a framebuffer where a subpass has a preserve "
4482 "attachment reference of VK_ATTACHMENT_UNUSED");
4483
4484 ASSERT_NO_FATAL_FAILURE(InitState());
4485 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
4486
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004487 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "must not be VK_ATTACHMENT_UNUSED");
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06004488
4489 VkAttachmentReference color_attach = {};
4490 color_attach.layout = VK_IMAGE_LAYOUT_GENERAL;
4491 color_attach.attachment = 0;
4492 uint32_t preserve_attachment = VK_ATTACHMENT_UNUSED;
4493 VkSubpassDescription subpass = {};
4494 subpass.colorAttachmentCount = 1;
4495 subpass.pColorAttachments = &color_attach;
4496 subpass.preserveAttachmentCount = 1;
4497 subpass.pPreserveAttachments = &preserve_attachment;
4498
4499 VkRenderPassCreateInfo rpci = {};
4500 rpci.subpassCount = 1;
4501 rpci.pSubpasses = &subpass;
4502 rpci.attachmentCount = 1;
4503 VkAttachmentDescription attach_desc = {};
4504 attach_desc.format = VK_FORMAT_UNDEFINED;
4505 rpci.pAttachments = &attach_desc;
4506 rpci.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
4507 VkRenderPass rp;
Mark Lobodzinskia4feeeb2016-06-17 12:00:46 -06004508 VkResult result = vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06004509
4510 m_errorMonitor->VerifyFound();
4511
Mark Lobodzinskia4feeeb2016-06-17 12:00:46 -06004512 if (result == VK_SUCCESS) {
4513 vkDestroyRenderPass(m_device->device(), rp, NULL);
4514 }
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06004515}
4516
Chris Forbesc5389742016-06-29 11:49:23 +12004517TEST_F(VkLayerTest, CreateRenderPassResolveRequiresColorMsaa) {
Chris Forbes6655bb32016-07-01 18:27:30 +12004518 TEST_DESCRIPTION("Ensure that CreateRenderPass produces a validation error "
4519 "when the source of a subpass multisample resolve "
4520 "does not have multiple samples.");
4521
Chris Forbesc5389742016-06-29 11:49:23 +12004522 ASSERT_NO_FATAL_FAILURE(InitState());
4523
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004524 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
4525 "Subpass 0 requests multisample resolve from attachment 0 which has "
4526 "VK_SAMPLE_COUNT_1_BIT");
Chris Forbesc5389742016-06-29 11:49:23 +12004527
4528 VkAttachmentDescription attachments[] = {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004529 {0, VK_FORMAT_R8G8B8A8_UNORM, VK_SAMPLE_COUNT_1_BIT, VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE,
4530 VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
4531 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL},
4532 {0, VK_FORMAT_R8G8B8A8_UNORM, VK_SAMPLE_COUNT_1_BIT, VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE,
4533 VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
4534 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL},
Chris Forbesc5389742016-06-29 11:49:23 +12004535 };
4536
4537 VkAttachmentReference color = {
4538 0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
4539 };
4540
4541 VkAttachmentReference resolve = {
4542 0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
4543 };
4544
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004545 VkSubpassDescription subpass = {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 1, &color, &resolve, nullptr, 0, nullptr};
Chris Forbesc5389742016-06-29 11:49:23 +12004546
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004547 VkRenderPassCreateInfo rpci = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 2, attachments, 1, &subpass, 0, nullptr};
Chris Forbesc5389742016-06-29 11:49:23 +12004548
4549 VkRenderPass rp;
4550 VkResult err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
4551
4552 m_errorMonitor->VerifyFound();
4553
4554 if (err == VK_SUCCESS)
4555 vkDestroyRenderPass(m_device->device(), rp, nullptr);
4556}
4557
4558TEST_F(VkLayerTest, CreateRenderPassResolveRequiresSingleSampleDest) {
Chris Forbes6655bb32016-07-01 18:27:30 +12004559 TEST_DESCRIPTION("Ensure CreateRenderPass produces a validation error "
4560 "when a subpass multisample resolve operation is "
4561 "requested, and the destination of that resolve has "
4562 "multiple samples.");
4563
Chris Forbesc5389742016-06-29 11:49:23 +12004564 ASSERT_NO_FATAL_FAILURE(InitState());
4565
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004566 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
4567 "Subpass 0 requests multisample resolve into attachment 1, which "
4568 "must have VK_SAMPLE_COUNT_1_BIT but has VK_SAMPLE_COUNT_4_BIT");
Chris Forbesc5389742016-06-29 11:49:23 +12004569
4570 VkAttachmentDescription attachments[] = {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004571 {0, VK_FORMAT_R8G8B8A8_UNORM, VK_SAMPLE_COUNT_4_BIT, VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE,
4572 VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
4573 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL},
4574 {0, VK_FORMAT_R8G8B8A8_UNORM, VK_SAMPLE_COUNT_4_BIT, VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE,
4575 VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
4576 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL},
Chris Forbesc5389742016-06-29 11:49:23 +12004577 };
4578
4579 VkAttachmentReference color = {
4580 0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
4581 };
4582
4583 VkAttachmentReference resolve = {
4584 1, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
4585 };
4586
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004587 VkSubpassDescription subpass = {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 1, &color, &resolve, nullptr, 0, nullptr};
Chris Forbesc5389742016-06-29 11:49:23 +12004588
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004589 VkRenderPassCreateInfo rpci = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 2, attachments, 1, &subpass, 0, nullptr};
Chris Forbesc5389742016-06-29 11:49:23 +12004590
4591 VkRenderPass rp;
4592 VkResult err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
4593
4594 m_errorMonitor->VerifyFound();
4595
4596 if (err == VK_SUCCESS)
4597 vkDestroyRenderPass(m_device->device(), rp, nullptr);
4598}
4599
Chris Forbes3f128ef2016-06-29 14:58:53 +12004600TEST_F(VkLayerTest, CreateRenderPassSubpassSampleCountConsistency) {
Chris Forbes6655bb32016-07-01 18:27:30 +12004601 TEST_DESCRIPTION("Ensure CreateRenderPass produces a validation error "
4602 "when the color and depth attachments used by a subpass "
4603 "have inconsistent sample counts");
4604
Chris Forbes3f128ef2016-06-29 14:58:53 +12004605 ASSERT_NO_FATAL_FAILURE(InitState());
4606
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004607 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
4608 "Subpass 0 attempts to render to attachments with inconsistent sample counts");
Chris Forbes3f128ef2016-06-29 14:58:53 +12004609
4610 VkAttachmentDescription attachments[] = {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004611 {0, VK_FORMAT_R8G8B8A8_UNORM, VK_SAMPLE_COUNT_1_BIT, VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE,
4612 VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
4613 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL},
4614 {0, VK_FORMAT_R8G8B8A8_UNORM, VK_SAMPLE_COUNT_4_BIT, VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE,
4615 VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
4616 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL},
Chris Forbes3f128ef2016-06-29 14:58:53 +12004617 };
4618
4619 VkAttachmentReference color[] = {
4620 {
4621 0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
4622 },
4623 {
4624 1, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
4625 },
4626 };
4627
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004628 VkSubpassDescription subpass = {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 2, color, nullptr, nullptr, 0, nullptr};
Chris Forbes3f128ef2016-06-29 14:58:53 +12004629
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004630 VkRenderPassCreateInfo rpci = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 2, attachments, 1, &subpass, 0, nullptr};
Chris Forbes3f128ef2016-06-29 14:58:53 +12004631
4632 VkRenderPass rp;
4633 VkResult err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
4634
4635 m_errorMonitor->VerifyFound();
4636
4637 if (err == VK_SUCCESS)
4638 vkDestroyRenderPass(m_device->device(), rp, nullptr);
4639}
4640
Tobin Ehlis2545e6f2016-06-22 10:42:19 -06004641TEST_F(VkLayerTest, FramebufferCreateErrors) {
4642 TEST_DESCRIPTION("Hit errors when attempting to create a framebuffer :\n"
4643 " 1. Mismatch between fb & renderPass attachmentCount\n"
Tobin Ehlisd3bb23a2016-06-22 13:34:46 -06004644 " 2. Use a color image as depthStencil attachment\n"
Tobin Ehlis77d717c2016-06-22 14:19:19 -06004645 " 3. Mismatch fb & renderPass attachment formats\n"
Tobin Ehlis6cfda642016-06-22 16:12:58 -06004646 " 4. Mismatch fb & renderPass attachment #samples\n"
Tobin Ehlis27f2ae82016-06-23 07:36:57 -06004647 " 5. FB attachment w/ non-1 mip-levels\n"
Tobin Ehlisb1f303b2016-06-23 08:19:55 -06004648 " 6. FB attachment where dimensions don't match\n"
Tobin Ehlis08d4b5e2016-06-23 08:52:39 -06004649 " 7. FB attachment w/o identity swizzle\n"
4650 " 8. FB dimensions exceed physical device limits\n");
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06004651
4652 ASSERT_NO_FATAL_FAILURE(InitState());
4653 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
4654
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004655 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
4656 "vkCreateFramebuffer(): VkFramebufferCreateInfo attachmentCount of 2 "
4657 "does not match attachmentCount of 1 of ");
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06004658
Tobin Ehlis2545e6f2016-06-22 10:42:19 -06004659 // Create a renderPass with a single color attachment
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06004660 VkAttachmentReference attach = {};
4661 attach.layout = VK_IMAGE_LAYOUT_GENERAL;
4662 VkSubpassDescription subpass = {};
Tobin Ehlis2545e6f2016-06-22 10:42:19 -06004663 subpass.pColorAttachments = &attach;
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06004664 VkRenderPassCreateInfo rpci = {};
4665 rpci.subpassCount = 1;
4666 rpci.pSubpasses = &subpass;
4667 rpci.attachmentCount = 1;
4668 VkAttachmentDescription attach_desc = {};
Tobin Ehlisd3bb23a2016-06-22 13:34:46 -06004669 attach_desc.format = VK_FORMAT_B8G8R8A8_UNORM;
Tobin Ehlis77d717c2016-06-22 14:19:19 -06004670 attach_desc.samples = VK_SAMPLE_COUNT_1_BIT;
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06004671 rpci.pAttachments = &attach_desc;
4672 rpci.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
4673 VkRenderPass rp;
4674 VkResult err = vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
4675 ASSERT_VK_SUCCESS(err);
4676
Tobin Ehlis2545e6f2016-06-22 10:42:19 -06004677 VkImageView ivs[2];
4678 ivs[0] = m_renderTargets[0]->targetView(VK_FORMAT_B8G8R8A8_UNORM);
4679 ivs[1] = m_renderTargets[0]->targetView(VK_FORMAT_B8G8R8A8_UNORM);
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06004680 VkFramebufferCreateInfo fb_info = {};
4681 fb_info.sType = VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO;
4682 fb_info.pNext = NULL;
4683 fb_info.renderPass = rp;
Tobin Ehlis2545e6f2016-06-22 10:42:19 -06004684 // Set mis-matching attachmentCount
4685 fb_info.attachmentCount = 2;
4686 fb_info.pAttachments = ivs;
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06004687 fb_info.width = 100;
4688 fb_info.height = 100;
4689 fb_info.layers = 1;
4690
4691 VkFramebuffer fb;
4692 err = vkCreateFramebuffer(device(), &fb_info, NULL, &fb);
4693
4694 m_errorMonitor->VerifyFound();
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06004695 if (err == VK_SUCCESS) {
4696 vkDestroyFramebuffer(m_device->device(), fb, NULL);
4697 }
4698 vkDestroyRenderPass(m_device->device(), rp, NULL);
Tobin Ehlis2545e6f2016-06-22 10:42:19 -06004699
4700 // Create a renderPass with a depth-stencil attachment created with
4701 // IMAGE_USAGE_COLOR_ATTACHMENT
4702 // Add our color attachment to pDepthStencilAttachment
4703 subpass.pDepthStencilAttachment = &attach;
4704 subpass.pColorAttachments = NULL;
4705 VkRenderPass rp_ds;
4706 err = vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp_ds);
4707 ASSERT_VK_SUCCESS(err);
4708 // Set correct attachment count, but attachment has COLOR usage bit set
4709 fb_info.attachmentCount = 1;
4710 fb_info.renderPass = rp_ds;
4711
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004712 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " conflicts with the image's IMAGE_USAGE flags ");
Tobin Ehlis2545e6f2016-06-22 10:42:19 -06004713 err = vkCreateFramebuffer(device(), &fb_info, NULL, &fb);
4714
4715 m_errorMonitor->VerifyFound();
4716 if (err == VK_SUCCESS) {
4717 vkDestroyFramebuffer(m_device->device(), fb, NULL);
4718 }
4719 vkDestroyRenderPass(m_device->device(), rp_ds, NULL);
Tobin Ehlisd3bb23a2016-06-22 13:34:46 -06004720
4721 // Create new renderpass with alternate attachment format from fb
4722 attach_desc.format = VK_FORMAT_R8G8B8A8_UNORM;
4723 subpass.pDepthStencilAttachment = NULL;
4724 subpass.pColorAttachments = &attach;
4725 err = vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
4726 ASSERT_VK_SUCCESS(err);
4727
4728 // Cause error due to mis-matched formats between rp & fb
4729 // rp attachment 0 now has RGBA8 but corresponding fb attach is BGRA8
4730 fb_info.renderPass = rp;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004731 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
4732 " has format of VK_FORMAT_B8G8R8A8_UNORM that does not match ");
Tobin Ehlisd3bb23a2016-06-22 13:34:46 -06004733 err = vkCreateFramebuffer(device(), &fb_info, NULL, &fb);
4734
4735 m_errorMonitor->VerifyFound();
4736 if (err == VK_SUCCESS) {
4737 vkDestroyFramebuffer(m_device->device(), fb, NULL);
4738 }
Tobin Ehlis77d717c2016-06-22 14:19:19 -06004739 vkDestroyRenderPass(m_device->device(), rp, NULL);
4740
4741 // Create new renderpass with alternate sample count from fb
4742 attach_desc.format = VK_FORMAT_B8G8R8A8_UNORM;
4743 attach_desc.samples = VK_SAMPLE_COUNT_4_BIT;
4744 err = vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
4745 ASSERT_VK_SUCCESS(err);
4746
4747 // Cause error due to mis-matched sample count between rp & fb
4748 fb_info.renderPass = rp;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004749 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " has VK_SAMPLE_COUNT_1_BIT samples "
4750 "that do not match the "
4751 "VK_SAMPLE_COUNT_4_BIT ");
Tobin Ehlis77d717c2016-06-22 14:19:19 -06004752 err = vkCreateFramebuffer(device(), &fb_info, NULL, &fb);
4753
4754 m_errorMonitor->VerifyFound();
4755 if (err == VK_SUCCESS) {
4756 vkDestroyFramebuffer(m_device->device(), fb, NULL);
4757 }
Tobin Ehlisd3bb23a2016-06-22 13:34:46 -06004758
4759 vkDestroyRenderPass(m_device->device(), rp, NULL);
Tobin Ehlis6cfda642016-06-22 16:12:58 -06004760
4761 // Create a custom imageView with non-1 mip levels
4762 VkImageObj image(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004763 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 -06004764 ASSERT_TRUE(image.initialized());
4765
4766 VkImageView view;
4767 VkImageViewCreateInfo ivci = {};
4768 ivci.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
4769 ivci.image = image.handle();
4770 ivci.viewType = VK_IMAGE_VIEW_TYPE_2D;
4771 ivci.format = VK_FORMAT_B8G8R8A8_UNORM;
4772 ivci.subresourceRange.layerCount = 1;
4773 ivci.subresourceRange.baseMipLevel = 0;
4774 // Set level count 2 (only 1 is allowed for FB attachment)
4775 ivci.subresourceRange.levelCount = 2;
4776 ivci.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
4777 err = vkCreateImageView(m_device->device(), &ivci, NULL, &view);
4778 ASSERT_VK_SUCCESS(err);
4779 // Re-create renderpass to have matching sample count
4780 attach_desc.samples = VK_SAMPLE_COUNT_1_BIT;
4781 err = vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
4782 ASSERT_VK_SUCCESS(err);
4783
4784 fb_info.renderPass = rp;
4785 fb_info.pAttachments = &view;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004786 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " has mip levelCount of 2 but only ");
Tobin Ehlis6cfda642016-06-22 16:12:58 -06004787 err = vkCreateFramebuffer(device(), &fb_info, NULL, &fb);
4788
4789 m_errorMonitor->VerifyFound();
4790 if (err == VK_SUCCESS) {
4791 vkDestroyFramebuffer(m_device->device(), fb, NULL);
4792 }
Tobin Ehlis6cfda642016-06-22 16:12:58 -06004793 vkDestroyImageView(m_device->device(), view, NULL);
Tobin Ehlis27f2ae82016-06-23 07:36:57 -06004794 // Update view to original color buffer and grow FB dimensions too big
4795 fb_info.pAttachments = ivs;
4796 fb_info.height = 1024;
4797 fb_info.width = 1024;
4798 fb_info.layers = 2;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004799 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " Attachment dimensions must be at "
4800 "least as large. ");
Tobin Ehlis27f2ae82016-06-23 07:36:57 -06004801 err = vkCreateFramebuffer(device(), &fb_info, NULL, &fb);
4802
4803 m_errorMonitor->VerifyFound();
4804 if (err == VK_SUCCESS) {
4805 vkDestroyFramebuffer(m_device->device(), fb, NULL);
4806 }
Tobin Ehlisb1f303b2016-06-23 08:19:55 -06004807 // Create view attachment with non-identity swizzle
4808 ivci.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
4809 ivci.image = image.handle();
4810 ivci.viewType = VK_IMAGE_VIEW_TYPE_2D;
4811 ivci.format = VK_FORMAT_B8G8R8A8_UNORM;
4812 ivci.subresourceRange.layerCount = 1;
4813 ivci.subresourceRange.baseMipLevel = 0;
4814 ivci.subresourceRange.levelCount = 1;
4815 ivci.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
4816 ivci.components.r = VK_COMPONENT_SWIZZLE_G;
4817 ivci.components.g = VK_COMPONENT_SWIZZLE_R;
4818 ivci.components.b = VK_COMPONENT_SWIZZLE_A;
4819 ivci.components.a = VK_COMPONENT_SWIZZLE_B;
4820 err = vkCreateImageView(m_device->device(), &ivci, NULL, &view);
4821 ASSERT_VK_SUCCESS(err);
4822
4823 fb_info.pAttachments = &view;
4824 fb_info.height = 100;
4825 fb_info.width = 100;
4826 fb_info.layers = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004827 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " has non-identy swizzle. All "
4828 "framebuffer attachments must have "
4829 "been created with the identity "
4830 "swizzle. ");
Tobin Ehlisb1f303b2016-06-23 08:19:55 -06004831 err = vkCreateFramebuffer(device(), &fb_info, NULL, &fb);
4832
4833 m_errorMonitor->VerifyFound();
4834 if (err == VK_SUCCESS) {
4835 vkDestroyFramebuffer(m_device->device(), fb, NULL);
4836 }
4837 vkDestroyImageView(m_device->device(), view, NULL);
Tobin Ehlis08d4b5e2016-06-23 08:52:39 -06004838 // Request fb that exceeds max dimensions
4839 // reset attachment to color attachment
4840 fb_info.pAttachments = ivs;
4841 fb_info.width = m_device->props.limits.maxFramebufferWidth + 1;
4842 fb_info.height = m_device->props.limits.maxFramebufferHeight + 1;
4843 fb_info.layers = m_device->props.limits.maxFramebufferLayers + 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004844 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " Requested VkFramebufferCreateInfo "
4845 "dimensions exceed physical device "
4846 "limits. ");
Tobin Ehlis08d4b5e2016-06-23 08:52:39 -06004847 err = vkCreateFramebuffer(device(), &fb_info, NULL, &fb);
4848
4849 m_errorMonitor->VerifyFound();
4850 if (err == VK_SUCCESS) {
4851 vkDestroyFramebuffer(m_device->device(), fb, NULL);
4852 }
Tobin Ehlis27f2ae82016-06-23 07:36:57 -06004853
Tobin Ehlis6cfda642016-06-22 16:12:58 -06004854 vkDestroyRenderPass(m_device->device(), rp, NULL);
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06004855}
4856
Mark Lobodzinskic808d442016-04-14 10:57:23 -06004857// This is a positive test. No errors should be generated.
Michael Lentine860b0fe2016-05-20 10:14:00 -05004858TEST_F(VkLayerTest, WaitEventThenSet) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004859 TEST_DESCRIPTION("Wait on a event then set it after the wait has been submitted.");
Michael Lentine860b0fe2016-05-20 10:14:00 -05004860
Michael Lentine860b0fe2016-05-20 10:14:00 -05004861 m_errorMonitor->ExpectSuccess();
Cody Northropc31a84f2016-08-22 10:41:47 -06004862 ASSERT_NO_FATAL_FAILURE(InitState());
Michael Lentine860b0fe2016-05-20 10:14:00 -05004863
4864 VkEvent event;
4865 VkEventCreateInfo event_create_info{};
4866 event_create_info.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO;
4867 vkCreateEvent(m_device->device(), &event_create_info, nullptr, &event);
4868
4869 VkCommandPool command_pool;
4870 VkCommandPoolCreateInfo pool_create_info{};
4871 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
4872 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
4873 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004874 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
Michael Lentine860b0fe2016-05-20 10:14:00 -05004875
4876 VkCommandBuffer command_buffer;
4877 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004878 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
Michael Lentine860b0fe2016-05-20 10:14:00 -05004879 command_buffer_allocate_info.commandPool = command_pool;
4880 command_buffer_allocate_info.commandBufferCount = 1;
4881 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004882 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, &command_buffer);
Michael Lentine860b0fe2016-05-20 10:14:00 -05004883
4884 VkQueue queue = VK_NULL_HANDLE;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004885 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 0, &queue);
Michael Lentine860b0fe2016-05-20 10:14:00 -05004886
4887 {
4888 VkCommandBufferBeginInfo begin_info{};
4889 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
4890 vkBeginCommandBuffer(command_buffer, &begin_info);
4891
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004892 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 -05004893 nullptr, 0, nullptr);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004894 vkCmdResetEvent(command_buffer, event, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT);
Michael Lentine860b0fe2016-05-20 10:14:00 -05004895 vkEndCommandBuffer(command_buffer);
4896 }
4897 {
4898 VkSubmitInfo submit_info{};
4899 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
4900 submit_info.commandBufferCount = 1;
4901 submit_info.pCommandBuffers = &command_buffer;
4902 submit_info.signalSemaphoreCount = 0;
4903 submit_info.pSignalSemaphores = nullptr;
4904 vkQueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE);
4905 }
4906 { vkSetEvent(m_device->device(), event); }
4907
4908 vkQueueWaitIdle(queue);
4909
4910 vkDestroyEvent(m_device->device(), event, nullptr);
4911 vkFreeCommandBuffers(m_device->device(), command_pool, 1, &command_buffer);
4912 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
4913
4914 m_errorMonitor->VerifyNotFound();
4915}
Michael Lentine5627e692016-05-20 17:45:02 -05004916// This is a positive test. No errors should be generated.
Michael Lentinef01fb382016-07-21 17:24:56 -05004917TEST_F(VkLayerTest, QueryAndCopySecondaryCommandBuffers) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004918 TEST_DESCRIPTION("Issue a query on a secondary command buffery and copy it on a primary.");
Michael Lentinef01fb382016-07-21 17:24:56 -05004919
Cody Northropc31a84f2016-08-22 10:41:47 -06004920 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004921 if ((m_device->queue_props.empty()) || (m_device->queue_props[0].queueCount < 2))
Michael Lentinef01fb382016-07-21 17:24:56 -05004922 return;
4923
4924 m_errorMonitor->ExpectSuccess();
4925
4926 VkQueryPool query_pool;
4927 VkQueryPoolCreateInfo query_pool_create_info{};
4928 query_pool_create_info.sType = VK_STRUCTURE_TYPE_QUERY_POOL_CREATE_INFO;
4929 query_pool_create_info.queryType = VK_QUERY_TYPE_TIMESTAMP;
4930 query_pool_create_info.queryCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004931 vkCreateQueryPool(m_device->device(), &query_pool_create_info, nullptr, &query_pool);
Michael Lentinef01fb382016-07-21 17:24:56 -05004932
4933 VkCommandPool command_pool;
4934 VkCommandPoolCreateInfo pool_create_info{};
4935 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
4936 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
4937 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004938 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
Michael Lentinef01fb382016-07-21 17:24:56 -05004939
4940 VkCommandBuffer command_buffer;
4941 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004942 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
Michael Lentinef01fb382016-07-21 17:24:56 -05004943 command_buffer_allocate_info.commandPool = command_pool;
4944 command_buffer_allocate_info.commandBufferCount = 1;
4945 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004946 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, &command_buffer);
Michael Lentinef01fb382016-07-21 17:24:56 -05004947
4948 VkCommandBuffer secondary_command_buffer;
4949 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_SECONDARY;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004950 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, &secondary_command_buffer);
Michael Lentinef01fb382016-07-21 17:24:56 -05004951
4952 VkQueue queue = VK_NULL_HANDLE;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004953 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 1, &queue);
Michael Lentinef01fb382016-07-21 17:24:56 -05004954
4955 uint32_t qfi = 0;
4956 VkBufferCreateInfo buff_create_info = {};
4957 buff_create_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
4958 buff_create_info.size = 1024;
4959 buff_create_info.usage = VK_BUFFER_USAGE_TRANSFER_DST_BIT;
4960 buff_create_info.queueFamilyIndexCount = 1;
4961 buff_create_info.pQueueFamilyIndices = &qfi;
4962
4963 VkResult err;
4964 VkBuffer buffer;
4965 err = vkCreateBuffer(m_device->device(), &buff_create_info, NULL, &buffer);
4966 ASSERT_VK_SUCCESS(err);
4967 VkMemoryAllocateInfo mem_alloc = {};
4968 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
4969 mem_alloc.pNext = NULL;
4970 mem_alloc.allocationSize = 1024;
4971 mem_alloc.memoryTypeIndex = 0;
4972
4973 VkMemoryRequirements memReqs;
4974 vkGetBufferMemoryRequirements(m_device->device(), buffer, &memReqs);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004975 bool pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &mem_alloc, 0);
Michael Lentinef01fb382016-07-21 17:24:56 -05004976 if (!pass) {
4977 vkDestroyBuffer(m_device->device(), buffer, NULL);
4978 return;
4979 }
4980
4981 VkDeviceMemory mem;
4982 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem);
4983 ASSERT_VK_SUCCESS(err);
4984 err = vkBindBufferMemory(m_device->device(), buffer, mem, 0);
4985 ASSERT_VK_SUCCESS(err);
4986
4987 VkCommandBufferInheritanceInfo hinfo = {};
4988 hinfo.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_INHERITANCE_INFO;
4989 hinfo.renderPass = VK_NULL_HANDLE;
4990 hinfo.subpass = 0;
4991 hinfo.framebuffer = VK_NULL_HANDLE;
4992 hinfo.occlusionQueryEnable = VK_FALSE;
4993 hinfo.queryFlags = 0;
4994 hinfo.pipelineStatistics = 0;
4995
4996 {
4997 VkCommandBufferBeginInfo begin_info{};
4998 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
4999 begin_info.pInheritanceInfo = &hinfo;
5000 vkBeginCommandBuffer(secondary_command_buffer, &begin_info);
5001
5002 vkCmdResetQueryPool(secondary_command_buffer, query_pool, 0, 1);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005003 vkCmdWriteTimestamp(secondary_command_buffer, VK_PIPELINE_STAGE_ALL_GRAPHICS_BIT, query_pool, 0);
Michael Lentinef01fb382016-07-21 17:24:56 -05005004
5005 vkEndCommandBuffer(secondary_command_buffer);
5006
5007 begin_info.pInheritanceInfo = nullptr;
5008 vkBeginCommandBuffer(command_buffer, &begin_info);
5009
5010 vkCmdExecuteCommands(command_buffer, 1, &secondary_command_buffer);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005011 vkCmdCopyQueryPoolResults(command_buffer, query_pool, 0, 1, buffer, 0, 0, 0);
Michael Lentinef01fb382016-07-21 17:24:56 -05005012
5013 vkEndCommandBuffer(command_buffer);
5014 }
5015 {
5016 VkSubmitInfo submit_info{};
5017 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
5018 submit_info.commandBufferCount = 1;
5019 submit_info.pCommandBuffers = &command_buffer;
5020 submit_info.signalSemaphoreCount = 0;
5021 submit_info.pSignalSemaphores = nullptr;
5022 vkQueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE);
5023 }
5024
5025 vkQueueWaitIdle(queue);
5026
5027 vkDestroyQueryPool(m_device->device(), query_pool, nullptr);
5028 vkFreeCommandBuffers(m_device->device(), command_pool, 1, &command_buffer);
5029 vkFreeCommandBuffers(m_device->device(), command_pool, 1, &secondary_command_buffer);
5030 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
5031 vkDestroyBuffer(m_device->device(), buffer, NULL);
5032 vkFreeMemory(m_device->device(), mem, NULL);
5033
5034 m_errorMonitor->VerifyNotFound();
5035}
5036
5037// This is a positive test. No errors should be generated.
Michael Lentine5627e692016-05-20 17:45:02 -05005038TEST_F(VkLayerTest, QueryAndCopyMultipleCommandBuffers) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005039 TEST_DESCRIPTION("Issue a query and copy from it on a second command buffer.");
Michael Lentine5627e692016-05-20 17:45:02 -05005040
Cody Northropc31a84f2016-08-22 10:41:47 -06005041 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005042 if ((m_device->queue_props.empty()) || (m_device->queue_props[0].queueCount < 2))
Michael Lentine5627e692016-05-20 17:45:02 -05005043 return;
5044
5045 m_errorMonitor->ExpectSuccess();
5046
5047 VkQueryPool query_pool;
5048 VkQueryPoolCreateInfo query_pool_create_info{};
5049 query_pool_create_info.sType = VK_STRUCTURE_TYPE_QUERY_POOL_CREATE_INFO;
5050 query_pool_create_info.queryType = VK_QUERY_TYPE_TIMESTAMP;
5051 query_pool_create_info.queryCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005052 vkCreateQueryPool(m_device->device(), &query_pool_create_info, nullptr, &query_pool);
Michael Lentine5627e692016-05-20 17:45:02 -05005053
5054 VkCommandPool command_pool;
5055 VkCommandPoolCreateInfo pool_create_info{};
5056 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
5057 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
5058 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005059 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
Michael Lentine5627e692016-05-20 17:45:02 -05005060
5061 VkCommandBuffer command_buffer[2];
5062 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005063 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
Michael Lentine5627e692016-05-20 17:45:02 -05005064 command_buffer_allocate_info.commandPool = command_pool;
5065 command_buffer_allocate_info.commandBufferCount = 2;
5066 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005067 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, command_buffer);
Michael Lentine5627e692016-05-20 17:45:02 -05005068
5069 VkQueue queue = VK_NULL_HANDLE;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005070 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 1, &queue);
Michael Lentine5627e692016-05-20 17:45:02 -05005071
5072 uint32_t qfi = 0;
5073 VkBufferCreateInfo buff_create_info = {};
5074 buff_create_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
5075 buff_create_info.size = 1024;
5076 buff_create_info.usage = VK_BUFFER_USAGE_TRANSFER_DST_BIT;
5077 buff_create_info.queueFamilyIndexCount = 1;
5078 buff_create_info.pQueueFamilyIndices = &qfi;
5079
5080 VkResult err;
5081 VkBuffer buffer;
5082 err = vkCreateBuffer(m_device->device(), &buff_create_info, NULL, &buffer);
5083 ASSERT_VK_SUCCESS(err);
5084 VkMemoryAllocateInfo mem_alloc = {};
5085 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
5086 mem_alloc.pNext = NULL;
5087 mem_alloc.allocationSize = 1024;
5088 mem_alloc.memoryTypeIndex = 0;
5089
5090 VkMemoryRequirements memReqs;
5091 vkGetBufferMemoryRequirements(m_device->device(), buffer, &memReqs);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005092 bool pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &mem_alloc, 0);
Michael Lentine5627e692016-05-20 17:45:02 -05005093 if (!pass) {
5094 vkDestroyBuffer(m_device->device(), buffer, NULL);
5095 return;
5096 }
5097
5098 VkDeviceMemory mem;
5099 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem);
5100 ASSERT_VK_SUCCESS(err);
5101 err = vkBindBufferMemory(m_device->device(), buffer, mem, 0);
5102 ASSERT_VK_SUCCESS(err);
5103
5104 {
5105 VkCommandBufferBeginInfo begin_info{};
5106 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
5107 vkBeginCommandBuffer(command_buffer[0], &begin_info);
5108
5109 vkCmdResetQueryPool(command_buffer[0], query_pool, 0, 1);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005110 vkCmdWriteTimestamp(command_buffer[0], VK_PIPELINE_STAGE_ALL_GRAPHICS_BIT, query_pool, 0);
Michael Lentine5627e692016-05-20 17:45:02 -05005111
5112 vkEndCommandBuffer(command_buffer[0]);
5113
5114 vkBeginCommandBuffer(command_buffer[1], &begin_info);
5115
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005116 vkCmdCopyQueryPoolResults(command_buffer[1], query_pool, 0, 1, buffer, 0, 0, 0);
Michael Lentine5627e692016-05-20 17:45:02 -05005117
5118 vkEndCommandBuffer(command_buffer[1]);
5119 }
5120 {
5121 VkSubmitInfo submit_info{};
5122 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
5123 submit_info.commandBufferCount = 2;
5124 submit_info.pCommandBuffers = command_buffer;
5125 submit_info.signalSemaphoreCount = 0;
5126 submit_info.pSignalSemaphores = nullptr;
5127 vkQueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE);
5128 }
5129
5130 vkQueueWaitIdle(queue);
5131
5132 vkDestroyQueryPool(m_device->device(), query_pool, nullptr);
5133 vkFreeCommandBuffers(m_device->device(), command_pool, 2, command_buffer);
5134 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
Tony Barbourdf4c0042016-06-01 15:55:43 -06005135 vkDestroyBuffer(m_device->device(), buffer, NULL);
5136 vkFreeMemory(m_device->device(), mem, NULL);
Michael Lentine5627e692016-05-20 17:45:02 -05005137
5138 m_errorMonitor->VerifyNotFound();
5139}
Michael Lentine860b0fe2016-05-20 10:14:00 -05005140
5141TEST_F(VkLayerTest, ResetEventThenSet) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005142 TEST_DESCRIPTION("Reset an event then set it after the reset has been submitted.");
Michael Lentine860b0fe2016-05-20 10:14:00 -05005143
Michael Lentine860b0fe2016-05-20 10:14:00 -05005144 m_errorMonitor->ExpectSuccess();
5145
Cody Northropc31a84f2016-08-22 10:41:47 -06005146 ASSERT_NO_FATAL_FAILURE(InitState());
Michael Lentine860b0fe2016-05-20 10:14:00 -05005147 VkEvent event;
5148 VkEventCreateInfo event_create_info{};
5149 event_create_info.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO;
5150 vkCreateEvent(m_device->device(), &event_create_info, nullptr, &event);
5151
5152 VkCommandPool command_pool;
5153 VkCommandPoolCreateInfo pool_create_info{};
5154 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
5155 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
5156 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005157 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
Michael Lentine860b0fe2016-05-20 10:14:00 -05005158
5159 VkCommandBuffer command_buffer;
5160 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005161 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
Michael Lentine860b0fe2016-05-20 10:14:00 -05005162 command_buffer_allocate_info.commandPool = command_pool;
5163 command_buffer_allocate_info.commandBufferCount = 1;
5164 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005165 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, &command_buffer);
Michael Lentine860b0fe2016-05-20 10:14:00 -05005166
5167 VkQueue queue = VK_NULL_HANDLE;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005168 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 0, &queue);
Michael Lentine860b0fe2016-05-20 10:14:00 -05005169
5170 {
5171 VkCommandBufferBeginInfo begin_info{};
5172 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
5173 vkBeginCommandBuffer(command_buffer, &begin_info);
5174
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005175 vkCmdResetEvent(command_buffer, event, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT);
5176 vkCmdWaitEvents(command_buffer, 1, &event, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0,
5177 nullptr, 0, nullptr, 0, nullptr);
Michael Lentine860b0fe2016-05-20 10:14:00 -05005178 vkEndCommandBuffer(command_buffer);
5179 }
5180 {
5181 VkSubmitInfo submit_info{};
5182 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
5183 submit_info.commandBufferCount = 1;
5184 submit_info.pCommandBuffers = &command_buffer;
5185 submit_info.signalSemaphoreCount = 0;
5186 submit_info.pSignalSemaphores = nullptr;
5187 vkQueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE);
5188 }
5189 {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005190 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "that is already in use by a "
5191 "command buffer.");
Michael Lentine860b0fe2016-05-20 10:14:00 -05005192 vkSetEvent(m_device->device(), event);
5193 m_errorMonitor->VerifyFound();
5194 }
5195
5196 vkQueueWaitIdle(queue);
5197
5198 vkDestroyEvent(m_device->device(), event, nullptr);
5199 vkFreeCommandBuffers(m_device->device(), command_pool, 1, &command_buffer);
5200 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
5201}
5202
5203// This is a positive test. No errors should be generated.
Tobin Ehlis0bb263b2016-05-10 12:13:02 -06005204TEST_F(VkLayerTest, TwoFencesThreeFrames) {
5205 TEST_DESCRIPTION("Two command buffers with two separate fences are each "
5206 "run through a Submit & WaitForFences cycle 3 times. This "
5207 "previously revealed a bug so running this positive test "
5208 "to prevent a regression.");
5209 m_errorMonitor->ExpectSuccess();
5210
5211 ASSERT_NO_FATAL_FAILURE(InitState());
5212 VkQueue queue = VK_NULL_HANDLE;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005213 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 0, &queue);
Tobin Ehlis0bb263b2016-05-10 12:13:02 -06005214
5215 static const uint32_t NUM_OBJECTS = 2;
5216 static const uint32_t NUM_FRAMES = 3;
5217 VkCommandBuffer cmd_buffers[NUM_OBJECTS] = {};
5218 VkFence fences[NUM_OBJECTS] = {};
5219
5220 VkCommandPool cmd_pool;
5221 VkCommandPoolCreateInfo cmd_pool_ci = {};
5222 cmd_pool_ci.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
5223 cmd_pool_ci.queueFamilyIndex = m_device->graphics_queue_node_index_;
5224 cmd_pool_ci.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005225 VkResult err = vkCreateCommandPool(m_device->device(), &cmd_pool_ci, nullptr, &cmd_pool);
Tobin Ehlis0bb263b2016-05-10 12:13:02 -06005226 ASSERT_VK_SUCCESS(err);
5227
5228 VkCommandBufferAllocateInfo cmd_buf_info = {};
5229 cmd_buf_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
5230 cmd_buf_info.commandPool = cmd_pool;
5231 cmd_buf_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
5232 cmd_buf_info.commandBufferCount = 1;
5233
5234 VkFenceCreateInfo fence_ci = {};
5235 fence_ci.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
5236 fence_ci.pNext = nullptr;
5237 fence_ci.flags = 0;
5238
5239 for (uint32_t i = 0; i < NUM_OBJECTS; ++i) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005240 err = vkAllocateCommandBuffers(m_device->device(), &cmd_buf_info, &cmd_buffers[i]);
Tobin Ehlis0bb263b2016-05-10 12:13:02 -06005241 ASSERT_VK_SUCCESS(err);
5242 err = vkCreateFence(m_device->device(), &fence_ci, nullptr, &fences[i]);
5243 ASSERT_VK_SUCCESS(err);
5244 }
5245
5246 for (uint32_t frame = 0; frame < NUM_FRAMES; ++frame) {
Tobin Ehlisf9025162016-05-26 06:55:21 -06005247 for (uint32_t obj = 0; obj < NUM_OBJECTS; ++obj) {
5248 // Create empty cmd buffer
5249 VkCommandBufferBeginInfo cmdBufBeginDesc = {};
5250 cmdBufBeginDesc.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
Tobin Ehlis0bb263b2016-05-10 12:13:02 -06005251
Tobin Ehlisf9025162016-05-26 06:55:21 -06005252 err = vkBeginCommandBuffer(cmd_buffers[obj], &cmdBufBeginDesc);
5253 ASSERT_VK_SUCCESS(err);
5254 err = vkEndCommandBuffer(cmd_buffers[obj]);
5255 ASSERT_VK_SUCCESS(err);
Tobin Ehlis0bb263b2016-05-10 12:13:02 -06005256
Tobin Ehlisf9025162016-05-26 06:55:21 -06005257 VkSubmitInfo submit_info = {};
5258 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
5259 submit_info.commandBufferCount = 1;
5260 submit_info.pCommandBuffers = &cmd_buffers[obj];
5261 // Submit cmd buffer and wait for fence
5262 err = vkQueueSubmit(queue, 1, &submit_info, fences[obj]);
5263 ASSERT_VK_SUCCESS(err);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005264 err = vkWaitForFences(m_device->device(), 1, &fences[obj], VK_TRUE, UINT64_MAX);
Tobin Ehlisf9025162016-05-26 06:55:21 -06005265 ASSERT_VK_SUCCESS(err);
5266 err = vkResetFences(m_device->device(), 1, &fences[obj]);
5267 ASSERT_VK_SUCCESS(err);
5268 }
Tobin Ehlis0bb263b2016-05-10 12:13:02 -06005269 }
5270 m_errorMonitor->VerifyNotFound();
Tony Barbourdf4c0042016-06-01 15:55:43 -06005271 vkDestroyCommandPool(m_device->device(), cmd_pool, NULL);
5272 for (uint32_t i = 0; i < NUM_OBJECTS; ++i) {
5273 vkDestroyFence(m_device->device(), fences[i], nullptr);
5274 }
Tobin Ehlis0bb263b2016-05-10 12:13:02 -06005275}
5276// This is a positive test. No errors should be generated.
Mark Lobodzinskic808d442016-04-14 10:57:23 -06005277TEST_F(VkLayerTest, TwoQueueSubmitsSeparateQueuesWithSemaphoreAndOneFenceQWI) {
5278
5279 TEST_DESCRIPTION("Two command buffers, each in a separate QueueSubmit call "
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005280 "submitted on separate queues followed by a QueueWaitIdle.");
Mark Lobodzinskic808d442016-04-14 10:57:23 -06005281
Cody Northropc31a84f2016-08-22 10:41:47 -06005282 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005283 if ((m_device->queue_props.empty()) || (m_device->queue_props[0].queueCount < 2))
Tony Barbourdc18b262016-04-22 14:49:48 -06005284 return;
5285
Mark Lobodzinskic808d442016-04-14 10:57:23 -06005286 m_errorMonitor->ExpectSuccess();
5287
5288 VkSemaphore semaphore;
5289 VkSemaphoreCreateInfo semaphore_create_info{};
5290 semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005291 vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr, &semaphore);
Mark Lobodzinskic808d442016-04-14 10:57:23 -06005292
5293 VkCommandPool command_pool;
5294 VkCommandPoolCreateInfo pool_create_info{};
5295 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
5296 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
5297 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005298 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
Mark Lobodzinskic808d442016-04-14 10:57:23 -06005299
5300 VkCommandBuffer command_buffer[2];
5301 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005302 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
Mark Lobodzinskic808d442016-04-14 10:57:23 -06005303 command_buffer_allocate_info.commandPool = command_pool;
5304 command_buffer_allocate_info.commandBufferCount = 2;
5305 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005306 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, command_buffer);
Mark Lobodzinskic808d442016-04-14 10:57:23 -06005307
5308 VkQueue queue = VK_NULL_HANDLE;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005309 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 1, &queue);
Mark Lobodzinskic808d442016-04-14 10:57:23 -06005310
5311 {
5312 VkCommandBufferBeginInfo begin_info{};
5313 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
5314 vkBeginCommandBuffer(command_buffer[0], &begin_info);
5315
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005316 vkCmdPipelineBarrier(command_buffer[0], VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0,
5317 nullptr, 0, nullptr, 0, nullptr);
Mark Lobodzinskic808d442016-04-14 10:57:23 -06005318
5319 VkViewport viewport{};
5320 viewport.maxDepth = 1.0f;
5321 viewport.minDepth = 0.0f;
5322 viewport.width = 512;
5323 viewport.height = 512;
5324 viewport.x = 0;
5325 viewport.y = 0;
5326 vkCmdSetViewport(command_buffer[0], 0, 1, &viewport);
5327 vkEndCommandBuffer(command_buffer[0]);
5328 }
5329 {
5330 VkCommandBufferBeginInfo begin_info{};
5331 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
5332 vkBeginCommandBuffer(command_buffer[1], &begin_info);
5333
5334 VkViewport viewport{};
5335 viewport.maxDepth = 1.0f;
5336 viewport.minDepth = 0.0f;
5337 viewport.width = 512;
5338 viewport.height = 512;
5339 viewport.x = 0;
5340 viewport.y = 0;
5341 vkCmdSetViewport(command_buffer[1], 0, 1, &viewport);
5342 vkEndCommandBuffer(command_buffer[1]);
5343 }
5344 {
5345 VkSubmitInfo submit_info{};
5346 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
5347 submit_info.commandBufferCount = 1;
5348 submit_info.pCommandBuffers = &command_buffer[0];
5349 submit_info.signalSemaphoreCount = 1;
5350 submit_info.pSignalSemaphores = &semaphore;
5351 vkQueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE);
5352 }
5353 {
5354 VkPipelineStageFlags flags[]{VK_PIPELINE_STAGE_ALL_COMMANDS_BIT};
5355 VkSubmitInfo submit_info{};
5356 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
5357 submit_info.commandBufferCount = 1;
5358 submit_info.pCommandBuffers = &command_buffer[1];
5359 submit_info.waitSemaphoreCount = 1;
5360 submit_info.pWaitSemaphores = &semaphore;
5361 submit_info.pWaitDstStageMask = flags;
5362 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
5363 }
5364
5365 vkQueueWaitIdle(m_device->m_queue);
5366
5367 vkDestroySemaphore(m_device->device(), semaphore, nullptr);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005368 vkFreeCommandBuffers(m_device->device(), command_pool, 2, &command_buffer[0]);
Mark Lobodzinskic808d442016-04-14 10:57:23 -06005369 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
5370
5371 m_errorMonitor->VerifyNotFound();
5372}
5373
5374// This is a positive test. No errors should be generated.
5375TEST_F(VkLayerTest, TwoQueueSubmitsSeparateQueuesWithSemaphoreAndOneFenceQWIFence) {
5376
5377 TEST_DESCRIPTION("Two command buffers, each in a separate QueueSubmit call "
5378 "submitted on separate queues, the second having a fence"
5379 "followed by a QueueWaitIdle.");
5380
Cody Northropc31a84f2016-08-22 10:41:47 -06005381 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005382 if ((m_device->queue_props.empty()) || (m_device->queue_props[0].queueCount < 2))
Tony Barbourdc18b262016-04-22 14:49:48 -06005383 return;
5384
Mark Lobodzinskic808d442016-04-14 10:57:23 -06005385 m_errorMonitor->ExpectSuccess();
5386
5387 VkFence fence;
5388 VkFenceCreateInfo fence_create_info{};
5389 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
5390 vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence);
5391
5392 VkSemaphore semaphore;
5393 VkSemaphoreCreateInfo semaphore_create_info{};
5394 semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005395 vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr, &semaphore);
Mark Lobodzinskic808d442016-04-14 10:57:23 -06005396
5397 VkCommandPool command_pool;
5398 VkCommandPoolCreateInfo pool_create_info{};
5399 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
5400 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
5401 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005402 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
Mark Lobodzinskic808d442016-04-14 10:57:23 -06005403
5404 VkCommandBuffer command_buffer[2];
5405 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005406 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
Mark Lobodzinskic808d442016-04-14 10:57:23 -06005407 command_buffer_allocate_info.commandPool = command_pool;
5408 command_buffer_allocate_info.commandBufferCount = 2;
5409 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005410 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, command_buffer);
Mark Lobodzinskic808d442016-04-14 10:57:23 -06005411
5412 VkQueue queue = VK_NULL_HANDLE;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005413 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 1, &queue);
Mark Lobodzinskic808d442016-04-14 10:57:23 -06005414
5415 {
5416 VkCommandBufferBeginInfo begin_info{};
5417 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
5418 vkBeginCommandBuffer(command_buffer[0], &begin_info);
5419
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005420 vkCmdPipelineBarrier(command_buffer[0], VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0,
5421 nullptr, 0, nullptr, 0, nullptr);
Mark Lobodzinskic808d442016-04-14 10:57:23 -06005422
5423 VkViewport viewport{};
5424 viewport.maxDepth = 1.0f;
5425 viewport.minDepth = 0.0f;
5426 viewport.width = 512;
5427 viewport.height = 512;
5428 viewport.x = 0;
5429 viewport.y = 0;
5430 vkCmdSetViewport(command_buffer[0], 0, 1, &viewport);
5431 vkEndCommandBuffer(command_buffer[0]);
5432 }
5433 {
5434 VkCommandBufferBeginInfo begin_info{};
5435 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
5436 vkBeginCommandBuffer(command_buffer[1], &begin_info);
5437
5438 VkViewport viewport{};
5439 viewport.maxDepth = 1.0f;
5440 viewport.minDepth = 0.0f;
5441 viewport.width = 512;
5442 viewport.height = 512;
5443 viewport.x = 0;
5444 viewport.y = 0;
5445 vkCmdSetViewport(command_buffer[1], 0, 1, &viewport);
5446 vkEndCommandBuffer(command_buffer[1]);
5447 }
5448 {
5449 VkSubmitInfo submit_info{};
5450 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
5451 submit_info.commandBufferCount = 1;
5452 submit_info.pCommandBuffers = &command_buffer[0];
5453 submit_info.signalSemaphoreCount = 1;
5454 submit_info.pSignalSemaphores = &semaphore;
5455 vkQueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE);
5456 }
5457 {
5458 VkPipelineStageFlags flags[]{VK_PIPELINE_STAGE_ALL_COMMANDS_BIT};
5459 VkSubmitInfo submit_info{};
5460 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
5461 submit_info.commandBufferCount = 1;
5462 submit_info.pCommandBuffers = &command_buffer[1];
5463 submit_info.waitSemaphoreCount = 1;
5464 submit_info.pWaitSemaphores = &semaphore;
5465 submit_info.pWaitDstStageMask = flags;
5466 vkQueueSubmit(m_device->m_queue, 1, &submit_info, fence);
5467 }
5468
5469 vkQueueWaitIdle(m_device->m_queue);
5470
5471 vkDestroyFence(m_device->device(), fence, nullptr);
5472 vkDestroySemaphore(m_device->device(), semaphore, nullptr);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005473 vkFreeCommandBuffers(m_device->device(), command_pool, 2, &command_buffer[0]);
Mark Lobodzinskic808d442016-04-14 10:57:23 -06005474 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
5475
5476 m_errorMonitor->VerifyNotFound();
5477}
5478
5479// This is a positive test. No errors should be generated.
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005480TEST_F(VkLayerTest, TwoQueueSubmitsSeparateQueuesWithSemaphoreAndOneFenceTwoWFF) {
Mark Lobodzinskic808d442016-04-14 10:57:23 -06005481
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005482 TEST_DESCRIPTION("Two command buffers, each in a separate QueueSubmit call "
5483 "submitted on separate queues, the second having a fence"
5484 "followed by two consecutive WaitForFences calls on the same fence.");
Mark Lobodzinskic808d442016-04-14 10:57:23 -06005485
Cody Northropc31a84f2016-08-22 10:41:47 -06005486 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005487 if ((m_device->queue_props.empty()) || (m_device->queue_props[0].queueCount < 2))
Tony Barbourdc18b262016-04-22 14:49:48 -06005488 return;
5489
Mark Lobodzinskic808d442016-04-14 10:57:23 -06005490 m_errorMonitor->ExpectSuccess();
5491
5492 VkFence fence;
5493 VkFenceCreateInfo fence_create_info{};
5494 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
5495 vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence);
5496
5497 VkSemaphore semaphore;
5498 VkSemaphoreCreateInfo semaphore_create_info{};
5499 semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005500 vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr, &semaphore);
Mark Lobodzinskic808d442016-04-14 10:57:23 -06005501
5502 VkCommandPool command_pool;
5503 VkCommandPoolCreateInfo pool_create_info{};
5504 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
5505 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
5506 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005507 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
Mark Lobodzinskic808d442016-04-14 10:57:23 -06005508
5509 VkCommandBuffer command_buffer[2];
5510 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005511 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
Mark Lobodzinskic808d442016-04-14 10:57:23 -06005512 command_buffer_allocate_info.commandPool = command_pool;
5513 command_buffer_allocate_info.commandBufferCount = 2;
5514 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005515 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, command_buffer);
Mark Lobodzinskic808d442016-04-14 10:57:23 -06005516
5517 VkQueue queue = VK_NULL_HANDLE;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005518 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 1, &queue);
Mark Lobodzinskic808d442016-04-14 10:57:23 -06005519
5520 {
5521 VkCommandBufferBeginInfo begin_info{};
5522 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
5523 vkBeginCommandBuffer(command_buffer[0], &begin_info);
5524
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005525 vkCmdPipelineBarrier(command_buffer[0], VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0,
5526 nullptr, 0, nullptr, 0, nullptr);
Mark Lobodzinskic808d442016-04-14 10:57:23 -06005527
5528 VkViewport viewport{};
5529 viewport.maxDepth = 1.0f;
5530 viewport.minDepth = 0.0f;
5531 viewport.width = 512;
5532 viewport.height = 512;
5533 viewport.x = 0;
5534 viewport.y = 0;
5535 vkCmdSetViewport(command_buffer[0], 0, 1, &viewport);
5536 vkEndCommandBuffer(command_buffer[0]);
5537 }
5538 {
5539 VkCommandBufferBeginInfo begin_info{};
5540 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
5541 vkBeginCommandBuffer(command_buffer[1], &begin_info);
5542
5543 VkViewport viewport{};
5544 viewport.maxDepth = 1.0f;
5545 viewport.minDepth = 0.0f;
5546 viewport.width = 512;
5547 viewport.height = 512;
5548 viewport.x = 0;
5549 viewport.y = 0;
5550 vkCmdSetViewport(command_buffer[1], 0, 1, &viewport);
5551 vkEndCommandBuffer(command_buffer[1]);
5552 }
5553 {
5554 VkSubmitInfo submit_info{};
5555 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
5556 submit_info.commandBufferCount = 1;
5557 submit_info.pCommandBuffers = &command_buffer[0];
5558 submit_info.signalSemaphoreCount = 1;
5559 submit_info.pSignalSemaphores = &semaphore;
5560 vkQueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE);
5561 }
5562 {
5563 VkPipelineStageFlags flags[]{VK_PIPELINE_STAGE_ALL_COMMANDS_BIT};
5564 VkSubmitInfo submit_info{};
5565 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
5566 submit_info.commandBufferCount = 1;
5567 submit_info.pCommandBuffers = &command_buffer[1];
5568 submit_info.waitSemaphoreCount = 1;
5569 submit_info.pWaitSemaphores = &semaphore;
5570 submit_info.pWaitDstStageMask = flags;
5571 vkQueueSubmit(m_device->m_queue, 1, &submit_info, fence);
5572 }
5573
5574 vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
5575 vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
5576
5577 vkDestroyFence(m_device->device(), fence, nullptr);
5578 vkDestroySemaphore(m_device->device(), semaphore, nullptr);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005579 vkFreeCommandBuffers(m_device->device(), command_pool, 2, &command_buffer[0]);
Mark Lobodzinskic808d442016-04-14 10:57:23 -06005580 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
5581
5582 m_errorMonitor->VerifyNotFound();
5583}
5584
Chris Forbes0f8126b2016-06-20 17:48:22 +12005585TEST_F(VkLayerTest, TwoQueuesEnsureCorrectRetirementWithWorkStolen) {
Cody Northropc31a84f2016-08-22 10:41:47 -06005586
5587 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005588 if ((m_device->queue_props.empty()) || (m_device->queue_props[0].queueCount < 2)) {
Chris Forbes0f8126b2016-06-20 17:48:22 +12005589 printf("Test requires two queues, skipping\n");
5590 return;
5591 }
5592
5593 VkResult err;
5594
5595 m_errorMonitor->ExpectSuccess();
5596
5597 VkQueue q0 = m_device->m_queue;
5598 VkQueue q1 = nullptr;
5599 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 1, &q1);
5600 ASSERT_NE(q1, nullptr);
5601
5602 // An (empty) command buffer. We must have work in the first submission --
5603 // the layer treats unfenced work differently from fenced work.
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005604 VkCommandPoolCreateInfo cpci = {VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO, nullptr, 0, 0};
Chris Forbes0f8126b2016-06-20 17:48:22 +12005605 VkCommandPool pool;
5606 err = vkCreateCommandPool(m_device->device(), &cpci, nullptr, &pool);
5607 ASSERT_VK_SUCCESS(err);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005608 VkCommandBufferAllocateInfo cbai = {VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO, nullptr, pool,
5609 VK_COMMAND_BUFFER_LEVEL_PRIMARY, 1};
Chris Forbes0f8126b2016-06-20 17:48:22 +12005610 VkCommandBuffer cb;
5611 err = vkAllocateCommandBuffers(m_device->device(), &cbai, &cb);
5612 ASSERT_VK_SUCCESS(err);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005613 VkCommandBufferBeginInfo cbbi = {VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO, nullptr, 0, nullptr};
Chris Forbes0f8126b2016-06-20 17:48:22 +12005614 err = vkBeginCommandBuffer(cb, &cbbi);
5615 ASSERT_VK_SUCCESS(err);
5616 err = vkEndCommandBuffer(cb);
5617 ASSERT_VK_SUCCESS(err);
5618
5619 // A semaphore
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005620 VkSemaphoreCreateInfo sci = {VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO, nullptr, 0};
Chris Forbes0f8126b2016-06-20 17:48:22 +12005621 VkSemaphore s;
5622 err = vkCreateSemaphore(m_device->device(), &sci, nullptr, &s);
5623 ASSERT_VK_SUCCESS(err);
5624
5625 // First submission, to q0
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005626 VkSubmitInfo s0 = {VK_STRUCTURE_TYPE_SUBMIT_INFO, nullptr, 0, nullptr, nullptr, 1, &cb, 1, &s};
Chris Forbes0f8126b2016-06-20 17:48:22 +12005627
5628 err = vkQueueSubmit(q0, 1, &s0, VK_NULL_HANDLE);
5629 ASSERT_VK_SUCCESS(err);
5630
5631 // Second submission, to q1, waiting on s
5632 VkFlags waitmask = VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT; // doesn't really matter what this value is.
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005633 VkSubmitInfo s1 = {VK_STRUCTURE_TYPE_SUBMIT_INFO, nullptr, 1, &s, &waitmask, 0, nullptr, 0, nullptr};
Chris Forbes0f8126b2016-06-20 17:48:22 +12005634
5635 err = vkQueueSubmit(q1, 1, &s1, VK_NULL_HANDLE);
5636 ASSERT_VK_SUCCESS(err);
5637
5638 // Wait for q0 idle
5639 err = vkQueueWaitIdle(q0);
5640 ASSERT_VK_SUCCESS(err);
5641
5642 // Command buffer should have been completed (it was on q0); reset the pool.
5643 vkFreeCommandBuffers(m_device->device(), pool, 1, &cb);
5644
5645 m_errorMonitor->VerifyNotFound();
5646
5647 // Force device completely idle and clean up resources
5648 vkDeviceWaitIdle(m_device->device());
5649 vkDestroyCommandPool(m_device->device(), pool, nullptr);
5650 vkDestroySemaphore(m_device->device(), s, nullptr);
5651}
Chris Forbes0f8126b2016-06-20 17:48:22 +12005652
Mark Lobodzinskic808d442016-04-14 10:57:23 -06005653// This is a positive test. No errors should be generated.
5654TEST_F(VkLayerTest, TwoQueueSubmitsSeparateQueuesWithSemaphoreAndOneFence) {
5655
5656 TEST_DESCRIPTION("Two command buffers, each in a separate QueueSubmit call "
5657 "submitted on separate queues, the second having a fence, "
5658 "followed by a WaitForFences call.");
5659
Cody Northropc31a84f2016-08-22 10:41:47 -06005660 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005661 if ((m_device->queue_props.empty()) || (m_device->queue_props[0].queueCount < 2))
Tony Barbourdc18b262016-04-22 14:49:48 -06005662 return;
5663
Mark Lobodzinskic808d442016-04-14 10:57:23 -06005664 m_errorMonitor->ExpectSuccess();
5665
Cody Northropc31a84f2016-08-22 10:41:47 -06005666 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinskic808d442016-04-14 10:57:23 -06005667 VkFence fence;
5668 VkFenceCreateInfo fence_create_info{};
5669 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
5670 vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence);
5671
5672 VkSemaphore semaphore;
5673 VkSemaphoreCreateInfo semaphore_create_info{};
5674 semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005675 vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr, &semaphore);
Mark Lobodzinskic808d442016-04-14 10:57:23 -06005676
5677 VkCommandPool command_pool;
5678 VkCommandPoolCreateInfo pool_create_info{};
5679 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
5680 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
5681 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005682 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
Mark Lobodzinskic808d442016-04-14 10:57:23 -06005683
5684 VkCommandBuffer command_buffer[2];
5685 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005686 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
Mark Lobodzinskic808d442016-04-14 10:57:23 -06005687 command_buffer_allocate_info.commandPool = command_pool;
5688 command_buffer_allocate_info.commandBufferCount = 2;
5689 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005690 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, command_buffer);
Mark Lobodzinskic808d442016-04-14 10:57:23 -06005691
5692 VkQueue queue = VK_NULL_HANDLE;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005693 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 1, &queue);
Mark Lobodzinskic808d442016-04-14 10:57:23 -06005694
5695 {
5696 VkCommandBufferBeginInfo begin_info{};
5697 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
5698 vkBeginCommandBuffer(command_buffer[0], &begin_info);
5699
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005700 vkCmdPipelineBarrier(command_buffer[0], VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0,
5701 nullptr, 0, nullptr, 0, nullptr);
Mark Lobodzinskic808d442016-04-14 10:57:23 -06005702
5703 VkViewport viewport{};
5704 viewport.maxDepth = 1.0f;
5705 viewport.minDepth = 0.0f;
5706 viewport.width = 512;
5707 viewport.height = 512;
5708 viewport.x = 0;
5709 viewport.y = 0;
5710 vkCmdSetViewport(command_buffer[0], 0, 1, &viewport);
5711 vkEndCommandBuffer(command_buffer[0]);
5712 }
5713 {
5714 VkCommandBufferBeginInfo begin_info{};
5715 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
5716 vkBeginCommandBuffer(command_buffer[1], &begin_info);
5717
5718 VkViewport viewport{};
5719 viewport.maxDepth = 1.0f;
5720 viewport.minDepth = 0.0f;
5721 viewport.width = 512;
5722 viewport.height = 512;
5723 viewport.x = 0;
5724 viewport.y = 0;
5725 vkCmdSetViewport(command_buffer[1], 0, 1, &viewport);
5726 vkEndCommandBuffer(command_buffer[1]);
5727 }
5728 {
5729 VkSubmitInfo submit_info{};
5730 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
5731 submit_info.commandBufferCount = 1;
5732 submit_info.pCommandBuffers = &command_buffer[0];
5733 submit_info.signalSemaphoreCount = 1;
5734 submit_info.pSignalSemaphores = &semaphore;
5735 vkQueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE);
5736 }
5737 {
5738 VkPipelineStageFlags flags[]{VK_PIPELINE_STAGE_ALL_COMMANDS_BIT};
5739 VkSubmitInfo submit_info{};
5740 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
5741 submit_info.commandBufferCount = 1;
5742 submit_info.pCommandBuffers = &command_buffer[1];
5743 submit_info.waitSemaphoreCount = 1;
5744 submit_info.pWaitSemaphores = &semaphore;
5745 submit_info.pWaitDstStageMask = flags;
5746 vkQueueSubmit(m_device->m_queue, 1, &submit_info, fence);
5747 }
5748
5749 vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
5750
5751 vkDestroyFence(m_device->device(), fence, nullptr);
5752 vkDestroySemaphore(m_device->device(), semaphore, nullptr);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005753 vkFreeCommandBuffers(m_device->device(), command_pool, 2, &command_buffer[0]);
Mark Lobodzinskic808d442016-04-14 10:57:23 -06005754 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
5755
5756 m_errorMonitor->VerifyNotFound();
5757}
5758
5759// This is a positive test. No errors should be generated.
5760TEST_F(VkLayerTest, TwoQueueSubmitsOneQueueWithSemaphoreAndOneFence) {
5761
5762 TEST_DESCRIPTION("Two command buffers, each in a separate QueueSubmit call "
5763 "on the same queue, sharing a signal/wait semaphore, the "
5764 "second having a fence, "
5765 "followed by a WaitForFences call.");
5766
5767 m_errorMonitor->ExpectSuccess();
5768
Cody Northropc31a84f2016-08-22 10:41:47 -06005769 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinskic808d442016-04-14 10:57:23 -06005770 VkFence fence;
5771 VkFenceCreateInfo fence_create_info{};
5772 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
5773 vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence);
5774
5775 VkSemaphore semaphore;
5776 VkSemaphoreCreateInfo semaphore_create_info{};
5777 semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005778 vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr, &semaphore);
Mark Lobodzinskic808d442016-04-14 10:57:23 -06005779
5780 VkCommandPool command_pool;
5781 VkCommandPoolCreateInfo pool_create_info{};
5782 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
5783 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
5784 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005785 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
Mark Lobodzinskic808d442016-04-14 10:57:23 -06005786
5787 VkCommandBuffer command_buffer[2];
5788 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005789 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
Mark Lobodzinskic808d442016-04-14 10:57:23 -06005790 command_buffer_allocate_info.commandPool = command_pool;
5791 command_buffer_allocate_info.commandBufferCount = 2;
5792 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005793 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, command_buffer);
Mark Lobodzinskic808d442016-04-14 10:57:23 -06005794
5795 {
5796 VkCommandBufferBeginInfo begin_info{};
5797 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
5798 vkBeginCommandBuffer(command_buffer[0], &begin_info);
5799
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005800 vkCmdPipelineBarrier(command_buffer[0], VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0,
5801 nullptr, 0, nullptr, 0, nullptr);
Mark Lobodzinskic808d442016-04-14 10:57:23 -06005802
5803 VkViewport viewport{};
5804 viewport.maxDepth = 1.0f;
5805 viewport.minDepth = 0.0f;
5806 viewport.width = 512;
5807 viewport.height = 512;
5808 viewport.x = 0;
5809 viewport.y = 0;
5810 vkCmdSetViewport(command_buffer[0], 0, 1, &viewport);
5811 vkEndCommandBuffer(command_buffer[0]);
5812 }
5813 {
5814 VkCommandBufferBeginInfo begin_info{};
5815 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
5816 vkBeginCommandBuffer(command_buffer[1], &begin_info);
5817
5818 VkViewport viewport{};
5819 viewport.maxDepth = 1.0f;
5820 viewport.minDepth = 0.0f;
5821 viewport.width = 512;
5822 viewport.height = 512;
5823 viewport.x = 0;
5824 viewport.y = 0;
5825 vkCmdSetViewport(command_buffer[1], 0, 1, &viewport);
5826 vkEndCommandBuffer(command_buffer[1]);
5827 }
5828 {
5829 VkSubmitInfo submit_info{};
5830 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
5831 submit_info.commandBufferCount = 1;
5832 submit_info.pCommandBuffers = &command_buffer[0];
5833 submit_info.signalSemaphoreCount = 1;
5834 submit_info.pSignalSemaphores = &semaphore;
5835 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
5836 }
5837 {
5838 VkPipelineStageFlags flags[]{VK_PIPELINE_STAGE_ALL_COMMANDS_BIT};
5839 VkSubmitInfo submit_info{};
5840 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
5841 submit_info.commandBufferCount = 1;
5842 submit_info.pCommandBuffers = &command_buffer[1];
5843 submit_info.waitSemaphoreCount = 1;
5844 submit_info.pWaitSemaphores = &semaphore;
5845 submit_info.pWaitDstStageMask = flags;
5846 vkQueueSubmit(m_device->m_queue, 1, &submit_info, fence);
5847 }
5848
5849 vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
5850
5851 vkDestroyFence(m_device->device(), fence, nullptr);
5852 vkDestroySemaphore(m_device->device(), semaphore, nullptr);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005853 vkFreeCommandBuffers(m_device->device(), command_pool, 2, &command_buffer[0]);
Mark Lobodzinskic808d442016-04-14 10:57:23 -06005854 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
5855
5856 m_errorMonitor->VerifyNotFound();
5857}
5858
5859// This is a positive test. No errors should be generated.
5860TEST_F(VkLayerTest, TwoQueueSubmitsOneQueueNullQueueSubmitWithFence) {
5861
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005862 TEST_DESCRIPTION("Two command buffers, each in a separate QueueSubmit call "
5863 "on the same queue, no fences, followed by a third QueueSubmit with NO "
5864 "SubmitInfos but with a fence, followed by a WaitForFences call.");
Mark Lobodzinskic808d442016-04-14 10:57:23 -06005865
5866 m_errorMonitor->ExpectSuccess();
5867
Cody Northropc31a84f2016-08-22 10:41:47 -06005868 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinskic808d442016-04-14 10:57:23 -06005869 VkFence fence;
5870 VkFenceCreateInfo fence_create_info{};
5871 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
5872 vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence);
5873
5874 VkCommandPool command_pool;
5875 VkCommandPoolCreateInfo pool_create_info{};
5876 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
5877 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
5878 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005879 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
Mark Lobodzinskic808d442016-04-14 10:57:23 -06005880
5881 VkCommandBuffer command_buffer[2];
5882 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005883 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
Mark Lobodzinskic808d442016-04-14 10:57:23 -06005884 command_buffer_allocate_info.commandPool = command_pool;
5885 command_buffer_allocate_info.commandBufferCount = 2;
5886 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005887 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, command_buffer);
Mark Lobodzinskic808d442016-04-14 10:57:23 -06005888
5889 {
5890 VkCommandBufferBeginInfo begin_info{};
5891 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
5892 vkBeginCommandBuffer(command_buffer[0], &begin_info);
5893
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005894 vkCmdPipelineBarrier(command_buffer[0], VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0,
5895 nullptr, 0, nullptr, 0, nullptr);
Mark Lobodzinskic808d442016-04-14 10:57:23 -06005896
5897 VkViewport viewport{};
5898 viewport.maxDepth = 1.0f;
5899 viewport.minDepth = 0.0f;
5900 viewport.width = 512;
5901 viewport.height = 512;
5902 viewport.x = 0;
5903 viewport.y = 0;
5904 vkCmdSetViewport(command_buffer[0], 0, 1, &viewport);
5905 vkEndCommandBuffer(command_buffer[0]);
5906 }
5907 {
5908 VkCommandBufferBeginInfo begin_info{};
5909 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
5910 vkBeginCommandBuffer(command_buffer[1], &begin_info);
5911
5912 VkViewport viewport{};
5913 viewport.maxDepth = 1.0f;
5914 viewport.minDepth = 0.0f;
5915 viewport.width = 512;
5916 viewport.height = 512;
5917 viewport.x = 0;
5918 viewport.y = 0;
5919 vkCmdSetViewport(command_buffer[1], 0, 1, &viewport);
5920 vkEndCommandBuffer(command_buffer[1]);
5921 }
5922 {
5923 VkSubmitInfo submit_info{};
5924 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
5925 submit_info.commandBufferCount = 1;
5926 submit_info.pCommandBuffers = &command_buffer[0];
5927 submit_info.signalSemaphoreCount = 0;
5928 submit_info.pSignalSemaphores = VK_NULL_HANDLE;
5929 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
5930 }
5931 {
5932 VkPipelineStageFlags flags[]{VK_PIPELINE_STAGE_ALL_COMMANDS_BIT};
5933 VkSubmitInfo submit_info{};
5934 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
5935 submit_info.commandBufferCount = 1;
5936 submit_info.pCommandBuffers = &command_buffer[1];
5937 submit_info.waitSemaphoreCount = 0;
5938 submit_info.pWaitSemaphores = VK_NULL_HANDLE;
5939 submit_info.pWaitDstStageMask = flags;
5940 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
5941 }
5942
5943 vkQueueSubmit(m_device->m_queue, 0, NULL, fence);
5944
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005945 VkResult err = vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
Mike Stroyancd1c3e52016-06-21 09:20:01 -06005946 ASSERT_VK_SUCCESS(err);
Mark Lobodzinskic808d442016-04-14 10:57:23 -06005947
5948 vkDestroyFence(m_device->device(), fence, nullptr);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005949 vkFreeCommandBuffers(m_device->device(), command_pool, 2, &command_buffer[0]);
Mark Lobodzinskic808d442016-04-14 10:57:23 -06005950 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
5951
5952 m_errorMonitor->VerifyNotFound();
5953}
5954
5955// This is a positive test. No errors should be generated.
5956TEST_F(VkLayerTest, TwoQueueSubmitsOneQueueOneFence) {
5957
5958 TEST_DESCRIPTION("Two command buffers, each in a separate QueueSubmit call "
5959 "on the same queue, the second having a fence, followed "
5960 "by a WaitForFences call.");
5961
5962 m_errorMonitor->ExpectSuccess();
5963
Cody Northropc31a84f2016-08-22 10:41:47 -06005964 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinskic808d442016-04-14 10:57:23 -06005965 VkFence fence;
5966 VkFenceCreateInfo fence_create_info{};
5967 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
5968 vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence);
5969
5970 VkCommandPool command_pool;
5971 VkCommandPoolCreateInfo pool_create_info{};
5972 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
5973 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
5974 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005975 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
Mark Lobodzinskic808d442016-04-14 10:57:23 -06005976
5977 VkCommandBuffer command_buffer[2];
5978 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005979 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
Mark Lobodzinskic808d442016-04-14 10:57:23 -06005980 command_buffer_allocate_info.commandPool = command_pool;
5981 command_buffer_allocate_info.commandBufferCount = 2;
5982 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005983 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, command_buffer);
Mark Lobodzinskic808d442016-04-14 10:57:23 -06005984
5985 {
5986 VkCommandBufferBeginInfo begin_info{};
5987 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
5988 vkBeginCommandBuffer(command_buffer[0], &begin_info);
5989
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005990 vkCmdPipelineBarrier(command_buffer[0], VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0,
5991 nullptr, 0, nullptr, 0, nullptr);
Mark Lobodzinskic808d442016-04-14 10:57:23 -06005992
5993 VkViewport viewport{};
5994 viewport.maxDepth = 1.0f;
5995 viewport.minDepth = 0.0f;
5996 viewport.width = 512;
5997 viewport.height = 512;
5998 viewport.x = 0;
5999 viewport.y = 0;
6000 vkCmdSetViewport(command_buffer[0], 0, 1, &viewport);
6001 vkEndCommandBuffer(command_buffer[0]);
6002 }
6003 {
6004 VkCommandBufferBeginInfo begin_info{};
6005 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
6006 vkBeginCommandBuffer(command_buffer[1], &begin_info);
6007
6008 VkViewport viewport{};
6009 viewport.maxDepth = 1.0f;
6010 viewport.minDepth = 0.0f;
6011 viewport.width = 512;
6012 viewport.height = 512;
6013 viewport.x = 0;
6014 viewport.y = 0;
6015 vkCmdSetViewport(command_buffer[1], 0, 1, &viewport);
6016 vkEndCommandBuffer(command_buffer[1]);
6017 }
6018 {
6019 VkSubmitInfo submit_info{};
6020 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
6021 submit_info.commandBufferCount = 1;
6022 submit_info.pCommandBuffers = &command_buffer[0];
6023 submit_info.signalSemaphoreCount = 0;
6024 submit_info.pSignalSemaphores = VK_NULL_HANDLE;
6025 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
6026 }
6027 {
6028 VkPipelineStageFlags flags[]{VK_PIPELINE_STAGE_ALL_COMMANDS_BIT};
6029 VkSubmitInfo submit_info{};
6030 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
6031 submit_info.commandBufferCount = 1;
6032 submit_info.pCommandBuffers = &command_buffer[1];
6033 submit_info.waitSemaphoreCount = 0;
6034 submit_info.pWaitSemaphores = VK_NULL_HANDLE;
6035 submit_info.pWaitDstStageMask = flags;
6036 vkQueueSubmit(m_device->m_queue, 1, &submit_info, fence);
6037 }
6038
6039 vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
6040
6041 vkDestroyFence(m_device->device(), fence, nullptr);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006042 vkFreeCommandBuffers(m_device->device(), command_pool, 2, &command_buffer[0]);
Mark Lobodzinskic808d442016-04-14 10:57:23 -06006043 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
6044
6045 m_errorMonitor->VerifyNotFound();
6046}
6047
6048// This is a positive test. No errors should be generated.
6049TEST_F(VkLayerTest, TwoSubmitInfosWithSemaphoreOneQueueSubmitsOneFence) {
6050
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006051 TEST_DESCRIPTION("Two command buffers each in a separate SubmitInfo sent in a single "
6052 "QueueSubmit call followed by a WaitForFences call.");
Cody Northropc31a84f2016-08-22 10:41:47 -06006053 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinskic808d442016-04-14 10:57:23 -06006054
6055 m_errorMonitor->ExpectSuccess();
6056
6057 VkFence fence;
6058 VkFenceCreateInfo fence_create_info{};
6059 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
6060 vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence);
6061
6062 VkSemaphore semaphore;
6063 VkSemaphoreCreateInfo semaphore_create_info{};
6064 semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006065 vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr, &semaphore);
Mark Lobodzinskic808d442016-04-14 10:57:23 -06006066
6067 VkCommandPool command_pool;
6068 VkCommandPoolCreateInfo pool_create_info{};
6069 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
6070 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
6071 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006072 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
Mark Lobodzinskic808d442016-04-14 10:57:23 -06006073
6074 VkCommandBuffer command_buffer[2];
6075 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006076 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
Mark Lobodzinskic808d442016-04-14 10:57:23 -06006077 command_buffer_allocate_info.commandPool = command_pool;
6078 command_buffer_allocate_info.commandBufferCount = 2;
6079 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006080 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, command_buffer);
Mark Lobodzinskic808d442016-04-14 10:57:23 -06006081
6082 {
6083 VkCommandBufferBeginInfo begin_info{};
6084 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
6085 vkBeginCommandBuffer(command_buffer[0], &begin_info);
6086
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006087 vkCmdPipelineBarrier(command_buffer[0], VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0,
6088 nullptr, 0, nullptr, 0, nullptr);
Mark Lobodzinskic808d442016-04-14 10:57:23 -06006089
6090 VkViewport viewport{};
6091 viewport.maxDepth = 1.0f;
6092 viewport.minDepth = 0.0f;
6093 viewport.width = 512;
6094 viewport.height = 512;
6095 viewport.x = 0;
6096 viewport.y = 0;
6097 vkCmdSetViewport(command_buffer[0], 0, 1, &viewport);
6098 vkEndCommandBuffer(command_buffer[0]);
6099 }
6100 {
6101 VkCommandBufferBeginInfo begin_info{};
6102 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
6103 vkBeginCommandBuffer(command_buffer[1], &begin_info);
6104
6105 VkViewport viewport{};
6106 viewport.maxDepth = 1.0f;
6107 viewport.minDepth = 0.0f;
6108 viewport.width = 512;
6109 viewport.height = 512;
6110 viewport.x = 0;
6111 viewport.y = 0;
6112 vkCmdSetViewport(command_buffer[1], 0, 1, &viewport);
6113 vkEndCommandBuffer(command_buffer[1]);
6114 }
6115 {
6116 VkSubmitInfo submit_info[2];
6117 VkPipelineStageFlags flags[]{VK_PIPELINE_STAGE_ALL_COMMANDS_BIT};
6118
6119 submit_info[0].sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
6120 submit_info[0].pNext = NULL;
6121 submit_info[0].commandBufferCount = 1;
6122 submit_info[0].pCommandBuffers = &command_buffer[0];
6123 submit_info[0].signalSemaphoreCount = 1;
6124 submit_info[0].pSignalSemaphores = &semaphore;
6125 submit_info[0].waitSemaphoreCount = 0;
6126 submit_info[0].pWaitSemaphores = NULL;
6127 submit_info[0].pWaitDstStageMask = 0;
6128
6129 submit_info[1].sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
6130 submit_info[1].pNext = NULL;
6131 submit_info[1].commandBufferCount = 1;
6132 submit_info[1].pCommandBuffers = &command_buffer[1];
6133 submit_info[1].waitSemaphoreCount = 1;
6134 submit_info[1].pWaitSemaphores = &semaphore;
6135 submit_info[1].pWaitDstStageMask = flags;
6136 submit_info[1].signalSemaphoreCount = 0;
6137 submit_info[1].pSignalSemaphores = NULL;
6138 vkQueueSubmit(m_device->m_queue, 2, &submit_info[0], fence);
6139 }
6140
6141 vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
6142
6143 vkDestroyFence(m_device->device(), fence, nullptr);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006144 vkFreeCommandBuffers(m_device->device(), command_pool, 2, &command_buffer[0]);
Mark Lobodzinskic808d442016-04-14 10:57:23 -06006145 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
Tony Barbourdf4c0042016-06-01 15:55:43 -06006146 vkDestroySemaphore(m_device->device(), semaphore, nullptr);
Mark Lobodzinskic808d442016-04-14 10:57:23 -06006147
6148 m_errorMonitor->VerifyNotFound();
6149}
6150
Tobin Ehlisb1a87992016-05-25 16:42:47 -06006151TEST_F(VkLayerTest, DynamicDepthBiasNotBound) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006152 TEST_DESCRIPTION("Run a simple draw calls to validate failure when Depth Bias dynamic "
6153 "state is required but not correctly bound.");
Tobin Ehlisb1a87992016-05-25 16:42:47 -06006154
Cody Northropc31a84f2016-08-22 10:41:47 -06006155 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisb1a87992016-05-25 16:42:47 -06006156 // Dynamic depth bias
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006157 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Dynamic depth bias state not set for this command buffer");
6158 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailDepthBias);
Tobin Ehlisb1a87992016-05-25 16:42:47 -06006159 m_errorMonitor->VerifyFound();
6160}
6161
6162TEST_F(VkLayerTest, DynamicLineWidthNotBound) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006163 TEST_DESCRIPTION("Run a simple draw calls to validate failure when Line Width dynamic "
6164 "state is required but not correctly bound.");
Tobin Ehlisa5200ef2016-05-03 10:34:08 -06006165
Cody Northropc31a84f2016-08-22 10:41:47 -06006166 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisa5200ef2016-05-03 10:34:08 -06006167 // Dynamic line width
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006168 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Dynamic line width state not set for this command buffer");
6169 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailLineWidth);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006170 m_errorMonitor->VerifyFound();
Tobin Ehlisb1a87992016-05-25 16:42:47 -06006171}
6172
6173TEST_F(VkLayerTest, DynamicViewportNotBound) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006174 TEST_DESCRIPTION("Run a simple draw calls to validate failure when Viewport dynamic "
6175 "state is required but not correctly bound.");
Tobin Ehlisb1a87992016-05-25 16:42:47 -06006176
Cody Northropc31a84f2016-08-22 10:41:47 -06006177 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisa5200ef2016-05-03 10:34:08 -06006178 // Dynamic viewport state
Chris Forbesb2ba95b2016-09-16 17:11:50 +12006179 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 -06006180 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailViewport);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006181 m_errorMonitor->VerifyFound();
Tobin Ehlisb1a87992016-05-25 16:42:47 -06006182}
6183
6184TEST_F(VkLayerTest, DynamicScissorNotBound) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006185 TEST_DESCRIPTION("Run a simple draw calls to validate failure when Scissor dynamic "
6186 "state is required but not correctly bound.");
Tobin Ehlisb1a87992016-05-25 16:42:47 -06006187
Cody Northropc31a84f2016-08-22 10:41:47 -06006188 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisa5200ef2016-05-03 10:34:08 -06006189 // Dynamic scissor state
Chris Forbesb2ba95b2016-09-16 17:11:50 +12006190 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 -06006191 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailScissor);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006192 m_errorMonitor->VerifyFound();
Tobin Ehlisb1a87992016-05-25 16:42:47 -06006193}
6194
Cortd713fe82016-07-27 09:51:27 -07006195TEST_F(VkLayerTest, DynamicBlendConstantsNotBound) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006196 TEST_DESCRIPTION("Run a simple draw calls to validate failure when Blend Constants "
6197 "dynamic state is required but not correctly bound.");
Cody Northropc31a84f2016-08-22 10:41:47 -06006198
6199 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlis21c88352016-05-26 06:15:45 -06006200 // Dynamic blend constant state
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006201 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
6202 "Dynamic blend constants state not set for this command buffer");
6203 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailBlend);
Tobin Ehlis21c88352016-05-26 06:15:45 -06006204 m_errorMonitor->VerifyFound();
6205}
6206
6207TEST_F(VkLayerTest, DynamicDepthBoundsNotBound) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006208 TEST_DESCRIPTION("Run a simple draw calls to validate failure when Depth Bounds dynamic "
6209 "state is required but not correctly bound.");
Cody Northropc31a84f2016-08-22 10:41:47 -06006210
6211 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlis21c88352016-05-26 06:15:45 -06006212 if (!m_device->phy().features().depthBounds) {
6213 printf("Device does not support depthBounds test; skipped.\n");
6214 return;
6215 }
6216 // Dynamic depth bounds
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006217 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
6218 "Dynamic depth bounds state not set for this command buffer");
6219 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailDepthBounds);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006220 m_errorMonitor->VerifyFound();
Tobin Ehlisb1a87992016-05-25 16:42:47 -06006221}
6222
6223TEST_F(VkLayerTest, DynamicStencilReadNotBound) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006224 TEST_DESCRIPTION("Run a simple draw calls to validate failure when Stencil Read dynamic "
6225 "state is required but not correctly bound.");
Cody Northropc31a84f2016-08-22 10:41:47 -06006226
6227 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisa5200ef2016-05-03 10:34:08 -06006228 // Dynamic stencil read mask
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006229 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
6230 "Dynamic stencil read mask state not set for this command buffer");
6231 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailStencilReadMask);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006232 m_errorMonitor->VerifyFound();
Tobin Ehlisb1a87992016-05-25 16:42:47 -06006233}
6234
6235TEST_F(VkLayerTest, DynamicStencilWriteNotBound) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006236 TEST_DESCRIPTION("Run a simple draw calls to validate failure when Stencil Write dynamic"
6237 " state is required but not correctly bound.");
Cody Northropc31a84f2016-08-22 10:41:47 -06006238
6239 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisa5200ef2016-05-03 10:34:08 -06006240 // Dynamic stencil write mask
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006241 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
6242 "Dynamic stencil write mask state not set for this command buffer");
6243 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailStencilWriteMask);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006244 m_errorMonitor->VerifyFound();
Tobin Ehlisb1a87992016-05-25 16:42:47 -06006245}
6246
6247TEST_F(VkLayerTest, DynamicStencilRefNotBound) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006248 TEST_DESCRIPTION("Run a simple draw calls to validate failure when Stencil Ref dynamic "
6249 "state is required but not correctly bound.");
Cody Northropc31a84f2016-08-22 10:41:47 -06006250
6251 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisa5200ef2016-05-03 10:34:08 -06006252 // Dynamic stencil reference
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006253 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
6254 "Dynamic stencil reference state not set for this command buffer");
6255 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailStencilReference);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006256 m_errorMonitor->VerifyFound();
Tobin Ehlis963a4042015-09-29 08:18:34 -06006257}
6258
Tobin Ehlis379ba3b2016-07-19 11:22:29 -06006259TEST_F(VkLayerTest, IndexBufferNotBound) {
6260 TEST_DESCRIPTION("Run an indexed draw call without an index buffer bound.");
Cody Northropc31a84f2016-08-22 10:41:47 -06006261
6262 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006263 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
6264 "Index buffer object not bound to this command buffer when Indexed ");
6265 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailIndexBuffer);
Tobin Ehlis379ba3b2016-07-19 11:22:29 -06006266 m_errorMonitor->VerifyFound();
6267}
6268
Karl Schultz6addd812016-02-02 17:17:23 -07006269TEST_F(VkLayerTest, CommandBufferTwoSubmits) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006270 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
6271 "was begun w/ VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT set, but has "
6272 "been submitted");
Tobin Ehlis59278bf2015-08-18 07:10:58 -06006273
Tobin Ehlis59278bf2015-08-18 07:10:58 -06006274 ASSERT_NO_FATAL_FAILURE(InitState());
6275 ASSERT_NO_FATAL_FAILURE(InitViewport());
6276 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
6277
Karl Schultz6addd812016-02-02 17:17:23 -07006278 // We luck out b/c by default the framework creates CB w/ the
6279 // VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT set
Tobin Ehlis59278bf2015-08-18 07:10:58 -06006280 BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006281 m_commandBuffer->ClearAllBuffers(m_clear_color, m_depth_clear_color, m_stencil_clear_color, NULL);
Tobin Ehlis59278bf2015-08-18 07:10:58 -06006282 EndCommandBuffer();
6283
Tobin Ehlis59278bf2015-08-18 07:10:58 -06006284 // Bypass framework since it does the waits automatically
6285 VkResult err = VK_SUCCESS;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06006286 VkSubmitInfo submit_info;
Chia-I Wuf9be13c2015-10-26 20:37:06 +08006287 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
6288 submit_info.pNext = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08006289 submit_info.waitSemaphoreCount = 0;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06006290 submit_info.pWaitSemaphores = NULL;
Jon Ashburn7f9716c2015-12-30 16:42:50 -07006291 submit_info.pWaitDstStageMask = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08006292 submit_info.commandBufferCount = 1;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08006293 submit_info.pCommandBuffers = &m_commandBuffer->handle();
Chia-I Wud50a7d72015-10-26 20:48:51 +08006294 submit_info.signalSemaphoreCount = 0;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06006295 submit_info.pSignalSemaphores = NULL;
6296
Chris Forbes40028e22016-06-13 09:59:34 +12006297 err = vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
Karl Schultz6addd812016-02-02 17:17:23 -07006298 ASSERT_VK_SUCCESS(err);
Tobin Ehlis59278bf2015-08-18 07:10:58 -06006299
Karl Schultz6addd812016-02-02 17:17:23 -07006300 // Cause validation error by re-submitting cmd buffer that should only be
6301 // submitted once
Chris Forbes40028e22016-06-13 09:59:34 +12006302 err = vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
Tobin Ehlis59278bf2015-08-18 07:10:58 -06006303
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006304 m_errorMonitor->VerifyFound();
Tobin Ehlis59278bf2015-08-18 07:10:58 -06006305}
6306
Karl Schultz6addd812016-02-02 17:17:23 -07006307TEST_F(VkLayerTest, AllocDescriptorFromEmptyPool) {
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06006308 // Initiate Draw w/o a PSO bound
Karl Schultz6addd812016-02-02 17:17:23 -07006309 VkResult err;
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06006310
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006311 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Unable to allocate 1 descriptors of "
6312 "type "
6313 "VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER ");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06006314
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06006315 ASSERT_NO_FATAL_FAILURE(InitState());
6316 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06006317
Karl Schultz6addd812016-02-02 17:17:23 -07006318 // Create Pool w/ 1 Sampler descriptor, but try to alloc Uniform Buffer
6319 // descriptor from it
Chia-I Wu1b99bb22015-10-27 19:25:11 +08006320 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006321 ds_type_count.type = VK_DESCRIPTOR_TYPE_SAMPLER;
6322 ds_type_count.descriptorCount = 1;
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06006323
6324 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006325 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
6326 ds_pool_ci.pNext = NULL;
6327 ds_pool_ci.flags = 0;
6328 ds_pool_ci.maxSets = 1;
6329 ds_pool_ci.poolSizeCount = 1;
6330 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06006331
6332 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006333 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06006334 ASSERT_VK_SUCCESS(err);
6335
6336 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006337 dsl_binding.binding = 0;
6338 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
6339 dsl_binding.descriptorCount = 1;
6340 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
6341 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06006342
6343 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006344 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
6345 ds_layout_ci.pNext = NULL;
6346 ds_layout_ci.bindingCount = 1;
6347 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06006348
6349 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006350 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06006351 ASSERT_VK_SUCCESS(err);
6352
6353 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08006354 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08006355 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07006356 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06006357 alloc_info.descriptorPool = ds_pool;
6358 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006359 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06006360
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006361 m_errorMonitor->VerifyFound();
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06006362
Chia-I Wuf7458c52015-10-26 21:10:41 +08006363 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
6364 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06006365}
6366
Karl Schultz6addd812016-02-02 17:17:23 -07006367TEST_F(VkLayerTest, FreeDescriptorFromOneShotPool) {
6368 VkResult err;
Tobin Ehlise735c692015-10-08 13:13:50 -06006369
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006370 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
6371 "It is invalid to call vkFreeDescriptorSets() with a pool created "
6372 "without setting VK_DESCRIPTOR_POOL_CREATE_FREE_DESCRIPTOR_SET_BIT.");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06006373
Tobin Ehlise735c692015-10-08 13:13:50 -06006374 ASSERT_NO_FATAL_FAILURE(InitState());
6375 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlise735c692015-10-08 13:13:50 -06006376
Chia-I Wu1b99bb22015-10-27 19:25:11 +08006377 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006378 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
6379 ds_type_count.descriptorCount = 1;
Tobin Ehlise735c692015-10-08 13:13:50 -06006380
6381 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006382 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
6383 ds_pool_ci.pNext = NULL;
6384 ds_pool_ci.maxSets = 1;
6385 ds_pool_ci.poolSizeCount = 1;
6386 ds_pool_ci.flags = 0;
6387 // Not specifying VK_DESCRIPTOR_POOL_CREATE_FREE_DESCRIPTOR_SET_BIT means
6388 // app can only call vkResetDescriptorPool on this pool.;
6389 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlise735c692015-10-08 13:13:50 -06006390
6391 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006392 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlise735c692015-10-08 13:13:50 -06006393 ASSERT_VK_SUCCESS(err);
6394
6395 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006396 dsl_binding.binding = 0;
6397 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
6398 dsl_binding.descriptorCount = 1;
6399 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
6400 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlise735c692015-10-08 13:13:50 -06006401
6402 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006403 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
6404 ds_layout_ci.pNext = NULL;
6405 ds_layout_ci.bindingCount = 1;
6406 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlise735c692015-10-08 13:13:50 -06006407
6408 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006409 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlise735c692015-10-08 13:13:50 -06006410 ASSERT_VK_SUCCESS(err);
6411
6412 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08006413 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08006414 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07006415 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06006416 alloc_info.descriptorPool = ds_pool;
6417 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006418 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlise735c692015-10-08 13:13:50 -06006419 ASSERT_VK_SUCCESS(err);
6420
6421 err = vkFreeDescriptorSets(m_device->device(), ds_pool, 1, &descriptorSet);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006422 m_errorMonitor->VerifyFound();
Tobin Ehlise735c692015-10-08 13:13:50 -06006423
Chia-I Wuf7458c52015-10-26 21:10:41 +08006424 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
6425 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlise735c692015-10-08 13:13:50 -06006426}
6427
Karl Schultz6addd812016-02-02 17:17:23 -07006428TEST_F(VkLayerTest, InvalidDescriptorPool) {
Karl Schultzbdb75952016-04-19 11:36:49 -06006429 // Attempt to clear Descriptor Pool with bad object.
6430 // ObjectTracker should catch this.
Cody Northropc31a84f2016-08-22 10:41:47 -06006431
6432 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006433 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Invalid Descriptor Pool Object 0xbaad6001");
Mark Lobodzinski02bf89d2016-05-10 14:45:13 -06006434 uint64_t fake_pool_handle = 0xbaad6001;
6435 VkDescriptorPool bad_pool = reinterpret_cast<VkDescriptorPool &>(fake_pool_handle);
6436 vkResetDescriptorPool(device(), bad_pool, 0);
Karl Schultzbdb75952016-04-19 11:36:49 -06006437 m_errorMonitor->VerifyFound();
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06006438}
6439
Karl Schultz6addd812016-02-02 17:17:23 -07006440TEST_F(VkLayerTest, InvalidDescriptorSet) {
Karl Schultzbdb75952016-04-19 11:36:49 -06006441 // Attempt to bind an invalid Descriptor Set to a valid Command Buffer
6442 // ObjectTracker should catch this.
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06006443 // Create a valid cmd buffer
Karl Schultzbdb75952016-04-19 11:36:49 -06006444 // call vkCmdBindDescriptorSets w/ false Descriptor Set
Mark Lobodzinski02bf89d2016-05-10 14:45:13 -06006445
6446 uint64_t fake_set_handle = 0xbaad6001;
6447 VkDescriptorSet bad_set = reinterpret_cast<VkDescriptorSet &>(fake_set_handle);
Karl Schultzbdb75952016-04-19 11:36:49 -06006448 VkResult err;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006449 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Invalid Descriptor Set Object 0xbaad6001");
Karl Schultzbdb75952016-04-19 11:36:49 -06006450
6451 ASSERT_NO_FATAL_FAILURE(InitState());
6452
6453 VkDescriptorSetLayoutBinding layout_bindings[1] = {};
6454 layout_bindings[0].binding = 0;
6455 layout_bindings[0].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
6456 layout_bindings[0].descriptorCount = 1;
6457 layout_bindings[0].stageFlags = VK_SHADER_STAGE_VERTEX_BIT;
6458 layout_bindings[0].pImmutableSamplers = NULL;
6459
6460 VkDescriptorSetLayout descriptor_set_layout;
6461 VkDescriptorSetLayoutCreateInfo dslci = {};
6462 dslci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
6463 dslci.pNext = NULL;
6464 dslci.bindingCount = 1;
6465 dslci.pBindings = layout_bindings;
6466 err = vkCreateDescriptorSetLayout(device(), &dslci, NULL, &descriptor_set_layout);
Karl Schultz5cb21112016-04-21 17:17:40 -06006467 ASSERT_VK_SUCCESS(err);
Karl Schultzbdb75952016-04-19 11:36:49 -06006468
6469 VkPipelineLayout pipeline_layout;
6470 VkPipelineLayoutCreateInfo plci = {};
6471 plci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
6472 plci.pNext = NULL;
6473 plci.setLayoutCount = 1;
6474 plci.pSetLayouts = &descriptor_set_layout;
6475 err = vkCreatePipelineLayout(device(), &plci, NULL, &pipeline_layout);
Karl Schultz5cb21112016-04-21 17:17:40 -06006476 ASSERT_VK_SUCCESS(err);
Karl Schultzbdb75952016-04-19 11:36:49 -06006477
6478 BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006479 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1, &bad_set, 0,
6480 NULL);
Karl Schultzbdb75952016-04-19 11:36:49 -06006481 m_errorMonitor->VerifyFound();
6482 EndCommandBuffer();
6483 vkDestroyPipelineLayout(device(), pipeline_layout, NULL);
6484 vkDestroyDescriptorSetLayout(device(), descriptor_set_layout, NULL);
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06006485}
6486
Karl Schultz6addd812016-02-02 17:17:23 -07006487TEST_F(VkLayerTest, InvalidDescriptorSetLayout) {
Karl Schultzbdb75952016-04-19 11:36:49 -06006488 // Attempt to create a Pipeline Layout with an invalid Descriptor Set Layout.
6489 // ObjectTracker should catch this.
Mark Lobodzinski02bf89d2016-05-10 14:45:13 -06006490 uint64_t fake_layout_handle = 0xbaad6001;
6491 VkDescriptorSetLayout bad_layout = reinterpret_cast<VkDescriptorSetLayout &>(fake_layout_handle);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006492 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Invalid Descriptor Set Layout Object 0xbaad6001");
Cody Northropc31a84f2016-08-22 10:41:47 -06006493 ASSERT_NO_FATAL_FAILURE(InitState());
Karl Schultzbdb75952016-04-19 11:36:49 -06006494 VkPipelineLayout pipeline_layout;
6495 VkPipelineLayoutCreateInfo plci = {};
6496 plci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
6497 plci.pNext = NULL;
6498 plci.setLayoutCount = 1;
6499 plci.pSetLayouts = &bad_layout;
6500 vkCreatePipelineLayout(device(), &plci, NULL, &pipeline_layout);
6501
6502 m_errorMonitor->VerifyFound();
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06006503}
6504
Mark Muellerd4914412016-06-13 17:52:06 -06006505TEST_F(VkLayerTest, WriteDescriptorSetIntegrityCheck) {
6506 TEST_DESCRIPTION("This test verifies some requirements of chapter 13.2.3 of the Vulkan Spec "
6507 "1) A uniform buffer update must have a valid buffer index."
6508 "2) When using an array of descriptors in a single WriteDescriptor,"
6509 " the descriptor types and stageflags must all be the same."
6510 "3) Immutable Sampler state must match across descriptors");
6511
6512 const char *invalid_BufferInfo_ErrorMessage =
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006513 "vkUpdateDescriptorSets: if pDescriptorWrites[0].descriptorType is VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, "
6514 "VK_DESCRIPTOR_TYPE_STORAGE_BUFFER, VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC or "
6515 "VK_DESCRIPTOR_TYPE_STORAGE_BUFFER_DYNAMIC, pDescriptorWrites[0].pBufferInfo must not be NULL";
6516 const char *stateFlag_ErrorMessage = "Attempting write update to descriptor set ";
6517 const char *immutable_ErrorMessage = "Attempting write update to descriptor set ";
Mark Muellerd4914412016-06-13 17:52:06 -06006518
Mark Muellerd4914412016-06-13 17:52:06 -06006519 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, invalid_BufferInfo_ErrorMessage);
6520
6521 ASSERT_NO_FATAL_FAILURE(InitState());
6522 VkDescriptorPoolSize ds_type_count[4] = {};
6523 ds_type_count[0].type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
6524 ds_type_count[0].descriptorCount = 1;
6525 ds_type_count[1].type = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
6526 ds_type_count[1].descriptorCount = 1;
6527 ds_type_count[2].type = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
6528 ds_type_count[2].descriptorCount = 1;
6529 ds_type_count[3].type = VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT;
6530 ds_type_count[3].descriptorCount = 1;
6531
6532 VkDescriptorPoolCreateInfo ds_pool_ci = {};
6533 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
6534 ds_pool_ci.maxSets = 1;
6535 ds_pool_ci.poolSizeCount = sizeof(ds_type_count) / sizeof(VkDescriptorPoolSize);
6536 ds_pool_ci.pPoolSizes = ds_type_count;
6537
6538 VkDescriptorPool ds_pool;
6539 VkResult err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
6540 ASSERT_VK_SUCCESS(err);
6541
Mark Muellerb9896722016-06-16 09:54:29 -06006542 VkDescriptorSetLayoutBinding layout_binding[3] = {};
Mark Muellerd4914412016-06-13 17:52:06 -06006543 layout_binding[0].binding = 0;
6544 layout_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
6545 layout_binding[0].descriptorCount = 1;
6546 layout_binding[0].stageFlags = VK_SHADER_STAGE_ALL;
6547 layout_binding[0].pImmutableSamplers = NULL;
6548
6549 layout_binding[1].binding = 1;
6550 layout_binding[1].descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
6551 layout_binding[1].descriptorCount = 1;
6552 layout_binding[1].stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
6553 layout_binding[1].pImmutableSamplers = NULL;
6554
6555 VkSamplerCreateInfo sampler_ci = {};
6556 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
6557 sampler_ci.pNext = NULL;
6558 sampler_ci.magFilter = VK_FILTER_NEAREST;
6559 sampler_ci.minFilter = VK_FILTER_NEAREST;
6560 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
6561 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
6562 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
6563 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
6564 sampler_ci.mipLodBias = 1.0;
6565 sampler_ci.anisotropyEnable = VK_FALSE;
6566 sampler_ci.maxAnisotropy = 1;
6567 sampler_ci.compareEnable = VK_FALSE;
6568 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
6569 sampler_ci.minLod = 1.0;
6570 sampler_ci.maxLod = 1.0;
6571 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
6572 sampler_ci.unnormalizedCoordinates = VK_FALSE;
6573 VkSampler sampler;
6574
6575 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
6576 ASSERT_VK_SUCCESS(err);
6577
6578 layout_binding[2].binding = 2;
6579 layout_binding[2].descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
6580 layout_binding[2].descriptorCount = 1;
6581 layout_binding[2].stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
6582 layout_binding[2].pImmutableSamplers = static_cast<VkSampler *>(&sampler);
6583
Mark Muellerd4914412016-06-13 17:52:06 -06006584 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
6585 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
6586 ds_layout_ci.bindingCount = sizeof(layout_binding) / sizeof(VkDescriptorSetLayoutBinding);
6587 ds_layout_ci.pBindings = layout_binding;
6588 VkDescriptorSetLayout ds_layout;
6589 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
6590 ASSERT_VK_SUCCESS(err);
6591
6592 VkDescriptorSetAllocateInfo alloc_info = {};
6593 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
6594 alloc_info.descriptorSetCount = 1;
6595 alloc_info.descriptorPool = ds_pool;
6596 alloc_info.pSetLayouts = &ds_layout;
6597 VkDescriptorSet descriptorSet;
6598 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
6599 ASSERT_VK_SUCCESS(err);
6600
6601 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
6602 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
6603 pipeline_layout_ci.pNext = NULL;
6604 pipeline_layout_ci.setLayoutCount = 1;
6605 pipeline_layout_ci.pSetLayouts = &ds_layout;
6606
6607 VkPipelineLayout pipeline_layout;
6608 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
6609 ASSERT_VK_SUCCESS(err);
6610
Mark Mueller5c838ce2016-06-16 09:54:29 -06006611 VkWriteDescriptorSet descriptor_write = {};
Mark Muellerd4914412016-06-13 17:52:06 -06006612 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
6613 descriptor_write.dstSet = descriptorSet;
6614 descriptor_write.dstBinding = 0;
6615 descriptor_write.descriptorCount = 1;
6616 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
6617
Mark Mueller5c838ce2016-06-16 09:54:29 -06006618 // 1) The uniform buffer is intentionally invalid here
Mark Muellerd4914412016-06-13 17:52:06 -06006619 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
6620 m_errorMonitor->VerifyFound();
6621
6622 // Create a buffer to update the descriptor with
6623 uint32_t qfi = 0;
6624 VkBufferCreateInfo buffCI = {};
6625 buffCI.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
6626 buffCI.size = 1024;
6627 buffCI.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
6628 buffCI.queueFamilyIndexCount = 1;
6629 buffCI.pQueueFamilyIndices = &qfi;
6630
6631 VkBuffer dyub;
6632 err = vkCreateBuffer(m_device->device(), &buffCI, NULL, &dyub);
6633 ASSERT_VK_SUCCESS(err);
6634 VkDescriptorBufferInfo buffInfo = {};
6635 buffInfo.buffer = dyub;
6636 buffInfo.offset = 0;
6637 buffInfo.range = 1024;
6638
6639 descriptor_write.pBufferInfo = &buffInfo;
6640 descriptor_write.descriptorCount = 2;
6641
Mark Mueller5c838ce2016-06-16 09:54:29 -06006642 // 2) The stateFlags don't match between the first and second descriptor
Mark Muellerd4914412016-06-13 17:52:06 -06006643 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, stateFlag_ErrorMessage);
6644 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
6645 m_errorMonitor->VerifyFound();
6646
Mark Mueller5c838ce2016-06-16 09:54:29 -06006647 // 3) The second descriptor has a null_ptr pImmutableSamplers and
6648 // the third descriptor contains an immutable sampler
Mark Muellerd4914412016-06-13 17:52:06 -06006649 descriptor_write.dstBinding = 1;
6650 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
Mark Mueller5c838ce2016-06-16 09:54:29 -06006651
Mark Mueller5c838ce2016-06-16 09:54:29 -06006652 // Make pImageInfo index non-null to avoid complaints of it missing
6653 VkDescriptorImageInfo imageInfo = {};
6654 imageInfo.imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
6655 descriptor_write.pImageInfo = &imageInfo;
Mark Muellerd4914412016-06-13 17:52:06 -06006656 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, immutable_ErrorMessage);
6657 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
6658 m_errorMonitor->VerifyFound();
6659
Mark Muellerd4914412016-06-13 17:52:06 -06006660 vkDestroyBuffer(m_device->device(), dyub, NULL);
6661 vkDestroySampler(m_device->device(), sampler, NULL);
6662 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
6663 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
6664 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
6665}
6666
Tobin Ehlis0283c4d2016-06-28 17:57:07 -06006667TEST_F(VkLayerTest, InvalidCmdBufferBufferDestroyed) {
6668 TEST_DESCRIPTION("Attempt to draw with a command buffer that is invalid "
6669 "due to a buffer dependency being destroyed.");
6670 ASSERT_NO_FATAL_FAILURE(InitState());
6671
Tobin Ehlis0283c4d2016-06-28 17:57:07 -06006672 VkBuffer buffer;
6673 VkDeviceMemory mem;
6674 VkMemoryRequirements mem_reqs;
6675
6676 VkBufferCreateInfo buf_info = {};
6677 buf_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
Chris Forbes3d5882f2016-09-16 17:37:17 +12006678 buf_info.usage = VK_BUFFER_USAGE_TRANSFER_DST_BIT;
Tobin Ehlis0283c4d2016-06-28 17:57:07 -06006679 buf_info.size = 256;
6680 buf_info.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
6681 VkResult err = vkCreateBuffer(m_device->device(), &buf_info, NULL, &buffer);
6682 ASSERT_VK_SUCCESS(err);
6683
6684 vkGetBufferMemoryRequirements(m_device->device(), buffer, &mem_reqs);
6685
6686 VkMemoryAllocateInfo alloc_info = {};
6687 alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
6688 alloc_info.allocationSize = 256;
6689 bool pass = false;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006690 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 -06006691 if (!pass) {
6692 vkDestroyBuffer(m_device->device(), buffer, NULL);
6693 return;
6694 }
6695 err = vkAllocateMemory(m_device->device(), &alloc_info, NULL, &mem);
6696 ASSERT_VK_SUCCESS(err);
6697
6698 err = vkBindBufferMemory(m_device->device(), buffer, mem, 0);
6699 ASSERT_VK_SUCCESS(err);
6700
Tobin Ehlis0283c4d2016-06-28 17:57:07 -06006701 m_commandBuffer->BeginCommandBuffer();
Chris Forbes3d5882f2016-09-16 17:37:17 +12006702 vkCmdFillBuffer(m_commandBuffer->GetBufferHandle(), buffer, 0, VK_WHOLE_SIZE, 0);
Tobin Ehlis0283c4d2016-06-28 17:57:07 -06006703 m_commandBuffer->EndCommandBuffer();
6704
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006705 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " that is invalid because bound buffer ");
Tobin Ehlis0283c4d2016-06-28 17:57:07 -06006706 // Destroy buffer dependency prior to submit to cause ERROR
6707 vkDestroyBuffer(m_device->device(), buffer, NULL);
6708
6709 VkSubmitInfo submit_info = {};
6710 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
6711 submit_info.commandBufferCount = 1;
6712 submit_info.pCommandBuffers = &m_commandBuffer->handle();
6713 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
6714
6715 m_errorMonitor->VerifyFound();
6716 vkFreeMemory(m_device->handle(), mem, NULL);
6717}
6718
Tobin Ehlis11c8cea2016-06-28 17:44:21 -06006719TEST_F(VkLayerTest, InvalidCmdBufferImageDestroyed) {
6720 TEST_DESCRIPTION("Attempt to draw with a command buffer that is invalid "
6721 "due to an image dependency being destroyed.");
6722 ASSERT_NO_FATAL_FAILURE(InitState());
6723
6724 VkImage image;
6725 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
6726 VkImageCreateInfo image_create_info = {};
6727 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
6728 image_create_info.pNext = NULL;
6729 image_create_info.imageType = VK_IMAGE_TYPE_2D;
6730 image_create_info.format = tex_format;
6731 image_create_info.extent.width = 32;
6732 image_create_info.extent.height = 32;
6733 image_create_info.extent.depth = 1;
6734 image_create_info.mipLevels = 1;
6735 image_create_info.arrayLayers = 1;
6736 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
6737 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006738 image_create_info.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT;
Tobin Ehlis11c8cea2016-06-28 17:44:21 -06006739 image_create_info.flags = 0;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006740 VkResult err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
Tobin Ehlis11c8cea2016-06-28 17:44:21 -06006741 ASSERT_VK_SUCCESS(err);
Tobin Ehlis3d09fd52016-07-06 08:12:56 -06006742 // Have to bind memory to image before recording cmd in cmd buffer using it
6743 VkMemoryRequirements mem_reqs;
6744 VkDeviceMemory image_mem;
6745 bool pass;
6746 VkMemoryAllocateInfo mem_alloc = {};
6747 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
6748 mem_alloc.pNext = NULL;
6749 mem_alloc.memoryTypeIndex = 0;
6750 vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs);
6751 mem_alloc.allocationSize = mem_reqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006752 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0);
Tobin Ehlis3d09fd52016-07-06 08:12:56 -06006753 ASSERT_TRUE(pass);
6754 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &image_mem);
6755 ASSERT_VK_SUCCESS(err);
6756 err = vkBindImageMemory(m_device->device(), image, image_mem, 0);
6757 ASSERT_VK_SUCCESS(err);
Tobin Ehlis11c8cea2016-06-28 17:44:21 -06006758
Tobin Ehlis11c8cea2016-06-28 17:44:21 -06006759 m_commandBuffer->BeginCommandBuffer();
Tobin Ehlis764d7072016-07-01 12:54:29 -06006760 VkClearColorValue ccv;
6761 ccv.float32[0] = 1.0f;
6762 ccv.float32[1] = 1.0f;
6763 ccv.float32[2] = 1.0f;
6764 ccv.float32[3] = 1.0f;
6765 VkImageSubresourceRange isr = {};
6766 isr.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Tobin Ehlis3d09fd52016-07-06 08:12:56 -06006767 isr.baseArrayLayer = 0;
6768 isr.baseMipLevel = 0;
Tobin Ehlis764d7072016-07-01 12:54:29 -06006769 isr.layerCount = 1;
6770 isr.levelCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006771 vkCmdClearColorImage(m_commandBuffer->GetBufferHandle(), image, VK_IMAGE_LAYOUT_GENERAL, &ccv, 1, &isr);
Tobin Ehlis11c8cea2016-06-28 17:44:21 -06006772 m_commandBuffer->EndCommandBuffer();
6773
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006774 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " that is invalid because bound image ");
Tobin Ehlis11c8cea2016-06-28 17:44:21 -06006775 // Destroy image dependency prior to submit to cause ERROR
6776 vkDestroyImage(m_device->device(), image, NULL);
6777
6778 VkSubmitInfo submit_info = {};
6779 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
6780 submit_info.commandBufferCount = 1;
6781 submit_info.pCommandBuffers = &m_commandBuffer->handle();
6782 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
6783
6784 m_errorMonitor->VerifyFound();
Tobin Ehlis3d09fd52016-07-06 08:12:56 -06006785 vkFreeMemory(m_device->device(), image_mem, nullptr);
Tobin Ehlis11c8cea2016-06-28 17:44:21 -06006786}
6787
Tobin Ehlis59f68ab2016-09-06 21:59:07 -06006788TEST_F(VkLayerTest, InvalidCmdBufferFramebufferImageDestroyed) {
6789 TEST_DESCRIPTION("Attempt to draw with a command buffer that is invalid "
6790 "due to a framebuffer image dependency being destroyed.");
6791 VkFormatProperties format_properties;
6792 VkResult err = VK_SUCCESS;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006793 vkGetPhysicalDeviceFormatProperties(gpu(), VK_FORMAT_B8G8R8A8_UNORM, &format_properties);
6794 if (!(format_properties.optimalTilingFeatures & VK_FORMAT_FEATURE_SAMPLED_IMAGE_BIT)) {
Tobin Ehlis59f68ab2016-09-06 21:59:07 -06006795 return;
6796 }
6797
6798 ASSERT_NO_FATAL_FAILURE(InitState());
6799 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
6800
6801 VkImageCreateInfo image_ci = {};
6802 image_ci.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
6803 image_ci.pNext = NULL;
6804 image_ci.imageType = VK_IMAGE_TYPE_2D;
6805 image_ci.format = VK_FORMAT_B8G8R8A8_UNORM;
6806 image_ci.extent.width = 32;
6807 image_ci.extent.height = 32;
6808 image_ci.extent.depth = 1;
6809 image_ci.mipLevels = 1;
6810 image_ci.arrayLayers = 1;
6811 image_ci.samples = VK_SAMPLE_COUNT_1_BIT;
6812 image_ci.tiling = VK_IMAGE_TILING_OPTIMAL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006813 image_ci.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_SAMPLED_BIT;
Tobin Ehlis59f68ab2016-09-06 21:59:07 -06006814 image_ci.initialLayout = VK_IMAGE_LAYOUT_UNDEFINED;
6815 image_ci.flags = 0;
6816 VkImage image;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006817 ASSERT_VK_SUCCESS(vkCreateImage(m_device->handle(), &image_ci, NULL, &image));
Tobin Ehlis59f68ab2016-09-06 21:59:07 -06006818
6819 VkMemoryRequirements memory_reqs;
6820 VkDeviceMemory image_memory;
6821 bool pass;
6822 VkMemoryAllocateInfo memory_info = {};
6823 memory_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
6824 memory_info.pNext = NULL;
6825 memory_info.allocationSize = 0;
6826 memory_info.memoryTypeIndex = 0;
6827 vkGetImageMemoryRequirements(m_device->device(), image, &memory_reqs);
6828 memory_info.allocationSize = memory_reqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006829 pass = m_device->phy().set_memory_type(memory_reqs.memoryTypeBits, &memory_info, 0);
Tobin Ehlis59f68ab2016-09-06 21:59:07 -06006830 ASSERT_TRUE(pass);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006831 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &image_memory);
Tobin Ehlis59f68ab2016-09-06 21:59:07 -06006832 ASSERT_VK_SUCCESS(err);
6833 err = vkBindImageMemory(m_device->device(), image, image_memory, 0);
6834 ASSERT_VK_SUCCESS(err);
6835
6836 VkImageViewCreateInfo ivci = {
6837 VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO,
6838 nullptr,
6839 0,
6840 image,
6841 VK_IMAGE_VIEW_TYPE_2D,
6842 VK_FORMAT_B8G8R8A8_UNORM,
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006843 {VK_COMPONENT_SWIZZLE_R, VK_COMPONENT_SWIZZLE_G, VK_COMPONENT_SWIZZLE_B, VK_COMPONENT_SWIZZLE_A},
Tobin Ehlis59f68ab2016-09-06 21:59:07 -06006844 {VK_IMAGE_ASPECT_COLOR_BIT, 0, 1, 0, 1},
6845 };
6846 VkImageView view;
6847 err = vkCreateImageView(m_device->device(), &ivci, nullptr, &view);
6848 ASSERT_VK_SUCCESS(err);
6849
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006850 VkFramebufferCreateInfo fci = {VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr, 0, m_renderPass, 1, &view, 32, 32, 1};
Tobin Ehlis59f68ab2016-09-06 21:59:07 -06006851 VkFramebuffer fb;
6852 err = vkCreateFramebuffer(m_device->device(), &fci, nullptr, &fb);
6853 ASSERT_VK_SUCCESS(err);
6854
6855 // Just use default renderpass with our framebuffer
6856 m_renderPassBeginInfo.framebuffer = fb;
6857 // Create Null cmd buffer for submit
6858 BeginCommandBuffer();
6859 EndCommandBuffer();
6860 // Destroy image attached to framebuffer to invalidate cmd buffer
6861 vkDestroyImage(m_device->device(), image, NULL);
6862 // Now attempt to submit cmd buffer and verify error
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006863 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " that is invalid because bound image ");
Tobin Ehlis59f68ab2016-09-06 21:59:07 -06006864 QueueCommandBuffer(false);
6865 m_errorMonitor->VerifyFound();
6866
6867 vkDestroyFramebuffer(m_device->device(), fb, nullptr);
6868 vkDestroyImageView(m_device->device(), view, nullptr);
6869 vkFreeMemory(m_device->device(), image_memory, nullptr);
6870}
6871
Tobin Ehlis88becd72016-09-21 14:33:41 -06006872TEST_F(VkLayerTest, FramebufferImageInUseDestroyedSignaled) {
6873 TEST_DESCRIPTION("Delete in-use image that's child of framebuffer.");
6874 VkFormatProperties format_properties;
6875 VkResult err = VK_SUCCESS;
6876 vkGetPhysicalDeviceFormatProperties(gpu(), VK_FORMAT_B8G8R8A8_UNORM, &format_properties);
Tobin Ehlis88becd72016-09-21 14:33:41 -06006877
6878 ASSERT_NO_FATAL_FAILURE(InitState());
6879 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
6880
6881 VkImageCreateInfo image_ci = {};
6882 image_ci.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
6883 image_ci.pNext = NULL;
6884 image_ci.imageType = VK_IMAGE_TYPE_2D;
6885 image_ci.format = VK_FORMAT_B8G8R8A8_UNORM;
6886 image_ci.extent.width = 256;
6887 image_ci.extent.height = 256;
6888 image_ci.extent.depth = 1;
6889 image_ci.mipLevels = 1;
6890 image_ci.arrayLayers = 1;
6891 image_ci.samples = VK_SAMPLE_COUNT_1_BIT;
6892 image_ci.tiling = VK_IMAGE_TILING_OPTIMAL;
Tobin Ehlisc8ca0312016-09-22 07:30:05 -06006893 image_ci.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
Tobin Ehlis88becd72016-09-21 14:33:41 -06006894 image_ci.initialLayout = VK_IMAGE_LAYOUT_UNDEFINED;
6895 image_ci.flags = 0;
6896 VkImage image;
6897 ASSERT_VK_SUCCESS(vkCreateImage(m_device->handle(), &image_ci, NULL, &image));
6898
6899 VkMemoryRequirements memory_reqs;
6900 VkDeviceMemory image_memory;
6901 bool pass;
6902 VkMemoryAllocateInfo memory_info = {};
6903 memory_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
6904 memory_info.pNext = NULL;
6905 memory_info.allocationSize = 0;
6906 memory_info.memoryTypeIndex = 0;
6907 vkGetImageMemoryRequirements(m_device->device(), image, &memory_reqs);
6908 memory_info.allocationSize = memory_reqs.size;
6909 pass = m_device->phy().set_memory_type(memory_reqs.memoryTypeBits, &memory_info, 0);
6910 ASSERT_TRUE(pass);
6911 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &image_memory);
6912 ASSERT_VK_SUCCESS(err);
6913 err = vkBindImageMemory(m_device->device(), image, image_memory, 0);
6914 ASSERT_VK_SUCCESS(err);
6915
6916 VkImageViewCreateInfo ivci = {
6917 VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO,
6918 nullptr,
6919 0,
6920 image,
6921 VK_IMAGE_VIEW_TYPE_2D,
6922 VK_FORMAT_B8G8R8A8_UNORM,
6923 {VK_COMPONENT_SWIZZLE_R, VK_COMPONENT_SWIZZLE_G, VK_COMPONENT_SWIZZLE_B, VK_COMPONENT_SWIZZLE_A},
6924 {VK_IMAGE_ASPECT_COLOR_BIT, 0, 1, 0, 1},
6925 };
6926 VkImageView view;
6927 err = vkCreateImageView(m_device->device(), &ivci, nullptr, &view);
6928 ASSERT_VK_SUCCESS(err);
6929
6930 VkFramebufferCreateInfo fci = {VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr, 0, m_renderPass, 1, &view, 256, 256, 1};
6931 VkFramebuffer fb;
6932 err = vkCreateFramebuffer(m_device->device(), &fci, nullptr, &fb);
6933 ASSERT_VK_SUCCESS(err);
6934
6935 // Just use default renderpass with our framebuffer
6936 m_renderPassBeginInfo.framebuffer = fb;
6937 // Create Null cmd buffer for submit
6938 BeginCommandBuffer();
6939 EndCommandBuffer();
6940 // Submit cmd buffer to put it (and attached imageView) in-flight
6941 VkSubmitInfo submit_info = {};
6942 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
6943 submit_info.commandBufferCount = 1;
6944 submit_info.pCommandBuffers = &m_commandBuffer->handle();
6945 // Submit cmd buffer to put framebuffer and children in-flight
6946 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
6947 // Destroy image attached to framebuffer while in-flight
6948 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Cannot delete image 0x");
6949 vkDestroyImage(m_device->device(), image, NULL);
6950 m_errorMonitor->VerifyFound();
6951 // Wait for queue to complete so we can safely destroy image and other objects
6952 vkQueueWaitIdle(m_device->m_queue);
6953 vkDestroyImage(m_device->device(), image, NULL);
6954 vkDestroyFramebuffer(m_device->device(), fb, nullptr);
6955 vkDestroyImageView(m_device->device(), view, nullptr);
6956 vkFreeMemory(m_device->device(), image_memory, nullptr);
6957}
6958
Mark Lobodzinskia4df3632016-07-14 09:57:41 -06006959TEST_F(VkLayerTest, ImageMemoryNotBound) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006960 TEST_DESCRIPTION("Attempt to draw with an image which has not had memory bound to it.");
Mark Lobodzinskia4df3632016-07-14 09:57:41 -06006961 ASSERT_NO_FATAL_FAILURE(InitState());
6962
6963 VkImage image;
6964 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
6965 VkImageCreateInfo image_create_info = {};
6966 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
6967 image_create_info.pNext = NULL;
6968 image_create_info.imageType = VK_IMAGE_TYPE_2D;
6969 image_create_info.format = tex_format;
6970 image_create_info.extent.width = 32;
6971 image_create_info.extent.height = 32;
6972 image_create_info.extent.depth = 1;
6973 image_create_info.mipLevels = 1;
6974 image_create_info.arrayLayers = 1;
6975 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
6976 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006977 image_create_info.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT;
Mark Lobodzinskia4df3632016-07-14 09:57:41 -06006978 image_create_info.flags = 0;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006979 VkResult err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
Mark Lobodzinskia4df3632016-07-14 09:57:41 -06006980 ASSERT_VK_SUCCESS(err);
6981 // Have to bind memory to image before recording cmd in cmd buffer using it
6982 VkMemoryRequirements mem_reqs;
6983 VkDeviceMemory image_mem;
6984 bool pass;
6985 VkMemoryAllocateInfo mem_alloc = {};
6986 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
6987 mem_alloc.pNext = NULL;
6988 mem_alloc.memoryTypeIndex = 0;
6989 vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs);
6990 mem_alloc.allocationSize = mem_reqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006991 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0);
Mark Lobodzinskia4df3632016-07-14 09:57:41 -06006992 ASSERT_TRUE(pass);
6993 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &image_mem);
6994 ASSERT_VK_SUCCESS(err);
6995
Tobin Ehlisfed999f2016-09-21 15:09:45 -06006996 // Introduce error, do not call vkBindImageMemory(m_device->device(), image, image_mem, 0);
6997 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
6998 " used with no memory bound. Memory should be bound by calling vkBindImageMemory() and ");
Mark Lobodzinskia4df3632016-07-14 09:57:41 -06006999
7000 m_commandBuffer->BeginCommandBuffer();
7001 VkClearColorValue ccv;
7002 ccv.float32[0] = 1.0f;
7003 ccv.float32[1] = 1.0f;
7004 ccv.float32[2] = 1.0f;
7005 ccv.float32[3] = 1.0f;
7006 VkImageSubresourceRange isr = {};
7007 isr.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
7008 isr.baseArrayLayer = 0;
7009 isr.baseMipLevel = 0;
7010 isr.layerCount = 1;
7011 isr.levelCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007012 vkCmdClearColorImage(m_commandBuffer->GetBufferHandle(), image, VK_IMAGE_LAYOUT_GENERAL, &ccv, 1, &isr);
Mark Lobodzinskia4df3632016-07-14 09:57:41 -06007013 m_commandBuffer->EndCommandBuffer();
7014
7015 m_errorMonitor->VerifyFound();
7016 vkDestroyImage(m_device->device(), image, NULL);
7017 vkFreeMemory(m_device->device(), image_mem, nullptr);
7018}
7019
7020TEST_F(VkLayerTest, BufferMemoryNotBound) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007021 TEST_DESCRIPTION("Attempt to copy from a buffer which has not had memory bound to it.");
Mark Lobodzinskia4df3632016-07-14 09:57:41 -06007022 ASSERT_NO_FATAL_FAILURE(InitState());
7023
7024 VkImageObj image(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007025 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 -06007026 VK_IMAGE_TILING_OPTIMAL, 0);
7027 ASSERT_TRUE(image.initialized());
7028
7029 VkBuffer buffer;
7030 VkDeviceMemory mem;
7031 VkMemoryRequirements mem_reqs;
7032
7033 VkBufferCreateInfo buf_info = {};
7034 buf_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
Chris Forbes8d260dd2016-09-16 17:42:42 +12007035 buf_info.usage = VK_BUFFER_USAGE_TRANSFER_SRC_BIT;
Mark Lobodzinskia4df3632016-07-14 09:57:41 -06007036 buf_info.size = 256;
7037 buf_info.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
7038 VkResult err = vkCreateBuffer(m_device->device(), &buf_info, NULL, &buffer);
7039 ASSERT_VK_SUCCESS(err);
7040
7041 vkGetBufferMemoryRequirements(m_device->device(), buffer, &mem_reqs);
7042
7043 VkMemoryAllocateInfo alloc_info = {};
7044 alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
7045 alloc_info.allocationSize = 256;
7046 bool pass = false;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007047 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 -06007048 if (!pass) {
7049 vkDestroyBuffer(m_device->device(), buffer, NULL);
7050 return;
7051 }
7052 err = vkAllocateMemory(m_device->device(), &alloc_info, NULL, &mem);
7053 ASSERT_VK_SUCCESS(err);
7054
Tobin Ehlisfed999f2016-09-21 15:09:45 -06007055 // Introduce failure by not calling vkBindBufferMemory(m_device->device(), buffer, mem, 0);
7056 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
7057 " used with no memory bound. Memory should be bound by calling vkBindImageMemory() and ");
Mark Lobodzinskia4df3632016-07-14 09:57:41 -06007058 VkBufferImageCopy region = {};
7059 region.bufferRowLength = 128;
7060 region.bufferImageHeight = 128;
7061 region.imageSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
7062
7063 region.imageSubresource.layerCount = 1;
7064 region.imageExtent.height = 4;
7065 region.imageExtent.width = 4;
7066 region.imageExtent.depth = 1;
7067 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007068 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer, image.handle(), VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1,
7069 &region);
Mark Lobodzinskia4df3632016-07-14 09:57:41 -06007070 m_commandBuffer->EndCommandBuffer();
7071
7072 m_errorMonitor->VerifyFound();
7073
7074 vkDestroyBuffer(m_device->device(), buffer, NULL);
7075 vkFreeMemory(m_device->handle(), mem, NULL);
7076}
7077
Tobin Ehlis85940f52016-07-07 16:57:21 -06007078TEST_F(VkLayerTest, InvalidCmdBufferEventDestroyed) {
7079 TEST_DESCRIPTION("Attempt to draw with a command buffer that is invalid "
7080 "due to an event dependency being destroyed.");
7081 ASSERT_NO_FATAL_FAILURE(InitState());
7082
7083 VkEvent event;
7084 VkEventCreateInfo evci = {};
7085 evci.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO;
7086 VkResult result = vkCreateEvent(m_device->device(), &evci, NULL, &event);
7087 ASSERT_VK_SUCCESS(result);
7088
7089 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007090 vkCmdSetEvent(m_commandBuffer->GetBufferHandle(), event, VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT);
Tobin Ehlis85940f52016-07-07 16:57:21 -06007091 m_commandBuffer->EndCommandBuffer();
7092
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007093 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " that is invalid because bound event ");
Tobin Ehlis85940f52016-07-07 16:57:21 -06007094 // Destroy event dependency prior to submit to cause ERROR
7095 vkDestroyEvent(m_device->device(), event, NULL);
7096
7097 VkSubmitInfo submit_info = {};
7098 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
7099 submit_info.commandBufferCount = 1;
7100 submit_info.pCommandBuffers = &m_commandBuffer->handle();
7101 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
7102
7103 m_errorMonitor->VerifyFound();
7104}
7105
Tobin Ehlisdbea7552016-07-08 14:33:31 -06007106TEST_F(VkLayerTest, InvalidCmdBufferQueryPoolDestroyed) {
7107 TEST_DESCRIPTION("Attempt to draw with a command buffer that is invalid "
7108 "due to a query pool dependency being destroyed.");
7109 ASSERT_NO_FATAL_FAILURE(InitState());
7110
7111 VkQueryPool query_pool;
7112 VkQueryPoolCreateInfo qpci{};
7113 qpci.sType = VK_STRUCTURE_TYPE_QUERY_POOL_CREATE_INFO;
7114 qpci.queryType = VK_QUERY_TYPE_TIMESTAMP;
7115 qpci.queryCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007116 VkResult result = vkCreateQueryPool(m_device->device(), &qpci, nullptr, &query_pool);
Tobin Ehlisdbea7552016-07-08 14:33:31 -06007117 ASSERT_VK_SUCCESS(result);
7118
7119 m_commandBuffer->BeginCommandBuffer();
7120 vkCmdResetQueryPool(m_commandBuffer->GetBufferHandle(), query_pool, 0, 1);
7121 m_commandBuffer->EndCommandBuffer();
7122
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007123 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " that is invalid because bound query pool ");
Tobin Ehlisdbea7552016-07-08 14:33:31 -06007124 // Destroy query pool dependency prior to submit to cause ERROR
7125 vkDestroyQueryPool(m_device->device(), query_pool, NULL);
7126
7127 VkSubmitInfo submit_info = {};
7128 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
7129 submit_info.commandBufferCount = 1;
7130 submit_info.pCommandBuffers = &m_commandBuffer->handle();
7131 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
7132
7133 m_errorMonitor->VerifyFound();
7134}
7135
Tobin Ehlis24130d92016-07-08 15:50:53 -06007136TEST_F(VkLayerTest, InvalidCmdBufferPipelineDestroyed) {
7137 TEST_DESCRIPTION("Attempt to draw with a command buffer that is invalid "
7138 "due to a pipeline dependency being destroyed.");
7139 ASSERT_NO_FATAL_FAILURE(InitState());
7140 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
7141
7142 VkResult err;
7143
7144 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
7145 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
7146
7147 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007148 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis24130d92016-07-08 15:50:53 -06007149 ASSERT_VK_SUCCESS(err);
7150
7151 VkPipelineViewportStateCreateInfo vp_state_ci = {};
7152 vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
7153 vp_state_ci.viewportCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007154 VkViewport vp = {}; // Just need dummy vp to point to
Tobin Ehlis52b504f2016-07-19 13:25:12 -06007155 vp_state_ci.pViewports = &vp;
Tobin Ehlis24130d92016-07-08 15:50:53 -06007156 vp_state_ci.scissorCount = 1;
7157 VkRect2D scissors = {}; // Dummy scissors to point to
7158 vp_state_ci.pScissors = &scissors;
Tobin Ehlis24130d92016-07-08 15:50:53 -06007159
7160 VkPipelineShaderStageCreateInfo shaderStages[2];
7161 memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo));
7162
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007163 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
7164 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this); // We shouldn't need a fragment shader
7165 // but add it to be able to run on more devices
Tobin Ehlis24130d92016-07-08 15:50:53 -06007166 shaderStages[0] = vs.GetStageCreateInfo();
7167 shaderStages[1] = fs.GetStageCreateInfo();
7168
7169 VkPipelineVertexInputStateCreateInfo vi_ci = {};
7170 vi_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
7171
7172 VkPipelineInputAssemblyStateCreateInfo ia_ci = {};
7173 ia_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
7174 ia_ci.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP;
7175
7176 VkPipelineRasterizationStateCreateInfo rs_ci = {};
7177 rs_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
Chris Forbese06ba252016-09-16 17:48:53 +12007178 rs_ci.rasterizerDiscardEnable = true;
7179 rs_ci.lineWidth = 1.0f;
Tobin Ehlis24130d92016-07-08 15:50:53 -06007180
7181 VkPipelineColorBlendAttachmentState att = {};
7182 att.blendEnable = VK_FALSE;
7183 att.colorWriteMask = 0xf;
7184
7185 VkPipelineColorBlendStateCreateInfo cb_ci = {};
7186 cb_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO;
7187 cb_ci.attachmentCount = 1;
7188 cb_ci.pAttachments = &att;
7189
7190 VkGraphicsPipelineCreateInfo gp_ci = {};
7191 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
7192 gp_ci.stageCount = 2;
7193 gp_ci.pStages = shaderStages;
7194 gp_ci.pVertexInputState = &vi_ci;
7195 gp_ci.pInputAssemblyState = &ia_ci;
7196 gp_ci.pViewportState = &vp_state_ci;
7197 gp_ci.pRasterizationState = &rs_ci;
7198 gp_ci.pColorBlendState = &cb_ci;
Tobin Ehlis24130d92016-07-08 15:50:53 -06007199 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
7200 gp_ci.layout = pipeline_layout;
7201 gp_ci.renderPass = renderPass();
7202
7203 VkPipelineCacheCreateInfo pc_ci = {};
7204 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
7205
7206 VkPipeline pipeline;
7207 VkPipelineCache pipelineCache;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007208 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Tobin Ehlis24130d92016-07-08 15:50:53 -06007209 ASSERT_VK_SUCCESS(err);
7210
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007211 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Tobin Ehlis24130d92016-07-08 15:50:53 -06007212 ASSERT_VK_SUCCESS(err);
7213
7214 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007215 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline);
Tobin Ehlis24130d92016-07-08 15:50:53 -06007216 m_commandBuffer->EndCommandBuffer();
7217 // Now destroy pipeline in order to cause error when submitting
7218 vkDestroyPipeline(m_device->device(), pipeline, nullptr);
7219
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007220 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " that is invalid because bound pipeline ");
Tobin Ehlis24130d92016-07-08 15:50:53 -06007221
7222 VkSubmitInfo submit_info = {};
7223 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
7224 submit_info.commandBufferCount = 1;
7225 submit_info.pCommandBuffers = &m_commandBuffer->handle();
7226 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
7227
7228 m_errorMonitor->VerifyFound();
7229 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
7230 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
7231}
7232
Tobin Ehlis31289162016-08-17 14:57:58 -06007233TEST_F(VkLayerTest, InvalidCmdBufferDescriptorSetBufferDestroyed) {
7234 TEST_DESCRIPTION("Attempt to draw with a command buffer that is invalid "
7235 "due to a bound descriptor set with a buffer dependency "
7236 "being destroyed.");
7237 ASSERT_NO_FATAL_FAILURE(InitState());
7238 ASSERT_NO_FATAL_FAILURE(InitViewport());
7239 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
7240
7241 VkDescriptorPoolSize ds_type_count = {};
7242 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
7243 ds_type_count.descriptorCount = 1;
7244
7245 VkDescriptorPoolCreateInfo ds_pool_ci = {};
7246 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
7247 ds_pool_ci.pNext = NULL;
7248 ds_pool_ci.maxSets = 1;
7249 ds_pool_ci.poolSizeCount = 1;
7250 ds_pool_ci.pPoolSizes = &ds_type_count;
7251
7252 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007253 VkResult err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis31289162016-08-17 14:57:58 -06007254 ASSERT_VK_SUCCESS(err);
7255
7256 VkDescriptorSetLayoutBinding dsl_binding = {};
7257 dsl_binding.binding = 0;
7258 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
7259 dsl_binding.descriptorCount = 1;
7260 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
7261 dsl_binding.pImmutableSamplers = NULL;
7262
7263 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
7264 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
7265 ds_layout_ci.pNext = NULL;
7266 ds_layout_ci.bindingCount = 1;
7267 ds_layout_ci.pBindings = &dsl_binding;
7268 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007269 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis31289162016-08-17 14:57:58 -06007270 ASSERT_VK_SUCCESS(err);
7271
7272 VkDescriptorSet descriptorSet;
7273 VkDescriptorSetAllocateInfo alloc_info = {};
7274 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
7275 alloc_info.descriptorSetCount = 1;
7276 alloc_info.descriptorPool = ds_pool;
7277 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007278 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis31289162016-08-17 14:57:58 -06007279 ASSERT_VK_SUCCESS(err);
7280
7281 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
7282 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
7283 pipeline_layout_ci.pNext = NULL;
7284 pipeline_layout_ci.setLayoutCount = 1;
7285 pipeline_layout_ci.pSetLayouts = &ds_layout;
7286
7287 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007288 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis31289162016-08-17 14:57:58 -06007289 ASSERT_VK_SUCCESS(err);
7290
7291 // Create a buffer to update the descriptor with
7292 uint32_t qfi = 0;
7293 VkBufferCreateInfo buffCI = {};
7294 buffCI.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
7295 buffCI.size = 1024;
7296 buffCI.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
7297 buffCI.queueFamilyIndexCount = 1;
7298 buffCI.pQueueFamilyIndices = &qfi;
7299
7300 VkBuffer buffer;
7301 err = vkCreateBuffer(m_device->device(), &buffCI, NULL, &buffer);
7302 ASSERT_VK_SUCCESS(err);
7303 // Allocate memory and bind to buffer so we can make it to the appropriate
7304 // error
7305 VkMemoryAllocateInfo mem_alloc = {};
7306 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
7307 mem_alloc.pNext = NULL;
7308 mem_alloc.allocationSize = 1024;
7309 mem_alloc.memoryTypeIndex = 0;
7310
7311 VkMemoryRequirements memReqs;
7312 vkGetBufferMemoryRequirements(m_device->device(), buffer, &memReqs);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007313 bool pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &mem_alloc, 0);
Tobin Ehlis31289162016-08-17 14:57:58 -06007314 if (!pass) {
7315 vkDestroyBuffer(m_device->device(), buffer, NULL);
7316 return;
7317 }
7318
7319 VkDeviceMemory mem;
7320 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem);
7321 ASSERT_VK_SUCCESS(err);
7322 err = vkBindBufferMemory(m_device->device(), buffer, mem, 0);
7323 ASSERT_VK_SUCCESS(err);
7324 // Correctly update descriptor to avoid "NOT_UPDATED" error
7325 VkDescriptorBufferInfo buffInfo = {};
7326 buffInfo.buffer = buffer;
7327 buffInfo.offset = 0;
7328 buffInfo.range = 1024;
7329
7330 VkWriteDescriptorSet descriptor_write;
7331 memset(&descriptor_write, 0, sizeof(descriptor_write));
7332 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
7333 descriptor_write.dstSet = descriptorSet;
7334 descriptor_write.dstBinding = 0;
7335 descriptor_write.descriptorCount = 1;
7336 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
7337 descriptor_write.pBufferInfo = &buffInfo;
7338
7339 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
7340
7341 // Create PSO to be used for draw-time errors below
7342 char const *vsSource = "#version 450\n"
7343 "\n"
7344 "out gl_PerVertex { \n"
7345 " vec4 gl_Position;\n"
7346 "};\n"
7347 "void main(){\n"
7348 " gl_Position = vec4(1);\n"
7349 "}\n";
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007350 char const *fsSource = "#version 450\n"
7351 "\n"
7352 "layout(location=0) out vec4 x;\n"
7353 "layout(set=0) layout(binding=0) uniform foo { int x; int y; } bar;\n"
7354 "void main(){\n"
7355 " x = vec4(bar.y);\n"
7356 "}\n";
Tobin Ehlis31289162016-08-17 14:57:58 -06007357 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
7358 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
7359 VkPipelineObj pipe(m_device);
7360 pipe.AddShader(&vs);
7361 pipe.AddShader(&fs);
7362 pipe.AddColorAttachment();
7363 pipe.CreateVKPipeline(pipeline_layout, renderPass());
7364
7365 BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007366 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
7367 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
7368 &descriptorSet, 0, NULL);
Tobin Ehlis31289162016-08-17 14:57:58 -06007369 Draw(1, 0, 0, 0);
7370 EndCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007371 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " that is invalid because bound buffer ");
Tobin Ehlis31289162016-08-17 14:57:58 -06007372 // Destroy buffer should invalidate the cmd buffer, causing error on submit
7373 vkDestroyBuffer(m_device->device(), buffer, NULL);
7374 // Attempt to submit cmd buffer
7375 VkSubmitInfo submit_info = {};
7376 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
7377 submit_info.commandBufferCount = 1;
7378 submit_info.pCommandBuffers = &m_commandBuffer->handle();
7379 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
7380 m_errorMonitor->VerifyFound();
7381 // Cleanup
7382 vkFreeMemory(m_device->device(), mem, NULL);
7383
7384 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
7385 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
7386 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
7387}
7388
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06007389TEST_F(VkLayerTest, InvalidCmdBufferDescriptorSetImageSamplerDestroyed) {
7390 TEST_DESCRIPTION("Attempt to draw with a command buffer that is invalid "
7391 "due to a bound descriptor sets with a combined image "
7392 "sampler having their image, sampler, and descriptor set "
7393 "each respectively destroyed and then attempting to "
Mark Mueller917f6bc2016-08-30 10:57:19 -06007394 "submit associated cmd buffers. Attempt to destroy a "
7395 "DescriptorSet that is in use.");
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06007396 ASSERT_NO_FATAL_FAILURE(InitState());
7397 ASSERT_NO_FATAL_FAILURE(InitViewport());
7398 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
7399
7400 VkDescriptorPoolSize ds_type_count = {};
7401 ds_type_count.type = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
7402 ds_type_count.descriptorCount = 1;
7403
7404 VkDescriptorPoolCreateInfo ds_pool_ci = {};
7405 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
7406 ds_pool_ci.pNext = NULL;
7407 ds_pool_ci.maxSets = 1;
7408 ds_pool_ci.poolSizeCount = 1;
7409 ds_pool_ci.pPoolSizes = &ds_type_count;
7410
7411 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007412 VkResult err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06007413 ASSERT_VK_SUCCESS(err);
7414
7415 VkDescriptorSetLayoutBinding dsl_binding = {};
7416 dsl_binding.binding = 0;
7417 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
7418 dsl_binding.descriptorCount = 1;
7419 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
7420 dsl_binding.pImmutableSamplers = NULL;
7421
7422 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
7423 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
7424 ds_layout_ci.pNext = NULL;
7425 ds_layout_ci.bindingCount = 1;
7426 ds_layout_ci.pBindings = &dsl_binding;
7427 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007428 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06007429 ASSERT_VK_SUCCESS(err);
7430
7431 VkDescriptorSet descriptorSet;
7432 VkDescriptorSetAllocateInfo alloc_info = {};
7433 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
7434 alloc_info.descriptorSetCount = 1;
7435 alloc_info.descriptorPool = ds_pool;
7436 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007437 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06007438 ASSERT_VK_SUCCESS(err);
7439
7440 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
7441 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
7442 pipeline_layout_ci.pNext = NULL;
7443 pipeline_layout_ci.setLayoutCount = 1;
7444 pipeline_layout_ci.pSetLayouts = &ds_layout;
7445
7446 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007447 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06007448 ASSERT_VK_SUCCESS(err);
7449
7450 // Create images to update the descriptor with
7451 VkImage image;
7452 VkImage image2;
7453 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
7454 const int32_t tex_width = 32;
7455 const int32_t tex_height = 32;
7456 VkImageCreateInfo image_create_info = {};
7457 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
7458 image_create_info.pNext = NULL;
7459 image_create_info.imageType = VK_IMAGE_TYPE_2D;
7460 image_create_info.format = tex_format;
7461 image_create_info.extent.width = tex_width;
7462 image_create_info.extent.height = tex_height;
7463 image_create_info.extent.depth = 1;
7464 image_create_info.mipLevels = 1;
7465 image_create_info.arrayLayers = 1;
7466 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
7467 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
7468 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
7469 image_create_info.flags = 0;
7470 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
7471 ASSERT_VK_SUCCESS(err);
7472 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image2);
7473 ASSERT_VK_SUCCESS(err);
7474
7475 VkMemoryRequirements memory_reqs;
7476 VkDeviceMemory image_memory;
7477 bool pass;
7478 VkMemoryAllocateInfo memory_info = {};
7479 memory_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
7480 memory_info.pNext = NULL;
7481 memory_info.allocationSize = 0;
7482 memory_info.memoryTypeIndex = 0;
7483 vkGetImageMemoryRequirements(m_device->device(), image, &memory_reqs);
7484 // Allocate enough memory for both images
7485 memory_info.allocationSize = memory_reqs.size * 2;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007486 pass = m_device->phy().set_memory_type(memory_reqs.memoryTypeBits, &memory_info, 0);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06007487 ASSERT_TRUE(pass);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007488 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &image_memory);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06007489 ASSERT_VK_SUCCESS(err);
7490 err = vkBindImageMemory(m_device->device(), image, image_memory, 0);
7491 ASSERT_VK_SUCCESS(err);
7492 // Bind second image to memory right after first image
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007493 err = vkBindImageMemory(m_device->device(), image2, image_memory, memory_reqs.size);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06007494 ASSERT_VK_SUCCESS(err);
7495
7496 VkImageViewCreateInfo image_view_create_info = {};
7497 image_view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
7498 image_view_create_info.image = image;
7499 image_view_create_info.viewType = VK_IMAGE_VIEW_TYPE_2D;
7500 image_view_create_info.format = tex_format;
7501 image_view_create_info.subresourceRange.layerCount = 1;
7502 image_view_create_info.subresourceRange.baseMipLevel = 0;
7503 image_view_create_info.subresourceRange.levelCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007504 image_view_create_info.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06007505
7506 VkImageView view;
7507 VkImageView view2;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007508 err = vkCreateImageView(m_device->device(), &image_view_create_info, NULL, &view);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06007509 ASSERT_VK_SUCCESS(err);
7510 image_view_create_info.image = image2;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007511 err = vkCreateImageView(m_device->device(), &image_view_create_info, NULL, &view2);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06007512 ASSERT_VK_SUCCESS(err);
7513 // Create Samplers
7514 VkSamplerCreateInfo sampler_ci = {};
7515 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
7516 sampler_ci.pNext = NULL;
7517 sampler_ci.magFilter = VK_FILTER_NEAREST;
7518 sampler_ci.minFilter = VK_FILTER_NEAREST;
7519 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
7520 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
7521 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
7522 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
7523 sampler_ci.mipLodBias = 1.0;
7524 sampler_ci.anisotropyEnable = VK_FALSE;
7525 sampler_ci.maxAnisotropy = 1;
7526 sampler_ci.compareEnable = VK_FALSE;
7527 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
7528 sampler_ci.minLod = 1.0;
7529 sampler_ci.maxLod = 1.0;
7530 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
7531 sampler_ci.unnormalizedCoordinates = VK_FALSE;
7532 VkSampler sampler;
7533 VkSampler sampler2;
7534 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
7535 ASSERT_VK_SUCCESS(err);
7536 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler2);
7537 ASSERT_VK_SUCCESS(err);
7538 // Update descriptor with image and sampler
7539 VkDescriptorImageInfo img_info = {};
7540 img_info.sampler = sampler;
7541 img_info.imageView = view;
7542 img_info.imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
7543
7544 VkWriteDescriptorSet descriptor_write;
7545 memset(&descriptor_write, 0, sizeof(descriptor_write));
7546 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
7547 descriptor_write.dstSet = descriptorSet;
7548 descriptor_write.dstBinding = 0;
7549 descriptor_write.descriptorCount = 1;
7550 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
7551 descriptor_write.pImageInfo = &img_info;
7552
7553 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
7554
7555 // Create PSO to be used for draw-time errors below
7556 char const *vsSource = "#version 450\n"
7557 "\n"
7558 "out gl_PerVertex { \n"
7559 " vec4 gl_Position;\n"
7560 "};\n"
7561 "void main(){\n"
7562 " gl_Position = vec4(1);\n"
7563 "}\n";
7564 char const *fsSource = "#version 450\n"
7565 "\n"
7566 "layout(set=0, binding=0) uniform sampler2D s;\n"
7567 "layout(location=0) out vec4 x;\n"
7568 "void main(){\n"
7569 " x = texture(s, vec2(1));\n"
7570 "}\n";
7571 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
7572 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
7573 VkPipelineObj pipe(m_device);
7574 pipe.AddShader(&vs);
7575 pipe.AddShader(&fs);
7576 pipe.AddColorAttachment();
7577 pipe.CreateVKPipeline(pipeline_layout, renderPass());
7578
7579 // First error case is destroying sampler prior to cmd buffer submission
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007580 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Cannot submit cmd buffer using deleted sampler ");
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06007581 BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007582 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
7583 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
7584 &descriptorSet, 0, NULL);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06007585 Draw(1, 0, 0, 0);
7586 EndCommandBuffer();
7587 // Destroy sampler invalidates the cmd buffer, causing error on submit
7588 vkDestroySampler(m_device->device(), sampler, NULL);
7589 // Attempt to submit cmd buffer
7590 VkSubmitInfo submit_info = {};
7591 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
7592 submit_info.commandBufferCount = 1;
7593 submit_info.pCommandBuffers = &m_commandBuffer->handle();
7594 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
7595 m_errorMonitor->VerifyFound();
7596 // Now re-update descriptor with valid sampler and delete image
7597 img_info.sampler = sampler2;
7598 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007599 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " that is invalid because bound image ");
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06007600 BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007601 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
7602 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
7603 &descriptorSet, 0, NULL);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06007604 Draw(1, 0, 0, 0);
7605 EndCommandBuffer();
7606 // Destroy image invalidates the cmd buffer, causing error on submit
7607 vkDestroyImage(m_device->device(), image, NULL);
7608 // Attempt to submit cmd buffer
7609 submit_info = {};
7610 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
7611 submit_info.commandBufferCount = 1;
7612 submit_info.pCommandBuffers = &m_commandBuffer->handle();
7613 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
7614 m_errorMonitor->VerifyFound();
7615 // Now update descriptor to be valid, but then free descriptor
7616 img_info.imageView = view2;
7617 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007618 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " that is invalid because bound descriptor set ");
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06007619 BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007620 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
7621 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
7622 &descriptorSet, 0, NULL);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06007623 Draw(1, 0, 0, 0);
7624 EndCommandBuffer();
7625 // Destroy descriptor set invalidates the cb, causing error on submit
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007626 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Cannot call vkFreeDescriptorSets() on descriptor set 0x");
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06007627 vkFreeDescriptorSets(m_device->device(), ds_pool, 1, &descriptorSet);
Mark Mueller917f6bc2016-08-30 10:57:19 -06007628 m_errorMonitor->VerifyFound();
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06007629 // Attempt to submit cmd buffer
7630 submit_info = {};
7631 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
7632 submit_info.commandBufferCount = 1;
7633 submit_info.pCommandBuffers = &m_commandBuffer->handle();
7634 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
7635 m_errorMonitor->VerifyFound();
7636 // Cleanup
7637 vkFreeMemory(m_device->device(), image_memory, NULL);
7638 vkDestroySampler(m_device->device(), sampler2, NULL);
7639 vkDestroyImage(m_device->device(), image2, NULL);
7640 vkDestroyImageView(m_device->device(), view, NULL);
7641 vkDestroyImageView(m_device->device(), view2, NULL);
7642 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
7643 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
7644 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
7645}
7646
Karl Schultz6addd812016-02-02 17:17:23 -07007647TEST_F(VkLayerTest, InvalidPipeline) {
Karl Schultzbdb75952016-04-19 11:36:49 -06007648 // Attempt to bind an invalid Pipeline to a valid Command Buffer
7649 // ObjectTracker should catch this.
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06007650 // Create a valid cmd buffer
7651 // call vkCmdBindPipeline w/ false Pipeline
Mark Lobodzinski02bf89d2016-05-10 14:45:13 -06007652 uint64_t fake_pipeline_handle = 0xbaad6001;
7653 VkPipeline bad_pipeline = reinterpret_cast<VkPipeline &>(fake_pipeline_handle);
Karl Schultzbdb75952016-04-19 11:36:49 -06007654 ASSERT_NO_FATAL_FAILURE(InitState());
Chris Forbes4dbf70f2016-09-16 17:58:00 +12007655 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
7656
7657 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Invalid Pipeline Object 0xbaad6001");
Karl Schultzbdb75952016-04-19 11:36:49 -06007658 BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007659 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, bad_pipeline);
Karl Schultzbdb75952016-04-19 11:36:49 -06007660 m_errorMonitor->VerifyFound();
Chris Forbes4dbf70f2016-09-16 17:58:00 +12007661
Tobin Ehlisb8b6b272016-05-02 13:26:06 -06007662 // Now issue a draw call with no pipeline bound
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007663 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 -06007664 Draw(1, 0, 0, 0);
7665 m_errorMonitor->VerifyFound();
Chris Forbes4dbf70f2016-09-16 17:58:00 +12007666
Tobin Ehlisb8b6b272016-05-02 13:26:06 -06007667 // Finally same check once more but with Dispatch/Compute
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007668 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 +12007669 vkCmdEndRenderPass(m_commandBuffer->GetBufferHandle()); // must be outside renderpass
Tobin Ehlisb8b6b272016-05-02 13:26:06 -06007670 vkCmdDispatch(m_commandBuffer->GetBufferHandle(), 0, 0, 0);
7671 m_errorMonitor->VerifyFound();
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06007672}
7673
Karl Schultz6addd812016-02-02 17:17:23 -07007674TEST_F(VkLayerTest, DescriptorSetNotUpdated) {
Tobin Ehlis5a5f5ef2016-08-17 13:56:55 -06007675 TEST_DESCRIPTION("Bind a descriptor set that hasn't been updated.");
Karl Schultz6addd812016-02-02 17:17:23 -07007676 VkResult err;
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06007677
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007678 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT, " bound but it was never updated. ");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06007679
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06007680 ASSERT_NO_FATAL_FAILURE(InitState());
Mike Stroyan713b2d72015-08-04 10:49:29 -06007681 ASSERT_NO_FATAL_FAILURE(InitViewport());
7682 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chia-I Wu1b99bb22015-10-27 19:25:11 +08007683 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007684 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
7685 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -06007686
7687 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007688 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
7689 ds_pool_ci.pNext = NULL;
7690 ds_pool_ci.maxSets = 1;
7691 ds_pool_ci.poolSizeCount = 1;
7692 ds_pool_ci.pPoolSizes = &ds_type_count;
Mike Stroyan713b2d72015-08-04 10:49:29 -06007693
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06007694 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007695 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06007696 ASSERT_VK_SUCCESS(err);
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06007697
Tony Barboureb254902015-07-15 12:50:33 -06007698 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007699 dsl_binding.binding = 0;
7700 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
7701 dsl_binding.descriptorCount = 1;
7702 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
7703 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06007704
Tony Barboureb254902015-07-15 12:50:33 -06007705 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007706 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
7707 ds_layout_ci.pNext = NULL;
7708 ds_layout_ci.bindingCount = 1;
7709 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06007710 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007711 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06007712 ASSERT_VK_SUCCESS(err);
7713
7714 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08007715 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08007716 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07007717 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06007718 alloc_info.descriptorPool = ds_pool;
7719 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007720 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06007721 ASSERT_VK_SUCCESS(err);
7722
Tony Barboureb254902015-07-15 12:50:33 -06007723 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007724 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
7725 pipeline_layout_ci.pNext = NULL;
7726 pipeline_layout_ci.setLayoutCount = 1;
7727 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06007728
7729 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007730 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06007731 ASSERT_VK_SUCCESS(err);
7732
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007733 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
Karl Schultzbdb75952016-04-19 11:36:49 -06007734 // We shouldn't need a fragment shader but add it to be able to run
Karl Schultz6addd812016-02-02 17:17:23 -07007735 // on more devices
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007736 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06007737
Tony Barbourc95e4ac2015-08-04 17:05:26 -06007738 VkPipelineObj pipe(m_device);
7739 pipe.AddShader(&vs);
Tony Barbour1c94d372015-08-06 11:21:08 -06007740 pipe.AddShader(&fs);
Mark Youngc89c6312016-03-31 16:03:20 -06007741 pipe.AddColorAttachment();
Tony Barbourc95e4ac2015-08-04 17:05:26 -06007742 pipe.CreateVKPipeline(pipeline_layout, renderPass());
Tony Barbourfe3351b2015-07-28 10:17:20 -06007743
7744 BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007745 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
7746 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
7747 &descriptorSet, 0, NULL);
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06007748
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007749 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06007750
Chia-I Wuf7458c52015-10-26 21:10:41 +08007751 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
7752 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
7753 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06007754}
7755
Karl Schultz6addd812016-02-02 17:17:23 -07007756TEST_F(VkLayerTest, InvalidBufferViewObject) {
Tobin Ehlisba31cab2015-11-02 15:24:32 -07007757 // Create a single TEXEL_BUFFER descriptor and send it an invalid bufferView
Karl Schultz6addd812016-02-02 17:17:23 -07007758 VkResult err;
Tobin Ehlisba31cab2015-11-02 15:24:32 -07007759
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007760 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Attempted write update to texel buffer "
7761 "descriptor with invalid buffer view");
Tobin Ehlisba31cab2015-11-02 15:24:32 -07007762
7763 ASSERT_NO_FATAL_FAILURE(InitState());
7764 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007765 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER;
7766 ds_type_count.descriptorCount = 1;
Tobin Ehlisba31cab2015-11-02 15:24:32 -07007767
7768 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007769 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
7770 ds_pool_ci.pNext = NULL;
7771 ds_pool_ci.maxSets = 1;
7772 ds_pool_ci.poolSizeCount = 1;
7773 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlisba31cab2015-11-02 15:24:32 -07007774
7775 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007776 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlisba31cab2015-11-02 15:24:32 -07007777 ASSERT_VK_SUCCESS(err);
7778
7779 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007780 dsl_binding.binding = 0;
7781 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER;
7782 dsl_binding.descriptorCount = 1;
7783 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
7784 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlisba31cab2015-11-02 15:24:32 -07007785
7786 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007787 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
7788 ds_layout_ci.pNext = NULL;
7789 ds_layout_ci.bindingCount = 1;
7790 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlisba31cab2015-11-02 15:24:32 -07007791 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007792 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlisba31cab2015-11-02 15:24:32 -07007793 ASSERT_VK_SUCCESS(err);
7794
7795 VkDescriptorSet descriptorSet;
7796 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08007797 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07007798 alloc_info.descriptorSetCount = 1;
Tobin Ehlisba31cab2015-11-02 15:24:32 -07007799 alloc_info.descriptorPool = ds_pool;
7800 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007801 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlisba31cab2015-11-02 15:24:32 -07007802 ASSERT_VK_SUCCESS(err);
7803
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007804 VkBufferView view = (VkBufferView)((size_t)0xbaadbeef); // invalid bufferView object
Tobin Ehlisba31cab2015-11-02 15:24:32 -07007805 VkWriteDescriptorSet descriptor_write;
7806 memset(&descriptor_write, 0, sizeof(descriptor_write));
7807 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
7808 descriptor_write.dstSet = descriptorSet;
7809 descriptor_write.dstBinding = 0;
7810 descriptor_write.descriptorCount = 1;
7811 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER;
7812 descriptor_write.pTexelBufferView = &view;
7813
7814 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
7815
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007816 m_errorMonitor->VerifyFound();
Tobin Ehlisba31cab2015-11-02 15:24:32 -07007817
7818 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
7819 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
7820}
7821
Mark Youngd339ba32016-05-30 13:28:35 -06007822TEST_F(VkLayerTest, CreateBufferViewNoMemoryBoundToBuffer) {
7823 TEST_DESCRIPTION("Attempt to create a buffer view with a buffer that has"
7824 " no memory bound to it.");
7825
7826 VkResult err;
Tobin Ehlisfed999f2016-09-21 15:09:45 -06007827 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
7828 " used with no memory bound. Memory should be bound by calling vkBindImageMemory() and ");
Mark Youngd339ba32016-05-30 13:28:35 -06007829
7830 ASSERT_NO_FATAL_FAILURE(InitState());
7831
7832 // Create a buffer with no bound memory and then attempt to create
7833 // a buffer view.
7834 VkBufferCreateInfo buff_ci = {};
7835 buff_ci.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
Chris Forbes4538d242016-09-13 18:13:58 +12007836 buff_ci.usage = VK_BUFFER_USAGE_UNIFORM_TEXEL_BUFFER_BIT;
Mark Youngd339ba32016-05-30 13:28:35 -06007837 buff_ci.size = 256;
7838 buff_ci.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
7839 VkBuffer buffer;
7840 err = vkCreateBuffer(m_device->device(), &buff_ci, NULL, &buffer);
7841 ASSERT_VK_SUCCESS(err);
7842
7843 VkBufferViewCreateInfo buff_view_ci = {};
7844 buff_view_ci.sType = VK_STRUCTURE_TYPE_BUFFER_VIEW_CREATE_INFO;
7845 buff_view_ci.buffer = buffer;
7846 buff_view_ci.format = VK_FORMAT_R8_UNORM;
7847 buff_view_ci.range = VK_WHOLE_SIZE;
7848 VkBufferView buff_view;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007849 err = vkCreateBufferView(m_device->device(), &buff_view_ci, NULL, &buff_view);
Mark Youngd339ba32016-05-30 13:28:35 -06007850
7851 m_errorMonitor->VerifyFound();
7852 vkDestroyBuffer(m_device->device(), buffer, NULL);
7853 // If last error is success, it still created the view, so delete it.
7854 if (err == VK_SUCCESS) {
7855 vkDestroyBufferView(m_device->device(), buff_view, NULL);
7856 }
7857}
7858
Karl Schultz6addd812016-02-02 17:17:23 -07007859TEST_F(VkLayerTest, InvalidDynamicOffsetCases) {
7860 // Create a descriptorSet w/ dynamic descriptor and then hit 3 offset error
7861 // cases:
Tobin Ehlisf6585052015-12-17 11:48:42 -07007862 // 1. No dynamicOffset supplied
7863 // 2. Too many dynamicOffsets supplied
7864 // 3. Dynamic offset oversteps buffer being updated
Karl Schultz6addd812016-02-02 17:17:23 -07007865 VkResult err;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007866 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " requires 1 dynamicOffsets, but only "
7867 "0 dynamicOffsets are left in "
7868 "pDynamicOffsets ");
Tobin Ehlis49f903e2015-11-04 13:30:34 -07007869
7870 ASSERT_NO_FATAL_FAILURE(InitState());
7871 ASSERT_NO_FATAL_FAILURE(InitViewport());
7872 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
7873
7874 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007875 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
7876 ds_type_count.descriptorCount = 1;
Tobin Ehlis49f903e2015-11-04 13:30:34 -07007877
7878 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007879 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
7880 ds_pool_ci.pNext = NULL;
7881 ds_pool_ci.maxSets = 1;
7882 ds_pool_ci.poolSizeCount = 1;
7883 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlis49f903e2015-11-04 13:30:34 -07007884
7885 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007886 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis49f903e2015-11-04 13:30:34 -07007887 ASSERT_VK_SUCCESS(err);
7888
7889 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007890 dsl_binding.binding = 0;
7891 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
7892 dsl_binding.descriptorCount = 1;
7893 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
7894 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis49f903e2015-11-04 13:30:34 -07007895
7896 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007897 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
7898 ds_layout_ci.pNext = NULL;
7899 ds_layout_ci.bindingCount = 1;
7900 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlis49f903e2015-11-04 13:30:34 -07007901 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007902 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis49f903e2015-11-04 13:30:34 -07007903 ASSERT_VK_SUCCESS(err);
7904
7905 VkDescriptorSet descriptorSet;
7906 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08007907 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07007908 alloc_info.descriptorSetCount = 1;
Tobin Ehlis49f903e2015-11-04 13:30:34 -07007909 alloc_info.descriptorPool = ds_pool;
7910 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007911 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis49f903e2015-11-04 13:30:34 -07007912 ASSERT_VK_SUCCESS(err);
7913
7914 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007915 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
7916 pipeline_layout_ci.pNext = NULL;
7917 pipeline_layout_ci.setLayoutCount = 1;
7918 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlis49f903e2015-11-04 13:30:34 -07007919
7920 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007921 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis49f903e2015-11-04 13:30:34 -07007922 ASSERT_VK_SUCCESS(err);
7923
7924 // Create a buffer to update the descriptor with
7925 uint32_t qfi = 0;
7926 VkBufferCreateInfo buffCI = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007927 buffCI.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
7928 buffCI.size = 1024;
7929 buffCI.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
7930 buffCI.queueFamilyIndexCount = 1;
7931 buffCI.pQueueFamilyIndices = &qfi;
Tobin Ehlis49f903e2015-11-04 13:30:34 -07007932
7933 VkBuffer dyub;
7934 err = vkCreateBuffer(m_device->device(), &buffCI, NULL, &dyub);
7935 ASSERT_VK_SUCCESS(err);
Tobin Ehlis0a43bde2016-05-03 08:31:08 -06007936 // Allocate memory and bind to buffer so we can make it to the appropriate
7937 // error
7938 VkMemoryAllocateInfo mem_alloc = {};
7939 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
7940 mem_alloc.pNext = NULL;
7941 mem_alloc.allocationSize = 1024;
Chris Forbesb6116cc2016-05-08 11:39:59 +12007942 mem_alloc.memoryTypeIndex = 0;
7943
7944 VkMemoryRequirements memReqs;
7945 vkGetBufferMemoryRequirements(m_device->device(), dyub, &memReqs);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007946 bool pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &mem_alloc, 0);
Chris Forbesb6116cc2016-05-08 11:39:59 +12007947 if (!pass) {
7948 vkDestroyBuffer(m_device->device(), dyub, NULL);
7949 return;
7950 }
7951
Tobin Ehlis0a43bde2016-05-03 08:31:08 -06007952 VkDeviceMemory mem;
7953 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem);
7954 ASSERT_VK_SUCCESS(err);
7955 err = vkBindBufferMemory(m_device->device(), dyub, mem, 0);
7956 ASSERT_VK_SUCCESS(err);
Tobin Ehlis49f903e2015-11-04 13:30:34 -07007957 // Correctly update descriptor to avoid "NOT_UPDATED" error
7958 VkDescriptorBufferInfo buffInfo = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007959 buffInfo.buffer = dyub;
7960 buffInfo.offset = 0;
7961 buffInfo.range = 1024;
Tobin Ehlis49f903e2015-11-04 13:30:34 -07007962
7963 VkWriteDescriptorSet descriptor_write;
7964 memset(&descriptor_write, 0, sizeof(descriptor_write));
7965 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
7966 descriptor_write.dstSet = descriptorSet;
7967 descriptor_write.dstBinding = 0;
7968 descriptor_write.descriptorCount = 1;
7969 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
7970 descriptor_write.pBufferInfo = &buffInfo;
7971
7972 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
7973
7974 BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007975 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
7976 &descriptorSet, 0, NULL);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007977 m_errorMonitor->VerifyFound();
Tobin Ehlisf6585052015-12-17 11:48:42 -07007978 uint32_t pDynOff[2] = {512, 756};
7979 // Now cause error b/c too many dynOffsets in array for # of dyn descriptors
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007980 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
7981 "Attempting to bind 1 descriptorSets with 1 dynamic descriptors, but ");
7982 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
7983 &descriptorSet, 2, pDynOff);
Chris Forbes7b342802016-04-07 13:20:10 +12007984 m_errorMonitor->VerifyFound();
Tobin Ehlisf6585052015-12-17 11:48:42 -07007985 // Finally cause error due to dynamicOffset being too big
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007986 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " dynamic offset 512 combined with "
7987 "offset 0 and range 1024 that "
7988 "oversteps the buffer size of 1024");
Tobin Ehlisf6585052015-12-17 11:48:42 -07007989 // Create PSO to be used for draw-time errors below
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007990 char const *vsSource = "#version 450\n"
7991 "\n"
7992 "out gl_PerVertex { \n"
7993 " vec4 gl_Position;\n"
7994 "};\n"
7995 "void main(){\n"
7996 " gl_Position = vec4(1);\n"
7997 "}\n";
7998 char const *fsSource = "#version 450\n"
7999 "\n"
8000 "layout(location=0) out vec4 x;\n"
8001 "layout(set=0) layout(binding=0) uniform foo { int x; int y; } bar;\n"
8002 "void main(){\n"
8003 " x = vec4(bar.y);\n"
8004 "}\n";
Tobin Ehlisf6585052015-12-17 11:48:42 -07008005 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
8006 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
8007 VkPipelineObj pipe(m_device);
8008 pipe.AddShader(&vs);
8009 pipe.AddShader(&fs);
8010 pipe.AddColorAttachment();
8011 pipe.CreateVKPipeline(pipeline_layout, renderPass());
8012
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008013 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Karl Schultz6addd812016-02-02 17:17:23 -07008014 // This update should succeed, but offset size of 512 will overstep buffer
8015 // /w range 1024 & size 1024
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008016 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
8017 &descriptorSet, 1, pDynOff);
Tobin Ehlisf6585052015-12-17 11:48:42 -07008018 Draw(1, 0, 0, 0);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008019 m_errorMonitor->VerifyFound();
Tobin Ehlis49f903e2015-11-04 13:30:34 -07008020
Tobin Ehlis0a43bde2016-05-03 08:31:08 -06008021 vkDestroyBuffer(m_device->device(), dyub, NULL);
Tobin Ehlis512098e2016-05-05 09:06:12 -06008022 vkFreeMemory(m_device->device(), mem, NULL);
Tobin Ehlis0a43bde2016-05-03 08:31:08 -06008023
Tobin Ehlis49f903e2015-11-04 13:30:34 -07008024 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
Tony Barbourdf4c0042016-06-01 15:55:43 -06008025 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
Tobin Ehlis49f903e2015-11-04 13:30:34 -07008026 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
8027}
8028
Tobin Ehlis8ef479c2016-07-20 16:14:49 -06008029TEST_F(VkLayerTest, DescriptorBufferUpdateNoMemoryBound) {
8030 TEST_DESCRIPTION("Attempt to update a descriptor with a non-sparse buffer "
8031 "that doesn't have memory bound");
8032 VkResult err;
Tobin Ehlisfed999f2016-09-21 15:09:45 -06008033 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
8034 " used with no memory bound. Memory should be bound by calling vkBindImageMemory() and ");
8035 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
8036 "vkUpdateDescriptorsSets() failed write update validation for Descriptor Set 0x");
Tobin Ehlis8ef479c2016-07-20 16:14:49 -06008037
8038 ASSERT_NO_FATAL_FAILURE(InitState());
8039 ASSERT_NO_FATAL_FAILURE(InitViewport());
8040 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
8041
8042 VkDescriptorPoolSize ds_type_count = {};
8043 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
8044 ds_type_count.descriptorCount = 1;
8045
8046 VkDescriptorPoolCreateInfo ds_pool_ci = {};
8047 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
8048 ds_pool_ci.pNext = NULL;
8049 ds_pool_ci.maxSets = 1;
8050 ds_pool_ci.poolSizeCount = 1;
8051 ds_pool_ci.pPoolSizes = &ds_type_count;
8052
8053 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008054 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis8ef479c2016-07-20 16:14:49 -06008055 ASSERT_VK_SUCCESS(err);
8056
8057 VkDescriptorSetLayoutBinding dsl_binding = {};
8058 dsl_binding.binding = 0;
8059 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
8060 dsl_binding.descriptorCount = 1;
8061 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
8062 dsl_binding.pImmutableSamplers = NULL;
8063
8064 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
8065 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
8066 ds_layout_ci.pNext = NULL;
8067 ds_layout_ci.bindingCount = 1;
8068 ds_layout_ci.pBindings = &dsl_binding;
8069 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008070 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis8ef479c2016-07-20 16:14:49 -06008071 ASSERT_VK_SUCCESS(err);
8072
8073 VkDescriptorSet descriptorSet;
8074 VkDescriptorSetAllocateInfo alloc_info = {};
8075 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
8076 alloc_info.descriptorSetCount = 1;
8077 alloc_info.descriptorPool = ds_pool;
8078 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008079 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis8ef479c2016-07-20 16:14:49 -06008080 ASSERT_VK_SUCCESS(err);
8081
8082 // Create a buffer to update the descriptor with
8083 uint32_t qfi = 0;
8084 VkBufferCreateInfo buffCI = {};
8085 buffCI.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
8086 buffCI.size = 1024;
8087 buffCI.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
8088 buffCI.queueFamilyIndexCount = 1;
8089 buffCI.pQueueFamilyIndices = &qfi;
8090
8091 VkBuffer dyub;
8092 err = vkCreateBuffer(m_device->device(), &buffCI, NULL, &dyub);
8093 ASSERT_VK_SUCCESS(err);
8094
8095 // Attempt to update descriptor without binding memory to it
8096 VkDescriptorBufferInfo buffInfo = {};
8097 buffInfo.buffer = dyub;
8098 buffInfo.offset = 0;
8099 buffInfo.range = 1024;
8100
8101 VkWriteDescriptorSet descriptor_write;
8102 memset(&descriptor_write, 0, sizeof(descriptor_write));
8103 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
8104 descriptor_write.dstSet = descriptorSet;
8105 descriptor_write.dstBinding = 0;
8106 descriptor_write.descriptorCount = 1;
8107 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
8108 descriptor_write.pBufferInfo = &buffInfo;
8109
8110 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
8111 m_errorMonitor->VerifyFound();
8112
8113 vkDestroyBuffer(m_device->device(), dyub, NULL);
8114 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
8115 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
8116}
8117
Tobin Ehlis3a23b6a2016-02-17 10:35:18 -07008118TEST_F(VkLayerTest, InvalidPushConstants) {
Tobin Ehlis3a23b6a2016-02-17 10:35:18 -07008119 VkResult err;
Tobin Ehlis3a23b6a2016-02-17 10:35:18 -07008120 ASSERT_NO_FATAL_FAILURE(InitState());
8121 ASSERT_NO_FATAL_FAILURE(InitViewport());
8122 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
8123
Karl Schultzfc8eaf12016-05-06 13:56:42 -06008124 VkPipelineLayout pipeline_layout;
Tobin Ehlis3a23b6a2016-02-17 10:35:18 -07008125 VkPushConstantRange pc_range = {};
Tobin Ehlis3a23b6a2016-02-17 10:35:18 -07008126 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
8127 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
8128 pipeline_layout_ci.pushConstantRangeCount = 1;
8129 pipeline_layout_ci.pPushConstantRanges = &pc_range;
8130
Karl Schultzfc8eaf12016-05-06 13:56:42 -06008131 //
8132 // Check for invalid push constant ranges in pipeline layouts.
8133 //
8134 struct PipelineLayoutTestCase {
Karl Schultzc81037d2016-05-12 08:11:23 -06008135 VkPushConstantRange const range;
Karl Schultzfc8eaf12016-05-06 13:56:42 -06008136 char const *msg;
8137 };
Tobin Ehlis3a23b6a2016-02-17 10:35:18 -07008138
Karl Schultzc81037d2016-05-12 08:11:23 -06008139 const uint32_t too_big = m_device->props.limits.maxPushConstantsSize + 0x4;
8140 const std::array<PipelineLayoutTestCase, 10> range_tests = {{
8141 {{VK_SHADER_STAGE_VERTEX_BIT, 0, 0},
8142 "vkCreatePipelineLayout() call has push constants index 0 with "
8143 "size 0."},
8144 {{VK_SHADER_STAGE_VERTEX_BIT, 0, 1},
8145 "vkCreatePipelineLayout() call has push constants index 0 with "
8146 "size 1."},
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06008147 {{VK_SHADER_STAGE_VERTEX_BIT, 4, 1},
Karl Schultzc81037d2016-05-12 08:11:23 -06008148 "vkCreatePipelineLayout() call has push constants index 0 with "
8149 "size 1."},
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06008150 {{VK_SHADER_STAGE_VERTEX_BIT, 4, 0},
Karl Schultzc81037d2016-05-12 08:11:23 -06008151 "vkCreatePipelineLayout() call has push constants index 0 with "
8152 "size 0."},
8153 {{VK_SHADER_STAGE_VERTEX_BIT, 1, 4},
8154 "vkCreatePipelineLayout() call has push constants index 0 with "
8155 "offset 1. Offset must"},
8156 {{VK_SHADER_STAGE_VERTEX_BIT, 0, too_big},
8157 "vkCreatePipelineLayout() call has push constants index 0 "
8158 "with offset "},
8159 {{VK_SHADER_STAGE_VERTEX_BIT, too_big, too_big},
8160 "vkCreatePipelineLayout() call has push constants "
8161 "index 0 with offset "},
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06008162 {{VK_SHADER_STAGE_VERTEX_BIT, too_big, 4},
Karl Schultzc81037d2016-05-12 08:11:23 -06008163 "vkCreatePipelineLayout() call has push constants index 0 "
8164 "with offset "},
8165 {{VK_SHADER_STAGE_VERTEX_BIT, 0xFFFFFFF0, 0x00000020},
8166 "vkCreatePipelineLayout() call has push "
8167 "constants index 0 with offset "},
8168 {{VK_SHADER_STAGE_VERTEX_BIT, 0x00000020, 0xFFFFFFF0},
8169 "vkCreatePipelineLayout() call has push "
8170 "constants index 0 with offset "},
Karl Schultzfc8eaf12016-05-06 13:56:42 -06008171 }};
8172
8173 // Check for invalid offset and size
Karl Schultzc81037d2016-05-12 08:11:23 -06008174 for (const auto &iter : range_tests) {
8175 pc_range = iter.range;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008176 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, iter.msg);
8177 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Karl Schultzfc8eaf12016-05-06 13:56:42 -06008178 m_errorMonitor->VerifyFound();
8179 if (VK_SUCCESS == err) {
8180 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
8181 }
8182 }
8183
8184 // Check for invalid stage flag
8185 pc_range.offset = 0;
8186 pc_range.size = 16;
8187 pc_range.stageFlags = 0;
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06008188 m_errorMonitor->SetDesiredFailureMsg(
8189 VK_DEBUG_REPORT_ERROR_BIT_EXT,
8190 "vkCreatePipelineLayout: value of pCreateInfo->pPushConstantRanges[0].stageFlags must not be 0");
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008191 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008192 m_errorMonitor->VerifyFound();
Karl Schultzfc8eaf12016-05-06 13:56:42 -06008193 if (VK_SUCCESS == err) {
8194 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
8195 }
8196
8197 // Check for overlapping ranges
Karl Schultzc81037d2016-05-12 08:11:23 -06008198 const uint32_t ranges_per_test = 5;
Karl Schultzfc8eaf12016-05-06 13:56:42 -06008199 struct OverlappingRangeTestCase {
Karl Schultzc81037d2016-05-12 08:11:23 -06008200 VkPushConstantRange const ranges[ranges_per_test];
Karl Schultzfc8eaf12016-05-06 13:56:42 -06008201 char const *msg;
8202 };
8203
Karl Schultzc81037d2016-05-12 08:11:23 -06008204 const std::array<OverlappingRangeTestCase, 5> overlapping_range_tests = {
Karl Schultzfc8eaf12016-05-06 13:56:42 -06008205 {{{{VK_SHADER_STAGE_VERTEX_BIT, 0, 4},
8206 {VK_SHADER_STAGE_VERTEX_BIT, 0, 4},
8207 {VK_SHADER_STAGE_VERTEX_BIT, 0, 4},
8208 {VK_SHADER_STAGE_VERTEX_BIT, 0, 4},
8209 {VK_SHADER_STAGE_VERTEX_BIT, 0, 4}},
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06008210 "vkCreatePipelineLayout() call has push constants with overlapping ranges:"},
Karl Schultzfc8eaf12016-05-06 13:56:42 -06008211 {
8212 {{VK_SHADER_STAGE_VERTEX_BIT, 0, 4},
8213 {VK_SHADER_STAGE_VERTEX_BIT, 4, 4},
8214 {VK_SHADER_STAGE_VERTEX_BIT, 8, 4},
8215 {VK_SHADER_STAGE_VERTEX_BIT, 12, 8},
8216 {VK_SHADER_STAGE_VERTEX_BIT, 16, 4}},
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06008217 "vkCreatePipelineLayout() call has push constants with overlapping ranges: 3:[12, 20), 4:[16, 20)",
Karl Schultzfc8eaf12016-05-06 13:56:42 -06008218 },
8219 {
8220 {{VK_SHADER_STAGE_VERTEX_BIT, 16, 4},
8221 {VK_SHADER_STAGE_VERTEX_BIT, 12, 8},
8222 {VK_SHADER_STAGE_VERTEX_BIT, 8, 4},
8223 {VK_SHADER_STAGE_VERTEX_BIT, 4, 4},
8224 {VK_SHADER_STAGE_VERTEX_BIT, 0, 4}},
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06008225 "vkCreatePipelineLayout() call has push constants with overlapping ranges: 0:[16, 20), 1:[12, 20)",
Karl Schultzfc8eaf12016-05-06 13:56:42 -06008226 },
8227 {
8228 {{VK_SHADER_STAGE_VERTEX_BIT, 16, 4},
8229 {VK_SHADER_STAGE_VERTEX_BIT, 8, 4},
8230 {VK_SHADER_STAGE_VERTEX_BIT, 4, 4},
8231 {VK_SHADER_STAGE_VERTEX_BIT, 12, 8},
8232 {VK_SHADER_STAGE_VERTEX_BIT, 0, 4}},
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06008233 "vkCreatePipelineLayout() call has push constants with overlapping ranges: 0:[16, 20), 3:[12, 20)",
Karl Schultzfc8eaf12016-05-06 13:56:42 -06008234 },
8235 {
8236 {{VK_SHADER_STAGE_VERTEX_BIT, 16, 4},
8237 {VK_SHADER_STAGE_VERTEX_BIT, 32, 4},
8238 {VK_SHADER_STAGE_VERTEX_BIT, 4, 96},
8239 {VK_SHADER_STAGE_VERTEX_BIT, 40, 8},
8240 {VK_SHADER_STAGE_VERTEX_BIT, 52, 4}},
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06008241 "vkCreatePipelineLayout() call has push constants with overlapping ranges:",
Karl Schultzfc8eaf12016-05-06 13:56:42 -06008242 }}};
Karl Schultzfc8eaf12016-05-06 13:56:42 -06008243
Karl Schultzc81037d2016-05-12 08:11:23 -06008244 for (const auto &iter : overlapping_range_tests) {
Karl Schultzfc8eaf12016-05-06 13:56:42 -06008245 pipeline_layout_ci.pPushConstantRanges = iter.ranges;
Karl Schultzc81037d2016-05-12 08:11:23 -06008246 pipeline_layout_ci.pushConstantRangeCount = ranges_per_test;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008247 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT, iter.msg);
8248 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Karl Schultzfc8eaf12016-05-06 13:56:42 -06008249 m_errorMonitor->VerifyFound();
8250 if (VK_SUCCESS == err) {
8251 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
8252 }
8253 }
8254
8255 // Run some positive tests to make sure overlap checking in the layer is OK
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008256 const std::array<OverlappingRangeTestCase, 2> overlapping_range_tests_pos = {{{{{VK_SHADER_STAGE_VERTEX_BIT, 0, 4},
8257 {VK_SHADER_STAGE_VERTEX_BIT, 4, 4},
8258 {VK_SHADER_STAGE_VERTEX_BIT, 8, 4},
8259 {VK_SHADER_STAGE_VERTEX_BIT, 12, 4},
8260 {VK_SHADER_STAGE_VERTEX_BIT, 16, 4}},
8261 ""},
8262 {{{VK_SHADER_STAGE_VERTEX_BIT, 92, 24},
8263 {VK_SHADER_STAGE_VERTEX_BIT, 80, 4},
8264 {VK_SHADER_STAGE_VERTEX_BIT, 64, 8},
8265 {VK_SHADER_STAGE_VERTEX_BIT, 4, 16},
8266 {VK_SHADER_STAGE_VERTEX_BIT, 0, 4}},
8267 ""}}};
Karl Schultzc81037d2016-05-12 08:11:23 -06008268 for (const auto &iter : overlapping_range_tests_pos) {
Karl Schultzfc8eaf12016-05-06 13:56:42 -06008269 pipeline_layout_ci.pPushConstantRanges = iter.ranges;
8270 m_errorMonitor->ExpectSuccess();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008271 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Karl Schultzfc8eaf12016-05-06 13:56:42 -06008272 m_errorMonitor->VerifyNotFound();
8273 if (VK_SUCCESS == err) {
8274 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
8275 }
8276 }
8277
8278 //
8279 // CmdPushConstants tests
8280 //
Karl Schultzc81037d2016-05-12 08:11:23 -06008281 const uint8_t dummy_values[100] = {};
Karl Schultzfc8eaf12016-05-06 13:56:42 -06008282
8283 // Check for invalid offset and size and if range is within layout range(s)
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06008284 const std::array<PipelineLayoutTestCase, 11> cmd_range_tests = {{
8285 {{VK_SHADER_STAGE_VERTEX_BIT, 0, 0}, "vkCmdPushConstants: parameter size must be greater than 0"},
Karl Schultzc81037d2016-05-12 08:11:23 -06008286 {{VK_SHADER_STAGE_VERTEX_BIT, 0, 1},
8287 "vkCmdPushConstants() call has push constants with size 1. Size "
8288 "must be greater than zero and a multiple of 4."},
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06008289 {{VK_SHADER_STAGE_VERTEX_BIT, 4, 1},
Karl Schultzc81037d2016-05-12 08:11:23 -06008290 "vkCmdPushConstants() call has push constants with size 1. Size "
8291 "must be greater than zero and a multiple of 4."},
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06008292 {{VK_SHADER_STAGE_VERTEX_BIT, 1, 4},
Karl Schultzc81037d2016-05-12 08:11:23 -06008293 "vkCmdPushConstants() call has push constants with offset 1. "
8294 "Offset must be a multiple of 4."},
8295 {{VK_SHADER_STAGE_VERTEX_BIT, 1, 4},
8296 "vkCmdPushConstants() call has push constants with offset 1. "
8297 "Offset must be a multiple of 4."},
8298 {{VK_SHADER_STAGE_VERTEX_BIT, 0, 20},
8299 "vkCmdPushConstants() Push constant range [0, 20) with stageFlags = "
8300 "0x1 not within flag-matching ranges in pipeline layout"},
8301 {{VK_SHADER_STAGE_VERTEX_BIT, 60, 8},
8302 "vkCmdPushConstants() Push constant range [60, 68) with stageFlags = "
8303 "0x1 not within flag-matching ranges in pipeline layout"},
8304 {{VK_SHADER_STAGE_VERTEX_BIT, 76, 8},
8305 "vkCmdPushConstants() Push constant range [76, 84) with stageFlags = "
8306 "0x1 not within flag-matching ranges in pipeline layout"},
8307 {{VK_SHADER_STAGE_VERTEX_BIT, 0, 80},
8308 "vkCmdPushConstants() Push constant range [0, 80) with stageFlags = "
8309 "0x1 not within flag-matching ranges in pipeline layout"},
8310 {{VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT, 0, 4},
8311 "vkCmdPushConstants() stageFlags = 0x2 do not match the stageFlags in "
8312 "any of the ranges in pipeline layout"},
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008313 {{VK_SHADER_STAGE_VERTEX_BIT | VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT, 0, 16},
Karl Schultzc81037d2016-05-12 08:11:23 -06008314 "vkCmdPushConstants() stageFlags = 0x3 do not match the stageFlags in "
8315 "any of the ranges in pipeline layout"},
Karl Schultzfc8eaf12016-05-06 13:56:42 -06008316 }};
8317
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06008318 BeginCommandBuffer();
8319
8320 // Setup ranges: [0,16) [64,80)
Karl Schultzc81037d2016-05-12 08:11:23 -06008321 const VkPushConstantRange pc_range2[] = {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008322 {VK_SHADER_STAGE_VERTEX_BIT, 64, 16}, {VK_SHADER_STAGE_VERTEX_BIT, 0, 16},
Karl Schultzfc8eaf12016-05-06 13:56:42 -06008323 };
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008324 pipeline_layout_ci.pushConstantRangeCount = sizeof(pc_range2) / sizeof(VkPushConstantRange);
Karl Schultzfc8eaf12016-05-06 13:56:42 -06008325 pipeline_layout_ci.pPushConstantRanges = pc_range2;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008326 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis3a23b6a2016-02-17 10:35:18 -07008327 ASSERT_VK_SUCCESS(err);
Karl Schultzc81037d2016-05-12 08:11:23 -06008328 for (const auto &iter : cmd_range_tests) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008329 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, iter.msg);
8330 vkCmdPushConstants(m_commandBuffer->GetBufferHandle(), pipeline_layout, iter.range.stageFlags, iter.range.offset,
Karl Schultzc81037d2016-05-12 08:11:23 -06008331 iter.range.size, dummy_values);
Karl Schultzfc8eaf12016-05-06 13:56:42 -06008332 m_errorMonitor->VerifyFound();
8333 }
8334
8335 // Check for invalid stage flag
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06008336 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "vkCmdPushConstants: value of stageFlags must not be 0");
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008337 vkCmdPushConstants(m_commandBuffer->GetBufferHandle(), pipeline_layout, 0, 0, 16, dummy_values);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008338 m_errorMonitor->VerifyFound();
Karl Schultzc81037d2016-05-12 08:11:23 -06008339 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
Karl Schultzfc8eaf12016-05-06 13:56:42 -06008340
Karl Schultzc81037d2016-05-12 08:11:23 -06008341 // overlapping range tests with cmd
8342 const std::array<PipelineLayoutTestCase, 3> cmd_overlap_tests = {{
8343 {{VK_SHADER_STAGE_VERTEX_BIT, 0, 20},
8344 "vkCmdPushConstants() Push constant range [0, 20) with stageFlags = "
8345 "0x1 not within flag-matching ranges in pipeline layout"},
8346 {{VK_SHADER_STAGE_VERTEX_BIT, 16, 4},
8347 "vkCmdPushConstants() Push constant range [16, 20) with stageFlags = "
8348 "0x1 not within flag-matching ranges in pipeline layout"},
8349 {{VK_SHADER_STAGE_VERTEX_BIT, 40, 16},
8350 "vkCmdPushConstants() Push constant range [40, 56) with stageFlags = "
8351 "0x1 not within flag-matching ranges in pipeline layout"},
8352 }};
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06008353 // Setup ranges: [0,16), [20,36), [36,44), [44,52), [80,92)
Karl Schultzc81037d2016-05-12 08:11:23 -06008354 const VkPushConstantRange pc_range3[] = {
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06008355 {VK_SHADER_STAGE_VERTEX_BIT, 20, 16}, {VK_SHADER_STAGE_VERTEX_BIT, 0, 16}, {VK_SHADER_STAGE_VERTEX_BIT, 44, 8},
8356 {VK_SHADER_STAGE_VERTEX_BIT, 80, 12}, {VK_SHADER_STAGE_VERTEX_BIT, 36, 8},
Karl Schultzc81037d2016-05-12 08:11:23 -06008357 };
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008358 pipeline_layout_ci.pushConstantRangeCount = sizeof(pc_range3) / sizeof(VkPushConstantRange);
Karl Schultzc81037d2016-05-12 08:11:23 -06008359 pipeline_layout_ci.pPushConstantRanges = pc_range3;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008360 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Karl Schultzc81037d2016-05-12 08:11:23 -06008361 ASSERT_VK_SUCCESS(err);
Karl Schultzc81037d2016-05-12 08:11:23 -06008362 for (const auto &iter : cmd_overlap_tests) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008363 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, iter.msg);
8364 vkCmdPushConstants(m_commandBuffer->GetBufferHandle(), pipeline_layout, iter.range.stageFlags, iter.range.offset,
Karl Schultzc81037d2016-05-12 08:11:23 -06008365 iter.range.size, dummy_values);
8366 m_errorMonitor->VerifyFound();
8367 }
Karl Schultzc81037d2016-05-12 08:11:23 -06008368 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
8369
8370 // positive overlapping range tests with cmd
8371 const std::array<PipelineLayoutTestCase, 4> cmd_overlap_tests_pos = {{
8372 {{VK_SHADER_STAGE_VERTEX_BIT, 0, 16}, ""},
8373 {{VK_SHADER_STAGE_VERTEX_BIT, 0, 4}, ""},
8374 {{VK_SHADER_STAGE_VERTEX_BIT, 20, 12}, ""},
8375 {{VK_SHADER_STAGE_VERTEX_BIT, 56, 36}, ""},
8376 }};
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06008377 // Setup ranges: [0,16) [20,36) [36,44) [44,52) [56,80) [80,92)
Karl Schultzc81037d2016-05-12 08:11:23 -06008378 const VkPushConstantRange pc_range4[] = {
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06008379 {VK_SHADER_STAGE_VERTEX_BIT, 20, 16}, {VK_SHADER_STAGE_VERTEX_BIT, 0, 16}, {VK_SHADER_STAGE_VERTEX_BIT, 44, 8},
8380 {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 -06008381 };
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008382 pipeline_layout_ci.pushConstantRangeCount = sizeof(pc_range4) / sizeof(VkPushConstantRange);
Karl Schultzc81037d2016-05-12 08:11:23 -06008383 pipeline_layout_ci.pPushConstantRanges = pc_range4;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008384 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Karl Schultzc81037d2016-05-12 08:11:23 -06008385 ASSERT_VK_SUCCESS(err);
Karl Schultzc81037d2016-05-12 08:11:23 -06008386 for (const auto &iter : cmd_overlap_tests_pos) {
8387 m_errorMonitor->ExpectSuccess();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008388 vkCmdPushConstants(m_commandBuffer->GetBufferHandle(), pipeline_layout, iter.range.stageFlags, iter.range.offset,
Karl Schultzc81037d2016-05-12 08:11:23 -06008389 iter.range.size, dummy_values);
8390 m_errorMonitor->VerifyNotFound();
8391 }
Tobin Ehlis3a23b6a2016-02-17 10:35:18 -07008392 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06008393
8394 EndCommandBuffer();
Tobin Ehlis3a23b6a2016-02-17 10:35:18 -07008395}
8396
Karl Schultz6addd812016-02-02 17:17:23 -07008397TEST_F(VkLayerTest, DescriptorSetCompatibility) {
Tobin Ehlis559c6382015-11-05 09:52:49 -07008398 // Test various desriptorSet errors with bad binding combinations
Karl Schultz6addd812016-02-02 17:17:23 -07008399 VkResult err;
Tobin Ehlis559c6382015-11-05 09:52:49 -07008400
8401 ASSERT_NO_FATAL_FAILURE(InitState());
8402 ASSERT_NO_FATAL_FAILURE(InitViewport());
8403 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
8404
Mike Stroyanb8a61002016-06-20 16:00:28 -06008405 const VkFormat tex_format = VK_FORMAT_R8G8B8A8_UNORM;
8406 VkImageTiling tiling;
8407 VkFormatProperties format_properties;
8408 vkGetPhysicalDeviceFormatProperties(gpu(), tex_format, &format_properties);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008409 if (format_properties.linearTilingFeatures & VK_FORMAT_FEATURE_STORAGE_IMAGE_BIT) {
Mike Stroyanb8a61002016-06-20 16:00:28 -06008410 tiling = VK_IMAGE_TILING_LINEAR;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008411 } else if (format_properties.optimalTilingFeatures & VK_FORMAT_FEATURE_STORAGE_IMAGE_BIT) {
Mike Stroyanb8a61002016-06-20 16:00:28 -06008412 tiling = VK_IMAGE_TILING_OPTIMAL;
8413 } else {
8414 printf("Device does not support VK_FORMAT_FEATURE_STORAGE_IMAGE_BIT; "
8415 "skipped.\n");
8416 return;
8417 }
8418
Tobin Ehlis559c6382015-11-05 09:52:49 -07008419 static const uint32_t NUM_DESCRIPTOR_TYPES = 5;
8420 VkDescriptorPoolSize ds_type_count[NUM_DESCRIPTOR_TYPES] = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008421 ds_type_count[0].type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
8422 ds_type_count[0].descriptorCount = 10;
8423 ds_type_count[1].type = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE;
8424 ds_type_count[1].descriptorCount = 2;
8425 ds_type_count[2].type = VK_DESCRIPTOR_TYPE_STORAGE_IMAGE;
8426 ds_type_count[2].descriptorCount = 2;
8427 ds_type_count[3].type = VK_DESCRIPTOR_TYPE_SAMPLER;
8428 ds_type_count[3].descriptorCount = 5;
8429 // TODO : LunarG ILO driver currently asserts in desc.c w/ INPUT_ATTACHMENT
8430 // type
8431 // ds_type_count[4].type = VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT;
8432 ds_type_count[4].type = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
8433 ds_type_count[4].descriptorCount = 2;
Tobin Ehlis559c6382015-11-05 09:52:49 -07008434
8435 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008436 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
8437 ds_pool_ci.pNext = NULL;
8438 ds_pool_ci.maxSets = 5;
8439 ds_pool_ci.poolSizeCount = NUM_DESCRIPTOR_TYPES;
8440 ds_pool_ci.pPoolSizes = ds_type_count;
Tobin Ehlis559c6382015-11-05 09:52:49 -07008441
8442 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008443 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis559c6382015-11-05 09:52:49 -07008444 ASSERT_VK_SUCCESS(err);
8445
8446 static const uint32_t MAX_DS_TYPES_IN_LAYOUT = 2;
8447 VkDescriptorSetLayoutBinding dsl_binding[MAX_DS_TYPES_IN_LAYOUT] = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008448 dsl_binding[0].binding = 0;
8449 dsl_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
8450 dsl_binding[0].descriptorCount = 5;
8451 dsl_binding[0].stageFlags = VK_SHADER_STAGE_ALL;
8452 dsl_binding[0].pImmutableSamplers = NULL;
Tobin Ehlis559c6382015-11-05 09:52:49 -07008453
Tobin Ehlis8fab6562015-12-01 09:57:09 -07008454 // Create layout identical to set0 layout but w/ different stageFlags
8455 VkDescriptorSetLayoutBinding dsl_fs_stage_only = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008456 dsl_fs_stage_only.binding = 0;
8457 dsl_fs_stage_only.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
8458 dsl_fs_stage_only.descriptorCount = 5;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008459 dsl_fs_stage_only.stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT; // Different stageFlags to cause error at
8460 // bind time
Karl Schultz6addd812016-02-02 17:17:23 -07008461 dsl_fs_stage_only.pImmutableSamplers = NULL;
Tobin Ehlis559c6382015-11-05 09:52:49 -07008462 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008463 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
8464 ds_layout_ci.pNext = NULL;
8465 ds_layout_ci.bindingCount = 1;
8466 ds_layout_ci.pBindings = dsl_binding;
Tobin Ehlis559c6382015-11-05 09:52:49 -07008467 static const uint32_t NUM_LAYOUTS = 4;
8468 VkDescriptorSetLayout ds_layout[NUM_LAYOUTS] = {};
Tobin Ehlis8fab6562015-12-01 09:57:09 -07008469 VkDescriptorSetLayout ds_layout_fs_only = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008470 // Create 4 unique layouts for full pipelineLayout, and 1 special fs-only
8471 // layout for error case
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008472 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout[0]);
Tobin Ehlis559c6382015-11-05 09:52:49 -07008473 ASSERT_VK_SUCCESS(err);
Jon Ashburn6e23c1f2015-12-30 18:01:16 -07008474 ds_layout_ci.pBindings = &dsl_fs_stage_only;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008475 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout_fs_only);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07008476 ASSERT_VK_SUCCESS(err);
Tobin Ehlis559c6382015-11-05 09:52:49 -07008477 dsl_binding[0].binding = 0;
8478 dsl_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE;
Tobin Ehlis8fab6562015-12-01 09:57:09 -07008479 dsl_binding[0].descriptorCount = 2;
Mike Stroyan9c70cdb2016-01-06 14:14:17 -07008480 dsl_binding[1].binding = 1;
8481 dsl_binding[1].descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_IMAGE;
8482 dsl_binding[1].descriptorCount = 2;
8483 dsl_binding[1].stageFlags = VK_SHADER_STAGE_ALL;
8484 dsl_binding[1].pImmutableSamplers = NULL;
Jon Ashburn6e23c1f2015-12-30 18:01:16 -07008485 ds_layout_ci.pBindings = dsl_binding;
Tobin Ehlis559c6382015-11-05 09:52:49 -07008486 ds_layout_ci.bindingCount = 2;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008487 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout[1]);
Tobin Ehlis559c6382015-11-05 09:52:49 -07008488 ASSERT_VK_SUCCESS(err);
8489 dsl_binding[0].binding = 0;
8490 dsl_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
Tobin Ehlis8fab6562015-12-01 09:57:09 -07008491 dsl_binding[0].descriptorCount = 5;
Tobin Ehlis559c6382015-11-05 09:52:49 -07008492 ds_layout_ci.bindingCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008493 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout[2]);
Tobin Ehlis559c6382015-11-05 09:52:49 -07008494 ASSERT_VK_SUCCESS(err);
8495 dsl_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
Tobin Ehlis8fab6562015-12-01 09:57:09 -07008496 dsl_binding[0].descriptorCount = 2;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008497 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout[3]);
Tobin Ehlis559c6382015-11-05 09:52:49 -07008498 ASSERT_VK_SUCCESS(err);
8499
8500 static const uint32_t NUM_SETS = 4;
8501 VkDescriptorSet descriptorSet[NUM_SETS] = {};
8502 VkDescriptorSetAllocateInfo alloc_info = {};
Tobin Ehlis8fab6562015-12-01 09:57:09 -07008503 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07008504 alloc_info.descriptorSetCount = NUM_LAYOUTS;
Tobin Ehlis559c6382015-11-05 09:52:49 -07008505 alloc_info.descriptorPool = ds_pool;
8506 alloc_info.pSetLayouts = ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008507 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, descriptorSet);
Tobin Ehlis559c6382015-11-05 09:52:49 -07008508 ASSERT_VK_SUCCESS(err);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07008509 VkDescriptorSet ds0_fs_only = {};
Jon Ashburnf19916e2016-01-11 13:12:43 -07008510 alloc_info.descriptorSetCount = 1;
Tobin Ehlis8fab6562015-12-01 09:57:09 -07008511 alloc_info.pSetLayouts = &ds_layout_fs_only;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008512 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &ds0_fs_only);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07008513 ASSERT_VK_SUCCESS(err);
Tobin Ehlis559c6382015-11-05 09:52:49 -07008514
8515 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008516 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
8517 pipeline_layout_ci.pNext = NULL;
8518 pipeline_layout_ci.setLayoutCount = NUM_LAYOUTS;
8519 pipeline_layout_ci.pSetLayouts = ds_layout;
Tobin Ehlis559c6382015-11-05 09:52:49 -07008520
8521 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008522 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis559c6382015-11-05 09:52:49 -07008523 ASSERT_VK_SUCCESS(err);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07008524 // Create pipelineLayout with only one setLayout
8525 pipeline_layout_ci.setLayoutCount = 1;
8526 VkPipelineLayout single_pipe_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008527 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &single_pipe_layout);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07008528 ASSERT_VK_SUCCESS(err);
8529 // Create pipelineLayout with 2 descriptor setLayout at index 0
8530 pipeline_layout_ci.pSetLayouts = &ds_layout[3];
8531 VkPipelineLayout pipe_layout_one_desc;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008532 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipe_layout_one_desc);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07008533 ASSERT_VK_SUCCESS(err);
8534 // Create pipelineLayout with 5 SAMPLER descriptor setLayout at index 0
8535 pipeline_layout_ci.pSetLayouts = &ds_layout[2];
8536 VkPipelineLayout pipe_layout_five_samp;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008537 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipe_layout_five_samp);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07008538 ASSERT_VK_SUCCESS(err);
8539 // Create pipelineLayout with UB type, but stageFlags for FS only
8540 pipeline_layout_ci.pSetLayouts = &ds_layout_fs_only;
8541 VkPipelineLayout pipe_layout_fs_only;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008542 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipe_layout_fs_only);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07008543 ASSERT_VK_SUCCESS(err);
8544 // Create pipelineLayout w/ incompatible set0 layout, but set1 is fine
8545 VkDescriptorSetLayout pl_bad_s0[2] = {};
8546 pl_bad_s0[0] = ds_layout_fs_only;
8547 pl_bad_s0[1] = ds_layout[1];
8548 pipeline_layout_ci.setLayoutCount = 2;
8549 pipeline_layout_ci.pSetLayouts = pl_bad_s0;
8550 VkPipelineLayout pipe_layout_bad_set0;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008551 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipe_layout_bad_set0);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07008552 ASSERT_VK_SUCCESS(err);
Tobin Ehlis559c6382015-11-05 09:52:49 -07008553
8554 // Create a buffer to update the descriptor with
8555 uint32_t qfi = 0;
8556 VkBufferCreateInfo buffCI = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008557 buffCI.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
8558 buffCI.size = 1024;
8559 buffCI.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
8560 buffCI.queueFamilyIndexCount = 1;
8561 buffCI.pQueueFamilyIndices = &qfi;
Tobin Ehlis559c6382015-11-05 09:52:49 -07008562
8563 VkBuffer dyub;
8564 err = vkCreateBuffer(m_device->device(), &buffCI, NULL, &dyub);
8565 ASSERT_VK_SUCCESS(err);
8566 // Correctly update descriptor to avoid "NOT_UPDATED" error
8567 static const uint32_t NUM_BUFFS = 5;
8568 VkDescriptorBufferInfo buffInfo[NUM_BUFFS] = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008569 for (uint32_t i = 0; i < NUM_BUFFS; ++i) {
Tobin Ehlis559c6382015-11-05 09:52:49 -07008570 buffInfo[i].buffer = dyub;
8571 buffInfo[i].offset = 0;
8572 buffInfo[i].range = 1024;
8573 }
Karl Schultz6addd812016-02-02 17:17:23 -07008574 VkImage image;
Karl Schultz6addd812016-02-02 17:17:23 -07008575 const int32_t tex_width = 32;
8576 const int32_t tex_height = 32;
Tobin Ehlis8fab6562015-12-01 09:57:09 -07008577 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008578 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
8579 image_create_info.pNext = NULL;
8580 image_create_info.imageType = VK_IMAGE_TYPE_2D;
8581 image_create_info.format = tex_format;
8582 image_create_info.extent.width = tex_width;
8583 image_create_info.extent.height = tex_height;
8584 image_create_info.extent.depth = 1;
8585 image_create_info.mipLevels = 1;
8586 image_create_info.arrayLayers = 1;
8587 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
Mike Stroyanb8a61002016-06-20 16:00:28 -06008588 image_create_info.tiling = tiling;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008589 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT | VK_IMAGE_USAGE_STORAGE_BIT;
Karl Schultz6addd812016-02-02 17:17:23 -07008590 image_create_info.flags = 0;
Tobin Ehlis8fab6562015-12-01 09:57:09 -07008591 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
8592 ASSERT_VK_SUCCESS(err);
Tobin Ehlis559c6382015-11-05 09:52:49 -07008593
Karl Schultz6addd812016-02-02 17:17:23 -07008594 VkMemoryRequirements memReqs;
8595 VkDeviceMemory imageMem;
8596 bool pass;
Mike Stroyan9c70cdb2016-01-06 14:14:17 -07008597 VkMemoryAllocateInfo memAlloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008598 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
8599 memAlloc.pNext = NULL;
8600 memAlloc.allocationSize = 0;
8601 memAlloc.memoryTypeIndex = 0;
Mike Stroyan9c70cdb2016-01-06 14:14:17 -07008602 vkGetImageMemoryRequirements(m_device->device(), image, &memReqs);
8603 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008604 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Mike Stroyan9c70cdb2016-01-06 14:14:17 -07008605 ASSERT_TRUE(pass);
8606 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &imageMem);
8607 ASSERT_VK_SUCCESS(err);
8608 err = vkBindImageMemory(m_device->device(), image, imageMem, 0);
8609 ASSERT_VK_SUCCESS(err);
8610
Tobin Ehlis8fab6562015-12-01 09:57:09 -07008611 VkImageViewCreateInfo image_view_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008612 image_view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
8613 image_view_create_info.image = image;
8614 image_view_create_info.viewType = VK_IMAGE_VIEW_TYPE_2D;
8615 image_view_create_info.format = tex_format;
8616 image_view_create_info.subresourceRange.layerCount = 1;
8617 image_view_create_info.subresourceRange.baseMipLevel = 0;
8618 image_view_create_info.subresourceRange.levelCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008619 image_view_create_info.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Tobin Ehlis559c6382015-11-05 09:52:49 -07008620
Tobin Ehlis8fab6562015-12-01 09:57:09 -07008621 VkImageView view;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008622 err = vkCreateImageView(m_device->device(), &image_view_create_info, NULL, &view);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07008623 ASSERT_VK_SUCCESS(err);
Tobin Ehlis991d45a2016-01-06 08:48:41 -07008624 VkDescriptorImageInfo imageInfo[4] = {};
Tobin Ehlis8fab6562015-12-01 09:57:09 -07008625 imageInfo[0].imageView = view;
8626 imageInfo[0].imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
8627 imageInfo[1].imageView = view;
8628 imageInfo[1].imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
Tobin Ehlis991d45a2016-01-06 08:48:41 -07008629 imageInfo[2].imageView = view;
8630 imageInfo[2].imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
8631 imageInfo[3].imageView = view;
8632 imageInfo[3].imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
Tobin Ehlis8fab6562015-12-01 09:57:09 -07008633
8634 static const uint32_t NUM_SET_UPDATES = 3;
8635 VkWriteDescriptorSet descriptor_write[NUM_SET_UPDATES] = {};
8636 descriptor_write[0].sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
8637 descriptor_write[0].dstSet = descriptorSet[0];
8638 descriptor_write[0].dstBinding = 0;
8639 descriptor_write[0].descriptorCount = 5;
8640 descriptor_write[0].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
8641 descriptor_write[0].pBufferInfo = buffInfo;
8642 descriptor_write[1].sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
8643 descriptor_write[1].dstSet = descriptorSet[1];
8644 descriptor_write[1].dstBinding = 0;
8645 descriptor_write[1].descriptorCount = 2;
8646 descriptor_write[1].descriptorType = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE;
8647 descriptor_write[1].pImageInfo = imageInfo;
8648 descriptor_write[2].sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
8649 descriptor_write[2].dstSet = descriptorSet[1];
8650 descriptor_write[2].dstBinding = 1;
8651 descriptor_write[2].descriptorCount = 2;
8652 descriptor_write[2].descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_IMAGE;
Tobin Ehlis991d45a2016-01-06 08:48:41 -07008653 descriptor_write[2].pImageInfo = &imageInfo[2];
Tobin Ehlis8fab6562015-12-01 09:57:09 -07008654
8655 vkUpdateDescriptorSets(m_device->device(), 3, descriptor_write, 0, NULL);
Tobin Ehlis559c6382015-11-05 09:52:49 -07008656
Tobin Ehlis88452832015-12-03 09:40:56 -07008657 // Create PSO to be used for draw-time errors below
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008658 char const *vsSource = "#version 450\n"
8659 "\n"
8660 "out gl_PerVertex {\n"
8661 " vec4 gl_Position;\n"
8662 "};\n"
8663 "void main(){\n"
8664 " gl_Position = vec4(1);\n"
8665 "}\n";
8666 char const *fsSource = "#version 450\n"
8667 "\n"
8668 "layout(location=0) out vec4 x;\n"
8669 "layout(set=0) layout(binding=0) uniform foo { int x; int y; } bar;\n"
8670 "void main(){\n"
8671 " x = vec4(bar.y);\n"
8672 "}\n";
Tobin Ehlis88452832015-12-03 09:40:56 -07008673 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
8674 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Tobin Ehlis559c6382015-11-05 09:52:49 -07008675 VkPipelineObj pipe(m_device);
8676 pipe.AddShader(&vs);
8677 pipe.AddShader(&fs);
Tobin Ehlis88452832015-12-03 09:40:56 -07008678 pipe.AddColorAttachment();
8679 pipe.CreateVKPipeline(pipe_layout_fs_only, renderPass());
Tobin Ehlis559c6382015-11-05 09:52:49 -07008680
8681 BeginCommandBuffer();
Tobin Ehlis88452832015-12-03 09:40:56 -07008682
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008683 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Karl Schultz6addd812016-02-02 17:17:23 -07008684 // NOTE : I believe LunarG ilo driver has bug (LX#189) that requires binding
8685 // of PSO
8686 // here before binding DSs. Otherwise we assert in cmd_copy_dset_data() of
8687 // cmd_pipeline.c
8688 // due to the fact that cmd_alloc_dset_data() has not been called in
8689 // cmd_bind_graphics_pipeline()
8690 // TODO : Want to cause various binding incompatibility issues here to test
8691 // DrawState
Tobin Ehlis559c6382015-11-05 09:52:49 -07008692 // First cause various verify_layout_compatibility() fails
8693 // Second disturb early and late sets and verify INFO msgs
Tobin Ehlis8fab6562015-12-01 09:57:09 -07008694 // verify_set_layout_compatibility fail cases:
8695 // 1. invalid VkPipelineLayout (layout) passed into vkCmdBindDescriptorSets
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008696 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Invalid Pipeline Layout Object ");
8697 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS,
8698 (VkPipelineLayout)((size_t)0xbaadb1be), 0, 1, &descriptorSet[0], 0, NULL);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008699 m_errorMonitor->VerifyFound();
8700
Tobin Ehlis8fab6562015-12-01 09:57:09 -07008701 // 2. layoutIndex exceeds # of layouts in layout
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008702 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " attempting to bind set to index 1");
8703 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, single_pipe_layout, 0, 2,
8704 &descriptorSet[0], 0, NULL);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008705 m_errorMonitor->VerifyFound();
8706
Tobin Ehlis8fab6562015-12-01 09:57:09 -07008707 vkDestroyPipelineLayout(m_device->device(), single_pipe_layout, NULL);
Karl Schultz6addd812016-02-02 17:17:23 -07008708 // 3. Pipeline setLayout[0] has 2 descriptors, but set being bound has 5
8709 // descriptors
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008710 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " has 2 descriptors, but DescriptorSetLayout ");
8711 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe_layout_one_desc, 0, 1,
8712 &descriptorSet[0], 0, NULL);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008713 m_errorMonitor->VerifyFound();
8714
Tobin Ehlis8fab6562015-12-01 09:57:09 -07008715 vkDestroyPipelineLayout(m_device->device(), pipe_layout_one_desc, NULL);
8716 // 4. same # of descriptors but mismatch in type
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008717 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " is type 'VK_DESCRIPTOR_TYPE_SAMPLER' but binding ");
8718 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe_layout_five_samp, 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_five_samp, NULL);
8723 // 5. same # of descriptors but mismatch in stageFlags
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008724 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
8725 " has stageFlags 16 but binding 0 for DescriptorSetLayout ");
8726 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe_layout_fs_only, 0, 1,
8727 &descriptorSet[0], 0, NULL);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008728 m_errorMonitor->VerifyFound();
8729
Tobin Ehlis8fab6562015-12-01 09:57:09 -07008730 // Cause INFO messages due to disturbing previously bound Sets
8731 // First bind sets 0 & 1
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008732 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 2,
8733 &descriptorSet[0], 0, NULL);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07008734 // 1. Disturb bound set0 by re-binding set1 w/ updated pipelineLayout
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008735 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT, " previously bound as set #0 was disturbed ");
8736 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe_layout_bad_set0, 1, 1,
8737 &descriptorSet[1], 0, NULL);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008738 m_errorMonitor->VerifyFound();
8739
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008740 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 2,
8741 &descriptorSet[0], 0, NULL);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07008742 // 2. Disturb set after last bound set
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008743 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT, " newly bound as set #0 so set #1 and "
8744 "any subsequent sets were disturbed ");
8745 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe_layout_fs_only, 0, 1,
8746 &ds0_fs_only, 0, NULL);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008747 m_errorMonitor->VerifyFound();
8748
Tobin Ehlis10fad692016-07-07 12:00:36 -06008749 // Now that we're done actively using the pipelineLayout that gfx pipeline
8750 // was created with, we should be able to delete it. Do that now to verify
8751 // that validation obeys pipelineLayout lifetime
8752 vkDestroyPipelineLayout(m_device->device(), pipe_layout_fs_only, NULL);
8753
Tobin Ehlis88452832015-12-03 09:40:56 -07008754 // Cause draw-time errors due to PSO incompatibilities
Karl Schultz6addd812016-02-02 17:17:23 -07008755 // 1. Error due to not binding required set (we actually use same code as
8756 // above to disturb set0)
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008757 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 2,
8758 &descriptorSet[0], 0, NULL);
8759 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe_layout_bad_set0, 1, 1,
8760 &descriptorSet[1], 0, NULL);
8761 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 -07008762 Draw(1, 0, 0, 0);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008763 m_errorMonitor->VerifyFound();
8764
Tobin Ehlis991d45a2016-01-06 08:48:41 -07008765 vkDestroyPipelineLayout(m_device->device(), pipe_layout_bad_set0, NULL);
Karl Schultz6addd812016-02-02 17:17:23 -07008766 // 2. Error due to bound set not being compatible with PSO's
8767 // VkPipelineLayout (diff stageFlags in this case)
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008768 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 2,
8769 &descriptorSet[0], 0, NULL);
8770 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " bound as set #0 is not compatible with ");
Tobin Ehlis88452832015-12-03 09:40:56 -07008771 Draw(1, 0, 0, 0);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008772 m_errorMonitor->VerifyFound();
8773
Tobin Ehlis8fab6562015-12-01 09:57:09 -07008774 // Remaining clean-up
Karl Schultz6addd812016-02-02 17:17:23 -07008775 for (uint32_t i = 0; i < NUM_LAYOUTS; ++i) {
Tobin Ehlis8fab6562015-12-01 09:57:09 -07008776 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout[i], NULL);
8777 }
8778 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout_fs_only, NULL);
Tobin Ehlis9bfd4492016-05-05 15:09:11 -06008779 vkFreeDescriptorSets(m_device->device(), ds_pool, 1, &ds0_fs_only);
8780 vkFreeDescriptorSets(m_device->device(), ds_pool, NUM_SETS, descriptorSet);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07008781 vkDestroyBuffer(m_device->device(), dyub, NULL);
Tobin Ehlis559c6382015-11-05 09:52:49 -07008782 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
8783 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tony Barbourdf4c0042016-06-01 15:55:43 -06008784 vkFreeMemory(m_device->device(), imageMem, NULL);
8785 vkDestroyImage(m_device->device(), image, NULL);
8786 vkDestroyImageView(m_device->device(), view, NULL);
Tobin Ehlis559c6382015-11-05 09:52:49 -07008787}
Tobin Ehlis559c6382015-11-05 09:52:49 -07008788
Karl Schultz6addd812016-02-02 17:17:23 -07008789TEST_F(VkLayerTest, NoBeginCommandBuffer) {
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06008790
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008791 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
8792 "You must call vkBeginCommandBuffer() before this call to ");
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06008793
8794 ASSERT_NO_FATAL_FAILURE(InitState());
Chia-I Wu3432a0c2015-10-27 18:04:07 +08008795 VkCommandBufferObj commandBuffer(m_device, m_commandPool);
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06008796 // Call EndCommandBuffer() w/o calling BeginCommandBuffer()
Chia-I Wu3432a0c2015-10-27 18:04:07 +08008797 vkEndCommandBuffer(commandBuffer.GetBufferHandle());
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06008798
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008799 m_errorMonitor->VerifyFound();
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06008800}
8801
Karl Schultz6addd812016-02-02 17:17:23 -07008802TEST_F(VkLayerTest, SecondaryCommandBufferNullRenderpass) {
8803 VkResult err;
8804 VkCommandBuffer draw_cmd;
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06008805
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008806 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " must specify a valid renderpass parameter.");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06008807
Mark Lobodzinskid9139a62015-08-04 16:24:20 -06008808 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinskid9139a62015-08-04 16:24:20 -06008809
Chia-I Wu3432a0c2015-10-27 18:04:07 +08008810 VkCommandBufferAllocateInfo cmd = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08008811 cmd.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
Cody Northropb4569702015-08-04 17:35:57 -06008812 cmd.pNext = NULL;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08008813 cmd.commandPool = m_commandPool;
8814 cmd.level = VK_COMMAND_BUFFER_LEVEL_SECONDARY;
Jon Ashburnf19916e2016-01-11 13:12:43 -07008815 cmd.commandBufferCount = 1;
Cody Northropb4569702015-08-04 17:35:57 -06008816
Chia-I Wu3432a0c2015-10-27 18:04:07 +08008817 err = vkAllocateCommandBuffers(m_device->device(), &cmd, &draw_cmd);
Mike Stroyand1c84a52015-08-18 14:40:24 -06008818 ASSERT_VK_SUCCESS(err);
Mark Lobodzinskid9139a62015-08-04 16:24:20 -06008819
8820 // Force the failure by not setting the Renderpass and Framebuffer fields
Chia-I Wu3432a0c2015-10-27 18:04:07 +08008821 VkCommandBufferBeginInfo cmd_buf_info = {};
Jon Ashburnf19916e2016-01-11 13:12:43 -07008822 VkCommandBufferInheritanceInfo cmd_buf_hinfo = {};
Chia-I Wu3432a0c2015-10-27 18:04:07 +08008823 cmd_buf_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
Cody Northropb4569702015-08-04 17:35:57 -06008824 cmd_buf_info.pNext = NULL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008825 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 -07008826 cmd_buf_info.pInheritanceInfo = &cmd_buf_hinfo;
Mark Lobodzinskid9139a62015-08-04 16:24:20 -06008827
8828 // The error should be caught by validation of the BeginCommandBuffer call
8829 vkBeginCommandBuffer(draw_cmd, &cmd_buf_info);
8830
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008831 m_errorMonitor->VerifyFound();
Chia-I Wu3432a0c2015-10-27 18:04:07 +08008832 vkFreeCommandBuffers(m_device->device(), m_commandPool, 1, &draw_cmd);
Mark Lobodzinskid9139a62015-08-04 16:24:20 -06008833}
8834
Karl Schultz6addd812016-02-02 17:17:23 -07008835TEST_F(VkLayerTest, CommandBufferResetErrors) {
Tobin Ehlisac0ef842015-12-14 13:46:38 -07008836 // Cause error due to Begin while recording CB
8837 // Then cause 2 errors for attempting to reset CB w/o having
8838 // VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT set for the pool from
8839 // which CBs were allocated. Note that this bit is off by default.
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008840 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Cannot call Begin on CB");
Tobin Ehlisac0ef842015-12-14 13:46:38 -07008841
8842 ASSERT_NO_FATAL_FAILURE(InitState());
8843
8844 // Calls AllocateCommandBuffers
8845 VkCommandBufferObj commandBuffer(m_device, m_commandPool);
8846
Karl Schultz6addd812016-02-02 17:17:23 -07008847 // Force the failure by setting the Renderpass and Framebuffer fields with
8848 // (fake) data
Tobin Ehlisac0ef842015-12-14 13:46:38 -07008849 VkCommandBufferBeginInfo cmd_buf_info = {};
Jon Ashburnf19916e2016-01-11 13:12:43 -07008850 VkCommandBufferInheritanceInfo cmd_buf_hinfo = {};
Tobin Ehlisac0ef842015-12-14 13:46:38 -07008851 cmd_buf_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
8852 cmd_buf_info.pNext = NULL;
8853 cmd_buf_info.flags = VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT;
Jon Ashburnf19916e2016-01-11 13:12:43 -07008854 cmd_buf_info.pInheritanceInfo = &cmd_buf_hinfo;
Tobin Ehlisac0ef842015-12-14 13:46:38 -07008855
8856 // Begin CB to transition to recording state
8857 vkBeginCommandBuffer(commandBuffer.GetBufferHandle(), &cmd_buf_info);
8858 // Can't re-begin. This should trigger error
8859 vkBeginCommandBuffer(commandBuffer.GetBufferHandle(), &cmd_buf_info);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008860 m_errorMonitor->VerifyFound();
8861
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008862 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Attempt to reset command buffer ");
Tobin Ehlisac0ef842015-12-14 13:46:38 -07008863 VkCommandBufferResetFlags flags = 0; // Don't care about flags for this test
8864 // Reset attempt will trigger error due to incorrect CommandPool state
8865 vkResetCommandBuffer(commandBuffer.GetBufferHandle(), flags);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008866 m_errorMonitor->VerifyFound();
8867
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008868 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " attempts to implicitly reset cmdBuffer created from ");
Tobin Ehlisac0ef842015-12-14 13:46:38 -07008869 // Transition CB to RECORDED state
8870 vkEndCommandBuffer(commandBuffer.GetBufferHandle());
8871 // Now attempting to Begin will implicitly reset, which triggers error
8872 vkBeginCommandBuffer(commandBuffer.GetBufferHandle(), &cmd_buf_info);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008873 m_errorMonitor->VerifyFound();
Tobin Ehlisac0ef842015-12-14 13:46:38 -07008874}
8875
Karl Schultz6addd812016-02-02 17:17:23 -07008876TEST_F(VkLayerTest, InvalidPipelineCreateState) {
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06008877 // Attempt to Create Gfx Pipeline w/o a VS
Karl Schultz6addd812016-02-02 17:17:23 -07008878 VkResult err;
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06008879
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008880 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Invalid Pipeline CreateInfo State: Vtx Shader required");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06008881
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06008882 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06008883 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Mark Lobodzinski209b5292015-09-17 09:44:05 -06008884
Chia-I Wu1b99bb22015-10-27 19:25:11 +08008885 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008886 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
8887 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -06008888
8889 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008890 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
8891 ds_pool_ci.pNext = NULL;
8892 ds_pool_ci.maxSets = 1;
8893 ds_pool_ci.poolSizeCount = 1;
8894 ds_pool_ci.pPoolSizes = &ds_type_count;
Mark Lobodzinski209b5292015-09-17 09:44:05 -06008895
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06008896 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008897 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06008898 ASSERT_VK_SUCCESS(err);
8899
Tony Barboureb254902015-07-15 12:50:33 -06008900 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008901 dsl_binding.binding = 0;
8902 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
8903 dsl_binding.descriptorCount = 1;
8904 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
8905 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06008906
Tony Barboureb254902015-07-15 12:50:33 -06008907 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008908 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
8909 ds_layout_ci.pNext = NULL;
8910 ds_layout_ci.bindingCount = 1;
8911 ds_layout_ci.pBindings = &dsl_binding;
Tony Barboureb254902015-07-15 12:50:33 -06008912
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06008913 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008914 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06008915 ASSERT_VK_SUCCESS(err);
8916
8917 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08008918 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08008919 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07008920 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06008921 alloc_info.descriptorPool = ds_pool;
8922 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008923 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06008924 ASSERT_VK_SUCCESS(err);
8925
Tony Barboureb254902015-07-15 12:50:33 -06008926 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008927 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
8928 pipeline_layout_ci.setLayoutCount = 1;
8929 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06008930
8931 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008932 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06008933 ASSERT_VK_SUCCESS(err);
8934
Tobin Ehlise68360f2015-10-01 11:15:13 -06008935 VkViewport vp = {}; // Just need dummy vp to point to
Karl Schultz6addd812016-02-02 17:17:23 -07008936 VkRect2D sc = {}; // dummy scissor to point to
Tobin Ehlise68360f2015-10-01 11:15:13 -06008937
8938 VkPipelineViewportStateCreateInfo vp_state_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008939 vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
8940 vp_state_ci.scissorCount = 1;
8941 vp_state_ci.pScissors = &sc;
8942 vp_state_ci.viewportCount = 1;
8943 vp_state_ci.pViewports = &vp;
Tobin Ehlise68360f2015-10-01 11:15:13 -06008944
Karl Schultzdfdb8d42016-03-08 10:30:21 -07008945 VkPipelineRasterizationStateCreateInfo rs_state_ci = {};
8946 rs_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
8947 rs_state_ci.polygonMode = VK_POLYGON_MODE_FILL;
8948 rs_state_ci.cullMode = VK_CULL_MODE_BACK_BIT;
8949 rs_state_ci.frontFace = VK_FRONT_FACE_COUNTER_CLOCKWISE;
8950 rs_state_ci.depthClampEnable = VK_FALSE;
8951 rs_state_ci.rasterizerDiscardEnable = VK_FALSE;
8952 rs_state_ci.depthBiasEnable = VK_FALSE;
8953
Tony Barboureb254902015-07-15 12:50:33 -06008954 VkGraphicsPipelineCreateInfo gp_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008955 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
8956 gp_ci.pViewportState = &vp_state_ci;
Karl Schultzdfdb8d42016-03-08 10:30:21 -07008957 gp_ci.pRasterizationState = &rs_state_ci;
Karl Schultz6addd812016-02-02 17:17:23 -07008958 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
8959 gp_ci.layout = pipeline_layout;
8960 gp_ci.renderPass = renderPass();
Tony Barboureb254902015-07-15 12:50:33 -06008961
8962 VkPipelineCacheCreateInfo pc_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008963 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
8964 pc_ci.initialDataSize = 0;
8965 pc_ci.pInitialData = 0;
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06008966
8967 VkPipeline pipeline;
Jon Ashburnc669cc62015-07-09 15:02:25 -06008968 VkPipelineCache pipelineCache;
8969
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008970 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Jon Ashburnc669cc62015-07-09 15:02:25 -06008971 ASSERT_VK_SUCCESS(err);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008972 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06008973
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008974 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06008975
Chia-I Wuf7458c52015-10-26 21:10:41 +08008976 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
8977 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
8978 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
8979 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06008980}
Tobin Ehlis912df022015-09-17 08:46:18 -06008981/*// TODO : This test should be good, but needs Tess support in compiler to run
8982TEST_F(VkLayerTest, InvalidPatchControlPoints)
8983{
8984 // Attempt to Create Gfx Pipeline w/o a VS
Tobin Ehlis912df022015-09-17 08:46:18 -06008985 VkResult err;
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06008986
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07008987 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Karl Schultz6addd812016-02-02 17:17:23 -07008988 "Invalid Pipeline CreateInfo State: VK_PRIMITIVE_TOPOLOGY_PATCH
8989primitive ");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06008990
Tobin Ehlis912df022015-09-17 08:46:18 -06008991 ASSERT_NO_FATAL_FAILURE(InitState());
8992 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlis912df022015-09-17 08:46:18 -06008993
Chia-I Wu1b99bb22015-10-27 19:25:11 +08008994 VkDescriptorPoolSize ds_type_count = {};
Tobin Ehlis912df022015-09-17 08:46:18 -06008995 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Chia-I Wud50a7d72015-10-26 20:48:51 +08008996 ds_type_count.descriptorCount = 1;
Tobin Ehlis912df022015-09-17 08:46:18 -06008997
8998 VkDescriptorPoolCreateInfo ds_pool_ci = {};
8999 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
9000 ds_pool_ci.pNext = NULL;
Chia-I Wu1b99bb22015-10-27 19:25:11 +08009001 ds_pool_ci.poolSizeCount = 1;
9002 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlis912df022015-09-17 08:46:18 -06009003
9004 VkDescriptorPool ds_pool;
Karl Schultz6addd812016-02-02 17:17:23 -07009005 err = vkCreateDescriptorPool(m_device->device(),
9006VK_DESCRIPTOR_POOL_USAGE_NON_FREE, 1, &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis912df022015-09-17 08:46:18 -06009007 ASSERT_VK_SUCCESS(err);
9008
9009 VkDescriptorSetLayoutBinding dsl_binding = {};
Chia-I Wud46e6ae2015-10-31 00:31:16 +08009010 dsl_binding.binding = 0;
Tobin Ehlis912df022015-09-17 08:46:18 -06009011 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Chia-I Wu02124482015-11-06 06:42:02 +08009012 dsl_binding.descriptorCount = 1;
Tobin Ehlis912df022015-09-17 08:46:18 -06009013 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
9014 dsl_binding.pImmutableSamplers = NULL;
9015
9016 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009017 ds_layout_ci.sType =
9018VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
Tobin Ehlis912df022015-09-17 08:46:18 -06009019 ds_layout_ci.pNext = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08009020 ds_layout_ci.bindingCount = 1;
Jon Ashburn6e23c1f2015-12-30 18:01:16 -07009021 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlis912df022015-09-17 08:46:18 -06009022
9023 VkDescriptorSetLayout ds_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07009024 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL,
9025&ds_layout);
Tobin Ehlis912df022015-09-17 08:46:18 -06009026 ASSERT_VK_SUCCESS(err);
9027
9028 VkDescriptorSet descriptorSet;
Karl Schultz6addd812016-02-02 17:17:23 -07009029 err = vkAllocateDescriptorSets(m_device->device(), ds_pool,
9030VK_DESCRIPTOR_SET_USAGE_NON_FREE, 1, &ds_layout, &descriptorSet);
Tobin Ehlis912df022015-09-17 08:46:18 -06009031 ASSERT_VK_SUCCESS(err);
9032
9033 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009034 pipeline_layout_ci.sType =
9035VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
Tobin Ehlis912df022015-09-17 08:46:18 -06009036 pipeline_layout_ci.pNext = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08009037 pipeline_layout_ci.setLayoutCount = 1;
Tobin Ehlis912df022015-09-17 08:46:18 -06009038 pipeline_layout_ci.pSetLayouts = &ds_layout;
9039
9040 VkPipelineLayout pipeline_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07009041 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL,
9042&pipeline_layout);
Tobin Ehlis912df022015-09-17 08:46:18 -06009043 ASSERT_VK_SUCCESS(err);
9044
9045 VkPipelineShaderStageCreateInfo shaderStages[3];
9046 memset(&shaderStages, 0, 3 * sizeof(VkPipelineShaderStageCreateInfo));
9047
Karl Schultz6addd812016-02-02 17:17:23 -07009048 VkShaderObj vs(m_device,bindStateVertShaderText,VK_SHADER_STAGE_VERTEX_BIT,
9049this);
Tobin Ehlis912df022015-09-17 08:46:18 -06009050 // Just using VS txt for Tess shaders as we don't care about functionality
Karl Schultz6addd812016-02-02 17:17:23 -07009051 VkShaderObj
9052tc(m_device,bindStateVertShaderText,VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT,
9053this);
9054 VkShaderObj
9055te(m_device,bindStateVertShaderText,VK_SHADER_STAGE_TESSELLATION_EVALUATION_BIT,
9056this);
Tobin Ehlis912df022015-09-17 08:46:18 -06009057
Karl Schultz6addd812016-02-02 17:17:23 -07009058 shaderStages[0].sType =
9059VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO;
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -06009060 shaderStages[0].stage = VK_SHADER_STAGE_VERTEX_BIT;
Tobin Ehlis912df022015-09-17 08:46:18 -06009061 shaderStages[0].shader = vs.handle();
Karl Schultz6addd812016-02-02 17:17:23 -07009062 shaderStages[1].sType =
9063VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO;
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -06009064 shaderStages[1].stage = VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT;
Tobin Ehlis912df022015-09-17 08:46:18 -06009065 shaderStages[1].shader = tc.handle();
Karl Schultz6addd812016-02-02 17:17:23 -07009066 shaderStages[2].sType =
9067VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO;
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -06009068 shaderStages[2].stage = VK_SHADER_STAGE_TESSELLATION_EVALUATION_BIT;
Tobin Ehlis912df022015-09-17 08:46:18 -06009069 shaderStages[2].shader = te.handle();
9070
9071 VkPipelineInputAssemblyStateCreateInfo iaCI = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009072 iaCI.sType =
9073VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
Chia-I Wu515eb8f2015-10-31 00:31:16 +08009074 iaCI.topology = VK_PRIMITIVE_TOPOLOGY_PATCH_LIST;
Tobin Ehlis912df022015-09-17 08:46:18 -06009075
9076 VkPipelineTessellationStateCreateInfo tsCI = {};
9077 tsCI.sType = VK_STRUCTURE_TYPE_PIPELINE_TESSELLATION_STATE_CREATE_INFO;
9078 tsCI.patchControlPoints = 0; // This will cause an error
9079
9080 VkGraphicsPipelineCreateInfo gp_ci = {};
9081 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
9082 gp_ci.pNext = NULL;
9083 gp_ci.stageCount = 3;
9084 gp_ci.pStages = shaderStages;
9085 gp_ci.pVertexInputState = NULL;
9086 gp_ci.pInputAssemblyState = &iaCI;
9087 gp_ci.pTessellationState = &tsCI;
9088 gp_ci.pViewportState = NULL;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009089 gp_ci.pRasterizationState = NULL;
Tobin Ehlis912df022015-09-17 08:46:18 -06009090 gp_ci.pMultisampleState = NULL;
9091 gp_ci.pDepthStencilState = NULL;
9092 gp_ci.pColorBlendState = NULL;
9093 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
9094 gp_ci.layout = pipeline_layout;
9095 gp_ci.renderPass = renderPass();
9096
9097 VkPipelineCacheCreateInfo pc_ci = {};
9098 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
9099 pc_ci.pNext = NULL;
9100 pc_ci.initialSize = 0;
9101 pc_ci.initialData = 0;
9102 pc_ci.maxSize = 0;
9103
9104 VkPipeline pipeline;
9105 VkPipelineCache pipelineCache;
9106
Karl Schultz6addd812016-02-02 17:17:23 -07009107 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL,
9108&pipelineCache);
Tobin Ehlis912df022015-09-17 08:46:18 -06009109 ASSERT_VK_SUCCESS(err);
Karl Schultz6addd812016-02-02 17:17:23 -07009110 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1,
9111&gp_ci, NULL, &pipeline);
Tobin Ehlis912df022015-09-17 08:46:18 -06009112
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009113 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06009114
Chia-I Wuf7458c52015-10-26 21:10:41 +08009115 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
9116 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
9117 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
9118 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis912df022015-09-17 08:46:18 -06009119}
9120*/
Tobin Ehlise68360f2015-10-01 11:15:13 -06009121// Set scissor and viewport counts to different numbers
Karl Schultz6addd812016-02-02 17:17:23 -07009122TEST_F(VkLayerTest, PSOViewportScissorCountMismatch) {
Karl Schultz6addd812016-02-02 17:17:23 -07009123 VkResult err;
Tobin Ehlise68360f2015-10-01 11:15:13 -06009124
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009125 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
9126 "Gfx Pipeline viewport count (1) must match scissor count (0).");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06009127
Tobin Ehlise68360f2015-10-01 11:15:13 -06009128 ASSERT_NO_FATAL_FAILURE(InitState());
9129 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlise68360f2015-10-01 11:15:13 -06009130
Chia-I Wu1b99bb22015-10-27 19:25:11 +08009131 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009132 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
9133 ds_type_count.descriptorCount = 1;
Tobin Ehlise68360f2015-10-01 11:15:13 -06009134
9135 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009136 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
9137 ds_pool_ci.maxSets = 1;
9138 ds_pool_ci.poolSizeCount = 1;
9139 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlise68360f2015-10-01 11:15:13 -06009140
9141 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009142 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlise68360f2015-10-01 11:15:13 -06009143 ASSERT_VK_SUCCESS(err);
9144
9145 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009146 dsl_binding.binding = 0;
9147 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
9148 dsl_binding.descriptorCount = 1;
9149 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
Tobin Ehlise68360f2015-10-01 11:15:13 -06009150
9151 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009152 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
9153 ds_layout_ci.bindingCount = 1;
9154 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlise68360f2015-10-01 11:15:13 -06009155
9156 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009157 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlise68360f2015-10-01 11:15:13 -06009158 ASSERT_VK_SUCCESS(err);
9159
9160 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009161 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08009162 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07009163 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06009164 alloc_info.descriptorPool = ds_pool;
9165 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009166 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlise68360f2015-10-01 11:15:13 -06009167 ASSERT_VK_SUCCESS(err);
9168
9169 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009170 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
9171 pipeline_layout_ci.setLayoutCount = 1;
9172 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlise68360f2015-10-01 11:15:13 -06009173
9174 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009175 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlise68360f2015-10-01 11:15:13 -06009176 ASSERT_VK_SUCCESS(err);
9177
9178 VkViewport vp = {}; // Just need dummy vp to point to
9179
9180 VkPipelineViewportStateCreateInfo vp_state_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009181 vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
9182 vp_state_ci.scissorCount = 0;
9183 vp_state_ci.viewportCount = 1; // Count mismatch should cause error
9184 vp_state_ci.pViewports = &vp;
Tobin Ehlise68360f2015-10-01 11:15:13 -06009185
Karl Schultzdfdb8d42016-03-08 10:30:21 -07009186 VkPipelineRasterizationStateCreateInfo rs_state_ci = {};
9187 rs_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
9188 rs_state_ci.polygonMode = VK_POLYGON_MODE_FILL;
9189 rs_state_ci.cullMode = VK_CULL_MODE_BACK_BIT;
9190 rs_state_ci.frontFace = VK_FRONT_FACE_COUNTER_CLOCKWISE;
9191 rs_state_ci.depthClampEnable = VK_FALSE;
9192 rs_state_ci.rasterizerDiscardEnable = VK_FALSE;
9193 rs_state_ci.depthBiasEnable = VK_FALSE;
9194
Cody Northropeb3a6c12015-10-05 14:44:45 -06009195 VkPipelineShaderStageCreateInfo shaderStages[2];
Karl Schultz6addd812016-02-02 17:17:23 -07009196 memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo));
Tobin Ehlise68360f2015-10-01 11:15:13 -06009197
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009198 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
9199 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this); // We shouldn't need a fragment shader
9200 // but add it to be able to run on more devices
Chia-I Wu28e06912015-10-31 00:31:16 +08009201 shaderStages[0] = vs.GetStageCreateInfo();
9202 shaderStages[1] = fs.GetStageCreateInfo();
Tobin Ehlise68360f2015-10-01 11:15:13 -06009203
9204 VkGraphicsPipelineCreateInfo gp_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009205 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
9206 gp_ci.stageCount = 2;
9207 gp_ci.pStages = shaderStages;
9208 gp_ci.pViewportState = &vp_state_ci;
Karl Schultzdfdb8d42016-03-08 10:30:21 -07009209 gp_ci.pRasterizationState = &rs_state_ci;
Karl Schultz6addd812016-02-02 17:17:23 -07009210 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
9211 gp_ci.layout = pipeline_layout;
9212 gp_ci.renderPass = renderPass();
Tobin Ehlise68360f2015-10-01 11:15:13 -06009213
9214 VkPipelineCacheCreateInfo pc_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009215 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
Tobin Ehlise68360f2015-10-01 11:15:13 -06009216
9217 VkPipeline pipeline;
9218 VkPipelineCache pipelineCache;
9219
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009220 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Tobin Ehlise68360f2015-10-01 11:15:13 -06009221 ASSERT_VK_SUCCESS(err);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009222 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Tobin Ehlise68360f2015-10-01 11:15:13 -06009223
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009224 m_errorMonitor->VerifyFound();
Tobin Ehlise68360f2015-10-01 11:15:13 -06009225
Chia-I Wuf7458c52015-10-26 21:10:41 +08009226 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
9227 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
9228 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
9229 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlise68360f2015-10-01 11:15:13 -06009230}
Karl Schultz6addd812016-02-02 17:17:23 -07009231// Don't set viewport state in PSO. This is an error b/c we always need this
9232// state
Tobin Ehlisd332f282015-10-02 11:00:56 -06009233// for the counts even if the data is going to be set dynamically.
Karl Schultz6addd812016-02-02 17:17:23 -07009234TEST_F(VkLayerTest, PSOViewportStateNotSet) {
Tobin Ehlise68360f2015-10-01 11:15:13 -06009235 // Attempt to Create Gfx Pipeline w/o a VS
Karl Schultz6addd812016-02-02 17:17:23 -07009236 VkResult err;
Tobin Ehlise68360f2015-10-01 11:15:13 -06009237
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009238 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Gfx Pipeline pViewportState is null. Even if ");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06009239
Tobin Ehlise68360f2015-10-01 11:15:13 -06009240 ASSERT_NO_FATAL_FAILURE(InitState());
9241 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlise68360f2015-10-01 11:15:13 -06009242
Chia-I Wu1b99bb22015-10-27 19:25:11 +08009243 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009244 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
9245 ds_type_count.descriptorCount = 1;
Tobin Ehlise68360f2015-10-01 11:15:13 -06009246
9247 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009248 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
9249 ds_pool_ci.maxSets = 1;
9250 ds_pool_ci.poolSizeCount = 1;
9251 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlise68360f2015-10-01 11:15:13 -06009252
9253 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009254 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlise68360f2015-10-01 11:15:13 -06009255 ASSERT_VK_SUCCESS(err);
9256
9257 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009258 dsl_binding.binding = 0;
9259 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
9260 dsl_binding.descriptorCount = 1;
9261 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
Tobin Ehlise68360f2015-10-01 11:15:13 -06009262
9263 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009264 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
9265 ds_layout_ci.bindingCount = 1;
9266 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlise68360f2015-10-01 11:15:13 -06009267
9268 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009269 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlise68360f2015-10-01 11:15:13 -06009270 ASSERT_VK_SUCCESS(err);
9271
9272 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009273 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08009274 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07009275 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06009276 alloc_info.descriptorPool = ds_pool;
9277 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009278 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlise68360f2015-10-01 11:15:13 -06009279 ASSERT_VK_SUCCESS(err);
9280
9281 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009282 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
9283 pipeline_layout_ci.setLayoutCount = 1;
9284 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlise68360f2015-10-01 11:15:13 -06009285
9286 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009287 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlise68360f2015-10-01 11:15:13 -06009288 ASSERT_VK_SUCCESS(err);
9289
9290 VkDynamicState sc_state = VK_DYNAMIC_STATE_SCISSOR;
9291 // Set scissor as dynamic to avoid second error
9292 VkPipelineDynamicStateCreateInfo dyn_state_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009293 dyn_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_DYNAMIC_STATE_CREATE_INFO;
9294 dyn_state_ci.dynamicStateCount = 1;
9295 dyn_state_ci.pDynamicStates = &sc_state;
Tobin Ehlise68360f2015-10-01 11:15:13 -06009296
Cody Northropeb3a6c12015-10-05 14:44:45 -06009297 VkPipelineShaderStageCreateInfo shaderStages[2];
Karl Schultz6addd812016-02-02 17:17:23 -07009298 memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo));
Tobin Ehlise68360f2015-10-01 11:15:13 -06009299
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009300 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
9301 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this); // We shouldn't need a fragment shader
9302 // but add it to be able to run on more devices
Chia-I Wu28e06912015-10-31 00:31:16 +08009303 shaderStages[0] = vs.GetStageCreateInfo();
9304 shaderStages[1] = fs.GetStageCreateInfo();
Tobin Ehlise68360f2015-10-01 11:15:13 -06009305
Karl Schultzdfdb8d42016-03-08 10:30:21 -07009306 VkPipelineRasterizationStateCreateInfo rs_state_ci = {};
9307 rs_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
9308 rs_state_ci.polygonMode = VK_POLYGON_MODE_FILL;
9309 rs_state_ci.cullMode = VK_CULL_MODE_BACK_BIT;
9310 rs_state_ci.frontFace = VK_FRONT_FACE_COUNTER_CLOCKWISE;
9311 rs_state_ci.depthClampEnable = VK_FALSE;
9312 rs_state_ci.rasterizerDiscardEnable = VK_FALSE;
9313 rs_state_ci.depthBiasEnable = VK_FALSE;
9314
Tobin Ehlise68360f2015-10-01 11:15:13 -06009315 VkGraphicsPipelineCreateInfo gp_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009316 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
9317 gp_ci.stageCount = 2;
9318 gp_ci.pStages = shaderStages;
Karl Schultzdfdb8d42016-03-08 10:30:21 -07009319 gp_ci.pRasterizationState = &rs_state_ci;
Karl Schultz6addd812016-02-02 17:17:23 -07009320 gp_ci.pViewportState = NULL; // Not setting VP state w/o dynamic vp state
9321 // should cause validation error
9322 gp_ci.pDynamicState = &dyn_state_ci;
9323 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
9324 gp_ci.layout = pipeline_layout;
9325 gp_ci.renderPass = renderPass();
Tobin Ehlise68360f2015-10-01 11:15:13 -06009326
9327 VkPipelineCacheCreateInfo pc_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009328 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
Tobin Ehlise68360f2015-10-01 11:15:13 -06009329
9330 VkPipeline pipeline;
9331 VkPipelineCache pipelineCache;
9332
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009333 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Tobin Ehlise68360f2015-10-01 11:15:13 -06009334 ASSERT_VK_SUCCESS(err);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009335 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Tobin Ehlise68360f2015-10-01 11:15:13 -06009336
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009337 m_errorMonitor->VerifyFound();
Tobin Ehlise68360f2015-10-01 11:15:13 -06009338
Chia-I Wuf7458c52015-10-26 21:10:41 +08009339 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
9340 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
9341 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
9342 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlise68360f2015-10-01 11:15:13 -06009343}
9344// Create PSO w/o non-zero viewportCount but no viewport data
Karl Schultz6addd812016-02-02 17:17:23 -07009345// Then run second test where dynamic scissor count doesn't match PSO scissor
9346// count
9347TEST_F(VkLayerTest, PSOViewportCountWithoutDataAndDynScissorMismatch) {
9348 VkResult err;
Tobin Ehlise68360f2015-10-01 11:15:13 -06009349
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009350 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
9351 "Gfx Pipeline viewportCount is 1, but pViewports is NULL. ");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06009352
Tobin Ehlise68360f2015-10-01 11:15:13 -06009353 ASSERT_NO_FATAL_FAILURE(InitState());
Chris Forbesc08a6ca2016-07-28 14:14:07 +12009354
9355 if (!m_device->phy().features().multiViewport) {
9356 printf("Device does not support multiple viewports/scissors; skipped.\n");
9357 return;
9358 }
9359
Tobin Ehlise68360f2015-10-01 11:15:13 -06009360 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlise68360f2015-10-01 11:15:13 -06009361
Chia-I Wu1b99bb22015-10-27 19:25:11 +08009362 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009363 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
9364 ds_type_count.descriptorCount = 1;
Tobin Ehlise68360f2015-10-01 11:15:13 -06009365
9366 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009367 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
9368 ds_pool_ci.maxSets = 1;
9369 ds_pool_ci.poolSizeCount = 1;
9370 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlise68360f2015-10-01 11:15:13 -06009371
9372 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009373 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlise68360f2015-10-01 11:15:13 -06009374 ASSERT_VK_SUCCESS(err);
9375
9376 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009377 dsl_binding.binding = 0;
9378 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
9379 dsl_binding.descriptorCount = 1;
9380 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
Tobin Ehlise68360f2015-10-01 11:15:13 -06009381
9382 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009383 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
9384 ds_layout_ci.bindingCount = 1;
9385 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlise68360f2015-10-01 11:15:13 -06009386
9387 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009388 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlise68360f2015-10-01 11:15:13 -06009389 ASSERT_VK_SUCCESS(err);
9390
9391 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009392 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08009393 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07009394 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06009395 alloc_info.descriptorPool = ds_pool;
9396 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009397 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlise68360f2015-10-01 11:15:13 -06009398 ASSERT_VK_SUCCESS(err);
9399
9400 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009401 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
9402 pipeline_layout_ci.setLayoutCount = 1;
9403 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlise68360f2015-10-01 11:15:13 -06009404
9405 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009406 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlise68360f2015-10-01 11:15:13 -06009407 ASSERT_VK_SUCCESS(err);
9408
9409 VkPipelineViewportStateCreateInfo vp_state_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009410 vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
9411 vp_state_ci.viewportCount = 1;
9412 vp_state_ci.pViewports = NULL; // Null vp w/ count of 1 should cause error
9413 vp_state_ci.scissorCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009414 vp_state_ci.pScissors = NULL; // Scissor is dynamic (below) so this won't cause error
Tobin Ehlise68360f2015-10-01 11:15:13 -06009415
9416 VkDynamicState sc_state = VK_DYNAMIC_STATE_SCISSOR;
9417 // Set scissor as dynamic to avoid that error
9418 VkPipelineDynamicStateCreateInfo dyn_state_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009419 dyn_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_DYNAMIC_STATE_CREATE_INFO;
9420 dyn_state_ci.dynamicStateCount = 1;
9421 dyn_state_ci.pDynamicStates = &sc_state;
Tobin Ehlise68360f2015-10-01 11:15:13 -06009422
Cody Northropeb3a6c12015-10-05 14:44:45 -06009423 VkPipelineShaderStageCreateInfo shaderStages[2];
Karl Schultz6addd812016-02-02 17:17:23 -07009424 memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo));
Tobin Ehlise68360f2015-10-01 11:15:13 -06009425
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009426 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
9427 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this); // We shouldn't need a fragment shader
9428 // but add it to be able to run on more devices
Chia-I Wu28e06912015-10-31 00:31:16 +08009429 shaderStages[0] = vs.GetStageCreateInfo();
9430 shaderStages[1] = fs.GetStageCreateInfo();
Tobin Ehlise68360f2015-10-01 11:15:13 -06009431
Cody Northropf6622dc2015-10-06 10:33:21 -06009432 VkPipelineVertexInputStateCreateInfo vi_ci = {};
9433 vi_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
9434 vi_ci.pNext = nullptr;
Chia-I Wud50a7d72015-10-26 20:48:51 +08009435 vi_ci.vertexBindingDescriptionCount = 0;
Cody Northropf6622dc2015-10-06 10:33:21 -06009436 vi_ci.pVertexBindingDescriptions = nullptr;
Chia-I Wud50a7d72015-10-26 20:48:51 +08009437 vi_ci.vertexAttributeDescriptionCount = 0;
Cody Northropf6622dc2015-10-06 10:33:21 -06009438 vi_ci.pVertexAttributeDescriptions = nullptr;
9439
9440 VkPipelineInputAssemblyStateCreateInfo ia_ci = {};
9441 ia_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
9442 ia_ci.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP;
9443
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009444 VkPipelineRasterizationStateCreateInfo rs_ci = {};
Chia-I Wu1b99bb22015-10-27 19:25:11 +08009445 rs_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
Cody Northropf6622dc2015-10-06 10:33:21 -06009446 rs_ci.pNext = nullptr;
9447
Mark Youngc89c6312016-03-31 16:03:20 -06009448 VkPipelineColorBlendAttachmentState att = {};
9449 att.blendEnable = VK_FALSE;
9450 att.colorWriteMask = 0xf;
9451
Cody Northropf6622dc2015-10-06 10:33:21 -06009452 VkPipelineColorBlendStateCreateInfo cb_ci = {};
9453 cb_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO;
9454 cb_ci.pNext = nullptr;
Mark Youngc89c6312016-03-31 16:03:20 -06009455 cb_ci.attachmentCount = 1;
9456 cb_ci.pAttachments = &att;
Cody Northropf6622dc2015-10-06 10:33:21 -06009457
Tobin Ehlise68360f2015-10-01 11:15:13 -06009458 VkGraphicsPipelineCreateInfo gp_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009459 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
9460 gp_ci.stageCount = 2;
9461 gp_ci.pStages = shaderStages;
9462 gp_ci.pVertexInputState = &vi_ci;
9463 gp_ci.pInputAssemblyState = &ia_ci;
9464 gp_ci.pViewportState = &vp_state_ci;
9465 gp_ci.pRasterizationState = &rs_ci;
9466 gp_ci.pColorBlendState = &cb_ci;
9467 gp_ci.pDynamicState = &dyn_state_ci;
9468 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
9469 gp_ci.layout = pipeline_layout;
9470 gp_ci.renderPass = renderPass();
Tobin Ehlise68360f2015-10-01 11:15:13 -06009471
9472 VkPipelineCacheCreateInfo pc_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009473 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
Tobin Ehlise68360f2015-10-01 11:15:13 -06009474
9475 VkPipeline pipeline;
9476 VkPipelineCache pipelineCache;
9477
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009478 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Tobin Ehlise68360f2015-10-01 11:15:13 -06009479 ASSERT_VK_SUCCESS(err);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009480 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Tobin Ehlise68360f2015-10-01 11:15:13 -06009481
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009482 m_errorMonitor->VerifyFound();
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06009483
Tobin Ehlisd332f282015-10-02 11:00:56 -06009484 // Now hit second fail case where we set scissor w/ different count than PSO
Karl Schultz6addd812016-02-02 17:17:23 -07009485 // First need to successfully create the PSO from above by setting
9486 // pViewports
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009487 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Dynamic scissor(s) 0 are used by PSO, ");
Karl Schultz6addd812016-02-02 17:17:23 -07009488
9489 VkViewport vp = {}; // Just need dummy vp to point to
9490 vp_state_ci.pViewports = &vp;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009491 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Karl Schultz6addd812016-02-02 17:17:23 -07009492 ASSERT_VK_SUCCESS(err);
9493 BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009494 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline);
Chris Forbesc08a6ca2016-07-28 14:14:07 +12009495 VkRect2D scissors[1] = {}; // don't care about data
Karl Schultz6addd812016-02-02 17:17:23 -07009496 // Count of 2 doesn't match PSO count of 1
Chris Forbesc08a6ca2016-07-28 14:14:07 +12009497 vkCmdSetScissor(m_commandBuffer->GetBufferHandle(), 1, 1, scissors);
Karl Schultz6addd812016-02-02 17:17:23 -07009498 Draw(1, 0, 0, 0);
9499
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009500 m_errorMonitor->VerifyFound();
Karl Schultz6addd812016-02-02 17:17:23 -07009501
9502 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
9503 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
9504 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
9505 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tony Barbourdf4c0042016-06-01 15:55:43 -06009506 vkDestroyPipeline(m_device->device(), pipeline, NULL);
Karl Schultz6addd812016-02-02 17:17:23 -07009507}
9508// Create PSO w/o non-zero scissorCount but no scissor data
9509// Then run second test where dynamic viewportCount doesn't match PSO
9510// viewportCount
9511TEST_F(VkLayerTest, PSOScissorCountWithoutDataAndDynViewportMismatch) {
9512 VkResult err;
9513
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009514 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 -07009515
9516 ASSERT_NO_FATAL_FAILURE(InitState());
Chris Forbesc08a6ca2016-07-28 14:14:07 +12009517
9518 if (!m_device->phy().features().multiViewport) {
9519 printf("Device does not support multiple viewports/scissors; skipped.\n");
9520 return;
9521 }
9522
Karl Schultz6addd812016-02-02 17:17:23 -07009523 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
9524
9525 VkDescriptorPoolSize ds_type_count = {};
9526 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
9527 ds_type_count.descriptorCount = 1;
9528
9529 VkDescriptorPoolCreateInfo ds_pool_ci = {};
9530 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
9531 ds_pool_ci.maxSets = 1;
9532 ds_pool_ci.poolSizeCount = 1;
9533 ds_pool_ci.pPoolSizes = &ds_type_count;
9534
9535 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009536 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Karl Schultz6addd812016-02-02 17:17:23 -07009537 ASSERT_VK_SUCCESS(err);
9538
9539 VkDescriptorSetLayoutBinding dsl_binding = {};
9540 dsl_binding.binding = 0;
9541 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
9542 dsl_binding.descriptorCount = 1;
9543 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
9544
9545 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
9546 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
9547 ds_layout_ci.bindingCount = 1;
9548 ds_layout_ci.pBindings = &dsl_binding;
9549
9550 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009551 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Karl Schultz6addd812016-02-02 17:17:23 -07009552 ASSERT_VK_SUCCESS(err);
9553
9554 VkDescriptorSet descriptorSet;
9555 VkDescriptorSetAllocateInfo alloc_info = {};
9556 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
9557 alloc_info.descriptorSetCount = 1;
9558 alloc_info.descriptorPool = ds_pool;
9559 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009560 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Karl Schultz6addd812016-02-02 17:17:23 -07009561 ASSERT_VK_SUCCESS(err);
9562
9563 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
9564 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
9565 pipeline_layout_ci.setLayoutCount = 1;
9566 pipeline_layout_ci.pSetLayouts = &ds_layout;
9567
9568 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009569 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Karl Schultz6addd812016-02-02 17:17:23 -07009570 ASSERT_VK_SUCCESS(err);
9571
9572 VkPipelineViewportStateCreateInfo vp_state_ci = {};
9573 vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
9574 vp_state_ci.scissorCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009575 vp_state_ci.pScissors = NULL; // Null scissor w/ count of 1 should cause error
Karl Schultz6addd812016-02-02 17:17:23 -07009576 vp_state_ci.viewportCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009577 vp_state_ci.pViewports = NULL; // vp is dynamic (below) so this won't cause error
Karl Schultz6addd812016-02-02 17:17:23 -07009578
9579 VkDynamicState vp_state = VK_DYNAMIC_STATE_VIEWPORT;
9580 // Set scissor as dynamic to avoid that error
9581 VkPipelineDynamicStateCreateInfo dyn_state_ci = {};
9582 dyn_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_DYNAMIC_STATE_CREATE_INFO;
9583 dyn_state_ci.dynamicStateCount = 1;
9584 dyn_state_ci.pDynamicStates = &vp_state;
9585
9586 VkPipelineShaderStageCreateInfo shaderStages[2];
9587 memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo));
9588
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009589 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
9590 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this); // We shouldn't need a fragment shader
9591 // but add it to be able to run on more devices
Karl Schultz6addd812016-02-02 17:17:23 -07009592 shaderStages[0] = vs.GetStageCreateInfo();
9593 shaderStages[1] = fs.GetStageCreateInfo();
9594
9595 VkPipelineVertexInputStateCreateInfo vi_ci = {};
9596 vi_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
9597 vi_ci.pNext = nullptr;
9598 vi_ci.vertexBindingDescriptionCount = 0;
9599 vi_ci.pVertexBindingDescriptions = nullptr;
9600 vi_ci.vertexAttributeDescriptionCount = 0;
9601 vi_ci.pVertexAttributeDescriptions = nullptr;
9602
9603 VkPipelineInputAssemblyStateCreateInfo ia_ci = {};
9604 ia_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
9605 ia_ci.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP;
9606
9607 VkPipelineRasterizationStateCreateInfo rs_ci = {};
9608 rs_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
9609 rs_ci.pNext = nullptr;
9610
Mark Youngc89c6312016-03-31 16:03:20 -06009611 VkPipelineColorBlendAttachmentState att = {};
9612 att.blendEnable = VK_FALSE;
9613 att.colorWriteMask = 0xf;
9614
Karl Schultz6addd812016-02-02 17:17:23 -07009615 VkPipelineColorBlendStateCreateInfo cb_ci = {};
9616 cb_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO;
9617 cb_ci.pNext = nullptr;
Mark Youngc89c6312016-03-31 16:03:20 -06009618 cb_ci.attachmentCount = 1;
9619 cb_ci.pAttachments = &att;
Karl Schultz6addd812016-02-02 17:17:23 -07009620
9621 VkGraphicsPipelineCreateInfo gp_ci = {};
9622 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
9623 gp_ci.stageCount = 2;
9624 gp_ci.pStages = shaderStages;
9625 gp_ci.pVertexInputState = &vi_ci;
9626 gp_ci.pInputAssemblyState = &ia_ci;
9627 gp_ci.pViewportState = &vp_state_ci;
9628 gp_ci.pRasterizationState = &rs_ci;
9629 gp_ci.pColorBlendState = &cb_ci;
9630 gp_ci.pDynamicState = &dyn_state_ci;
9631 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
9632 gp_ci.layout = pipeline_layout;
9633 gp_ci.renderPass = renderPass();
9634
9635 VkPipelineCacheCreateInfo pc_ci = {};
9636 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
9637
9638 VkPipeline pipeline;
9639 VkPipelineCache pipelineCache;
9640
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009641 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Karl Schultz6addd812016-02-02 17:17:23 -07009642 ASSERT_VK_SUCCESS(err);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009643 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Karl Schultz6addd812016-02-02 17:17:23 -07009644
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009645 m_errorMonitor->VerifyFound();
Karl Schultz6addd812016-02-02 17:17:23 -07009646
9647 // Now hit second fail case where we set scissor w/ different count than PSO
9648 // First need to successfully create the PSO from above by setting
9649 // pViewports
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009650 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Dynamic viewport(s) 0 are used by PSO, ");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06009651
Tobin Ehlisd332f282015-10-02 11:00:56 -06009652 VkRect2D sc = {}; // Just need dummy vp to point to
9653 vp_state_ci.pScissors = &sc;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009654 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Tobin Ehlisd332f282015-10-02 11:00:56 -06009655 ASSERT_VK_SUCCESS(err);
9656 BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009657 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline);
Chris Forbesc08a6ca2016-07-28 14:14:07 +12009658 VkViewport viewports[1] = {}; // don't care about data
Tobin Ehlisd332f282015-10-02 11:00:56 -06009659 // Count of 2 doesn't match PSO count of 1
Chris Forbesc08a6ca2016-07-28 14:14:07 +12009660 vkCmdSetViewport(m_commandBuffer->GetBufferHandle(), 1, 1, viewports);
Tobin Ehlisd332f282015-10-02 11:00:56 -06009661 Draw(1, 0, 0, 0);
9662
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009663 m_errorMonitor->VerifyFound();
Tobin Ehlise68360f2015-10-01 11:15:13 -06009664
Chia-I Wuf7458c52015-10-26 21:10:41 +08009665 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
9666 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
9667 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
9668 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tony Barbourdf4c0042016-06-01 15:55:43 -06009669 vkDestroyPipeline(m_device->device(), pipeline, NULL);
Tobin Ehlise68360f2015-10-01 11:15:13 -06009670}
9671
Mark Young7394fdd2016-03-31 14:56:43 -06009672TEST_F(VkLayerTest, PSOLineWidthInvalid) {
9673 VkResult err;
9674
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009675 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Attempt to set lineWidth to -1");
Mark Young7394fdd2016-03-31 14:56:43 -06009676
9677 ASSERT_NO_FATAL_FAILURE(InitState());
9678 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
9679
9680 VkDescriptorPoolSize ds_type_count = {};
9681 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
9682 ds_type_count.descriptorCount = 1;
9683
9684 VkDescriptorPoolCreateInfo ds_pool_ci = {};
9685 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
9686 ds_pool_ci.maxSets = 1;
9687 ds_pool_ci.poolSizeCount = 1;
9688 ds_pool_ci.pPoolSizes = &ds_type_count;
9689
9690 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009691 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Mark Young7394fdd2016-03-31 14:56:43 -06009692 ASSERT_VK_SUCCESS(err);
9693
9694 VkDescriptorSetLayoutBinding dsl_binding = {};
9695 dsl_binding.binding = 0;
9696 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
9697 dsl_binding.descriptorCount = 1;
9698 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
9699
9700 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
9701 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
9702 ds_layout_ci.bindingCount = 1;
9703 ds_layout_ci.pBindings = &dsl_binding;
9704
9705 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009706 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Mark Young7394fdd2016-03-31 14:56:43 -06009707 ASSERT_VK_SUCCESS(err);
9708
9709 VkDescriptorSet descriptorSet;
9710 VkDescriptorSetAllocateInfo alloc_info = {};
9711 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
9712 alloc_info.descriptorSetCount = 1;
9713 alloc_info.descriptorPool = ds_pool;
9714 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009715 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Mark Young7394fdd2016-03-31 14:56:43 -06009716 ASSERT_VK_SUCCESS(err);
9717
9718 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
9719 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
9720 pipeline_layout_ci.setLayoutCount = 1;
9721 pipeline_layout_ci.pSetLayouts = &ds_layout;
9722
9723 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009724 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Mark Young7394fdd2016-03-31 14:56:43 -06009725 ASSERT_VK_SUCCESS(err);
9726
9727 VkPipelineViewportStateCreateInfo vp_state_ci = {};
9728 vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
9729 vp_state_ci.scissorCount = 1;
9730 vp_state_ci.pScissors = NULL;
9731 vp_state_ci.viewportCount = 1;
9732 vp_state_ci.pViewports = NULL;
9733
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009734 VkDynamicState dynamic_states[3] = {VK_DYNAMIC_STATE_VIEWPORT, VK_DYNAMIC_STATE_SCISSOR, VK_DYNAMIC_STATE_LINE_WIDTH};
Mark Young7394fdd2016-03-31 14:56:43 -06009735 // Set scissor as dynamic to avoid that error
9736 VkPipelineDynamicStateCreateInfo dyn_state_ci = {};
9737 dyn_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_DYNAMIC_STATE_CREATE_INFO;
9738 dyn_state_ci.dynamicStateCount = 2;
9739 dyn_state_ci.pDynamicStates = dynamic_states;
9740
9741 VkPipelineShaderStageCreateInfo shaderStages[2];
9742 memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo));
9743
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009744 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
9745 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT,
Mark Young7394fdd2016-03-31 14:56:43 -06009746 this); // TODO - We shouldn't need a fragment shader
9747 // but add it to be able to run on more devices
9748 shaderStages[0] = vs.GetStageCreateInfo();
9749 shaderStages[1] = fs.GetStageCreateInfo();
9750
9751 VkPipelineVertexInputStateCreateInfo vi_ci = {};
9752 vi_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
9753 vi_ci.pNext = nullptr;
9754 vi_ci.vertexBindingDescriptionCount = 0;
9755 vi_ci.pVertexBindingDescriptions = nullptr;
9756 vi_ci.vertexAttributeDescriptionCount = 0;
9757 vi_ci.pVertexAttributeDescriptions = nullptr;
9758
9759 VkPipelineInputAssemblyStateCreateInfo ia_ci = {};
9760 ia_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
9761 ia_ci.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP;
9762
9763 VkPipelineRasterizationStateCreateInfo rs_ci = {};
9764 rs_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
9765 rs_ci.pNext = nullptr;
9766
Mark Young47107952016-05-02 15:59:55 -06009767 // Check too low (line width of -1.0f).
9768 rs_ci.lineWidth = -1.0f;
Mark Young7394fdd2016-03-31 14:56:43 -06009769
9770 VkPipelineColorBlendAttachmentState att = {};
9771 att.blendEnable = VK_FALSE;
9772 att.colorWriteMask = 0xf;
9773
9774 VkPipelineColorBlendStateCreateInfo cb_ci = {};
9775 cb_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO;
9776 cb_ci.pNext = nullptr;
9777 cb_ci.attachmentCount = 1;
9778 cb_ci.pAttachments = &att;
9779
9780 VkGraphicsPipelineCreateInfo gp_ci = {};
9781 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
9782 gp_ci.stageCount = 2;
9783 gp_ci.pStages = shaderStages;
9784 gp_ci.pVertexInputState = &vi_ci;
9785 gp_ci.pInputAssemblyState = &ia_ci;
9786 gp_ci.pViewportState = &vp_state_ci;
9787 gp_ci.pRasterizationState = &rs_ci;
9788 gp_ci.pColorBlendState = &cb_ci;
9789 gp_ci.pDynamicState = &dyn_state_ci;
9790 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
9791 gp_ci.layout = pipeline_layout;
9792 gp_ci.renderPass = renderPass();
9793
9794 VkPipelineCacheCreateInfo pc_ci = {};
9795 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
9796
9797 VkPipeline pipeline;
9798 VkPipelineCache pipelineCache;
9799
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009800 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Mark Young7394fdd2016-03-31 14:56:43 -06009801 ASSERT_VK_SUCCESS(err);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009802 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Mark Young7394fdd2016-03-31 14:56:43 -06009803
9804 m_errorMonitor->VerifyFound();
Tony Barbourdf4c0042016-06-01 15:55:43 -06009805 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
Mark Young7394fdd2016-03-31 14:56:43 -06009806
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009807 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Attempt to set lineWidth to 65536");
Mark Young7394fdd2016-03-31 14:56:43 -06009808
9809 // Check too high (line width of 65536.0f).
9810 rs_ci.lineWidth = 65536.0f;
9811
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009812 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Mark Young7394fdd2016-03-31 14:56:43 -06009813 ASSERT_VK_SUCCESS(err);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009814 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Mark Young7394fdd2016-03-31 14:56:43 -06009815
9816 m_errorMonitor->VerifyFound();
Tony Barbourdf4c0042016-06-01 15:55:43 -06009817 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
Mark Young7394fdd2016-03-31 14:56:43 -06009818
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009819 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Attempt to set lineWidth to -1");
Mark Young7394fdd2016-03-31 14:56:43 -06009820
9821 dyn_state_ci.dynamicStateCount = 3;
9822
9823 rs_ci.lineWidth = 1.0f;
9824
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009825 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Mark Young7394fdd2016-03-31 14:56:43 -06009826 ASSERT_VK_SUCCESS(err);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009827 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Mark Young7394fdd2016-03-31 14:56:43 -06009828 BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009829 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline);
Mark Young7394fdd2016-03-31 14:56:43 -06009830
9831 // Check too low with dynamic setting.
Mark Young47107952016-05-02 15:59:55 -06009832 vkCmdSetLineWidth(m_commandBuffer->GetBufferHandle(), -1.0f);
Mark Young7394fdd2016-03-31 14:56:43 -06009833 m_errorMonitor->VerifyFound();
9834
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009835 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Attempt to set lineWidth to 65536");
Mark Young7394fdd2016-03-31 14:56:43 -06009836
9837 // Check too high with dynamic setting.
9838 vkCmdSetLineWidth(m_commandBuffer->GetBufferHandle(), 65536.0f);
9839 m_errorMonitor->VerifyFound();
9840 EndCommandBuffer();
9841
9842 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
9843 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
9844 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
9845 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tony Barbourdf4c0042016-06-01 15:55:43 -06009846 vkDestroyPipeline(m_device->device(), pipeline, NULL);
Mark Young7394fdd2016-03-31 14:56:43 -06009847}
9848
Karl Schultz6addd812016-02-02 17:17:23 -07009849TEST_F(VkLayerTest, NullRenderPass) {
Tobin Ehlis98aa0ed2015-06-25 16:27:19 -06009850 // Bind a NULL RenderPass
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009851 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
9852 "You cannot use a NULL RenderPass object in vkCmdBeginRenderPass()");
Tobin Ehlis98aa0ed2015-06-25 16:27:19 -06009853
9854 ASSERT_NO_FATAL_FAILURE(InitState());
9855 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlis98aa0ed2015-06-25 16:27:19 -06009856
Tony Barbourfe3351b2015-07-28 10:17:20 -06009857 BeginCommandBuffer();
Karl Schultz6addd812016-02-02 17:17:23 -07009858 // Don't care about RenderPass handle b/c error should be flagged before
9859 // that
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009860 vkCmdBeginRenderPass(m_commandBuffer->GetBufferHandle(), NULL, VK_SUBPASS_CONTENTS_INLINE);
Tobin Ehlis98aa0ed2015-06-25 16:27:19 -06009861
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009862 m_errorMonitor->VerifyFound();
Tobin Ehlis98aa0ed2015-06-25 16:27:19 -06009863}
9864
Karl Schultz6addd812016-02-02 17:17:23 -07009865TEST_F(VkLayerTest, RenderPassWithinRenderPass) {
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06009866 // Bind a BeginRenderPass within an active RenderPass
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009867 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
9868 "It is invalid to issue this call inside an active render pass");
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06009869
9870 ASSERT_NO_FATAL_FAILURE(InitState());
9871 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06009872
Tony Barbourfe3351b2015-07-28 10:17:20 -06009873 BeginCommandBuffer();
Karl Schultz6addd812016-02-02 17:17:23 -07009874 // Just create a dummy Renderpass that's non-NULL so we can get to the
9875 // proper error
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009876 vkCmdBeginRenderPass(m_commandBuffer->GetBufferHandle(), &m_renderPassBeginInfo, VK_SUBPASS_CONTENTS_INLINE);
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06009877
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009878 m_errorMonitor->VerifyFound();
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06009879}
9880
Chris Forbes2eeabe32016-06-21 20:52:34 +12009881TEST_F(VkLayerTest, RenderPassSecondaryCommandBuffersMultipleTimes) {
9882 m_errorMonitor->ExpectSuccess();
9883
9884 ASSERT_NO_FATAL_FAILURE(InitState());
9885 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
9886
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009887 BeginCommandBuffer(); // framework implicitly begins the renderpass.
Chris Forbes2eeabe32016-06-21 20:52:34 +12009888 vkCmdEndRenderPass(m_commandBuffer->GetBufferHandle()); // end implicit.
9889
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009890 vkCmdBeginRenderPass(m_commandBuffer->GetBufferHandle(), &m_renderPassBeginInfo, VK_SUBPASS_CONTENTS_SECONDARY_COMMAND_BUFFERS);
Chris Forbes2eeabe32016-06-21 20:52:34 +12009891 vkCmdEndRenderPass(m_commandBuffer->GetBufferHandle());
9892 m_errorMonitor->VerifyNotFound();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009893 vkCmdBeginRenderPass(m_commandBuffer->GetBufferHandle(), &m_renderPassBeginInfo, VK_SUBPASS_CONTENTS_INLINE);
Chris Forbes2eeabe32016-06-21 20:52:34 +12009894 m_errorMonitor->VerifyNotFound();
9895 vkCmdEndRenderPass(m_commandBuffer->GetBufferHandle());
9896 m_errorMonitor->VerifyNotFound();
9897
9898 m_commandBuffer->EndCommandBuffer();
9899 m_errorMonitor->VerifyNotFound();
9900}
9901
Tobin Ehlis5a1c0332016-05-31 13:59:26 -06009902TEST_F(VkLayerTest, RenderPassClearOpMismatch) {
9903 TEST_DESCRIPTION("Begin a renderPass where clearValueCount is less than"
9904 "the number of renderPass attachments that use loadOp"
9905 "VK_ATTACHMENT_LOAD_OP_CLEAR.");
9906
9907 ASSERT_NO_FATAL_FAILURE(InitState());
9908 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
9909
9910 // Create a renderPass with a single attachment that uses loadOp CLEAR
9911 VkAttachmentReference attach = {};
9912 attach.layout = VK_IMAGE_LAYOUT_GENERAL;
9913 VkSubpassDescription subpass = {};
9914 subpass.inputAttachmentCount = 1;
9915 subpass.pInputAttachments = &attach;
9916 VkRenderPassCreateInfo rpci = {};
9917 rpci.subpassCount = 1;
9918 rpci.pSubpasses = &subpass;
9919 rpci.attachmentCount = 1;
9920 VkAttachmentDescription attach_desc = {};
9921 attach_desc.format = VK_FORMAT_UNDEFINED;
9922 // Set loadOp to CLEAR
9923 attach_desc.loadOp = VK_ATTACHMENT_LOAD_OP_CLEAR;
9924 rpci.pAttachments = &attach_desc;
9925 rpci.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
9926 VkRenderPass rp;
9927 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
9928
9929 VkCommandBufferInheritanceInfo hinfo = {};
9930 hinfo.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_INHERITANCE_INFO;
9931 hinfo.renderPass = VK_NULL_HANDLE;
9932 hinfo.subpass = 0;
9933 hinfo.framebuffer = VK_NULL_HANDLE;
9934 hinfo.occlusionQueryEnable = VK_FALSE;
9935 hinfo.queryFlags = 0;
9936 hinfo.pipelineStatistics = 0;
9937 VkCommandBufferBeginInfo info = {};
9938 info.flags = VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT;
9939 info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
9940 info.pInheritanceInfo = &hinfo;
9941
9942 vkBeginCommandBuffer(m_commandBuffer->handle(), &info);
9943 VkRenderPassBeginInfo rp_begin = {};
9944 rp_begin.sType = VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO;
9945 rp_begin.pNext = NULL;
9946 rp_begin.renderPass = renderPass();
9947 rp_begin.framebuffer = framebuffer();
9948 rp_begin.clearValueCount = 0; // Should be 1
9949
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009950 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " has a clearValueCount of 0 but "
9951 "there must be at least 1 entries in "
9952 "pClearValues array to account for ");
Tobin Ehlis5a1c0332016-05-31 13:59:26 -06009953
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009954 vkCmdBeginRenderPass(m_commandBuffer->GetBufferHandle(), &rp_begin, VK_SUBPASS_CONTENTS_INLINE);
Tobin Ehlis5a1c0332016-05-31 13:59:26 -06009955
9956 m_errorMonitor->VerifyFound();
Mark Lobodzinski5c70ebd2016-06-09 13:45:00 -06009957
9958 vkDestroyRenderPass(m_device->device(), rp, NULL);
Tobin Ehlis5a1c0332016-05-31 13:59:26 -06009959}
9960
Cody Northrop3bb4d962016-05-09 16:15:57 -06009961TEST_F(VkLayerTest, EndCommandBufferWithinRenderPass) {
9962
9963 TEST_DESCRIPTION("End a command buffer with an active render pass");
9964
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009965 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
9966 "It is invalid to issue this call inside an active render pass");
Cody Northrop3bb4d962016-05-09 16:15:57 -06009967
9968 ASSERT_NO_FATAL_FAILURE(InitState());
9969 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
9970
9971 // The framework's BeginCommandBuffer calls CreateRenderPass
9972 BeginCommandBuffer();
9973
9974 // Call directly into vkEndCommandBuffer instead of the
9975 // the framework's EndCommandBuffer, which inserts a
9976 // vkEndRenderPass
9977 vkEndCommandBuffer(m_commandBuffer->GetBufferHandle());
9978
9979 m_errorMonitor->VerifyFound();
9980
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009981 // TODO: Add test for VK_COMMAND_BUFFER_LEVEL_SECONDARY
9982 // TODO: Add test for VK_COMMAND_BUFFER_USAGE_RENDER_PASS_CONTINUE_BIT
Cody Northrop3bb4d962016-05-09 16:15:57 -06009983}
9984
Karl Schultz6addd812016-02-02 17:17:23 -07009985TEST_F(VkLayerTest, FillBufferWithinRenderPass) {
Mark Lobodzinskid5639502015-09-24 09:51:47 -06009986 // Call CmdFillBuffer within an active renderpass
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009987 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
9988 "It is invalid to issue this call inside an active render pass");
Mark Lobodzinskid5639502015-09-24 09:51:47 -06009989
9990 ASSERT_NO_FATAL_FAILURE(InitState());
9991 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Mark Lobodzinskid5639502015-09-24 09:51:47 -06009992
9993 // Renderpass is started here
9994 BeginCommandBuffer();
9995
9996 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009997 vk_testing::Buffer dstBuffer;
9998 dstBuffer.init_as_dst(*m_device, (VkDeviceSize)1024, reqs);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06009999
Chia-I Wu3432a0c2015-10-27 18:04:07 +080010000 m_commandBuffer->FillBuffer(dstBuffer.handle(), 0, 4, 0x11111111);
Mark Lobodzinskid5639502015-09-24 09:51:47 -060010001
Chris Forbes8f36a8a2016-04-07 13:21:07 +120010002 m_errorMonitor->VerifyFound();
Mark Lobodzinskid5639502015-09-24 09:51:47 -060010003}
10004
Karl Schultz6addd812016-02-02 17:17:23 -070010005TEST_F(VkLayerTest, UpdateBufferWithinRenderPass) {
Mark Lobodzinskid5639502015-09-24 09:51:47 -060010006 // Call CmdUpdateBuffer within an active renderpass
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010007 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
10008 "It is invalid to issue this call inside an active render pass");
Mark Lobodzinskid5639502015-09-24 09:51:47 -060010009
10010 ASSERT_NO_FATAL_FAILURE(InitState());
10011 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Mark Lobodzinskid5639502015-09-24 09:51:47 -060010012
10013 // Renderpass is started here
10014 BeginCommandBuffer();
10015
10016 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080010017 vk_testing::Buffer dstBuffer;
10018 dstBuffer.init_as_dst(*m_device, (VkDeviceSize)1024, reqs);
Mark Lobodzinskid5639502015-09-24 09:51:47 -060010019
Karl Schultz6addd812016-02-02 17:17:23 -070010020 VkDeviceSize dstOffset = 0;
10021 VkDeviceSize dataSize = 1024;
Karl Schultzee344492016-07-11 15:09:57 -060010022 const void *pData = NULL;
Mark Lobodzinskid5639502015-09-24 09:51:47 -060010023
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010024 vkCmdUpdateBuffer(m_commandBuffer->GetBufferHandle(), dstBuffer.handle(), dstOffset, dataSize, pData);
Mark Lobodzinskid5639502015-09-24 09:51:47 -060010025
Chris Forbes8f36a8a2016-04-07 13:21:07 +120010026 m_errorMonitor->VerifyFound();
Mark Lobodzinskid5639502015-09-24 09:51:47 -060010027}
10028
Karl Schultz6addd812016-02-02 17:17:23 -070010029TEST_F(VkLayerTest, ClearColorImageWithinRenderPass) {
Mark Lobodzinskid5639502015-09-24 09:51:47 -060010030 // Call CmdClearColorImage within an active RenderPass
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010031 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
10032 "It is invalid to issue this call inside an active render pass");
Mark Lobodzinskid5639502015-09-24 09:51:47 -060010033
10034 ASSERT_NO_FATAL_FAILURE(InitState());
10035 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Mark Lobodzinskid5639502015-09-24 09:51:47 -060010036
10037 // Renderpass is started here
10038 BeginCommandBuffer();
10039
Michael Lentine0a369f62016-02-03 16:51:46 -060010040 VkClearColorValue clear_color;
10041 memset(clear_color.uint32, 0, sizeof(uint32_t) * 4);
Karl Schultz6addd812016-02-02 17:17:23 -070010042 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
10043 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
10044 const int32_t tex_width = 32;
10045 const int32_t tex_height = 32;
10046 VkImageCreateInfo image_create_info = {};
10047 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
10048 image_create_info.pNext = NULL;
10049 image_create_info.imageType = VK_IMAGE_TYPE_2D;
10050 image_create_info.format = tex_format;
10051 image_create_info.extent.width = tex_width;
10052 image_create_info.extent.height = tex_height;
10053 image_create_info.extent.depth = 1;
10054 image_create_info.mipLevels = 1;
10055 image_create_info.arrayLayers = 1;
10056 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
10057 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
10058 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
Mark Lobodzinskid5639502015-09-24 09:51:47 -060010059
Chia-I Wu3432a0c2015-10-27 18:04:07 +080010060 vk_testing::Image dstImage;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010061 dstImage.init(*m_device, (const VkImageCreateInfo &)image_create_info, reqs);
Mark Lobodzinskid5639502015-09-24 09:51:47 -060010062
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010063 const VkImageSubresourceRange range = vk_testing::Image::subresource_range(image_create_info, VK_IMAGE_ASPECT_COLOR_BIT);
Mark Lobodzinskid5639502015-09-24 09:51:47 -060010064
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010065 vkCmdClearColorImage(m_commandBuffer->GetBufferHandle(), dstImage.handle(), VK_IMAGE_LAYOUT_GENERAL, &clear_color, 1, &range);
Mark Lobodzinskid5639502015-09-24 09:51:47 -060010066
Chris Forbes8f36a8a2016-04-07 13:21:07 +120010067 m_errorMonitor->VerifyFound();
Mark Lobodzinskid5639502015-09-24 09:51:47 -060010068}
10069
Karl Schultz6addd812016-02-02 17:17:23 -070010070TEST_F(VkLayerTest, ClearDepthStencilImageWithinRenderPass) {
Mark Lobodzinskid5639502015-09-24 09:51:47 -060010071 // Call CmdClearDepthStencilImage within an active RenderPass
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010072 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
10073 "It is invalid to issue this call inside an active render pass");
Mark Lobodzinskid5639502015-09-24 09:51:47 -060010074
10075 ASSERT_NO_FATAL_FAILURE(InitState());
10076 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Mark Lobodzinskid5639502015-09-24 09:51:47 -060010077
10078 // Renderpass is started here
10079 BeginCommandBuffer();
10080
10081 VkClearDepthStencilValue clear_value = {0};
Dustin Gravesa2e5c942016-02-11 18:28:06 -070010082 VkMemoryPropertyFlags reqs = 0;
Karl Schultz6addd812016-02-02 17:17:23 -070010083 VkImageCreateInfo image_create_info = vk_testing::Image::create_info();
10084 image_create_info.imageType = VK_IMAGE_TYPE_2D;
10085 image_create_info.format = VK_FORMAT_D24_UNORM_S8_UINT;
10086 image_create_info.extent.width = 64;
10087 image_create_info.extent.height = 64;
10088 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
10089 image_create_info.usage = VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT;
Mark Lobodzinskid5639502015-09-24 09:51:47 -060010090
Chia-I Wu3432a0c2015-10-27 18:04:07 +080010091 vk_testing::Image dstImage;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010092 dstImage.init(*m_device, (const VkImageCreateInfo &)image_create_info, reqs);
Mark Lobodzinskid5639502015-09-24 09:51:47 -060010093
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010094 const VkImageSubresourceRange range = vk_testing::Image::subresource_range(image_create_info, VK_IMAGE_ASPECT_DEPTH_BIT);
Mark Lobodzinskid5639502015-09-24 09:51:47 -060010095
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010096 vkCmdClearDepthStencilImage(m_commandBuffer->GetBufferHandle(), dstImage.handle(),
10097 VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL, &clear_value, 1, &range);
Mark Lobodzinskid5639502015-09-24 09:51:47 -060010098
Chris Forbes8f36a8a2016-04-07 13:21:07 +120010099 m_errorMonitor->VerifyFound();
Mark Lobodzinskid5639502015-09-24 09:51:47 -060010100}
10101
Karl Schultz6addd812016-02-02 17:17:23 -070010102TEST_F(VkLayerTest, ClearColorAttachmentsOutsideRenderPass) {
Courtney Goeltzenleuchterc9323e02015-10-15 16:51:05 -060010103 // Call CmdClearAttachmentss outside of an active RenderPass
Karl Schultz6addd812016-02-02 17:17:23 -070010104 VkResult err;
Mark Lobodzinskid5639502015-09-24 09:51:47 -060010105
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010106 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "vkCmdClearAttachments(): This call "
10107 "must be issued inside an active "
10108 "render pass");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060010109
Mark Lobodzinskid5639502015-09-24 09:51:47 -060010110 ASSERT_NO_FATAL_FAILURE(InitState());
10111 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Mark Lobodzinskid5639502015-09-24 09:51:47 -060010112
10113 // Start no RenderPass
Chia-I Wu3432a0c2015-10-27 18:04:07 +080010114 err = m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskid5639502015-09-24 09:51:47 -060010115 ASSERT_VK_SUCCESS(err);
10116
Courtney Goeltzenleuchterc9323e02015-10-15 16:51:05 -060010117 VkClearAttachment color_attachment;
10118 color_attachment.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
10119 color_attachment.clearValue.color.float32[0] = 0;
10120 color_attachment.clearValue.color.float32[1] = 0;
10121 color_attachment.clearValue.color.float32[2] = 0;
10122 color_attachment.clearValue.color.float32[3] = 0;
10123 color_attachment.colorAttachment = 0;
Karl Schultz6addd812016-02-02 17:17:23 -070010124 VkClearRect clear_rect = {{{0, 0}, {32, 32}}};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010125 vkCmdClearAttachments(m_commandBuffer->GetBufferHandle(), 1, &color_attachment, 1, &clear_rect);
Mark Lobodzinskid5639502015-09-24 09:51:47 -060010126
Chris Forbes8f36a8a2016-04-07 13:21:07 +120010127 m_errorMonitor->VerifyFound();
Mark Lobodzinskid5639502015-09-24 09:51:47 -060010128}
10129
Chris Forbes3b97e932016-09-07 11:29:24 +120010130TEST_F(VkLayerTest, RenderPassExcessiveNextSubpass) {
10131 TEST_DESCRIPTION("Test that an error is produced when CmdNextSubpass is "
10132 "called too many times in a renderpass instance");
10133
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010134 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "vkCmdNextSubpass(): Attempted to advance "
10135 "beyond final subpass");
Chris Forbes3b97e932016-09-07 11:29:24 +120010136
10137 ASSERT_NO_FATAL_FAILURE(InitState());
10138 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
10139
10140 BeginCommandBuffer();
10141
10142 // error here.
10143 vkCmdNextSubpass(m_commandBuffer->GetBufferHandle(), VK_SUBPASS_CONTENTS_INLINE);
10144 m_errorMonitor->VerifyFound();
10145
10146 EndCommandBuffer();
10147}
10148
Chris Forbes6d624702016-09-07 13:57:05 +120010149TEST_F(VkLayerTest, RenderPassEndedBeforeFinalSubpass) {
10150 TEST_DESCRIPTION("Test that an error is produced when CmdEndRenderPass is "
10151 "called before the final subpass has been reached");
10152
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010153 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "vkCmdEndRenderPass(): Called before reaching "
10154 "final subpass");
Chris Forbes6d624702016-09-07 13:57:05 +120010155
10156 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010157 VkSubpassDescription sd[2] = {{0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 0, nullptr, nullptr, nullptr, 0, nullptr},
10158 {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 0, nullptr, nullptr, nullptr, 0, nullptr}};
Chris Forbes6d624702016-09-07 13:57:05 +120010159
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010160 VkRenderPassCreateInfo rcpi = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 0, nullptr, 2, sd, 0, nullptr};
Chris Forbes6d624702016-09-07 13:57:05 +120010161
10162 VkRenderPass rp;
10163 VkResult err = vkCreateRenderPass(m_device->device(), &rcpi, nullptr, &rp);
10164 ASSERT_VK_SUCCESS(err);
10165
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010166 VkFramebufferCreateInfo fbci = {VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr, 0, rp, 0, nullptr, 16, 16, 1};
Chris Forbes6d624702016-09-07 13:57:05 +120010167
10168 VkFramebuffer fb;
10169 err = vkCreateFramebuffer(m_device->device(), &fbci, nullptr, &fb);
10170 ASSERT_VK_SUCCESS(err);
10171
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010172 m_commandBuffer->BeginCommandBuffer(); // no implicit RP begin
Chris Forbes6d624702016-09-07 13:57:05 +120010173
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010174 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 +120010175
10176 vkCmdBeginRenderPass(m_commandBuffer->GetBufferHandle(), &rpbi, VK_SUBPASS_CONTENTS_INLINE);
10177
10178 // Error here.
10179 vkCmdEndRenderPass(m_commandBuffer->GetBufferHandle());
10180 m_errorMonitor->VerifyFound();
10181
10182 // Clean up.
10183 vkDestroyFramebuffer(m_device->device(), fb, nullptr);
10184 vkDestroyRenderPass(m_device->device(), rp, nullptr);
10185}
10186
Karl Schultz9e66a292016-04-21 15:57:51 -060010187TEST_F(VkLayerTest, BufferMemoryBarrierNoBuffer) {
10188 // Try to add a buffer memory barrier with no buffer.
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010189 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
10190 "required parameter pBufferMemoryBarriers[0].buffer specified as VK_NULL_HANDLE");
Karl Schultz9e66a292016-04-21 15:57:51 -060010191
10192 ASSERT_NO_FATAL_FAILURE(InitState());
10193 BeginCommandBuffer();
10194
10195 VkBufferMemoryBarrier buf_barrier = {};
10196 buf_barrier.sType = VK_STRUCTURE_TYPE_BUFFER_MEMORY_BARRIER;
10197 buf_barrier.srcAccessMask = VK_ACCESS_HOST_WRITE_BIT;
10198 buf_barrier.dstAccessMask = VK_ACCESS_SHADER_READ_BIT;
10199 buf_barrier.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
10200 buf_barrier.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
10201 buf_barrier.buffer = VK_NULL_HANDLE;
10202 buf_barrier.offset = 0;
10203 buf_barrier.size = VK_WHOLE_SIZE;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010204 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
10205 nullptr, 1, &buf_barrier, 0, nullptr);
Karl Schultz9e66a292016-04-21 15:57:51 -060010206
10207 m_errorMonitor->VerifyFound();
10208}
10209
Tony Barbour7fd5c0f2016-05-03 16:11:53 -060010210TEST_F(VkLayerTest, InvalidBarriers) {
10211 TEST_DESCRIPTION("A variety of ways to get VK_INVALID_BARRIER ");
10212
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010213 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Barriers cannot be set during subpass");
Tony Barbour7fd5c0f2016-05-03 16:11:53 -060010214
10215 ASSERT_NO_FATAL_FAILURE(InitState());
10216 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
10217
10218 VkMemoryBarrier mem_barrier = {};
10219 mem_barrier.sType = VK_STRUCTURE_TYPE_MEMORY_BARRIER;
10220 mem_barrier.pNext = NULL;
10221 mem_barrier.srcAccessMask = VK_ACCESS_HOST_WRITE_BIT;
10222 mem_barrier.dstAccessMask = VK_ACCESS_SHADER_READ_BIT;
10223 BeginCommandBuffer();
10224 // BeginCommandBuffer() starts a render pass
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010225 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 1,
Tony Barbour7fd5c0f2016-05-03 16:11:53 -060010226 &mem_barrier, 0, nullptr, 0, nullptr);
10227 m_errorMonitor->VerifyFound();
10228
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010229 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Image Layout cannot be transitioned to UNDEFINED");
Tony Barbour7fd5c0f2016-05-03 16:11:53 -060010230 VkImageObj image(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010231 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 -060010232 ASSERT_TRUE(image.initialized());
10233 VkImageMemoryBarrier img_barrier = {};
10234 img_barrier.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
10235 img_barrier.pNext = NULL;
10236 img_barrier.srcAccessMask = VK_ACCESS_HOST_WRITE_BIT;
10237 img_barrier.dstAccessMask = VK_ACCESS_SHADER_READ_BIT;
10238 img_barrier.oldLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
10239 // New layout can't be UNDEFINED
10240 img_barrier.newLayout = VK_IMAGE_LAYOUT_UNDEFINED;
10241 img_barrier.image = image.handle();
10242 img_barrier.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
10243 img_barrier.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
10244 img_barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
10245 img_barrier.subresourceRange.baseArrayLayer = 0;
10246 img_barrier.subresourceRange.baseMipLevel = 0;
10247 img_barrier.subresourceRange.layerCount = 1;
10248 img_barrier.subresourceRange.levelCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010249 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
10250 nullptr, 0, nullptr, 1, &img_barrier);
Tony Barbour7fd5c0f2016-05-03 16:11:53 -060010251 m_errorMonitor->VerifyFound();
10252 img_barrier.newLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
10253
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010254 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Subresource must have the sum of the "
10255 "baseArrayLayer");
Tony Barbour7fd5c0f2016-05-03 16:11:53 -060010256 // baseArrayLayer + layerCount must be <= image's arrayLayers
10257 img_barrier.subresourceRange.baseArrayLayer = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010258 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
10259 nullptr, 0, nullptr, 1, &img_barrier);
Tony Barbour7fd5c0f2016-05-03 16:11:53 -060010260 m_errorMonitor->VerifyFound();
10261 img_barrier.subresourceRange.baseArrayLayer = 0;
10262
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010263 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Subresource must have the sum of the baseMipLevel");
Tony Barbour7fd5c0f2016-05-03 16:11:53 -060010264 // baseMipLevel + levelCount must be <= image's mipLevels
10265 img_barrier.subresourceRange.baseMipLevel = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010266 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
10267 nullptr, 0, nullptr, 1, &img_barrier);
Tony Barbour7fd5c0f2016-05-03 16:11:53 -060010268 m_errorMonitor->VerifyFound();
10269 img_barrier.subresourceRange.baseMipLevel = 0;
10270
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010271 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 -060010272 vk_testing::Buffer buffer;
10273 buffer.init(*m_device, 256);
10274 VkBufferMemoryBarrier buf_barrier = {};
10275 buf_barrier.sType = VK_STRUCTURE_TYPE_BUFFER_MEMORY_BARRIER;
10276 buf_barrier.pNext = NULL;
10277 buf_barrier.srcAccessMask = VK_ACCESS_HOST_WRITE_BIT;
10278 buf_barrier.dstAccessMask = VK_ACCESS_SHADER_READ_BIT;
10279 buf_barrier.buffer = buffer.handle();
10280 buf_barrier.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
10281 buf_barrier.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
10282 buf_barrier.offset = 0;
10283 buf_barrier.size = VK_WHOLE_SIZE;
10284 // Can't send buffer barrier during a render pass
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010285 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
10286 nullptr, 1, &buf_barrier, 0, nullptr);
Tony Barbour7fd5c0f2016-05-03 16:11:53 -060010287 m_errorMonitor->VerifyFound();
10288 vkCmdEndRenderPass(m_commandBuffer->GetBufferHandle());
10289
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010290 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "which is not less than total size");
Tony Barbour7fd5c0f2016-05-03 16:11:53 -060010291 buf_barrier.offset = 257;
10292 // Offset greater than total size
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010293 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
10294 nullptr, 1, &buf_barrier, 0, nullptr);
Tony Barbour7fd5c0f2016-05-03 16:11:53 -060010295 m_errorMonitor->VerifyFound();
10296 buf_barrier.offset = 0;
10297
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010298 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "whose sum is greater than total size");
Tony Barbour7fd5c0f2016-05-03 16:11:53 -060010299 buf_barrier.size = 257;
10300 // Size greater than total size
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010301 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
10302 nullptr, 1, &buf_barrier, 0, nullptr);
Tony Barbour7fd5c0f2016-05-03 16:11:53 -060010303 m_errorMonitor->VerifyFound();
Tony Barbour7fd5c0f2016-05-03 16:11:53 -060010304
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -060010305 // Now exercise barrier aspect bit errors, first DS
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010306 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Image is a depth and stencil format and thus must "
10307 "have either one or both of VK_IMAGE_ASPECT_DEPTH_BIT and "
10308 "VK_IMAGE_ASPECT_STENCIL_BIT set.");
Tony Barbour7fd5c0f2016-05-03 16:11:53 -060010309 VkDepthStencilObj ds_image(m_device);
10310 ds_image.Init(m_device, 128, 128, VK_FORMAT_D24_UNORM_S8_UINT);
10311 ASSERT_TRUE(ds_image.initialized());
Tobin Ehlis15684a02016-07-21 14:55:26 -060010312 img_barrier.oldLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
10313 img_barrier.newLayout = VK_IMAGE_LAYOUT_GENERAL;
Tony Barbour7fd5c0f2016-05-03 16:11:53 -060010314 img_barrier.image = ds_image.handle();
Tobin Ehlis15684a02016-07-21 14:55:26 -060010315 // Use of COLOR aspect on DS image is error
10316 img_barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010317 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
10318 nullptr, 0, nullptr, 1, &img_barrier);
Tony Barbour7fd5c0f2016-05-03 16:11:53 -060010319 m_errorMonitor->VerifyFound();
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -060010320 // Now test depth-only
10321 VkFormatProperties format_props;
10322
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010323 vkGetPhysicalDeviceFormatProperties(m_device->phy().handle(), VK_FORMAT_D16_UNORM, &format_props);
10324 if (format_props.optimalTilingFeatures & VK_FORMAT_FEATURE_DEPTH_STENCIL_ATTACHMENT_BIT) {
10325 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Image is a depth-only format and thus must "
10326 "have VK_IMAGE_ASPECT_DEPTH_BIT set.");
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -060010327 VkDepthStencilObj d_image(m_device);
10328 d_image.Init(m_device, 128, 128, VK_FORMAT_D16_UNORM);
10329 ASSERT_TRUE(d_image.initialized());
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010330 img_barrier.oldLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
Tobin Ehlis15684a02016-07-21 14:55:26 -060010331 img_barrier.newLayout = VK_IMAGE_LAYOUT_GENERAL;
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -060010332 img_barrier.image = d_image.handle();
Tobin Ehlis15684a02016-07-21 14:55:26 -060010333 // Use of COLOR aspect on depth image is error
10334 img_barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010335 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0,
10336 0, nullptr, 0, nullptr, 1, &img_barrier);
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -060010337 m_errorMonitor->VerifyFound();
10338 }
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010339 vkGetPhysicalDeviceFormatProperties(m_device->phy().handle(), VK_FORMAT_S8_UINT, &format_props);
10340 if (format_props.optimalTilingFeatures & VK_FORMAT_FEATURE_DEPTH_STENCIL_ATTACHMENT_BIT) {
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -060010341 // Now test stencil-only
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010342 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Image is a stencil-only format and thus must "
10343 "have VK_IMAGE_ASPECT_STENCIL_BIT set.");
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -060010344 VkDepthStencilObj s_image(m_device);
10345 s_image.Init(m_device, 128, 128, VK_FORMAT_S8_UINT);
10346 ASSERT_TRUE(s_image.initialized());
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010347 img_barrier.oldLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
Tobin Ehlis15684a02016-07-21 14:55:26 -060010348 img_barrier.newLayout = VK_IMAGE_LAYOUT_GENERAL;
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -060010349 img_barrier.image = s_image.handle();
Tobin Ehlis15684a02016-07-21 14:55:26 -060010350 // Use of COLOR aspect on depth image is error
10351 img_barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010352 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0,
10353 0, nullptr, 0, nullptr, 1, &img_barrier);
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -060010354 m_errorMonitor->VerifyFound();
10355 }
10356 // Finally test color
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010357 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Image is a color format and thus must "
10358 "have VK_IMAGE_ASPECT_COLOR_BIT set.");
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -060010359 VkImageObj c_image(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010360 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 -060010361 ASSERT_TRUE(c_image.initialized());
10362 img_barrier.oldLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
10363 img_barrier.newLayout = VK_IMAGE_LAYOUT_GENERAL;
10364 img_barrier.image = c_image.handle();
10365 // Set aspect to depth (non-color)
10366 img_barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010367 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
10368 nullptr, 0, nullptr, 1, &img_barrier);
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -060010369 m_errorMonitor->VerifyFound();
Tony Barbour7fd5c0f2016-05-03 16:11:53 -060010370}
10371
Karl Schultz6addd812016-02-02 17:17:23 -070010372TEST_F(VkLayerTest, IdxBufferAlignmentError) {
Tobin Ehlisc4c23182015-09-17 12:24:13 -060010373 // Bind a BeginRenderPass within an active RenderPass
Karl Schultz6addd812016-02-02 17:17:23 -070010374 VkResult err;
Tobin Ehlisc4c23182015-09-17 12:24:13 -060010375
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010376 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "vkCmdBindIndexBuffer() offset (0x7) does not fall on ");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060010377
Tobin Ehlisc4c23182015-09-17 12:24:13 -060010378 ASSERT_NO_FATAL_FAILURE(InitState());
10379 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlisc4c23182015-09-17 12:24:13 -060010380 uint32_t qfi = 0;
10381 VkBufferCreateInfo buffCI = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010382 buffCI.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
10383 buffCI.size = 1024;
10384 buffCI.usage = VK_BUFFER_USAGE_INDEX_BUFFER_BIT;
10385 buffCI.queueFamilyIndexCount = 1;
10386 buffCI.pQueueFamilyIndices = &qfi;
Tobin Ehlisc4c23182015-09-17 12:24:13 -060010387
10388 VkBuffer ib;
Chia-I Wuf7458c52015-10-26 21:10:41 +080010389 err = vkCreateBuffer(m_device->device(), &buffCI, NULL, &ib);
Tobin Ehlisc4c23182015-09-17 12:24:13 -060010390 ASSERT_VK_SUCCESS(err);
10391
10392 BeginCommandBuffer();
10393 ASSERT_VK_SUCCESS(err);
Karl Schultz6addd812016-02-02 17:17:23 -070010394 // vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(),
10395 // VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Tobin Ehlisc4c23182015-09-17 12:24:13 -060010396 // Should error before calling to driver so don't care about actual data
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010397 vkCmdBindIndexBuffer(m_commandBuffer->GetBufferHandle(), ib, 7, VK_INDEX_TYPE_UINT16);
Tobin Ehlisc4c23182015-09-17 12:24:13 -060010398
Chris Forbes8f36a8a2016-04-07 13:21:07 +120010399 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -060010400
Chia-I Wuf7458c52015-10-26 21:10:41 +080010401 vkDestroyBuffer(m_device->device(), ib, NULL);
Tobin Ehlisc4c23182015-09-17 12:24:13 -060010402}
10403
Mark Lobodzinski52a6e7d2016-02-25 15:09:52 -070010404TEST_F(VkLayerTest, InvalidQueueFamilyIndex) {
10405 // Create an out-of-range queueFamilyIndex
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010406 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
10407 "vkCreateBuffer: pCreateInfo->pQueueFamilyIndices[0] (777) must be one "
10408 "of the indices specified when the device was created, via the "
10409 "VkDeviceQueueCreateInfo structure.");
Mark Lobodzinski52a6e7d2016-02-25 15:09:52 -070010410
10411 ASSERT_NO_FATAL_FAILURE(InitState());
10412 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
10413 VkBufferCreateInfo buffCI = {};
10414 buffCI.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
10415 buffCI.size = 1024;
10416 buffCI.usage = VK_BUFFER_USAGE_INDEX_BUFFER_BIT;
10417 buffCI.queueFamilyIndexCount = 1;
10418 // Introduce failure by specifying invalid queue_family_index
10419 uint32_t qfi = 777;
10420 buffCI.pQueueFamilyIndices = &qfi;
Tobin Ehlis24aab042016-03-24 10:54:18 -060010421 buffCI.sharingMode = VK_SHARING_MODE_CONCURRENT; // qfi only matters in CONCURRENT mode
Mark Lobodzinski52a6e7d2016-02-25 15:09:52 -070010422
10423 VkBuffer ib;
10424 vkCreateBuffer(m_device->device(), &buffCI, NULL, &ib);
10425
Chris Forbes8f36a8a2016-04-07 13:21:07 +120010426 m_errorMonitor->VerifyFound();
Tony Barbourdf4c0042016-06-01 15:55:43 -060010427 vkDestroyBuffer(m_device->device(), ib, NULL);
Mark Lobodzinski52a6e7d2016-02-25 15:09:52 -070010428}
10429
Karl Schultz6addd812016-02-02 17:17:23 -070010430TEST_F(VkLayerTest, ExecuteCommandsPrimaryCB) {
Tobin Ehlis0c94db02016-07-19 10:49:32 -060010431 TEST_DESCRIPTION("Attempt vkCmdExecuteCommands w/ a primary cmd buffer"
10432 " (should only be secondary)");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060010433
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010434 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "vkCmdExecuteCommands() called w/ Primary Cmd Buffer ");
Tobin Ehlis4b34ddc2015-09-17 14:18:16 -060010435
10436 ASSERT_NO_FATAL_FAILURE(InitState());
10437 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlis4b34ddc2015-09-17 14:18:16 -060010438
10439 BeginCommandBuffer();
Tobin Ehlis0c94db02016-07-19 10:49:32 -060010440
Chia-I Wu3432a0c2015-10-27 18:04:07 +080010441 VkCommandBuffer primCB = m_commandBuffer->GetBufferHandle();
10442 vkCmdExecuteCommands(m_commandBuffer->GetBufferHandle(), 1, &primCB);
Tobin Ehlis4b34ddc2015-09-17 14:18:16 -060010443
Chris Forbes8f36a8a2016-04-07 13:21:07 +120010444 m_errorMonitor->VerifyFound();
Tobin Ehlis4b34ddc2015-09-17 14:18:16 -060010445}
10446
Tobin Ehlis17826bd2016-05-25 11:12:50 -060010447TEST_F(VkLayerTest, DSUsageBitsErrors) {
10448 TEST_DESCRIPTION("Attempt to update descriptor sets for images and buffers "
10449 "that do not have correct usage bits sets.");
10450 VkResult err;
10451
10452 ASSERT_NO_FATAL_FAILURE(InitState());
10453 VkDescriptorPoolSize ds_type_count[VK_DESCRIPTOR_TYPE_RANGE_SIZE] = {};
10454 for (uint32_t i = 0; i < VK_DESCRIPTOR_TYPE_RANGE_SIZE; ++i) {
10455 ds_type_count[i].type = VkDescriptorType(i);
10456 ds_type_count[i].descriptorCount = 1;
10457 }
10458 VkDescriptorPoolCreateInfo ds_pool_ci = {};
10459 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
10460 ds_pool_ci.pNext = NULL;
10461 ds_pool_ci.maxSets = VK_DESCRIPTOR_TYPE_RANGE_SIZE;
10462 ds_pool_ci.poolSizeCount = VK_DESCRIPTOR_TYPE_RANGE_SIZE;
10463 ds_pool_ci.pPoolSizes = ds_type_count;
10464
10465 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010466 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis17826bd2016-05-25 11:12:50 -060010467 ASSERT_VK_SUCCESS(err);
10468
10469 // Create 10 layouts where each has a single descriptor of different type
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010470 VkDescriptorSetLayoutBinding dsl_binding[VK_DESCRIPTOR_TYPE_RANGE_SIZE] = {};
Tobin Ehlis17826bd2016-05-25 11:12:50 -060010471 for (uint32_t i = 0; i < VK_DESCRIPTOR_TYPE_RANGE_SIZE; ++i) {
10472 dsl_binding[i].binding = 0;
10473 dsl_binding[i].descriptorType = VkDescriptorType(i);
10474 dsl_binding[i].descriptorCount = 1;
10475 dsl_binding[i].stageFlags = VK_SHADER_STAGE_ALL;
10476 dsl_binding[i].pImmutableSamplers = NULL;
10477 }
10478
10479 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
10480 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
10481 ds_layout_ci.pNext = NULL;
10482 ds_layout_ci.bindingCount = 1;
10483 VkDescriptorSetLayout ds_layouts[VK_DESCRIPTOR_TYPE_RANGE_SIZE];
10484 for (uint32_t i = 0; i < VK_DESCRIPTOR_TYPE_RANGE_SIZE; ++i) {
10485 ds_layout_ci.pBindings = dsl_binding + i;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010486 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, ds_layouts + i);
Tobin Ehlis17826bd2016-05-25 11:12:50 -060010487 ASSERT_VK_SUCCESS(err);
10488 }
10489 VkDescriptorSet descriptor_sets[VK_DESCRIPTOR_TYPE_RANGE_SIZE] = {};
10490 VkDescriptorSetAllocateInfo alloc_info = {};
10491 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
10492 alloc_info.descriptorSetCount = VK_DESCRIPTOR_TYPE_RANGE_SIZE;
10493 alloc_info.descriptorPool = ds_pool;
10494 alloc_info.pSetLayouts = ds_layouts;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010495 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, descriptor_sets);
Tobin Ehlis17826bd2016-05-25 11:12:50 -060010496 ASSERT_VK_SUCCESS(err);
10497
10498 // Create a buffer & bufferView to be used for invalid updates
10499 VkBufferCreateInfo buff_ci = {};
10500 buff_ci.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
10501 // This usage is not valid for any descriptor type
10502 buff_ci.usage = VK_BUFFER_USAGE_TRANSFER_SRC_BIT;
10503 buff_ci.size = 256;
10504 buff_ci.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
10505 VkBuffer buffer;
10506 err = vkCreateBuffer(m_device->device(), &buff_ci, NULL, &buffer);
10507 ASSERT_VK_SUCCESS(err);
10508
10509 VkBufferViewCreateInfo buff_view_ci = {};
10510 buff_view_ci.sType = VK_STRUCTURE_TYPE_BUFFER_VIEW_CREATE_INFO;
10511 buff_view_ci.buffer = buffer;
10512 buff_view_ci.format = VK_FORMAT_R8_UNORM;
10513 buff_view_ci.range = VK_WHOLE_SIZE;
10514 VkBufferView buff_view;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010515 err = vkCreateBufferView(m_device->device(), &buff_view_ci, NULL, &buff_view);
Tobin Ehlis17826bd2016-05-25 11:12:50 -060010516 ASSERT_VK_SUCCESS(err);
10517
10518 // Create an image to be used for invalid updates
10519 VkImageCreateInfo image_ci = {};
10520 image_ci.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
10521 image_ci.imageType = VK_IMAGE_TYPE_2D;
10522 image_ci.format = VK_FORMAT_R8G8B8A8_UNORM;
10523 image_ci.extent.width = 64;
10524 image_ci.extent.height = 64;
10525 image_ci.extent.depth = 1;
10526 image_ci.mipLevels = 1;
10527 image_ci.arrayLayers = 1;
10528 image_ci.samples = VK_SAMPLE_COUNT_1_BIT;
10529 image_ci.tiling = VK_IMAGE_TILING_LINEAR;
10530 image_ci.initialLayout = VK_IMAGE_LAYOUT_PREINITIALIZED;
10531 // This usage is not valid for any descriptor type
10532 image_ci.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
10533 image_ci.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
10534 VkImage image;
10535 err = vkCreateImage(m_device->device(), &image_ci, NULL, &image);
10536 ASSERT_VK_SUCCESS(err);
10537 // Bind memory to image
10538 VkMemoryRequirements mem_reqs;
10539 VkDeviceMemory image_mem;
10540 bool pass;
10541 VkMemoryAllocateInfo mem_alloc = {};
10542 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
10543 mem_alloc.pNext = NULL;
10544 mem_alloc.allocationSize = 0;
10545 mem_alloc.memoryTypeIndex = 0;
10546 vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs);
10547 mem_alloc.allocationSize = mem_reqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010548 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0);
Tobin Ehlis17826bd2016-05-25 11:12:50 -060010549 ASSERT_TRUE(pass);
10550 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &image_mem);
10551 ASSERT_VK_SUCCESS(err);
10552 err = vkBindImageMemory(m_device->device(), image, image_mem, 0);
10553 ASSERT_VK_SUCCESS(err);
10554 // Now create view for image
10555 VkImageViewCreateInfo image_view_ci = {};
10556 image_view_ci.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
10557 image_view_ci.image = image;
10558 image_view_ci.format = VK_FORMAT_R8G8B8A8_UNORM;
10559 image_view_ci.viewType = VK_IMAGE_VIEW_TYPE_2D;
10560 image_view_ci.subresourceRange.layerCount = 1;
10561 image_view_ci.subresourceRange.baseArrayLayer = 0;
10562 image_view_ci.subresourceRange.levelCount = 1;
10563 image_view_ci.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
10564 VkImageView image_view;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010565 err = vkCreateImageView(m_device->device(), &image_view_ci, NULL, &image_view);
Tobin Ehlis17826bd2016-05-25 11:12:50 -060010566 ASSERT_VK_SUCCESS(err);
10567
10568 VkDescriptorBufferInfo buff_info = {};
10569 buff_info.buffer = buffer;
10570 VkDescriptorImageInfo img_info = {};
10571 img_info.imageView = image_view;
10572 VkWriteDescriptorSet descriptor_write = {};
10573 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
10574 descriptor_write.dstBinding = 0;
10575 descriptor_write.descriptorCount = 1;
10576 descriptor_write.pTexelBufferView = &buff_view;
10577 descriptor_write.pBufferInfo = &buff_info;
10578 descriptor_write.pImageInfo = &img_info;
10579
10580 // These error messages align with VkDescriptorType struct
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010581 const char *error_msgs[] = {"", // placeholder, no error for SAMPLER descriptor
10582 " does not have VK_IMAGE_USAGE_SAMPLED_BIT set.",
10583 " does not have VK_IMAGE_USAGE_SAMPLED_BIT set.",
10584 " does not have VK_IMAGE_USAGE_STORAGE_BIT set.",
10585 " does not have VK_BUFFER_USAGE_UNIFORM_TEXEL_BUFFER_BIT set.",
10586 " does not have VK_BUFFER_USAGE_STORAGE_TEXEL_BUFFER_BIT set.",
10587 " does not have VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT set.",
10588 " does not have VK_BUFFER_USAGE_STORAGE_BUFFER_BIT set.",
10589 " does not have VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT set.",
10590 " does not have VK_BUFFER_USAGE_STORAGE_BUFFER_BIT set.",
10591 " does not have VK_IMAGE_USAGE_INPUT_ATTACHMENT_BIT set."};
Tobin Ehlis17826bd2016-05-25 11:12:50 -060010592 // Start loop at 1 as SAMPLER desc type has no usage bit error
10593 for (uint32_t i = 1; i < VK_DESCRIPTOR_TYPE_RANGE_SIZE; ++i) {
10594 descriptor_write.descriptorType = VkDescriptorType(i);
10595 descriptor_write.dstSet = descriptor_sets[i];
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010596 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, error_msgs[i]);
Tobin Ehlis17826bd2016-05-25 11:12:50 -060010597
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010598 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
Tobin Ehlis17826bd2016-05-25 11:12:50 -060010599
10600 m_errorMonitor->VerifyFound();
10601 vkDestroyDescriptorSetLayout(m_device->device(), ds_layouts[i], NULL);
10602 }
10603 vkDestroyDescriptorSetLayout(m_device->device(), ds_layouts[0], NULL);
10604 vkDestroyImage(m_device->device(), image, NULL);
Tony Barbourdf4c0042016-06-01 15:55:43 -060010605 vkFreeMemory(m_device->device(), image_mem, NULL);
Tobin Ehlis17826bd2016-05-25 11:12:50 -060010606 vkDestroyImageView(m_device->device(), image_view, NULL);
10607 vkDestroyBuffer(m_device->device(), buffer, NULL);
10608 vkDestroyBufferView(m_device->device(), buff_view, NULL);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010609 vkFreeDescriptorSets(m_device->device(), ds_pool, VK_DESCRIPTOR_TYPE_RANGE_SIZE, descriptor_sets);
Tobin Ehlis17826bd2016-05-25 11:12:50 -060010610 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
10611}
10612
Tobin Ehlis585f66d2016-07-01 18:23:58 -060010613TEST_F(VkLayerTest, DSBufferInfoErrors) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010614 TEST_DESCRIPTION("Attempt to update buffer descriptor set that has incorrect "
10615 "parameters in VkDescriptorBufferInfo struct. This includes:\n"
10616 "1. offset value greater than buffer size\n"
10617 "2. range value of 0\n"
10618 "3. range value greater than buffer (size - offset)");
Tobin Ehlis585f66d2016-07-01 18:23:58 -060010619 VkResult err;
10620
10621 ASSERT_NO_FATAL_FAILURE(InitState());
10622 VkDescriptorPoolSize ds_type_count = {};
10623 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
10624 ds_type_count.descriptorCount = 1;
10625
10626 VkDescriptorPoolCreateInfo ds_pool_ci = {};
10627 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
10628 ds_pool_ci.pNext = NULL;
10629 ds_pool_ci.maxSets = 1;
10630 ds_pool_ci.poolSizeCount = 1;
10631 ds_pool_ci.pPoolSizes = &ds_type_count;
10632
10633 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010634 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis585f66d2016-07-01 18:23:58 -060010635 ASSERT_VK_SUCCESS(err);
10636
10637 // Create layout with single uniform buffer descriptor
10638 VkDescriptorSetLayoutBinding dsl_binding = {};
10639 dsl_binding.binding = 0;
10640 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
10641 dsl_binding.descriptorCount = 1;
10642 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
10643 dsl_binding.pImmutableSamplers = NULL;
10644
10645 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
10646 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
10647 ds_layout_ci.pNext = NULL;
10648 ds_layout_ci.bindingCount = 1;
10649 ds_layout_ci.pBindings = &dsl_binding;
10650 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010651 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis585f66d2016-07-01 18:23:58 -060010652 ASSERT_VK_SUCCESS(err);
10653
10654 VkDescriptorSet descriptor_set = {};
10655 VkDescriptorSetAllocateInfo alloc_info = {};
10656 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
10657 alloc_info.descriptorSetCount = 1;
10658 alloc_info.descriptorPool = ds_pool;
10659 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010660 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
Tobin Ehlis585f66d2016-07-01 18:23:58 -060010661 ASSERT_VK_SUCCESS(err);
10662
10663 // Create a buffer to be used for invalid updates
10664 VkBufferCreateInfo buff_ci = {};
10665 buff_ci.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
10666 buff_ci.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
10667 buff_ci.size = 256;
10668 buff_ci.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
10669 VkBuffer buffer;
10670 err = vkCreateBuffer(m_device->device(), &buff_ci, NULL, &buffer);
10671 ASSERT_VK_SUCCESS(err);
10672 // Have to bind memory to buffer before descriptor update
10673 VkMemoryAllocateInfo mem_alloc = {};
10674 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
10675 mem_alloc.pNext = NULL;
10676 mem_alloc.allocationSize = 256;
10677 mem_alloc.memoryTypeIndex = 0;
10678
10679 VkMemoryRequirements mem_reqs;
10680 vkGetBufferMemoryRequirements(m_device->device(), buffer, &mem_reqs);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010681 bool pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0);
Tobin Ehlis585f66d2016-07-01 18:23:58 -060010682 if (!pass) {
10683 vkDestroyBuffer(m_device->device(), buffer, NULL);
10684 return;
10685 }
10686
10687 VkDeviceMemory mem;
10688 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem);
10689 ASSERT_VK_SUCCESS(err);
10690 err = vkBindBufferMemory(m_device->device(), buffer, mem, 0);
10691 ASSERT_VK_SUCCESS(err);
10692
10693 VkDescriptorBufferInfo buff_info = {};
10694 buff_info.buffer = buffer;
10695 // First make offset 1 larger than buffer size
10696 buff_info.offset = 257;
10697 buff_info.range = VK_WHOLE_SIZE;
10698 VkWriteDescriptorSet descriptor_write = {};
10699 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
10700 descriptor_write.dstBinding = 0;
10701 descriptor_write.descriptorCount = 1;
10702 descriptor_write.pTexelBufferView = nullptr;
10703 descriptor_write.pBufferInfo = &buff_info;
10704 descriptor_write.pImageInfo = nullptr;
10705
10706 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
10707 descriptor_write.dstSet = descriptor_set;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010708 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " offset of 257 is greater than buffer ");
Tobin Ehlis585f66d2016-07-01 18:23:58 -060010709
10710 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
10711
10712 m_errorMonitor->VerifyFound();
10713 // Now cause error due to range of 0
10714 buff_info.offset = 0;
10715 buff_info.range = 0;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010716 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
10717 " range is not VK_WHOLE_SIZE and is zero, which is not allowed.");
Tobin Ehlis585f66d2016-07-01 18:23:58 -060010718
10719 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
10720
10721 m_errorMonitor->VerifyFound();
10722 // Now cause error due to range exceeding buffer size - offset
10723 buff_info.offset = 128;
10724 buff_info.range = 200;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010725 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 -060010726
10727 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
10728
10729 m_errorMonitor->VerifyFound();
Mark Lobodzinski4bb54092016-07-06 14:27:19 -060010730 vkFreeMemory(m_device->device(), mem, NULL);
Tobin Ehlis585f66d2016-07-01 18:23:58 -060010731 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
10732 vkDestroyBuffer(m_device->device(), buffer, NULL);
10733 vkFreeDescriptorSets(m_device->device(), ds_pool, 1, &descriptor_set);
10734 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
10735}
10736
Tobin Ehlis2fc296b2016-06-15 14:05:27 -060010737TEST_F(VkLayerTest, DSAspectBitsErrors) {
10738 // TODO : Initially only catching case where DEPTH & STENCIL aspect bits
10739 // are set, but could expand this test to hit more cases.
10740 TEST_DESCRIPTION("Attempt to update descriptor sets for images "
10741 "that do not have correct aspect bits sets.");
10742 VkResult err;
10743
10744 ASSERT_NO_FATAL_FAILURE(InitState());
10745 VkDescriptorPoolSize ds_type_count = {};
10746 ds_type_count.type = VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT;
10747 ds_type_count.descriptorCount = 1;
10748
10749 VkDescriptorPoolCreateInfo ds_pool_ci = {};
10750 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
10751 ds_pool_ci.pNext = NULL;
10752 ds_pool_ci.maxSets = 5;
10753 ds_pool_ci.poolSizeCount = 1;
10754 ds_pool_ci.pPoolSizes = &ds_type_count;
10755
10756 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010757 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis2fc296b2016-06-15 14:05:27 -060010758 ASSERT_VK_SUCCESS(err);
10759
10760 VkDescriptorSetLayoutBinding dsl_binding = {};
10761 dsl_binding.binding = 0;
10762 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT;
10763 dsl_binding.descriptorCount = 1;
10764 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
10765 dsl_binding.pImmutableSamplers = NULL;
10766
10767 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
10768 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
10769 ds_layout_ci.pNext = NULL;
10770 ds_layout_ci.bindingCount = 1;
10771 ds_layout_ci.pBindings = &dsl_binding;
10772 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010773 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis2fc296b2016-06-15 14:05:27 -060010774 ASSERT_VK_SUCCESS(err);
10775
10776 VkDescriptorSet descriptor_set = {};
10777 VkDescriptorSetAllocateInfo alloc_info = {};
10778 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
10779 alloc_info.descriptorSetCount = 1;
10780 alloc_info.descriptorPool = ds_pool;
10781 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010782 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
Tobin Ehlis2fc296b2016-06-15 14:05:27 -060010783 ASSERT_VK_SUCCESS(err);
10784
10785 // Create an image to be used for invalid updates
10786 VkImageCreateInfo image_ci = {};
10787 image_ci.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
10788 image_ci.imageType = VK_IMAGE_TYPE_2D;
10789 image_ci.format = VK_FORMAT_D24_UNORM_S8_UINT;
10790 image_ci.extent.width = 64;
10791 image_ci.extent.height = 64;
10792 image_ci.extent.depth = 1;
10793 image_ci.mipLevels = 1;
10794 image_ci.arrayLayers = 1;
10795 image_ci.samples = VK_SAMPLE_COUNT_1_BIT;
10796 image_ci.tiling = VK_IMAGE_TILING_LINEAR;
10797 image_ci.initialLayout = VK_IMAGE_LAYOUT_PREINITIALIZED;
10798 image_ci.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
10799 image_ci.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
10800 VkImage image;
10801 err = vkCreateImage(m_device->device(), &image_ci, NULL, &image);
10802 ASSERT_VK_SUCCESS(err);
10803 // Bind memory to image
10804 VkMemoryRequirements mem_reqs;
10805 VkDeviceMemory image_mem;
10806 bool pass;
10807 VkMemoryAllocateInfo mem_alloc = {};
10808 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
10809 mem_alloc.pNext = NULL;
10810 mem_alloc.allocationSize = 0;
10811 mem_alloc.memoryTypeIndex = 0;
10812 vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs);
10813 mem_alloc.allocationSize = mem_reqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010814 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0);
Tobin Ehlis2fc296b2016-06-15 14:05:27 -060010815 ASSERT_TRUE(pass);
10816 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &image_mem);
10817 ASSERT_VK_SUCCESS(err);
10818 err = vkBindImageMemory(m_device->device(), image, image_mem, 0);
10819 ASSERT_VK_SUCCESS(err);
10820 // Now create view for image
10821 VkImageViewCreateInfo image_view_ci = {};
10822 image_view_ci.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
10823 image_view_ci.image = image;
10824 image_view_ci.format = VK_FORMAT_D24_UNORM_S8_UINT;
10825 image_view_ci.viewType = VK_IMAGE_VIEW_TYPE_2D;
10826 image_view_ci.subresourceRange.layerCount = 1;
10827 image_view_ci.subresourceRange.baseArrayLayer = 0;
10828 image_view_ci.subresourceRange.levelCount = 1;
10829 // Setting both depth & stencil aspect bits is illegal for descriptor
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010830 image_view_ci.subresourceRange.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT;
Tobin Ehlis2fc296b2016-06-15 14:05:27 -060010831
10832 VkImageView image_view;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010833 err = vkCreateImageView(m_device->device(), &image_view_ci, NULL, &image_view);
Tobin Ehlis2fc296b2016-06-15 14:05:27 -060010834 ASSERT_VK_SUCCESS(err);
10835
10836 VkDescriptorImageInfo img_info = {};
10837 img_info.imageView = image_view;
10838 VkWriteDescriptorSet descriptor_write = {};
10839 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
10840 descriptor_write.dstBinding = 0;
10841 descriptor_write.descriptorCount = 1;
10842 descriptor_write.pTexelBufferView = NULL;
10843 descriptor_write.pBufferInfo = NULL;
10844 descriptor_write.pImageInfo = &img_info;
10845 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT;
10846 descriptor_write.dstSet = descriptor_set;
10847 const char *error_msg = " please only set either VK_IMAGE_ASPECT_DEPTH_BIT "
10848 "or VK_IMAGE_ASPECT_STENCIL_BIT ";
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010849 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, error_msg);
Tobin Ehlis2fc296b2016-06-15 14:05:27 -060010850
10851 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
10852
10853 m_errorMonitor->VerifyFound();
10854 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
10855 vkDestroyImage(m_device->device(), image, NULL);
10856 vkFreeMemory(m_device->device(), image_mem, NULL);
10857 vkDestroyImageView(m_device->device(), image_view, NULL);
10858 vkFreeDescriptorSets(m_device->device(), ds_pool, 1, &descriptor_set);
10859 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
10860}
10861
Karl Schultz6addd812016-02-02 17:17:23 -070010862TEST_F(VkLayerTest, DSTypeMismatch) {
Tobin Ehlis49eb23d2015-05-22 12:38:55 -060010863 // Create DS w/ layout of one type and attempt Update w/ mis-matched type
Karl Schultz6addd812016-02-02 17:17:23 -070010864 VkResult err;
Tobin Ehlis3b780662015-05-28 12:11:26 -060010865
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010866 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
10867 " binding #0 with type VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER but update "
10868 "type is VK_DESCRIPTOR_TYPE_SAMPLER");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060010869
Tobin Ehlis3b780662015-05-28 12:11:26 -060010870 ASSERT_NO_FATAL_FAILURE(InitState());
Karl Schultz6addd812016-02-02 17:17:23 -070010871 // VkDescriptorSetObj descriptorSet(m_device);
Chia-I Wu1b99bb22015-10-27 19:25:11 +080010872 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010873 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
10874 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -060010875
10876 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010877 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
10878 ds_pool_ci.pNext = NULL;
10879 ds_pool_ci.maxSets = 1;
10880 ds_pool_ci.poolSizeCount = 1;
10881 ds_pool_ci.pPoolSizes = &ds_type_count;
Tony Barboureb254902015-07-15 12:50:33 -060010882
Tobin Ehlis3b780662015-05-28 12:11:26 -060010883 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010884 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis3b780662015-05-28 12:11:26 -060010885 ASSERT_VK_SUCCESS(err);
Tony Barboureb254902015-07-15 12:50:33 -060010886 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010887 dsl_binding.binding = 0;
10888 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
10889 dsl_binding.descriptorCount = 1;
10890 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
10891 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis3b780662015-05-28 12:11:26 -060010892
Tony Barboureb254902015-07-15 12:50:33 -060010893 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010894 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
10895 ds_layout_ci.pNext = NULL;
10896 ds_layout_ci.bindingCount = 1;
10897 ds_layout_ci.pBindings = &dsl_binding;
Tony Barboureb254902015-07-15 12:50:33 -060010898
Tobin Ehlis3b780662015-05-28 12:11:26 -060010899 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010900 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis3b780662015-05-28 12:11:26 -060010901 ASSERT_VK_SUCCESS(err);
10902
10903 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080010904 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +080010905 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -070010906 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -060010907 alloc_info.descriptorPool = ds_pool;
10908 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010909 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis3b780662015-05-28 12:11:26 -060010910 ASSERT_VK_SUCCESS(err);
Tobin Ehlis3b780662015-05-28 12:11:26 -060010911
Tobin Ehlis30db8f82016-05-05 08:19:48 -060010912 VkSamplerCreateInfo sampler_ci = {};
10913 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
10914 sampler_ci.pNext = NULL;
10915 sampler_ci.magFilter = VK_FILTER_NEAREST;
10916 sampler_ci.minFilter = VK_FILTER_NEAREST;
10917 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
10918 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
10919 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
10920 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
10921 sampler_ci.mipLodBias = 1.0;
10922 sampler_ci.anisotropyEnable = VK_FALSE;
10923 sampler_ci.maxAnisotropy = 1;
10924 sampler_ci.compareEnable = VK_FALSE;
10925 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
10926 sampler_ci.minLod = 1.0;
10927 sampler_ci.maxLod = 1.0;
10928 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
10929 sampler_ci.unnormalizedCoordinates = VK_FALSE;
10930 VkSampler sampler;
10931 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
10932 ASSERT_VK_SUCCESS(err);
10933
10934 VkDescriptorImageInfo info = {};
10935 info.sampler = sampler;
Chia-I Wu9d00ed72015-05-25 16:27:55 +080010936
10937 VkWriteDescriptorSet descriptor_write;
10938 memset(&descriptor_write, 0, sizeof(descriptor_write));
10939 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080010940 descriptor_write.dstSet = descriptorSet;
Chia-I Wud50a7d72015-10-26 20:48:51 +080010941 descriptor_write.descriptorCount = 1;
Tobin Ehlis3b780662015-05-28 12:11:26 -060010942 // This is a mismatched type for the layout which expects BUFFER
Chia-I Wu9d00ed72015-05-25 16:27:55 +080010943 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
Courtney Goeltzenleuchter4cb6d922015-10-23 13:38:14 -060010944 descriptor_write.pImageInfo = &info;
Chia-I Wu9d00ed72015-05-25 16:27:55 +080010945
10946 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
10947
Chris Forbes8f36a8a2016-04-07 13:21:07 +120010948 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -060010949
Chia-I Wuf7458c52015-10-26 21:10:41 +080010950 vkDestroySampler(m_device->device(), sampler, NULL);
10951 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
10952 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis49eb23d2015-05-22 12:38:55 -060010953}
10954
Karl Schultz6addd812016-02-02 17:17:23 -070010955TEST_F(VkLayerTest, DSUpdateOutOfBounds) {
Tobin Ehlis49eb23d2015-05-22 12:38:55 -060010956 // For overlapping Update, have arrayIndex exceed that of layout
Karl Schultz6addd812016-02-02 17:17:23 -070010957 VkResult err;
Tobin Ehlis3b780662015-05-28 12:11:26 -060010958
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010959 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
10960 " binding #0 with 1 total descriptors but update of 1 descriptors "
10961 "starting at binding offset of 0 combined with update array element "
10962 "offset of 1 oversteps the size of this descriptor set.");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060010963
Tobin Ehlis3b780662015-05-28 12:11:26 -060010964 ASSERT_NO_FATAL_FAILURE(InitState());
Karl Schultz6addd812016-02-02 17:17:23 -070010965 // VkDescriptorSetObj descriptorSet(m_device);
Chia-I Wu1b99bb22015-10-27 19:25:11 +080010966 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010967 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
10968 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -060010969
10970 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010971 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
10972 ds_pool_ci.pNext = NULL;
10973 ds_pool_ci.maxSets = 1;
10974 ds_pool_ci.poolSizeCount = 1;
10975 ds_pool_ci.pPoolSizes = &ds_type_count;
Tony Barboureb254902015-07-15 12:50:33 -060010976
Tobin Ehlis3b780662015-05-28 12:11:26 -060010977 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010978 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis3b780662015-05-28 12:11:26 -060010979 ASSERT_VK_SUCCESS(err);
Tobin Ehlis3b780662015-05-28 12:11:26 -060010980
Tony Barboureb254902015-07-15 12:50:33 -060010981 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010982 dsl_binding.binding = 0;
10983 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
10984 dsl_binding.descriptorCount = 1;
10985 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
10986 dsl_binding.pImmutableSamplers = NULL;
Tony Barboureb254902015-07-15 12:50:33 -060010987
10988 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010989 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
10990 ds_layout_ci.pNext = NULL;
10991 ds_layout_ci.bindingCount = 1;
10992 ds_layout_ci.pBindings = &dsl_binding;
Tony Barboureb254902015-07-15 12:50:33 -060010993
Tobin Ehlis3b780662015-05-28 12:11:26 -060010994 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010995 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis3b780662015-05-28 12:11:26 -060010996 ASSERT_VK_SUCCESS(err);
10997
10998 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080010999 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +080011000 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -070011001 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -060011002 alloc_info.descriptorPool = ds_pool;
11003 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011004 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis3b780662015-05-28 12:11:26 -060011005 ASSERT_VK_SUCCESS(err);
Tobin Ehlis3b780662015-05-28 12:11:26 -060011006
Tobin Ehlis30db8f82016-05-05 08:19:48 -060011007 // Correctly update descriptor to avoid "NOT_UPDATED" error
11008 VkDescriptorBufferInfo buff_info = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011009 buff_info.buffer = VkBuffer(0); // Don't care about buffer handle for this test
Tobin Ehlis30db8f82016-05-05 08:19:48 -060011010 buff_info.offset = 0;
11011 buff_info.range = 1024;
Chia-I Wu9d00ed72015-05-25 16:27:55 +080011012
11013 VkWriteDescriptorSet descriptor_write;
11014 memset(&descriptor_write, 0, sizeof(descriptor_write));
11015 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080011016 descriptor_write.dstSet = descriptorSet;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011017 descriptor_write.dstArrayElement = 1; /* This index out of bounds for the update */
Chia-I Wud50a7d72015-10-26 20:48:51 +080011018 descriptor_write.descriptorCount = 1;
Tobin Ehlis0a43bde2016-05-03 08:31:08 -060011019 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
11020 descriptor_write.pBufferInfo = &buff_info;
Chia-I Wu9d00ed72015-05-25 16:27:55 +080011021
11022 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
11023
Chris Forbes8f36a8a2016-04-07 13:21:07 +120011024 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -060011025
Chia-I Wuf7458c52015-10-26 21:10:41 +080011026 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
11027 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis49eb23d2015-05-22 12:38:55 -060011028}
11029
Karl Schultz6addd812016-02-02 17:17:23 -070011030TEST_F(VkLayerTest, InvalidDSUpdateIndex) {
11031 // Create layout w/ count of 1 and attempt update to that layout w/ binding
11032 // index 2
11033 VkResult err;
Tobin Ehlis3b780662015-05-28 12:11:26 -060011034
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011035 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " does not have binding 2.");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060011036
Tobin Ehlis3b780662015-05-28 12:11:26 -060011037 ASSERT_NO_FATAL_FAILURE(InitState());
Karl Schultz6addd812016-02-02 17:17:23 -070011038 // VkDescriptorSetObj descriptorSet(m_device);
Chia-I Wu1b99bb22015-10-27 19:25:11 +080011039 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011040 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
11041 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -060011042
11043 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011044 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
11045 ds_pool_ci.pNext = NULL;
11046 ds_pool_ci.maxSets = 1;
11047 ds_pool_ci.poolSizeCount = 1;
11048 ds_pool_ci.pPoolSizes = &ds_type_count;
Courtney Goeltzenleuchterfe908d32015-09-16 16:12:45 -060011049
Tobin Ehlis3b780662015-05-28 12:11:26 -060011050 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011051 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis3b780662015-05-28 12:11:26 -060011052 ASSERT_VK_SUCCESS(err);
Tobin Ehlis3b780662015-05-28 12:11:26 -060011053
Tony Barboureb254902015-07-15 12:50:33 -060011054 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011055 dsl_binding.binding = 0;
11056 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
11057 dsl_binding.descriptorCount = 1;
11058 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
11059 dsl_binding.pImmutableSamplers = NULL;
Tony Barboureb254902015-07-15 12:50:33 -060011060
11061 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011062 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
11063 ds_layout_ci.pNext = NULL;
11064 ds_layout_ci.bindingCount = 1;
11065 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlis3b780662015-05-28 12:11:26 -060011066 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011067 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis3b780662015-05-28 12:11:26 -060011068 ASSERT_VK_SUCCESS(err);
11069
11070 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080011071 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +080011072 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -070011073 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -060011074 alloc_info.descriptorPool = ds_pool;
11075 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011076 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis3b780662015-05-28 12:11:26 -060011077 ASSERT_VK_SUCCESS(err);
Tobin Ehlis3b780662015-05-28 12:11:26 -060011078
Tony Barboureb254902015-07-15 12:50:33 -060011079 VkSamplerCreateInfo sampler_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011080 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
11081 sampler_ci.pNext = NULL;
11082 sampler_ci.magFilter = VK_FILTER_NEAREST;
11083 sampler_ci.minFilter = VK_FILTER_NEAREST;
11084 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
11085 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
11086 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
11087 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
11088 sampler_ci.mipLodBias = 1.0;
11089 sampler_ci.anisotropyEnable = VK_FALSE;
11090 sampler_ci.maxAnisotropy = 1;
11091 sampler_ci.compareEnable = VK_FALSE;
11092 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
11093 sampler_ci.minLod = 1.0;
11094 sampler_ci.maxLod = 1.0;
11095 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
11096 sampler_ci.unnormalizedCoordinates = VK_FALSE;
Tony Barboureb254902015-07-15 12:50:33 -060011097
Tobin Ehlis3b780662015-05-28 12:11:26 -060011098 VkSampler sampler;
Chia-I Wuf7458c52015-10-26 21:10:41 +080011099 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
Tobin Ehlis3b780662015-05-28 12:11:26 -060011100 ASSERT_VK_SUCCESS(err);
Chia-I Wu9d00ed72015-05-25 16:27:55 +080011101
Courtney Goeltzenleuchter4cb6d922015-10-23 13:38:14 -060011102 VkDescriptorImageInfo info = {};
11103 info.sampler = sampler;
Chia-I Wu9d00ed72015-05-25 16:27:55 +080011104
11105 VkWriteDescriptorSet descriptor_write;
11106 memset(&descriptor_write, 0, sizeof(descriptor_write));
11107 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080011108 descriptor_write.dstSet = descriptorSet;
11109 descriptor_write.dstBinding = 2;
Chia-I Wud50a7d72015-10-26 20:48:51 +080011110 descriptor_write.descriptorCount = 1;
Tobin Ehlis3b780662015-05-28 12:11:26 -060011111 // This is the wrong type, but out of bounds will be flagged first
Chia-I Wu9d00ed72015-05-25 16:27:55 +080011112 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
Courtney Goeltzenleuchter4cb6d922015-10-23 13:38:14 -060011113 descriptor_write.pImageInfo = &info;
Chia-I Wu9d00ed72015-05-25 16:27:55 +080011114
11115 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
11116
Chris Forbes8f36a8a2016-04-07 13:21:07 +120011117 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -060011118
Chia-I Wuf7458c52015-10-26 21:10:41 +080011119 vkDestroySampler(m_device->device(), sampler, NULL);
11120 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
11121 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis49eb23d2015-05-22 12:38:55 -060011122}
11123
Karl Schultz6addd812016-02-02 17:17:23 -070011124TEST_F(VkLayerTest, InvalidDSUpdateStruct) {
11125 // Call UpdateDS w/ struct type other than valid VK_STRUCTUR_TYPE_UPDATE_*
11126 // types
11127 VkResult err;
Tobin Ehlis3b780662015-05-28 12:11:26 -060011128
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011129 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 -060011130
Tobin Ehlis3b780662015-05-28 12:11:26 -060011131 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinski209b5292015-09-17 09:44:05 -060011132
Chia-I Wu1b99bb22015-10-27 19:25:11 +080011133 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011134 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
11135 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -060011136
11137 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011138 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
11139 ds_pool_ci.pNext = NULL;
11140 ds_pool_ci.maxSets = 1;
11141 ds_pool_ci.poolSizeCount = 1;
11142 ds_pool_ci.pPoolSizes = &ds_type_count;
Courtney Goeltzenleuchterfe908d32015-09-16 16:12:45 -060011143
Tobin Ehlis3b780662015-05-28 12:11:26 -060011144 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011145 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis3b780662015-05-28 12:11:26 -060011146 ASSERT_VK_SUCCESS(err);
Tony Barboureb254902015-07-15 12:50:33 -060011147 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011148 dsl_binding.binding = 0;
11149 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
11150 dsl_binding.descriptorCount = 1;
11151 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
11152 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis3b780662015-05-28 12:11:26 -060011153
Tony Barboureb254902015-07-15 12:50:33 -060011154 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011155 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
11156 ds_layout_ci.pNext = NULL;
11157 ds_layout_ci.bindingCount = 1;
11158 ds_layout_ci.pBindings = &dsl_binding;
Tony Barboureb254902015-07-15 12:50:33 -060011159
Tobin Ehlis3b780662015-05-28 12:11:26 -060011160 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011161 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis3b780662015-05-28 12:11:26 -060011162 ASSERT_VK_SUCCESS(err);
11163
11164 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080011165 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +080011166 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -070011167 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -060011168 alloc_info.descriptorPool = ds_pool;
11169 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011170 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis3b780662015-05-28 12:11:26 -060011171 ASSERT_VK_SUCCESS(err);
Tobin Ehlis3b780662015-05-28 12:11:26 -060011172
Tony Barboureb254902015-07-15 12:50:33 -060011173 VkSamplerCreateInfo sampler_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011174 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
11175 sampler_ci.pNext = NULL;
11176 sampler_ci.magFilter = VK_FILTER_NEAREST;
11177 sampler_ci.minFilter = VK_FILTER_NEAREST;
11178 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
11179 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
11180 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
11181 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
11182 sampler_ci.mipLodBias = 1.0;
11183 sampler_ci.anisotropyEnable = VK_FALSE;
11184 sampler_ci.maxAnisotropy = 1;
11185 sampler_ci.compareEnable = VK_FALSE;
11186 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
11187 sampler_ci.minLod = 1.0;
11188 sampler_ci.maxLod = 1.0;
11189 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
11190 sampler_ci.unnormalizedCoordinates = VK_FALSE;
Tobin Ehlis3b780662015-05-28 12:11:26 -060011191 VkSampler sampler;
Chia-I Wuf7458c52015-10-26 21:10:41 +080011192 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
Tobin Ehlis3b780662015-05-28 12:11:26 -060011193 ASSERT_VK_SUCCESS(err);
Chia-I Wu9d00ed72015-05-25 16:27:55 +080011194
Courtney Goeltzenleuchter4cb6d922015-10-23 13:38:14 -060011195 VkDescriptorImageInfo info = {};
11196 info.sampler = sampler;
Chia-I Wu9d00ed72015-05-25 16:27:55 +080011197
11198 VkWriteDescriptorSet descriptor_write;
11199 memset(&descriptor_write, 0, sizeof(descriptor_write));
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011200 descriptor_write.sType = (VkStructureType)0x99999999; /* Intentionally broken struct type */
Chia-I Wu3432a0c2015-10-27 18:04:07 +080011201 descriptor_write.dstSet = descriptorSet;
Chia-I Wud50a7d72015-10-26 20:48:51 +080011202 descriptor_write.descriptorCount = 1;
Tobin Ehlis3b780662015-05-28 12:11:26 -060011203 // This is the wrong type, but out of bounds will be flagged first
Chia-I Wu9d00ed72015-05-25 16:27:55 +080011204 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
Courtney Goeltzenleuchter4cb6d922015-10-23 13:38:14 -060011205 descriptor_write.pImageInfo = &info;
Chia-I Wu9d00ed72015-05-25 16:27:55 +080011206
11207 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
11208
Chris Forbes8f36a8a2016-04-07 13:21:07 +120011209 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -060011210
Chia-I Wuf7458c52015-10-26 21:10:41 +080011211 vkDestroySampler(m_device->device(), sampler, NULL);
11212 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
11213 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis49eb23d2015-05-22 12:38:55 -060011214}
11215
Karl Schultz6addd812016-02-02 17:17:23 -070011216TEST_F(VkLayerTest, SampleDescriptorUpdateError) {
Tobin Ehlisa1c28562015-10-23 16:00:08 -060011217 // Create a single Sampler descriptor and send it an invalid Sampler
Karl Schultz6addd812016-02-02 17:17:23 -070011218 VkResult err;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060011219
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011220 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
11221 "Attempted write update to sampler descriptor with invalid sampler");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060011222
Tobin Ehlisa1c28562015-10-23 16:00:08 -060011223 ASSERT_NO_FATAL_FAILURE(InitState());
Karl Schultz6addd812016-02-02 17:17:23 -070011224 // TODO : Farm Descriptor setup code to helper function(s) to reduce copied
11225 // code
Chia-I Wu1b99bb22015-10-27 19:25:11 +080011226 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011227 ds_type_count.type = VK_DESCRIPTOR_TYPE_SAMPLER;
11228 ds_type_count.descriptorCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060011229
11230 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011231 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
11232 ds_pool_ci.pNext = NULL;
11233 ds_pool_ci.maxSets = 1;
11234 ds_pool_ci.poolSizeCount = 1;
11235 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060011236
11237 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011238 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060011239 ASSERT_VK_SUCCESS(err);
11240
11241 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011242 dsl_binding.binding = 0;
11243 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
11244 dsl_binding.descriptorCount = 1;
11245 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
11246 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060011247
11248 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011249 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
11250 ds_layout_ci.pNext = NULL;
11251 ds_layout_ci.bindingCount = 1;
11252 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060011253 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011254 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060011255 ASSERT_VK_SUCCESS(err);
11256
11257 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080011258 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +080011259 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -070011260 alloc_info.descriptorSetCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060011261 alloc_info.descriptorPool = ds_pool;
11262 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011263 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060011264 ASSERT_VK_SUCCESS(err);
11265
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011266 VkSampler sampler = (VkSampler)((size_t)0xbaadbeef); // Sampler with invalid handle
Tobin Ehlisa1c28562015-10-23 16:00:08 -060011267
11268 VkDescriptorImageInfo descriptor_info;
11269 memset(&descriptor_info, 0, sizeof(VkDescriptorImageInfo));
11270 descriptor_info.sampler = sampler;
11271
11272 VkWriteDescriptorSet descriptor_write;
11273 memset(&descriptor_write, 0, sizeof(descriptor_write));
11274 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080011275 descriptor_write.dstSet = descriptorSet;
11276 descriptor_write.dstBinding = 0;
Chia-I Wud50a7d72015-10-26 20:48:51 +080011277 descriptor_write.descriptorCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060011278 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
11279 descriptor_write.pImageInfo = &descriptor_info;
11280
11281 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
11282
Chris Forbes8f36a8a2016-04-07 13:21:07 +120011283 m_errorMonitor->VerifyFound();
Tobin Ehlisa1c28562015-10-23 16:00:08 -060011284
Chia-I Wuf7458c52015-10-26 21:10:41 +080011285 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
11286 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060011287}
11288
Karl Schultz6addd812016-02-02 17:17:23 -070011289TEST_F(VkLayerTest, ImageViewDescriptorUpdateError) {
11290 // Create a single combined Image/Sampler descriptor and send it an invalid
11291 // imageView
11292 VkResult err;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060011293
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011294 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Attempted write update to combined "
11295 "image sampler descriptor failed due "
11296 "to: Invalid VkImageView:");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060011297
Tobin Ehlisa1c28562015-10-23 16:00:08 -060011298 ASSERT_NO_FATAL_FAILURE(InitState());
Chia-I Wu1b99bb22015-10-27 19:25:11 +080011299 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011300 ds_type_count.type = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
11301 ds_type_count.descriptorCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060011302
11303 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011304 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
11305 ds_pool_ci.pNext = NULL;
11306 ds_pool_ci.maxSets = 1;
11307 ds_pool_ci.poolSizeCount = 1;
11308 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060011309
11310 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011311 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060011312 ASSERT_VK_SUCCESS(err);
11313
11314 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011315 dsl_binding.binding = 0;
11316 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
11317 dsl_binding.descriptorCount = 1;
11318 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
11319 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060011320
11321 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011322 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
11323 ds_layout_ci.pNext = NULL;
11324 ds_layout_ci.bindingCount = 1;
11325 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060011326 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011327 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060011328 ASSERT_VK_SUCCESS(err);
11329
11330 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080011331 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +080011332 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -070011333 alloc_info.descriptorSetCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060011334 alloc_info.descriptorPool = ds_pool;
11335 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011336 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060011337 ASSERT_VK_SUCCESS(err);
11338
11339 VkSamplerCreateInfo sampler_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011340 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
11341 sampler_ci.pNext = NULL;
11342 sampler_ci.magFilter = VK_FILTER_NEAREST;
11343 sampler_ci.minFilter = VK_FILTER_NEAREST;
11344 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
11345 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
11346 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
11347 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
11348 sampler_ci.mipLodBias = 1.0;
11349 sampler_ci.anisotropyEnable = VK_FALSE;
11350 sampler_ci.maxAnisotropy = 1;
11351 sampler_ci.compareEnable = VK_FALSE;
11352 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
11353 sampler_ci.minLod = 1.0;
11354 sampler_ci.maxLod = 1.0;
11355 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
11356 sampler_ci.unnormalizedCoordinates = VK_FALSE;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060011357
11358 VkSampler sampler;
Chia-I Wuf7458c52015-10-26 21:10:41 +080011359 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060011360 ASSERT_VK_SUCCESS(err);
11361
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011362 VkImageView view = (VkImageView)((size_t)0xbaadbeef); // invalid imageView object
Tobin Ehlisa1c28562015-10-23 16:00:08 -060011363
11364 VkDescriptorImageInfo descriptor_info;
11365 memset(&descriptor_info, 0, sizeof(VkDescriptorImageInfo));
11366 descriptor_info.sampler = sampler;
11367 descriptor_info.imageView = view;
11368
11369 VkWriteDescriptorSet descriptor_write;
11370 memset(&descriptor_write, 0, sizeof(descriptor_write));
11371 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080011372 descriptor_write.dstSet = descriptorSet;
11373 descriptor_write.dstBinding = 0;
Chia-I Wud50a7d72015-10-26 20:48:51 +080011374 descriptor_write.descriptorCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060011375 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
11376 descriptor_write.pImageInfo = &descriptor_info;
11377
11378 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
11379
Chris Forbes8f36a8a2016-04-07 13:21:07 +120011380 m_errorMonitor->VerifyFound();
Tobin Ehlisa1c28562015-10-23 16:00:08 -060011381
Chia-I Wuf7458c52015-10-26 21:10:41 +080011382 vkDestroySampler(m_device->device(), sampler, NULL);
11383 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
11384 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060011385}
11386
Karl Schultz6addd812016-02-02 17:17:23 -070011387TEST_F(VkLayerTest, CopyDescriptorUpdateErrors) {
11388 // Create DS w/ layout of 2 types, write update 1 and attempt to copy-update
11389 // into the other
11390 VkResult err;
Tobin Ehlis04356f92015-10-27 16:35:27 -060011391
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011392 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " binding #1 with type "
11393 "VK_DESCRIPTOR_TYPE_SAMPLER. Types do "
11394 "not match.");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060011395
Tobin Ehlis04356f92015-10-27 16:35:27 -060011396 ASSERT_NO_FATAL_FAILURE(InitState());
Karl Schultz6addd812016-02-02 17:17:23 -070011397 // VkDescriptorSetObj descriptorSet(m_device);
Chia-I Wu1b99bb22015-10-27 19:25:11 +080011398 VkDescriptorPoolSize ds_type_count[2] = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011399 ds_type_count[0].type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
11400 ds_type_count[0].descriptorCount = 1;
11401 ds_type_count[1].type = VK_DESCRIPTOR_TYPE_SAMPLER;
11402 ds_type_count[1].descriptorCount = 1;
Tobin Ehlis04356f92015-10-27 16:35:27 -060011403
11404 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011405 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
11406 ds_pool_ci.pNext = NULL;
11407 ds_pool_ci.maxSets = 1;
11408 ds_pool_ci.poolSizeCount = 2;
11409 ds_pool_ci.pPoolSizes = ds_type_count;
Tobin Ehlis04356f92015-10-27 16:35:27 -060011410
11411 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011412 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis04356f92015-10-27 16:35:27 -060011413 ASSERT_VK_SUCCESS(err);
11414 VkDescriptorSetLayoutBinding dsl_binding[2] = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011415 dsl_binding[0].binding = 0;
11416 dsl_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
11417 dsl_binding[0].descriptorCount = 1;
11418 dsl_binding[0].stageFlags = VK_SHADER_STAGE_ALL;
11419 dsl_binding[0].pImmutableSamplers = NULL;
11420 dsl_binding[1].binding = 1;
11421 dsl_binding[1].descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
11422 dsl_binding[1].descriptorCount = 1;
11423 dsl_binding[1].stageFlags = VK_SHADER_STAGE_ALL;
11424 dsl_binding[1].pImmutableSamplers = NULL;
Tobin Ehlis04356f92015-10-27 16:35:27 -060011425
11426 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011427 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
11428 ds_layout_ci.pNext = NULL;
11429 ds_layout_ci.bindingCount = 2;
11430 ds_layout_ci.pBindings = dsl_binding;
Tobin Ehlis04356f92015-10-27 16:35:27 -060011431
11432 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011433 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis04356f92015-10-27 16:35:27 -060011434 ASSERT_VK_SUCCESS(err);
11435
11436 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080011437 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +080011438 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -070011439 alloc_info.descriptorSetCount = 1;
Tobin Ehlis04356f92015-10-27 16:35:27 -060011440 alloc_info.descriptorPool = ds_pool;
11441 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011442 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis04356f92015-10-27 16:35:27 -060011443 ASSERT_VK_SUCCESS(err);
11444
11445 VkSamplerCreateInfo sampler_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011446 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
11447 sampler_ci.pNext = NULL;
11448 sampler_ci.magFilter = VK_FILTER_NEAREST;
11449 sampler_ci.minFilter = VK_FILTER_NEAREST;
11450 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
11451 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
11452 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
11453 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
11454 sampler_ci.mipLodBias = 1.0;
11455 sampler_ci.anisotropyEnable = VK_FALSE;
11456 sampler_ci.maxAnisotropy = 1;
11457 sampler_ci.compareEnable = VK_FALSE;
11458 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
11459 sampler_ci.minLod = 1.0;
11460 sampler_ci.maxLod = 1.0;
11461 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
11462 sampler_ci.unnormalizedCoordinates = VK_FALSE;
Tobin Ehlis04356f92015-10-27 16:35:27 -060011463
11464 VkSampler sampler;
Chia-I Wuf7458c52015-10-26 21:10:41 +080011465 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
Tobin Ehlis04356f92015-10-27 16:35:27 -060011466 ASSERT_VK_SUCCESS(err);
11467
11468 VkDescriptorImageInfo info = {};
11469 info.sampler = sampler;
11470
11471 VkWriteDescriptorSet descriptor_write;
11472 memset(&descriptor_write, 0, sizeof(VkWriteDescriptorSet));
11473 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080011474 descriptor_write.dstSet = descriptorSet;
11475 descriptor_write.dstBinding = 1; // SAMPLER binding from layout above
Chia-I Wud50a7d72015-10-26 20:48:51 +080011476 descriptor_write.descriptorCount = 1;
Tobin Ehlis04356f92015-10-27 16:35:27 -060011477 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
11478 descriptor_write.pImageInfo = &info;
11479 // This write update should succeed
11480 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
11481 // Now perform a copy update that fails due to type mismatch
11482 VkCopyDescriptorSet copy_ds_update;
11483 memset(&copy_ds_update, 0, sizeof(VkCopyDescriptorSet));
11484 copy_ds_update.sType = VK_STRUCTURE_TYPE_COPY_DESCRIPTOR_SET;
11485 copy_ds_update.srcSet = descriptorSet;
Mark Young29927482016-05-04 14:38:51 -060011486 copy_ds_update.srcBinding = 1; // Copy from SAMPLER binding
Chia-I Wu3432a0c2015-10-27 18:04:07 +080011487 copy_ds_update.dstSet = descriptorSet;
Karl Schultz6addd812016-02-02 17:17:23 -070011488 copy_ds_update.dstBinding = 0; // ERROR : copy to UNIFORM binding
Chia-I Wud50a7d72015-10-26 20:48:51 +080011489 copy_ds_update.descriptorCount = 1; // copy 1 descriptor
Tobin Ehlis04356f92015-10-27 16:35:27 -060011490 vkUpdateDescriptorSets(m_device->device(), 0, NULL, 1, &copy_ds_update);
11491
Chris Forbes8f36a8a2016-04-07 13:21:07 +120011492 m_errorMonitor->VerifyFound();
Tobin Ehlis04356f92015-10-27 16:35:27 -060011493 // Now perform a copy update that fails due to binding out of bounds
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011494 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 -060011495 memset(&copy_ds_update, 0, sizeof(VkCopyDescriptorSet));
11496 copy_ds_update.sType = VK_STRUCTURE_TYPE_COPY_DESCRIPTOR_SET;
11497 copy_ds_update.srcSet = descriptorSet;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011498 copy_ds_update.srcBinding = 3; // ERROR : Invalid binding for matching layout
Chia-I Wu3432a0c2015-10-27 18:04:07 +080011499 copy_ds_update.dstSet = descriptorSet;
11500 copy_ds_update.dstBinding = 0;
Mark Young29927482016-05-04 14:38:51 -060011501 copy_ds_update.descriptorCount = 1; // Copy 1 descriptor
Tobin Ehlis04356f92015-10-27 16:35:27 -060011502 vkUpdateDescriptorSets(m_device->device(), 0, NULL, 1, &copy_ds_update);
11503
Chris Forbes8f36a8a2016-04-07 13:21:07 +120011504 m_errorMonitor->VerifyFound();
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060011505
Tobin Ehlis04356f92015-10-27 16:35:27 -060011506 // Now perform a copy update that fails due to binding out of bounds
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011507 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " binding#1 with offset index of 1 plus "
11508 "update array offset of 0 and update of "
11509 "5 descriptors oversteps total number "
11510 "of descriptors in set: 2.");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060011511
Tobin Ehlis04356f92015-10-27 16:35:27 -060011512 memset(&copy_ds_update, 0, sizeof(VkCopyDescriptorSet));
11513 copy_ds_update.sType = VK_STRUCTURE_TYPE_COPY_DESCRIPTOR_SET;
11514 copy_ds_update.srcSet = descriptorSet;
11515 copy_ds_update.srcBinding = 1;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080011516 copy_ds_update.dstSet = descriptorSet;
11517 copy_ds_update.dstBinding = 0;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011518 copy_ds_update.descriptorCount = 5; // ERROR copy 5 descriptors (out of bounds for layout)
Tobin Ehlis04356f92015-10-27 16:35:27 -060011519 vkUpdateDescriptorSets(m_device->device(), 0, NULL, 1, &copy_ds_update);
11520
Chris Forbes8f36a8a2016-04-07 13:21:07 +120011521 m_errorMonitor->VerifyFound();
Tobin Ehlis04356f92015-10-27 16:35:27 -060011522
Chia-I Wuf7458c52015-10-26 21:10:41 +080011523 vkDestroySampler(m_device->device(), sampler, NULL);
11524 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
11525 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis04356f92015-10-27 16:35:27 -060011526}
11527
Karl Schultz6addd812016-02-02 17:17:23 -070011528TEST_F(VkLayerTest, NumSamplesMismatch) {
11529 // Create CommandBuffer where MSAA samples doesn't match RenderPass
11530 // sampleCount
11531 VkResult err;
Tobin Ehlis3b780662015-05-28 12:11:26 -060011532
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011533 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Num samples mismatch! ");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060011534
Tobin Ehlis3b780662015-05-28 12:11:26 -060011535 ASSERT_NO_FATAL_FAILURE(InitState());
11536 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chia-I Wu1b99bb22015-10-27 19:25:11 +080011537 VkDescriptorPoolSize ds_type_count = {};
Tony Barboureb254902015-07-15 12:50:33 -060011538 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Chia-I Wud50a7d72015-10-26 20:48:51 +080011539 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -060011540
11541 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011542 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
11543 ds_pool_ci.pNext = NULL;
11544 ds_pool_ci.maxSets = 1;
11545 ds_pool_ci.poolSizeCount = 1;
11546 ds_pool_ci.pPoolSizes = &ds_type_count;
Courtney Goeltzenleuchterfe908d32015-09-16 16:12:45 -060011547
Tobin Ehlis3b780662015-05-28 12:11:26 -060011548 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011549 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis3b780662015-05-28 12:11:26 -060011550 ASSERT_VK_SUCCESS(err);
Tobin Ehlis3b780662015-05-28 12:11:26 -060011551
Tony Barboureb254902015-07-15 12:50:33 -060011552 VkDescriptorSetLayoutBinding dsl_binding = {};
Chia-I Wud46e6ae2015-10-31 00:31:16 +080011553 dsl_binding.binding = 0;
Tony Barboureb254902015-07-15 12:50:33 -060011554 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Chia-I Wu02124482015-11-06 06:42:02 +080011555 dsl_binding.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -060011556 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
11557 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis3b780662015-05-28 12:11:26 -060011558
Tony Barboureb254902015-07-15 12:50:33 -060011559 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
11560 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
11561 ds_layout_ci.pNext = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +080011562 ds_layout_ci.bindingCount = 1;
Jon Ashburn6e23c1f2015-12-30 18:01:16 -070011563 ds_layout_ci.pBindings = &dsl_binding;
Tony Barboureb254902015-07-15 12:50:33 -060011564
Tobin Ehlis3b780662015-05-28 12:11:26 -060011565 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011566 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis3b780662015-05-28 12:11:26 -060011567 ASSERT_VK_SUCCESS(err);
11568
11569 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080011570 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +080011571 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -070011572 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -060011573 alloc_info.descriptorPool = ds_pool;
11574 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011575 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis3b780662015-05-28 12:11:26 -060011576 ASSERT_VK_SUCCESS(err);
11577
Tony Barboureb254902015-07-15 12:50:33 -060011578 VkPipelineMultisampleStateCreateInfo pipe_ms_state_ci = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011579 pipe_ms_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
Karl Schultz6addd812016-02-02 17:17:23 -070011580 pipe_ms_state_ci.pNext = NULL;
11581 pipe_ms_state_ci.rasterizationSamples = VK_SAMPLE_COUNT_4_BIT;
11582 pipe_ms_state_ci.sampleShadingEnable = 0;
11583 pipe_ms_state_ci.minSampleShading = 1.0;
11584 pipe_ms_state_ci.pSampleMask = NULL;
Tobin Ehlis3b780662015-05-28 12:11:26 -060011585
Tony Barboureb254902015-07-15 12:50:33 -060011586 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011587 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
11588 pipeline_layout_ci.pNext = NULL;
11589 pipeline_layout_ci.setLayoutCount = 1;
11590 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlis3b780662015-05-28 12:11:26 -060011591
11592 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011593 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis3b780662015-05-28 12:11:26 -060011594 ASSERT_VK_SUCCESS(err);
11595
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011596 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
11597 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this); // We shouldn't need a fragment shader
11598 // but add it to be able to run on more devices
Tony Barbour62e1a5b2015-08-06 10:16:07 -060011599 VkPipelineObj pipe(m_device);
11600 pipe.AddShader(&vs);
Tony Barbour1c94d372015-08-06 11:21:08 -060011601 pipe.AddShader(&fs);
Mark Youngc89c6312016-03-31 16:03:20 -060011602 pipe.AddColorAttachment();
Tony Barbour62e1a5b2015-08-06 10:16:07 -060011603 pipe.SetMSAA(&pipe_ms_state_ci);
11604 pipe.CreateVKPipeline(pipeline_layout, renderPass());
Tobin Ehlis3b780662015-05-28 12:11:26 -060011605
Tony Barbourfe3351b2015-07-28 10:17:20 -060011606 BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011607 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Tobin Ehlis3b780662015-05-28 12:11:26 -060011608
Mark Young29927482016-05-04 14:38:51 -060011609 // Render triangle (the error should trigger on the attempt to draw).
11610 Draw(3, 1, 0, 0);
11611
11612 // Finalize recording of the command buffer
11613 EndCommandBuffer();
11614
Chris Forbes8f36a8a2016-04-07 13:21:07 +120011615 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -060011616
Chia-I Wuf7458c52015-10-26 21:10:41 +080011617 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
11618 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
11619 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis49eb23d2015-05-22 12:38:55 -060011620}
Mark Young29927482016-05-04 14:38:51 -060011621
Tobin Ehlis85aa15a2016-06-15 10:52:37 -060011622TEST_F(VkLayerTest, RenderPassIncompatible) {
11623 TEST_DESCRIPTION("Hit RenderPass incompatible cases. "
11624 "Initial case is drawing with an active renderpass that's "
11625 "not compatible with the bound PSO's creation renderpass");
11626 VkResult err;
11627
11628 ASSERT_NO_FATAL_FAILURE(InitState());
11629 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
11630
11631 VkDescriptorSetLayoutBinding dsl_binding = {};
11632 dsl_binding.binding = 0;
11633 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
11634 dsl_binding.descriptorCount = 1;
11635 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
11636 dsl_binding.pImmutableSamplers = NULL;
11637
11638 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
11639 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
11640 ds_layout_ci.pNext = NULL;
11641 ds_layout_ci.bindingCount = 1;
11642 ds_layout_ci.pBindings = &dsl_binding;
11643
11644 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011645 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis85aa15a2016-06-15 10:52:37 -060011646 ASSERT_VK_SUCCESS(err);
11647
11648 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
11649 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
11650 pipeline_layout_ci.pNext = NULL;
11651 pipeline_layout_ci.setLayoutCount = 1;
11652 pipeline_layout_ci.pSetLayouts = &ds_layout;
11653
11654 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011655 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis85aa15a2016-06-15 10:52:37 -060011656 ASSERT_VK_SUCCESS(err);
11657
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011658 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
11659 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this); // We shouldn't need a fragment shader
11660 // but add it to be able to run on more devices
Tobin Ehlis85aa15a2016-06-15 10:52:37 -060011661 // Create a renderpass that will be incompatible with default renderpass
11662 VkAttachmentReference attach = {};
11663 attach.layout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
11664 VkAttachmentReference color_att = {};
11665 color_att.layout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
11666 VkSubpassDescription subpass = {};
11667 subpass.inputAttachmentCount = 1;
11668 subpass.pInputAttachments = &attach;
11669 subpass.colorAttachmentCount = 1;
11670 subpass.pColorAttachments = &color_att;
11671 VkRenderPassCreateInfo rpci = {};
11672 rpci.subpassCount = 1;
11673 rpci.pSubpasses = &subpass;
11674 rpci.attachmentCount = 1;
11675 VkAttachmentDescription attach_desc = {};
11676 attach_desc.samples = VK_SAMPLE_COUNT_1_BIT;
Cody Northropbd16af12016-06-21 09:25:48 -060011677 // Format incompatible with PSO RP color attach format B8G8R8A8_UNORM
11678 attach_desc.format = VK_FORMAT_R8G8B8A8_UNORM;
Tobin Ehlis85aa15a2016-06-15 10:52:37 -060011679 rpci.pAttachments = &attach_desc;
11680 rpci.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
11681 VkRenderPass rp;
11682 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
11683 VkPipelineObj pipe(m_device);
11684 pipe.AddShader(&vs);
11685 pipe.AddShader(&fs);
11686 pipe.AddColorAttachment();
11687 VkViewport view_port = {};
11688 m_viewports.push_back(view_port);
11689 pipe.SetViewport(m_viewports);
11690 VkRect2D rect = {};
11691 m_scissors.push_back(rect);
11692 pipe.SetScissor(m_scissors);
11693 pipe.CreateVKPipeline(pipeline_layout, renderPass());
11694
11695 VkCommandBufferInheritanceInfo cbii = {};
11696 cbii.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_INHERITANCE_INFO;
11697 cbii.renderPass = rp;
11698 cbii.subpass = 0;
11699 VkCommandBufferBeginInfo cbbi = {};
11700 cbbi.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
11701 cbbi.pInheritanceInfo = &cbii;
11702 vkBeginCommandBuffer(m_commandBuffer->handle(), &cbbi);
11703 VkRenderPassBeginInfo rpbi = {};
11704 rpbi.sType = VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO;
11705 rpbi.framebuffer = m_framebuffer;
11706 rpbi.renderPass = rp;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011707 vkCmdBeginRenderPass(m_commandBuffer->GetBufferHandle(), &rpbi, VK_SUBPASS_CONTENTS_INLINE);
11708 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Tobin Ehlis85aa15a2016-06-15 10:52:37 -060011709
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011710 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " is incompatible w/ gfx pipeline ");
Tobin Ehlis85aa15a2016-06-15 10:52:37 -060011711 // Render triangle (the error should trigger on the attempt to draw).
11712 Draw(3, 1, 0, 0);
11713
11714 // Finalize recording of the command buffer
11715 EndCommandBuffer();
11716
11717 m_errorMonitor->VerifyFound();
11718
11719 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
11720 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
11721 vkDestroyRenderPass(m_device->device(), rp, NULL);
11722}
11723
Mark Youngc89c6312016-03-31 16:03:20 -060011724TEST_F(VkLayerTest, NumBlendAttachMismatch) {
11725 // Create Pipeline where the number of blend attachments doesn't match the
11726 // number of color attachments. In this case, we don't add any color
11727 // blend attachments even though we have a color attachment.
11728 VkResult err;
11729
11730 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011731 "Render pass subpass 0 mismatch with blending state defined and blend state attachment");
Mark Youngc89c6312016-03-31 16:03:20 -060011732
11733 ASSERT_NO_FATAL_FAILURE(InitState());
11734 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
11735 VkDescriptorPoolSize ds_type_count = {};
11736 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
11737 ds_type_count.descriptorCount = 1;
11738
11739 VkDescriptorPoolCreateInfo ds_pool_ci = {};
11740 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
11741 ds_pool_ci.pNext = NULL;
11742 ds_pool_ci.maxSets = 1;
11743 ds_pool_ci.poolSizeCount = 1;
11744 ds_pool_ci.pPoolSizes = &ds_type_count;
11745
11746 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011747 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Mark Youngc89c6312016-03-31 16:03:20 -060011748 ASSERT_VK_SUCCESS(err);
11749
11750 VkDescriptorSetLayoutBinding dsl_binding = {};
11751 dsl_binding.binding = 0;
11752 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
11753 dsl_binding.descriptorCount = 1;
11754 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
11755 dsl_binding.pImmutableSamplers = NULL;
11756
11757 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
11758 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
11759 ds_layout_ci.pNext = NULL;
11760 ds_layout_ci.bindingCount = 1;
11761 ds_layout_ci.pBindings = &dsl_binding;
11762
11763 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011764 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Mark Youngc89c6312016-03-31 16:03:20 -060011765 ASSERT_VK_SUCCESS(err);
11766
11767 VkDescriptorSet descriptorSet;
11768 VkDescriptorSetAllocateInfo alloc_info = {};
11769 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
11770 alloc_info.descriptorSetCount = 1;
11771 alloc_info.descriptorPool = ds_pool;
11772 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011773 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Mark Youngc89c6312016-03-31 16:03:20 -060011774 ASSERT_VK_SUCCESS(err);
11775
11776 VkPipelineMultisampleStateCreateInfo pipe_ms_state_ci = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011777 pipe_ms_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
Mark Youngc89c6312016-03-31 16:03:20 -060011778 pipe_ms_state_ci.pNext = NULL;
11779 pipe_ms_state_ci.rasterizationSamples = VK_SAMPLE_COUNT_1_BIT;
11780 pipe_ms_state_ci.sampleShadingEnable = 0;
11781 pipe_ms_state_ci.minSampleShading = 1.0;
11782 pipe_ms_state_ci.pSampleMask = NULL;
11783
11784 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
11785 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
11786 pipeline_layout_ci.pNext = NULL;
11787 pipeline_layout_ci.setLayoutCount = 1;
11788 pipeline_layout_ci.pSetLayouts = &ds_layout;
11789
11790 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011791 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Mark Youngc89c6312016-03-31 16:03:20 -060011792 ASSERT_VK_SUCCESS(err);
11793
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011794 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
11795 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this); // We shouldn't need a fragment shader
11796 // but add it to be able to run on more devices
Mark Youngc89c6312016-03-31 16:03:20 -060011797 VkPipelineObj pipe(m_device);
11798 pipe.AddShader(&vs);
11799 pipe.AddShader(&fs);
11800 pipe.SetMSAA(&pipe_ms_state_ci);
11801 pipe.CreateVKPipeline(pipeline_layout, renderPass());
11802
11803 BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011804 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Mark Youngc89c6312016-03-31 16:03:20 -060011805
Mark Young29927482016-05-04 14:38:51 -060011806 // Render triangle (the error should trigger on the attempt to draw).
11807 Draw(3, 1, 0, 0);
11808
11809 // Finalize recording of the command buffer
11810 EndCommandBuffer();
11811
Chris Forbes8f36a8a2016-04-07 13:21:07 +120011812 m_errorMonitor->VerifyFound();
Mark Youngc89c6312016-03-31 16:03:20 -060011813
11814 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
11815 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
11816 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
11817}
Mark Young29927482016-05-04 14:38:51 -060011818
Mark Muellerd4914412016-06-13 17:52:06 -060011819TEST_F(VkLayerTest, MissingClearAttachment) {
11820 TEST_DESCRIPTION("Points to a wrong colorAttachment index in a VkClearAttachment "
11821 "structure passed to vkCmdClearAttachments");
Cody Northropc31a84f2016-08-22 10:41:47 -060011822 ASSERT_NO_FATAL_FAILURE(InitState());
Chris Forbesda6ae6f2016-09-09 14:36:33 +120011823 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Chris Forbesef5e2842016-09-08 15:25:24 +120011824 "vkCmdClearAttachments() color attachment index 1 out of range for active subpass 0; ignored");
Mark Muellerd4914412016-06-13 17:52:06 -060011825
11826 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailCmdClearAttachments);
11827 m_errorMonitor->VerifyFound();
11828}
11829
Karl Schultz6addd812016-02-02 17:17:23 -070011830TEST_F(VkLayerTest, ClearCmdNoDraw) {
11831 // Create CommandBuffer where we add ClearCmd for FB Color attachment prior
11832 // to issuing a Draw
11833 VkResult err;
Tobin Ehlis53eddda2015-07-01 16:46:13 -060011834
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011835 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
11836 "vkCmdClearAttachments() issued on CB object ");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060011837
Tobin Ehlis53eddda2015-07-01 16:46:13 -060011838 ASSERT_NO_FATAL_FAILURE(InitState());
11839 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barboureb254902015-07-15 12:50:33 -060011840
Chia-I Wu1b99bb22015-10-27 19:25:11 +080011841 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011842 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
11843 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -060011844
11845 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011846 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
11847 ds_pool_ci.pNext = NULL;
11848 ds_pool_ci.maxSets = 1;
11849 ds_pool_ci.poolSizeCount = 1;
11850 ds_pool_ci.pPoolSizes = &ds_type_count;
Tony Barboureb254902015-07-15 12:50:33 -060011851
Tobin Ehlis53eddda2015-07-01 16:46:13 -060011852 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011853 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis53eddda2015-07-01 16:46:13 -060011854 ASSERT_VK_SUCCESS(err);
11855
Tony Barboureb254902015-07-15 12:50:33 -060011856 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011857 dsl_binding.binding = 0;
11858 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
11859 dsl_binding.descriptorCount = 1;
11860 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
11861 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis53eddda2015-07-01 16:46:13 -060011862
Tony Barboureb254902015-07-15 12:50:33 -060011863 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011864 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
11865 ds_layout_ci.pNext = NULL;
11866 ds_layout_ci.bindingCount = 1;
11867 ds_layout_ci.pBindings = &dsl_binding;
Mark Lobodzinski209b5292015-09-17 09:44:05 -060011868
Tobin Ehlis53eddda2015-07-01 16:46:13 -060011869 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011870 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis53eddda2015-07-01 16:46:13 -060011871 ASSERT_VK_SUCCESS(err);
11872
11873 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080011874 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +080011875 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -070011876 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -060011877 alloc_info.descriptorPool = ds_pool;
11878 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011879 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis53eddda2015-07-01 16:46:13 -060011880 ASSERT_VK_SUCCESS(err);
11881
Tony Barboureb254902015-07-15 12:50:33 -060011882 VkPipelineMultisampleStateCreateInfo pipe_ms_state_ci = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011883 pipe_ms_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
Karl Schultz6addd812016-02-02 17:17:23 -070011884 pipe_ms_state_ci.pNext = NULL;
11885 pipe_ms_state_ci.rasterizationSamples = VK_SAMPLE_COUNT_4_BIT;
11886 pipe_ms_state_ci.sampleShadingEnable = 0;
11887 pipe_ms_state_ci.minSampleShading = 1.0;
11888 pipe_ms_state_ci.pSampleMask = NULL;
Tobin Ehlis53eddda2015-07-01 16:46:13 -060011889
Tony Barboureb254902015-07-15 12:50:33 -060011890 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011891 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
11892 pipeline_layout_ci.pNext = NULL;
11893 pipeline_layout_ci.setLayoutCount = 1;
11894 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlis53eddda2015-07-01 16:46:13 -060011895
11896 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011897 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis53eddda2015-07-01 16:46:13 -060011898 ASSERT_VK_SUCCESS(err);
Mark Lobodzinski209b5292015-09-17 09:44:05 -060011899
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011900 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
Karl Schultzbdb75952016-04-19 11:36:49 -060011901 // We shouldn't need a fragment shader but add it to be able to run
Karl Schultz6addd812016-02-02 17:17:23 -070011902 // on more devices
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011903 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060011904
Tony Barbour62e1a5b2015-08-06 10:16:07 -060011905 VkPipelineObj pipe(m_device);
11906 pipe.AddShader(&vs);
Tony Barbour1c94d372015-08-06 11:21:08 -060011907 pipe.AddShader(&fs);
Tony Barbour62e1a5b2015-08-06 10:16:07 -060011908 pipe.SetMSAA(&pipe_ms_state_ci);
11909 pipe.CreateVKPipeline(pipeline_layout, renderPass());
Tony Barbourfe3351b2015-07-28 10:17:20 -060011910
11911 BeginCommandBuffer();
Tobin Ehlis53eddda2015-07-01 16:46:13 -060011912
Karl Schultz6addd812016-02-02 17:17:23 -070011913 // Main thing we care about for this test is that the VkImage obj we're
11914 // clearing matches Color Attachment of FB
Tobin Ehlis53eddda2015-07-01 16:46:13 -060011915 // Also pass down other dummy params to keep driver and paramchecker happy
Courtney Goeltzenleuchterc9323e02015-10-15 16:51:05 -060011916 VkClearAttachment color_attachment;
11917 color_attachment.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
11918 color_attachment.clearValue.color.float32[0] = 1.0;
11919 color_attachment.clearValue.color.float32[1] = 1.0;
11920 color_attachment.clearValue.color.float32[2] = 1.0;
11921 color_attachment.clearValue.color.float32[3] = 1.0;
11922 color_attachment.colorAttachment = 0;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011923 VkClearRect clear_rect = {{{0, 0}, {(uint32_t)m_width, (uint32_t)m_height}}};
Tobin Ehlis53eddda2015-07-01 16:46:13 -060011924
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011925 vkCmdClearAttachments(m_commandBuffer->GetBufferHandle(), 1, &color_attachment, 1, &clear_rect);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060011926
Chris Forbes8f36a8a2016-04-07 13:21:07 +120011927 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -060011928
Chia-I Wuf7458c52015-10-26 21:10:41 +080011929 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
11930 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
11931 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis53eddda2015-07-01 16:46:13 -060011932}
11933
Karl Schultz6addd812016-02-02 17:17:23 -070011934TEST_F(VkLayerTest, VtxBufferBadIndex) {
11935 VkResult err;
Tobin Ehlis502480b2015-06-24 15:53:07 -060011936
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011937 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
11938 "but no vertex buffers are attached to this Pipeline State Object");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060011939
Tobin Ehlis502480b2015-06-24 15:53:07 -060011940 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisd332f282015-10-02 11:00:56 -060011941 ASSERT_NO_FATAL_FAILURE(InitViewport());
Tobin Ehlis502480b2015-06-24 15:53:07 -060011942 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barboureb254902015-07-15 12:50:33 -060011943
Chia-I Wu1b99bb22015-10-27 19:25:11 +080011944 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011945 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
11946 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -060011947
11948 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011949 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
11950 ds_pool_ci.pNext = NULL;
11951 ds_pool_ci.maxSets = 1;
11952 ds_pool_ci.poolSizeCount = 1;
11953 ds_pool_ci.pPoolSizes = &ds_type_count;
Tony Barboureb254902015-07-15 12:50:33 -060011954
Courtney Goeltzenleuchterfe908d32015-09-16 16:12:45 -060011955 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011956 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis502480b2015-06-24 15:53:07 -060011957 ASSERT_VK_SUCCESS(err);
11958
Tony Barboureb254902015-07-15 12:50:33 -060011959 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011960 dsl_binding.binding = 0;
11961 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
11962 dsl_binding.descriptorCount = 1;
11963 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
11964 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis502480b2015-06-24 15:53:07 -060011965
Tony Barboureb254902015-07-15 12:50:33 -060011966 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011967 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
11968 ds_layout_ci.pNext = NULL;
11969 ds_layout_ci.bindingCount = 1;
11970 ds_layout_ci.pBindings = &dsl_binding;
Tony Barboureb254902015-07-15 12:50:33 -060011971
Tobin Ehlis502480b2015-06-24 15:53:07 -060011972 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011973 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis502480b2015-06-24 15:53:07 -060011974 ASSERT_VK_SUCCESS(err);
11975
11976 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080011977 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +080011978 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -070011979 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -060011980 alloc_info.descriptorPool = ds_pool;
11981 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011982 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis502480b2015-06-24 15:53:07 -060011983 ASSERT_VK_SUCCESS(err);
11984
Tony Barboureb254902015-07-15 12:50:33 -060011985 VkPipelineMultisampleStateCreateInfo pipe_ms_state_ci = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011986 pipe_ms_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
Karl Schultz6addd812016-02-02 17:17:23 -070011987 pipe_ms_state_ci.pNext = NULL;
11988 pipe_ms_state_ci.rasterizationSamples = VK_SAMPLE_COUNT_1_BIT;
11989 pipe_ms_state_ci.sampleShadingEnable = 0;
11990 pipe_ms_state_ci.minSampleShading = 1.0;
11991 pipe_ms_state_ci.pSampleMask = NULL;
Tobin Ehlis502480b2015-06-24 15:53:07 -060011992
Tony Barboureb254902015-07-15 12:50:33 -060011993 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011994 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
11995 pipeline_layout_ci.pNext = NULL;
11996 pipeline_layout_ci.setLayoutCount = 1;
11997 pipeline_layout_ci.pSetLayouts = &ds_layout;
11998 VkPipelineLayout pipeline_layout;
Tobin Ehlis502480b2015-06-24 15:53:07 -060011999
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012000 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis502480b2015-06-24 15:53:07 -060012001 ASSERT_VK_SUCCESS(err);
12002
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012003 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
12004 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this); // We shouldn't need a fragment shader
12005 // but add it to be able to run on more devices
Tony Barbour62e1a5b2015-08-06 10:16:07 -060012006 VkPipelineObj pipe(m_device);
12007 pipe.AddShader(&vs);
Tony Barbour1c94d372015-08-06 11:21:08 -060012008 pipe.AddShader(&fs);
Mark Youngc89c6312016-03-31 16:03:20 -060012009 pipe.AddColorAttachment();
Tony Barbour62e1a5b2015-08-06 10:16:07 -060012010 pipe.SetMSAA(&pipe_ms_state_ci);
Tobin Ehlisd332f282015-10-02 11:00:56 -060012011 pipe.SetViewport(m_viewports);
12012 pipe.SetScissor(m_scissors);
Tony Barbour62e1a5b2015-08-06 10:16:07 -060012013 pipe.CreateVKPipeline(pipeline_layout, renderPass());
Tony Barbourfe3351b2015-07-28 10:17:20 -060012014
12015 BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012016 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Tobin Ehlisf7bf4502015-09-09 15:12:35 -060012017 // Don't care about actual data, just need to get to draw to flag error
12018 static const float vbo_data[3] = {1.f, 0.f, 1.f};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012019 VkConstantBufferObj vbo(m_device, sizeof(vbo_data), sizeof(float), (const void *)&vbo_data);
Tobin Ehlisf7bf4502015-09-09 15:12:35 -060012020 BindVertexBuffer(&vbo, (VkDeviceSize)0, 1); // VBO idx 1, but no VBO in PSO
Courtney Goeltzenleuchter08c26372015-09-23 12:31:50 -060012021 Draw(1, 0, 0, 0);
Tobin Ehlis502480b2015-06-24 15:53:07 -060012022
Chris Forbes8f36a8a2016-04-07 13:21:07 +120012023 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -060012024
Chia-I Wuf7458c52015-10-26 21:10:41 +080012025 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
12026 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
12027 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis502480b2015-06-24 15:53:07 -060012028}
Mark Muellerdfe37552016-07-07 14:47:42 -060012029
Mark Mueller2ee294f2016-08-04 12:59:48 -060012030TEST_F(VkLayerTest, MismatchCountQueueCreateRequestedFeature) {
12031 TEST_DESCRIPTION("Use an invalid count in a vkEnumeratePhysicalDevices call."
12032 "Use invalid Queue Family Index in vkCreateDevice");
Cody Northropc31a84f2016-08-22 10:41:47 -060012033 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Mueller2ee294f2016-08-04 12:59:48 -060012034
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012035 const char *mismatch_count_message = "Call to vkEnumeratePhysicalDevices() "
12036 "w/ pPhysicalDeviceCount value ";
Mark Mueller2ee294f2016-08-04 12:59:48 -060012037
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012038 const char *invalid_queueFamilyIndex_message = "Invalid queue create request in vkCreateDevice(). Invalid "
12039 "queueFamilyIndex ";
Mark Mueller2ee294f2016-08-04 12:59:48 -060012040
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012041 const char *unavailable_feature_message = "While calling vkCreateDevice(), requesting feature #";
Mark Mueller2ee294f2016-08-04 12:59:48 -060012042
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012043 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT, mismatch_count_message);
Mark Mueller880fce52016-08-17 15:23:23 -060012044 // The following test fails with recent NVidia drivers.
12045 // By the time core_validation is reached, the NVidia
12046 // driver has sanitized the invalid condition and core_validation
12047 // is not introduced to the failure condition. This is not the case
12048 // with AMD and Mesa drivers. Futher investigation is required
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012049 // uint32_t count = static_cast<uint32_t>(~0);
12050 // VkPhysicalDevice physical_device;
12051 // vkEnumeratePhysicalDevices(instance(), &count, &physical_device);
12052 // m_errorMonitor->VerifyFound();
Mark Mueller2ee294f2016-08-04 12:59:48 -060012053
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012054 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, invalid_queueFamilyIndex_message);
Mark Mueller2ee294f2016-08-04 12:59:48 -060012055 float queue_priority = 0.0;
12056
12057 VkDeviceQueueCreateInfo queue_create_info = {};
12058 queue_create_info.sType = VK_STRUCTURE_TYPE_DEVICE_QUEUE_CREATE_INFO;
12059 queue_create_info.queueCount = 1;
12060 queue_create_info.pQueuePriorities = &queue_priority;
12061 queue_create_info.queueFamilyIndex = static_cast<uint32_t>(~0);
12062
12063 VkPhysicalDeviceFeatures features = m_device->phy().features();
12064 VkDevice testDevice;
12065 VkDeviceCreateInfo device_create_info = {};
12066 device_create_info.sType = VK_STRUCTURE_TYPE_DEVICE_CREATE_INFO;
12067 device_create_info.queueCreateInfoCount = 1;
12068 device_create_info.pQueueCreateInfos = &queue_create_info;
12069 device_create_info.pEnabledFeatures = &features;
12070 vkCreateDevice(gpu(), &device_create_info, nullptr, &testDevice);
12071 m_errorMonitor->VerifyFound();
12072
12073 queue_create_info.queueFamilyIndex = 1;
12074
12075 unsigned feature_count = sizeof(VkPhysicalDeviceFeatures) / sizeof(VkBool32);
12076 VkBool32 *feature_array = reinterpret_cast<VkBool32 *>(&features);
12077 for (unsigned i = 0; i < feature_count; i++) {
12078 if (VK_FALSE == feature_array[i]) {
12079 feature_array[i] = VK_TRUE;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012080 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, unavailable_feature_message);
Mark Mueller2ee294f2016-08-04 12:59:48 -060012081 device_create_info.pEnabledFeatures = &features;
12082 vkCreateDevice(gpu(), &device_create_info, nullptr, &testDevice);
12083 m_errorMonitor->VerifyFound();
12084 break;
12085 }
12086 }
12087}
12088
12089TEST_F(VkLayerTest, InvalidQueueIndexInvalidQuery) {
12090 TEST_DESCRIPTION("Use an invalid queue index in a vkCmdWaitEvents call."
12091 "End a command buffer with a query still in progress.");
12092
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012093 const char *invalid_queue_index = "was created with sharingMode of VK_SHARING_MODE_EXCLUSIVE. If one "
12094 "of src- or dstQueueFamilyIndex is VK_QUEUE_FAMILY_IGNORED, both "
12095 "must be.";
Mark Mueller2ee294f2016-08-04 12:59:48 -060012096
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012097 const char *invalid_query = "Ending command buffer with in progress query: queryPool 0x";
Mark Mueller2ee294f2016-08-04 12:59:48 -060012098
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012099 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, invalid_queue_index);
Mark Mueller2ee294f2016-08-04 12:59:48 -060012100
12101 ASSERT_NO_FATAL_FAILURE(InitState());
12102
12103 VkEvent event;
12104 VkEventCreateInfo event_create_info{};
12105 event_create_info.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO;
12106 vkCreateEvent(m_device->device(), &event_create_info, nullptr, &event);
12107
Mark Mueller2ee294f2016-08-04 12:59:48 -060012108 VkQueue queue = VK_NULL_HANDLE;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012109 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 0, &queue);
Mark Mueller2ee294f2016-08-04 12:59:48 -060012110
12111 BeginCommandBuffer();
12112
12113 VkImageObj image(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012114 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 -060012115 ASSERT_TRUE(image.initialized());
12116 VkImageMemoryBarrier img_barrier = {};
12117 img_barrier.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
12118 img_barrier.pNext = NULL;
12119 img_barrier.srcAccessMask = VK_ACCESS_HOST_WRITE_BIT;
12120 img_barrier.dstAccessMask = VK_ACCESS_SHADER_READ_BIT;
12121 img_barrier.oldLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
12122 img_barrier.newLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
12123 img_barrier.image = image.handle();
12124 img_barrier.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
Mark Lobodzinski2a74c5c2016-08-17 13:26:28 -060012125
12126 // QueueFamilyIndex must be VK_QUEUE_FAMILY_IGNORED, this verifies
12127 // that layer validation catches the case when it is not.
12128 img_barrier.dstQueueFamilyIndex = 0;
Mark Mueller2ee294f2016-08-04 12:59:48 -060012129 img_barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
12130 img_barrier.subresourceRange.baseArrayLayer = 0;
12131 img_barrier.subresourceRange.baseMipLevel = 0;
12132 img_barrier.subresourceRange.layerCount = 1;
12133 img_barrier.subresourceRange.levelCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012134 vkCmdWaitEvents(m_commandBuffer->handle(), 1, &event, VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0,
12135 nullptr, 0, nullptr, 1, &img_barrier);
Mark Mueller2ee294f2016-08-04 12:59:48 -060012136 m_errorMonitor->VerifyFound();
12137
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012138 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, invalid_query);
Mark Mueller2ee294f2016-08-04 12:59:48 -060012139
12140 VkQueryPool query_pool;
12141 VkQueryPoolCreateInfo query_pool_create_info = {};
12142 query_pool_create_info.sType = VK_STRUCTURE_TYPE_QUERY_POOL_CREATE_INFO;
12143 query_pool_create_info.queryType = VK_QUERY_TYPE_OCCLUSION;
12144 query_pool_create_info.queryCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012145 vkCreateQueryPool(m_device->device(), &query_pool_create_info, nullptr, &query_pool);
Mark Mueller2ee294f2016-08-04 12:59:48 -060012146
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012147 vkCmdResetQueryPool(m_commandBuffer->handle(), query_pool, 0 /*startQuery*/, 1 /*queryCount*/);
Mark Mueller2ee294f2016-08-04 12:59:48 -060012148 vkCmdBeginQuery(m_commandBuffer->handle(), query_pool, 0, 0);
12149
12150 vkEndCommandBuffer(m_commandBuffer->handle());
12151 m_errorMonitor->VerifyFound();
12152
12153 vkDestroyQueryPool(m_device->device(), query_pool, nullptr);
12154 vkDestroyEvent(m_device->device(), event, nullptr);
12155}
12156
Mark Muellerdfe37552016-07-07 14:47:42 -060012157TEST_F(VkLayerTest, VertexBufferInvalid) {
12158 TEST_DESCRIPTION("Submit a command buffer using deleted vertex buffer, "
12159 "delete a buffer twice, use an invalid offset for each "
12160 "buffer type, and attempt to bind a null buffer");
12161
12162 const char *deleted_buffer_in_command_buffer = "Cannot submit cmd buffer "
12163 "using deleted buffer ";
12164 const char *double_destroy_message = "Cannot free buffer 0x";
12165 const char *invalid_offset_message = "vkBindBufferMemory(): "
12166 "memoryOffset is 0x";
12167 const char *invalid_storage_buffer_offset_message = "vkBindBufferMemory(): "
12168 "storage memoryOffset "
12169 "is 0x";
12170 const char *invalid_texel_buffer_offset_message = "vkBindBufferMemory(): "
12171 "texel memoryOffset "
12172 "is 0x";
12173 const char *invalid_uniform_buffer_offset_message = "vkBindBufferMemory(): "
12174 "uniform memoryOffset "
12175 "is 0x";
12176 const char *bind_null_buffer_message = "In vkBindBufferMemory, attempting"
12177 " to Bind Obj(0x";
12178 const char *free_invalid_buffer_message = "Request to delete memory "
12179 "object 0x";
12180
12181 ASSERT_NO_FATAL_FAILURE(InitState());
12182 ASSERT_NO_FATAL_FAILURE(InitViewport());
12183 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12184
12185 VkPipelineMultisampleStateCreateInfo pipe_ms_state_ci = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012186 pipe_ms_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
Mark Muellerdfe37552016-07-07 14:47:42 -060012187 pipe_ms_state_ci.pNext = NULL;
12188 pipe_ms_state_ci.rasterizationSamples = VK_SAMPLE_COUNT_1_BIT;
12189 pipe_ms_state_ci.sampleShadingEnable = 0;
12190 pipe_ms_state_ci.minSampleShading = 1.0;
12191 pipe_ms_state_ci.pSampleMask = nullptr;
12192
12193 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
12194 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
12195 VkPipelineLayout pipeline_layout;
12196
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012197 VkResult err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, nullptr, &pipeline_layout);
Mark Muellerdfe37552016-07-07 14:47:42 -060012198 ASSERT_VK_SUCCESS(err);
12199
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012200 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
12201 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Mark Muellerdfe37552016-07-07 14:47:42 -060012202 VkPipelineObj pipe(m_device);
12203 pipe.AddShader(&vs);
12204 pipe.AddShader(&fs);
12205 pipe.AddColorAttachment();
12206 pipe.SetMSAA(&pipe_ms_state_ci);
12207 pipe.SetViewport(m_viewports);
12208 pipe.SetScissor(m_scissors);
12209 pipe.CreateVKPipeline(pipeline_layout, renderPass());
12210
12211 BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012212 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Mark Muellerdfe37552016-07-07 14:47:42 -060012213
12214 {
12215 // Create and bind a vertex buffer in a reduced scope, which will cause
12216 // it to be deleted upon leaving this scope
12217 const float vbo_data[3] = {1.f, 0.f, 1.f};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012218 VkVerticesObj draw_verticies(m_device, 1, 1, sizeof(vbo_data), 3, vbo_data);
Mark Muellerdfe37552016-07-07 14:47:42 -060012219 draw_verticies.BindVertexBuffers(m_commandBuffer->handle());
12220 draw_verticies.AddVertexInputToPipe(pipe);
12221 }
12222
12223 Draw(1, 0, 0, 0);
12224
12225 EndCommandBuffer();
12226
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012227 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, deleted_buffer_in_command_buffer);
Mark Muellerdfe37552016-07-07 14:47:42 -060012228 QueueCommandBuffer(false);
12229 m_errorMonitor->VerifyFound();
12230
12231 {
12232 // Create and bind a vertex buffer in a reduced scope, and delete it
12233 // twice, the second through the destructor
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012234 VkBufferTest buffer_test(m_device, VK_BUFFER_USAGE_STORAGE_BUFFER_BIT, VkBufferTest::eDoubleDelete);
12235 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, double_destroy_message);
Mark Muellerdfe37552016-07-07 14:47:42 -060012236 buffer_test.TestDoubleDestroy();
12237 }
12238 m_errorMonitor->VerifyFound();
12239
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012240 if (VkBufferTest::GetTestConditionValid(m_device, VkBufferTest::eInvalidMemoryOffset)) {
Mark Muellerdfe37552016-07-07 14:47:42 -060012241 // Create and bind a memory buffer with an invalid offset.
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012242 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, invalid_offset_message);
12243 VkBufferTest buffer_test(m_device, VK_BUFFER_USAGE_UNIFORM_TEXEL_BUFFER_BIT, VkBufferTest::eInvalidMemoryOffset);
12244 (void)buffer_test;
Mark Muellerdfe37552016-07-07 14:47:42 -060012245 m_errorMonitor->VerifyFound();
12246 }
12247
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012248 if (VkBufferTest::GetTestConditionValid(m_device, VkBufferTest::eInvalidDeviceOffset,
12249 VK_BUFFER_USAGE_UNIFORM_TEXEL_BUFFER_BIT)) {
Mark Muellerdfe37552016-07-07 14:47:42 -060012250 // Create and bind a memory buffer with an invalid offset again,
12251 // but look for a texel buffer message.
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012252 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, invalid_texel_buffer_offset_message);
12253 VkBufferTest buffer_test(m_device, VK_BUFFER_USAGE_UNIFORM_TEXEL_BUFFER_BIT, VkBufferTest::eInvalidDeviceOffset);
12254 (void)buffer_test;
Mark Muellerdfe37552016-07-07 14:47:42 -060012255 m_errorMonitor->VerifyFound();
12256 }
12257
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012258 if (VkBufferTest::GetTestConditionValid(m_device, VkBufferTest::eInvalidDeviceOffset, VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT)) {
Mark Muellerdfe37552016-07-07 14:47:42 -060012259 // Create and bind a memory buffer with an invalid offset again, but
12260 // look for a uniform buffer message.
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012261 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, invalid_uniform_buffer_offset_message);
12262 VkBufferTest buffer_test(m_device, VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT, VkBufferTest::eInvalidDeviceOffset);
12263 (void)buffer_test;
Mark Muellerdfe37552016-07-07 14:47:42 -060012264 m_errorMonitor->VerifyFound();
12265 }
12266
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012267 if (VkBufferTest::GetTestConditionValid(m_device, VkBufferTest::eInvalidDeviceOffset, VK_BUFFER_USAGE_STORAGE_BUFFER_BIT)) {
Mark Muellerdfe37552016-07-07 14:47:42 -060012268 // Create and bind a memory buffer with an invalid offset again, but
12269 // look for a storage buffer message.
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012270 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, invalid_storage_buffer_offset_message);
12271 VkBufferTest buffer_test(m_device, VK_BUFFER_USAGE_STORAGE_BUFFER_BIT, VkBufferTest::eInvalidDeviceOffset);
12272 (void)buffer_test;
Mark Muellerdfe37552016-07-07 14:47:42 -060012273 m_errorMonitor->VerifyFound();
12274 }
12275
12276 {
12277 // Attempt to bind a null buffer.
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012278 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, bind_null_buffer_message);
12279 VkBufferTest buffer_test(m_device, VK_BUFFER_USAGE_STORAGE_BUFFER_BIT, VkBufferTest::eBindNullBuffer);
12280 (void)buffer_test;
Mark Muellerdfe37552016-07-07 14:47:42 -060012281 m_errorMonitor->VerifyFound();
12282 }
12283
12284 {
12285 // Attempt to use an invalid handle to delete a buffer.
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012286 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, free_invalid_buffer_message);
12287 VkBufferTest buffer_test(m_device, VK_BUFFER_USAGE_STORAGE_BUFFER_BIT, VkBufferTest::eFreeInvalidHandle);
12288 (void)buffer_test;
Mark Muellerdfe37552016-07-07 14:47:42 -060012289 }
12290 m_errorMonitor->VerifyFound();
12291
12292 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
12293}
12294
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060012295// INVALID_IMAGE_LAYOUT tests (one other case is hit by MapMemWithoutHostVisibleBit and not here)
12296TEST_F(VkLayerTest, InvalidImageLayout) {
12297 TEST_DESCRIPTION("Hit all possible validation checks associated with the "
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012298 "DRAWSTATE_INVALID_IMAGE_LAYOUT enum. Generally these involve having"
12299 "images in the wrong layout when they're copied or transitioned.");
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060012300 // 3 in ValidateCmdBufImageLayouts
12301 // * -1 Attempt to submit cmd buf w/ deleted image
12302 // * -2 Cmd buf submit of image w/ layout not matching first use w/ subresource
12303 // * -3 Cmd buf submit of image w/ layout not matching first use w/o subresource
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012304 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
12305 "Layout for input image should be TRANSFER_SRC_OPTIMAL instead of GENERAL.");
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060012306
12307 ASSERT_NO_FATAL_FAILURE(InitState());
12308 // Create src & dst images to use for copy operations
12309 VkImage src_image;
12310 VkImage dst_image;
12311
12312 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
12313 const int32_t tex_width = 32;
12314 const int32_t tex_height = 32;
12315
12316 VkImageCreateInfo image_create_info = {};
12317 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
12318 image_create_info.pNext = NULL;
12319 image_create_info.imageType = VK_IMAGE_TYPE_2D;
12320 image_create_info.format = tex_format;
12321 image_create_info.extent.width = tex_width;
12322 image_create_info.extent.height = tex_height;
12323 image_create_info.extent.depth = 1;
12324 image_create_info.mipLevels = 1;
12325 image_create_info.arrayLayers = 4;
12326 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
12327 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
12328 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
12329 image_create_info.flags = 0;
12330
12331 VkResult err = vkCreateImage(m_device->device(), &image_create_info, NULL, &src_image);
12332 ASSERT_VK_SUCCESS(err);
12333 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &dst_image);
12334 ASSERT_VK_SUCCESS(err);
12335
12336 BeginCommandBuffer();
12337 VkImageCopy copyRegion;
12338 copyRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
12339 copyRegion.srcSubresource.mipLevel = 0;
12340 copyRegion.srcSubresource.baseArrayLayer = 0;
12341 copyRegion.srcSubresource.layerCount = 1;
12342 copyRegion.srcOffset.x = 0;
12343 copyRegion.srcOffset.y = 0;
12344 copyRegion.srcOffset.z = 0;
12345 copyRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
12346 copyRegion.dstSubresource.mipLevel = 0;
12347 copyRegion.dstSubresource.baseArrayLayer = 0;
12348 copyRegion.dstSubresource.layerCount = 1;
12349 copyRegion.dstOffset.x = 0;
12350 copyRegion.dstOffset.y = 0;
12351 copyRegion.dstOffset.z = 0;
12352 copyRegion.extent.width = 1;
12353 copyRegion.extent.height = 1;
12354 copyRegion.extent.depth = 1;
12355 m_commandBuffer->CopyImage(src_image, VK_IMAGE_LAYOUT_GENERAL, dst_image, VK_IMAGE_LAYOUT_GENERAL, 1, &copyRegion);
12356 m_errorMonitor->VerifyFound();
12357 // Now cause error due to src image layout changing
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012358 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Cannot copy from an image whose source layout is "
12359 "VK_IMAGE_LAYOUT_UNDEFINED and doesn't match the current "
12360 "layout VK_IMAGE_LAYOUT_GENERAL.");
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060012361 m_commandBuffer->CopyImage(src_image, VK_IMAGE_LAYOUT_UNDEFINED, dst_image, VK_IMAGE_LAYOUT_GENERAL, 1, &copyRegion);
12362 m_errorMonitor->VerifyFound();
12363 // Final src error is due to bad layout type
12364 m_errorMonitor->SetDesiredFailureMsg(
12365 VK_DEBUG_REPORT_ERROR_BIT_EXT,
12366 "Layout for input image is VK_IMAGE_LAYOUT_UNDEFINED but can only be TRANSFER_SRC_OPTIMAL or GENERAL.");
12367 m_commandBuffer->CopyImage(src_image, VK_IMAGE_LAYOUT_UNDEFINED, dst_image, VK_IMAGE_LAYOUT_GENERAL, 1, &copyRegion);
12368 m_errorMonitor->VerifyFound();
12369 // Now verify same checks for dst
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012370 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
12371 "Layout for output image should be TRANSFER_DST_OPTIMAL instead of GENERAL.");
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060012372 m_commandBuffer->CopyImage(src_image, VK_IMAGE_LAYOUT_GENERAL, dst_image, VK_IMAGE_LAYOUT_GENERAL, 1, &copyRegion);
12373 m_errorMonitor->VerifyFound();
12374 // Now cause error due to src image layout changing
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012375 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Cannot copy from an image whose dest layout is "
12376 "VK_IMAGE_LAYOUT_UNDEFINED and doesn't match the current "
12377 "layout VK_IMAGE_LAYOUT_GENERAL.");
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060012378 m_commandBuffer->CopyImage(src_image, VK_IMAGE_LAYOUT_GENERAL, dst_image, VK_IMAGE_LAYOUT_UNDEFINED, 1, &copyRegion);
12379 m_errorMonitor->VerifyFound();
12380 m_errorMonitor->SetDesiredFailureMsg(
12381 VK_DEBUG_REPORT_ERROR_BIT_EXT,
12382 "Layout for output image is VK_IMAGE_LAYOUT_UNDEFINED but can only be TRANSFER_DST_OPTIMAL or GENERAL.");
12383 m_commandBuffer->CopyImage(src_image, VK_IMAGE_LAYOUT_GENERAL, dst_image, VK_IMAGE_LAYOUT_UNDEFINED, 1, &copyRegion);
12384 m_errorMonitor->VerifyFound();
12385 // Now cause error due to bad image layout transition in PipelineBarrier
12386 VkImageMemoryBarrier image_barrier[1] = {};
12387 image_barrier[0].oldLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL;
12388 image_barrier[0].image = src_image;
12389 image_barrier[0].subresourceRange.layerCount = 2;
12390 image_barrier[0].subresourceRange.levelCount = 2;
12391 image_barrier[0].subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012392 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "You cannot transition the layout from "
12393 "VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL when "
12394 "current layout is VK_IMAGE_LAYOUT_GENERAL.");
12395 vkCmdPipelineBarrier(m_commandBuffer->handle(), VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0,
12396 NULL, 0, NULL, 1, image_barrier);
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060012397 m_errorMonitor->VerifyFound();
12398
12399 // Finally some layout errors at RenderPass create time
12400 // Just hacking in specific state to get to the errors we want so don't copy this unless you know what you're doing.
12401 VkAttachmentReference attach = {};
12402 // perf warning for GENERAL layout w/ non-DS input attachment
12403 attach.layout = VK_IMAGE_LAYOUT_GENERAL;
12404 VkSubpassDescription subpass = {};
12405 subpass.inputAttachmentCount = 1;
12406 subpass.pInputAttachments = &attach;
12407 VkRenderPassCreateInfo rpci = {};
12408 rpci.subpassCount = 1;
12409 rpci.pSubpasses = &subpass;
12410 rpci.attachmentCount = 1;
12411 VkAttachmentDescription attach_desc = {};
12412 attach_desc.format = VK_FORMAT_UNDEFINED;
12413 rpci.pAttachments = &attach_desc;
Tobin Ehlis1efce022016-05-11 10:40:34 -060012414 rpci.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060012415 VkRenderPass rp;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012416 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
12417 "Layout for input attachment is GENERAL but should be READ_ONLY_OPTIMAL.");
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060012418 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
12419 m_errorMonitor->VerifyFound();
12420 // error w/ non-general layout
12421 attach.layout = VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL;
12422
12423 m_errorMonitor->SetDesiredFailureMsg(
12424 VK_DEBUG_REPORT_ERROR_BIT_EXT,
12425 "Layout for input attachment is VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL but can only be READ_ONLY_OPTIMAL or GENERAL.");
12426 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
12427 m_errorMonitor->VerifyFound();
12428 subpass.inputAttachmentCount = 0;
12429 subpass.colorAttachmentCount = 1;
12430 subpass.pColorAttachments = &attach;
12431 attach.layout = VK_IMAGE_LAYOUT_GENERAL;
12432 // perf warning for GENERAL layout on color attachment
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012433 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
12434 "Layout for color attachment is GENERAL but should be COLOR_ATTACHMENT_OPTIMAL.");
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060012435 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
12436 m_errorMonitor->VerifyFound();
12437 // error w/ non-color opt or GENERAL layout for color attachment
12438 attach.layout = VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL;
12439 m_errorMonitor->SetDesiredFailureMsg(
12440 VK_DEBUG_REPORT_ERROR_BIT_EXT,
12441 "Layout for color attachment is VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL but can only be COLOR_ATTACHMENT_OPTIMAL or GENERAL.");
12442 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
12443 m_errorMonitor->VerifyFound();
12444 subpass.colorAttachmentCount = 0;
12445 subpass.pDepthStencilAttachment = &attach;
12446 attach.layout = VK_IMAGE_LAYOUT_GENERAL;
12447 // perf warning for GENERAL layout on DS attachment
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012448 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
12449 "GENERAL layout for depth attachment may not give optimal performance.");
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060012450 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
12451 m_errorMonitor->VerifyFound();
12452 // error w/ non-ds opt or GENERAL layout for color attachment
12453 attach.layout = VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012454 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
12455 "Layout for depth attachment is VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL but can only be "
12456 "DEPTH_STENCIL_ATTACHMENT_OPTIMAL, DEPTH_STENCIL_READ_ONLY_OPTIMAL or GENERAL.");
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060012457 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
12458 m_errorMonitor->VerifyFound();
Tobin Ehlis1efce022016-05-11 10:40:34 -060012459 // For this error we need a valid renderpass so create default one
12460 attach.layout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL;
12461 attach.attachment = 0;
12462 attach_desc.format = VK_FORMAT_D24_UNORM_S8_UINT;
12463 attach_desc.samples = VK_SAMPLE_COUNT_1_BIT;
12464 attach_desc.storeOp = VK_ATTACHMENT_STORE_OP_STORE;
12465 attach_desc.stencilLoadOp = VK_ATTACHMENT_LOAD_OP_DONT_CARE;
12466 attach_desc.stencilStoreOp = VK_ATTACHMENT_STORE_OP_DONT_CARE;
12467 // Can't do a CLEAR load on READ_ONLY initialLayout
12468 attach_desc.loadOp = VK_ATTACHMENT_LOAD_OP_CLEAR;
12469 attach_desc.initialLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL;
12470 attach_desc.finalLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012471 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " with invalid first layout "
12472 "VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_"
12473 "ONLY_OPTIMAL");
Tobin Ehlis1efce022016-05-11 10:40:34 -060012474 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
12475 m_errorMonitor->VerifyFound();
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060012476
12477 vkDestroyImage(m_device->device(), src_image, NULL);
12478 vkDestroyImage(m_device->device(), dst_image, NULL);
12479}
Tobin Ehlisd8d89182016-07-18 20:13:11 -060012480
12481TEST_F(VkLayerTest, ValidRenderPassAttachmentLayoutWithLoadOp) {
12482 TEST_DESCRIPTION("Positive test where we create a renderpass with an "
12483 "attachment that uses LOAD_OP_CLEAR, the first subpass "
12484 "has a valid layout, and a second subpass then uses a "
12485 "valid *READ_ONLY* layout.");
12486 m_errorMonitor->ExpectSuccess();
12487 ASSERT_NO_FATAL_FAILURE(InitState());
12488
12489 VkAttachmentReference attach[2] = {};
12490 attach[0].attachment = 0;
12491 attach[0].layout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
12492 attach[1].attachment = 0;
12493 attach[1].layout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL;
12494 VkSubpassDescription subpasses[2] = {};
12495 // First subpass clears DS attach on load
12496 subpasses[0].pDepthStencilAttachment = &attach[0];
12497 // 2nd subpass reads in DS as input attachment
12498 subpasses[1].inputAttachmentCount = 1;
12499 subpasses[1].pInputAttachments = &attach[1];
12500 VkAttachmentDescription attach_desc = {};
12501 attach_desc.format = VK_FORMAT_D24_UNORM_S8_UINT;
12502 attach_desc.samples = VK_SAMPLE_COUNT_1_BIT;
12503 attach_desc.storeOp = VK_ATTACHMENT_STORE_OP_STORE;
12504 attach_desc.stencilStoreOp = VK_ATTACHMENT_STORE_OP_DONT_CARE;
12505 attach_desc.loadOp = VK_ATTACHMENT_LOAD_OP_CLEAR;
12506 attach_desc.stencilLoadOp = VK_ATTACHMENT_LOAD_OP_CLEAR;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012507 attach_desc.initialLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
Tobin Ehlisd8d89182016-07-18 20:13:11 -060012508 attach_desc.finalLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL;
12509 VkRenderPassCreateInfo rpci = {};
12510 rpci.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
12511 rpci.attachmentCount = 1;
12512 rpci.pAttachments = &attach_desc;
12513 rpci.subpassCount = 2;
12514 rpci.pSubpasses = subpasses;
12515
12516 // Now create RenderPass and verify no errors
12517 VkRenderPass rp;
12518 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
12519 m_errorMonitor->VerifyNotFound();
12520
12521 vkDestroyRenderPass(m_device->device(), rp, NULL);
12522}
Tobin Ehlis4af23302016-07-19 10:50:30 -060012523
Mark Mueller93b938f2016-08-18 10:27:40 -060012524TEST_F(VkLayerTest, SimultaneousUse) {
12525 TEST_DESCRIPTION("Use vkCmdExecuteCommands with invalid state "
12526 "in primary and secondary command buffers.");
12527
12528 ASSERT_NO_FATAL_FAILURE(InitState());
12529 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12530
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012531 const char *simultaneous_use_message1 = "w/o VK_COMMAND_BUFFER_USAGE_SIMULTANEOUS_USE_BIT set!";
12532 const char *simultaneous_use_message2 = "does not have VK_COMMAND_BUFFER_USAGE_SIMULTANEOUS_USE_BIT set and "
12533 "will cause primary command buffer";
Mark Mueller93b938f2016-08-18 10:27:40 -060012534
12535 VkCommandBufferAllocateInfo command_buffer_allocate_info = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012536 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
Mark Mueller93b938f2016-08-18 10:27:40 -060012537 command_buffer_allocate_info.commandPool = m_commandPool;
12538 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_SECONDARY;
12539 command_buffer_allocate_info.commandBufferCount = 1;
12540
12541 VkCommandBuffer secondary_command_buffer;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012542 ASSERT_VK_SUCCESS(vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, &secondary_command_buffer));
Mark Mueller93b938f2016-08-18 10:27:40 -060012543 VkCommandBufferBeginInfo command_buffer_begin_info = {};
12544 VkCommandBufferInheritanceInfo command_buffer_inheritance_info = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012545 command_buffer_inheritance_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_INHERITANCE_INFO;
Mark Mueller93b938f2016-08-18 10:27:40 -060012546 command_buffer_inheritance_info.renderPass = m_renderPass;
12547 command_buffer_inheritance_info.framebuffer = m_framebuffer;
12548 command_buffer_begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012549 command_buffer_begin_info.flags =
12550 VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT | VK_COMMAND_BUFFER_USAGE_RENDER_PASS_CONTINUE_BIT;
Mark Mueller93b938f2016-08-18 10:27:40 -060012551 command_buffer_begin_info.pInheritanceInfo = &command_buffer_inheritance_info;
12552
12553 vkBeginCommandBuffer(secondary_command_buffer, &command_buffer_begin_info);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012554 vkCmdBeginRenderPass(m_commandBuffer->handle(), &renderPassBeginInfo(), VK_SUBPASS_CONTENTS_SECONDARY_COMMAND_BUFFERS);
12555 vkCmdExecuteCommands(m_commandBuffer->handle(), 1, &secondary_command_buffer);
Mark Mueller4042b652016-09-05 22:52:21 -060012556 vkCmdEndRenderPass(m_commandBuffer->GetBufferHandle());
Mark Mueller93b938f2016-08-18 10:27:40 -060012557 vkEndCommandBuffer(secondary_command_buffer);
12558
Mark Mueller93b938f2016-08-18 10:27:40 -060012559 VkSubmitInfo submit_info = {};
12560 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
12561 submit_info.commandBufferCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012562 submit_info.pCommandBuffers = &m_commandBuffer->handle();
Mark Mueller4042b652016-09-05 22:52:21 -060012563 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
Mark Mueller93b938f2016-08-18 10:27:40 -060012564
Mark Mueller4042b652016-09-05 22:52:21 -060012565 vkBeginCommandBuffer(m_commandBuffer->handle(), &command_buffer_begin_info);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012566 vkCmdBeginRenderPass(m_commandBuffer->handle(), &renderPassBeginInfo(), VK_SUBPASS_CONTENTS_SECONDARY_COMMAND_BUFFERS);
12567 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, simultaneous_use_message1);
12568 vkCmdExecuteCommands(m_commandBuffer->handle(), 1, &secondary_command_buffer);
Mark Mueller93b938f2016-08-18 10:27:40 -060012569 m_errorMonitor->VerifyFound();
Mark Mueller4042b652016-09-05 22:52:21 -060012570 vkCmdEndRenderPass(m_commandBuffer->GetBufferHandle());
12571 vkEndCommandBuffer(m_commandBuffer->handle());
Mark Mueller93b938f2016-08-18 10:27:40 -060012572
12573 m_errorMonitor->SetDesiredFailureMsg(0, "");
Mark Mueller93b938f2016-08-18 10:27:40 -060012574 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
12575
Mark Mueller4042b652016-09-05 22:52:21 -060012576 command_buffer_begin_info.flags = VK_COMMAND_BUFFER_USAGE_SIMULTANEOUS_USE_BIT;
Mark Mueller93b938f2016-08-18 10:27:40 -060012577 vkBeginCommandBuffer(m_commandBuffer->handle(), &command_buffer_begin_info);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012578 vkCmdBeginRenderPass(m_commandBuffer->handle(), &renderPassBeginInfo(), VK_SUBPASS_CONTENTS_SECONDARY_COMMAND_BUFFERS);
Mark Mueller4042b652016-09-05 22:52:21 -060012579
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012580 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT, simultaneous_use_message2);
12581 vkCmdExecuteCommands(m_commandBuffer->handle(), 1, &secondary_command_buffer);
Mark Mueller93b938f2016-08-18 10:27:40 -060012582 m_errorMonitor->VerifyFound();
Mark Mueller4042b652016-09-05 22:52:21 -060012583 vkCmdEndRenderPass(m_commandBuffer->GetBufferHandle());
12584 vkEndCommandBuffer(m_commandBuffer->handle());
Mark Mueller93b938f2016-08-18 10:27:40 -060012585}
12586
Mark Mueller917f6bc2016-08-30 10:57:19 -060012587TEST_F(VkLayerTest, InUseDestroyedSignaled) {
12588 TEST_DESCRIPTION("Use vkCmdExecuteCommands with invalid state "
12589 "in primary and secondary command buffers. "
Mark Muellerc8d441e2016-08-23 17:36:00 -060012590 "Delete objects that are inuse. Call VkQueueSubmit "
12591 "with an event that has been deleted.");
Mark Mueller917f6bc2016-08-30 10:57:19 -060012592
12593 ASSERT_NO_FATAL_FAILURE(InitState());
12594 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12595
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012596 const char *submit_with_deleted_event_message = "Cannot submit cmd buffer using deleted event 0x";
12597 const char *cannot_delete_event_message = "Cannot delete event 0x";
12598 const char *cannot_delete_semaphore_message = "Cannot delete semaphore 0x";
12599 const char *cannot_destroy_fence_message = "Fence 0x";
Mark Mueller917f6bc2016-08-30 10:57:19 -060012600
12601 BeginCommandBuffer();
12602
12603 VkEvent event;
12604 VkEventCreateInfo event_create_info = {};
12605 event_create_info.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO;
12606 vkCreateEvent(m_device->device(), &event_create_info, nullptr, &event);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012607 vkCmdSetEvent(m_commandBuffer->handle(), event, VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT);
Mark Mueller917f6bc2016-08-30 10:57:19 -060012608
Mark Muellerc8d441e2016-08-23 17:36:00 -060012609 EndCommandBuffer();
12610 vkDestroyEvent(m_device->device(), event, nullptr);
12611
12612 VkSubmitInfo submit_info = {};
12613 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
12614 submit_info.commandBufferCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012615 submit_info.pCommandBuffers = &m_commandBuffer->handle();
12616 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, submit_with_deleted_event_message);
Mark Muellerc8d441e2016-08-23 17:36:00 -060012617 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
12618 m_errorMonitor->VerifyFound();
12619
12620 m_errorMonitor->SetDesiredFailureMsg(0, "");
12621 vkResetCommandBuffer(m_commandBuffer->handle(), 0);
12622
12623 vkCreateEvent(m_device->device(), &event_create_info, nullptr, &event);
12624
Mark Mueller917f6bc2016-08-30 10:57:19 -060012625 VkSemaphoreCreateInfo semaphore_create_info = {};
12626 semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
12627 VkSemaphore semaphore;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012628 ASSERT_VK_SUCCESS(vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr, &semaphore));
Mark Mueller917f6bc2016-08-30 10:57:19 -060012629 VkFenceCreateInfo fence_create_info = {};
12630 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
12631 VkFence fence;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012632 ASSERT_VK_SUCCESS(vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence));
Mark Mueller917f6bc2016-08-30 10:57:19 -060012633
12634 VkDescriptorPoolSize descriptor_pool_type_count = {};
Mark Mueller4042b652016-09-05 22:52:21 -060012635 descriptor_pool_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Mark Mueller917f6bc2016-08-30 10:57:19 -060012636 descriptor_pool_type_count.descriptorCount = 1;
12637
12638 VkDescriptorPoolCreateInfo descriptor_pool_create_info = {};
12639 descriptor_pool_create_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
12640 descriptor_pool_create_info.maxSets = 1;
12641 descriptor_pool_create_info.poolSizeCount = 1;
12642 descriptor_pool_create_info.pPoolSizes = &descriptor_pool_type_count;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012643 descriptor_pool_create_info.flags = VK_DESCRIPTOR_POOL_CREATE_FREE_DESCRIPTOR_SET_BIT;
Mark Mueller917f6bc2016-08-30 10:57:19 -060012644
12645 VkDescriptorPool descriptorset_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012646 ASSERT_VK_SUCCESS(vkCreateDescriptorPool(m_device->device(), &descriptor_pool_create_info, nullptr, &descriptorset_pool));
Mark Mueller917f6bc2016-08-30 10:57:19 -060012647
12648 VkDescriptorSetLayoutBinding descriptorset_layout_binding = {};
Mark Mueller4042b652016-09-05 22:52:21 -060012649 descriptorset_layout_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Mark Mueller917f6bc2016-08-30 10:57:19 -060012650 descriptorset_layout_binding.descriptorCount = 1;
12651 descriptorset_layout_binding.stageFlags = VK_SHADER_STAGE_ALL;
12652
12653 VkDescriptorSetLayoutCreateInfo descriptorset_layout_create_info = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012654 descriptorset_layout_create_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
Mark Mueller917f6bc2016-08-30 10:57:19 -060012655 descriptorset_layout_create_info.bindingCount = 1;
12656 descriptorset_layout_create_info.pBindings = &descriptorset_layout_binding;
12657
12658 VkDescriptorSetLayout descriptorset_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012659 ASSERT_VK_SUCCESS(
12660 vkCreateDescriptorSetLayout(m_device->device(), &descriptorset_layout_create_info, nullptr, &descriptorset_layout));
Mark Mueller917f6bc2016-08-30 10:57:19 -060012661
12662 VkDescriptorSet descriptorset;
12663 VkDescriptorSetAllocateInfo descriptorset_allocate_info = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012664 descriptorset_allocate_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Mark Mueller917f6bc2016-08-30 10:57:19 -060012665 descriptorset_allocate_info.descriptorSetCount = 1;
12666 descriptorset_allocate_info.descriptorPool = descriptorset_pool;
12667 descriptorset_allocate_info.pSetLayouts = &descriptorset_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012668 ASSERT_VK_SUCCESS(vkAllocateDescriptorSets(m_device->device(), &descriptorset_allocate_info, &descriptorset));
Mark Mueller917f6bc2016-08-30 10:57:19 -060012669
Mark Mueller4042b652016-09-05 22:52:21 -060012670 VkBufferTest buffer_test(m_device, VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT);
12671
12672 VkDescriptorBufferInfo buffer_info = {};
12673 buffer_info.buffer = buffer_test.GetBuffer();
12674 buffer_info.offset = 0;
12675 buffer_info.range = 1024;
12676
12677 VkWriteDescriptorSet write_descriptor_set = {};
12678 write_descriptor_set.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
12679 write_descriptor_set.dstSet = descriptorset;
12680 write_descriptor_set.descriptorCount = 1;
12681 write_descriptor_set.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
12682 write_descriptor_set.pBufferInfo = &buffer_info;
12683
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012684 vkUpdateDescriptorSets(m_device->device(), 1, &write_descriptor_set, 0, nullptr);
Mark Mueller4042b652016-09-05 22:52:21 -060012685
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012686 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
12687 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Mark Mueller917f6bc2016-08-30 10:57:19 -060012688
12689 VkPipelineObj pipe(m_device);
12690 pipe.AddColorAttachment();
12691 pipe.AddShader(&vs);
12692 pipe.AddShader(&fs);
12693
12694 VkPipelineLayoutCreateInfo pipeline_layout_create_info = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012695 pipeline_layout_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
Mark Mueller917f6bc2016-08-30 10:57:19 -060012696 pipeline_layout_create_info.setLayoutCount = 1;
12697 pipeline_layout_create_info.pSetLayouts = &descriptorset_layout;
12698
12699 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012700 ASSERT_VK_SUCCESS(vkCreatePipelineLayout(m_device->device(), &pipeline_layout_create_info, nullptr, &pipeline_layout));
Mark Mueller917f6bc2016-08-30 10:57:19 -060012701
12702 pipe.CreateVKPipeline(pipeline_layout, m_renderPass);
12703
Mark Muellerc8d441e2016-08-23 17:36:00 -060012704 BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012705 vkCmdSetEvent(m_commandBuffer->handle(), event, VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT);
Mark Muellerc8d441e2016-08-23 17:36:00 -060012706
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012707 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
12708 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
12709 &descriptorset, 0, NULL);
Mark Mueller917f6bc2016-08-30 10:57:19 -060012710
Mark Muellerc8d441e2016-08-23 17:36:00 -060012711 EndCommandBuffer();
Mark Mueller917f6bc2016-08-30 10:57:19 -060012712
Mark Mueller917f6bc2016-08-30 10:57:19 -060012713 submit_info.signalSemaphoreCount = 1;
12714 submit_info.pSignalSemaphores = &semaphore;
12715 vkQueueSubmit(m_device->m_queue, 1, &submit_info, fence);
Mark Muellerc8d441e2016-08-23 17:36:00 -060012716
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012717 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, cannot_delete_event_message);
Mark Mueller917f6bc2016-08-30 10:57:19 -060012718 vkDestroyEvent(m_device->device(), event, nullptr);
12719 m_errorMonitor->VerifyFound();
12720
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012721 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, cannot_delete_semaphore_message);
Mark Mueller917f6bc2016-08-30 10:57:19 -060012722 vkDestroySemaphore(m_device->device(), semaphore, nullptr);
12723 m_errorMonitor->VerifyFound();
12724
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012725 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, cannot_destroy_fence_message);
Mark Mueller917f6bc2016-08-30 10:57:19 -060012726 vkDestroyFence(m_device->device(), fence, nullptr);
12727 m_errorMonitor->VerifyFound();
12728
Tobin Ehlis122207b2016-09-01 08:50:06 -070012729 vkQueueWaitIdle(m_device->m_queue);
Mark Mueller917f6bc2016-08-30 10:57:19 -060012730 vkDestroySemaphore(m_device->device(), semaphore, nullptr);
12731 vkDestroyFence(m_device->device(), fence, nullptr);
12732 vkDestroyEvent(m_device->device(), event, nullptr);
12733 vkDestroyDescriptorPool(m_device->device(), descriptorset_pool, nullptr);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012734 vkDestroyDescriptorSetLayout(m_device->device(), descriptorset_layout, nullptr);
Mark Mueller917f6bc2016-08-30 10:57:19 -060012735 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, nullptr);
12736}
12737
Tobin Ehlis2adda372016-09-01 08:51:06 -070012738TEST_F(VkLayerTest, QueryPoolInUseDestroyedSignaled) {
12739 TEST_DESCRIPTION("Delete in-use query pool.");
12740
12741 ASSERT_NO_FATAL_FAILURE(InitState());
12742 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12743
12744 VkQueryPool query_pool;
12745 VkQueryPoolCreateInfo query_pool_ci{};
12746 query_pool_ci.sType = VK_STRUCTURE_TYPE_QUERY_POOL_CREATE_INFO;
12747 query_pool_ci.queryType = VK_QUERY_TYPE_TIMESTAMP;
12748 query_pool_ci.queryCount = 1;
12749 vkCreateQueryPool(m_device->device(), &query_pool_ci, nullptr, &query_pool);
12750 BeginCommandBuffer();
12751 // Reset query pool to create binding with cmd buffer
12752 vkCmdResetQueryPool(m_commandBuffer->handle(), query_pool, 0, 1);
12753
12754 EndCommandBuffer();
12755
12756 VkSubmitInfo submit_info = {};
12757 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
12758 submit_info.commandBufferCount = 1;
12759 submit_info.pCommandBuffers = &m_commandBuffer->handle();
12760 // Submit cmd buffer and then destroy query pool while in-flight
12761 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
12762
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012763 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Cannot delete query pool 0x");
Tobin Ehlis2adda372016-09-01 08:51:06 -070012764 vkDestroyQueryPool(m_device->handle(), query_pool, NULL);
12765 m_errorMonitor->VerifyFound();
12766
12767 vkQueueWaitIdle(m_device->m_queue);
12768 // Now that cmd buffer done we can safely destroy query_pool
12769 vkDestroyQueryPool(m_device->handle(), query_pool, NULL);
12770}
12771
Tobin Ehlisfafab2d2016-09-07 13:51:24 -060012772TEST_F(VkLayerTest, PipelineInUseDestroyedSignaled) {
12773 TEST_DESCRIPTION("Delete in-use pipeline.");
12774
12775 ASSERT_NO_FATAL_FAILURE(InitState());
12776 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12777
12778 // Empty pipeline layout used for binding PSO
12779 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
12780 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
12781 pipeline_layout_ci.setLayoutCount = 0;
12782 pipeline_layout_ci.pSetLayouts = NULL;
12783
12784 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012785 VkResult err = vkCreatePipelineLayout(m_device->handle(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlisfafab2d2016-09-07 13:51:24 -060012786 ASSERT_VK_SUCCESS(err);
12787
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012788 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Cannot delete pipeline 0x");
Tobin Ehlisfafab2d2016-09-07 13:51:24 -060012789 // Create PSO to be used for draw-time errors below
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012790 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
12791 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Tobin Ehlisfafab2d2016-09-07 13:51:24 -060012792 // Store pipeline handle so we can actually delete it before test finishes
12793 VkPipeline delete_this_pipeline;
12794 { // Scope pipeline so it will be auto-deleted
12795 VkPipelineObj pipe(m_device);
12796 pipe.AddShader(&vs);
12797 pipe.AddShader(&fs);
12798 pipe.AddColorAttachment();
12799 pipe.CreateVKPipeline(pipeline_layout, renderPass());
12800 delete_this_pipeline = pipe.handle();
12801
12802 BeginCommandBuffer();
12803 // Bind pipeline to cmd buffer
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012804 vkCmdBindPipeline(m_commandBuffer->handle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Tobin Ehlisfafab2d2016-09-07 13:51:24 -060012805
12806 EndCommandBuffer();
12807
12808 VkSubmitInfo submit_info = {};
12809 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
12810 submit_info.commandBufferCount = 1;
12811 submit_info.pCommandBuffers = &m_commandBuffer->handle();
12812 // Submit cmd buffer and then pipeline destroyed while in-flight
12813 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
12814 } // Pipeline deletion triggered here
12815 m_errorMonitor->VerifyFound();
12816 // Make sure queue finished and then actually delete pipeline
12817 vkQueueWaitIdle(m_device->m_queue);
12818 vkDestroyPipeline(m_device->handle(), delete_this_pipeline, nullptr);
12819 vkDestroyPipelineLayout(m_device->handle(), pipeline_layout, nullptr);
12820}
12821
Tobin Ehlis7d965da2016-09-19 16:15:45 -060012822TEST_F(VkLayerTest, ImageViewInUseDestroyedSignaled) {
12823 TEST_DESCRIPTION("Delete in-use imageView.");
12824
12825 ASSERT_NO_FATAL_FAILURE(InitState());
12826 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12827
12828 VkDescriptorPoolSize ds_type_count;
12829 ds_type_count.type = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
12830 ds_type_count.descriptorCount = 1;
12831
12832 VkDescriptorPoolCreateInfo ds_pool_ci = {};
12833 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
12834 ds_pool_ci.maxSets = 1;
12835 ds_pool_ci.poolSizeCount = 1;
12836 ds_pool_ci.pPoolSizes = &ds_type_count;
12837
12838 VkDescriptorPool ds_pool;
12839 VkResult err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
12840 ASSERT_VK_SUCCESS(err);
12841
12842 VkSamplerCreateInfo sampler_ci = {};
12843 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
12844 sampler_ci.pNext = NULL;
12845 sampler_ci.magFilter = VK_FILTER_NEAREST;
12846 sampler_ci.minFilter = VK_FILTER_NEAREST;
12847 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
12848 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
12849 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
12850 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
12851 sampler_ci.mipLodBias = 1.0;
12852 sampler_ci.anisotropyEnable = VK_FALSE;
12853 sampler_ci.maxAnisotropy = 1;
12854 sampler_ci.compareEnable = VK_FALSE;
12855 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
12856 sampler_ci.minLod = 1.0;
12857 sampler_ci.maxLod = 1.0;
12858 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
12859 sampler_ci.unnormalizedCoordinates = VK_FALSE;
12860 VkSampler sampler;
12861
12862 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
12863 ASSERT_VK_SUCCESS(err);
12864
12865 VkDescriptorSetLayoutBinding layout_binding;
12866 layout_binding.binding = 0;
12867 layout_binding.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
12868 layout_binding.descriptorCount = 1;
12869 layout_binding.stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
12870 layout_binding.pImmutableSamplers = NULL;
12871
12872 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
12873 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
12874 ds_layout_ci.bindingCount = 1;
12875 ds_layout_ci.pBindings = &layout_binding;
12876 VkDescriptorSetLayout ds_layout;
12877 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
12878 ASSERT_VK_SUCCESS(err);
12879
12880 VkDescriptorSetAllocateInfo alloc_info = {};
12881 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
12882 alloc_info.descriptorSetCount = 1;
12883 alloc_info.descriptorPool = ds_pool;
12884 alloc_info.pSetLayouts = &ds_layout;
12885 VkDescriptorSet descriptor_set;
12886 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
12887 ASSERT_VK_SUCCESS(err);
12888
12889 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
12890 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
12891 pipeline_layout_ci.pNext = NULL;
12892 pipeline_layout_ci.setLayoutCount = 1;
12893 pipeline_layout_ci.pSetLayouts = &ds_layout;
12894
12895 VkPipelineLayout pipeline_layout;
12896 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
12897 ASSERT_VK_SUCCESS(err);
12898
12899 VkImageObj image(m_device);
12900 image.init(128, 128, VK_FORMAT_R8G8B8A8_UNORM, VK_IMAGE_USAGE_SAMPLED_BIT, VK_IMAGE_TILING_OPTIMAL, 0);
12901 ASSERT_TRUE(image.initialized());
12902
12903 VkImageView view;
12904 VkImageViewCreateInfo ivci = {};
12905 ivci.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
12906 ivci.image = image.handle();
12907 ivci.viewType = VK_IMAGE_VIEW_TYPE_2D;
12908 ivci.format = VK_FORMAT_R8G8B8A8_UNORM;
12909 ivci.subresourceRange.layerCount = 1;
12910 ivci.subresourceRange.baseMipLevel = 0;
12911 ivci.subresourceRange.levelCount = 1;
12912 ivci.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
12913
12914 err = vkCreateImageView(m_device->device(), &ivci, NULL, &view);
12915 ASSERT_VK_SUCCESS(err);
12916
12917 VkDescriptorImageInfo image_info{};
12918 image_info.imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
12919 image_info.imageView = view;
12920 image_info.sampler = sampler;
12921
12922 VkWriteDescriptorSet descriptor_write = {};
12923 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
12924 descriptor_write.dstSet = descriptor_set;
12925 descriptor_write.dstBinding = 0;
12926 descriptor_write.descriptorCount = 1;
12927 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
12928 descriptor_write.pImageInfo = &image_info;
12929
12930 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
12931
12932 // Create PSO to use the sampler
12933 char const *vsSource = "#version 450\n"
12934 "\n"
12935 "out gl_PerVertex { \n"
12936 " vec4 gl_Position;\n"
12937 "};\n"
12938 "void main(){\n"
12939 " gl_Position = vec4(1);\n"
12940 "}\n";
12941 char const *fsSource = "#version 450\n"
12942 "\n"
12943 "layout(set=0, binding=0) uniform sampler2D s;\n"
12944 "layout(location=0) out vec4 x;\n"
12945 "void main(){\n"
12946 " x = texture(s, vec2(1));\n"
12947 "}\n";
12948 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
12949 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
12950 VkPipelineObj pipe(m_device);
12951 pipe.AddShader(&vs);
12952 pipe.AddShader(&fs);
12953 pipe.AddColorAttachment();
12954 pipe.CreateVKPipeline(pipeline_layout, renderPass());
12955
12956 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Cannot delete image view 0x");
12957
12958 BeginCommandBuffer();
12959 // Bind pipeline to cmd buffer
12960 vkCmdBindPipeline(m_commandBuffer->handle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
12961 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
12962 &descriptor_set, 0, nullptr);
12963 Draw(1, 0, 0, 0);
12964 EndCommandBuffer();
12965 // Submit cmd buffer then destroy sampler
12966 VkSubmitInfo submit_info = {};
12967 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
12968 submit_info.commandBufferCount = 1;
12969 submit_info.pCommandBuffers = &m_commandBuffer->handle();
12970 // Submit cmd buffer and then destroy imageView while in-flight
12971 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
12972
12973 vkDestroyImageView(m_device->device(), view, nullptr);
12974 m_errorMonitor->VerifyFound();
12975 vkQueueWaitIdle(m_device->m_queue);
12976 // Now we can actually destroy imageView
12977 vkDestroyImageView(m_device->device(), view, NULL);
12978 vkDestroySampler(m_device->device(), sampler, nullptr);
12979 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
12980 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
12981 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
12982}
12983
Tobin Ehlis209532e2016-09-07 13:52:18 -060012984TEST_F(VkLayerTest, SamplerInUseDestroyedSignaled) {
12985 TEST_DESCRIPTION("Delete in-use sampler.");
12986
12987 ASSERT_NO_FATAL_FAILURE(InitState());
12988 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12989
12990 VkDescriptorPoolSize ds_type_count;
12991 ds_type_count.type = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
12992 ds_type_count.descriptorCount = 1;
12993
12994 VkDescriptorPoolCreateInfo ds_pool_ci = {};
12995 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
12996 ds_pool_ci.maxSets = 1;
12997 ds_pool_ci.poolSizeCount = 1;
12998 ds_pool_ci.pPoolSizes = &ds_type_count;
12999
13000 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013001 VkResult err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis209532e2016-09-07 13:52:18 -060013002 ASSERT_VK_SUCCESS(err);
13003
13004 VkSamplerCreateInfo sampler_ci = {};
13005 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
13006 sampler_ci.pNext = NULL;
13007 sampler_ci.magFilter = VK_FILTER_NEAREST;
13008 sampler_ci.minFilter = VK_FILTER_NEAREST;
13009 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
13010 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
13011 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
13012 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
13013 sampler_ci.mipLodBias = 1.0;
13014 sampler_ci.anisotropyEnable = VK_FALSE;
13015 sampler_ci.maxAnisotropy = 1;
13016 sampler_ci.compareEnable = VK_FALSE;
13017 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
13018 sampler_ci.minLod = 1.0;
13019 sampler_ci.maxLod = 1.0;
13020 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
13021 sampler_ci.unnormalizedCoordinates = VK_FALSE;
13022 VkSampler sampler;
13023
13024 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
13025 ASSERT_VK_SUCCESS(err);
13026
13027 VkDescriptorSetLayoutBinding layout_binding;
13028 layout_binding.binding = 0;
Tobin Ehlis94fc0ad2016-09-19 16:23:01 -060013029 layout_binding.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
Tobin Ehlis209532e2016-09-07 13:52:18 -060013030 layout_binding.descriptorCount = 1;
13031 layout_binding.stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
13032 layout_binding.pImmutableSamplers = NULL;
13033
13034 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
13035 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
13036 ds_layout_ci.bindingCount = 1;
13037 ds_layout_ci.pBindings = &layout_binding;
13038 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013039 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis209532e2016-09-07 13:52:18 -060013040 ASSERT_VK_SUCCESS(err);
13041
13042 VkDescriptorSetAllocateInfo alloc_info = {};
13043 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
13044 alloc_info.descriptorSetCount = 1;
13045 alloc_info.descriptorPool = ds_pool;
13046 alloc_info.pSetLayouts = &ds_layout;
13047 VkDescriptorSet descriptor_set;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013048 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
Tobin Ehlis209532e2016-09-07 13:52:18 -060013049 ASSERT_VK_SUCCESS(err);
13050
13051 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
13052 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
13053 pipeline_layout_ci.pNext = NULL;
13054 pipeline_layout_ci.setLayoutCount = 1;
13055 pipeline_layout_ci.pSetLayouts = &ds_layout;
13056
13057 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013058 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis209532e2016-09-07 13:52:18 -060013059 ASSERT_VK_SUCCESS(err);
13060
13061 VkImageObj image(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013062 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 -060013063 ASSERT_TRUE(image.initialized());
13064
13065 VkImageView view;
13066 VkImageViewCreateInfo ivci = {};
13067 ivci.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
13068 ivci.image = image.handle();
13069 ivci.viewType = VK_IMAGE_VIEW_TYPE_2D;
13070 ivci.format = VK_FORMAT_R8G8B8A8_UNORM;
13071 ivci.subresourceRange.layerCount = 1;
13072 ivci.subresourceRange.baseMipLevel = 0;
13073 ivci.subresourceRange.levelCount = 1;
13074 ivci.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
13075
13076 err = vkCreateImageView(m_device->device(), &ivci, NULL, &view);
13077 ASSERT_VK_SUCCESS(err);
13078
13079 VkDescriptorImageInfo image_info{};
13080 image_info.imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
13081 image_info.imageView = view;
13082 image_info.sampler = sampler;
13083
13084 VkWriteDescriptorSet descriptor_write = {};
13085 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
13086 descriptor_write.dstSet = descriptor_set;
13087 descriptor_write.dstBinding = 0;
13088 descriptor_write.descriptorCount = 1;
13089 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
13090 descriptor_write.pImageInfo = &image_info;
13091
13092 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
13093
13094 // Create PSO to use the sampler
13095 char const *vsSource = "#version 450\n"
13096 "\n"
13097 "out gl_PerVertex { \n"
13098 " vec4 gl_Position;\n"
13099 "};\n"
13100 "void main(){\n"
13101 " gl_Position = vec4(1);\n"
13102 "}\n";
13103 char const *fsSource = "#version 450\n"
13104 "\n"
13105 "layout(set=0, binding=0) uniform sampler2D s;\n"
13106 "layout(location=0) out vec4 x;\n"
13107 "void main(){\n"
13108 " x = texture(s, vec2(1));\n"
13109 "}\n";
13110 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13111 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
13112 VkPipelineObj pipe(m_device);
13113 pipe.AddShader(&vs);
13114 pipe.AddShader(&fs);
13115 pipe.AddColorAttachment();
13116 pipe.CreateVKPipeline(pipeline_layout, renderPass());
13117
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013118 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Cannot delete sampler 0x");
Tobin Ehlis209532e2016-09-07 13:52:18 -060013119
13120 BeginCommandBuffer();
13121 // Bind pipeline to cmd buffer
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013122 vkCmdBindPipeline(m_commandBuffer->handle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
13123 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
13124 &descriptor_set, 0, nullptr);
Tobin Ehlis209532e2016-09-07 13:52:18 -060013125 Draw(1, 0, 0, 0);
13126 EndCommandBuffer();
13127 // Submit cmd buffer then destroy sampler
13128 VkSubmitInfo submit_info = {};
13129 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
13130 submit_info.commandBufferCount = 1;
13131 submit_info.pCommandBuffers = &m_commandBuffer->handle();
13132 // Submit cmd buffer and then destroy sampler while in-flight
13133 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
13134
13135 vkDestroySampler(m_device->device(), sampler, nullptr);
13136 m_errorMonitor->VerifyFound();
13137 vkQueueWaitIdle(m_device->m_queue);
13138 // Now we can actually destroy sampler
13139 vkDestroySampler(m_device->device(), sampler, nullptr);
13140 vkDestroyImageView(m_device->device(), view, NULL);
13141 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
13142 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
13143 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
13144}
13145
Mark Mueller1cd9f412016-08-25 13:23:52 -060013146TEST_F(VkLayerTest, QueueForwardProgressFenceWait) {
Mark Mueller96a56d52016-08-24 10:28:05 -060013147 TEST_DESCRIPTION("Call VkQueueSubmit with a semaphore that is already "
Mark Mueller1cd9f412016-08-25 13:23:52 -060013148 "signaled but not waited on by the queue. Wait on a "
13149 "fence that has not yet been submitted to a queue.");
Mark Mueller96a56d52016-08-24 10:28:05 -060013150
13151 ASSERT_NO_FATAL_FAILURE(InitState());
13152 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13153
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013154 const char *queue_forward_progress_message = " that has already been signaled but not waited on by queue 0x";
13155 const char *invalid_fence_wait_message = " which has not been submitted on a Queue or during "
13156 "acquire next image.";
Mark Mueller96a56d52016-08-24 10:28:05 -060013157
13158 BeginCommandBuffer();
13159 EndCommandBuffer();
13160
13161 VkSemaphoreCreateInfo semaphore_create_info = {};
13162 semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
13163 VkSemaphore semaphore;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013164 ASSERT_VK_SUCCESS(vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr, &semaphore));
Mark Mueller96a56d52016-08-24 10:28:05 -060013165 VkSubmitInfo submit_info = {};
13166 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
13167 submit_info.commandBufferCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013168 submit_info.pCommandBuffers = &m_commandBuffer->handle();
Mark Mueller96a56d52016-08-24 10:28:05 -060013169 submit_info.signalSemaphoreCount = 1;
13170 submit_info.pSignalSemaphores = &semaphore;
13171 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
13172 m_errorMonitor->SetDesiredFailureMsg(0, "");
13173 vkResetCommandBuffer(m_commandBuffer->handle(), 0);
13174 BeginCommandBuffer();
13175 EndCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013176 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, queue_forward_progress_message);
Mark Mueller96a56d52016-08-24 10:28:05 -060013177 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
13178 m_errorMonitor->VerifyFound();
13179
Mark Mueller1cd9f412016-08-25 13:23:52 -060013180 VkFenceCreateInfo fence_create_info = {};
13181 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
13182 VkFence fence;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013183 ASSERT_VK_SUCCESS(vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence));
Mark Mueller1cd9f412016-08-25 13:23:52 -060013184
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013185 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT, invalid_fence_wait_message);
Mark Mueller1cd9f412016-08-25 13:23:52 -060013186 vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
13187 m_errorMonitor->VerifyFound();
13188
Mark Mueller4042b652016-09-05 22:52:21 -060013189 vkDeviceWaitIdle(m_device->device());
Mark Mueller1cd9f412016-08-25 13:23:52 -060013190 vkDestroyFence(m_device->device(), fence, nullptr);
Mark Mueller96a56d52016-08-24 10:28:05 -060013191 vkDestroySemaphore(m_device->device(), semaphore, nullptr);
13192}
13193
Tobin Ehlis4af23302016-07-19 10:50:30 -060013194TEST_F(VkLayerTest, FramebufferIncompatible) {
13195 TEST_DESCRIPTION("Bind a secondary command buffer with with a framebuffer "
13196 "that does not match the framebuffer for the active "
13197 "renderpass.");
13198 ASSERT_NO_FATAL_FAILURE(InitState());
13199 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13200
13201 // A renderpass with one color attachment.
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013202 VkAttachmentDescription attachment = {0,
13203 VK_FORMAT_B8G8R8A8_UNORM,
13204 VK_SAMPLE_COUNT_1_BIT,
13205 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
13206 VK_ATTACHMENT_STORE_OP_STORE,
13207 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
13208 VK_ATTACHMENT_STORE_OP_DONT_CARE,
13209 VK_IMAGE_LAYOUT_UNDEFINED,
13210 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL};
Tobin Ehlis4af23302016-07-19 10:50:30 -060013211
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013212 VkAttachmentReference att_ref = {0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL};
Tobin Ehlis4af23302016-07-19 10:50:30 -060013213
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013214 VkSubpassDescription subpass = {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 1, &att_ref, nullptr, nullptr, 0, nullptr};
Tobin Ehlis4af23302016-07-19 10:50:30 -060013215
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013216 VkRenderPassCreateInfo rpci = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 1, &attachment, 1, &subpass, 0, nullptr};
Tobin Ehlis4af23302016-07-19 10:50:30 -060013217
13218 VkRenderPass rp;
13219 VkResult err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
13220 ASSERT_VK_SUCCESS(err);
13221
13222 // A compatible framebuffer.
13223 VkImageObj image(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013224 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 -060013225 ASSERT_TRUE(image.initialized());
13226
13227 VkImageViewCreateInfo ivci = {
13228 VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO,
13229 nullptr,
13230 0,
13231 image.handle(),
13232 VK_IMAGE_VIEW_TYPE_2D,
13233 VK_FORMAT_B8G8R8A8_UNORM,
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013234 {VK_COMPONENT_SWIZZLE_IDENTITY, VK_COMPONENT_SWIZZLE_IDENTITY, VK_COMPONENT_SWIZZLE_IDENTITY,
13235 VK_COMPONENT_SWIZZLE_IDENTITY},
Tobin Ehlis4af23302016-07-19 10:50:30 -060013236 {VK_IMAGE_ASPECT_COLOR_BIT, 0, 1, 0, 1},
13237 };
13238 VkImageView view;
13239 err = vkCreateImageView(m_device->device(), &ivci, nullptr, &view);
13240 ASSERT_VK_SUCCESS(err);
13241
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013242 VkFramebufferCreateInfo fci = {VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr, 0, rp, 1, &view, 32, 32, 1};
Tobin Ehlis4af23302016-07-19 10:50:30 -060013243 VkFramebuffer fb;
13244 err = vkCreateFramebuffer(m_device->device(), &fci, nullptr, &fb);
13245 ASSERT_VK_SUCCESS(err);
13246
13247 VkCommandBufferAllocateInfo cbai = {};
13248 cbai.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
13249 cbai.commandPool = m_commandPool;
13250 cbai.level = VK_COMMAND_BUFFER_LEVEL_SECONDARY;
13251 cbai.commandBufferCount = 1;
13252
13253 VkCommandBuffer sec_cb;
13254 err = vkAllocateCommandBuffers(m_device->device(), &cbai, &sec_cb);
13255 ASSERT_VK_SUCCESS(err);
13256 VkCommandBufferBeginInfo cbbi = {};
13257 VkCommandBufferInheritanceInfo cbii = {};
13258 cbii.renderPass = renderPass();
13259 cbii.framebuffer = fb;
13260 cbbi.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
13261 cbbi.pNext = NULL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013262 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 -060013263 cbbi.pInheritanceInfo = &cbii;
13264 vkBeginCommandBuffer(sec_cb, &cbbi);
13265 vkEndCommandBuffer(sec_cb);
13266
Chris Forbes3400bc52016-09-13 18:10:34 +120013267 VkCommandBufferBeginInfo cbbi2 = {
13268 VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO, nullptr,
13269 0, nullptr
13270 };
13271 vkBeginCommandBuffer(m_commandBuffer->GetBufferHandle(), &cbbi2);
13272 vkCmdBeginRenderPass(m_commandBuffer->GetBufferHandle(), &m_renderPassBeginInfo, VK_SUBPASS_CONTENTS_SECONDARY_COMMAND_BUFFERS);
Tobin Ehlis4af23302016-07-19 10:50:30 -060013273
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013274 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
13275 " that is not the same as the primaryCB's current active framebuffer ");
Tobin Ehlis4af23302016-07-19 10:50:30 -060013276 vkCmdExecuteCommands(m_commandBuffer->GetBufferHandle(), 1, &sec_cb);
13277 m_errorMonitor->VerifyFound();
13278 // Cleanup
13279 vkDestroyImageView(m_device->device(), view, NULL);
13280 vkDestroyRenderPass(m_device->device(), rp, NULL);
13281 vkDestroyFramebuffer(m_device->device(), fb, NULL);
13282}
Tobin Ehlis52b504f2016-07-19 13:25:12 -060013283
13284TEST_F(VkLayerTest, ColorBlendLogicOpTests) {
13285 TEST_DESCRIPTION("If logicOp is available on the device, set it to an "
13286 "invalid value. If logicOp is not available, attempt to "
13287 "use it and verify that we see the correct error.");
13288 ASSERT_NO_FATAL_FAILURE(InitState());
13289 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13290
13291 auto features = m_device->phy().features();
13292 // Set the expected error depending on whether or not logicOp available
13293 if (VK_FALSE == features.logicOp) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013294 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "If logic operations feature not "
13295 "enabled, logicOpEnable must be "
13296 "VK_FALSE");
Tobin Ehlis52b504f2016-07-19 13:25:12 -060013297 } else {
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013298 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, ", logicOp must be a valid VkLogicOp value");
Tobin Ehlis52b504f2016-07-19 13:25:12 -060013299 }
13300 // Create a pipeline using logicOp
13301 VkResult err;
13302
13303 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
13304 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
13305
13306 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013307 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis52b504f2016-07-19 13:25:12 -060013308 ASSERT_VK_SUCCESS(err);
13309
13310 VkPipelineViewportStateCreateInfo vp_state_ci = {};
13311 vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
13312 vp_state_ci.viewportCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013313 VkViewport vp = {}; // Just need dummy vp to point to
Tobin Ehlis52b504f2016-07-19 13:25:12 -060013314 vp_state_ci.pViewports = &vp;
13315 vp_state_ci.scissorCount = 1;
13316 VkRect2D scissors = {}; // Dummy scissors to point to
13317 vp_state_ci.pScissors = &scissors;
13318 // No dynamic state
13319 VkPipelineDynamicStateCreateInfo dyn_state_ci = {};
13320 dyn_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_DYNAMIC_STATE_CREATE_INFO;
13321
13322 VkPipelineShaderStageCreateInfo shaderStages[2];
13323 memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo));
13324
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013325 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
13326 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Tobin Ehlis52b504f2016-07-19 13:25:12 -060013327 shaderStages[0] = vs.GetStageCreateInfo();
13328 shaderStages[1] = fs.GetStageCreateInfo();
13329
13330 VkPipelineVertexInputStateCreateInfo vi_ci = {};
13331 vi_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
13332
13333 VkPipelineInputAssemblyStateCreateInfo ia_ci = {};
13334 ia_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
13335 ia_ci.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP;
13336
13337 VkPipelineRasterizationStateCreateInfo rs_ci = {};
13338 rs_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
13339
13340 VkPipelineColorBlendAttachmentState att = {};
13341 att.blendEnable = VK_FALSE;
13342 att.colorWriteMask = 0xf;
13343
13344 VkPipelineColorBlendStateCreateInfo cb_ci = {};
13345 cb_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO;
13346 // Enable logicOp & set logicOp to value 1 beyond allowed entries
13347 cb_ci.logicOpEnable = VK_TRUE;
13348 cb_ci.logicOp = VK_LOGIC_OP_RANGE_SIZE; // This should cause an error
13349 cb_ci.attachmentCount = 1;
13350 cb_ci.pAttachments = &att;
13351
13352 VkGraphicsPipelineCreateInfo gp_ci = {};
13353 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
13354 gp_ci.stageCount = 2;
13355 gp_ci.pStages = shaderStages;
13356 gp_ci.pVertexInputState = &vi_ci;
13357 gp_ci.pInputAssemblyState = &ia_ci;
13358 gp_ci.pViewportState = &vp_state_ci;
13359 gp_ci.pRasterizationState = &rs_ci;
13360 gp_ci.pColorBlendState = &cb_ci;
13361 gp_ci.pDynamicState = &dyn_state_ci;
13362 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
13363 gp_ci.layout = pipeline_layout;
13364 gp_ci.renderPass = renderPass();
13365
13366 VkPipelineCacheCreateInfo pc_ci = {};
13367 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
13368
13369 VkPipeline pipeline;
13370 VkPipelineCache pipelineCache;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013371 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Tobin Ehlis52b504f2016-07-19 13:25:12 -060013372 ASSERT_VK_SUCCESS(err);
13373
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013374 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Tobin Ehlis52b504f2016-07-19 13:25:12 -060013375 m_errorMonitor->VerifyFound();
13376 if (VK_SUCCESS == err) {
13377 vkDestroyPipeline(m_device->device(), pipeline, NULL);
13378 }
13379 m_errorMonitor->VerifyFound();
13380 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
13381 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
13382}
Mark Lobodzinski209b5292015-09-17 09:44:05 -060013383#endif // DRAW_STATE_TESTS
13384
Tobin Ehlis0788f522015-05-26 16:11:58 -060013385#if THREADING_TESTS
Mike Stroyanaccf7692015-05-12 16:00:45 -060013386#if GTEST_IS_THREADSAFE
13387struct thread_data_struct {
Chia-I Wu3432a0c2015-10-27 18:04:07 +080013388 VkCommandBuffer commandBuffer;
Mike Stroyanaccf7692015-05-12 16:00:45 -060013389 VkEvent event;
13390 bool bailout;
13391};
13392
Karl Schultz6addd812016-02-02 17:17:23 -070013393extern "C" void *AddToCommandBuffer(void *arg) {
13394 struct thread_data_struct *data = (struct thread_data_struct *)arg;
Mike Stroyanaccf7692015-05-12 16:00:45 -060013395
Mike Stroyana6d14942016-07-13 15:10:05 -060013396 for (int i = 0; i < 80000; i++) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013397 vkCmdSetEvent(data->commandBuffer, data->event, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT);
Mike Stroyanaccf7692015-05-12 16:00:45 -060013398 if (data->bailout) {
13399 break;
13400 }
13401 }
13402 return NULL;
13403}
13404
Karl Schultz6addd812016-02-02 17:17:23 -070013405TEST_F(VkLayerTest, ThreadCommandBufferCollision) {
Mike Stroyan4268d1f2015-07-13 14:45:35 -060013406 test_platform_thread thread;
Mike Stroyanaccf7692015-05-12 16:00:45 -060013407
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013408 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "THREADING ERROR");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060013409
Mike Stroyanaccf7692015-05-12 16:00:45 -060013410 ASSERT_NO_FATAL_FAILURE(InitState());
13411 ASSERT_NO_FATAL_FAILURE(InitViewport());
13412 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13413
Chia-I Wu3432a0c2015-10-27 18:04:07 +080013414 // Calls AllocateCommandBuffers
13415 VkCommandBufferObj commandBuffer(m_device, m_commandPool);
Mark Lobodzinski5495d132015-09-30 16:19:16 -060013416
13417 // Avoid creating RenderPass
Chia-I Wu3432a0c2015-10-27 18:04:07 +080013418 commandBuffer.BeginCommandBuffer();
Mike Stroyanaccf7692015-05-12 16:00:45 -060013419
13420 VkEventCreateInfo event_info;
13421 VkEvent event;
Mike Stroyanaccf7692015-05-12 16:00:45 -060013422 VkResult err;
13423
13424 memset(&event_info, 0, sizeof(event_info));
13425 event_info.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO;
13426
Chia-I Wuf7458c52015-10-26 21:10:41 +080013427 err = vkCreateEvent(device(), &event_info, NULL, &event);
Mike Stroyanaccf7692015-05-12 16:00:45 -060013428 ASSERT_VK_SUCCESS(err);
13429
Mike Stroyanaccf7692015-05-12 16:00:45 -060013430 err = vkResetEvent(device(), event);
13431 ASSERT_VK_SUCCESS(err);
13432
13433 struct thread_data_struct data;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080013434 data.commandBuffer = commandBuffer.GetBufferHandle();
Mike Stroyanaccf7692015-05-12 16:00:45 -060013435 data.event = event;
13436 data.bailout = false;
13437 m_errorMonitor->SetBailout(&data.bailout);
Mike Stroyana6d14942016-07-13 15:10:05 -060013438
13439 // First do some correct operations using multiple threads.
13440 // Add many entries to command buffer from another thread.
13441 test_platform_thread_create(&thread, AddToCommandBuffer, (void *)&data);
13442 // Make non-conflicting calls from this thread at the same time.
13443 for (int i = 0; i < 80000; i++) {
Mike Stroyand6343902016-07-14 08:56:16 -060013444 uint32_t count;
13445 vkEnumeratePhysicalDevices(instance(), &count, NULL);
Mike Stroyana6d14942016-07-13 15:10:05 -060013446 }
13447 test_platform_thread_join(thread, NULL);
13448
13449 // Then do some incorrect operations using multiple threads.
Mike Stroyanaccf7692015-05-12 16:00:45 -060013450 // Add many entries to command buffer from another thread.
Mike Stroyan4268d1f2015-07-13 14:45:35 -060013451 test_platform_thread_create(&thread, AddToCommandBuffer, (void *)&data);
Mike Stroyanaccf7692015-05-12 16:00:45 -060013452 // Add many entries to command buffer from this thread at the same time.
13453 AddToCommandBuffer(&data);
Mark Lobodzinski5495d132015-09-30 16:19:16 -060013454
Mike Stroyan4268d1f2015-07-13 14:45:35 -060013455 test_platform_thread_join(thread, NULL);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080013456 commandBuffer.EndCommandBuffer();
Mike Stroyanaccf7692015-05-12 16:00:45 -060013457
Mike Stroyan10b8cb72016-01-22 15:22:03 -070013458 m_errorMonitor->SetBailout(NULL);
13459
Chris Forbes8f36a8a2016-04-07 13:21:07 +120013460 m_errorMonitor->VerifyFound();
Mike Stroyanaccf7692015-05-12 16:00:45 -060013461
Chia-I Wuf7458c52015-10-26 21:10:41 +080013462 vkDestroyEvent(device(), event, NULL);
Mike Stroyanaccf7692015-05-12 16:00:45 -060013463}
Mark Lobodzinski209b5292015-09-17 09:44:05 -060013464#endif // GTEST_IS_THREADSAFE
13465#endif // THREADING_TESTS
13466
Chris Forbes9f7ff632015-05-25 11:13:08 +120013467#if SHADER_CHECKER_TESTS
Karl Schultz6addd812016-02-02 17:17:23 -070013468TEST_F(VkLayerTest, InvalidSPIRVCodeSize) {
Chris Forbes1cc79542016-07-20 11:13:44 +120013469 TEST_DESCRIPTION("Test that an error is produced for a spirv module "
13470 "with an impossible code size");
13471
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013472 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Invalid SPIR-V header");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060013473
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060013474 ASSERT_NO_FATAL_FAILURE(InitState());
13475 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13476
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060013477 VkShaderModule module;
13478 VkShaderModuleCreateInfo moduleCreateInfo;
13479 struct icd_spv_header spv;
13480
13481 spv.magic = ICD_SPV_MAGIC;
13482 spv.version = ICD_SPV_VERSION;
13483 spv.gen_magic = 0;
13484
13485 moduleCreateInfo.sType = VK_STRUCTURE_TYPE_SHADER_MODULE_CREATE_INFO;
13486 moduleCreateInfo.pNext = NULL;
Karl Schultz6addd812016-02-02 17:17:23 -070013487 moduleCreateInfo.pCode = (const uint32_t *)&spv;
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060013488 moduleCreateInfo.codeSize = 4;
13489 moduleCreateInfo.flags = 0;
Chia-I Wuf7458c52015-10-26 21:10:41 +080013490 vkCreateShaderModule(m_device->device(), &moduleCreateInfo, NULL, &module);
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060013491
Chris Forbes8f36a8a2016-04-07 13:21:07 +120013492 m_errorMonitor->VerifyFound();
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060013493}
13494
Karl Schultz6addd812016-02-02 17:17:23 -070013495TEST_F(VkLayerTest, InvalidSPIRVMagic) {
Chris Forbes1cc79542016-07-20 11:13:44 +120013496 TEST_DESCRIPTION("Test that an error is produced for a spirv module "
13497 "with a bad magic number");
13498
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013499 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Invalid SPIR-V magic number");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060013500
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060013501 ASSERT_NO_FATAL_FAILURE(InitState());
13502 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13503
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060013504 VkShaderModule module;
13505 VkShaderModuleCreateInfo moduleCreateInfo;
13506 struct icd_spv_header spv;
13507
13508 spv.magic = ~ICD_SPV_MAGIC;
13509 spv.version = ICD_SPV_VERSION;
13510 spv.gen_magic = 0;
13511
13512 moduleCreateInfo.sType = VK_STRUCTURE_TYPE_SHADER_MODULE_CREATE_INFO;
13513 moduleCreateInfo.pNext = NULL;
Karl Schultz6addd812016-02-02 17:17:23 -070013514 moduleCreateInfo.pCode = (const uint32_t *)&spv;
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060013515 moduleCreateInfo.codeSize = sizeof(spv) + 10;
13516 moduleCreateInfo.flags = 0;
Chia-I Wuf7458c52015-10-26 21:10:41 +080013517 vkCreateShaderModule(m_device->device(), &moduleCreateInfo, NULL, &module);
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060013518
Chris Forbes8f36a8a2016-04-07 13:21:07 +120013519 m_errorMonitor->VerifyFound();
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060013520}
13521
Chris Forbesb4afd0f2016-04-04 10:48:35 +120013522#if 0
13523// Not currently covered by SPIRV-Tools validator
Karl Schultz6addd812016-02-02 17:17:23 -070013524TEST_F(VkLayerTest, InvalidSPIRVVersion) {
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -070013525 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Chris Forbesb4afd0f2016-04-04 10:48:35 +120013526 "Invalid SPIR-V header");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060013527
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060013528 ASSERT_NO_FATAL_FAILURE(InitState());
13529 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13530
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060013531 VkShaderModule module;
13532 VkShaderModuleCreateInfo moduleCreateInfo;
13533 struct icd_spv_header spv;
13534
13535 spv.magic = ICD_SPV_MAGIC;
13536 spv.version = ~ICD_SPV_VERSION;
13537 spv.gen_magic = 0;
13538
13539 moduleCreateInfo.sType = VK_STRUCTURE_TYPE_SHADER_MODULE_CREATE_INFO;
13540 moduleCreateInfo.pNext = NULL;
13541
Karl Schultz6addd812016-02-02 17:17:23 -070013542 moduleCreateInfo.pCode = (const uint32_t *)&spv;
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060013543 moduleCreateInfo.codeSize = sizeof(spv) + 10;
13544 moduleCreateInfo.flags = 0;
Chia-I Wuf7458c52015-10-26 21:10:41 +080013545 vkCreateShaderModule(m_device->device(), &moduleCreateInfo, NULL, &module);
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060013546
Chris Forbes8f36a8a2016-04-07 13:21:07 +120013547 m_errorMonitor->VerifyFound();
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060013548}
Chris Forbesb4afd0f2016-04-04 10:48:35 +120013549#endif
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060013550
Karl Schultz6addd812016-02-02 17:17:23 -070013551TEST_F(VkLayerTest, CreatePipelineVertexOutputNotConsumed) {
Chris Forbes1cc79542016-07-20 11:13:44 +120013552 TEST_DESCRIPTION("Test that a warning is produced for a vertex output that "
13553 "is not consumed by the fragment stage");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013554 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT, "not consumed by fragment shader");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060013555
Chris Forbes9f7ff632015-05-25 11:13:08 +120013556 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -060013557 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbes9f7ff632015-05-25 11:13:08 +120013558
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013559 char const *vsSource = "#version 450\n"
13560 "\n"
13561 "layout(location=0) out float x;\n"
13562 "out gl_PerVertex {\n"
13563 " vec4 gl_Position;\n"
13564 "};\n"
13565 "void main(){\n"
13566 " gl_Position = vec4(1);\n"
13567 " x = 0;\n"
13568 "}\n";
13569 char const *fsSource = "#version 450\n"
13570 "\n"
13571 "layout(location=0) out vec4 color;\n"
13572 "void main(){\n"
13573 " color = vec4(1);\n"
13574 "}\n";
Chris Forbes9f7ff632015-05-25 11:13:08 +120013575
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060013576 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13577 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbes9f7ff632015-05-25 11:13:08 +120013578
13579 VkPipelineObj pipe(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +080013580 pipe.AddColorAttachment();
Chris Forbes9f7ff632015-05-25 11:13:08 +120013581 pipe.AddShader(&vs);
13582 pipe.AddShader(&fs);
13583
Chris Forbes9f7ff632015-05-25 11:13:08 +120013584 VkDescriptorSetObj descriptorSet(m_device);
13585 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080013586 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbes9f7ff632015-05-25 11:13:08 +120013587
Tony Barbour5781e8f2015-08-04 16:23:11 -060013588 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbes9f7ff632015-05-25 11:13:08 +120013589
Chris Forbes8f36a8a2016-04-07 13:21:07 +120013590 m_errorMonitor->VerifyFound();
Chris Forbes9f7ff632015-05-25 11:13:08 +120013591}
Chris Forbes9f7ff632015-05-25 11:13:08 +120013592
Karl Schultz6addd812016-02-02 17:17:23 -070013593TEST_F(VkLayerTest, CreatePipelineFragmentInputNotProvided) {
Chris Forbes1cc79542016-07-20 11:13:44 +120013594 TEST_DESCRIPTION("Test that an error is produced for a fragment shader input "
13595 "which is not present in the outputs of the previous stage");
13596
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013597 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "not written by vertex shader");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060013598
Chris Forbes59cb88d2015-05-25 11:13:13 +120013599 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -060013600 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbes59cb88d2015-05-25 11:13:13 +120013601
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013602 char const *vsSource = "#version 450\n"
13603 "\n"
13604 "out gl_PerVertex {\n"
13605 " vec4 gl_Position;\n"
13606 "};\n"
13607 "void main(){\n"
13608 " gl_Position = vec4(1);\n"
13609 "}\n";
13610 char const *fsSource = "#version 450\n"
13611 "\n"
13612 "layout(location=0) in float x;\n"
13613 "layout(location=0) out vec4 color;\n"
13614 "void main(){\n"
13615 " color = vec4(x);\n"
13616 "}\n";
Chris Forbes59cb88d2015-05-25 11:13:13 +120013617
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060013618 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13619 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbes59cb88d2015-05-25 11:13:13 +120013620
13621 VkPipelineObj pipe(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +080013622 pipe.AddColorAttachment();
Chris Forbes59cb88d2015-05-25 11:13:13 +120013623 pipe.AddShader(&vs);
13624 pipe.AddShader(&fs);
13625
Chris Forbes59cb88d2015-05-25 11:13:13 +120013626 VkDescriptorSetObj descriptorSet(m_device);
13627 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080013628 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbes59cb88d2015-05-25 11:13:13 +120013629
Tony Barbour5781e8f2015-08-04 16:23:11 -060013630 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbes59cb88d2015-05-25 11:13:13 +120013631
Chris Forbes8f36a8a2016-04-07 13:21:07 +120013632 m_errorMonitor->VerifyFound();
Chris Forbes59cb88d2015-05-25 11:13:13 +120013633}
13634
Karl Schultz6addd812016-02-02 17:17:23 -070013635TEST_F(VkLayerTest, CreatePipelineFragmentInputNotProvidedInBlock) {
Chris Forbes1cc79542016-07-20 11:13:44 +120013636 TEST_DESCRIPTION("Test that an error is produced for a fragment shader input "
13637 "within an interace block, which is not present in the outputs "
13638 "of the previous stage.");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013639 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "not written by vertex shader");
Chris Forbesa3e85f62016-01-15 14:53:11 +130013640
13641 ASSERT_NO_FATAL_FAILURE(InitState());
13642 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13643
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013644 char const *vsSource = "#version 450\n"
13645 "\n"
13646 "out gl_PerVertex {\n"
13647 " vec4 gl_Position;\n"
13648 "};\n"
13649 "void main(){\n"
13650 " gl_Position = vec4(1);\n"
13651 "}\n";
13652 char const *fsSource = "#version 450\n"
13653 "\n"
13654 "in block { layout(location=0) float x; } ins;\n"
13655 "layout(location=0) out vec4 color;\n"
13656 "void main(){\n"
13657 " color = vec4(ins.x);\n"
13658 "}\n";
Chris Forbesa3e85f62016-01-15 14:53:11 +130013659
13660 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13661 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
13662
13663 VkPipelineObj pipe(m_device);
13664 pipe.AddColorAttachment();
13665 pipe.AddShader(&vs);
13666 pipe.AddShader(&fs);
13667
13668 VkDescriptorSetObj descriptorSet(m_device);
13669 descriptorSet.AppendDummy();
13670 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
13671
13672 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
13673
Chris Forbes8f36a8a2016-04-07 13:21:07 +120013674 m_errorMonitor->VerifyFound();
Chris Forbesa3e85f62016-01-15 14:53:11 +130013675}
13676
Karl Schultz6addd812016-02-02 17:17:23 -070013677TEST_F(VkLayerTest, CreatePipelineVsFsTypeMismatchArraySize) {
Chris Forbes1cc79542016-07-20 11:13:44 +120013678 TEST_DESCRIPTION("Test that an error is produced for mismatched array sizes "
13679 "across the VS->FS interface");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013680 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Type mismatch on location 0.0: 'ptr to "
13681 "output arr[2] of float32' vs 'ptr to "
13682 "input arr[3] of float32'");
Chris Forbes0036fd12016-01-26 14:19:49 +130013683
13684 ASSERT_NO_FATAL_FAILURE(InitState());
13685 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13686
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013687 char const *vsSource = "#version 450\n"
13688 "\n"
13689 "layout(location=0) out float x[2];\n"
13690 "out gl_PerVertex {\n"
13691 " vec4 gl_Position;\n"
13692 "};\n"
13693 "void main(){\n"
13694 " x[0] = 0; x[1] = 0;\n"
13695 " gl_Position = vec4(1);\n"
13696 "}\n";
13697 char const *fsSource = "#version 450\n"
13698 "\n"
13699 "layout(location=0) in float x[3];\n"
13700 "layout(location=0) out vec4 color;\n"
13701 "void main(){\n"
13702 " color = vec4(x[0] + x[1] + x[2]);\n"
13703 "}\n";
Chris Forbes0036fd12016-01-26 14:19:49 +130013704
13705 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13706 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
13707
13708 VkPipelineObj pipe(m_device);
13709 pipe.AddColorAttachment();
13710 pipe.AddShader(&vs);
13711 pipe.AddShader(&fs);
13712
13713 VkDescriptorSetObj descriptorSet(m_device);
13714 descriptorSet.AppendDummy();
13715 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
13716
13717 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
13718
Chris Forbes8f36a8a2016-04-07 13:21:07 +120013719 m_errorMonitor->VerifyFound();
Chris Forbes0036fd12016-01-26 14:19:49 +130013720}
13721
Karl Schultz6addd812016-02-02 17:17:23 -070013722TEST_F(VkLayerTest, CreatePipelineVsFsTypeMismatch) {
Chris Forbes1cc79542016-07-20 11:13:44 +120013723 TEST_DESCRIPTION("Test that an error is produced for mismatched types across "
13724 "the VS->FS interface");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013725 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Type mismatch on location 0");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060013726
Chris Forbesb56af562015-05-25 11:13:17 +120013727 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -060013728 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbesb56af562015-05-25 11:13:17 +120013729
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013730 char const *vsSource = "#version 450\n"
13731 "\n"
13732 "layout(location=0) out int x;\n"
13733 "out gl_PerVertex {\n"
13734 " vec4 gl_Position;\n"
13735 "};\n"
13736 "void main(){\n"
13737 " x = 0;\n"
13738 " gl_Position = vec4(1);\n"
13739 "}\n";
13740 char const *fsSource = "#version 450\n"
13741 "\n"
13742 "layout(location=0) in float x;\n" /* VS writes int */
13743 "layout(location=0) out vec4 color;\n"
13744 "void main(){\n"
13745 " color = vec4(x);\n"
13746 "}\n";
Chris Forbesb56af562015-05-25 11:13:17 +120013747
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060013748 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13749 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbesb56af562015-05-25 11:13:17 +120013750
13751 VkPipelineObj pipe(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +080013752 pipe.AddColorAttachment();
Chris Forbesb56af562015-05-25 11:13:17 +120013753 pipe.AddShader(&vs);
13754 pipe.AddShader(&fs);
13755
Chris Forbesb56af562015-05-25 11:13:17 +120013756 VkDescriptorSetObj descriptorSet(m_device);
13757 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080013758 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbesb56af562015-05-25 11:13:17 +120013759
Tony Barbour5781e8f2015-08-04 16:23:11 -060013760 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbesb56af562015-05-25 11:13:17 +120013761
Chris Forbes8f36a8a2016-04-07 13:21:07 +120013762 m_errorMonitor->VerifyFound();
Chris Forbesb56af562015-05-25 11:13:17 +120013763}
13764
Karl Schultz6addd812016-02-02 17:17:23 -070013765TEST_F(VkLayerTest, CreatePipelineVsFsTypeMismatchInBlock) {
Chris Forbes1cc79542016-07-20 11:13:44 +120013766 TEST_DESCRIPTION("Test that an error is produced for mismatched types across "
13767 "the VS->FS interface, when the variable is contained within "
13768 "an interface block");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013769 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Type mismatch on location 0");
Chris Forbesa3e85f62016-01-15 14:53:11 +130013770
13771 ASSERT_NO_FATAL_FAILURE(InitState());
13772 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13773
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013774 char const *vsSource = "#version 450\n"
13775 "\n"
13776 "out block { layout(location=0) int x; } outs;\n"
13777 "out gl_PerVertex {\n"
13778 " vec4 gl_Position;\n"
13779 "};\n"
13780 "void main(){\n"
13781 " outs.x = 0;\n"
13782 " gl_Position = vec4(1);\n"
13783 "}\n";
13784 char const *fsSource = "#version 450\n"
13785 "\n"
13786 "in block { layout(location=0) float x; } ins;\n" /* VS writes int */
13787 "layout(location=0) out vec4 color;\n"
13788 "void main(){\n"
13789 " color = vec4(ins.x);\n"
13790 "}\n";
Chris Forbesa3e85f62016-01-15 14:53:11 +130013791
13792 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13793 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
13794
13795 VkPipelineObj pipe(m_device);
13796 pipe.AddColorAttachment();
13797 pipe.AddShader(&vs);
13798 pipe.AddShader(&fs);
13799
13800 VkDescriptorSetObj descriptorSet(m_device);
13801 descriptorSet.AppendDummy();
13802 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
13803
13804 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
13805
Chris Forbes8f36a8a2016-04-07 13:21:07 +120013806 m_errorMonitor->VerifyFound();
Chris Forbese9928822016-02-17 14:44:52 +130013807}
13808
13809TEST_F(VkLayerTest, CreatePipelineVsFsMismatchByLocation) {
Chris Forbes1cc79542016-07-20 11:13:44 +120013810 TEST_DESCRIPTION("Test that an error is produced for location mismatches across "
13811 "the VS->FS interface; This should manifest as a not-written/not-consumed "
13812 "pair, but flushes out broken walking of the interfaces");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013813 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 +130013814
13815 ASSERT_NO_FATAL_FAILURE(InitState());
13816 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13817
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013818 char const *vsSource = "#version 450\n"
13819 "\n"
13820 "out block { layout(location=1) float x; } outs;\n"
13821 "out gl_PerVertex {\n"
13822 " vec4 gl_Position;\n"
13823 "};\n"
13824 "void main(){\n"
13825 " outs.x = 0;\n"
13826 " gl_Position = vec4(1);\n"
13827 "}\n";
13828 char const *fsSource = "#version 450\n"
13829 "\n"
13830 "in block { layout(location=0) float x; } ins;\n"
13831 "layout(location=0) out vec4 color;\n"
13832 "void main(){\n"
13833 " color = vec4(ins.x);\n"
13834 "}\n";
Chris Forbese9928822016-02-17 14:44:52 +130013835
13836 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13837 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
13838
13839 VkPipelineObj pipe(m_device);
13840 pipe.AddColorAttachment();
13841 pipe.AddShader(&vs);
13842 pipe.AddShader(&fs);
13843
13844 VkDescriptorSetObj descriptorSet(m_device);
13845 descriptorSet.AppendDummy();
13846 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
13847
13848 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
13849
Chris Forbes8f36a8a2016-04-07 13:21:07 +120013850 m_errorMonitor->VerifyFound();
Chris Forbese9928822016-02-17 14:44:52 +130013851}
13852
13853TEST_F(VkLayerTest, CreatePipelineVsFsMismatchByComponent) {
Chris Forbes1cc79542016-07-20 11:13:44 +120013854 TEST_DESCRIPTION("Test that an error is produced for component mismatches across the "
13855 "VS->FS interface. It's not enough to have the same set of locations in "
13856 "use; matching is defined in terms of spirv variables.");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013857 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 +130013858
13859 ASSERT_NO_FATAL_FAILURE(InitState());
13860 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13861
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013862 char const *vsSource = "#version 450\n"
13863 "\n"
13864 "out block { layout(location=0, component=0) float x; } outs;\n"
13865 "out gl_PerVertex {\n"
13866 " vec4 gl_Position;\n"
13867 "};\n"
13868 "void main(){\n"
13869 " outs.x = 0;\n"
13870 " gl_Position = vec4(1);\n"
13871 "}\n";
13872 char const *fsSource = "#version 450\n"
13873 "\n"
13874 "in block { layout(location=0, component=1) float x; } ins;\n"
13875 "layout(location=0) out vec4 color;\n"
13876 "void main(){\n"
13877 " color = vec4(ins.x);\n"
13878 "}\n";
Chris Forbese9928822016-02-17 14:44:52 +130013879
13880 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13881 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
13882
13883 VkPipelineObj pipe(m_device);
13884 pipe.AddColorAttachment();
13885 pipe.AddShader(&vs);
13886 pipe.AddShader(&fs);
13887
13888 VkDescriptorSetObj descriptorSet(m_device);
13889 descriptorSet.AppendDummy();
13890 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
13891
13892 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
13893
Chris Forbes8f36a8a2016-04-07 13:21:07 +120013894 m_errorMonitor->VerifyFound();
Chris Forbesa3e85f62016-01-15 14:53:11 +130013895}
13896
Karl Schultz6addd812016-02-02 17:17:23 -070013897TEST_F(VkLayerTest, CreatePipelineAttribNotConsumed) {
Chris Forbes1cc79542016-07-20 11:13:44 +120013898 TEST_DESCRIPTION("Test that a warning is produced for a vertex attribute which is "
13899 "not consumed by the vertex shader");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013900 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT, "location 0 not consumed by VS");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060013901
Chris Forbesde136e02015-05-25 11:13:28 +120013902 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -060013903 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbesde136e02015-05-25 11:13:28 +120013904
13905 VkVertexInputBindingDescription input_binding;
13906 memset(&input_binding, 0, sizeof(input_binding));
13907
13908 VkVertexInputAttributeDescription input_attrib;
13909 memset(&input_attrib, 0, sizeof(input_attrib));
13910 input_attrib.format = VK_FORMAT_R32_SFLOAT;
13911
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013912 char const *vsSource = "#version 450\n"
13913 "\n"
13914 "out gl_PerVertex {\n"
13915 " vec4 gl_Position;\n"
13916 "};\n"
13917 "void main(){\n"
13918 " gl_Position = vec4(1);\n"
13919 "}\n";
13920 char const *fsSource = "#version 450\n"
13921 "\n"
13922 "layout(location=0) out vec4 color;\n"
13923 "void main(){\n"
13924 " color = vec4(1);\n"
13925 "}\n";
Chris Forbesde136e02015-05-25 11:13:28 +120013926
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060013927 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13928 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbesde136e02015-05-25 11:13:28 +120013929
13930 VkPipelineObj pipe(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +080013931 pipe.AddColorAttachment();
Chris Forbesde136e02015-05-25 11:13:28 +120013932 pipe.AddShader(&vs);
13933 pipe.AddShader(&fs);
13934
13935 pipe.AddVertexInputBindings(&input_binding, 1);
13936 pipe.AddVertexInputAttribs(&input_attrib, 1);
13937
Chris Forbesde136e02015-05-25 11:13:28 +120013938 VkDescriptorSetObj descriptorSet(m_device);
13939 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080013940 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbesde136e02015-05-25 11:13:28 +120013941
Tony Barbour5781e8f2015-08-04 16:23:11 -060013942 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbesde136e02015-05-25 11:13:28 +120013943
Chris Forbes8f36a8a2016-04-07 13:21:07 +120013944 m_errorMonitor->VerifyFound();
Chris Forbesde136e02015-05-25 11:13:28 +120013945}
13946
Karl Schultz6addd812016-02-02 17:17:23 -070013947TEST_F(VkLayerTest, CreatePipelineAttribLocationMismatch) {
Chris Forbes1cc79542016-07-20 11:13:44 +120013948 TEST_DESCRIPTION("Test that a warning is produced for a location mismatch on "
13949 "vertex attributes. This flushes out bad behavior in the interface walker");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013950 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT, "location 0 not consumed by VS");
Chris Forbes7d83cd52016-01-15 11:32:03 +130013951
13952 ASSERT_NO_FATAL_FAILURE(InitState());
13953 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13954
13955 VkVertexInputBindingDescription input_binding;
13956 memset(&input_binding, 0, sizeof(input_binding));
13957
13958 VkVertexInputAttributeDescription input_attrib;
13959 memset(&input_attrib, 0, sizeof(input_attrib));
13960 input_attrib.format = VK_FORMAT_R32_SFLOAT;
13961
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013962 char const *vsSource = "#version 450\n"
13963 "\n"
13964 "layout(location=1) in float x;\n"
13965 "out gl_PerVertex {\n"
13966 " vec4 gl_Position;\n"
13967 "};\n"
13968 "void main(){\n"
13969 " gl_Position = vec4(x);\n"
13970 "}\n";
13971 char const *fsSource = "#version 450\n"
13972 "\n"
13973 "layout(location=0) out vec4 color;\n"
13974 "void main(){\n"
13975 " color = vec4(1);\n"
13976 "}\n";
Chris Forbes7d83cd52016-01-15 11:32:03 +130013977
13978 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13979 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
13980
13981 VkPipelineObj pipe(m_device);
13982 pipe.AddColorAttachment();
13983 pipe.AddShader(&vs);
13984 pipe.AddShader(&fs);
13985
13986 pipe.AddVertexInputBindings(&input_binding, 1);
13987 pipe.AddVertexInputAttribs(&input_attrib, 1);
13988
13989 VkDescriptorSetObj descriptorSet(m_device);
13990 descriptorSet.AppendDummy();
13991 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
13992
13993 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
13994
Chris Forbes8f36a8a2016-04-07 13:21:07 +120013995 m_errorMonitor->VerifyFound();
Chris Forbes7d83cd52016-01-15 11:32:03 +130013996}
13997
Karl Schultz6addd812016-02-02 17:17:23 -070013998TEST_F(VkLayerTest, CreatePipelineAttribNotProvided) {
Chris Forbes1cc79542016-07-20 11:13:44 +120013999 TEST_DESCRIPTION("Test that an error is produced for a VS input which is not "
14000 "provided by a vertex attribute");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014001 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 -060014002
Chris Forbes62e8e502015-05-25 11:13:29 +120014003 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -060014004 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbes62e8e502015-05-25 11:13:29 +120014005
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014006 char const *vsSource = "#version 450\n"
14007 "\n"
14008 "layout(location=0) in vec4 x;\n" /* not provided */
14009 "out gl_PerVertex {\n"
14010 " vec4 gl_Position;\n"
14011 "};\n"
14012 "void main(){\n"
14013 " gl_Position = x;\n"
14014 "}\n";
14015 char const *fsSource = "#version 450\n"
14016 "\n"
14017 "layout(location=0) out vec4 color;\n"
14018 "void main(){\n"
14019 " color = vec4(1);\n"
14020 "}\n";
Chris Forbes62e8e502015-05-25 11:13:29 +120014021
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060014022 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
14023 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbes62e8e502015-05-25 11:13:29 +120014024
14025 VkPipelineObj pipe(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +080014026 pipe.AddColorAttachment();
Chris Forbes62e8e502015-05-25 11:13:29 +120014027 pipe.AddShader(&vs);
14028 pipe.AddShader(&fs);
14029
Chris Forbes62e8e502015-05-25 11:13:29 +120014030 VkDescriptorSetObj descriptorSet(m_device);
14031 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014032 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbes62e8e502015-05-25 11:13:29 +120014033
Tony Barbour5781e8f2015-08-04 16:23:11 -060014034 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbes62e8e502015-05-25 11:13:29 +120014035
Chris Forbes8f36a8a2016-04-07 13:21:07 +120014036 m_errorMonitor->VerifyFound();
Chris Forbes62e8e502015-05-25 11:13:29 +120014037}
14038
Karl Schultz6addd812016-02-02 17:17:23 -070014039TEST_F(VkLayerTest, CreatePipelineAttribTypeMismatch) {
Chris Forbes1cc79542016-07-20 11:13:44 +120014040 TEST_DESCRIPTION("Test that an error is produced for a mismatch between the "
14041 "fundamental type (float/int/uint) of an attribute and the "
14042 "VS input that consumes it");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014043 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "location 0 does not match VS input type");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060014044
Chris Forbesc97d98e2015-05-25 11:13:31 +120014045 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -060014046 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbesc97d98e2015-05-25 11:13:31 +120014047
14048 VkVertexInputBindingDescription input_binding;
14049 memset(&input_binding, 0, sizeof(input_binding));
14050
14051 VkVertexInputAttributeDescription input_attrib;
14052 memset(&input_attrib, 0, sizeof(input_attrib));
14053 input_attrib.format = VK_FORMAT_R32_SFLOAT;
14054
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014055 char const *vsSource = "#version 450\n"
14056 "\n"
14057 "layout(location=0) in int x;\n" /* attrib provided float */
14058 "out gl_PerVertex {\n"
14059 " vec4 gl_Position;\n"
14060 "};\n"
14061 "void main(){\n"
14062 " gl_Position = vec4(x);\n"
14063 "}\n";
14064 char const *fsSource = "#version 450\n"
14065 "\n"
14066 "layout(location=0) out vec4 color;\n"
14067 "void main(){\n"
14068 " color = vec4(1);\n"
14069 "}\n";
Chris Forbesc97d98e2015-05-25 11:13:31 +120014070
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060014071 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
14072 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbesc97d98e2015-05-25 11:13:31 +120014073
14074 VkPipelineObj pipe(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +080014075 pipe.AddColorAttachment();
Chris Forbesc97d98e2015-05-25 11:13:31 +120014076 pipe.AddShader(&vs);
14077 pipe.AddShader(&fs);
14078
14079 pipe.AddVertexInputBindings(&input_binding, 1);
14080 pipe.AddVertexInputAttribs(&input_attrib, 1);
14081
Chris Forbesc97d98e2015-05-25 11:13:31 +120014082 VkDescriptorSetObj descriptorSet(m_device);
14083 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014084 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbesc97d98e2015-05-25 11:13:31 +120014085
Tony Barbour5781e8f2015-08-04 16:23:11 -060014086 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbesc97d98e2015-05-25 11:13:31 +120014087
Chris Forbes8f36a8a2016-04-07 13:21:07 +120014088 m_errorMonitor->VerifyFound();
Chris Forbesc97d98e2015-05-25 11:13:31 +120014089}
14090
Chris Forbesc68b43c2016-04-06 11:18:47 +120014091TEST_F(VkLayerTest, CreatePipelineDuplicateStage) {
Chris Forbes1cc79542016-07-20 11:13:44 +120014092 TEST_DESCRIPTION("Test that an error is produced for a pipeline containing multiple "
14093 "shaders for the same stage");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014094 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
14095 "Multiple shaders provided for stage VK_SHADER_STAGE_VERTEX_BIT");
Chris Forbesc68b43c2016-04-06 11:18:47 +120014096
14097 ASSERT_NO_FATAL_FAILURE(InitState());
14098 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
14099
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014100 char const *vsSource = "#version 450\n"
14101 "\n"
14102 "out gl_PerVertex {\n"
14103 " vec4 gl_Position;\n"
14104 "};\n"
14105 "void main(){\n"
14106 " gl_Position = vec4(1);\n"
14107 "}\n";
14108 char const *fsSource = "#version 450\n"
14109 "\n"
14110 "layout(location=0) out vec4 color;\n"
14111 "void main(){\n"
14112 " color = vec4(1);\n"
14113 "}\n";
Chris Forbesc68b43c2016-04-06 11:18:47 +120014114
14115 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
14116 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
14117
14118 VkPipelineObj pipe(m_device);
14119 pipe.AddColorAttachment();
14120 pipe.AddShader(&vs);
14121 pipe.AddShader(&vs);
14122 pipe.AddShader(&fs);
14123
14124 VkDescriptorSetObj descriptorSet(m_device);
14125 descriptorSet.AppendDummy();
14126 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
14127
14128 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
14129
Chris Forbes8f36a8a2016-04-07 13:21:07 +120014130 m_errorMonitor->VerifyFound();
Chris Forbesc68b43c2016-04-06 11:18:47 +120014131}
14132
Karl Schultz6addd812016-02-02 17:17:23 -070014133TEST_F(VkLayerTest, CreatePipelineAttribMatrixType) {
Chris Forbes1cc79542016-07-20 11:13:44 +120014134 TEST_DESCRIPTION("Test that pipeline validation accepts matrices passed "
14135 "as vertex attributes");
Chris Forbes8f36a8a2016-04-07 13:21:07 +120014136 m_errorMonitor->ExpectSuccess();
Chris Forbes2682b242015-11-24 11:13:14 +130014137
14138 ASSERT_NO_FATAL_FAILURE(InitState());
14139 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
14140
14141 VkVertexInputBindingDescription input_binding;
14142 memset(&input_binding, 0, sizeof(input_binding));
14143
14144 VkVertexInputAttributeDescription input_attribs[2];
14145 memset(input_attribs, 0, sizeof(input_attribs));
14146
14147 for (int i = 0; i < 2; i++) {
14148 input_attribs[i].format = VK_FORMAT_R32G32B32A32_SFLOAT;
14149 input_attribs[i].location = i;
14150 }
14151
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014152 char const *vsSource = "#version 450\n"
14153 "\n"
14154 "layout(location=0) in mat2x4 x;\n"
14155 "out gl_PerVertex {\n"
14156 " vec4 gl_Position;\n"
14157 "};\n"
14158 "void main(){\n"
14159 " gl_Position = x[0] + x[1];\n"
14160 "}\n";
14161 char const *fsSource = "#version 450\n"
14162 "\n"
14163 "layout(location=0) out vec4 color;\n"
14164 "void main(){\n"
14165 " color = vec4(1);\n"
14166 "}\n";
Chris Forbes2682b242015-11-24 11:13:14 +130014167
14168 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
14169 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
14170
14171 VkPipelineObj pipe(m_device);
14172 pipe.AddColorAttachment();
14173 pipe.AddShader(&vs);
14174 pipe.AddShader(&fs);
14175
14176 pipe.AddVertexInputBindings(&input_binding, 1);
14177 pipe.AddVertexInputAttribs(input_attribs, 2);
14178
14179 VkDescriptorSetObj descriptorSet(m_device);
14180 descriptorSet.AppendDummy();
14181 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
14182
14183 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
14184
14185 /* expect success */
Chris Forbes8f36a8a2016-04-07 13:21:07 +120014186 m_errorMonitor->VerifyNotFound();
Chris Forbes2682b242015-11-24 11:13:14 +130014187}
14188
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014189TEST_F(VkLayerTest, CreatePipelineAttribArrayType) {
Chris Forbes8f36a8a2016-04-07 13:21:07 +120014190 m_errorMonitor->ExpectSuccess();
Chris Forbes2682b242015-11-24 11:13:14 +130014191
14192 ASSERT_NO_FATAL_FAILURE(InitState());
14193 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
14194
14195 VkVertexInputBindingDescription input_binding;
14196 memset(&input_binding, 0, sizeof(input_binding));
14197
14198 VkVertexInputAttributeDescription input_attribs[2];
14199 memset(input_attribs, 0, sizeof(input_attribs));
14200
14201 for (int i = 0; i < 2; i++) {
14202 input_attribs[i].format = VK_FORMAT_R32G32B32A32_SFLOAT;
14203 input_attribs[i].location = i;
14204 }
14205
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014206 char const *vsSource = "#version 450\n"
14207 "\n"
14208 "layout(location=0) in vec4 x[2];\n"
14209 "out gl_PerVertex {\n"
14210 " vec4 gl_Position;\n"
14211 "};\n"
14212 "void main(){\n"
14213 " gl_Position = x[0] + x[1];\n"
14214 "}\n";
14215 char const *fsSource = "#version 450\n"
14216 "\n"
14217 "layout(location=0) out vec4 color;\n"
14218 "void main(){\n"
14219 " color = vec4(1);\n"
14220 "}\n";
Chris Forbes2682b242015-11-24 11:13:14 +130014221
14222 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
14223 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
14224
14225 VkPipelineObj pipe(m_device);
14226 pipe.AddColorAttachment();
14227 pipe.AddShader(&vs);
14228 pipe.AddShader(&fs);
14229
14230 pipe.AddVertexInputBindings(&input_binding, 1);
14231 pipe.AddVertexInputAttribs(input_attribs, 2);
14232
14233 VkDescriptorSetObj descriptorSet(m_device);
14234 descriptorSet.AppendDummy();
14235 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
14236
14237 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
14238
Chris Forbes8f36a8a2016-04-07 13:21:07 +120014239 m_errorMonitor->VerifyNotFound();
Chris Forbes2682b242015-11-24 11:13:14 +130014240}
Chris Forbes2682b242015-11-24 11:13:14 +130014241
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014242TEST_F(VkLayerTest, CreatePipelineAttribComponents) {
Chris Forbes1cc79542016-07-20 11:13:44 +120014243 TEST_DESCRIPTION("Test that pipeline validation accepts consuming a vertex attribute "
14244 "through multiple VS inputs, each consuming a different subset of the "
14245 "components.");
Chris Forbesbc290ce2016-07-06 12:01:49 +120014246 m_errorMonitor->ExpectSuccess();
14247
14248 ASSERT_NO_FATAL_FAILURE(InitState());
14249 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
14250
14251 VkVertexInputBindingDescription input_binding;
14252 memset(&input_binding, 0, sizeof(input_binding));
14253
14254 VkVertexInputAttributeDescription input_attribs[3];
14255 memset(input_attribs, 0, sizeof(input_attribs));
14256
14257 for (int i = 0; i < 3; i++) {
14258 input_attribs[i].format = VK_FORMAT_R32G32B32A32_SFLOAT;
14259 input_attribs[i].location = i;
14260 }
14261
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014262 char const *vsSource = "#version 450\n"
14263 "\n"
14264 "layout(location=0) in vec4 x;\n"
14265 "layout(location=1) in vec3 y1;\n"
14266 "layout(location=1, component=3) in float y2;\n"
14267 "layout(location=2) in vec4 z;\n"
14268 "out gl_PerVertex {\n"
14269 " vec4 gl_Position;\n"
14270 "};\n"
14271 "void main(){\n"
14272 " gl_Position = x + vec4(y1, y2) + z;\n"
14273 "}\n";
14274 char const *fsSource = "#version 450\n"
14275 "\n"
14276 "layout(location=0) out vec4 color;\n"
14277 "void main(){\n"
14278 " color = vec4(1);\n"
14279 "}\n";
Chris Forbesbc290ce2016-07-06 12:01:49 +120014280
14281 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
14282 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
14283
14284 VkPipelineObj pipe(m_device);
14285 pipe.AddColorAttachment();
14286 pipe.AddShader(&vs);
14287 pipe.AddShader(&fs);
14288
14289 pipe.AddVertexInputBindings(&input_binding, 1);
14290 pipe.AddVertexInputAttribs(input_attribs, 3);
14291
14292 VkDescriptorSetObj descriptorSet(m_device);
14293 descriptorSet.AppendDummy();
14294 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
14295
14296 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
14297
14298 m_errorMonitor->VerifyNotFound();
14299}
14300
Chris Forbes82ff92a2016-09-09 10:50:24 +120014301TEST_F(VkLayerTest, CreatePipelineMissingEntrypoint) {
14302 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
14303 "No entrypoint found named `foo`");
14304
14305 ASSERT_NO_FATAL_FAILURE(InitState());
14306 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
14307
14308 char const *vsSource = "#version 450\n"
14309 "out gl_PerVertex {\n"
14310 " vec4 gl_Position;\n"
14311 "};\n"
14312 "void main(){\n"
14313 " gl_Position = vec4(0);\n"
14314 "}\n";
14315 char const *fsSource = "#version 450\n"
14316 "\n"
14317 "layout(location=0) out vec4 color;\n"
14318 "void main(){\n"
14319 " color = vec4(1);\n"
14320 "}\n";
14321
14322 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
14323 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this, "foo");
14324
14325 VkPipelineObj pipe(m_device);
14326 pipe.AddColorAttachment();
14327 pipe.AddShader(&vs);
14328 pipe.AddShader(&fs);
14329
14330 VkDescriptorSetObj descriptorSet(m_device);
14331 descriptorSet.AppendDummy();
14332 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
14333
14334 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
14335
14336 m_errorMonitor->VerifyFound();
14337}
14338
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014339TEST_F(VkLayerTest, CreatePipelineSimplePositive) {
Chris Forbes8f36a8a2016-04-07 13:21:07 +120014340 m_errorMonitor->ExpectSuccess();
Chris Forbes4ea14fc2016-04-04 18:52:54 +120014341
14342 ASSERT_NO_FATAL_FAILURE(InitState());
14343 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
14344
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014345 char const *vsSource = "#version 450\n"
14346 "out gl_PerVertex {\n"
14347 " vec4 gl_Position;\n"
14348 "};\n"
14349 "void main(){\n"
14350 " gl_Position = vec4(0);\n"
14351 "}\n";
14352 char const *fsSource = "#version 450\n"
14353 "\n"
14354 "layout(location=0) out vec4 color;\n"
14355 "void main(){\n"
14356 " color = vec4(1);\n"
14357 "}\n";
Chris Forbes4ea14fc2016-04-04 18:52:54 +120014358
14359 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
14360 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
14361
14362 VkPipelineObj pipe(m_device);
14363 pipe.AddColorAttachment();
14364 pipe.AddShader(&vs);
14365 pipe.AddShader(&fs);
14366
14367 VkDescriptorSetObj descriptorSet(m_device);
14368 descriptorSet.AppendDummy();
14369 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
14370
14371 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
14372
Chris Forbes8f36a8a2016-04-07 13:21:07 +120014373 m_errorMonitor->VerifyNotFound();
Chris Forbes4ea14fc2016-04-04 18:52:54 +120014374}
14375
Chris Forbesae9d8cd2016-09-13 16:32:57 +120014376TEST_F(VkLayerTest, CreatePipelineDepthStencilRequired) {
14377 m_errorMonitor->SetDesiredFailureMsg(
14378 VK_DEBUG_REPORT_ERROR_BIT_EXT,
14379 "pDepthStencilState is NULL when rasterization is enabled and subpass "
14380 "uses a depth/stencil attachment");
14381
14382 ASSERT_NO_FATAL_FAILURE(InitState());
14383 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
14384
14385 char const *vsSource = "#version 450\n"
14386 "void main(){ gl_Position = vec4(0); }\n";
14387 char const *fsSource = "#version 450\n"
14388 "\n"
14389 "layout(location=0) out vec4 color;\n"
14390 "void main(){\n"
14391 " color = vec4(1);\n"
14392 "}\n";
14393
14394 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
14395 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
14396
14397 VkPipelineObj pipe(m_device);
14398 pipe.AddColorAttachment();
14399 pipe.AddShader(&vs);
14400 pipe.AddShader(&fs);
14401
14402 VkDescriptorSetObj descriptorSet(m_device);
14403 descriptorSet.AppendDummy();
14404 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
14405
14406 VkAttachmentDescription attachments[] = {
14407 { 0, VK_FORMAT_B8G8R8A8_UNORM, VK_SAMPLE_COUNT_1_BIT,
14408 VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE,
14409 VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE,
14410 VK_IMAGE_LAYOUT_UNDEFINED, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
14411 },
14412 { 0, VK_FORMAT_D16_UNORM, VK_SAMPLE_COUNT_1_BIT,
14413 VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE,
14414 VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE,
14415 VK_IMAGE_LAYOUT_UNDEFINED, VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL,
14416 },
14417 };
14418 VkAttachmentReference refs[] = {
14419 { 0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL },
14420 { 1, VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL },
14421 };
14422 VkSubpassDescription subpass = {
14423 0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr,
14424 1, &refs[0], nullptr, &refs[1],
14425 0, nullptr
14426 };
14427 VkRenderPassCreateInfo rpci = {
14428 VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr,
14429 0, 2, attachments, 1, &subpass, 0, nullptr
14430 };
14431 VkRenderPass rp;
14432 VkResult err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
14433 ASSERT_VK_SUCCESS(err);
14434
14435 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), rp);
14436
14437 m_errorMonitor->VerifyFound();
14438
14439 vkDestroyRenderPass(m_device->device(), rp, nullptr);
14440}
14441
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014442TEST_F(VkLayerTest, CreatePipelineRelaxedTypeMatch) {
Chris Forbes1cc79542016-07-20 11:13:44 +120014443 TEST_DESCRIPTION("Test that pipeline validation accepts the relaxed type matching rules "
14444 "set out in 14.1.3: fundamental type must match, and producer side must "
14445 "have at least as many components");
Chris Forbes8f36a8a2016-04-07 13:21:07 +120014446 m_errorMonitor->ExpectSuccess();
Chris Forbes912c9192016-04-05 17:50:35 +120014447
14448 // VK 1.0.8 Specification, 14.1.3 "Additionally,..." block
14449
14450 ASSERT_NO_FATAL_FAILURE(InitState());
14451 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
14452
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014453 char const *vsSource = "#version 450\n"
14454 "out gl_PerVertex {\n"
14455 " vec4 gl_Position;\n"
14456 "};\n"
14457 "layout(location=0) out vec3 x;\n"
14458 "layout(location=1) out ivec3 y;\n"
14459 "layout(location=2) out vec3 z;\n"
14460 "void main(){\n"
14461 " gl_Position = vec4(0);\n"
14462 " x = vec3(0); y = ivec3(0); z = vec3(0);\n"
14463 "}\n";
14464 char const *fsSource = "#version 450\n"
14465 "\n"
14466 "layout(location=0) out vec4 color;\n"
14467 "layout(location=0) in float x;\n"
14468 "layout(location=1) flat in int y;\n"
14469 "layout(location=2) in vec2 z;\n"
14470 "void main(){\n"
14471 " color = vec4(1 + x + y + z.x);\n"
14472 "}\n";
Chris Forbes912c9192016-04-05 17:50:35 +120014473
14474 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
14475 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
14476
14477 VkPipelineObj pipe(m_device);
14478 pipe.AddColorAttachment();
14479 pipe.AddShader(&vs);
14480 pipe.AddShader(&fs);
14481
14482 VkDescriptorSetObj descriptorSet(m_device);
14483 descriptorSet.AppendDummy();
14484 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
14485
Mike Stroyan255e9582016-06-24 09:49:32 -060014486 VkResult err = VK_SUCCESS;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014487 err = pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Mike Stroyan255e9582016-06-24 09:49:32 -060014488 ASSERT_VK_SUCCESS(err);
14489
Chris Forbes8f36a8a2016-04-07 13:21:07 +120014490 m_errorMonitor->VerifyNotFound();
Chris Forbes912c9192016-04-05 17:50:35 +120014491}
14492
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014493TEST_F(VkLayerTest, CreatePipelineTessPerVertex) {
Chris Forbes1cc79542016-07-20 11:13:44 +120014494 TEST_DESCRIPTION("Test that pipeline validation accepts per-vertex variables "
14495 "passed between the TCS and TES stages");
Chris Forbes8f36a8a2016-04-07 13:21:07 +120014496 m_errorMonitor->ExpectSuccess();
Chris Forbes4ea14fc2016-04-04 18:52:54 +120014497
14498 ASSERT_NO_FATAL_FAILURE(InitState());
14499 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
14500
Chris Forbesc1e852d2016-04-04 19:26:42 +120014501 if (!m_device->phy().features().tessellationShader) {
14502 printf("Device does not support tessellation shaders; skipped.\n");
14503 return;
14504 }
14505
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014506 char const *vsSource = "#version 450\n"
14507 "void main(){}\n";
14508 char const *tcsSource = "#version 450\n"
14509 "layout(location=0) out int x[];\n"
14510 "layout(vertices=3) out;\n"
14511 "void main(){\n"
14512 " gl_TessLevelOuter[0] = gl_TessLevelOuter[1] = gl_TessLevelOuter[2] = 1;\n"
14513 " gl_TessLevelInner[0] = 1;\n"
14514 " x[gl_InvocationID] = gl_InvocationID;\n"
14515 "}\n";
14516 char const *tesSource = "#version 450\n"
14517 "layout(triangles, equal_spacing, cw) in;\n"
14518 "layout(location=0) in int x[];\n"
14519 "out gl_PerVertex { vec4 gl_Position; };\n"
14520 "void main(){\n"
14521 " gl_Position.xyz = gl_TessCoord;\n"
14522 " gl_Position.w = x[0] + x[1] + x[2];\n"
14523 "}\n";
14524 char const *fsSource = "#version 450\n"
14525 "layout(location=0) out vec4 color;\n"
14526 "void main(){\n"
14527 " color = vec4(1);\n"
14528 "}\n";
Chris Forbes4ea14fc2016-04-04 18:52:54 +120014529
14530 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
14531 VkShaderObj tcs(m_device, tcsSource, VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT, this);
14532 VkShaderObj tes(m_device, tesSource, VK_SHADER_STAGE_TESSELLATION_EVALUATION_BIT, this);
14533 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
14534
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014535 VkPipelineInputAssemblyStateCreateInfo iasci{VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO, nullptr, 0,
14536 VK_PRIMITIVE_TOPOLOGY_PATCH_LIST, VK_FALSE};
Chris Forbes4ea14fc2016-04-04 18:52:54 +120014537
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014538 VkPipelineTessellationStateCreateInfo tsci{VK_STRUCTURE_TYPE_PIPELINE_TESSELLATION_STATE_CREATE_INFO, nullptr, 0, 3};
Chris Forbesb4cacb62016-04-04 19:15:00 +120014539
Chris Forbes4ea14fc2016-04-04 18:52:54 +120014540 VkPipelineObj pipe(m_device);
14541 pipe.SetInputAssembly(&iasci);
Chris Forbesb4cacb62016-04-04 19:15:00 +120014542 pipe.SetTessellation(&tsci);
Chris Forbes4ea14fc2016-04-04 18:52:54 +120014543 pipe.AddColorAttachment();
14544 pipe.AddShader(&vs);
14545 pipe.AddShader(&tcs);
14546 pipe.AddShader(&tes);
14547 pipe.AddShader(&fs);
14548
14549 VkDescriptorSetObj descriptorSet(m_device);
14550 descriptorSet.AppendDummy();
14551 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
14552
14553 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
14554
Chris Forbes8f36a8a2016-04-07 13:21:07 +120014555 m_errorMonitor->VerifyNotFound();
Chris Forbes4ea14fc2016-04-04 18:52:54 +120014556}
14557
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014558TEST_F(VkLayerTest, CreatePipelineGeometryInputBlockPositive) {
Chris Forbes1cc79542016-07-20 11:13:44 +120014559 TEST_DESCRIPTION("Test that pipeline validation accepts a user-defined "
14560 "interface block passed into the geometry shader. This "
14561 "is interesting because the 'extra' array level is not "
14562 "present on the member type, but on the block instance.");
Chris Forbesa0ab8152016-04-20 13:34:27 +120014563 m_errorMonitor->ExpectSuccess();
14564
14565 ASSERT_NO_FATAL_FAILURE(InitState());
14566 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
14567
14568 if (!m_device->phy().features().geometryShader) {
14569 printf("Device does not support geometry shaders; skipped.\n");
14570 return;
14571 }
14572
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014573 char const *vsSource = "#version 450\n"
14574 "layout(location=0) out VertexData { vec4 x; } vs_out;\n"
14575 "void main(){\n"
14576 " vs_out.x = vec4(1);\n"
14577 "}\n";
14578 char const *gsSource = "#version 450\n"
14579 "layout(triangles) in;\n"
14580 "layout(triangle_strip, max_vertices=3) out;\n"
14581 "layout(location=0) in VertexData { vec4 x; } gs_in[];\n"
14582 "out gl_PerVertex { vec4 gl_Position; };\n"
14583 "void main() {\n"
14584 " gl_Position = gs_in[0].x;\n"
14585 " EmitVertex();\n"
14586 "}\n";
14587 char const *fsSource = "#version 450\n"
14588 "layout(location=0) out vec4 color;\n"
14589 "void main(){\n"
14590 " color = vec4(1);\n"
14591 "}\n";
Chris Forbesa0ab8152016-04-20 13:34:27 +120014592
14593 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
14594 VkShaderObj gs(m_device, gsSource, VK_SHADER_STAGE_GEOMETRY_BIT, this);
14595 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
14596
14597 VkPipelineObj pipe(m_device);
14598 pipe.AddColorAttachment();
14599 pipe.AddShader(&vs);
14600 pipe.AddShader(&gs);
14601 pipe.AddShader(&fs);
14602
14603 VkDescriptorSetObj descriptorSet(m_device);
14604 descriptorSet.AppendDummy();
14605 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
14606
14607 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
14608
14609 m_errorMonitor->VerifyNotFound();
14610}
14611
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014612TEST_F(VkLayerTest, CreatePipelineTessPatchDecorationMismatch) {
Chris Forbes1cc79542016-07-20 11:13:44 +120014613 TEST_DESCRIPTION("Test that an error is produced for a variable output from "
14614 "the TCS without the patch decoration, but consumed in the TES "
14615 "with the decoration.");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014616 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "is per-vertex in tessellation control shader stage "
14617 "but per-patch in tessellation evaluation shader stage");
Chris Forbesa0193bc2016-04-04 19:19:47 +120014618
14619 ASSERT_NO_FATAL_FAILURE(InitState());
14620 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
14621
Chris Forbesc1e852d2016-04-04 19:26:42 +120014622 if (!m_device->phy().features().tessellationShader) {
14623 printf("Device does not support tessellation shaders; skipped.\n");
14624 return;
14625 }
14626
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014627 char const *vsSource = "#version 450\n"
14628 "void main(){}\n";
14629 char const *tcsSource = "#version 450\n"
14630 "layout(location=0) out int x[];\n"
14631 "layout(vertices=3) out;\n"
14632 "void main(){\n"
14633 " gl_TessLevelOuter[0] = gl_TessLevelOuter[1] = gl_TessLevelOuter[2] = 1;\n"
14634 " gl_TessLevelInner[0] = 1;\n"
14635 " x[gl_InvocationID] = gl_InvocationID;\n"
14636 "}\n";
14637 char const *tesSource = "#version 450\n"
14638 "layout(triangles, equal_spacing, cw) in;\n"
14639 "layout(location=0) patch in int x;\n"
14640 "out gl_PerVertex { vec4 gl_Position; };\n"
14641 "void main(){\n"
14642 " gl_Position.xyz = gl_TessCoord;\n"
14643 " gl_Position.w = x;\n"
14644 "}\n";
14645 char const *fsSource = "#version 450\n"
14646 "layout(location=0) out vec4 color;\n"
14647 "void main(){\n"
14648 " color = vec4(1);\n"
14649 "}\n";
Chris Forbesa0193bc2016-04-04 19:19:47 +120014650
14651 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
14652 VkShaderObj tcs(m_device, tcsSource, VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT, this);
14653 VkShaderObj tes(m_device, tesSource, VK_SHADER_STAGE_TESSELLATION_EVALUATION_BIT, this);
14654 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
14655
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014656 VkPipelineInputAssemblyStateCreateInfo iasci{VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO, nullptr, 0,
14657 VK_PRIMITIVE_TOPOLOGY_PATCH_LIST, VK_FALSE};
Chris Forbesa0193bc2016-04-04 19:19:47 +120014658
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014659 VkPipelineTessellationStateCreateInfo tsci{VK_STRUCTURE_TYPE_PIPELINE_TESSELLATION_STATE_CREATE_INFO, nullptr, 0, 3};
Chris Forbesa0193bc2016-04-04 19:19:47 +120014660
14661 VkPipelineObj pipe(m_device);
14662 pipe.SetInputAssembly(&iasci);
14663 pipe.SetTessellation(&tsci);
14664 pipe.AddColorAttachment();
14665 pipe.AddShader(&vs);
14666 pipe.AddShader(&tcs);
14667 pipe.AddShader(&tes);
14668 pipe.AddShader(&fs);
14669
14670 VkDescriptorSetObj descriptorSet(m_device);
14671 descriptorSet.AppendDummy();
14672 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
14673
14674 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
14675
Chris Forbes8f36a8a2016-04-07 13:21:07 +120014676 m_errorMonitor->VerifyFound();
Chris Forbesa0193bc2016-04-04 19:19:47 +120014677}
14678
Karl Schultz6addd812016-02-02 17:17:23 -070014679TEST_F(VkLayerTest, CreatePipelineAttribBindingConflict) {
Chris Forbes1cc79542016-07-20 11:13:44 +120014680 TEST_DESCRIPTION("Test that an error is produced for a vertex attribute setup where multiple "
14681 "bindings provide the same location");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014682 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
14683 "Duplicate vertex input binding descriptions for binding 0");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060014684
Chris Forbes280ba2c2015-06-12 11:16:41 +120014685 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -060014686 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbes280ba2c2015-06-12 11:16:41 +120014687
14688 /* Two binding descriptions for binding 0 */
14689 VkVertexInputBindingDescription input_bindings[2];
14690 memset(input_bindings, 0, sizeof(input_bindings));
14691
14692 VkVertexInputAttributeDescription input_attrib;
14693 memset(&input_attrib, 0, sizeof(input_attrib));
14694 input_attrib.format = VK_FORMAT_R32_SFLOAT;
14695
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014696 char const *vsSource = "#version 450\n"
14697 "\n"
14698 "layout(location=0) in float x;\n" /* attrib provided float */
14699 "out gl_PerVertex {\n"
14700 " vec4 gl_Position;\n"
14701 "};\n"
14702 "void main(){\n"
14703 " gl_Position = vec4(x);\n"
14704 "}\n";
14705 char const *fsSource = "#version 450\n"
14706 "\n"
14707 "layout(location=0) out vec4 color;\n"
14708 "void main(){\n"
14709 " color = vec4(1);\n"
14710 "}\n";
Chris Forbes280ba2c2015-06-12 11:16:41 +120014711
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060014712 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
14713 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbes280ba2c2015-06-12 11:16:41 +120014714
14715 VkPipelineObj pipe(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +080014716 pipe.AddColorAttachment();
Chris Forbes280ba2c2015-06-12 11:16:41 +120014717 pipe.AddShader(&vs);
14718 pipe.AddShader(&fs);
14719
14720 pipe.AddVertexInputBindings(input_bindings, 2);
14721 pipe.AddVertexInputAttribs(&input_attrib, 1);
14722
Chris Forbes280ba2c2015-06-12 11:16:41 +120014723 VkDescriptorSetObj descriptorSet(m_device);
14724 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014725 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbes280ba2c2015-06-12 11:16:41 +120014726
Tony Barbour5781e8f2015-08-04 16:23:11 -060014727 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbes280ba2c2015-06-12 11:16:41 +120014728
Chris Forbes8f36a8a2016-04-07 13:21:07 +120014729 m_errorMonitor->VerifyFound();
Chris Forbes280ba2c2015-06-12 11:16:41 +120014730}
Chris Forbes8f68b562015-05-25 11:13:32 +120014731
Chris Forbes35efec72016-04-21 14:32:08 +120014732TEST_F(VkLayerTest, CreatePipeline64BitAttributesPositive) {
Chris Forbes1cc79542016-07-20 11:13:44 +120014733 TEST_DESCRIPTION("Test that pipeline validation accepts basic use of 64bit vertex "
14734 "attributes. This is interesting because they consume multiple "
14735 "locations.");
Chris Forbes35efec72016-04-21 14:32:08 +120014736 m_errorMonitor->ExpectSuccess();
14737
14738 ASSERT_NO_FATAL_FAILURE(InitState());
14739 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
14740
Chris Forbes91cf3a82016-06-28 17:51:35 +120014741 if (!m_device->phy().features().shaderFloat64) {
Chris Forbes35efec72016-04-21 14:32:08 +120014742 printf("Device does not support 64bit vertex attributes; skipped.\n");
14743 return;
14744 }
14745
14746 VkVertexInputBindingDescription input_bindings[1];
14747 memset(input_bindings, 0, sizeof(input_bindings));
14748
14749 VkVertexInputAttributeDescription input_attribs[4];
14750 memset(input_attribs, 0, sizeof(input_attribs));
14751 input_attribs[0].location = 0;
14752 input_attribs[0].offset = 0;
14753 input_attribs[0].format = VK_FORMAT_R64G64B64A64_SFLOAT;
14754 input_attribs[1].location = 2;
14755 input_attribs[1].offset = 32;
14756 input_attribs[1].format = VK_FORMAT_R64G64B64A64_SFLOAT;
14757 input_attribs[2].location = 4;
14758 input_attribs[2].offset = 64;
14759 input_attribs[2].format = VK_FORMAT_R64G64B64A64_SFLOAT;
14760 input_attribs[3].location = 6;
14761 input_attribs[3].offset = 96;
14762 input_attribs[3].format = VK_FORMAT_R64G64B64A64_SFLOAT;
14763
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014764 char const *vsSource = "#version 450\n"
14765 "\n"
14766 "layout(location=0) in dmat4 x;\n"
14767 "out gl_PerVertex {\n"
14768 " vec4 gl_Position;\n"
14769 "};\n"
14770 "void main(){\n"
14771 " gl_Position = vec4(x[0][0]);\n"
14772 "}\n";
14773 char const *fsSource = "#version 450\n"
14774 "\n"
14775 "layout(location=0) out vec4 color;\n"
14776 "void main(){\n"
14777 " color = vec4(1);\n"
14778 "}\n";
Chris Forbes35efec72016-04-21 14:32:08 +120014779
14780 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
14781 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
14782
14783 VkPipelineObj pipe(m_device);
14784 pipe.AddColorAttachment();
14785 pipe.AddShader(&vs);
14786 pipe.AddShader(&fs);
14787
14788 pipe.AddVertexInputBindings(input_bindings, 1);
14789 pipe.AddVertexInputAttribs(input_attribs, 4);
14790
14791 VkDescriptorSetObj descriptorSet(m_device);
14792 descriptorSet.AppendDummy();
14793 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
14794
14795 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
14796
14797 m_errorMonitor->VerifyNotFound();
14798}
14799
Karl Schultz6addd812016-02-02 17:17:23 -070014800TEST_F(VkLayerTest, CreatePipelineFragmentOutputNotWritten) {
Chris Forbes1cc79542016-07-20 11:13:44 +120014801 TEST_DESCRIPTION("Test that an error is produced for a FS which does not "
14802 "provide an output for one of the pipeline's color attachments");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014803 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Attachment 0 not written by FS");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060014804
Chris Forbes4d6d1e52015-05-25 11:13:40 +120014805 ASSERT_NO_FATAL_FAILURE(InitState());
Chris Forbes4d6d1e52015-05-25 11:13:40 +120014806
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014807 char const *vsSource = "#version 450\n"
14808 "\n"
14809 "out gl_PerVertex {\n"
14810 " vec4 gl_Position;\n"
14811 "};\n"
14812 "void main(){\n"
14813 " gl_Position = vec4(1);\n"
14814 "}\n";
14815 char const *fsSource = "#version 450\n"
14816 "\n"
14817 "void main(){\n"
14818 "}\n";
Chris Forbes4d6d1e52015-05-25 11:13:40 +120014819
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060014820 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
14821 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbes4d6d1e52015-05-25 11:13:40 +120014822
14823 VkPipelineObj pipe(m_device);
14824 pipe.AddShader(&vs);
14825 pipe.AddShader(&fs);
14826
Chia-I Wu08accc62015-07-07 11:50:03 +080014827 /* set up CB 0, not written */
14828 pipe.AddColorAttachment();
14829 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbes4d6d1e52015-05-25 11:13:40 +120014830
Chris Forbes4d6d1e52015-05-25 11:13:40 +120014831 VkDescriptorSetObj descriptorSet(m_device);
14832 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014833 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbes4d6d1e52015-05-25 11:13:40 +120014834
Tony Barbour5781e8f2015-08-04 16:23:11 -060014835 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbes4d6d1e52015-05-25 11:13:40 +120014836
Chris Forbes8f36a8a2016-04-07 13:21:07 +120014837 m_errorMonitor->VerifyFound();
Chris Forbes4d6d1e52015-05-25 11:13:40 +120014838}
14839
Karl Schultz6addd812016-02-02 17:17:23 -070014840TEST_F(VkLayerTest, CreatePipelineFragmentOutputNotConsumed) {
Chris Forbes1cc79542016-07-20 11:13:44 +120014841 TEST_DESCRIPTION("Test that a warning is produced for a FS which provides a spurious "
14842 "output with no matching attachment");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014843 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT,
14844 "FS writes to output location 1 with no matching attachment");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060014845
Chris Forbesf3fffaa2015-05-25 11:13:43 +120014846 ASSERT_NO_FATAL_FAILURE(InitState());
Chris Forbesf3fffaa2015-05-25 11:13:43 +120014847
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014848 char const *vsSource = "#version 450\n"
14849 "\n"
14850 "out gl_PerVertex {\n"
14851 " vec4 gl_Position;\n"
14852 "};\n"
14853 "void main(){\n"
14854 " gl_Position = vec4(1);\n"
14855 "}\n";
14856 char const *fsSource = "#version 450\n"
14857 "\n"
14858 "layout(location=0) out vec4 x;\n"
14859 "layout(location=1) out vec4 y;\n" /* no matching attachment for this */
14860 "void main(){\n"
14861 " x = vec4(1);\n"
14862 " y = vec4(1);\n"
14863 "}\n";
Chris Forbesf3fffaa2015-05-25 11:13:43 +120014864
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060014865 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
14866 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbesf3fffaa2015-05-25 11:13:43 +120014867
14868 VkPipelineObj pipe(m_device);
14869 pipe.AddShader(&vs);
14870 pipe.AddShader(&fs);
14871
Chia-I Wu08accc62015-07-07 11:50:03 +080014872 /* set up CB 0, not written */
14873 pipe.AddColorAttachment();
14874 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbesf3fffaa2015-05-25 11:13:43 +120014875 /* FS writes CB 1, but we don't configure it */
14876
Chris Forbesf3fffaa2015-05-25 11:13:43 +120014877 VkDescriptorSetObj descriptorSet(m_device);
14878 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014879 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbesf3fffaa2015-05-25 11:13:43 +120014880
Tony Barbour5781e8f2015-08-04 16:23:11 -060014881 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbesf3fffaa2015-05-25 11:13:43 +120014882
Chris Forbes8f36a8a2016-04-07 13:21:07 +120014883 m_errorMonitor->VerifyFound();
Chris Forbesf3fffaa2015-05-25 11:13:43 +120014884}
14885
Karl Schultz6addd812016-02-02 17:17:23 -070014886TEST_F(VkLayerTest, CreatePipelineFragmentOutputTypeMismatch) {
Chris Forbes1cc79542016-07-20 11:13:44 +120014887 TEST_DESCRIPTION("Test that an error is produced for a mismatch between the fundamental "
14888 "type of an FS output variable, and the format of the corresponding attachment");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014889 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "does not match FS output type");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060014890
Chris Forbesa36d69e2015-05-25 11:13:44 +120014891 ASSERT_NO_FATAL_FAILURE(InitState());
Chris Forbesa36d69e2015-05-25 11:13:44 +120014892
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014893 char const *vsSource = "#version 450\n"
14894 "\n"
14895 "out gl_PerVertex {\n"
14896 " vec4 gl_Position;\n"
14897 "};\n"
14898 "void main(){\n"
14899 " gl_Position = vec4(1);\n"
14900 "}\n";
14901 char const *fsSource = "#version 450\n"
14902 "\n"
14903 "layout(location=0) out ivec4 x;\n" /* not UNORM */
14904 "void main(){\n"
14905 " x = ivec4(1);\n"
14906 "}\n";
Chris Forbesa36d69e2015-05-25 11:13:44 +120014907
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060014908 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
14909 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbesa36d69e2015-05-25 11:13:44 +120014910
14911 VkPipelineObj pipe(m_device);
14912 pipe.AddShader(&vs);
14913 pipe.AddShader(&fs);
14914
Chia-I Wu08accc62015-07-07 11:50:03 +080014915 /* set up CB 0; type is UNORM by default */
14916 pipe.AddColorAttachment();
14917 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbesa36d69e2015-05-25 11:13:44 +120014918
Chris Forbesa36d69e2015-05-25 11:13:44 +120014919 VkDescriptorSetObj descriptorSet(m_device);
14920 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014921 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbesa36d69e2015-05-25 11:13:44 +120014922
Tony Barbour5781e8f2015-08-04 16:23:11 -060014923 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbesa36d69e2015-05-25 11:13:44 +120014924
Chris Forbes8f36a8a2016-04-07 13:21:07 +120014925 m_errorMonitor->VerifyFound();
Chris Forbesa36d69e2015-05-25 11:13:44 +120014926}
Chris Forbes7b1b8932015-06-05 14:43:36 +120014927
Karl Schultz6addd812016-02-02 17:17:23 -070014928TEST_F(VkLayerTest, CreatePipelineUniformBlockNotProvided) {
Chris Forbes1cc79542016-07-20 11:13:44 +120014929 TEST_DESCRIPTION("Test that an error is produced for a shader consuming a uniform "
14930 "block which has no corresponding binding in the pipeline layout");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014931 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "not declared in pipeline layout");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060014932
Chris Forbes556c76c2015-08-14 12:04:59 +120014933 ASSERT_NO_FATAL_FAILURE(InitState());
Chris Forbes556c76c2015-08-14 12:04:59 +120014934
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014935 char const *vsSource = "#version 450\n"
14936 "\n"
14937 "out gl_PerVertex {\n"
14938 " vec4 gl_Position;\n"
14939 "};\n"
14940 "void main(){\n"
14941 " gl_Position = vec4(1);\n"
14942 "}\n";
14943 char const *fsSource = "#version 450\n"
14944 "\n"
14945 "layout(location=0) out vec4 x;\n"
14946 "layout(set=0) layout(binding=0) uniform foo { int x; int y; } bar;\n"
14947 "void main(){\n"
14948 " x = vec4(bar.y);\n"
14949 "}\n";
Chris Forbes556c76c2015-08-14 12:04:59 +120014950
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060014951 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
14952 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbes556c76c2015-08-14 12:04:59 +120014953
Chris Forbes556c76c2015-08-14 12:04:59 +120014954 VkPipelineObj pipe(m_device);
14955 pipe.AddShader(&vs);
14956 pipe.AddShader(&fs);
14957
14958 /* set up CB 0; type is UNORM by default */
14959 pipe.AddColorAttachment();
14960 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
14961
14962 VkDescriptorSetObj descriptorSet(m_device);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014963 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbes556c76c2015-08-14 12:04:59 +120014964
14965 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
14966
Chris Forbes8f36a8a2016-04-07 13:21:07 +120014967 m_errorMonitor->VerifyFound();
Chris Forbes556c76c2015-08-14 12:04:59 +120014968}
14969
Chris Forbes5c59e902016-02-26 16:56:09 +130014970TEST_F(VkLayerTest, CreatePipelinePushConstantsNotInLayout) {
Chris Forbes1cc79542016-07-20 11:13:44 +120014971 TEST_DESCRIPTION("Test that an error is produced for a shader consuming push constants "
14972 "which are not provided in the pipeline layout");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014973 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "not declared in layout");
Chris Forbes5c59e902016-02-26 16:56:09 +130014974
14975 ASSERT_NO_FATAL_FAILURE(InitState());
14976
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014977 char const *vsSource = "#version 450\n"
14978 "\n"
14979 "layout(push_constant, std430) uniform foo { float x; } consts;\n"
14980 "out gl_PerVertex {\n"
14981 " vec4 gl_Position;\n"
14982 "};\n"
14983 "void main(){\n"
14984 " gl_Position = vec4(consts.x);\n"
14985 "}\n";
14986 char const *fsSource = "#version 450\n"
14987 "\n"
14988 "layout(location=0) out vec4 x;\n"
14989 "void main(){\n"
14990 " x = vec4(1);\n"
14991 "}\n";
Chris Forbes5c59e902016-02-26 16:56:09 +130014992
14993 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
14994 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
14995
14996 VkPipelineObj pipe(m_device);
14997 pipe.AddShader(&vs);
14998 pipe.AddShader(&fs);
14999
15000 /* set up CB 0; type is UNORM by default */
15001 pipe.AddColorAttachment();
15002 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
15003
15004 VkDescriptorSetObj descriptorSet(m_device);
15005 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
15006
15007 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
15008
15009 /* should have generated an error -- no push constant ranges provided! */
Chris Forbes8f36a8a2016-04-07 13:21:07 +120015010 m_errorMonitor->VerifyFound();
Chris Forbes5c59e902016-02-26 16:56:09 +130015011}
15012
Chris Forbes3fb17902016-08-22 14:57:55 +120015013TEST_F(VkLayerTest, CreatePipelineInputAttachmentMissing) {
15014 TEST_DESCRIPTION("Test that an error is produced for a shader consuming an input attachment "
15015 "which is not included in the subpass description");
15016 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
15017 "consumes input attachment index 0 but not provided in subpass");
15018
15019 ASSERT_NO_FATAL_FAILURE(InitState());
15020
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015021 char const *vsSource = "#version 450\n"
15022 "\n"
15023 "out gl_PerVertex {\n"
15024 " vec4 gl_Position;\n"
15025 "};\n"
15026 "void main(){\n"
15027 " gl_Position = vec4(1);\n"
15028 "}\n";
15029 char const *fsSource = "#version 450\n"
15030 "\n"
15031 "layout(input_attachment_index=0, set=0, binding=0) uniform subpassInput x;\n"
15032 "layout(location=0) out vec4 color;\n"
15033 "void main() {\n"
15034 " color = subpassLoad(x);\n"
15035 "}\n";
Chris Forbes3fb17902016-08-22 14:57:55 +120015036
15037 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
15038 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
15039
15040 VkPipelineObj pipe(m_device);
15041 pipe.AddShader(&vs);
15042 pipe.AddShader(&fs);
15043 pipe.AddColorAttachment();
15044 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
15045
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015046 VkDescriptorSetLayoutBinding dslb = {0, VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT, 1, VK_SHADER_STAGE_FRAGMENT_BIT, nullptr};
15047 VkDescriptorSetLayoutCreateInfo dslci = {VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dslb};
Chris Forbes3fb17902016-08-22 14:57:55 +120015048 VkDescriptorSetLayout dsl;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015049 VkResult err = vkCreateDescriptorSetLayout(m_device->device(), &dslci, nullptr, &dsl);
Chris Forbes3fb17902016-08-22 14:57:55 +120015050 ASSERT_VK_SUCCESS(err);
15051
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015052 VkPipelineLayoutCreateInfo plci = {VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dsl, 0, nullptr};
Chris Forbes3fb17902016-08-22 14:57:55 +120015053 VkPipelineLayout pl;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015054 err = vkCreatePipelineLayout(m_device->device(), &plci, nullptr, &pl);
Chris Forbes3fb17902016-08-22 14:57:55 +120015055 ASSERT_VK_SUCCESS(err);
15056
15057 // error here.
15058 pipe.CreateVKPipeline(pl, renderPass());
15059
15060 m_errorMonitor->VerifyFound();
15061
15062 vkDestroyPipelineLayout(m_device->device(), pl, nullptr);
15063 vkDestroyDescriptorSetLayout(m_device->device(), dsl, nullptr);
15064}
15065
Chris Forbes663b5a82016-08-22 16:14:06 +120015066TEST_F(VkLayerTest, CreatePipelineInputAttachmentPositive) {
15067 TEST_DESCRIPTION("Positive test for a correctly matched input attachment");
15068 m_errorMonitor->ExpectSuccess();
15069
15070 ASSERT_NO_FATAL_FAILURE(InitState());
15071
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015072 char const *vsSource = "#version 450\n"
15073 "\n"
15074 "out gl_PerVertex {\n"
15075 " vec4 gl_Position;\n"
15076 "};\n"
15077 "void main(){\n"
15078 " gl_Position = vec4(1);\n"
15079 "}\n";
15080 char const *fsSource = "#version 450\n"
15081 "\n"
15082 "layout(input_attachment_index=0, set=0, binding=0) uniform subpassInput x;\n"
15083 "layout(location=0) out vec4 color;\n"
15084 "void main() {\n"
15085 " color = subpassLoad(x);\n"
15086 "}\n";
Chris Forbes663b5a82016-08-22 16:14:06 +120015087
15088 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
15089 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
15090
15091 VkPipelineObj pipe(m_device);
15092 pipe.AddShader(&vs);
15093 pipe.AddShader(&fs);
15094 pipe.AddColorAttachment();
15095 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
15096
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015097 VkDescriptorSetLayoutBinding dslb = {0, VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT, 1, VK_SHADER_STAGE_FRAGMENT_BIT, nullptr};
15098 VkDescriptorSetLayoutCreateInfo dslci = {VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dslb};
Chris Forbes663b5a82016-08-22 16:14:06 +120015099 VkDescriptorSetLayout dsl;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015100 VkResult err = vkCreateDescriptorSetLayout(m_device->device(), &dslci, nullptr, &dsl);
Chris Forbes663b5a82016-08-22 16:14:06 +120015101 ASSERT_VK_SUCCESS(err);
15102
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015103 VkPipelineLayoutCreateInfo plci = {VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dsl, 0, nullptr};
Chris Forbes663b5a82016-08-22 16:14:06 +120015104 VkPipelineLayout pl;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015105 err = vkCreatePipelineLayout(m_device->device(), &plci, nullptr, &pl);
Chris Forbes663b5a82016-08-22 16:14:06 +120015106 ASSERT_VK_SUCCESS(err);
15107
15108 VkAttachmentDescription descs[2] = {
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015109 {0, VK_FORMAT_R8G8B8A8_UNORM, VK_SAMPLE_COUNT_1_BIT, VK_ATTACHMENT_LOAD_OP_LOAD, VK_ATTACHMENT_STORE_OP_STORE,
15110 VK_ATTACHMENT_LOAD_OP_LOAD, VK_ATTACHMENT_STORE_OP_STORE, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
15111 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL},
15112 {0, VK_FORMAT_R8G8B8A8_UNORM, VK_SAMPLE_COUNT_1_BIT, VK_ATTACHMENT_LOAD_OP_LOAD, VK_ATTACHMENT_STORE_OP_STORE,
15113 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 +120015114 };
15115 VkAttachmentReference color = {
15116 0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
15117 };
15118 VkAttachmentReference input = {
15119 1, VK_IMAGE_LAYOUT_GENERAL,
15120 };
15121
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015122 VkSubpassDescription sd = {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 1, &input, 1, &color, nullptr, nullptr, 0, nullptr};
Chris Forbes663b5a82016-08-22 16:14:06 +120015123
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015124 VkRenderPassCreateInfo rpci = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 2, descs, 1, &sd, 0, nullptr};
Chris Forbes663b5a82016-08-22 16:14:06 +120015125 VkRenderPass rp;
15126 err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
15127 ASSERT_VK_SUCCESS(err);
15128
15129 // should be OK. would go wrong here if it's going to...
15130 pipe.CreateVKPipeline(pl, rp);
15131
15132 m_errorMonitor->VerifyNotFound();
15133
15134 vkDestroyRenderPass(m_device->device(), rp, nullptr);
15135 vkDestroyPipelineLayout(m_device->device(), pl, nullptr);
15136 vkDestroyDescriptorSetLayout(m_device->device(), dsl, nullptr);
15137}
15138
Chris Forbes5a9a0472016-08-22 16:02:09 +120015139TEST_F(VkLayerTest, CreatePipelineInputAttachmentTypeMismatch) {
15140 TEST_DESCRIPTION("Test that an error is produced for a shader consuming an input attachment "
15141 "with a format having a different fundamental type");
15142 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
15143 "input attachment 0 format of VK_FORMAT_R8G8B8A8_UINT does not match");
15144
15145 ASSERT_NO_FATAL_FAILURE(InitState());
15146
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015147 char const *vsSource = "#version 450\n"
15148 "\n"
15149 "out gl_PerVertex {\n"
15150 " vec4 gl_Position;\n"
15151 "};\n"
15152 "void main(){\n"
15153 " gl_Position = vec4(1);\n"
15154 "}\n";
15155 char const *fsSource = "#version 450\n"
15156 "\n"
15157 "layout(input_attachment_index=0, set=0, binding=0) uniform subpassInput x;\n"
15158 "layout(location=0) out vec4 color;\n"
15159 "void main() {\n"
15160 " color = subpassLoad(x);\n"
15161 "}\n";
Chris Forbes5a9a0472016-08-22 16:02:09 +120015162
15163 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
15164 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
15165
15166 VkPipelineObj pipe(m_device);
15167 pipe.AddShader(&vs);
15168 pipe.AddShader(&fs);
15169 pipe.AddColorAttachment();
15170 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
15171
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015172 VkDescriptorSetLayoutBinding dslb = {0, VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT, 1, VK_SHADER_STAGE_FRAGMENT_BIT, nullptr};
15173 VkDescriptorSetLayoutCreateInfo dslci = {VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dslb};
Chris Forbes5a9a0472016-08-22 16:02:09 +120015174 VkDescriptorSetLayout dsl;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015175 VkResult err = vkCreateDescriptorSetLayout(m_device->device(), &dslci, nullptr, &dsl);
Chris Forbes5a9a0472016-08-22 16:02:09 +120015176 ASSERT_VK_SUCCESS(err);
15177
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015178 VkPipelineLayoutCreateInfo plci = {VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dsl, 0, nullptr};
Chris Forbes5a9a0472016-08-22 16:02:09 +120015179 VkPipelineLayout pl;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015180 err = vkCreatePipelineLayout(m_device->device(), &plci, nullptr, &pl);
Chris Forbes5a9a0472016-08-22 16:02:09 +120015181 ASSERT_VK_SUCCESS(err);
15182
15183 VkAttachmentDescription descs[2] = {
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015184 {0, VK_FORMAT_R8G8B8A8_UNORM, VK_SAMPLE_COUNT_1_BIT, VK_ATTACHMENT_LOAD_OP_LOAD, VK_ATTACHMENT_STORE_OP_STORE,
15185 VK_ATTACHMENT_LOAD_OP_LOAD, VK_ATTACHMENT_STORE_OP_STORE, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
15186 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL},
15187 {0, VK_FORMAT_R8G8B8A8_UINT, VK_SAMPLE_COUNT_1_BIT, VK_ATTACHMENT_LOAD_OP_LOAD, VK_ATTACHMENT_STORE_OP_STORE,
15188 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 +120015189 };
15190 VkAttachmentReference color = {
15191 0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
15192 };
15193 VkAttachmentReference input = {
15194 1, VK_IMAGE_LAYOUT_GENERAL,
15195 };
15196
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015197 VkSubpassDescription sd = {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 1, &input, 1, &color, nullptr, nullptr, 0, nullptr};
Chris Forbes5a9a0472016-08-22 16:02:09 +120015198
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015199 VkRenderPassCreateInfo rpci = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 2, descs, 1, &sd, 0, nullptr};
Chris Forbes5a9a0472016-08-22 16:02:09 +120015200 VkRenderPass rp;
15201 err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
15202 ASSERT_VK_SUCCESS(err);
15203
15204 // error here.
15205 pipe.CreateVKPipeline(pl, rp);
15206
15207 m_errorMonitor->VerifyFound();
15208
15209 vkDestroyRenderPass(m_device->device(), rp, nullptr);
15210 vkDestroyPipelineLayout(m_device->device(), pl, nullptr);
15211 vkDestroyDescriptorSetLayout(m_device->device(), dsl, nullptr);
15212}
15213
Chris Forbes541f7b02016-08-22 15:30:27 +120015214TEST_F(VkLayerTest, CreatePipelineInputAttachmentMissingArray) {
15215 TEST_DESCRIPTION("Test that an error is produced for a shader consuming an input attachment "
15216 "which is not included in the subpass description -- array case");
15217 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
15218 "consumes input attachment index 1 but not provided in subpass");
15219
15220 ASSERT_NO_FATAL_FAILURE(InitState());
15221
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015222 char const *vsSource = "#version 450\n"
15223 "\n"
15224 "out gl_PerVertex {\n"
15225 " vec4 gl_Position;\n"
15226 "};\n"
15227 "void main(){\n"
15228 " gl_Position = vec4(1);\n"
15229 "}\n";
15230 char const *fsSource = "#version 450\n"
15231 "\n"
15232 "layout(input_attachment_index=0, set=0, binding=0) uniform subpassInput xs[2];\n"
15233 "layout(location=0) out vec4 color;\n"
15234 "void main() {\n"
15235 " color = subpassLoad(xs[1]);\n"
15236 "}\n";
Chris Forbes541f7b02016-08-22 15:30:27 +120015237
15238 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
15239 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
15240
15241 VkPipelineObj pipe(m_device);
15242 pipe.AddShader(&vs);
15243 pipe.AddShader(&fs);
15244 pipe.AddColorAttachment();
15245 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
15246
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015247 VkDescriptorSetLayoutBinding dslb = {0, VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT, 2, VK_SHADER_STAGE_FRAGMENT_BIT, nullptr};
15248 VkDescriptorSetLayoutCreateInfo dslci = {VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dslb};
Chris Forbes541f7b02016-08-22 15:30:27 +120015249 VkDescriptorSetLayout dsl;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015250 VkResult err = vkCreateDescriptorSetLayout(m_device->device(), &dslci, nullptr, &dsl);
Chris Forbes541f7b02016-08-22 15:30:27 +120015251 ASSERT_VK_SUCCESS(err);
15252
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015253 VkPipelineLayoutCreateInfo plci = {VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dsl, 0, nullptr};
Chris Forbes541f7b02016-08-22 15:30:27 +120015254 VkPipelineLayout pl;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015255 err = vkCreatePipelineLayout(m_device->device(), &plci, nullptr, &pl);
Chris Forbes541f7b02016-08-22 15:30:27 +120015256 ASSERT_VK_SUCCESS(err);
15257
15258 // error here.
15259 pipe.CreateVKPipeline(pl, renderPass());
15260
15261 m_errorMonitor->VerifyFound();
15262
15263 vkDestroyPipelineLayout(m_device->device(), pl, nullptr);
15264 vkDestroyDescriptorSetLayout(m_device->device(), dsl, nullptr);
15265}
15266
Chris Forbes10eb9ae2016-05-31 16:09:42 +120015267TEST_F(VkLayerTest, CreateComputePipelineMissingDescriptor) {
Chris Forbes1cc79542016-07-20 11:13:44 +120015268 TEST_DESCRIPTION("Test that an error is produced for a compute pipeline consuming a "
15269 "descriptor which is not provided in the pipeline layout");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015270 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Shader uses descriptor slot 0.0");
Chris Forbes10eb9ae2016-05-31 16:09:42 +120015271
15272 ASSERT_NO_FATAL_FAILURE(InitState());
15273
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015274 char const *csSource = "#version 450\n"
15275 "\n"
15276 "layout(local_size_x=1) in;\n"
15277 "layout(set=0, binding=0) buffer block { vec4 x; };\n"
15278 "void main(){\n"
15279 " x = vec4(1);\n"
15280 "}\n";
Chris Forbes10eb9ae2016-05-31 16:09:42 +120015281
15282 VkShaderObj cs(m_device, csSource, VK_SHADER_STAGE_COMPUTE_BIT, this);
15283
15284 VkDescriptorSetObj descriptorSet(m_device);
15285 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
15286
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015287 VkComputePipelineCreateInfo cpci = {VK_STRUCTURE_TYPE_COMPUTE_PIPELINE_CREATE_INFO,
15288 nullptr,
15289 0,
15290 {VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO, nullptr, 0,
15291 VK_SHADER_STAGE_COMPUTE_BIT, cs.handle(), "main", nullptr},
15292 descriptorSet.GetPipelineLayout(),
15293 VK_NULL_HANDLE,
15294 -1};
Chris Forbes10eb9ae2016-05-31 16:09:42 +120015295
15296 VkPipeline pipe;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015297 VkResult err = vkCreateComputePipelines(m_device->device(), VK_NULL_HANDLE, 1, &cpci, nullptr, &pipe);
Chris Forbes10eb9ae2016-05-31 16:09:42 +120015298
15299 m_errorMonitor->VerifyFound();
15300
15301 if (err == VK_SUCCESS) {
15302 vkDestroyPipeline(m_device->device(), pipe, nullptr);
15303 }
15304}
15305
15306TEST_F(VkLayerTest, CreateComputePipelineMissingDescriptorUnusedPositive) {
Chris Forbes1cc79542016-07-20 11:13:44 +120015307 TEST_DESCRIPTION("Test that pipeline validation accepts a compute pipeline which declares a "
15308 "descriptor-backed resource which is not provided, but the shader does not "
15309 "statically use it. This is interesting because it requires compute pipelines "
15310 "to have a proper descriptor use walk, which they didn't for some time.");
Chris Forbes10eb9ae2016-05-31 16:09:42 +120015311 m_errorMonitor->ExpectSuccess();
15312
15313 ASSERT_NO_FATAL_FAILURE(InitState());
15314
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015315 char const *csSource = "#version 450\n"
15316 "\n"
15317 "layout(local_size_x=1) in;\n"
15318 "layout(set=0, binding=0) buffer block { vec4 x; };\n"
15319 "void main(){\n"
15320 " // x is not used.\n"
15321 "}\n";
Chris Forbes10eb9ae2016-05-31 16:09:42 +120015322
15323 VkShaderObj cs(m_device, csSource, VK_SHADER_STAGE_COMPUTE_BIT, this);
15324
15325 VkDescriptorSetObj descriptorSet(m_device);
15326 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
15327
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015328 VkComputePipelineCreateInfo cpci = {VK_STRUCTURE_TYPE_COMPUTE_PIPELINE_CREATE_INFO,
15329 nullptr,
15330 0,
15331 {VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO, nullptr, 0,
15332 VK_SHADER_STAGE_COMPUTE_BIT, cs.handle(), "main", nullptr},
15333 descriptorSet.GetPipelineLayout(),
15334 VK_NULL_HANDLE,
15335 -1};
Chris Forbes10eb9ae2016-05-31 16:09:42 +120015336
15337 VkPipeline pipe;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015338 VkResult err = vkCreateComputePipelines(m_device->device(), VK_NULL_HANDLE, 1, &cpci, nullptr, &pipe);
Chris Forbes10eb9ae2016-05-31 16:09:42 +120015339
15340 m_errorMonitor->VerifyNotFound();
15341
15342 if (err == VK_SUCCESS) {
15343 vkDestroyPipeline(m_device->device(), pipe, nullptr);
15344 }
15345}
15346
Chris Forbes22a9b092016-07-19 14:34:05 +120015347TEST_F(VkLayerTest, CreateComputePipelineDescriptorTypeMismatch) {
Chris Forbes1cc79542016-07-20 11:13:44 +120015348 TEST_DESCRIPTION("Test that an error is produced for a pipeline consuming a "
15349 "descriptor-backed resource of a mismatched type");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015350 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
15351 "but descriptor of type VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER");
Chris Forbes22a9b092016-07-19 14:34:05 +120015352
15353 ASSERT_NO_FATAL_FAILURE(InitState());
15354
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015355 VkDescriptorSetLayoutBinding binding = {0, VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, 1, VK_SHADER_STAGE_COMPUTE_BIT, nullptr};
15356 VkDescriptorSetLayoutCreateInfo dslci = {VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO, nullptr, 0, 1, &binding};
Chris Forbes22a9b092016-07-19 14:34:05 +120015357 VkDescriptorSetLayout dsl;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015358 VkResult err = vkCreateDescriptorSetLayout(m_device->device(), &dslci, nullptr, &dsl);
Chris Forbes22a9b092016-07-19 14:34:05 +120015359 ASSERT_VK_SUCCESS(err);
15360
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015361 VkPipelineLayoutCreateInfo plci = {VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dsl, 0, nullptr};
Chris Forbes22a9b092016-07-19 14:34:05 +120015362 VkPipelineLayout pl;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015363 err = vkCreatePipelineLayout(m_device->device(), &plci, nullptr, &pl);
Chris Forbes22a9b092016-07-19 14:34:05 +120015364 ASSERT_VK_SUCCESS(err);
15365
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015366 char const *csSource = "#version 450\n"
15367 "\n"
15368 "layout(local_size_x=1) in;\n"
15369 "layout(set=0, binding=0) buffer block { vec4 x; };\n"
15370 "void main() {\n"
15371 " x.x = 1.0f;\n"
15372 "}\n";
Chris Forbes22a9b092016-07-19 14:34:05 +120015373 VkShaderObj cs(m_device, csSource, VK_SHADER_STAGE_COMPUTE_BIT, this);
15374
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015375 VkComputePipelineCreateInfo cpci = {VK_STRUCTURE_TYPE_COMPUTE_PIPELINE_CREATE_INFO,
15376 nullptr,
15377 0,
15378 {VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO, nullptr, 0,
15379 VK_SHADER_STAGE_COMPUTE_BIT, cs.handle(), "main", nullptr},
15380 pl,
15381 VK_NULL_HANDLE,
15382 -1};
Chris Forbes22a9b092016-07-19 14:34:05 +120015383
15384 VkPipeline pipe;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015385 err = vkCreateComputePipelines(m_device->device(), VK_NULL_HANDLE, 1, &cpci, nullptr, &pipe);
Chris Forbes22a9b092016-07-19 14:34:05 +120015386
15387 m_errorMonitor->VerifyFound();
15388
15389 if (err == VK_SUCCESS) {
15390 vkDestroyPipeline(m_device->device(), pipe, nullptr);
15391 }
15392
15393 vkDestroyPipelineLayout(m_device->device(), pl, nullptr);
15394 vkDestroyDescriptorSetLayout(m_device->device(), dsl, nullptr);
15395}
15396
Chris Forbese10a51f2016-07-19 14:42:51 +120015397TEST_F(VkLayerTest, CreateComputePipelineCombinedImageSamplerConsumedAsSampler) {
Chris Forbes1cc79542016-07-20 11:13:44 +120015398 TEST_DESCRIPTION("Test that pipeline validation accepts a shader consuming only the "
15399 "sampler portion of a combined image + sampler");
Chris Forbese10a51f2016-07-19 14:42:51 +120015400 m_errorMonitor->ExpectSuccess();
15401
15402 ASSERT_NO_FATAL_FAILURE(InitState());
15403
15404 VkDescriptorSetLayoutBinding bindings[] = {
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015405 {0, VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, 1, VK_SHADER_STAGE_COMPUTE_BIT, nullptr},
15406 {1, VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE, 1, VK_SHADER_STAGE_COMPUTE_BIT, nullptr},
15407 {2, VK_DESCRIPTOR_TYPE_STORAGE_BUFFER, 1, VK_SHADER_STAGE_COMPUTE_BIT, nullptr},
Chris Forbese10a51f2016-07-19 14:42:51 +120015408 };
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015409 VkDescriptorSetLayoutCreateInfo dslci = {VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO, nullptr, 0, 3, bindings};
Chris Forbese10a51f2016-07-19 14:42:51 +120015410 VkDescriptorSetLayout dsl;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015411 VkResult err = vkCreateDescriptorSetLayout(m_device->device(), &dslci, nullptr, &dsl);
Chris Forbese10a51f2016-07-19 14:42:51 +120015412 ASSERT_VK_SUCCESS(err);
15413
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015414 VkPipelineLayoutCreateInfo plci = {VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dsl, 0, nullptr};
Chris Forbese10a51f2016-07-19 14:42:51 +120015415 VkPipelineLayout pl;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015416 err = vkCreatePipelineLayout(m_device->device(), &plci, nullptr, &pl);
Chris Forbese10a51f2016-07-19 14:42:51 +120015417 ASSERT_VK_SUCCESS(err);
15418
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015419 char const *csSource = "#version 450\n"
15420 "\n"
15421 "layout(local_size_x=1) in;\n"
15422 "layout(set=0, binding=0) uniform sampler s;\n"
15423 "layout(set=0, binding=1) uniform texture2D t;\n"
15424 "layout(set=0, binding=2) buffer block { vec4 x; };\n"
15425 "void main() {\n"
15426 " x = texture(sampler2D(t, s), vec2(0));\n"
15427 "}\n";
Chris Forbese10a51f2016-07-19 14:42:51 +120015428 VkShaderObj cs(m_device, csSource, VK_SHADER_STAGE_COMPUTE_BIT, this);
15429
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015430 VkComputePipelineCreateInfo cpci = {VK_STRUCTURE_TYPE_COMPUTE_PIPELINE_CREATE_INFO,
15431 nullptr,
15432 0,
15433 {VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO, nullptr, 0,
15434 VK_SHADER_STAGE_COMPUTE_BIT, cs.handle(), "main", nullptr},
15435 pl,
15436 VK_NULL_HANDLE,
15437 -1};
Chris Forbese10a51f2016-07-19 14:42:51 +120015438
15439 VkPipeline pipe;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015440 err = vkCreateComputePipelines(m_device->device(), VK_NULL_HANDLE, 1, &cpci, nullptr, &pipe);
Chris Forbese10a51f2016-07-19 14:42:51 +120015441
15442 m_errorMonitor->VerifyNotFound();
15443
15444 if (err == VK_SUCCESS) {
15445 vkDestroyPipeline(m_device->device(), pipe, nullptr);
15446 }
15447
15448 vkDestroyPipelineLayout(m_device->device(), pl, nullptr);
15449 vkDestroyDescriptorSetLayout(m_device->device(), dsl, nullptr);
15450}
15451
Chris Forbes91c3b2a2016-07-19 14:46:38 +120015452TEST_F(VkLayerTest, CreateComputePipelineCombinedImageSamplerConsumedAsImage) {
Chris Forbes1cc79542016-07-20 11:13:44 +120015453 TEST_DESCRIPTION("Test that pipeline validation accepts a shader consuming only the "
15454 "image portion of a combined image + sampler");
Chris Forbes91c3b2a2016-07-19 14:46:38 +120015455 m_errorMonitor->ExpectSuccess();
15456
15457 ASSERT_NO_FATAL_FAILURE(InitState());
15458
15459 VkDescriptorSetLayoutBinding bindings[] = {
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015460 {0, VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, 1, VK_SHADER_STAGE_COMPUTE_BIT, nullptr},
15461 {1, VK_DESCRIPTOR_TYPE_SAMPLER, 1, VK_SHADER_STAGE_COMPUTE_BIT, nullptr},
15462 {2, VK_DESCRIPTOR_TYPE_STORAGE_BUFFER, 1, VK_SHADER_STAGE_COMPUTE_BIT, nullptr},
Chris Forbes91c3b2a2016-07-19 14:46:38 +120015463 };
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015464 VkDescriptorSetLayoutCreateInfo dslci = {VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO, nullptr, 0, 3, bindings};
Chris Forbes91c3b2a2016-07-19 14:46:38 +120015465 VkDescriptorSetLayout dsl;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015466 VkResult err = vkCreateDescriptorSetLayout(m_device->device(), &dslci, nullptr, &dsl);
Chris Forbes91c3b2a2016-07-19 14:46:38 +120015467 ASSERT_VK_SUCCESS(err);
15468
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015469 VkPipelineLayoutCreateInfo plci = {VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dsl, 0, nullptr};
Chris Forbes91c3b2a2016-07-19 14:46:38 +120015470 VkPipelineLayout pl;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015471 err = vkCreatePipelineLayout(m_device->device(), &plci, nullptr, &pl);
Chris Forbes91c3b2a2016-07-19 14:46:38 +120015472 ASSERT_VK_SUCCESS(err);
15473
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015474 char const *csSource = "#version 450\n"
15475 "\n"
15476 "layout(local_size_x=1) in;\n"
15477 "layout(set=0, binding=0) uniform texture2D t;\n"
15478 "layout(set=0, binding=1) uniform sampler s;\n"
15479 "layout(set=0, binding=2) buffer block { vec4 x; };\n"
15480 "void main() {\n"
15481 " x = texture(sampler2D(t, s), vec2(0));\n"
15482 "}\n";
Chris Forbes91c3b2a2016-07-19 14:46:38 +120015483 VkShaderObj cs(m_device, csSource, VK_SHADER_STAGE_COMPUTE_BIT, this);
15484
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015485 VkComputePipelineCreateInfo cpci = {VK_STRUCTURE_TYPE_COMPUTE_PIPELINE_CREATE_INFO,
15486 nullptr,
15487 0,
15488 {VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO, nullptr, 0,
15489 VK_SHADER_STAGE_COMPUTE_BIT, cs.handle(), "main", nullptr},
15490 pl,
15491 VK_NULL_HANDLE,
15492 -1};
Chris Forbes91c3b2a2016-07-19 14:46:38 +120015493
15494 VkPipeline pipe;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015495 err = vkCreateComputePipelines(m_device->device(), VK_NULL_HANDLE, 1, &cpci, nullptr, &pipe);
Chris Forbes91c3b2a2016-07-19 14:46:38 +120015496
15497 m_errorMonitor->VerifyNotFound();
15498
15499 if (err == VK_SUCCESS) {
15500 vkDestroyPipeline(m_device->device(), pipe, nullptr);
15501 }
15502
15503 vkDestroyPipelineLayout(m_device->device(), pl, nullptr);
15504 vkDestroyDescriptorSetLayout(m_device->device(), dsl, nullptr);
15505}
15506
Chris Forbes6a4991a2016-07-19 15:07:32 +120015507TEST_F(VkLayerTest, CreateComputePipelineCombinedImageSamplerConsumedAsBoth) {
Chris Forbes1cc79542016-07-20 11:13:44 +120015508 TEST_DESCRIPTION("Test that pipeline validation accepts a shader consuming "
15509 "both the sampler and the image of a combined image+sampler "
15510 "but via separate variables");
Chris Forbes6a4991a2016-07-19 15:07:32 +120015511 m_errorMonitor->ExpectSuccess();
15512
15513 ASSERT_NO_FATAL_FAILURE(InitState());
15514
15515 VkDescriptorSetLayoutBinding bindings[] = {
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015516 {0, VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, 1, VK_SHADER_STAGE_COMPUTE_BIT, nullptr},
15517 {1, VK_DESCRIPTOR_TYPE_STORAGE_BUFFER, 1, VK_SHADER_STAGE_COMPUTE_BIT, nullptr},
Chris Forbes6a4991a2016-07-19 15:07:32 +120015518 };
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015519 VkDescriptorSetLayoutCreateInfo dslci = {VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO, nullptr, 0, 2, bindings};
Chris Forbes6a4991a2016-07-19 15:07:32 +120015520 VkDescriptorSetLayout dsl;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015521 VkResult err = vkCreateDescriptorSetLayout(m_device->device(), &dslci, nullptr, &dsl);
Chris Forbes6a4991a2016-07-19 15:07:32 +120015522 ASSERT_VK_SUCCESS(err);
15523
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015524 VkPipelineLayoutCreateInfo plci = {VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dsl, 0, nullptr};
Chris Forbes6a4991a2016-07-19 15:07:32 +120015525 VkPipelineLayout pl;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015526 err = vkCreatePipelineLayout(m_device->device(), &plci, nullptr, &pl);
Chris Forbes6a4991a2016-07-19 15:07:32 +120015527 ASSERT_VK_SUCCESS(err);
15528
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015529 char const *csSource = "#version 450\n"
15530 "\n"
15531 "layout(local_size_x=1) in;\n"
15532 "layout(set=0, binding=0) uniform texture2D t;\n"
15533 "layout(set=0, binding=0) uniform sampler s; // both binding 0!\n"
15534 "layout(set=0, binding=1) buffer block { vec4 x; };\n"
15535 "void main() {\n"
15536 " x = texture(sampler2D(t, s), vec2(0));\n"
15537 "}\n";
Chris Forbes6a4991a2016-07-19 15:07:32 +120015538 VkShaderObj cs(m_device, csSource, VK_SHADER_STAGE_COMPUTE_BIT, this);
15539
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015540 VkComputePipelineCreateInfo cpci = {VK_STRUCTURE_TYPE_COMPUTE_PIPELINE_CREATE_INFO,
15541 nullptr,
15542 0,
15543 {VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO, nullptr, 0,
15544 VK_SHADER_STAGE_COMPUTE_BIT, cs.handle(), "main", nullptr},
15545 pl,
15546 VK_NULL_HANDLE,
15547 -1};
Chris Forbes6a4991a2016-07-19 15:07:32 +120015548
15549 VkPipeline pipe;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015550 err = vkCreateComputePipelines(m_device->device(), VK_NULL_HANDLE, 1, &cpci, nullptr, &pipe);
Chris Forbes6a4991a2016-07-19 15:07:32 +120015551
15552 m_errorMonitor->VerifyNotFound();
15553
15554 if (err == VK_SUCCESS) {
15555 vkDestroyPipeline(m_device->device(), pipe, nullptr);
15556 }
15557
15558 vkDestroyPipelineLayout(m_device->device(), pl, nullptr);
15559 vkDestroyDescriptorSetLayout(m_device->device(), dsl, nullptr);
15560}
15561
Chris Forbes50020592016-07-27 13:52:41 +120015562TEST_F(VkLayerTest, DrawTimeImageViewTypeMismatchWithPipeline) {
15563 TEST_DESCRIPTION("Test that an error is produced when an image view type "
15564 "does not match the dimensionality declared in the shader");
15565
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015566 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 +120015567
15568 ASSERT_NO_FATAL_FAILURE(InitState());
15569 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
15570
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015571 char const *vsSource = "#version 450\n"
15572 "\n"
15573 "out gl_PerVertex { vec4 gl_Position; };\n"
15574 "void main() { gl_Position = vec4(0); }\n";
15575 char const *fsSource = "#version 450\n"
15576 "\n"
15577 "layout(set=0, binding=0) uniform sampler3D s;\n"
15578 "layout(location=0) out vec4 color;\n"
15579 "void main() {\n"
15580 " color = texture(s, vec3(0));\n"
15581 "}\n";
Chris Forbes50020592016-07-27 13:52:41 +120015582 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
15583 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
15584
15585 VkPipelineObj pipe(m_device);
15586 pipe.AddShader(&vs);
15587 pipe.AddShader(&fs);
15588 pipe.AddColorAttachment();
15589
15590 VkTextureObj texture(m_device, nullptr);
15591 VkSamplerObj sampler(m_device);
15592
15593 VkDescriptorSetObj descriptorSet(m_device);
15594 descriptorSet.AppendSamplerTexture(&sampler, &texture);
15595 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
15596
15597 VkResult err = pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
15598 ASSERT_VK_SUCCESS(err);
15599
15600 BeginCommandBuffer();
15601
15602 m_commandBuffer->BindPipeline(pipe);
15603 m_commandBuffer->BindDescriptorSet(descriptorSet);
15604
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015605 VkViewport viewport = {0, 0, 16, 16, 0, 1};
Chris Forbes50020592016-07-27 13:52:41 +120015606 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015607 VkRect2D scissor = {{0, 0}, {16, 16}};
Chris Forbes50020592016-07-27 13:52:41 +120015608 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
15609
15610 // error produced here.
15611 vkCmdDraw(m_commandBuffer->handle(), 3, 1, 0, 0);
15612
15613 m_errorMonitor->VerifyFound();
15614
15615 EndCommandBuffer();
15616}
15617
Chris Forbes5533bfc2016-07-27 14:12:34 +120015618TEST_F(VkLayerTest, DrawTimeImageMultisampleMismatchWithPipeline) {
15619 TEST_DESCRIPTION("Test that an error is produced when a multisampled images "
15620 "are consumed via singlesample images types in the shader, or vice versa.");
15621
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015622 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "requires bound image to have multiple samples");
Chris Forbes5533bfc2016-07-27 14:12:34 +120015623
15624 ASSERT_NO_FATAL_FAILURE(InitState());
15625 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
15626
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015627 char const *vsSource = "#version 450\n"
15628 "\n"
15629 "out gl_PerVertex { vec4 gl_Position; };\n"
15630 "void main() { gl_Position = vec4(0); }\n";
15631 char const *fsSource = "#version 450\n"
15632 "\n"
15633 "layout(set=0, binding=0) uniform sampler2DMS s;\n"
15634 "layout(location=0) out vec4 color;\n"
15635 "void main() {\n"
15636 " color = texelFetch(s, ivec2(0), 0);\n"
15637 "}\n";
Chris Forbes5533bfc2016-07-27 14:12:34 +120015638 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
15639 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
15640
15641 VkPipelineObj pipe(m_device);
15642 pipe.AddShader(&vs);
15643 pipe.AddShader(&fs);
15644 pipe.AddColorAttachment();
15645
15646 VkTextureObj texture(m_device, nullptr);
15647 VkSamplerObj sampler(m_device);
15648
15649 VkDescriptorSetObj descriptorSet(m_device);
15650 descriptorSet.AppendSamplerTexture(&sampler, &texture);
15651 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
15652
15653 VkResult err = pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
15654 ASSERT_VK_SUCCESS(err);
15655
15656 BeginCommandBuffer();
15657
15658 m_commandBuffer->BindPipeline(pipe);
15659 m_commandBuffer->BindDescriptorSet(descriptorSet);
15660
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015661 VkViewport viewport = {0, 0, 16, 16, 0, 1};
Chris Forbes5533bfc2016-07-27 14:12:34 +120015662 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015663 VkRect2D scissor = {{0, 0}, {16, 16}};
Chris Forbes5533bfc2016-07-27 14:12:34 +120015664 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
15665
15666 // error produced here.
15667 vkCmdDraw(m_commandBuffer->handle(), 3, 1, 0, 0);
15668
15669 m_errorMonitor->VerifyFound();
15670
15671 EndCommandBuffer();
15672}
15673
Mark Lobodzinski209b5292015-09-17 09:44:05 -060015674#endif // SHADER_CHECKER_TESTS
15675
15676#if DEVICE_LIMITS_TESTS
Mark Youngc48c4c12016-04-11 14:26:49 -060015677TEST_F(VkLayerTest, CreateImageLimitsViolationMaxWidth) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015678 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "CreateImage extents exceed allowable limits for format");
Mark Lobodzinski6f2274e2015-09-22 09:33:21 -060015679
15680 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinski6f2274e2015-09-22 09:33:21 -060015681
15682 // Create an image
15683 VkImage image;
15684
Karl Schultz6addd812016-02-02 17:17:23 -070015685 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
15686 const int32_t tex_width = 32;
15687 const int32_t tex_height = 32;
Mark Lobodzinski6f2274e2015-09-22 09:33:21 -060015688
15689 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070015690 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
15691 image_create_info.pNext = NULL;
15692 image_create_info.imageType = VK_IMAGE_TYPE_2D;
15693 image_create_info.format = tex_format;
15694 image_create_info.extent.width = tex_width;
Mark Lobodzinski6f2274e2015-09-22 09:33:21 -060015695 image_create_info.extent.height = tex_height;
Karl Schultz6addd812016-02-02 17:17:23 -070015696 image_create_info.extent.depth = 1;
15697 image_create_info.mipLevels = 1;
15698 image_create_info.arrayLayers = 1;
15699 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
15700 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
15701 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
15702 image_create_info.flags = 0;
Mark Lobodzinski6f2274e2015-09-22 09:33:21 -060015703
15704 // Introduce error by sending down a bogus width extent
15705 image_create_info.extent.width = 65536;
Chia-I Wuf7458c52015-10-26 21:10:41 +080015706 vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
Mark Lobodzinski6f2274e2015-09-22 09:33:21 -060015707
Chris Forbes8f36a8a2016-04-07 13:21:07 +120015708 m_errorMonitor->VerifyFound();
Mark Lobodzinski6f2274e2015-09-22 09:33:21 -060015709}
15710
Mark Youngc48c4c12016-04-11 14:26:49 -060015711TEST_F(VkLayerTest, CreateImageLimitsViolationMinWidth) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015712 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
15713 "CreateImage extents is 0 for at least one required dimension");
Mark Youngc48c4c12016-04-11 14:26:49 -060015714
15715 ASSERT_NO_FATAL_FAILURE(InitState());
15716
15717 // Create an image
15718 VkImage image;
15719
15720 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
15721 const int32_t tex_width = 32;
15722 const int32_t tex_height = 32;
15723
15724 VkImageCreateInfo image_create_info = {};
15725 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
15726 image_create_info.pNext = NULL;
15727 image_create_info.imageType = VK_IMAGE_TYPE_2D;
15728 image_create_info.format = tex_format;
15729 image_create_info.extent.width = tex_width;
15730 image_create_info.extent.height = tex_height;
15731 image_create_info.extent.depth = 1;
15732 image_create_info.mipLevels = 1;
15733 image_create_info.arrayLayers = 1;
15734 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
15735 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
15736 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
15737 image_create_info.flags = 0;
15738
15739 // Introduce error by sending down a bogus width extent
15740 image_create_info.extent.width = 0;
15741 vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
15742
15743 m_errorMonitor->VerifyFound();
15744}
Mark Lobodzinski209b5292015-09-17 09:44:05 -060015745#endif // DEVICE_LIMITS_TESTS
Chris Forbesa36d69e2015-05-25 11:13:44 +120015746
Tobin Ehliscde08892015-09-22 10:11:37 -060015747#if IMAGE_TESTS
Mark Lobodzinskidf4c57d2016-08-05 11:47:16 -060015748TEST_F(VkLayerTest, AttachmentDescriptionUndefinedFormat) {
15749 TEST_DESCRIPTION("Create a render pass with an attachment description "
15750 "format set to VK_FORMAT_UNDEFINED");
15751
15752 ASSERT_NO_FATAL_FAILURE(InitState());
15753 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
15754
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015755 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "format is VK_FORMAT_UNDEFINED");
Mark Lobodzinskidf4c57d2016-08-05 11:47:16 -060015756
15757 VkAttachmentReference color_attach = {};
15758 color_attach.layout = VK_IMAGE_LAYOUT_GENERAL;
15759 color_attach.attachment = 0;
15760 VkSubpassDescription subpass = {};
15761 subpass.colorAttachmentCount = 1;
15762 subpass.pColorAttachments = &color_attach;
15763
15764 VkRenderPassCreateInfo rpci = {};
15765 rpci.subpassCount = 1;
15766 rpci.pSubpasses = &subpass;
15767 rpci.attachmentCount = 1;
15768 VkAttachmentDescription attach_desc = {};
15769 attach_desc.format = VK_FORMAT_UNDEFINED;
15770 rpci.pAttachments = &attach_desc;
15771 rpci.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
15772 VkRenderPass rp;
15773 VkResult result = vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
15774
15775 m_errorMonitor->VerifyFound();
15776
15777 if (result == VK_SUCCESS) {
15778 vkDestroyRenderPass(m_device->device(), rp, NULL);
15779 }
15780}
15781
Karl Schultz6addd812016-02-02 17:17:23 -070015782TEST_F(VkLayerTest, InvalidImageView) {
15783 VkResult err;
Tobin Ehliscde08892015-09-22 10:11:37 -060015784
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015785 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "vkCreateImageView called with baseMipLevel 10 ");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060015786
Tobin Ehliscde08892015-09-22 10:11:37 -060015787 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehliscde08892015-09-22 10:11:37 -060015788
Mike Stroyana3082432015-09-25 13:39:21 -060015789 // Create an image and try to create a view with bad baseMipLevel
Karl Schultz6addd812016-02-02 17:17:23 -070015790 VkImage image;
Tobin Ehliscde08892015-09-22 10:11:37 -060015791
Karl Schultz6addd812016-02-02 17:17:23 -070015792 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
15793 const int32_t tex_width = 32;
15794 const int32_t tex_height = 32;
Tobin Ehliscde08892015-09-22 10:11:37 -060015795
15796 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070015797 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
15798 image_create_info.pNext = NULL;
15799 image_create_info.imageType = VK_IMAGE_TYPE_2D;
15800 image_create_info.format = tex_format;
15801 image_create_info.extent.width = tex_width;
15802 image_create_info.extent.height = tex_height;
15803 image_create_info.extent.depth = 1;
15804 image_create_info.mipLevels = 1;
15805 image_create_info.arrayLayers = 1;
15806 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
15807 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
15808 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
15809 image_create_info.flags = 0;
Tobin Ehliscde08892015-09-22 10:11:37 -060015810
Chia-I Wuf7458c52015-10-26 21:10:41 +080015811 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
Tobin Ehliscde08892015-09-22 10:11:37 -060015812 ASSERT_VK_SUCCESS(err);
15813
15814 VkImageViewCreateInfo image_view_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070015815 image_view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
15816 image_view_create_info.image = image;
15817 image_view_create_info.viewType = VK_IMAGE_VIEW_TYPE_2D;
15818 image_view_create_info.format = tex_format;
15819 image_view_create_info.subresourceRange.layerCount = 1;
15820 image_view_create_info.subresourceRange.baseMipLevel = 10; // cause an error
15821 image_view_create_info.subresourceRange.levelCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015822 image_view_create_info.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Tobin Ehliscde08892015-09-22 10:11:37 -060015823
15824 VkImageView view;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015825 err = vkCreateImageView(m_device->device(), &image_view_create_info, NULL, &view);
Tobin Ehliscde08892015-09-22 10:11:37 -060015826
Chris Forbes8f36a8a2016-04-07 13:21:07 +120015827 m_errorMonitor->VerifyFound();
Tony Barbourdf4c0042016-06-01 15:55:43 -060015828 vkDestroyImage(m_device->device(), image, NULL);
Tobin Ehliscde08892015-09-22 10:11:37 -060015829}
Mike Stroyana3082432015-09-25 13:39:21 -060015830
Mark Youngd339ba32016-05-30 13:28:35 -060015831TEST_F(VkLayerTest, CreateImageViewNoMemoryBoundToImage) {
15832 VkResult err;
Tobin Ehlisfed999f2016-09-21 15:09:45 -060015833 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
15834 " used with no memory bound. Memory should be bound by calling vkBindImageMemory() and ");
Mark Youngd339ba32016-05-30 13:28:35 -060015835
15836 ASSERT_NO_FATAL_FAILURE(InitState());
15837
15838 // Create an image and try to create a view with no memory backing the image
15839 VkImage image;
15840
15841 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
15842 const int32_t tex_width = 32;
15843 const int32_t tex_height = 32;
15844
15845 VkImageCreateInfo image_create_info = {};
15846 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
15847 image_create_info.pNext = NULL;
15848 image_create_info.imageType = VK_IMAGE_TYPE_2D;
15849 image_create_info.format = tex_format;
15850 image_create_info.extent.width = tex_width;
15851 image_create_info.extent.height = tex_height;
15852 image_create_info.extent.depth = 1;
15853 image_create_info.mipLevels = 1;
15854 image_create_info.arrayLayers = 1;
15855 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
15856 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
15857 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
15858 image_create_info.flags = 0;
15859
15860 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
15861 ASSERT_VK_SUCCESS(err);
15862
15863 VkImageViewCreateInfo image_view_create_info = {};
15864 image_view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
15865 image_view_create_info.image = image;
15866 image_view_create_info.viewType = VK_IMAGE_VIEW_TYPE_2D;
15867 image_view_create_info.format = tex_format;
15868 image_view_create_info.subresourceRange.layerCount = 1;
15869 image_view_create_info.subresourceRange.baseMipLevel = 0;
15870 image_view_create_info.subresourceRange.levelCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015871 image_view_create_info.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mark Youngd339ba32016-05-30 13:28:35 -060015872
15873 VkImageView view;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015874 err = vkCreateImageView(m_device->device(), &image_view_create_info, NULL, &view);
Mark Youngd339ba32016-05-30 13:28:35 -060015875
15876 m_errorMonitor->VerifyFound();
15877 vkDestroyImage(m_device->device(), image, NULL);
15878 // If last error is success, it still created the view, so delete it.
15879 if (err == VK_SUCCESS) {
15880 vkDestroyImageView(m_device->device(), view, NULL);
15881 }
Mark Youngd339ba32016-05-30 13:28:35 -060015882}
15883
Karl Schultz6addd812016-02-02 17:17:23 -070015884TEST_F(VkLayerTest, InvalidImageViewAspect) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015885 TEST_DESCRIPTION("Create an image and try to create a view with an invalid aspectMask");
15886 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "vkCreateImageView: Color image "
15887 "formats must have ONLY the "
15888 "VK_IMAGE_ASPECT_COLOR_BIT set");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060015889
Mark Lobodzinskidc86b852015-10-23 14:20:31 -060015890 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinskidc86b852015-10-23 14:20:31 -060015891
Karl Schultz6addd812016-02-02 17:17:23 -070015892 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
Tobin Ehlis1f567a22016-05-25 16:15:18 -060015893 VkImageObj image(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015894 image.init(32, 32, tex_format, VK_IMAGE_USAGE_SAMPLED_BIT, VK_IMAGE_TILING_LINEAR, 0);
Tobin Ehlis1f567a22016-05-25 16:15:18 -060015895 ASSERT_TRUE(image.initialized());
Mark Lobodzinskidc86b852015-10-23 14:20:31 -060015896
15897 VkImageViewCreateInfo image_view_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070015898 image_view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
Tobin Ehlis1f567a22016-05-25 16:15:18 -060015899 image_view_create_info.image = image.handle();
Karl Schultz6addd812016-02-02 17:17:23 -070015900 image_view_create_info.viewType = VK_IMAGE_VIEW_TYPE_2D;
15901 image_view_create_info.format = tex_format;
15902 image_view_create_info.subresourceRange.baseMipLevel = 0;
15903 image_view_create_info.subresourceRange.levelCount = 1;
15904 // Cause an error by setting an invalid image aspect
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015905 image_view_create_info.subresourceRange.aspectMask = VK_IMAGE_ASPECT_METADATA_BIT;
Mark Lobodzinskidc86b852015-10-23 14:20:31 -060015906
15907 VkImageView view;
Tobin Ehlis1f567a22016-05-25 16:15:18 -060015908 vkCreateImageView(m_device->device(), &image_view_create_info, NULL, &view);
Mark Lobodzinskidc86b852015-10-23 14:20:31 -060015909
Chris Forbes8f36a8a2016-04-07 13:21:07 +120015910 m_errorMonitor->VerifyFound();
Mark Lobodzinskidc86b852015-10-23 14:20:31 -060015911}
15912
Mark Lobodzinskidb117632016-03-31 10:45:56 -060015913TEST_F(VkLayerTest, CopyImageLayerCountMismatch) {
Karl Schultz6addd812016-02-02 17:17:23 -070015914 VkResult err;
15915 bool pass;
Mike Stroyana3082432015-09-25 13:39:21 -060015916
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015917 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
15918 "vkCmdCopyImage: number of layers in source and destination subresources for pRegions");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060015919
Mike Stroyana3082432015-09-25 13:39:21 -060015920 ASSERT_NO_FATAL_FAILURE(InitState());
Mike Stroyana3082432015-09-25 13:39:21 -060015921
15922 // Create two images of different types and try to copy between them
Karl Schultz6addd812016-02-02 17:17:23 -070015923 VkImage srcImage;
15924 VkImage dstImage;
15925 VkDeviceMemory srcMem;
15926 VkDeviceMemory destMem;
15927 VkMemoryRequirements memReqs;
Mike Stroyana3082432015-09-25 13:39:21 -060015928
15929 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070015930 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
15931 image_create_info.pNext = NULL;
15932 image_create_info.imageType = VK_IMAGE_TYPE_2D;
15933 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
15934 image_create_info.extent.width = 32;
15935 image_create_info.extent.height = 32;
15936 image_create_info.extent.depth = 1;
15937 image_create_info.mipLevels = 1;
Mark Lobodzinskidb117632016-03-31 10:45:56 -060015938 image_create_info.arrayLayers = 4;
Karl Schultz6addd812016-02-02 17:17:23 -070015939 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
15940 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
15941 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
15942 image_create_info.flags = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060015943
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015944 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
Mike Stroyana3082432015-09-25 13:39:21 -060015945 ASSERT_VK_SUCCESS(err);
15946
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015947 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
Mike Stroyana3082432015-09-25 13:39:21 -060015948 ASSERT_VK_SUCCESS(err);
15949
15950 // Allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015951 VkMemoryAllocateInfo memAlloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -070015952 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
15953 memAlloc.pNext = NULL;
15954 memAlloc.allocationSize = 0;
15955 memAlloc.memoryTypeIndex = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060015956
Courtney Goeltzenleuchter06d89472015-10-20 16:40:38 -060015957 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060015958 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015959 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060015960 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015961 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
Mike Stroyana3082432015-09-25 13:39:21 -060015962 ASSERT_VK_SUCCESS(err);
15963
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015964 vkGetImageMemoryRequirements(m_device->device(), dstImage, &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);
Mike Stroyana3082432015-09-25 13:39:21 -060015967 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015968 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
Mike Stroyana3082432015-09-25 13:39:21 -060015969 ASSERT_VK_SUCCESS(err);
15970
15971 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
15972 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015973 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
Mike Stroyana3082432015-09-25 13:39:21 -060015974 ASSERT_VK_SUCCESS(err);
15975
15976 BeginCommandBuffer();
15977 VkImageCopy copyRegion;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080015978 copyRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060015979 copyRegion.srcSubresource.mipLevel = 0;
Courtney Goeltzenleuchter8367ce02015-10-16 09:46:00 -060015980 copyRegion.srcSubresource.baseArrayLayer = 0;
Mark Lobodzinskidb117632016-03-31 10:45:56 -060015981 copyRegion.srcSubresource.layerCount = 1;
Mike Stroyana3082432015-09-25 13:39:21 -060015982 copyRegion.srcOffset.x = 0;
15983 copyRegion.srcOffset.y = 0;
15984 copyRegion.srcOffset.z = 0;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080015985 copyRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015986 copyRegion.dstSubresource.mipLevel = 0;
15987 copyRegion.dstSubresource.baseArrayLayer = 0;
Mark Lobodzinskidb117632016-03-31 10:45:56 -060015988 // Introduce failure by forcing the dst layerCount to differ from src
15989 copyRegion.dstSubresource.layerCount = 3;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015990 copyRegion.dstOffset.x = 0;
15991 copyRegion.dstOffset.y = 0;
15992 copyRegion.dstOffset.z = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060015993 copyRegion.extent.width = 1;
15994 copyRegion.extent.height = 1;
15995 copyRegion.extent.depth = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015996 m_commandBuffer->CopyImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, VK_IMAGE_LAYOUT_GENERAL, 1, &copyRegion);
Mike Stroyana3082432015-09-25 13:39:21 -060015997 EndCommandBuffer();
15998
Chris Forbes8f36a8a2016-04-07 13:21:07 +120015999 m_errorMonitor->VerifyFound();
Mike Stroyana3082432015-09-25 13:39:21 -060016000
Chia-I Wuf7458c52015-10-26 21:10:41 +080016001 vkDestroyImage(m_device->device(), srcImage, NULL);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016002 vkDestroyImage(m_device->device(), dstImage, NULL);
Chia-I Wuf7458c52015-10-26 21:10:41 +080016003 vkFreeMemory(m_device->device(), srcMem, NULL);
16004 vkFreeMemory(m_device->device(), destMem, NULL);
Mike Stroyana3082432015-09-25 13:39:21 -060016005}
16006
Tony Barbourd6673642016-05-05 14:46:39 -060016007TEST_F(VkLayerTest, ImageLayerUnsupportedFormat) {
16008
16009 TEST_DESCRIPTION("Creating images with unsuported formats ");
16010
16011 ASSERT_NO_FATAL_FAILURE(InitState());
16012 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
16013 VkImageObj image(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016014 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 -060016015 VK_IMAGE_TILING_OPTIMAL, 0);
16016 ASSERT_TRUE(image.initialized());
16017
Mark Lobodzinskiba5c6862016-05-17 08:14:00 -060016018 // Create image with unsupported format - Expect FORMAT_UNSUPPORTED
16019 VkImageCreateInfo image_create_info;
16020 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
16021 image_create_info.pNext = NULL;
16022 image_create_info.imageType = VK_IMAGE_TYPE_2D;
16023 image_create_info.format = VK_FORMAT_UNDEFINED;
16024 image_create_info.extent.width = 32;
16025 image_create_info.extent.height = 32;
16026 image_create_info.extent.depth = 1;
16027 image_create_info.mipLevels = 1;
16028 image_create_info.arrayLayers = 1;
16029 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
16030 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
16031 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
16032 image_create_info.flags = 0;
16033
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016034 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
16035 "vkCreateImage: VkFormat for image must not be VK_FORMAT_UNDEFINED");
Mark Lobodzinskiba5c6862016-05-17 08:14:00 -060016036
16037 VkImage localImage;
16038 vkCreateImage(m_device->handle(), &image_create_info, NULL, &localImage);
16039 m_errorMonitor->VerifyFound();
16040
Tony Barbourd6673642016-05-05 14:46:39 -060016041 VkFormat unsupported = VK_FORMAT_UNDEFINED;
Mark Lobodzinskiba5c6862016-05-17 08:14:00 -060016042 // Look for a format that is COMPLETELY unsupported with this hardware
Tony Barbourd6673642016-05-05 14:46:39 -060016043 for (int f = VK_FORMAT_BEGIN_RANGE; f <= VK_FORMAT_END_RANGE; f++) {
16044 VkFormat format = static_cast<VkFormat>(f);
16045 VkFormatProperties fProps = m_device->format_properties(format);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016046 if (format != VK_FORMAT_UNDEFINED && fProps.linearTilingFeatures == 0 && fProps.optimalTilingFeatures == 0) {
Tony Barbourd6673642016-05-05 14:46:39 -060016047 unsupported = format;
16048 break;
16049 }
16050 }
Mark Lobodzinskiba5c6862016-05-17 08:14:00 -060016051
Tony Barbourd6673642016-05-05 14:46:39 -060016052 if (unsupported != VK_FORMAT_UNDEFINED) {
Tony Barbourd6673642016-05-05 14:46:39 -060016053 image_create_info.format = unsupported;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016054 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "is an unsupported format");
Tony Barbourd6673642016-05-05 14:46:39 -060016055
Mark Lobodzinskiba5c6862016-05-17 08:14:00 -060016056 vkCreateImage(m_device->handle(), &image_create_info, NULL, &localImage);
Tony Barbourd6673642016-05-05 14:46:39 -060016057 m_errorMonitor->VerifyFound();
16058 }
16059}
16060
16061TEST_F(VkLayerTest, ImageLayerViewTests) {
16062 VkResult ret;
16063 TEST_DESCRIPTION("Passing bad parameters to CreateImageView");
16064
16065 ASSERT_NO_FATAL_FAILURE(InitState());
16066
16067 VkImageObj image(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016068 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 -060016069 VK_IMAGE_TILING_OPTIMAL, 0);
16070 ASSERT_TRUE(image.initialized());
16071
16072 VkImageView imgView;
16073 VkImageViewCreateInfo imgViewInfo = {};
16074 imgViewInfo.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
16075 imgViewInfo.image = image.handle();
16076 imgViewInfo.viewType = VK_IMAGE_VIEW_TYPE_2D;
16077 imgViewInfo.format = VK_FORMAT_B8G8R8A8_UNORM;
16078 imgViewInfo.subresourceRange.layerCount = 1;
16079 imgViewInfo.subresourceRange.baseMipLevel = 0;
16080 imgViewInfo.subresourceRange.levelCount = 1;
16081 imgViewInfo.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
16082
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016083 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "vkCreateImageView called with baseMipLevel");
Tony Barbourd6673642016-05-05 14:46:39 -060016084 // View can't have baseMipLevel >= image's mipLevels - Expect
16085 // VIEW_CREATE_ERROR
16086 imgViewInfo.subresourceRange.baseMipLevel = 1;
16087 vkCreateImageView(m_device->handle(), &imgViewInfo, NULL, &imgView);
16088 m_errorMonitor->VerifyFound();
16089 imgViewInfo.subresourceRange.baseMipLevel = 0;
16090
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016091 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "vkCreateImageView called with baseArrayLayer");
Tony Barbourd6673642016-05-05 14:46:39 -060016092 // View can't have baseArrayLayer >= image's arraySize - Expect
16093 // VIEW_CREATE_ERROR
16094 imgViewInfo.subresourceRange.baseArrayLayer = 1;
16095 vkCreateImageView(m_device->handle(), &imgViewInfo, NULL, &imgView);
16096 m_errorMonitor->VerifyFound();
16097 imgViewInfo.subresourceRange.baseArrayLayer = 0;
16098
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016099 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "vkCreateImageView called with 0 in "
16100 "pCreateInfo->subresourceRange."
16101 "levelCount");
Tony Barbourd6673642016-05-05 14:46:39 -060016102 // View's levelCount can't be 0 - Expect VIEW_CREATE_ERROR
16103 imgViewInfo.subresourceRange.levelCount = 0;
16104 vkCreateImageView(m_device->handle(), &imgViewInfo, NULL, &imgView);
16105 m_errorMonitor->VerifyFound();
16106 imgViewInfo.subresourceRange.levelCount = 1;
16107
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016108 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "vkCreateImageView called with 0 in "
16109 "pCreateInfo->subresourceRange."
16110 "layerCount");
Tony Barbourd6673642016-05-05 14:46:39 -060016111 // View's layerCount can't be 0 - Expect VIEW_CREATE_ERROR
16112 imgViewInfo.subresourceRange.layerCount = 0;
16113 vkCreateImageView(m_device->handle(), &imgViewInfo, NULL, &imgView);
16114 m_errorMonitor->VerifyFound();
16115 imgViewInfo.subresourceRange.layerCount = 1;
16116
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016117 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "but both must be color formats");
Tony Barbourd6673642016-05-05 14:46:39 -060016118 // Can't use depth format for view into color image - Expect INVALID_FORMAT
16119 imgViewInfo.format = VK_FORMAT_D24_UNORM_S8_UINT;
16120 vkCreateImageView(m_device->handle(), &imgViewInfo, NULL, &imgView);
16121 m_errorMonitor->VerifyFound();
16122 imgViewInfo.format = VK_FORMAT_B8G8R8A8_UNORM;
16123
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016124 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Formats MUST be IDENTICAL unless "
16125 "VK_IMAGE_CREATE_MUTABLE_FORMAT BIT "
16126 "was set on image creation.");
Tony Barbourd6673642016-05-05 14:46:39 -060016127 // Same compatibility class but no MUTABLE_FORMAT bit - Expect
16128 // VIEW_CREATE_ERROR
16129 imgViewInfo.format = VK_FORMAT_B8G8R8A8_UINT;
16130 vkCreateImageView(m_device->handle(), &imgViewInfo, NULL, &imgView);
16131 m_errorMonitor->VerifyFound();
16132 imgViewInfo.format = VK_FORMAT_B8G8R8A8_UNORM;
16133
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016134 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "can support ImageViews with "
16135 "differing formats but they must be "
16136 "in the same compatibility class.");
Tony Barbourd6673642016-05-05 14:46:39 -060016137 // Have MUTABLE_FORMAT bit but not in same compatibility class - Expect
16138 // VIEW_CREATE_ERROR
16139 VkImageCreateInfo mutImgInfo = image.create_info();
16140 VkImage mutImage;
16141 mutImgInfo.format = VK_FORMAT_R8_UINT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016142 assert(m_device->format_properties(VK_FORMAT_R8_UINT).optimalTilingFeatures & VK_FORMAT_FEATURE_COLOR_ATTACHMENT_BIT);
Tony Barbourd6673642016-05-05 14:46:39 -060016143 mutImgInfo.flags = VK_IMAGE_CREATE_MUTABLE_FORMAT_BIT;
16144 mutImgInfo.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
16145 ret = vkCreateImage(m_device->handle(), &mutImgInfo, NULL, &mutImage);
16146 ASSERT_VK_SUCCESS(ret);
16147 imgViewInfo.image = mutImage;
16148 vkCreateImageView(m_device->handle(), &imgViewInfo, NULL, &imgView);
16149 m_errorMonitor->VerifyFound();
16150 imgViewInfo.image = image.handle();
16151 vkDestroyImage(m_device->handle(), mutImage, NULL);
16152}
16153
16154TEST_F(VkLayerTest, MiscImageLayerTests) {
16155
16156 TEST_DESCRIPTION("Image layer tests that don't belong elsewhare");
16157
16158 ASSERT_NO_FATAL_FAILURE(InitState());
16159
16160 VkImageObj image(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016161 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 -060016162 VK_IMAGE_TILING_OPTIMAL, 0);
16163 ASSERT_TRUE(image.initialized());
16164
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016165 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "number of layers in image subresource is zero");
Tony Barbourd6673642016-05-05 14:46:39 -060016166 vk_testing::Buffer buffer;
16167 VkMemoryPropertyFlags reqs = 0;
16168 buffer.init_as_src(*m_device, 128 * 128 * 4, reqs);
16169 VkBufferImageCopy region = {};
16170 region.bufferRowLength = 128;
16171 region.bufferImageHeight = 128;
16172 region.imageSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
16173 // layerCount can't be 0 - Expect MISMATCHED_IMAGE_ASPECT
16174 region.imageSubresource.layerCount = 0;
16175 region.imageExtent.height = 4;
16176 region.imageExtent.width = 4;
16177 region.imageExtent.depth = 1;
16178 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016179 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer.handle(), image.handle(),
16180 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, &region);
Tony Barbourd6673642016-05-05 14:46:39 -060016181 m_errorMonitor->VerifyFound();
16182 region.imageSubresource.layerCount = 1;
16183
Mark Lobodzinski7d8cf142016-08-19 10:53:26 -060016184 // BufferOffset must be a multiple of the calling command's VkImage parameter's texel size
16185 // Introduce failure by setting bufferOffset to 1 and 1/2 texels
16186 region.bufferOffset = 6;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016187 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "must be a multiple of this format's texel size");
16188 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer.handle(), image.handle(),
16189 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, &region);
Mark Lobodzinski7d8cf142016-08-19 10:53:26 -060016190 m_errorMonitor->VerifyFound();
16191
16192 // BufferOffset must be a multiple of 4
16193 // Introduce failure by setting bufferOffset to a value not divisible by 4
16194 region.bufferOffset = 6;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016195 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "must be a multiple of 4");
16196 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer.handle(), image.handle(),
16197 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, &region);
Mark Lobodzinski7d8cf142016-08-19 10:53:26 -060016198 m_errorMonitor->VerifyFound();
16199
16200 // BufferRowLength must be 0, or greater than or equal to the width member of imageExtent
16201 region.bufferOffset = 0;
16202 region.imageExtent.height = 128;
16203 region.imageExtent.width = 128;
16204 // Introduce failure by setting bufferRowLength > 0 but less than width
16205 region.bufferRowLength = 64;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016206 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
16207 "must be zero or greater-than-or-equal-to imageExtent.width");
16208 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer.handle(), image.handle(),
16209 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, &region);
Mark Lobodzinski7d8cf142016-08-19 10:53:26 -060016210 m_errorMonitor->VerifyFound();
16211
16212 // BufferImageHeight must be 0, or greater than or equal to the height member of imageExtent
16213 region.bufferRowLength = 128;
16214 // Introduce failure by setting bufferRowHeight > 0 but less than height
16215 region.bufferImageHeight = 64;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016216 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
16217 "must be zero or greater-than-or-equal-to imageExtent.height");
16218 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer.handle(), image.handle(),
16219 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, &region);
Mark Lobodzinski7d8cf142016-08-19 10:53:26 -060016220 m_errorMonitor->VerifyFound();
16221
16222 region.bufferImageHeight = 128;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016223 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "aspectMasks for each region must "
16224 "specify only COLOR or DEPTH or "
16225 "STENCIL");
Tony Barbourd6673642016-05-05 14:46:39 -060016226 // Expect MISMATCHED_IMAGE_ASPECT
16227 region.imageSubresource.aspectMask = VK_IMAGE_ASPECT_METADATA_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016228 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer.handle(), image.handle(),
16229 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, &region);
Tony Barbourd6673642016-05-05 14:46:39 -060016230 m_errorMonitor->VerifyFound();
16231 region.imageSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
16232
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016233 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
16234 "If the format of srcImage is a depth, stencil, depth stencil or "
16235 "integer-based format then filter must be VK_FILTER_NEAREST");
Tony Barbourd6673642016-05-05 14:46:39 -060016236 // Expect INVALID_FILTER
16237 VkImageObj intImage1(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016238 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 -060016239 VkImageObj intImage2(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016240 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 -060016241 VkImageBlit blitRegion = {};
16242 blitRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
16243 blitRegion.srcSubresource.baseArrayLayer = 0;
16244 blitRegion.srcSubresource.layerCount = 1;
16245 blitRegion.srcSubresource.mipLevel = 0;
16246 blitRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
16247 blitRegion.dstSubresource.baseArrayLayer = 0;
16248 blitRegion.dstSubresource.layerCount = 1;
16249 blitRegion.dstSubresource.mipLevel = 0;
16250
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016251 vkCmdBlitImage(m_commandBuffer->GetBufferHandle(), intImage1.handle(), intImage1.layout(), intImage2.handle(),
16252 intImage2.layout(), 16, &blitRegion, VK_FILTER_LINEAR);
Tony Barbourd6673642016-05-05 14:46:39 -060016253 m_errorMonitor->VerifyFound();
16254
Mark Lobodzinskib02ea642016-08-17 13:03:57 -060016255 // Look for NULL-blit warning
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016256 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT, "Offsets specify a zero-volume area.");
16257 vkCmdBlitImage(m_commandBuffer->GetBufferHandle(), intImage1.handle(), intImage1.layout(), intImage2.handle(),
16258 intImage2.layout(), 1, &blitRegion, VK_FILTER_LINEAR);
Mark Lobodzinskib02ea642016-08-17 13:03:57 -060016259 m_errorMonitor->VerifyFound();
16260
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016261 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "called with 0 in ppMemoryBarriers");
Tony Barbourd6673642016-05-05 14:46:39 -060016262 VkImageMemoryBarrier img_barrier;
16263 img_barrier.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
16264 img_barrier.pNext = NULL;
16265 img_barrier.srcAccessMask = VK_ACCESS_HOST_WRITE_BIT;
16266 img_barrier.dstAccessMask = VK_ACCESS_SHADER_READ_BIT;
16267 img_barrier.oldLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
16268 img_barrier.newLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
16269 img_barrier.image = image.handle();
16270 img_barrier.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
16271 img_barrier.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
16272 img_barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
16273 img_barrier.subresourceRange.baseArrayLayer = 0;
16274 img_barrier.subresourceRange.baseMipLevel = 0;
16275 // layerCount should not be 0 - Expect INVALID_IMAGE_RESOURCE
16276 img_barrier.subresourceRange.layerCount = 0;
16277 img_barrier.subresourceRange.levelCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016278 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
16279 nullptr, 0, nullptr, 1, &img_barrier);
Tony Barbourd6673642016-05-05 14:46:39 -060016280 m_errorMonitor->VerifyFound();
16281 img_barrier.subresourceRange.layerCount = 1;
16282}
16283
16284TEST_F(VkLayerTest, ImageFormatLimits) {
16285
16286 TEST_DESCRIPTION("Exceed the limits of image format ");
16287
Cody Northropc31a84f2016-08-22 10:41:47 -060016288 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016289 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "CreateImage extents exceed allowable limits for format");
Tony Barbourd6673642016-05-05 14:46:39 -060016290 VkImageCreateInfo image_create_info = {};
16291 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
16292 image_create_info.pNext = NULL;
16293 image_create_info.imageType = VK_IMAGE_TYPE_2D;
16294 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
16295 image_create_info.extent.width = 32;
16296 image_create_info.extent.height = 32;
16297 image_create_info.extent.depth = 1;
16298 image_create_info.mipLevels = 1;
16299 image_create_info.arrayLayers = 1;
16300 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
16301 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
16302 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
16303 image_create_info.initialLayout = VK_IMAGE_LAYOUT_UNDEFINED;
16304 image_create_info.flags = 0;
16305
16306 VkImage nullImg;
16307 VkImageFormatProperties imgFmtProps;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016308 vkGetPhysicalDeviceImageFormatProperties(gpu(), image_create_info.format, image_create_info.imageType, image_create_info.tiling,
16309 image_create_info.usage, image_create_info.flags, &imgFmtProps);
Tony Barbourd6673642016-05-05 14:46:39 -060016310 image_create_info.extent.depth = imgFmtProps.maxExtent.depth + 1;
16311 // Expect INVALID_FORMAT_LIMITS_VIOLATION
16312 vkCreateImage(m_device->handle(), &image_create_info, NULL, &nullImg);
16313 m_errorMonitor->VerifyFound();
16314 image_create_info.extent.depth = 1;
16315
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016316 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "exceeds allowable maximum supported by format of");
Tony Barbourd6673642016-05-05 14:46:39 -060016317 image_create_info.mipLevels = imgFmtProps.maxMipLevels + 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.mipLevels = 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.arrayLayers = imgFmtProps.maxArrayLayers + 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.arrayLayers = 1;
16329
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016330 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "is not supported by format");
Tony Barbourd6673642016-05-05 14:46:39 -060016331 int samples = imgFmtProps.sampleCounts >> 1;
16332 image_create_info.samples = (VkSampleCountFlagBits)samples;
16333 // Expect INVALID_FORMAT_LIMITS_VIOLATION
16334 vkCreateImage(m_device->handle(), &image_create_info, NULL, &nullImg);
16335 m_errorMonitor->VerifyFound();
16336 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
16337
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016338 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "pCreateInfo->initialLayout, must be "
16339 "VK_IMAGE_LAYOUT_UNDEFINED or "
16340 "VK_IMAGE_LAYOUT_PREINITIALIZED");
Tony Barbourd6673642016-05-05 14:46:39 -060016341 image_create_info.initialLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
16342 // Expect INVALID_LAYOUT
16343 vkCreateImage(m_device->handle(), &image_create_info, NULL, &nullImg);
16344 m_errorMonitor->VerifyFound();
16345 image_create_info.initialLayout = VK_IMAGE_LAYOUT_UNDEFINED;
16346}
16347
Karl Schultz6addd812016-02-02 17:17:23 -070016348TEST_F(VkLayerTest, CopyImageFormatSizeMismatch) {
Karl Schultzbdb75952016-04-19 11:36:49 -060016349 VkResult err;
16350 bool pass;
16351
16352 // Create color images with different format sizes and try to copy between them
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016353 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
16354 "vkCmdCopyImage called with unmatched source and dest image format sizes");
Karl Schultzbdb75952016-04-19 11:36:49 -060016355
16356 ASSERT_NO_FATAL_FAILURE(InitState());
16357
16358 // Create two images of different types and try to copy between them
16359 VkImage srcImage;
16360 VkImage dstImage;
16361 VkDeviceMemory srcMem;
16362 VkDeviceMemory destMem;
16363 VkMemoryRequirements memReqs;
16364
16365 VkImageCreateInfo image_create_info = {};
16366 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
16367 image_create_info.pNext = NULL;
16368 image_create_info.imageType = VK_IMAGE_TYPE_2D;
16369 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
16370 image_create_info.extent.width = 32;
16371 image_create_info.extent.height = 32;
16372 image_create_info.extent.depth = 1;
16373 image_create_info.mipLevels = 1;
16374 image_create_info.arrayLayers = 1;
16375 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
16376 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
16377 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
16378 image_create_info.flags = 0;
16379
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016380 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
Karl Schultzbdb75952016-04-19 11:36:49 -060016381 ASSERT_VK_SUCCESS(err);
16382
16383 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT;
16384 // Introduce failure by creating second image with a different-sized format.
16385 image_create_info.format = VK_FORMAT_R5G5B5A1_UNORM_PACK16;
16386
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016387 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
Karl Schultzbdb75952016-04-19 11:36:49 -060016388 ASSERT_VK_SUCCESS(err);
16389
16390 // Allocate memory
16391 VkMemoryAllocateInfo memAlloc = {};
16392 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
16393 memAlloc.pNext = NULL;
16394 memAlloc.allocationSize = 0;
16395 memAlloc.memoryTypeIndex = 0;
16396
16397 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
16398 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016399 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Karl Schultzbdb75952016-04-19 11:36:49 -060016400 ASSERT_TRUE(pass);
16401 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
16402 ASSERT_VK_SUCCESS(err);
16403
16404 vkGetImageMemoryRequirements(m_device->device(), dstImage, &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, &destMem);
16409 ASSERT_VK_SUCCESS(err);
16410
16411 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
16412 ASSERT_VK_SUCCESS(err);
16413 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
16414 ASSERT_VK_SUCCESS(err);
16415
16416 BeginCommandBuffer();
16417 VkImageCopy copyRegion;
16418 copyRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
16419 copyRegion.srcSubresource.mipLevel = 0;
16420 copyRegion.srcSubresource.baseArrayLayer = 0;
16421 copyRegion.srcSubresource.layerCount = 0;
16422 copyRegion.srcOffset.x = 0;
16423 copyRegion.srcOffset.y = 0;
16424 copyRegion.srcOffset.z = 0;
16425 copyRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
16426 copyRegion.dstSubresource.mipLevel = 0;
16427 copyRegion.dstSubresource.baseArrayLayer = 0;
16428 copyRegion.dstSubresource.layerCount = 0;
16429 copyRegion.dstOffset.x = 0;
16430 copyRegion.dstOffset.y = 0;
16431 copyRegion.dstOffset.z = 0;
16432 copyRegion.extent.width = 1;
16433 copyRegion.extent.height = 1;
16434 copyRegion.extent.depth = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016435 m_commandBuffer->CopyImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, VK_IMAGE_LAYOUT_GENERAL, 1, &copyRegion);
Karl Schultzbdb75952016-04-19 11:36:49 -060016436 EndCommandBuffer();
16437
16438 m_errorMonitor->VerifyFound();
16439
16440 vkDestroyImage(m_device->device(), srcImage, NULL);
16441 vkDestroyImage(m_device->device(), dstImage, NULL);
16442 vkFreeMemory(m_device->device(), srcMem, NULL);
16443 vkFreeMemory(m_device->device(), destMem, NULL);
Mike Stroyana3082432015-09-25 13:39:21 -060016444}
16445
Karl Schultz6addd812016-02-02 17:17:23 -070016446TEST_F(VkLayerTest, CopyImageDepthStencilFormatMismatch) {
16447 VkResult err;
16448 bool pass;
Mike Stroyana3082432015-09-25 13:39:21 -060016449
Mark Lobodzinskidb117632016-03-31 10:45:56 -060016450 // Create a color image and a depth/stencil image and try to copy between them
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016451 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
16452 "vkCmdCopyImage called with unmatched source and dest image depth");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060016453
Mike Stroyana3082432015-09-25 13:39:21 -060016454 ASSERT_NO_FATAL_FAILURE(InitState());
Mike Stroyana3082432015-09-25 13:39:21 -060016455
16456 // Create two images of different types and try to copy between them
Karl Schultz6addd812016-02-02 17:17:23 -070016457 VkImage srcImage;
16458 VkImage dstImage;
16459 VkDeviceMemory srcMem;
16460 VkDeviceMemory destMem;
16461 VkMemoryRequirements memReqs;
Mike Stroyana3082432015-09-25 13:39:21 -060016462
16463 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070016464 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
16465 image_create_info.pNext = NULL;
16466 image_create_info.imageType = VK_IMAGE_TYPE_2D;
16467 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
16468 image_create_info.extent.width = 32;
16469 image_create_info.extent.height = 32;
16470 image_create_info.extent.depth = 1;
16471 image_create_info.mipLevels = 1;
16472 image_create_info.arrayLayers = 1;
16473 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
16474 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
16475 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
16476 image_create_info.flags = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060016477
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016478 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
Mike Stroyana3082432015-09-25 13:39:21 -060016479 ASSERT_VK_SUCCESS(err);
16480
Karl Schultzbdb75952016-04-19 11:36:49 -060016481 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT;
16482
Mark Lobodzinskidb117632016-03-31 10:45:56 -060016483 // Introduce failure by creating second image with a depth/stencil format
Karl Schultz6addd812016-02-02 17:17:23 -070016484 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
Mark Lobodzinskidb117632016-03-31 10:45:56 -060016485 image_create_info.format = VK_FORMAT_D24_UNORM_S8_UINT;
16486 image_create_info.usage = VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060016487
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016488 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
Mike Stroyana3082432015-09-25 13:39:21 -060016489 ASSERT_VK_SUCCESS(err);
16490
16491 // Allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016492 VkMemoryAllocateInfo memAlloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -070016493 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
16494 memAlloc.pNext = NULL;
16495 memAlloc.allocationSize = 0;
16496 memAlloc.memoryTypeIndex = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060016497
Courtney Goeltzenleuchter06d89472015-10-20 16:40:38 -060016498 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060016499 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016500 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060016501 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016502 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
Mike Stroyana3082432015-09-25 13:39:21 -060016503 ASSERT_VK_SUCCESS(err);
16504
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016505 vkGetImageMemoryRequirements(m_device->device(), dstImage, &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, &destMem);
Mike Stroyana3082432015-09-25 13:39:21 -060016510 ASSERT_VK_SUCCESS(err);
16511
16512 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
16513 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016514 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
Mike Stroyana3082432015-09-25 13:39:21 -060016515 ASSERT_VK_SUCCESS(err);
16516
16517 BeginCommandBuffer();
16518 VkImageCopy copyRegion;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080016519 copyRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060016520 copyRegion.srcSubresource.mipLevel = 0;
Courtney Goeltzenleuchter8367ce02015-10-16 09:46:00 -060016521 copyRegion.srcSubresource.baseArrayLayer = 0;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016522 copyRegion.srcSubresource.layerCount = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060016523 copyRegion.srcOffset.x = 0;
16524 copyRegion.srcOffset.y = 0;
16525 copyRegion.srcOffset.z = 0;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080016526 copyRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016527 copyRegion.dstSubresource.mipLevel = 0;
16528 copyRegion.dstSubresource.baseArrayLayer = 0;
16529 copyRegion.dstSubresource.layerCount = 0;
16530 copyRegion.dstOffset.x = 0;
16531 copyRegion.dstOffset.y = 0;
16532 copyRegion.dstOffset.z = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060016533 copyRegion.extent.width = 1;
16534 copyRegion.extent.height = 1;
16535 copyRegion.extent.depth = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016536 m_commandBuffer->CopyImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, VK_IMAGE_LAYOUT_GENERAL, 1, &copyRegion);
Mike Stroyana3082432015-09-25 13:39:21 -060016537 EndCommandBuffer();
16538
Chris Forbes8f36a8a2016-04-07 13:21:07 +120016539 m_errorMonitor->VerifyFound();
Mike Stroyana3082432015-09-25 13:39:21 -060016540
Chia-I Wuf7458c52015-10-26 21:10:41 +080016541 vkDestroyImage(m_device->device(), srcImage, NULL);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016542 vkDestroyImage(m_device->device(), dstImage, NULL);
Chia-I Wuf7458c52015-10-26 21:10:41 +080016543 vkFreeMemory(m_device->device(), srcMem, NULL);
16544 vkFreeMemory(m_device->device(), destMem, NULL);
Mike Stroyana3082432015-09-25 13:39:21 -060016545}
16546
Karl Schultz6addd812016-02-02 17:17:23 -070016547TEST_F(VkLayerTest, ResolveImageLowSampleCount) {
16548 VkResult err;
16549 bool pass;
Mike Stroyana3082432015-09-25 13:39:21 -060016550
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016551 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
16552 "vkCmdResolveImage called with source sample count less than 2.");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060016553
Mike Stroyana3082432015-09-25 13:39:21 -060016554 ASSERT_NO_FATAL_FAILURE(InitState());
Mike Stroyana3082432015-09-25 13:39:21 -060016555
16556 // Create two images of sample count 1 and try to Resolve between them
Karl Schultz6addd812016-02-02 17:17:23 -070016557 VkImage srcImage;
16558 VkImage dstImage;
16559 VkDeviceMemory srcMem;
16560 VkDeviceMemory destMem;
16561 VkMemoryRequirements memReqs;
Mike Stroyana3082432015-09-25 13:39:21 -060016562
16563 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070016564 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
16565 image_create_info.pNext = NULL;
16566 image_create_info.imageType = VK_IMAGE_TYPE_2D;
16567 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
16568 image_create_info.extent.width = 32;
16569 image_create_info.extent.height = 1;
16570 image_create_info.extent.depth = 1;
16571 image_create_info.mipLevels = 1;
16572 image_create_info.arrayLayers = 1;
16573 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
16574 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
16575 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
16576 image_create_info.flags = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060016577
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016578 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
Mike Stroyana3082432015-09-25 13:39:21 -060016579 ASSERT_VK_SUCCESS(err);
16580
Karl Schultz6addd812016-02-02 17:17:23 -070016581 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060016582
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016583 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
Mike Stroyana3082432015-09-25 13:39:21 -060016584 ASSERT_VK_SUCCESS(err);
16585
16586 // Allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016587 VkMemoryAllocateInfo memAlloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -070016588 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
16589 memAlloc.pNext = NULL;
16590 memAlloc.allocationSize = 0;
16591 memAlloc.memoryTypeIndex = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060016592
Courtney Goeltzenleuchter06d89472015-10-20 16:40:38 -060016593 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060016594 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016595 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060016596 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016597 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
Mike Stroyana3082432015-09-25 13:39:21 -060016598 ASSERT_VK_SUCCESS(err);
16599
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016600 vkGetImageMemoryRequirements(m_device->device(), dstImage, &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, &destMem);
Mike Stroyana3082432015-09-25 13:39:21 -060016605 ASSERT_VK_SUCCESS(err);
16606
16607 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
16608 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016609 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
Mike Stroyana3082432015-09-25 13:39:21 -060016610 ASSERT_VK_SUCCESS(err);
16611
16612 BeginCommandBuffer();
16613 // Need memory barrier to VK_IMAGE_LAYOUT_GENERAL for source and dest?
Karl Schultz6addd812016-02-02 17:17:23 -070016614 // VK_IMAGE_LAYOUT_UNDEFINED = 0,
16615 // VK_IMAGE_LAYOUT_GENERAL = 1,
Mike Stroyana3082432015-09-25 13:39:21 -060016616 VkImageResolve resolveRegion;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080016617 resolveRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060016618 resolveRegion.srcSubresource.mipLevel = 0;
Courtney Goeltzenleuchter8367ce02015-10-16 09:46:00 -060016619 resolveRegion.srcSubresource.baseArrayLayer = 0;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016620 resolveRegion.srcSubresource.layerCount = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060016621 resolveRegion.srcOffset.x = 0;
16622 resolveRegion.srcOffset.y = 0;
16623 resolveRegion.srcOffset.z = 0;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080016624 resolveRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016625 resolveRegion.dstSubresource.mipLevel = 0;
16626 resolveRegion.dstSubresource.baseArrayLayer = 0;
16627 resolveRegion.dstSubresource.layerCount = 0;
16628 resolveRegion.dstOffset.x = 0;
16629 resolveRegion.dstOffset.y = 0;
16630 resolveRegion.dstOffset.z = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060016631 resolveRegion.extent.width = 1;
16632 resolveRegion.extent.height = 1;
16633 resolveRegion.extent.depth = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016634 m_commandBuffer->ResolveImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, VK_IMAGE_LAYOUT_GENERAL, 1, &resolveRegion);
Mike Stroyana3082432015-09-25 13:39:21 -060016635 EndCommandBuffer();
16636
Chris Forbes8f36a8a2016-04-07 13:21:07 +120016637 m_errorMonitor->VerifyFound();
Mike Stroyana3082432015-09-25 13:39:21 -060016638
Chia-I Wuf7458c52015-10-26 21:10:41 +080016639 vkDestroyImage(m_device->device(), srcImage, NULL);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016640 vkDestroyImage(m_device->device(), dstImage, NULL);
Chia-I Wuf7458c52015-10-26 21:10:41 +080016641 vkFreeMemory(m_device->device(), srcMem, NULL);
16642 vkFreeMemory(m_device->device(), destMem, NULL);
Mike Stroyana3082432015-09-25 13:39:21 -060016643}
16644
Karl Schultz6addd812016-02-02 17:17:23 -070016645TEST_F(VkLayerTest, ResolveImageHighSampleCount) {
16646 VkResult err;
16647 bool pass;
Mike Stroyana3082432015-09-25 13:39:21 -060016648
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016649 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
16650 "vkCmdResolveImage called with dest sample count greater than 1.");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060016651
Mike Stroyana3082432015-09-25 13:39:21 -060016652 ASSERT_NO_FATAL_FAILURE(InitState());
Mike Stroyana3082432015-09-25 13:39:21 -060016653
Chris Forbesa7530692016-05-08 12:35:39 +120016654 // Create two images of sample count 4 and try to Resolve between them
Karl Schultz6addd812016-02-02 17:17:23 -070016655 VkImage srcImage;
16656 VkImage dstImage;
16657 VkDeviceMemory srcMem;
16658 VkDeviceMemory destMem;
16659 VkMemoryRequirements memReqs;
Mike Stroyana3082432015-09-25 13:39:21 -060016660
16661 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070016662 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
16663 image_create_info.pNext = NULL;
16664 image_create_info.imageType = VK_IMAGE_TYPE_2D;
16665 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
16666 image_create_info.extent.width = 32;
16667 image_create_info.extent.height = 1;
16668 image_create_info.extent.depth = 1;
16669 image_create_info.mipLevels = 1;
16670 image_create_info.arrayLayers = 1;
Chris Forbesa7530692016-05-08 12:35:39 +120016671 image_create_info.samples = VK_SAMPLE_COUNT_4_BIT;
Karl Schultz6addd812016-02-02 17:17:23 -070016672 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
16673 // Note: Some implementations expect color attachment usage for any
16674 // multisample surface
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016675 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
Karl Schultz6addd812016-02-02 17:17:23 -070016676 image_create_info.flags = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060016677
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016678 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
Mike Stroyana3082432015-09-25 13:39:21 -060016679 ASSERT_VK_SUCCESS(err);
16680
Karl Schultz6addd812016-02-02 17:17:23 -070016681 // Note: Some implementations expect color attachment usage for any
16682 // multisample surface
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016683 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
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, &dstImage);
Mike Stroyana3082432015-09-25 13:39:21 -060016686 ASSERT_VK_SUCCESS(err);
16687
16688 // Allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016689 VkMemoryAllocateInfo memAlloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -070016690 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
16691 memAlloc.pNext = NULL;
16692 memAlloc.allocationSize = 0;
16693 memAlloc.memoryTypeIndex = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060016694
Courtney Goeltzenleuchter06d89472015-10-20 16:40:38 -060016695 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060016696 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016697 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060016698 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016699 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
Mike Stroyana3082432015-09-25 13:39:21 -060016700 ASSERT_VK_SUCCESS(err);
16701
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016702 vkGetImageMemoryRequirements(m_device->device(), dstImage, &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, &destMem);
Mike Stroyana3082432015-09-25 13:39:21 -060016707 ASSERT_VK_SUCCESS(err);
16708
16709 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
16710 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016711 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
Mike Stroyana3082432015-09-25 13:39:21 -060016712 ASSERT_VK_SUCCESS(err);
16713
16714 BeginCommandBuffer();
16715 // Need memory barrier to VK_IMAGE_LAYOUT_GENERAL for source and dest?
Karl Schultz6addd812016-02-02 17:17:23 -070016716 // VK_IMAGE_LAYOUT_UNDEFINED = 0,
16717 // VK_IMAGE_LAYOUT_GENERAL = 1,
Mike Stroyana3082432015-09-25 13:39:21 -060016718 VkImageResolve resolveRegion;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080016719 resolveRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060016720 resolveRegion.srcSubresource.mipLevel = 0;
Courtney Goeltzenleuchter8367ce02015-10-16 09:46:00 -060016721 resolveRegion.srcSubresource.baseArrayLayer = 0;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016722 resolveRegion.srcSubresource.layerCount = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060016723 resolveRegion.srcOffset.x = 0;
16724 resolveRegion.srcOffset.y = 0;
16725 resolveRegion.srcOffset.z = 0;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080016726 resolveRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016727 resolveRegion.dstSubresource.mipLevel = 0;
16728 resolveRegion.dstSubresource.baseArrayLayer = 0;
16729 resolveRegion.dstSubresource.layerCount = 0;
16730 resolveRegion.dstOffset.x = 0;
16731 resolveRegion.dstOffset.y = 0;
16732 resolveRegion.dstOffset.z = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060016733 resolveRegion.extent.width = 1;
16734 resolveRegion.extent.height = 1;
16735 resolveRegion.extent.depth = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016736 m_commandBuffer->ResolveImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, VK_IMAGE_LAYOUT_GENERAL, 1, &resolveRegion);
Mike Stroyana3082432015-09-25 13:39:21 -060016737 EndCommandBuffer();
16738
Chris Forbes8f36a8a2016-04-07 13:21:07 +120016739 m_errorMonitor->VerifyFound();
Mike Stroyana3082432015-09-25 13:39:21 -060016740
Chia-I Wuf7458c52015-10-26 21:10:41 +080016741 vkDestroyImage(m_device->device(), srcImage, NULL);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016742 vkDestroyImage(m_device->device(), dstImage, NULL);
Chia-I Wuf7458c52015-10-26 21:10:41 +080016743 vkFreeMemory(m_device->device(), srcMem, NULL);
16744 vkFreeMemory(m_device->device(), destMem, NULL);
Mike Stroyana3082432015-09-25 13:39:21 -060016745}
16746
Karl Schultz6addd812016-02-02 17:17:23 -070016747TEST_F(VkLayerTest, ResolveImageFormatMismatch) {
16748 VkResult err;
16749 bool pass;
Mike Stroyana3082432015-09-25 13:39:21 -060016750
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016751 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
16752 "vkCmdResolveImage called with unmatched source and dest formats.");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060016753
Mike Stroyana3082432015-09-25 13:39:21 -060016754 ASSERT_NO_FATAL_FAILURE(InitState());
Mike Stroyana3082432015-09-25 13:39:21 -060016755
16756 // Create two images of different types and try to copy between them
Karl Schultz6addd812016-02-02 17:17:23 -070016757 VkImage srcImage;
16758 VkImage dstImage;
16759 VkDeviceMemory srcMem;
16760 VkDeviceMemory destMem;
16761 VkMemoryRequirements memReqs;
Mike Stroyana3082432015-09-25 13:39:21 -060016762
16763 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070016764 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
16765 image_create_info.pNext = NULL;
16766 image_create_info.imageType = VK_IMAGE_TYPE_2D;
16767 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
16768 image_create_info.extent.width = 32;
16769 image_create_info.extent.height = 1;
16770 image_create_info.extent.depth = 1;
16771 image_create_info.mipLevels = 1;
16772 image_create_info.arrayLayers = 1;
16773 image_create_info.samples = VK_SAMPLE_COUNT_2_BIT;
16774 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
16775 // Note: Some implementations expect color attachment usage for any
16776 // multisample surface
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016777 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
Karl Schultz6addd812016-02-02 17:17:23 -070016778 image_create_info.flags = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060016779
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016780 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
Mike Stroyana3082432015-09-25 13:39:21 -060016781 ASSERT_VK_SUCCESS(err);
16782
Karl Schultz6addd812016-02-02 17:17:23 -070016783 // Set format to something other than source image
16784 image_create_info.format = VK_FORMAT_R32_SFLOAT;
16785 // Note: Some implementations expect color attachment usage for any
16786 // multisample surface
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016787 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
Karl Schultz6addd812016-02-02 17:17:23 -070016788 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060016789
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016790 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
Mike Stroyana3082432015-09-25 13:39:21 -060016791 ASSERT_VK_SUCCESS(err);
16792
16793 // Allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016794 VkMemoryAllocateInfo memAlloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -070016795 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
16796 memAlloc.pNext = NULL;
16797 memAlloc.allocationSize = 0;
16798 memAlloc.memoryTypeIndex = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060016799
Courtney Goeltzenleuchter06d89472015-10-20 16:40:38 -060016800 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060016801 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016802 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060016803 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016804 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
Mike Stroyana3082432015-09-25 13:39:21 -060016805 ASSERT_VK_SUCCESS(err);
16806
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016807 vkGetImageMemoryRequirements(m_device->device(), dstImage, &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, &destMem);
Mike Stroyana3082432015-09-25 13:39:21 -060016812 ASSERT_VK_SUCCESS(err);
16813
16814 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
16815 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016816 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
Mike Stroyana3082432015-09-25 13:39:21 -060016817 ASSERT_VK_SUCCESS(err);
16818
16819 BeginCommandBuffer();
16820 // Need memory barrier to VK_IMAGE_LAYOUT_GENERAL for source and dest?
Karl Schultz6addd812016-02-02 17:17:23 -070016821 // VK_IMAGE_LAYOUT_UNDEFINED = 0,
16822 // VK_IMAGE_LAYOUT_GENERAL = 1,
Mike Stroyana3082432015-09-25 13:39:21 -060016823 VkImageResolve resolveRegion;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080016824 resolveRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060016825 resolveRegion.srcSubresource.mipLevel = 0;
Courtney Goeltzenleuchter8367ce02015-10-16 09:46:00 -060016826 resolveRegion.srcSubresource.baseArrayLayer = 0;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016827 resolveRegion.srcSubresource.layerCount = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060016828 resolveRegion.srcOffset.x = 0;
16829 resolveRegion.srcOffset.y = 0;
16830 resolveRegion.srcOffset.z = 0;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080016831 resolveRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016832 resolveRegion.dstSubresource.mipLevel = 0;
16833 resolveRegion.dstSubresource.baseArrayLayer = 0;
16834 resolveRegion.dstSubresource.layerCount = 0;
16835 resolveRegion.dstOffset.x = 0;
16836 resolveRegion.dstOffset.y = 0;
16837 resolveRegion.dstOffset.z = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060016838 resolveRegion.extent.width = 1;
16839 resolveRegion.extent.height = 1;
16840 resolveRegion.extent.depth = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016841 m_commandBuffer->ResolveImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, VK_IMAGE_LAYOUT_GENERAL, 1, &resolveRegion);
Mike Stroyana3082432015-09-25 13:39:21 -060016842 EndCommandBuffer();
16843
Chris Forbes8f36a8a2016-04-07 13:21:07 +120016844 m_errorMonitor->VerifyFound();
Mike Stroyana3082432015-09-25 13:39:21 -060016845
Chia-I Wuf7458c52015-10-26 21:10:41 +080016846 vkDestroyImage(m_device->device(), srcImage, NULL);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016847 vkDestroyImage(m_device->device(), dstImage, NULL);
Chia-I Wuf7458c52015-10-26 21:10:41 +080016848 vkFreeMemory(m_device->device(), srcMem, NULL);
16849 vkFreeMemory(m_device->device(), destMem, NULL);
Mike Stroyana3082432015-09-25 13:39:21 -060016850}
16851
Karl Schultz6addd812016-02-02 17:17:23 -070016852TEST_F(VkLayerTest, ResolveImageTypeMismatch) {
16853 VkResult err;
16854 bool pass;
Mike Stroyana3082432015-09-25 13:39:21 -060016855
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016856 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
16857 "vkCmdResolveImage called with unmatched source and dest image types.");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060016858
Mike Stroyana3082432015-09-25 13:39:21 -060016859 ASSERT_NO_FATAL_FAILURE(InitState());
Mike Stroyana3082432015-09-25 13:39:21 -060016860
16861 // Create two images of different types and try to copy between them
Karl Schultz6addd812016-02-02 17:17:23 -070016862 VkImage srcImage;
16863 VkImage dstImage;
16864 VkDeviceMemory srcMem;
16865 VkDeviceMemory destMem;
16866 VkMemoryRequirements memReqs;
Mike Stroyana3082432015-09-25 13:39:21 -060016867
16868 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070016869 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
16870 image_create_info.pNext = NULL;
16871 image_create_info.imageType = VK_IMAGE_TYPE_2D;
16872 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
16873 image_create_info.extent.width = 32;
16874 image_create_info.extent.height = 1;
16875 image_create_info.extent.depth = 1;
16876 image_create_info.mipLevels = 1;
16877 image_create_info.arrayLayers = 1;
16878 image_create_info.samples = VK_SAMPLE_COUNT_2_BIT;
16879 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
16880 // Note: Some implementations expect color attachment usage for any
16881 // multisample surface
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016882 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
Karl Schultz6addd812016-02-02 17:17:23 -070016883 image_create_info.flags = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060016884
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016885 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
Mike Stroyana3082432015-09-25 13:39:21 -060016886 ASSERT_VK_SUCCESS(err);
16887
Karl Schultz6addd812016-02-02 17:17:23 -070016888 image_create_info.imageType = VK_IMAGE_TYPE_1D;
16889 // Note: Some implementations expect color attachment usage for any
16890 // multisample surface
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016891 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
Karl Schultz6addd812016-02-02 17:17:23 -070016892 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060016893
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016894 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
Mike Stroyana3082432015-09-25 13:39:21 -060016895 ASSERT_VK_SUCCESS(err);
16896
16897 // Allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016898 VkMemoryAllocateInfo memAlloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -070016899 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
16900 memAlloc.pNext = NULL;
16901 memAlloc.allocationSize = 0;
16902 memAlloc.memoryTypeIndex = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060016903
Courtney Goeltzenleuchter06d89472015-10-20 16:40:38 -060016904 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060016905 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016906 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060016907 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016908 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
Mike Stroyana3082432015-09-25 13:39:21 -060016909 ASSERT_VK_SUCCESS(err);
16910
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016911 vkGetImageMemoryRequirements(m_device->device(), dstImage, &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, &destMem);
Mike Stroyana3082432015-09-25 13:39:21 -060016916 ASSERT_VK_SUCCESS(err);
16917
16918 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
16919 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016920 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
Mike Stroyana3082432015-09-25 13:39:21 -060016921 ASSERT_VK_SUCCESS(err);
16922
16923 BeginCommandBuffer();
16924 // Need memory barrier to VK_IMAGE_LAYOUT_GENERAL for source and dest?
Karl Schultz6addd812016-02-02 17:17:23 -070016925 // VK_IMAGE_LAYOUT_UNDEFINED = 0,
16926 // VK_IMAGE_LAYOUT_GENERAL = 1,
Mike Stroyana3082432015-09-25 13:39:21 -060016927 VkImageResolve resolveRegion;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080016928 resolveRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060016929 resolveRegion.srcSubresource.mipLevel = 0;
Courtney Goeltzenleuchter8367ce02015-10-16 09:46:00 -060016930 resolveRegion.srcSubresource.baseArrayLayer = 0;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016931 resolveRegion.srcSubresource.layerCount = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060016932 resolveRegion.srcOffset.x = 0;
16933 resolveRegion.srcOffset.y = 0;
16934 resolveRegion.srcOffset.z = 0;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080016935 resolveRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016936 resolveRegion.dstSubresource.mipLevel = 0;
16937 resolveRegion.dstSubresource.baseArrayLayer = 0;
16938 resolveRegion.dstSubresource.layerCount = 0;
16939 resolveRegion.dstOffset.x = 0;
16940 resolveRegion.dstOffset.y = 0;
16941 resolveRegion.dstOffset.z = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060016942 resolveRegion.extent.width = 1;
16943 resolveRegion.extent.height = 1;
16944 resolveRegion.extent.depth = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016945 m_commandBuffer->ResolveImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, VK_IMAGE_LAYOUT_GENERAL, 1, &resolveRegion);
Mike Stroyana3082432015-09-25 13:39:21 -060016946 EndCommandBuffer();
16947
Chris Forbes8f36a8a2016-04-07 13:21:07 +120016948 m_errorMonitor->VerifyFound();
Mike Stroyana3082432015-09-25 13:39:21 -060016949
Chia-I Wuf7458c52015-10-26 21:10:41 +080016950 vkDestroyImage(m_device->device(), srcImage, NULL);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016951 vkDestroyImage(m_device->device(), dstImage, NULL);
Chia-I Wuf7458c52015-10-26 21:10:41 +080016952 vkFreeMemory(m_device->device(), srcMem, NULL);
16953 vkFreeMemory(m_device->device(), destMem, NULL);
Mike Stroyana3082432015-09-25 13:39:21 -060016954}
Tobin Ehlisa1c28562015-10-23 16:00:08 -060016955
Karl Schultz6addd812016-02-02 17:17:23 -070016956TEST_F(VkLayerTest, DepthStencilImageViewWithColorAspectBitError) {
Tobin Ehlisa1c28562015-10-23 16:00:08 -060016957 // Create a single Image descriptor and cause it to first hit an error due
Karl Schultz6addd812016-02-02 17:17:23 -070016958 // to using a DS format, then cause it to hit error due to COLOR_BIT not
16959 // set in aspect
Tobin Ehlisa1c28562015-10-23 16:00:08 -060016960 // The image format check comes 2nd in validation so we trigger it first,
16961 // then when we cause aspect fail next, bad format check will be preempted
Karl Schultz6addd812016-02-02 17:17:23 -070016962 VkResult err;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060016963
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016964 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
16965 "Combination depth/stencil image formats can have only the ");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060016966
Tobin Ehlisa1c28562015-10-23 16:00:08 -060016967 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060016968
Chia-I Wu1b99bb22015-10-27 19:25:11 +080016969 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -070016970 ds_type_count.type = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE;
16971 ds_type_count.descriptorCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060016972
16973 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070016974 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
16975 ds_pool_ci.pNext = NULL;
16976 ds_pool_ci.maxSets = 1;
16977 ds_pool_ci.poolSizeCount = 1;
16978 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060016979
16980 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016981 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060016982 ASSERT_VK_SUCCESS(err);
16983
16984 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -070016985 dsl_binding.binding = 0;
16986 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE;
16987 dsl_binding.descriptorCount = 1;
16988 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
16989 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060016990
16991 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070016992 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
16993 ds_layout_ci.pNext = NULL;
16994 ds_layout_ci.bindingCount = 1;
16995 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060016996 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016997 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060016998 ASSERT_VK_SUCCESS(err);
16999
17000 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080017001 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +080017002 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -070017003 alloc_info.descriptorSetCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060017004 alloc_info.descriptorPool = ds_pool;
17005 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017006 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060017007 ASSERT_VK_SUCCESS(err);
17008
Karl Schultz6addd812016-02-02 17:17:23 -070017009 VkImage image_bad;
17010 VkImage image_good;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060017011 // One bad format and one good format for Color attachment
Tobin Ehlis269f0322016-05-25 16:24:21 -060017012 const VkFormat tex_format_bad = VK_FORMAT_D24_UNORM_S8_UINT;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060017013 const VkFormat tex_format_good = VK_FORMAT_B8G8R8A8_UNORM;
Karl Schultz6addd812016-02-02 17:17:23 -070017014 const int32_t tex_width = 32;
17015 const int32_t tex_height = 32;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060017016
17017 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070017018 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
17019 image_create_info.pNext = NULL;
17020 image_create_info.imageType = VK_IMAGE_TYPE_2D;
17021 image_create_info.format = tex_format_bad;
17022 image_create_info.extent.width = tex_width;
17023 image_create_info.extent.height = tex_height;
17024 image_create_info.extent.depth = 1;
17025 image_create_info.mipLevels = 1;
17026 image_create_info.arrayLayers = 1;
17027 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
17028 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017029 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT | VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT;
Karl Schultz6addd812016-02-02 17:17:23 -070017030 image_create_info.flags = 0;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060017031
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017032 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image_bad);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060017033 ASSERT_VK_SUCCESS(err);
17034 image_create_info.format = tex_format_good;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017035 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
17036 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image_good);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060017037 ASSERT_VK_SUCCESS(err);
17038
17039 VkImageViewCreateInfo image_view_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070017040 image_view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
17041 image_view_create_info.image = image_bad;
17042 image_view_create_info.viewType = VK_IMAGE_VIEW_TYPE_2D;
17043 image_view_create_info.format = tex_format_bad;
17044 image_view_create_info.subresourceRange.baseArrayLayer = 0;
17045 image_view_create_info.subresourceRange.baseMipLevel = 0;
17046 image_view_create_info.subresourceRange.layerCount = 1;
17047 image_view_create_info.subresourceRange.levelCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017048 image_view_create_info.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060017049
17050 VkImageView view;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017051 err = vkCreateImageView(m_device->device(), &image_view_create_info, NULL, &view);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060017052
Chris Forbes8f36a8a2016-04-07 13:21:07 +120017053 m_errorMonitor->VerifyFound();
Tobin Ehlisa1c28562015-10-23 16:00:08 -060017054
Chia-I Wuf7458c52015-10-26 21:10:41 +080017055 vkDestroyImage(m_device->device(), image_bad, NULL);
17056 vkDestroyImage(m_device->device(), image_good, NULL);
Chia-I Wuf7458c52015-10-26 21:10:41 +080017057 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
17058 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060017059}
Tobin Ehlis6e23d772016-05-19 11:08:34 -060017060
17061TEST_F(VkLayerTest, ClearImageErrors) {
17062 TEST_DESCRIPTION("Call ClearColorImage w/ a depth|stencil image and "
17063 "ClearDepthStencilImage with a color image.");
17064
17065 ASSERT_NO_FATAL_FAILURE(InitState());
17066 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
17067
17068 // Renderpass is started here so end it as Clear cmds can't be in renderpass
17069 BeginCommandBuffer();
17070 m_commandBuffer->EndRenderPass();
17071
17072 // Color image
17073 VkClearColorValue clear_color;
17074 memset(clear_color.uint32, 0, sizeof(uint32_t) * 4);
17075 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
17076 const VkFormat color_format = VK_FORMAT_B8G8R8A8_UNORM;
17077 const int32_t img_width = 32;
17078 const int32_t img_height = 32;
17079 VkImageCreateInfo image_create_info = {};
17080 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
17081 image_create_info.pNext = NULL;
17082 image_create_info.imageType = VK_IMAGE_TYPE_2D;
17083 image_create_info.format = color_format;
17084 image_create_info.extent.width = img_width;
17085 image_create_info.extent.height = img_height;
17086 image_create_info.extent.depth = 1;
17087 image_create_info.mipLevels = 1;
17088 image_create_info.arrayLayers = 1;
17089 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
17090 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
17091 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
17092
17093 vk_testing::Image color_image;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017094 color_image.init(*m_device, (const VkImageCreateInfo &)image_create_info, reqs);
Tobin Ehlis6e23d772016-05-19 11:08:34 -060017095
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017096 const VkImageSubresourceRange color_range = vk_testing::Image::subresource_range(image_create_info, VK_IMAGE_ASPECT_COLOR_BIT);
Tobin Ehlis6e23d772016-05-19 11:08:34 -060017097
17098 // Depth/Stencil image
17099 VkClearDepthStencilValue clear_value = {0};
17100 reqs = 0; // don't need HOST_VISIBLE DS image
17101 VkImageCreateInfo ds_image_create_info = vk_testing::Image::create_info();
17102 ds_image_create_info.imageType = VK_IMAGE_TYPE_2D;
17103 ds_image_create_info.format = VK_FORMAT_D24_UNORM_S8_UINT;
17104 ds_image_create_info.extent.width = 64;
17105 ds_image_create_info.extent.height = 64;
17106 ds_image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
17107 ds_image_create_info.usage = VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT;
17108
17109 vk_testing::Image ds_image;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017110 ds_image.init(*m_device, (const VkImageCreateInfo &)ds_image_create_info, reqs);
Tobin Ehlis6e23d772016-05-19 11:08:34 -060017111
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017112 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 -060017113
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017114 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "vkCmdClearColorImage called with depth/stencil image.");
Tobin Ehlis6e23d772016-05-19 11:08:34 -060017115
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017116 vkCmdClearColorImage(m_commandBuffer->GetBufferHandle(), ds_image.handle(), VK_IMAGE_LAYOUT_GENERAL, &clear_color, 1,
Tobin Ehlis6e23d772016-05-19 11:08:34 -060017117 &color_range);
17118
17119 m_errorMonitor->VerifyFound();
17120
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017121 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "vkCmdClearColorImage called with "
17122 "image created without "
17123 "VK_IMAGE_USAGE_TRANSFER_DST_BIT");
Tony Barbour26434b92016-06-02 09:43:50 -060017124
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017125 vkCmdClearColorImage(m_commandBuffer->GetBufferHandle(), ds_image.handle(), VK_IMAGE_LAYOUT_GENERAL, &clear_color, 1,
Tony Barbour26434b92016-06-02 09:43:50 -060017126 &color_range);
17127
17128 m_errorMonitor->VerifyFound();
17129
Tobin Ehlis6e23d772016-05-19 11:08:34 -060017130 // Call CmdClearDepthStencilImage with color image
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017131 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
17132 "vkCmdClearDepthStencilImage called without a depth/stencil image.");
Tobin Ehlis6e23d772016-05-19 11:08:34 -060017133
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017134 vkCmdClearDepthStencilImage(m_commandBuffer->GetBufferHandle(), color_image.handle(),
17135 VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL, &clear_value, 1, &ds_range);
Tobin Ehlis6e23d772016-05-19 11:08:34 -060017136
17137 m_errorMonitor->VerifyFound();
17138}
Tobin Ehliscde08892015-09-22 10:11:37 -060017139#endif // IMAGE_TESTS
17140
Cody Northrop1242dfd2016-07-13 17:24:59 -060017141#if defined(ANDROID) && defined(VALIDATION_APK)
17142static bool initialized = false;
17143static bool active = false;
17144
17145// Convert Intents to argv
17146// Ported from Hologram sample, only difference is flexible key
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017147std::vector<std::string> get_args(android_app &app, const char *intent_extra_data_key) {
Cody Northrop1242dfd2016-07-13 17:24:59 -060017148 std::vector<std::string> args;
17149 JavaVM &vm = *app.activity->vm;
17150 JNIEnv *p_env;
17151 if (vm.AttachCurrentThread(&p_env, nullptr) != JNI_OK)
17152 return args;
17153
17154 JNIEnv &env = *p_env;
17155 jobject activity = app.activity->clazz;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017156 jmethodID get_intent_method = env.GetMethodID(env.GetObjectClass(activity), "getIntent", "()Landroid/content/Intent;");
Cody Northrop1242dfd2016-07-13 17:24:59 -060017157 jobject intent = env.CallObjectMethod(activity, get_intent_method);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017158 jmethodID get_string_extra_method =
17159 env.GetMethodID(env.GetObjectClass(intent), "getStringExtra", "(Ljava/lang/String;)Ljava/lang/String;");
Cody Northrop1242dfd2016-07-13 17:24:59 -060017160 jvalue get_string_extra_args;
17161 get_string_extra_args.l = env.NewStringUTF(intent_extra_data_key);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017162 jstring extra_str = static_cast<jstring>(env.CallObjectMethodA(intent, get_string_extra_method, &get_string_extra_args));
Cody Northrop1242dfd2016-07-13 17:24:59 -060017163
17164 std::string args_str;
17165 if (extra_str) {
17166 const char *extra_utf = env.GetStringUTFChars(extra_str, nullptr);
17167 args_str = extra_utf;
17168 env.ReleaseStringUTFChars(extra_str, extra_utf);
17169 env.DeleteLocalRef(extra_str);
17170 }
17171
17172 env.DeleteLocalRef(get_string_extra_args.l);
17173 env.DeleteLocalRef(intent);
17174 vm.DetachCurrentThread();
17175
17176 // split args_str
17177 std::stringstream ss(args_str);
17178 std::string arg;
17179 while (std::getline(ss, arg, ' ')) {
17180 if (!arg.empty())
17181 args.push_back(arg);
17182 }
17183
17184 return args;
17185}
17186
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017187static int32_t processInput(struct android_app *app, AInputEvent *event) { return 0; }
Cody Northrop1242dfd2016-07-13 17:24:59 -060017188
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017189static void processCommand(struct android_app *app, int32_t cmd) {
17190 switch (cmd) {
17191 case APP_CMD_INIT_WINDOW: {
17192 if (app->window) {
17193 initialized = true;
Cody Northrop1242dfd2016-07-13 17:24:59 -060017194 }
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017195 break;
17196 }
17197 case APP_CMD_GAINED_FOCUS: {
17198 active = true;
17199 break;
17200 }
17201 case APP_CMD_LOST_FOCUS: {
17202 active = false;
17203 break;
17204 }
Cody Northrop1242dfd2016-07-13 17:24:59 -060017205 }
17206}
17207
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017208void android_main(struct android_app *app) {
Cody Northrop1242dfd2016-07-13 17:24:59 -060017209 app_dummy();
17210
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017211 const char *appTag = "VulkanLayerValidationTests";
Cody Northrop1242dfd2016-07-13 17:24:59 -060017212
17213 int vulkanSupport = InitVulkan();
17214 if (vulkanSupport == 0) {
17215 __android_log_print(ANDROID_LOG_INFO, appTag, "==== FAILED ==== No Vulkan support found");
17216 return;
17217 }
17218
17219 app->onAppCmd = processCommand;
17220 app->onInputEvent = processInput;
17221
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017222 while (1) {
Cody Northrop1242dfd2016-07-13 17:24:59 -060017223 int events;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017224 struct android_poll_source *source;
17225 while (ALooper_pollAll(active ? 0 : -1, NULL, &events, (void **)&source) >= 0) {
Cody Northrop1242dfd2016-07-13 17:24:59 -060017226 if (source) {
17227 source->process(app, source);
17228 }
17229
17230 if (app->destroyRequested != 0) {
17231 VkTestFramework::Finish();
17232 return;
17233 }
17234 }
17235
17236 if (initialized && active) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017237 // Use the following key to send arguments to gtest, i.e.
17238 // --es args "--gtest_filter=-VkLayerTest.foo"
17239 const char key[] = "args";
17240 std::vector<std::string> args = get_args(*app, key);
Cody Northrop1242dfd2016-07-13 17:24:59 -060017241
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017242 std::string filter = "";
17243 if (args.size() > 0) {
17244 __android_log_print(ANDROID_LOG_INFO, appTag, "Intent args = %s", args[0].c_str());
17245 filter += args[0];
17246 } else {
17247 __android_log_print(ANDROID_LOG_INFO, appTag, "No Intent args detected");
17248 }
Cody Northrop1242dfd2016-07-13 17:24:59 -060017249
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017250 int argc = 2;
17251 char *argv[] = {(char *)"foo", (char *)filter.c_str()};
17252 __android_log_print(ANDROID_LOG_DEBUG, appTag, "filter = %s", argv[1]);
Cody Northrop1242dfd2016-07-13 17:24:59 -060017253
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017254 // Route output to files until we can override the gtest output
17255 freopen("/sdcard/Android/data/com.example.VulkanLayerValidationTests/files/out.txt", "w", stdout);
17256 freopen("/sdcard/Android/data/com.example.VulkanLayerValidationTests/files/err.txt", "w", stderr);
Cody Northrop1242dfd2016-07-13 17:24:59 -060017257
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017258 ::testing::InitGoogleTest(&argc, argv);
17259 VkTestFramework::InitArgs(&argc, argv);
17260 ::testing::AddGlobalTestEnvironment(new TestEnvironment);
Cody Northrop1242dfd2016-07-13 17:24:59 -060017261
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017262 int result = RUN_ALL_TESTS();
Cody Northrop1242dfd2016-07-13 17:24:59 -060017263
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017264 if (result != 0) {
17265 __android_log_print(ANDROID_LOG_INFO, appTag, "==== Tests FAILED ====");
17266 } else {
17267 __android_log_print(ANDROID_LOG_INFO, appTag, "==== Tests PASSED ====");
17268 }
Cody Northrop1242dfd2016-07-13 17:24:59 -060017269
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017270 VkTestFramework::Finish();
Cody Northrop1242dfd2016-07-13 17:24:59 -060017271
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017272 fclose(stdout);
17273 fclose(stderr);
Cody Northrop1242dfd2016-07-13 17:24:59 -060017274
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017275 ANativeActivity_finish(app->activity);
Cody Northrop1242dfd2016-07-13 17:24:59 -060017276
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017277 return;
Cody Northrop1242dfd2016-07-13 17:24:59 -060017278 }
17279 }
17280}
17281#endif
17282
Tony Barbour300a6082015-04-07 13:44:53 -060017283int main(int argc, char **argv) {
17284 int result;
17285
Cody Northrop8e54a402016-03-08 22:25:52 -070017286#ifdef ANDROID
17287 int vulkanSupport = InitVulkan();
17288 if (vulkanSupport == 0)
17289 return 1;
17290#endif
17291
Tony Barbour300a6082015-04-07 13:44:53 -060017292 ::testing::InitGoogleTest(&argc, argv);
Tony Barbour6918cd52015-04-09 12:58:51 -060017293 VkTestFramework::InitArgs(&argc, argv);
Tony Barbour300a6082015-04-07 13:44:53 -060017294
17295 ::testing::AddGlobalTestEnvironment(new TestEnvironment);
17296
17297 result = RUN_ALL_TESTS();
17298
Tony Barbour6918cd52015-04-09 12:58:51 -060017299 VkTestFramework::Finish();
Tony Barbour300a6082015-04-07 13:44:53 -060017300 return result;
17301}