blob: 987c4f18d547b98eaeae3d1064f7e25476c70c51 [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);
Tobin Ehlisd332f282015-10-02 11:00:56 -0600418 m_viewports.clear();
419 m_scissors.clear();
Courtney Goeltzenleuchter507ba972015-09-30 16:16:57 -0600420 }
421 if (failMask & BsoFailScissor) {
422 pipelineobj.MakeDynamic(VK_DYNAMIC_STATE_SCISSOR);
Tobin Ehlisd332f282015-10-02 11:00:56 -0600423 m_scissors.clear();
424 m_viewports.clear();
Courtney Goeltzenleuchter507ba972015-09-30 16:16:57 -0600425 }
426 if (failMask & BsoFailBlend) {
427 pipelineobj.MakeDynamic(VK_DYNAMIC_STATE_BLEND_CONSTANTS);
Tobin Ehlis7a1d2352016-03-28 11:18:19 -0600428 VkPipelineColorBlendAttachmentState att_state = {};
429 att_state.dstAlphaBlendFactor = VK_BLEND_FACTOR_CONSTANT_COLOR;
430 att_state.blendEnable = VK_TRUE;
431 pipelineobj.AddColorAttachment(0, &att_state);
Courtney Goeltzenleuchter507ba972015-09-30 16:16:57 -0600432 }
433 if (failMask & BsoFailDepthBounds) {
434 pipelineobj.MakeDynamic(VK_DYNAMIC_STATE_DEPTH_BOUNDS);
435 }
436 if (failMask & BsoFailStencilReadMask) {
437 pipelineobj.MakeDynamic(VK_DYNAMIC_STATE_STENCIL_COMPARE_MASK);
438 }
439 if (failMask & BsoFailStencilWriteMask) {
440 pipelineobj.MakeDynamic(VK_DYNAMIC_STATE_STENCIL_WRITE_MASK);
441 }
442 if (failMask & BsoFailStencilReference) {
443 pipelineobj.MakeDynamic(VK_DYNAMIC_STATE_STENCIL_REFERENCE);
444 }
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500445
446 VkDescriptorSetObj descriptorSet(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600447 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, constantBuffer);
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500448
449 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barbourfe3351b2015-07-28 10:17:20 -0600450 ASSERT_VK_SUCCESS(BeginCommandBuffer());
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500451
Tony Barbourfe3351b2015-07-28 10:17:20 -0600452 GenericDrawPreparation(pipelineobj, descriptorSet, failMask);
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500453
454 // render triangle
Tobin Ehlis379ba3b2016-07-19 11:22:29 -0600455 if (failMask & BsoFailIndexBuffer) {
456 // Use DrawIndexed w/o an index buffer bound
457 DrawIndexed(3, 1, 0, 0, 0);
458 } else {
459 Draw(3, 1, 0, 0);
460 }
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500461
Mark Muellerd4914412016-06-13 17:52:06 -0600462 if (failMask & BsoFailCmdClearAttachments) {
463 VkClearAttachment color_attachment = {};
464 color_attachment.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
465 color_attachment.colorAttachment = 1; // Someone who knew what they were doing would use 0 for the index;
466 VkClearRect clear_rect = {{{0, 0}, {static_cast<uint32_t>(m_width), static_cast<uint32_t>(m_height)}}, 0, 0};
467
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600468 vkCmdClearAttachments(m_commandBuffer->GetBufferHandle(), 1, &color_attachment, 1, &clear_rect);
Mark Muellerd4914412016-06-13 17:52:06 -0600469 }
470
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500471 // finalize recording of the command buffer
Tony Barbourfe3351b2015-07-28 10:17:20 -0600472 EndCommandBuffer();
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500473
Tony Barbourfe3351b2015-07-28 10:17:20 -0600474 QueueCommandBuffer();
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500475}
476
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600477void VkLayerTest::GenericDrawPreparation(VkCommandBufferObj *commandBuffer, VkPipelineObj &pipelineobj,
478 VkDescriptorSetObj &descriptorSet, BsoFailSelect failMask) {
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500479 if (m_depthStencil->Initialized()) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600480 commandBuffer->ClearAllBuffers(m_clear_color, m_depth_clear_color, m_stencil_clear_color, m_depthStencil);
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500481 } else {
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600482 commandBuffer->ClearAllBuffers(m_clear_color, m_depth_clear_color, m_stencil_clear_color, NULL);
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500483 }
484
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800485 commandBuffer->PrepareAttachments();
Karl Schultz6addd812016-02-02 17:17:23 -0700486 // Make sure depthWriteEnable is set so that Depth fail test will work
487 // correctly
488 // Make sure stencilTestEnable is set so that Stencil fail test will work
489 // correctly
Tony Barboureb254902015-07-15 12:50:33 -0600490 VkStencilOpState stencil = {};
Chia-I Wu1b99bb22015-10-27 19:25:11 +0800491 stencil.failOp = VK_STENCIL_OP_KEEP;
492 stencil.passOp = VK_STENCIL_OP_KEEP;
493 stencil.depthFailOp = VK_STENCIL_OP_KEEP;
494 stencil.compareOp = VK_COMPARE_OP_NEVER;
Tony Barboureb254902015-07-15 12:50:33 -0600495
496 VkPipelineDepthStencilStateCreateInfo ds_ci = {};
497 ds_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_DEPTH_STENCIL_STATE_CREATE_INFO;
Courtney Goeltzenleuchter507ba972015-09-30 16:16:57 -0600498 ds_ci.pNext = NULL;
499 ds_ci.depthTestEnable = VK_FALSE;
500 ds_ci.depthWriteEnable = VK_TRUE;
501 ds_ci.depthCompareOp = VK_COMPARE_OP_NEVER;
502 ds_ci.depthBoundsTestEnable = VK_FALSE;
Tobin Ehlis7a1d2352016-03-28 11:18:19 -0600503 if (failMask & BsoFailDepthBounds) {
504 ds_ci.depthBoundsTestEnable = VK_TRUE;
Tobin Ehlis21c88352016-05-26 06:15:45 -0600505 ds_ci.maxDepthBounds = 0.0f;
506 ds_ci.minDepthBounds = 0.0f;
Tobin Ehlis7a1d2352016-03-28 11:18:19 -0600507 }
Courtney Goeltzenleuchter507ba972015-09-30 16:16:57 -0600508 ds_ci.stencilTestEnable = VK_TRUE;
509 ds_ci.front = stencil;
510 ds_ci.back = stencil;
Tony Barboureb254902015-07-15 12:50:33 -0600511
Tobin Ehlis4bf96d12015-06-25 11:58:41 -0600512 pipelineobj.SetDepthStencil(&ds_ci);
Tobin Ehlisd332f282015-10-02 11:00:56 -0600513 pipelineobj.SetViewport(m_viewports);
514 pipelineobj.SetScissor(m_scissors);
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800515 descriptorSet.CreateVKDescriptorSet(commandBuffer);
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600516 VkResult err = pipelineobj.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Cody Northrop29a08f22015-08-27 10:20:35 -0600517 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800518 commandBuffer->BindPipeline(pipelineobj);
519 commandBuffer->BindDescriptorSet(descriptorSet);
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500520}
521
Ian Elliott2c1daf52016-05-12 09:41:46 -0600522class VkWsiEnabledLayerTest : public VkLayerTest {
523 public:
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600524 protected:
525 VkWsiEnabledLayerTest() { m_enableWSI = true; }
Ian Elliott2c1daf52016-05-12 09:41:46 -0600526};
527
Mark Muellerdfe37552016-07-07 14:47:42 -0600528class VkBufferTest {
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600529 public:
Mark Muellerdfe37552016-07-07 14:47:42 -0600530 enum eTestEnFlags {
531 eDoubleDelete,
532 eInvalidDeviceOffset,
533 eInvalidMemoryOffset,
534 eBindNullBuffer,
535 eFreeInvalidHandle,
Mark Mueller4042b652016-09-05 22:52:21 -0600536 eNone,
Mark Muellerdfe37552016-07-07 14:47:42 -0600537 };
538
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600539 enum eTestConditions { eOffsetAlignment = 1 };
Mark Muellerdfe37552016-07-07 14:47:42 -0600540
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600541 static bool GetTestConditionValid(VkDeviceObj *aVulkanDevice, eTestEnFlags aTestFlag, VkBufferUsageFlags aBufferUsage = 0) {
542 if (eInvalidDeviceOffset != aTestFlag && eInvalidMemoryOffset != aTestFlag) {
Mark Muellerdfe37552016-07-07 14:47:42 -0600543 return true;
544 }
545 VkDeviceSize offset_limit = 0;
546 if (eInvalidMemoryOffset == aTestFlag) {
547 VkBuffer vulkanBuffer;
548 VkBufferCreateInfo buffer_create_info = {};
549 buffer_create_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
550 buffer_create_info.size = 32;
551 buffer_create_info.usage = aBufferUsage;
552
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600553 vkCreateBuffer(aVulkanDevice->device(), &buffer_create_info, nullptr, &vulkanBuffer);
Mark Mueller4042b652016-09-05 22:52:21 -0600554 VkMemoryRequirements memory_reqs = {};
Mark Muellerdfe37552016-07-07 14:47:42 -0600555
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600556 vkGetBufferMemoryRequirements(aVulkanDevice->device(), vulkanBuffer, &memory_reqs);
Mark Muellerdfe37552016-07-07 14:47:42 -0600557 vkDestroyBuffer(aVulkanDevice->device(), vulkanBuffer, nullptr);
558 offset_limit = memory_reqs.alignment;
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600559 } else if ((VK_BUFFER_USAGE_UNIFORM_TEXEL_BUFFER_BIT | VK_BUFFER_USAGE_STORAGE_TEXEL_BUFFER_BIT) & aBufferUsage) {
560 offset_limit = aVulkanDevice->props.limits.minTexelBufferOffsetAlignment;
Mark Muellerdfe37552016-07-07 14:47:42 -0600561 } else if (VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT & aBufferUsage) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600562 offset_limit = aVulkanDevice->props.limits.minUniformBufferOffsetAlignment;
Mark Muellerdfe37552016-07-07 14:47:42 -0600563 } else if (VK_BUFFER_USAGE_STORAGE_BUFFER_BIT & aBufferUsage) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600564 offset_limit = aVulkanDevice->props.limits.minStorageBufferOffsetAlignment;
Mark Muellerdfe37552016-07-07 14:47:42 -0600565 }
566 if (eOffsetAlignment < offset_limit) {
567 return true;
568 }
569 return false;
570 }
571
572 // A constructor which performs validation tests within construction.
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600573 VkBufferTest(VkDeviceObj *aVulkanDevice, VkBufferUsageFlags aBufferUsage, eTestEnFlags aTestFlag = eNone)
574 : AllocateCurrent(false), BoundCurrent(false), CreateCurrent(false), VulkanDevice(aVulkanDevice->device()) {
Mark Muellerdfe37552016-07-07 14:47:42 -0600575
576 if (eBindNullBuffer == aTestFlag) {
577 VulkanMemory = 0;
578 vkBindBufferMemory(VulkanDevice, VulkanBuffer, VulkanMemory, 0);
579 } else {
580 VkBufferCreateInfo buffer_create_info = {};
581 buffer_create_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
582 buffer_create_info.size = 32;
583 buffer_create_info.usage = aBufferUsage;
584
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600585 vkCreateBuffer(VulkanDevice, &buffer_create_info, nullptr, &VulkanBuffer);
Mark Muellerdfe37552016-07-07 14:47:42 -0600586
587 CreateCurrent = true;
588
589 VkMemoryRequirements memory_requirements;
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600590 vkGetBufferMemoryRequirements(VulkanDevice, VulkanBuffer, &memory_requirements);
Mark Muellerdfe37552016-07-07 14:47:42 -0600591
592 VkMemoryAllocateInfo memory_allocate_info = {};
593 memory_allocate_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
594 memory_allocate_info.allocationSize = memory_requirements.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600595 bool pass = aVulkanDevice->phy().set_memory_type(memory_requirements.memoryTypeBits, &memory_allocate_info,
596 VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT);
Mark Muellerdfe37552016-07-07 14:47:42 -0600597 if (!pass) {
598 vkDestroyBuffer(VulkanDevice, VulkanBuffer, nullptr);
599 return;
600 }
601
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600602 vkAllocateMemory(VulkanDevice, &memory_allocate_info, NULL, &VulkanMemory);
Mark Muellerdfe37552016-07-07 14:47:42 -0600603 AllocateCurrent = true;
604 // NB: 1 is intentionally an invalid offset value
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600605 const bool offset_en = eInvalidDeviceOffset == aTestFlag || eInvalidMemoryOffset == aTestFlag;
606 vkBindBufferMemory(VulkanDevice, VulkanBuffer, VulkanMemory, offset_en ? eOffsetAlignment : 0);
Mark Muellerdfe37552016-07-07 14:47:42 -0600607 BoundCurrent = true;
608
609 InvalidDeleteEn = (eFreeInvalidHandle == aTestFlag);
610 }
611 }
612
613 ~VkBufferTest() {
614 if (CreateCurrent) {
615 vkDestroyBuffer(VulkanDevice, VulkanBuffer, nullptr);
616 }
617 if (AllocateCurrent) {
618 if (InvalidDeleteEn) {
619 union {
620 VkDeviceMemory device_memory;
621 unsigned long long index_access;
622 } bad_index;
623
624 bad_index.device_memory = VulkanMemory;
625 bad_index.index_access++;
626
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600627 vkFreeMemory(VulkanDevice, bad_index.device_memory, nullptr);
Mark Muellerdfe37552016-07-07 14:47:42 -0600628 }
629 vkFreeMemory(VulkanDevice, VulkanMemory, nullptr);
630 }
631 }
632
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600633 bool GetBufferCurrent() { return AllocateCurrent && BoundCurrent && CreateCurrent; }
Mark Muellerdfe37552016-07-07 14:47:42 -0600634
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600635 const VkBuffer &GetBuffer() { return VulkanBuffer; }
Mark Muellerdfe37552016-07-07 14:47:42 -0600636
637 void TestDoubleDestroy() {
638 // Destroy the buffer but leave the flag set, which will cause
639 // the buffer to be destroyed again in the destructor.
640 vkDestroyBuffer(VulkanDevice, VulkanBuffer, nullptr);
641 }
642
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600643 protected:
Mark Muellerdfe37552016-07-07 14:47:42 -0600644 bool AllocateCurrent;
645 bool BoundCurrent;
646 bool CreateCurrent;
647 bool InvalidDeleteEn;
648
649 VkBuffer VulkanBuffer;
650 VkDevice VulkanDevice;
651 VkDeviceMemory VulkanMemory;
Mark Muellerdfe37552016-07-07 14:47:42 -0600652};
653
654class VkVerticesObj {
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600655 public:
656 VkVerticesObj(VkDeviceObj *aVulkanDevice, unsigned aAttributeCount, unsigned aBindingCount, unsigned aByteStride,
Mark Muellerdfe37552016-07-07 14:47:42 -0600657 VkDeviceSize aVertexCount, const float *aVerticies)
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600658 : BoundCurrent(false), AttributeCount(aAttributeCount), BindingCount(aBindingCount), BindId(BindIdGenerator),
Mark Muellerdfe37552016-07-07 14:47:42 -0600659 PipelineVertexInputStateCreateInfo(),
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600660 VulkanMemoryBuffer(aVulkanDevice, 1, static_cast<int>(aByteStride * aVertexCount),
661 reinterpret_cast<const void *>(aVerticies), VK_BUFFER_USAGE_VERTEX_BUFFER_BIT) {
Mark Muellerdfe37552016-07-07 14:47:42 -0600662 BindIdGenerator++; // NB: This can wrap w/misuse
663
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600664 VertexInputAttributeDescription = new VkVertexInputAttributeDescription[AttributeCount];
665 VertexInputBindingDescription = new VkVertexInputBindingDescription[BindingCount];
Mark Muellerdfe37552016-07-07 14:47:42 -0600666
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600667 PipelineVertexInputStateCreateInfo.pVertexAttributeDescriptions = VertexInputAttributeDescription;
668 PipelineVertexInputStateCreateInfo.vertexAttributeDescriptionCount = AttributeCount;
669 PipelineVertexInputStateCreateInfo.pVertexBindingDescriptions = VertexInputBindingDescription;
670 PipelineVertexInputStateCreateInfo.vertexBindingDescriptionCount = BindingCount;
671 PipelineVertexInputStateCreateInfo.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
Mark Muellerdfe37552016-07-07 14:47:42 -0600672
673 unsigned i = 0;
674 do {
675 VertexInputAttributeDescription[i].binding = BindId;
676 VertexInputAttributeDescription[i].location = i;
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600677 VertexInputAttributeDescription[i].format = VK_FORMAT_R32G32B32_SFLOAT;
678 VertexInputAttributeDescription[i].offset = sizeof(float) * aByteStride;
Mark Muellerdfe37552016-07-07 14:47:42 -0600679 i++;
680 } while (AttributeCount < i);
681
682 i = 0;
683 do {
684 VertexInputBindingDescription[i].binding = BindId;
685 VertexInputBindingDescription[i].stride = aByteStride;
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600686 VertexInputBindingDescription[i].inputRate = VK_VERTEX_INPUT_RATE_VERTEX;
Mark Muellerdfe37552016-07-07 14:47:42 -0600687 i++;
688 } while (BindingCount < i);
689 }
690
691 ~VkVerticesObj() {
692 if (VertexInputAttributeDescription) {
693 delete[] VertexInputAttributeDescription;
694 }
695 if (VertexInputBindingDescription) {
696 delete[] VertexInputBindingDescription;
697 }
698 }
699
700 bool AddVertexInputToPipe(VkPipelineObj &aPipelineObj) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600701 aPipelineObj.AddVertexInputAttribs(VertexInputAttributeDescription, AttributeCount);
702 aPipelineObj.AddVertexInputBindings(VertexInputBindingDescription, BindingCount);
Mark Muellerdfe37552016-07-07 14:47:42 -0600703 return true;
704 }
705
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600706 void BindVertexBuffers(VkCommandBuffer aCommandBuffer, unsigned aOffsetCount = 0, VkDeviceSize *aOffsetList = nullptr) {
Mark Muellerdfe37552016-07-07 14:47:42 -0600707 VkDeviceSize *offsetList;
708 unsigned offsetCount;
709
710 if (aOffsetCount) {
711 offsetList = aOffsetList;
712 offsetCount = aOffsetCount;
713 } else {
714 offsetList = new VkDeviceSize[1]();
715 offsetCount = 1;
716 }
717
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600718 vkCmdBindVertexBuffers(aCommandBuffer, BindId, offsetCount, &VulkanMemoryBuffer.handle(), offsetList);
Mark Muellerdfe37552016-07-07 14:47:42 -0600719 BoundCurrent = true;
720
721 if (!aOffsetCount) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600722 delete[] offsetList;
Mark Muellerdfe37552016-07-07 14:47:42 -0600723 }
724 }
725
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600726 protected:
Mark Muellerdfe37552016-07-07 14:47:42 -0600727 static uint32_t BindIdGenerator;
728
729 bool BoundCurrent;
730 unsigned AttributeCount;
731 unsigned BindingCount;
732 uint32_t BindId;
733
734 VkPipelineVertexInputStateCreateInfo PipelineVertexInputStateCreateInfo;
735 VkVertexInputAttributeDescription *VertexInputAttributeDescription;
736 VkVertexInputBindingDescription *VertexInputBindingDescription;
737 VkConstantBufferObj VulkanMemoryBuffer;
738};
739
740uint32_t VkVerticesObj::BindIdGenerator;
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500741// ********************************************************************************************************************
742// ********************************************************************************************************************
743// ********************************************************************************************************************
744// ********************************************************************************************************************
Dustin Gravesffa90fa2016-05-06 11:20:38 -0600745#if PARAMETER_VALIDATION_TESTS
746TEST_F(VkLayerTest, RequiredParameter) {
747 TEST_DESCRIPTION("Specify VK_NULL_HANDLE, NULL, and 0 for required handle, "
748 "pointer, array, and array count parameters");
749
750 ASSERT_NO_FATAL_FAILURE(InitState());
751
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600752 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "required parameter pFeatures specified as NULL");
Dustin Gravesffa90fa2016-05-06 11:20:38 -0600753 // Specify NULL for a pointer to a handle
754 // Expected to trigger an error with
755 // parameter_validation::validate_required_pointer
756 vkGetPhysicalDeviceFeatures(gpu(), NULL);
757 m_errorMonitor->VerifyFound();
758
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600759 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
760 "required parameter pQueueFamilyPropertyCount specified as NULL");
Dustin Gravesffa90fa2016-05-06 11:20:38 -0600761 // Specify NULL for pointer to array count
762 // Expected to trigger an error with parameter_validation::validate_array
Dustin Gravesa4bb8c12016-05-16 17:22:51 -0600763 vkGetPhysicalDeviceQueueFamilyProperties(gpu(), NULL, NULL);
Dustin Gravesffa90fa2016-05-06 11:20:38 -0600764 m_errorMonitor->VerifyFound();
765
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600766 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "parameter viewportCount must be greater than 0");
Dustin Gravesffa90fa2016-05-06 11:20:38 -0600767 // Specify 0 for a required array count
768 // Expected to trigger an error with parameter_validation::validate_array
769 VkViewport view_port = {};
770 m_commandBuffer->SetViewport(0, 0, &view_port);
771 m_errorMonitor->VerifyFound();
772
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600773 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "required parameter pViewports specified as NULL");
Dustin Gravesffa90fa2016-05-06 11:20:38 -0600774 // Specify NULL for a required array
775 // Expected to trigger an error with parameter_validation::validate_array
776 m_commandBuffer->SetViewport(0, 1, NULL);
777 m_errorMonitor->VerifyFound();
778
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600779 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "required parameter memory specified as VK_NULL_HANDLE");
Dustin Gravesffa90fa2016-05-06 11:20:38 -0600780 // Specify VK_NULL_HANDLE for a required handle
781 // Expected to trigger an error with
782 // parameter_validation::validate_required_handle
783 vkUnmapMemory(device(), VK_NULL_HANDLE);
784 m_errorMonitor->VerifyFound();
785
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600786 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
787 "required parameter pFences[0] specified as VK_NULL_HANDLE");
Dustin Gravesffa90fa2016-05-06 11:20:38 -0600788 // Specify VK_NULL_HANDLE for a required handle array entry
789 // Expected to trigger an error with
790 // parameter_validation::validate_required_handle_array
791 VkFence fence = VK_NULL_HANDLE;
792 vkResetFences(device(), 1, &fence);
793 m_errorMonitor->VerifyFound();
794
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600795 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "required parameter pAllocateInfo specified as NULL");
Dustin Gravesffa90fa2016-05-06 11:20:38 -0600796 // Specify NULL for a required struct pointer
797 // Expected to trigger an error with
798 // parameter_validation::validate_struct_type
799 VkDeviceMemory memory = VK_NULL_HANDLE;
800 vkAllocateMemory(device(), NULL, NULL, &memory);
801 m_errorMonitor->VerifyFound();
802
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600803 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "value of faceMask must not be 0");
Dustin Gravesffa90fa2016-05-06 11:20:38 -0600804 // Specify 0 for a required VkFlags parameter
805 // Expected to trigger an error with parameter_validation::validate_flags
806 m_commandBuffer->SetStencilReference(0, 0);
807 m_errorMonitor->VerifyFound();
808
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600809 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 -0600810 // Specify 0 for a required VkFlags array entry
811 // Expected to trigger an error with
812 // parameter_validation::validate_flags_array
813 VkSemaphore semaphore = VK_NULL_HANDLE;
814 VkPipelineStageFlags stageFlags = 0;
815 VkSubmitInfo submitInfo = {};
816 submitInfo.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
817 submitInfo.waitSemaphoreCount = 1;
818 submitInfo.pWaitSemaphores = &semaphore;
819 submitInfo.pWaitDstStageMask = &stageFlags;
820 vkQueueSubmit(m_device->m_queue, 1, &submitInfo, VK_NULL_HANDLE);
821 m_errorMonitor->VerifyFound();
822}
Dustin Gravesc99cf5a2016-05-09 14:40:29 -0600823
Dustin Gravesfce74c02016-05-10 11:42:58 -0600824TEST_F(VkLayerTest, ReservedParameter) {
825 TEST_DESCRIPTION("Specify a non-zero value for a reserved parameter");
826
827 ASSERT_NO_FATAL_FAILURE(InitState());
828
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600829 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " must be 0");
Dustin Gravesfce74c02016-05-10 11:42:58 -0600830 // Specify 0 for a reserved VkFlags parameter
831 // Expected to trigger an error with
832 // parameter_validation::validate_reserved_flags
833 VkEvent event_handle = VK_NULL_HANDLE;
834 VkEventCreateInfo event_info = {};
835 event_info.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO;
836 event_info.flags = 1;
837 vkCreateEvent(device(), &event_info, NULL, &event_handle);
838 m_errorMonitor->VerifyFound();
839}
840
Dustin Gravesc99cf5a2016-05-09 14:40:29 -0600841TEST_F(VkLayerTest, InvalidStructSType) {
842 TEST_DESCRIPTION("Specify an invalid VkStructureType for a Vulkan "
843 "structure's sType field");
844
845 ASSERT_NO_FATAL_FAILURE(InitState());
846
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600847 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "parameter pAllocateInfo->sType must be");
Dustin Gravesc99cf5a2016-05-09 14:40:29 -0600848 // Zero struct memory, effectively setting sType to
849 // VK_STRUCTURE_TYPE_APPLICATION_INFO
850 // Expected to trigger an error with
851 // parameter_validation::validate_struct_type
852 VkMemoryAllocateInfo alloc_info = {};
853 VkDeviceMemory memory = VK_NULL_HANDLE;
854 vkAllocateMemory(device(), &alloc_info, NULL, &memory);
855 m_errorMonitor->VerifyFound();
856
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600857 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "parameter pSubmits[0].sType must be");
Dustin Gravesc99cf5a2016-05-09 14:40:29 -0600858 // Zero struct memory, effectively setting sType to
859 // VK_STRUCTURE_TYPE_APPLICATION_INFO
860 // Expected to trigger an error with
861 // parameter_validation::validate_struct_type_array
862 VkSubmitInfo submit_info = {};
863 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
864 m_errorMonitor->VerifyFound();
865}
866
867TEST_F(VkLayerTest, InvalidStructPNext) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600868 TEST_DESCRIPTION("Specify an invalid value for a Vulkan structure's pNext field");
Dustin Gravesc99cf5a2016-05-09 14:40:29 -0600869
870 ASSERT_NO_FATAL_FAILURE(InitState());
871
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600872 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT, "value of pCreateInfo->pNext must be NULL");
Dustin Gravesc99cf5a2016-05-09 14:40:29 -0600873 // Set VkMemoryAllocateInfo::pNext to a non-NULL value, when pNext must be
Karl Schultz38b50992016-07-11 16:09:09 -0600874 // NULL.
875 // Need to pick a function that has no allowed pNext structure types.
876 // Expected to trigger an error with
877 // parameter_validation::validate_struct_pnext
878 VkEvent event = VK_NULL_HANDLE;
Karl Schultz70db3902016-07-11 16:22:10 -0600879 VkEventCreateInfo event_alloc_info = {};
Karl Schultz38b50992016-07-11 16:09:09 -0600880 // Zero-initialization will provide the correct sType
881 VkApplicationInfo app_info = {};
882 event_alloc_info.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO;
883 event_alloc_info.pNext = &app_info;
884 vkCreateEvent(device(), &event_alloc_info, NULL, &event);
885 m_errorMonitor->VerifyFound();
886
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600887 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT,
888 " chain includes a structure with unexpected VkStructureType ");
Karl Schultz38b50992016-07-11 16:09:09 -0600889 // Set VkMemoryAllocateInfo::pNext to a non-NULL value, but use
890 // a function that has allowed pNext structure types and specify
891 // a structure type that is not allowed.
Dustin Gravesc99cf5a2016-05-09 14:40:29 -0600892 // Expected to trigger an error with
893 // parameter_validation::validate_struct_pnext
894 VkDeviceMemory memory = VK_NULL_HANDLE;
Dustin Graves47b6cba2016-05-10 17:34:38 -0600895 VkMemoryAllocateInfo memory_alloc_info = {};
896 memory_alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
897 memory_alloc_info.pNext = &app_info;
898 vkAllocateMemory(device(), &memory_alloc_info, NULL, &memory);
Dustin Gravesc99cf5a2016-05-09 14:40:29 -0600899 m_errorMonitor->VerifyFound();
900
Dustin Gravesfd1c8fe2016-07-15 11:40:20 -0600901 // Positive test to check parameter_validation and unique_objects support
902 // for NV_dedicated_allocation
903 uint32_t extension_count = 0;
904 bool supports_nv_dedicated_allocation = false;
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600905 VkResult err = vkEnumerateDeviceExtensionProperties(gpu(), nullptr, &extension_count, nullptr);
Dustin Gravesfd1c8fe2016-07-15 11:40:20 -0600906 ASSERT_VK_SUCCESS(err);
907
908 if (extension_count > 0) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600909 std::vector<VkExtensionProperties> available_extensions(extension_count);
Dustin Gravesfd1c8fe2016-07-15 11:40:20 -0600910
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600911 err = vkEnumerateDeviceExtensionProperties(gpu(), nullptr, &extension_count, &available_extensions[0]);
Dustin Gravesfd1c8fe2016-07-15 11:40:20 -0600912 ASSERT_VK_SUCCESS(err);
913
914 for (const auto &extension_props : available_extensions) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600915 if (strcmp(extension_props.extensionName, VK_NV_DEDICATED_ALLOCATION_EXTENSION_NAME) == 0) {
Dustin Gravesfd1c8fe2016-07-15 11:40:20 -0600916 supports_nv_dedicated_allocation = true;
917 }
918 }
919 }
920
921 if (supports_nv_dedicated_allocation) {
922 m_errorMonitor->ExpectSuccess();
923
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600924 VkDedicatedAllocationBufferCreateInfoNV dedicated_buffer_create_info = {};
925 dedicated_buffer_create_info.sType = VK_STRUCTURE_TYPE_DEDICATED_ALLOCATION_BUFFER_CREATE_INFO_NV;
Dustin Gravesfd1c8fe2016-07-15 11:40:20 -0600926 dedicated_buffer_create_info.pNext = nullptr;
927 dedicated_buffer_create_info.dedicatedAllocation = VK_TRUE;
928
929 uint32_t queue_family_index = 0;
930 VkBufferCreateInfo buffer_create_info = {};
931 buffer_create_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
932 buffer_create_info.pNext = &dedicated_buffer_create_info;
933 buffer_create_info.size = 1024;
934 buffer_create_info.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
935 buffer_create_info.queueFamilyIndexCount = 1;
936 buffer_create_info.pQueueFamilyIndices = &queue_family_index;
937
938 VkBuffer buffer;
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600939 VkResult err = vkCreateBuffer(m_device->device(), &buffer_create_info, NULL, &buffer);
Dustin Gravesfd1c8fe2016-07-15 11:40:20 -0600940 ASSERT_VK_SUCCESS(err);
941
942 VkMemoryRequirements memory_reqs;
943 vkGetBufferMemoryRequirements(m_device->device(), buffer, &memory_reqs);
944
945 VkDedicatedAllocationMemoryAllocateInfoNV dedicated_memory_info = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600946 dedicated_memory_info.sType = VK_STRUCTURE_TYPE_DEDICATED_ALLOCATION_MEMORY_ALLOCATE_INFO_NV;
Dustin Gravesfd1c8fe2016-07-15 11:40:20 -0600947 dedicated_memory_info.pNext = nullptr;
948 dedicated_memory_info.buffer = buffer;
949 dedicated_memory_info.image = VK_NULL_HANDLE;
950
951 VkMemoryAllocateInfo memory_info = {};
952 memory_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
953 memory_info.pNext = &dedicated_memory_info;
954 memory_info.allocationSize = memory_reqs.size;
955
956 bool pass;
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600957 pass = m_device->phy().set_memory_type(memory_reqs.memoryTypeBits, &memory_info, 0);
Dustin Gravesfd1c8fe2016-07-15 11:40:20 -0600958 ASSERT_TRUE(pass);
959
960 VkDeviceMemory buffer_memory;
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600961 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &buffer_memory);
Dustin Gravesfd1c8fe2016-07-15 11:40:20 -0600962 ASSERT_VK_SUCCESS(err);
963
964 err = vkBindBufferMemory(m_device->device(), buffer, buffer_memory, 0);
965 ASSERT_VK_SUCCESS(err);
966
967 vkDestroyBuffer(m_device->device(), buffer, NULL);
968 vkFreeMemory(m_device->device(), buffer_memory, NULL);
969
970 m_errorMonitor->VerifyNotFound();
971 }
Dustin Gravesc99cf5a2016-05-09 14:40:29 -0600972}
Dustin Graves5d33d532016-05-09 16:21:12 -0600973
974TEST_F(VkLayerTest, UnrecognizedValue) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600975 TEST_DESCRIPTION("Specify unrecognized Vulkan enumeration, flags, and VkBool32 values");
Dustin Graves5d33d532016-05-09 16:21:12 -0600976
977 ASSERT_NO_FATAL_FAILURE(InitState());
978
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600979 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "does not fall within the begin..end "
980 "range of the core VkFormat "
981 "enumeration tokens");
Dustin Graves5d33d532016-05-09 16:21:12 -0600982 // Specify an invalid VkFormat value
983 // Expected to trigger an error with
984 // parameter_validation::validate_ranged_enum
985 VkFormatProperties format_properties;
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600986 vkGetPhysicalDeviceFormatProperties(gpu(), static_cast<VkFormat>(8000), &format_properties);
Dustin Graves5d33d532016-05-09 16:21:12 -0600987 m_errorMonitor->VerifyFound();
988
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600989 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 -0600990 // Specify an invalid VkFlags bitmask value
991 // Expected to trigger an error with parameter_validation::validate_flags
992 VkImageFormatProperties image_format_properties;
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600993 vkGetPhysicalDeviceImageFormatProperties(gpu(), VK_FORMAT_R8G8B8A8_UNORM, VK_IMAGE_TYPE_2D, VK_IMAGE_TILING_OPTIMAL,
994 static_cast<VkImageUsageFlags>(1 << 25), 0, &image_format_properties);
Dustin Graves5d33d532016-05-09 16:21:12 -0600995 m_errorMonitor->VerifyFound();
996
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600997 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 -0600998 // Specify an invalid VkFlags array entry
999 // Expected to trigger an error with
1000 // parameter_validation::validate_flags_array
1001 VkSemaphore semaphore = VK_NULL_HANDLE;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001002 VkPipelineStageFlags stage_flags = static_cast<VkPipelineStageFlags>(1 << 25);
Dustin Graves5d33d532016-05-09 16:21:12 -06001003 VkSubmitInfo submit_info = {};
1004 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
1005 submit_info.waitSemaphoreCount = 1;
1006 submit_info.pWaitSemaphores = &semaphore;
1007 submit_info.pWaitDstStageMask = &stage_flags;
1008 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
1009 m_errorMonitor->VerifyFound();
1010
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001011 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT, "is neither VK_TRUE nor VK_FALSE");
Dustin Graves5d33d532016-05-09 16:21:12 -06001012 // Specify an invalid VkBool32 value
1013 // Expected to trigger a warning with
1014 // parameter_validation::validate_bool32
1015 VkSampler sampler = VK_NULL_HANDLE;
1016 VkSamplerCreateInfo sampler_info = {};
1017 sampler_info.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
1018 sampler_info.pNext = NULL;
1019 sampler_info.magFilter = VK_FILTER_NEAREST;
1020 sampler_info.minFilter = VK_FILTER_NEAREST;
1021 sampler_info.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
1022 sampler_info.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
1023 sampler_info.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
1024 sampler_info.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
1025 sampler_info.mipLodBias = 1.0;
1026 sampler_info.maxAnisotropy = 1;
1027 sampler_info.compareEnable = VK_FALSE;
1028 sampler_info.compareOp = VK_COMPARE_OP_NEVER;
1029 sampler_info.minLod = 1.0;
1030 sampler_info.maxLod = 1.0;
1031 sampler_info.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
1032 sampler_info.unnormalizedCoordinates = VK_FALSE;
1033 // Not VK_TRUE or VK_FALSE
1034 sampler_info.anisotropyEnable = 3;
1035 vkCreateSampler(m_device->device(), &sampler_info, NULL, &sampler);
1036 m_errorMonitor->VerifyFound();
1037}
Dustin Gravesfce74c02016-05-10 11:42:58 -06001038
1039TEST_F(VkLayerTest, FailedReturnValue) {
1040 TEST_DESCRIPTION("Check for a message describing a VkResult failure code");
1041
1042 ASSERT_NO_FATAL_FAILURE(InitState());
1043
Dustin Graves13c1e2b2016-05-16 15:31:02 -06001044 // Find an unsupported image format
1045 VkFormat unsupported = VK_FORMAT_UNDEFINED;
1046 for (int f = VK_FORMAT_BEGIN_RANGE; f <= VK_FORMAT_END_RANGE; f++) {
1047 VkFormat format = static_cast<VkFormat>(f);
1048 VkFormatProperties fProps = m_device->format_properties(format);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001049 if (format != VK_FORMAT_UNDEFINED && fProps.linearTilingFeatures == 0 && fProps.optimalTilingFeatures == 0) {
Dustin Graves13c1e2b2016-05-16 15:31:02 -06001050 unsupported = format;
1051 break;
1052 }
1053 }
1054
1055 if (unsupported != VK_FORMAT_UNDEFINED) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001056 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT,
1057 "the requested format is not supported on this device");
Dustin Graves13c1e2b2016-05-16 15:31:02 -06001058 // Specify an unsupported VkFormat value to generate a
1059 // VK_ERROR_FORMAT_NOT_SUPPORTED return code
1060 // Expected to trigger a warning from
1061 // parameter_validation::validate_result
1062 VkImageFormatProperties image_format_properties;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001063 VkResult err = vkGetPhysicalDeviceImageFormatProperties(gpu(), unsupported, VK_IMAGE_TYPE_2D, VK_IMAGE_TILING_OPTIMAL,
1064 VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT, 0, &image_format_properties);
Dustin Graves13c1e2b2016-05-16 15:31:02 -06001065 ASSERT_TRUE(err == VK_ERROR_FORMAT_NOT_SUPPORTED);
1066 m_errorMonitor->VerifyFound();
1067 }
Dustin Gravesfce74c02016-05-10 11:42:58 -06001068}
Mark Lobodzinskie090fef2016-06-09 17:04:56 -06001069
1070TEST_F(VkLayerTest, UpdateBufferAlignment) {
1071 TEST_DESCRIPTION("Check alignment parameters for vkCmdUpdateBuffer");
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001072 uint32_t updateData[] = {1, 2, 3, 4, 5, 6, 7, 8};
Mark Lobodzinskie090fef2016-06-09 17:04:56 -06001073
1074 ASSERT_NO_FATAL_FAILURE(InitState());
1075
1076 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
1077 vk_testing::Buffer buffer;
1078 buffer.init_as_dst(*m_device, (VkDeviceSize)20, reqs);
1079
1080 BeginCommandBuffer();
1081 // Introduce failure by using dstOffset that is not multiple of 4
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001082 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " is not a multiple of 4");
Mark Lobodzinskie090fef2016-06-09 17:04:56 -06001083 m_commandBuffer->UpdateBuffer(buffer.handle(), 1, 4, updateData);
1084 m_errorMonitor->VerifyFound();
1085
1086 // Introduce failure by using dataSize that is not multiple of 4
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001087 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " is not a multiple of 4");
Mark Lobodzinskie090fef2016-06-09 17:04:56 -06001088 m_commandBuffer->UpdateBuffer(buffer.handle(), 0, 6, updateData);
1089 m_errorMonitor->VerifyFound();
1090
1091 // Introduce failure by using dataSize that is < 0
1092 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001093 "must be greater than zero and less than or equal to 65536");
Mark Lobodzinskie090fef2016-06-09 17:04:56 -06001094 m_commandBuffer->UpdateBuffer(buffer.handle(), 0, -44, updateData);
1095 m_errorMonitor->VerifyFound();
1096
1097 // Introduce failure by using dataSize that is > 65536
1098 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001099 "must be greater than zero and less than or equal to 65536");
Mark Lobodzinskie090fef2016-06-09 17:04:56 -06001100 m_commandBuffer->UpdateBuffer(buffer.handle(), 0, 80000, updateData);
1101 m_errorMonitor->VerifyFound();
1102
1103 EndCommandBuffer();
1104}
1105
1106TEST_F(VkLayerTest, FillBufferAlignment) {
1107 TEST_DESCRIPTION("Check alignment parameters for vkCmdFillBuffer");
1108
1109 ASSERT_NO_FATAL_FAILURE(InitState());
1110
1111 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
1112 vk_testing::Buffer buffer;
1113 buffer.init_as_dst(*m_device, (VkDeviceSize)20, reqs);
1114
1115 BeginCommandBuffer();
1116
1117 // Introduce failure by using dstOffset that is not multiple of 4
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001118 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " is not a multiple of 4");
Mark Lobodzinskie090fef2016-06-09 17:04:56 -06001119 m_commandBuffer->FillBuffer(buffer.handle(), 1, 4, 0x11111111);
1120 m_errorMonitor->VerifyFound();
1121
1122 // Introduce failure by using size that is not multiple of 4
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001123 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " is not a multiple of 4");
Mark Lobodzinskie090fef2016-06-09 17:04:56 -06001124 m_commandBuffer->FillBuffer(buffer.handle(), 0, 6, 0x11111111);
1125 m_errorMonitor->VerifyFound();
1126
1127 // Introduce failure by using size that is zero
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001128 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "must be greater than zero");
Mark Lobodzinskie090fef2016-06-09 17:04:56 -06001129 m_commandBuffer->FillBuffer(buffer.handle(), 0, 0, 0x11111111);
1130 m_errorMonitor->VerifyFound();
1131
1132 EndCommandBuffer();
1133}
Dustin Graves40f35822016-06-23 11:12:53 -06001134
1135// This is a positive test. No failures are expected.
1136TEST_F(VkLayerTest, IgnoreUnrelatedDescriptor) {
1137 TEST_DESCRIPTION("Ensure that the vkUpdateDescriptorSet validation code "
1138 "is ignoring VkWriteDescriptorSet members that are not "
1139 "related to the descriptor type specified by "
1140 "VkWriteDescriptorSet::descriptorType. Correct "
1141 "validation behavior will result in the test running to "
1142 "completion without validation errors.");
1143
Dustin Graves5e2d8fc2016-07-07 16:18:49 -06001144 const uintptr_t invalid_ptr = 0xcdcdcdcd;
1145
Dustin Graves40f35822016-06-23 11:12:53 -06001146 ASSERT_NO_FATAL_FAILURE(InitState());
1147
1148 // Image Case
1149 {
1150 m_errorMonitor->ExpectSuccess();
1151
1152 VkImage image;
1153 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
1154 const int32_t tex_width = 32;
1155 const int32_t tex_height = 32;
1156 VkImageCreateInfo image_create_info = {};
1157 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
1158 image_create_info.pNext = NULL;
1159 image_create_info.imageType = VK_IMAGE_TYPE_2D;
1160 image_create_info.format = tex_format;
1161 image_create_info.extent.width = tex_width;
1162 image_create_info.extent.height = tex_height;
1163 image_create_info.extent.depth = 1;
1164 image_create_info.mipLevels = 1;
1165 image_create_info.arrayLayers = 1;
1166 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
Tobin Ehlis51cde412016-07-11 16:08:30 -06001167 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
Dustin Graves40f35822016-06-23 11:12:53 -06001168 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
1169 image_create_info.flags = 0;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001170 VkResult err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
Dustin Graves40f35822016-06-23 11:12:53 -06001171 ASSERT_VK_SUCCESS(err);
1172
1173 VkMemoryRequirements memory_reqs;
1174 VkDeviceMemory image_memory;
1175 bool pass;
1176 VkMemoryAllocateInfo memory_info = {};
1177 memory_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
1178 memory_info.pNext = NULL;
1179 memory_info.allocationSize = 0;
1180 memory_info.memoryTypeIndex = 0;
1181 vkGetImageMemoryRequirements(m_device->device(), image, &memory_reqs);
1182 memory_info.allocationSize = memory_reqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001183 pass = m_device->phy().set_memory_type(memory_reqs.memoryTypeBits, &memory_info, 0);
Dustin Graves40f35822016-06-23 11:12:53 -06001184 ASSERT_TRUE(pass);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001185 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &image_memory);
Dustin Graves40f35822016-06-23 11:12:53 -06001186 ASSERT_VK_SUCCESS(err);
1187 err = vkBindImageMemory(m_device->device(), image, image_memory, 0);
1188 ASSERT_VK_SUCCESS(err);
1189
1190 VkImageViewCreateInfo image_view_create_info = {};
1191 image_view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
1192 image_view_create_info.image = image;
1193 image_view_create_info.viewType = VK_IMAGE_VIEW_TYPE_2D;
1194 image_view_create_info.format = tex_format;
1195 image_view_create_info.subresourceRange.layerCount = 1;
1196 image_view_create_info.subresourceRange.baseMipLevel = 0;
1197 image_view_create_info.subresourceRange.levelCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001198 image_view_create_info.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Dustin Graves40f35822016-06-23 11:12:53 -06001199
1200 VkImageView view;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001201 err = vkCreateImageView(m_device->device(), &image_view_create_info, NULL, &view);
Dustin Graves40f35822016-06-23 11:12:53 -06001202 ASSERT_VK_SUCCESS(err);
1203
1204 VkDescriptorPoolSize ds_type_count = {};
1205 ds_type_count.type = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE;
1206 ds_type_count.descriptorCount = 1;
1207
1208 VkDescriptorPoolCreateInfo ds_pool_ci = {};
1209 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
1210 ds_pool_ci.pNext = NULL;
1211 ds_pool_ci.maxSets = 1;
1212 ds_pool_ci.poolSizeCount = 1;
1213 ds_pool_ci.pPoolSizes = &ds_type_count;
1214
1215 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001216 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Dustin Graves40f35822016-06-23 11:12:53 -06001217 ASSERT_VK_SUCCESS(err);
1218
1219 VkDescriptorSetLayoutBinding dsl_binding = {};
1220 dsl_binding.binding = 0;
1221 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE;
1222 dsl_binding.descriptorCount = 1;
1223 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
1224 dsl_binding.pImmutableSamplers = NULL;
1225
1226 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001227 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
Dustin Graves40f35822016-06-23 11:12:53 -06001228 ds_layout_ci.pNext = NULL;
1229 ds_layout_ci.bindingCount = 1;
1230 ds_layout_ci.pBindings = &dsl_binding;
1231 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001232 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Dustin Graves40f35822016-06-23 11:12:53 -06001233 ASSERT_VK_SUCCESS(err);
1234
1235 VkDescriptorSet descriptor_set;
1236 VkDescriptorSetAllocateInfo alloc_info = {};
1237 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
1238 alloc_info.descriptorSetCount = 1;
1239 alloc_info.descriptorPool = ds_pool;
1240 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001241 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
Dustin Graves40f35822016-06-23 11:12:53 -06001242 ASSERT_VK_SUCCESS(err);
1243
1244 VkDescriptorImageInfo image_info = {};
1245 image_info.imageView = view;
1246 image_info.imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
1247
1248 VkWriteDescriptorSet descriptor_write;
1249 memset(&descriptor_write, 0, sizeof(descriptor_write));
1250 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
1251 descriptor_write.dstSet = descriptor_set;
1252 descriptor_write.dstBinding = 0;
1253 descriptor_write.descriptorCount = 1;
1254 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE;
1255 descriptor_write.pImageInfo = &image_info;
1256
1257 // Set pBufferInfo and pTexelBufferView to invalid values, which should
1258 // be
1259 // ignored for descriptorType == VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE.
1260 // This will most likely produce a crash if the parameter_validation
1261 // layer
1262 // does not correctly ignore pBufferInfo.
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001263 descriptor_write.pBufferInfo = reinterpret_cast<const VkDescriptorBufferInfo *>(invalid_ptr);
1264 descriptor_write.pTexelBufferView = reinterpret_cast<const VkBufferView *>(invalid_ptr);
Dustin Graves40f35822016-06-23 11:12:53 -06001265
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001266 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
Dustin Graves40f35822016-06-23 11:12:53 -06001267
1268 m_errorMonitor->VerifyNotFound();
1269
Dustin Graves40f35822016-06-23 11:12:53 -06001270 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
1271 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
1272 vkDestroyImageView(m_device->device(), view, NULL);
1273 vkDestroyImage(m_device->device(), image, NULL);
1274 vkFreeMemory(m_device->device(), image_memory, NULL);
1275 }
1276
1277 // Buffer Case
1278 {
1279 m_errorMonitor->ExpectSuccess();
1280
1281 VkBuffer buffer;
1282 uint32_t queue_family_index = 0;
1283 VkBufferCreateInfo buffer_create_info = {};
1284 buffer_create_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
1285 buffer_create_info.size = 1024;
1286 buffer_create_info.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
1287 buffer_create_info.queueFamilyIndexCount = 1;
1288 buffer_create_info.pQueueFamilyIndices = &queue_family_index;
1289
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001290 VkResult err = vkCreateBuffer(m_device->device(), &buffer_create_info, NULL, &buffer);
Dustin Graves40f35822016-06-23 11:12:53 -06001291 ASSERT_VK_SUCCESS(err);
1292
1293 VkMemoryRequirements memory_reqs;
1294 VkDeviceMemory buffer_memory;
1295 bool pass;
1296 VkMemoryAllocateInfo memory_info = {};
1297 memory_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
1298 memory_info.pNext = NULL;
1299 memory_info.allocationSize = 0;
1300 memory_info.memoryTypeIndex = 0;
1301
1302 vkGetBufferMemoryRequirements(m_device->device(), buffer, &memory_reqs);
1303 memory_info.allocationSize = memory_reqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001304 pass = m_device->phy().set_memory_type(memory_reqs.memoryTypeBits, &memory_info, 0);
Dustin Graves40f35822016-06-23 11:12:53 -06001305 ASSERT_TRUE(pass);
1306
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001307 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &buffer_memory);
Dustin Graves40f35822016-06-23 11:12:53 -06001308 ASSERT_VK_SUCCESS(err);
1309 err = vkBindBufferMemory(m_device->device(), buffer, buffer_memory, 0);
1310 ASSERT_VK_SUCCESS(err);
1311
1312 VkDescriptorPoolSize ds_type_count = {};
1313 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
1314 ds_type_count.descriptorCount = 1;
1315
1316 VkDescriptorPoolCreateInfo ds_pool_ci = {};
1317 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
1318 ds_pool_ci.pNext = NULL;
1319 ds_pool_ci.maxSets = 1;
1320 ds_pool_ci.poolSizeCount = 1;
1321 ds_pool_ci.pPoolSizes = &ds_type_count;
1322
1323 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001324 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Dustin Graves40f35822016-06-23 11:12:53 -06001325 ASSERT_VK_SUCCESS(err);
1326
1327 VkDescriptorSetLayoutBinding dsl_binding = {};
1328 dsl_binding.binding = 0;
1329 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
1330 dsl_binding.descriptorCount = 1;
1331 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
1332 dsl_binding.pImmutableSamplers = NULL;
1333
1334 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001335 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
Dustin Graves40f35822016-06-23 11:12:53 -06001336 ds_layout_ci.pNext = NULL;
1337 ds_layout_ci.bindingCount = 1;
1338 ds_layout_ci.pBindings = &dsl_binding;
1339 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001340 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Dustin Graves40f35822016-06-23 11:12:53 -06001341 ASSERT_VK_SUCCESS(err);
1342
1343 VkDescriptorSet descriptor_set;
1344 VkDescriptorSetAllocateInfo alloc_info = {};
1345 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
1346 alloc_info.descriptorSetCount = 1;
1347 alloc_info.descriptorPool = ds_pool;
1348 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001349 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
Dustin Graves40f35822016-06-23 11:12:53 -06001350 ASSERT_VK_SUCCESS(err);
1351
1352 VkDescriptorBufferInfo buffer_info = {};
1353 buffer_info.buffer = buffer;
1354 buffer_info.offset = 0;
1355 buffer_info.range = 1024;
1356
1357 VkWriteDescriptorSet descriptor_write;
1358 memset(&descriptor_write, 0, sizeof(descriptor_write));
1359 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
1360 descriptor_write.dstSet = descriptor_set;
1361 descriptor_write.dstBinding = 0;
1362 descriptor_write.descriptorCount = 1;
1363 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
1364 descriptor_write.pBufferInfo = &buffer_info;
1365
1366 // Set pImageInfo and pTexelBufferView to invalid values, which should
1367 // be
1368 // ignored for descriptorType == VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER.
1369 // This will most likely produce a crash if the parameter_validation
1370 // layer
1371 // does not correctly ignore pImageInfo.
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001372 descriptor_write.pImageInfo = reinterpret_cast<const VkDescriptorImageInfo *>(invalid_ptr);
1373 descriptor_write.pTexelBufferView = reinterpret_cast<const VkBufferView *>(invalid_ptr);
Dustin Graves40f35822016-06-23 11:12:53 -06001374
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001375 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
Dustin Graves40f35822016-06-23 11:12:53 -06001376
1377 m_errorMonitor->VerifyNotFound();
1378
1379 vkFreeDescriptorSets(m_device->device(), ds_pool, 1, &descriptor_set);
1380 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
1381 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
1382 vkDestroyBuffer(m_device->device(), buffer, NULL);
1383 vkFreeMemory(m_device->device(), buffer_memory, NULL);
1384 }
1385
1386 // Texel Buffer Case
1387 {
1388 m_errorMonitor->ExpectSuccess();
1389
1390 VkBuffer buffer;
1391 uint32_t queue_family_index = 0;
1392 VkBufferCreateInfo buffer_create_info = {};
1393 buffer_create_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
1394 buffer_create_info.size = 1024;
1395 buffer_create_info.usage = VK_BUFFER_USAGE_STORAGE_TEXEL_BUFFER_BIT;
1396 buffer_create_info.queueFamilyIndexCount = 1;
1397 buffer_create_info.pQueueFamilyIndices = &queue_family_index;
1398
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001399 VkResult err = vkCreateBuffer(m_device->device(), &buffer_create_info, NULL, &buffer);
Dustin Graves40f35822016-06-23 11:12:53 -06001400 ASSERT_VK_SUCCESS(err);
1401
1402 VkMemoryRequirements memory_reqs;
1403 VkDeviceMemory buffer_memory;
1404 bool pass;
1405 VkMemoryAllocateInfo memory_info = {};
1406 memory_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
1407 memory_info.pNext = NULL;
1408 memory_info.allocationSize = 0;
1409 memory_info.memoryTypeIndex = 0;
1410
1411 vkGetBufferMemoryRequirements(m_device->device(), buffer, &memory_reqs);
1412 memory_info.allocationSize = memory_reqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001413 pass = m_device->phy().set_memory_type(memory_reqs.memoryTypeBits, &memory_info, 0);
Dustin Graves40f35822016-06-23 11:12:53 -06001414 ASSERT_TRUE(pass);
1415
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001416 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &buffer_memory);
Dustin Graves40f35822016-06-23 11:12:53 -06001417 ASSERT_VK_SUCCESS(err);
1418 err = vkBindBufferMemory(m_device->device(), buffer, buffer_memory, 0);
1419 ASSERT_VK_SUCCESS(err);
1420
1421 VkBufferViewCreateInfo buff_view_ci = {};
1422 buff_view_ci.sType = VK_STRUCTURE_TYPE_BUFFER_VIEW_CREATE_INFO;
1423 buff_view_ci.buffer = buffer;
1424 buff_view_ci.format = VK_FORMAT_R8_UNORM;
1425 buff_view_ci.range = VK_WHOLE_SIZE;
1426 VkBufferView buffer_view;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001427 err = vkCreateBufferView(m_device->device(), &buff_view_ci, NULL, &buffer_view);
Dustin Graves40f35822016-06-23 11:12:53 -06001428
1429 VkDescriptorPoolSize ds_type_count = {};
1430 ds_type_count.type = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
1431 ds_type_count.descriptorCount = 1;
1432
1433 VkDescriptorPoolCreateInfo ds_pool_ci = {};
1434 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
1435 ds_pool_ci.pNext = NULL;
1436 ds_pool_ci.maxSets = 1;
1437 ds_pool_ci.poolSizeCount = 1;
1438 ds_pool_ci.pPoolSizes = &ds_type_count;
1439
1440 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001441 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Dustin Graves40f35822016-06-23 11:12:53 -06001442 ASSERT_VK_SUCCESS(err);
1443
1444 VkDescriptorSetLayoutBinding dsl_binding = {};
1445 dsl_binding.binding = 0;
1446 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
1447 dsl_binding.descriptorCount = 1;
1448 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
1449 dsl_binding.pImmutableSamplers = NULL;
1450
1451 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001452 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
Dustin Graves40f35822016-06-23 11:12:53 -06001453 ds_layout_ci.pNext = NULL;
1454 ds_layout_ci.bindingCount = 1;
1455 ds_layout_ci.pBindings = &dsl_binding;
1456 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001457 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Dustin Graves40f35822016-06-23 11:12:53 -06001458 ASSERT_VK_SUCCESS(err);
1459
1460 VkDescriptorSet descriptor_set;
1461 VkDescriptorSetAllocateInfo alloc_info = {};
1462 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
1463 alloc_info.descriptorSetCount = 1;
1464 alloc_info.descriptorPool = ds_pool;
1465 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001466 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
Dustin Graves40f35822016-06-23 11:12:53 -06001467 ASSERT_VK_SUCCESS(err);
1468
1469 VkWriteDescriptorSet descriptor_write;
1470 memset(&descriptor_write, 0, sizeof(descriptor_write));
1471 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
1472 descriptor_write.dstSet = descriptor_set;
1473 descriptor_write.dstBinding = 0;
1474 descriptor_write.descriptorCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001475 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
Dustin Graves40f35822016-06-23 11:12:53 -06001476 descriptor_write.pTexelBufferView = &buffer_view;
1477
1478 // Set pImageInfo and pBufferInfo to invalid values, which should be
1479 // ignored for descriptorType ==
1480 // VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER.
1481 // This will most likely produce a crash if the parameter_validation
1482 // layer
1483 // does not correctly ignore pImageInfo and pBufferInfo.
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001484 descriptor_write.pImageInfo = reinterpret_cast<const VkDescriptorImageInfo *>(invalid_ptr);
1485 descriptor_write.pBufferInfo = reinterpret_cast<const VkDescriptorBufferInfo *>(invalid_ptr);
Dustin Graves40f35822016-06-23 11:12:53 -06001486
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001487 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
Dustin Graves40f35822016-06-23 11:12:53 -06001488
1489 m_errorMonitor->VerifyNotFound();
1490
1491 vkFreeDescriptorSets(m_device->device(), ds_pool, 1, &descriptor_set);
1492 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
1493 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
1494 vkDestroyBufferView(m_device->device(), buffer_view, NULL);
1495 vkDestroyBuffer(m_device->device(), buffer, NULL);
1496 vkFreeMemory(m_device->device(), buffer_memory, NULL);
1497 }
1498}
Cortd889ff92016-07-27 09:51:27 -07001499
1500TEST_F(VkLayerTest, PSOPolygonModeInvalid) {
1501 VkResult err;
1502
1503 TEST_DESCRIPTION("Attempt to use a non-solid polygon fill mode in a "
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001504 "pipeline when this feature is not enabled.");
Cortd889ff92016-07-27 09:51:27 -07001505
1506 ASSERT_NO_FATAL_FAILURE(InitState());
1507 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
1508
1509 std::vector<const char *> device_extension_names;
1510 auto features = m_device->phy().features();
1511 // Artificially disable support for non-solid fill modes
1512 features.fillModeNonSolid = false;
1513 // The sacrificial device object
1514 VkDeviceObj test_device(0, gpu(), device_extension_names, &features);
1515
1516 VkRenderpassObj render_pass(&test_device);
1517
1518 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
1519 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
1520 pipeline_layout_ci.setLayoutCount = 0;
1521 pipeline_layout_ci.pSetLayouts = NULL;
1522
1523 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001524 err = vkCreatePipelineLayout(test_device.device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Cortd889ff92016-07-27 09:51:27 -07001525 ASSERT_VK_SUCCESS(err);
1526
1527 VkPipelineRasterizationStateCreateInfo rs_ci = {};
1528 rs_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
1529 rs_ci.pNext = nullptr;
1530 rs_ci.lineWidth = 1.0f;
1531 rs_ci.rasterizerDiscardEnable = true;
1532
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001533 VkShaderObj vs(&test_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
1534 VkShaderObj fs(&test_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Cortd889ff92016-07-27 09:51:27 -07001535
Mark Lobodzinski5e644732016-08-15 16:51:19 -06001536 // Set polygonMode to unsupported value POINT, should fail
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001537 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
1538 "polygonMode cannot be VK_POLYGON_MODE_POINT or VK_POLYGON_MODE_LINE");
Cortd889ff92016-07-27 09:51:27 -07001539 {
1540 VkPipelineObj pipe(&test_device);
1541 pipe.AddShader(&vs);
1542 pipe.AddShader(&fs);
1543 pipe.AddColorAttachment();
1544 // Introduce failure by setting unsupported polygon mode
1545 rs_ci.polygonMode = VK_POLYGON_MODE_POINT;
1546 pipe.SetRasterization(&rs_ci);
1547 pipe.CreateVKPipeline(pipeline_layout, render_pass.handle());
1548 }
1549 m_errorMonitor->VerifyFound();
1550
1551 // Try again with polygonMode=LINE, should fail
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001552 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
1553 "polygonMode cannot be VK_POLYGON_MODE_POINT or VK_POLYGON_MODE_LINE");
Cortd889ff92016-07-27 09:51:27 -07001554 {
1555 VkPipelineObj pipe(&test_device);
1556 pipe.AddShader(&vs);
1557 pipe.AddShader(&fs);
1558 pipe.AddColorAttachment();
1559 // Introduce failure by setting unsupported polygon mode
1560 rs_ci.polygonMode = VK_POLYGON_MODE_LINE;
1561 pipe.SetRasterization(&rs_ci);
1562 pipe.CreateVKPipeline(pipeline_layout, render_pass.handle());
1563 }
1564 m_errorMonitor->VerifyFound();
1565
1566 // Try again with polygonMode=FILL. No error is expected
1567 m_errorMonitor->ExpectSuccess();
1568 {
1569 VkPipelineObj pipe(&test_device);
1570 pipe.AddShader(&vs);
1571 pipe.AddShader(&fs);
1572 pipe.AddColorAttachment();
1573 // Set polygonMode to a good value
1574 rs_ci.polygonMode = VK_POLYGON_MODE_FILL;
1575 pipe.SetRasterization(&rs_ci);
1576 pipe.CreateVKPipeline(pipeline_layout, render_pass.handle());
1577 }
1578 m_errorMonitor->VerifyNotFound();
1579
1580 vkDestroyPipelineLayout(test_device.device(), pipeline_layout, NULL);
1581}
1582
Dustin Gravesffa90fa2016-05-06 11:20:38 -06001583#endif // PARAMETER_VALIDATION_TESTS
1584
Tobin Ehlis0788f522015-05-26 16:11:58 -06001585#if MEM_TRACKER_TESTS
Tobin Ehlis8fab6562015-12-01 09:57:09 -07001586#if 0
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001587TEST_F(VkLayerTest, CallResetCommandBufferBeforeCompletion)
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001588{
1589 vk_testing::Fence testFence;
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001590 VkFenceCreateInfo fenceInfo = {};
1591 fenceInfo.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
1592 fenceInfo.pNext = NULL;
1593 fenceInfo.flags = 0;
1594
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07001595 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Resetting CB");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06001596
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001597 ASSERT_NO_FATAL_FAILURE(InitState());
Tony Barbourc1eb1a52015-07-20 13:00:10 -06001598
1599 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
1600 vk_testing::Buffer buffer;
1601 buffer.init_as_dst(*m_device, (VkDeviceSize)20, reqs);
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001602
Tony Barbourfe3351b2015-07-28 10:17:20 -06001603 BeginCommandBuffer();
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001604 m_commandBuffer->FillBuffer(buffer.handle(), 0, 4, 0x11111111);
Tony Barbourfe3351b2015-07-28 10:17:20 -06001605 EndCommandBuffer();
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001606
1607 testFence.init(*m_device, fenceInfo);
1608
1609 // Bypass framework since it does the waits automatically
1610 VkResult err = VK_SUCCESS;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06001611 VkSubmitInfo submit_info;
Chia-I Wuf9be13c2015-10-26 20:37:06 +08001612 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
1613 submit_info.pNext = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08001614 submit_info.waitSemaphoreCount = 0;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06001615 submit_info.pWaitSemaphores = NULL;
Jon Ashburn7f9716c2015-12-30 16:42:50 -07001616 submit_info.pWaitDstStageMask = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08001617 submit_info.commandBufferCount = 1;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001618 submit_info.pCommandBuffers = &m_commandBuffer->handle();
Chia-I Wud50a7d72015-10-26 20:48:51 +08001619 submit_info.signalSemaphoreCount = 0;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06001620 submit_info.pSignalSemaphores = NULL;
Courtney Goeltzenleuchter646b9072015-10-20 18:04:07 -06001621
1622 err = vkQueueSubmit( m_device->m_queue, 1, &submit_info, testFence.handle());
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001623 ASSERT_VK_SUCCESS( err );
1624
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001625 // Introduce failure by calling begin again before checking fence
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001626 vkResetCommandBuffer(m_commandBuffer->handle(), 0);
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001627
Chris Forbes8f36a8a2016-04-07 13:21:07 +12001628 m_errorMonitor->VerifyFound();
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001629}
1630
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001631TEST_F(VkLayerTest, CallBeginCommandBufferBeforeCompletion)
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001632{
1633 vk_testing::Fence testFence;
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001634 VkFenceCreateInfo fenceInfo = {};
1635 fenceInfo.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
1636 fenceInfo.pNext = NULL;
1637 fenceInfo.flags = 0;
1638
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07001639 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Calling vkBeginCommandBuffer() on active CB");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06001640
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001641 ASSERT_NO_FATAL_FAILURE(InitState());
1642 ASSERT_NO_FATAL_FAILURE(InitViewport());
1643 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
1644
Tony Barbourfe3351b2015-07-28 10:17:20 -06001645 BeginCommandBuffer();
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001646 m_commandBuffer->ClearAllBuffers(m_clear_color, m_depth_clear_color, m_stencil_clear_color, NULL);
Tony Barbourfe3351b2015-07-28 10:17:20 -06001647 EndCommandBuffer();
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001648
1649 testFence.init(*m_device, fenceInfo);
1650
1651 // Bypass framework since it does the waits automatically
1652 VkResult err = VK_SUCCESS;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06001653 VkSubmitInfo submit_info;
Chia-I Wuf9be13c2015-10-26 20:37:06 +08001654 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
1655 submit_info.pNext = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08001656 submit_info.waitSemaphoreCount = 0;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06001657 submit_info.pWaitSemaphores = NULL;
Jon Ashburn7f9716c2015-12-30 16:42:50 -07001658 submit_info.pWaitDstStageMask = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08001659 submit_info.commandBufferCount = 1;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001660 submit_info.pCommandBuffers = &m_commandBuffer->handle();
Chia-I Wud50a7d72015-10-26 20:48:51 +08001661 submit_info.signalSemaphoreCount = 0;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06001662 submit_info.pSignalSemaphores = NULL;
Courtney Goeltzenleuchter646b9072015-10-20 18:04:07 -06001663
1664 err = vkQueueSubmit( m_device->m_queue, 1, &submit_info, testFence.handle());
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001665 ASSERT_VK_SUCCESS( err );
1666
Jon Ashburnf19916e2016-01-11 13:12:43 -07001667 VkCommandBufferInheritanceInfo hinfo = {};
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001668 VkCommandBufferBeginInfo info = {};
1669 info.flags = VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT;
1670 info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
Mark Lobodzinski5fcc4212015-09-14 17:43:42 -06001671 info.renderPass = VK_NULL_HANDLE;
1672 info.subpass = 0;
1673 info.framebuffer = VK_NULL_HANDLE;
Chia-I Wub8d47ae2015-11-11 10:18:12 +08001674 info.occlusionQueryEnable = VK_FALSE;
1675 info.queryFlags = 0;
1676 info.pipelineStatistics = 0;
Mark Lobodzinski5fcc4212015-09-14 17:43:42 -06001677
1678 // Introduce failure by calling BCB again before checking fence
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001679 vkBeginCommandBuffer(m_commandBuffer->handle(), &info);
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001680
Chris Forbes8f36a8a2016-04-07 13:21:07 +12001681 m_errorMonitor->VerifyFound();
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001682}
Tobin Ehlis8fab6562015-12-01 09:57:09 -07001683#endif
Chris Forbes8f36a8a2016-04-07 13:21:07 +12001684
Mark Lobodzinski152fe252016-05-03 16:49:15 -06001685// This is a positive test. No failures are expected.
1686TEST_F(VkLayerTest, TestAliasedMemoryTracking) {
1687 VkResult err;
1688 bool pass;
1689
1690 TEST_DESCRIPTION("Create a buffer, allocate memory, bind memory, destroy "
1691 "the buffer, create an image, and bind the same memory to "
1692 "it");
1693
1694 m_errorMonitor->ExpectSuccess();
1695
1696 ASSERT_NO_FATAL_FAILURE(InitState());
1697
1698 VkBuffer buffer;
1699 VkImage image;
1700 VkDeviceMemory mem;
1701 VkMemoryRequirements mem_reqs;
1702
1703 VkBufferCreateInfo buf_info = {};
1704 buf_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
1705 buf_info.pNext = NULL;
1706 buf_info.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
1707 buf_info.size = 256;
1708 buf_info.queueFamilyIndexCount = 0;
1709 buf_info.pQueueFamilyIndices = NULL;
1710 buf_info.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
1711 buf_info.flags = 0;
1712 err = vkCreateBuffer(m_device->device(), &buf_info, NULL, &buffer);
1713 ASSERT_VK_SUCCESS(err);
1714
1715 vkGetBufferMemoryRequirements(m_device->device(), buffer, &mem_reqs);
1716
1717 VkMemoryAllocateInfo alloc_info = {};
1718 alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
1719 alloc_info.pNext = NULL;
1720 alloc_info.memoryTypeIndex = 0;
1721
1722 // Ensure memory is big enough for both bindings
1723 alloc_info.allocationSize = 0x10000;
1724
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001725 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 -06001726 if (!pass) {
1727 vkDestroyBuffer(m_device->device(), buffer, NULL);
1728 return;
1729 }
1730
1731 err = vkAllocateMemory(m_device->device(), &alloc_info, NULL, &mem);
1732 ASSERT_VK_SUCCESS(err);
1733
1734 uint8_t *pData;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001735 err = vkMapMemory(m_device->device(), mem, 0, mem_reqs.size, 0, (void **)&pData);
Mark Lobodzinski152fe252016-05-03 16:49:15 -06001736 ASSERT_VK_SUCCESS(err);
1737
Mark Lobodzinski2abefa92016-05-05 11:45:57 -06001738 memset(pData, 0xCADECADE, static_cast<size_t>(mem_reqs.size));
Mark Lobodzinski152fe252016-05-03 16:49:15 -06001739
1740 vkUnmapMemory(m_device->device(), mem);
1741
1742 err = vkBindBufferMemory(m_device->device(), buffer, mem, 0);
1743 ASSERT_VK_SUCCESS(err);
1744
1745 // NOW, destroy the buffer. Obviously, the resource no longer occupies this
1746 // memory. In fact, it was never used by the GPU.
1747 // Just be be sure, wait for idle.
1748 vkDestroyBuffer(m_device->device(), buffer, NULL);
1749 vkDeviceWaitIdle(m_device->device());
1750
1751 VkImageCreateInfo image_create_info = {};
1752 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
1753 image_create_info.pNext = NULL;
1754 image_create_info.imageType = VK_IMAGE_TYPE_2D;
1755 image_create_info.format = VK_FORMAT_R8G8B8A8_UNORM;
1756 image_create_info.extent.width = 64;
1757 image_create_info.extent.height = 64;
1758 image_create_info.extent.depth = 1;
1759 image_create_info.mipLevels = 1;
1760 image_create_info.arrayLayers = 1;
1761 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
1762 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
1763 image_create_info.initialLayout = VK_IMAGE_LAYOUT_PREINITIALIZED;
1764 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
1765 image_create_info.queueFamilyIndexCount = 0;
1766 image_create_info.pQueueFamilyIndices = NULL;
1767 image_create_info.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
1768 image_create_info.flags = 0;
1769
1770 VkMemoryAllocateInfo mem_alloc = {};
1771 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
1772 mem_alloc.pNext = NULL;
1773 mem_alloc.allocationSize = 0;
1774 mem_alloc.memoryTypeIndex = 0;
1775
1776 /* Create a mappable image. It will be the texture if linear images are ok
1777 * to be textures or it will be the staging image if they are not.
1778 */
1779 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
1780 ASSERT_VK_SUCCESS(err);
1781
1782 vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs);
1783
1784 mem_alloc.allocationSize = mem_reqs.size;
1785
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001786 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 -06001787 if (!pass) {
1788 vkDestroyImage(m_device->device(), image, NULL);
1789 return;
1790 }
1791
Tobin Ehlis077ded32016-05-12 17:39:13 -06001792 // VALIDATION FAILURE:
Mark Lobodzinski152fe252016-05-03 16:49:15 -06001793 err = vkBindImageMemory(m_device->device(), image, mem, 0);
1794 ASSERT_VK_SUCCESS(err);
1795
1796 m_errorMonitor->VerifyNotFound();
1797
Tony Barbourdf4c0042016-06-01 15:55:43 -06001798 vkFreeMemory(m_device->device(), mem, NULL);
Mark Lobodzinski152fe252016-05-03 16:49:15 -06001799 vkDestroyBuffer(m_device->device(), buffer, NULL);
1800 vkDestroyImage(m_device->device(), image, NULL);
1801}
1802
Tobin Ehlisf11be982016-05-11 13:52:53 -06001803TEST_F(VkLayerTest, InvalidMemoryAliasing) {
1804 TEST_DESCRIPTION("Create a buffer and image, allocate memory, and bind the "
1805 "buffer and image to memory such that they will alias.");
1806 VkResult err;
1807 bool pass;
1808 ASSERT_NO_FATAL_FAILURE(InitState());
1809
Tobin Ehlis077ded32016-05-12 17:39:13 -06001810 VkBuffer buffer, buffer2;
Tobin Ehlisf11be982016-05-11 13:52:53 -06001811 VkImage image;
1812 VkDeviceMemory mem; // buffer will be bound first
1813 VkDeviceMemory mem_img; // image bound first
Tobin Ehlis077ded32016-05-12 17:39:13 -06001814 VkMemoryRequirements buff_mem_reqs, img_mem_reqs;
Tobin Ehlisf11be982016-05-11 13:52:53 -06001815
1816 VkBufferCreateInfo buf_info = {};
1817 buf_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
1818 buf_info.pNext = NULL;
1819 buf_info.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
1820 buf_info.size = 256;
1821 buf_info.queueFamilyIndexCount = 0;
1822 buf_info.pQueueFamilyIndices = NULL;
1823 buf_info.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
1824 buf_info.flags = 0;
1825 err = vkCreateBuffer(m_device->device(), &buf_info, NULL, &buffer);
1826 ASSERT_VK_SUCCESS(err);
1827
Tobin Ehlis077ded32016-05-12 17:39:13 -06001828 vkGetBufferMemoryRequirements(m_device->device(), buffer, &buff_mem_reqs);
Tobin Ehlisf11be982016-05-11 13:52:53 -06001829
1830 VkImageCreateInfo image_create_info = {};
1831 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
1832 image_create_info.pNext = NULL;
1833 image_create_info.imageType = VK_IMAGE_TYPE_2D;
1834 image_create_info.format = VK_FORMAT_R8G8B8A8_UNORM;
1835 image_create_info.extent.width = 64;
1836 image_create_info.extent.height = 64;
1837 image_create_info.extent.depth = 1;
1838 image_create_info.mipLevels = 1;
1839 image_create_info.arrayLayers = 1;
1840 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
Tobin Ehlis12a4b5e2016-08-08 12:33:11 -06001841 // Image tiling must be optimal to trigger error when aliasing linear buffer
1842 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
Tobin Ehlisf11be982016-05-11 13:52:53 -06001843 image_create_info.initialLayout = VK_IMAGE_LAYOUT_PREINITIALIZED;
1844 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
1845 image_create_info.queueFamilyIndexCount = 0;
1846 image_create_info.pQueueFamilyIndices = NULL;
1847 image_create_info.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
1848 image_create_info.flags = 0;
1849
Tobin Ehlisf11be982016-05-11 13:52:53 -06001850 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
1851 ASSERT_VK_SUCCESS(err);
1852
Tobin Ehlis077ded32016-05-12 17:39:13 -06001853 vkGetImageMemoryRequirements(m_device->device(), image, &img_mem_reqs);
1854
1855 VkMemoryAllocateInfo alloc_info = {};
1856 alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
1857 alloc_info.pNext = NULL;
1858 alloc_info.memoryTypeIndex = 0;
1859 // Ensure memory is big enough for both bindings
1860 alloc_info.allocationSize = buff_mem_reqs.size + img_mem_reqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001861 pass = m_device->phy().set_memory_type(buff_mem_reqs.memoryTypeBits & img_mem_reqs.memoryTypeBits, &alloc_info,
1862 VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT);
Tobin Ehlisf11be982016-05-11 13:52:53 -06001863 if (!pass) {
Tobin Ehlis077ded32016-05-12 17:39:13 -06001864 vkDestroyBuffer(m_device->device(), buffer, NULL);
Tobin Ehlisf11be982016-05-11 13:52:53 -06001865 vkDestroyImage(m_device->device(), image, NULL);
1866 return;
1867 }
Tobin Ehlis077ded32016-05-12 17:39:13 -06001868 err = vkAllocateMemory(m_device->device(), &alloc_info, NULL, &mem);
1869 ASSERT_VK_SUCCESS(err);
1870 err = vkBindBufferMemory(m_device->device(), buffer, mem, 0);
1871 ASSERT_VK_SUCCESS(err);
1872
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001873 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " is aliased with linear buffer 0x");
Tobin Ehlis077ded32016-05-12 17:39:13 -06001874 // VALIDATION FAILURE due to image mapping overlapping buffer mapping
Tobin Ehlisf11be982016-05-11 13:52:53 -06001875 err = vkBindImageMemory(m_device->device(), image, mem, 0);
1876 m_errorMonitor->VerifyFound();
1877
1878 // Now correctly bind image to second mem allocation before incorrectly
Tobin Ehlis077ded32016-05-12 17:39:13 -06001879 // aliasing buffer2
1880 err = vkCreateBuffer(m_device->device(), &buf_info, NULL, &buffer2);
1881 ASSERT_VK_SUCCESS(err);
Tobin Ehlisf11be982016-05-11 13:52:53 -06001882 err = vkAllocateMemory(m_device->device(), &alloc_info, NULL, &mem_img);
1883 ASSERT_VK_SUCCESS(err);
1884 err = vkBindImageMemory(m_device->device(), image, mem_img, 0);
1885 ASSERT_VK_SUCCESS(err);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001886 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "is aliased with non-linear image 0x");
Tobin Ehlis077ded32016-05-12 17:39:13 -06001887 err = vkBindBufferMemory(m_device->device(), buffer2, mem_img, 0);
Tobin Ehlisf11be982016-05-11 13:52:53 -06001888 m_errorMonitor->VerifyFound();
1889
1890 vkDestroyBuffer(m_device->device(), buffer, NULL);
Tobin Ehlis077ded32016-05-12 17:39:13 -06001891 vkDestroyBuffer(m_device->device(), buffer2, NULL);
Tobin Ehlisf11be982016-05-11 13:52:53 -06001892 vkDestroyImage(m_device->device(), image, NULL);
1893 vkFreeMemory(m_device->device(), mem, NULL);
1894 vkFreeMemory(m_device->device(), mem_img, NULL);
1895}
1896
Tobin Ehlis35372522016-05-12 08:32:31 -06001897TEST_F(VkLayerTest, InvalidMemoryMapping) {
1898 TEST_DESCRIPTION("Attempt to map memory in a number of incorrect ways");
1899 VkResult err;
1900 bool pass;
1901 ASSERT_NO_FATAL_FAILURE(InitState());
1902
1903 VkBuffer buffer;
1904 VkDeviceMemory mem;
1905 VkMemoryRequirements mem_reqs;
1906
1907 VkBufferCreateInfo buf_info = {};
1908 buf_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
1909 buf_info.pNext = NULL;
1910 buf_info.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
1911 buf_info.size = 256;
1912 buf_info.queueFamilyIndexCount = 0;
1913 buf_info.pQueueFamilyIndices = NULL;
1914 buf_info.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
1915 buf_info.flags = 0;
1916 err = vkCreateBuffer(m_device->device(), &buf_info, NULL, &buffer);
1917 ASSERT_VK_SUCCESS(err);
1918
1919 vkGetBufferMemoryRequirements(m_device->device(), buffer, &mem_reqs);
1920 VkMemoryAllocateInfo alloc_info = {};
1921 alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
1922 alloc_info.pNext = NULL;
1923 alloc_info.memoryTypeIndex = 0;
1924
1925 // Ensure memory is big enough for both bindings
1926 static const VkDeviceSize allocation_size = 0x10000;
1927 alloc_info.allocationSize = allocation_size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001928 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 -06001929 if (!pass) {
1930 vkDestroyBuffer(m_device->device(), buffer, NULL);
1931 return;
1932 }
1933 err = vkAllocateMemory(m_device->device(), &alloc_info, NULL, &mem);
1934 ASSERT_VK_SUCCESS(err);
1935
1936 uint8_t *pData;
1937 // Attempt to map memory size 0 is invalid
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001938 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 -06001939 err = vkMapMemory(m_device->device(), mem, 0, 0, 0, (void **)&pData);
1940 m_errorMonitor->VerifyFound();
1941 // Map memory twice
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001942 err = vkMapMemory(m_device->device(), mem, 0, mem_reqs.size, 0, (void **)&pData);
Tobin Ehlis35372522016-05-12 08:32:31 -06001943 ASSERT_VK_SUCCESS(err);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001944 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
1945 "VkMapMemory: Attempting to map memory on an already-mapped object ");
1946 err = vkMapMemory(m_device->device(), mem, 0, mem_reqs.size, 0, (void **)&pData);
Tobin Ehlis35372522016-05-12 08:32:31 -06001947 m_errorMonitor->VerifyFound();
1948
1949 // Unmap the memory to avoid re-map error
1950 vkUnmapMemory(m_device->device(), mem);
1951 // overstep allocation with VK_WHOLE_SIZE
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001952 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
1953 " with size of VK_WHOLE_SIZE oversteps total array size 0x");
1954 err = vkMapMemory(m_device->device(), mem, allocation_size + 1, VK_WHOLE_SIZE, 0, (void **)&pData);
Tobin Ehlis35372522016-05-12 08:32:31 -06001955 m_errorMonitor->VerifyFound();
1956 // overstep allocation w/o VK_WHOLE_SIZE
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001957 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " oversteps total array size 0x");
1958 err = vkMapMemory(m_device->device(), mem, 1, allocation_size, 0, (void **)&pData);
Tobin Ehlis35372522016-05-12 08:32:31 -06001959 m_errorMonitor->VerifyFound();
1960 // Now error due to unmapping memory that's not mapped
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001961 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Unmapping Memory without memory being mapped: ");
Tobin Ehlis35372522016-05-12 08:32:31 -06001962 vkUnmapMemory(m_device->device(), mem);
1963 m_errorMonitor->VerifyFound();
1964 // Now map memory and cause errors due to flushing invalid ranges
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001965 err = vkMapMemory(m_device->device(), mem, 16, VK_WHOLE_SIZE, 0, (void **)&pData);
Tobin Ehlis35372522016-05-12 08:32:31 -06001966 ASSERT_VK_SUCCESS(err);
1967 VkMappedMemoryRange mmr = {};
Chris Forbes3aec0892016-06-13 10:29:26 +12001968 mmr.sType = VK_STRUCTURE_TYPE_MAPPED_MEMORY_RANGE;
Tobin Ehlis35372522016-05-12 08:32:31 -06001969 mmr.memory = mem;
1970 mmr.offset = 15; // Error b/c offset less than offset of mapped mem
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001971 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, ") is less than Memory Object's offset (");
Tobin Ehlis35372522016-05-12 08:32:31 -06001972 vkFlushMappedMemoryRanges(m_device->device(), 1, &mmr);
1973 m_errorMonitor->VerifyFound();
1974 // Now flush range that oversteps mapped range
1975 vkUnmapMemory(m_device->device(), mem);
1976 err = vkMapMemory(m_device->device(), mem, 0, 256, 0, (void **)&pData);
1977 ASSERT_VK_SUCCESS(err);
1978 mmr.offset = 16;
1979 mmr.size = 256; // flushing bounds (272) exceed mapped bounds (256)
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001980 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, ") exceeds the Memory Object's upper-bound (");
Tobin Ehlis35372522016-05-12 08:32:31 -06001981 vkFlushMappedMemoryRanges(m_device->device(), 1, &mmr);
1982 m_errorMonitor->VerifyFound();
1983
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001984 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &alloc_info, VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT,
1985 VK_MEMORY_PROPERTY_HOST_COHERENT_BIT);
Tobin Ehlis35372522016-05-12 08:32:31 -06001986 if (!pass) {
1987 vkFreeMemory(m_device->device(), mem, NULL);
1988 vkDestroyBuffer(m_device->device(), buffer, NULL);
1989 return;
1990 }
1991 // TODO : If we can get HOST_VISIBLE w/o HOST_COHERENT we can test cases of
1992 // MEMTRACK_INVALID_MAP in validateAndCopyNoncoherentMemoryToDriver()
1993
1994 vkDestroyBuffer(m_device->device(), buffer, NULL);
1995 vkFreeMemory(m_device->device(), mem, NULL);
1996}
1997
Mark Lobodzinski1f515922016-08-16 10:03:30 -06001998TEST_F(VkLayerTest, NonCoherentMemoryMapping) {
1999
2000 TEST_DESCRIPTION("Ensure that validations handling of non-coherent memory "
2001 "mapping while using VK_WHOLE_SIZE does not cause access "
2002 "violations");
2003 VkResult err;
2004 uint8_t *pData;
2005 ASSERT_NO_FATAL_FAILURE(InitState());
2006
2007 VkDeviceMemory mem;
2008 VkMemoryRequirements mem_reqs;
2009 mem_reqs.memoryTypeBits = 0xFFFFFFFF;
2010 VkMemoryAllocateInfo alloc_info = {};
2011 alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
2012 alloc_info.pNext = NULL;
2013 alloc_info.memoryTypeIndex = 0;
2014
2015 static const VkDeviceSize allocation_size = 0x1000;
2016 alloc_info.allocationSize = allocation_size;
2017
2018 // Find a memory configurations WITHOUT a COHERENT bit, otherwise exit
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002019 bool pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &alloc_info, VK_MEMORY_PROPERTY_HOST_VISIBLE_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_COHERENT_BIT);
Mark Lobodzinski1f515922016-08-16 10:03:30 -06002025 if (!pass) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002026 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &alloc_info,
2027 VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT |
2028 VK_MEMORY_PROPERTY_HOST_CACHED_BIT,
2029 VK_MEMORY_PROPERTY_HOST_COHERENT_BIT);
Mark Lobodzinski1f515922016-08-16 10:03:30 -06002030 if (!pass) {
2031 return;
2032 }
2033 }
2034 }
2035
2036 err = vkAllocateMemory(m_device->device(), &alloc_info, NULL, &mem);
2037 ASSERT_VK_SUCCESS(err);
2038
2039 // Map/Flush/Invalidate using WHOLE_SIZE and zero offsets and entire
2040 // mapped range
2041 m_errorMonitor->ExpectSuccess();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002042 err = vkMapMemory(m_device->device(), mem, 0, VK_WHOLE_SIZE, 0, (void **)&pData);
Mark Lobodzinski1f515922016-08-16 10:03:30 -06002043 ASSERT_VK_SUCCESS(err);
2044 VkMappedMemoryRange mmr = {};
2045 mmr.sType = VK_STRUCTURE_TYPE_MAPPED_MEMORY_RANGE;
2046 mmr.memory = mem;
2047 mmr.offset = 0;
2048 mmr.size = VK_WHOLE_SIZE;
2049 err = vkFlushMappedMemoryRanges(m_device->device(), 1, &mmr);
2050 ASSERT_VK_SUCCESS(err);
2051 err = vkInvalidateMappedMemoryRanges(m_device->device(), 1, &mmr);
2052 ASSERT_VK_SUCCESS(err);
2053 m_errorMonitor->VerifyNotFound();
2054 vkUnmapMemory(m_device->device(), mem);
2055
2056 // Map/Flush/Invalidate using WHOLE_SIZE and a prime offset and entire
2057 // mapped range
2058 m_errorMonitor->ExpectSuccess();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002059 err = vkMapMemory(m_device->device(), mem, 13, VK_WHOLE_SIZE, 0, (void **)&pData);
Mark Lobodzinski1f515922016-08-16 10:03:30 -06002060 ASSERT_VK_SUCCESS(err);
2061 mmr.sType = VK_STRUCTURE_TYPE_MAPPED_MEMORY_RANGE;
2062 mmr.memory = mem;
2063 mmr.offset = 13;
2064 mmr.size = VK_WHOLE_SIZE;
2065 err = vkFlushMappedMemoryRanges(m_device->device(), 1, &mmr);
2066 ASSERT_VK_SUCCESS(err);
2067 err = vkInvalidateMappedMemoryRanges(m_device->device(), 1, &mmr);
2068 ASSERT_VK_SUCCESS(err);
2069 m_errorMonitor->VerifyNotFound();
2070 vkUnmapMemory(m_device->device(), mem);
2071
2072 // Map with prime offset and size
2073 // Flush/Invalidate subrange of mapped area with prime offset and size
2074 m_errorMonitor->ExpectSuccess();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002075 err = vkMapMemory(m_device->device(), mem, allocation_size - 137, 109, 0, (void **)&pData);
Mark Lobodzinski1f515922016-08-16 10:03:30 -06002076 ASSERT_VK_SUCCESS(err);
2077 mmr.sType = VK_STRUCTURE_TYPE_MAPPED_MEMORY_RANGE;
2078 mmr.memory = mem;
2079 mmr.offset = allocation_size - 107;
2080 mmr.size = 61;
2081 err = vkFlushMappedMemoryRanges(m_device->device(), 1, &mmr);
2082 ASSERT_VK_SUCCESS(err);
2083 err = vkInvalidateMappedMemoryRanges(m_device->device(), 1, &mmr);
2084 ASSERT_VK_SUCCESS(err);
2085 m_errorMonitor->VerifyNotFound();
2086 vkUnmapMemory(m_device->device(), mem);
2087
2088 vkFreeMemory(m_device->device(), mem, NULL);
2089}
2090
Ian Elliott1c32c772016-04-28 14:47:13 -06002091TEST_F(VkLayerTest, EnableWsiBeforeUse) {
2092 VkResult err;
2093 bool pass;
2094
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002095 // FIXME: After we turn on this code for non-Linux platforms, uncomment the
2096 // following declaration (which is temporarily being moved below):
2097 // VkSurfaceKHR surface = VK_NULL_HANDLE;
Ian Elliott1c32c772016-04-28 14:47:13 -06002098 VkSwapchainKHR swapchain = VK_NULL_HANDLE;
2099 VkSwapchainCreateInfoKHR swapchain_create_info = {};
2100 uint32_t swapchain_image_count = 0;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002101 // VkImage swapchain_images[1] = {VK_NULL_HANDLE};
Ian Elliott1c32c772016-04-28 14:47:13 -06002102 uint32_t image_index = 0;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002103 // VkPresentInfoKHR present_info = {};
Ian Elliott1c32c772016-04-28 14:47:13 -06002104
2105 ASSERT_NO_FATAL_FAILURE(InitState());
2106
Ian Elliott3f06ce52016-04-29 14:46:21 -06002107#ifdef NEED_TO_TEST_THIS_ON_PLATFORM
2108#if defined(VK_USE_PLATFORM_ANDROID_KHR)
2109 // Use the functions from the VK_KHR_android_surface extension without
2110 // enabling that extension:
2111
2112 // Create a surface:
2113 VkAndroidSurfaceCreateInfoKHR android_create_info = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002114 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
2115 err = vkCreateAndroidSurfaceKHR(instance(), &android_create_info, NULL, &surface);
Ian Elliott3f06ce52016-04-29 14:46:21 -06002116 pass = (err != VK_SUCCESS);
2117 ASSERT_TRUE(pass);
2118 m_errorMonitor->VerifyFound();
2119#endif // VK_USE_PLATFORM_ANDROID_KHR
2120
Ian Elliott3f06ce52016-04-29 14:46:21 -06002121#if defined(VK_USE_PLATFORM_MIR_KHR)
2122 // Use the functions from the VK_KHR_mir_surface extension without enabling
2123 // that extension:
2124
2125 // Create a surface:
2126 VkMirSurfaceCreateInfoKHR mir_create_info = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002127 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
Ian Elliott3f06ce52016-04-29 14:46:21 -06002128 err = vkCreateMirSurfaceKHR(instance(), &mir_create_info, NULL, &surface);
2129 pass = (err != VK_SUCCESS);
2130 ASSERT_TRUE(pass);
2131 m_errorMonitor->VerifyFound();
2132
2133 // Tell whether an mir_connection supports presentation:
2134 MirConnection *mir_connection = NULL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002135 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
2136 vkGetPhysicalDeviceMirPresentationSupportKHR(gpu(), 0, mir_connection, visual_id);
Ian Elliott3f06ce52016-04-29 14:46:21 -06002137 m_errorMonitor->VerifyFound();
2138#endif // VK_USE_PLATFORM_MIR_KHR
2139
Ian Elliott3f06ce52016-04-29 14:46:21 -06002140#if defined(VK_USE_PLATFORM_WAYLAND_KHR)
2141 // Use the functions from the VK_KHR_wayland_surface extension without
2142 // enabling that extension:
2143
2144 // Create a surface:
2145 VkWaylandSurfaceCreateInfoKHR wayland_create_info = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002146 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
2147 err = vkCreateWaylandSurfaceKHR(instance(), &wayland_create_info, NULL, &surface);
Ian Elliott3f06ce52016-04-29 14:46:21 -06002148 pass = (err != VK_SUCCESS);
2149 ASSERT_TRUE(pass);
2150 m_errorMonitor->VerifyFound();
2151
2152 // Tell whether an wayland_display supports presentation:
2153 struct wl_display wayland_display = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002154 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
2155 vkGetPhysicalDeviceWaylandPresentationSupportKHR(gpu(), 0, &wayland_display);
Ian Elliott3f06ce52016-04-29 14:46:21 -06002156 m_errorMonitor->VerifyFound();
2157#endif // VK_USE_PLATFORM_WAYLAND_KHR
Ian Elliott489eec02016-05-05 14:12:44 -06002158#endif // NEED_TO_TEST_THIS_ON_PLATFORM
Ian Elliott3f06ce52016-04-29 14:46:21 -06002159
Ian Elliott3f06ce52016-04-29 14:46:21 -06002160#if defined(VK_USE_PLATFORM_WIN32_KHR)
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002161 // FIXME: REMOVE THIS HERE, AND UNCOMMENT ABOVE, WHEN THIS TEST HAS BEEN PORTED
2162 // TO NON-LINUX PLATFORMS:
2163 VkSurfaceKHR surface = VK_NULL_HANDLE;
Ian Elliott3f06ce52016-04-29 14:46:21 -06002164 // Use the functions from the VK_KHR_win32_surface extension without
2165 // enabling that extension:
2166
2167 // Create a surface:
2168 VkWin32SurfaceCreateInfoKHR win32_create_info = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002169 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
2170 err = vkCreateWin32SurfaceKHR(instance(), &win32_create_info, NULL, &surface);
Ian Elliott3f06ce52016-04-29 14:46:21 -06002171 pass = (err != VK_SUCCESS);
2172 ASSERT_TRUE(pass);
2173 m_errorMonitor->VerifyFound();
2174
2175 // Tell whether win32 supports presentation:
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002176 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
Ian Elliott489eec02016-05-05 14:12:44 -06002177 vkGetPhysicalDeviceWin32PresentationSupportKHR(gpu(), 0);
Ian Elliott3f06ce52016-04-29 14:46:21 -06002178 m_errorMonitor->VerifyFound();
Ian Elliott489eec02016-05-05 14:12:44 -06002179// Set this (for now, until all platforms are supported and tested):
2180#define NEED_TO_TEST_THIS_ON_PLATFORM
2181#endif // VK_USE_PLATFORM_WIN32_KHR
Ian Elliott3f06ce52016-04-29 14:46:21 -06002182
Ian Elliott1c32c772016-04-28 14:47:13 -06002183#if defined(VK_USE_PLATFORM_XCB_KHR)
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002184 // FIXME: REMOVE THIS HERE, AND UNCOMMENT ABOVE, WHEN THIS TEST HAS BEEN PORTED
2185 // TO NON-LINUX PLATFORMS:
2186 VkSurfaceKHR surface = VK_NULL_HANDLE;
Ian Elliott1c32c772016-04-28 14:47:13 -06002187 // Use the functions from the VK_KHR_xcb_surface extension without enabling
2188 // that extension:
2189
2190 // Create a surface:
2191 VkXcbSurfaceCreateInfoKHR xcb_create_info = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002192 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
Ian Elliott1c32c772016-04-28 14:47:13 -06002193 err = vkCreateXcbSurfaceKHR(instance(), &xcb_create_info, NULL, &surface);
2194 pass = (err != VK_SUCCESS);
2195 ASSERT_TRUE(pass);
2196 m_errorMonitor->VerifyFound();
2197
2198 // Tell whether an xcb_visualid_t supports presentation:
Ian Elliott3f06ce52016-04-29 14:46:21 -06002199 xcb_connection_t *xcb_connection = NULL;
Ian Elliott1c32c772016-04-28 14:47:13 -06002200 xcb_visualid_t visual_id = 0;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002201 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
2202 vkGetPhysicalDeviceXcbPresentationSupportKHR(gpu(), 0, xcb_connection, visual_id);
Ian Elliott1c32c772016-04-28 14:47:13 -06002203 m_errorMonitor->VerifyFound();
Ian Elliott489eec02016-05-05 14:12:44 -06002204// Set this (for now, until all platforms are supported and tested):
2205#define NEED_TO_TEST_THIS_ON_PLATFORM
Ian Elliott1c32c772016-04-28 14:47:13 -06002206#endif // VK_USE_PLATFORM_XCB_KHR
2207
Ian Elliott12630812016-04-29 14:35:43 -06002208#if defined(VK_USE_PLATFORM_XLIB_KHR)
2209 // Use the functions from the VK_KHR_xlib_surface extension without enabling
2210 // that extension:
2211
2212 // Create a surface:
2213 VkXlibSurfaceCreateInfoKHR xlib_create_info = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002214 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
Ian Elliott12630812016-04-29 14:35:43 -06002215 err = vkCreateXlibSurfaceKHR(instance(), &xlib_create_info, NULL, &surface);
2216 pass = (err != VK_SUCCESS);
2217 ASSERT_TRUE(pass);
2218 m_errorMonitor->VerifyFound();
2219
2220 // Tell whether an Xlib VisualID supports presentation:
2221 Display *dpy = NULL;
2222 VisualID visual = 0;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002223 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
Ian Elliott12630812016-04-29 14:35:43 -06002224 vkGetPhysicalDeviceXlibPresentationSupportKHR(gpu(), 0, dpy, visual);
2225 m_errorMonitor->VerifyFound();
Ian Elliott489eec02016-05-05 14:12:44 -06002226// Set this (for now, until all platforms are supported and tested):
2227#define NEED_TO_TEST_THIS_ON_PLATFORM
Ian Elliott12630812016-04-29 14:35:43 -06002228#endif // VK_USE_PLATFORM_XLIB_KHR
2229
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002230// Use the functions from the VK_KHR_surface extension without enabling
2231// that extension:
Ian Elliott1c32c772016-04-28 14:47:13 -06002232
Ian Elliott489eec02016-05-05 14:12:44 -06002233#ifdef NEED_TO_TEST_THIS_ON_PLATFORM
Ian Elliott1c32c772016-04-28 14:47:13 -06002234 // Destroy a surface:
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002235 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
Ian Elliott1c32c772016-04-28 14:47:13 -06002236 vkDestroySurfaceKHR(instance(), surface, NULL);
2237 m_errorMonitor->VerifyFound();
2238
2239 // Check if surface supports presentation:
2240 VkBool32 supported = false;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002241 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
Ian Elliott1c32c772016-04-28 14:47:13 -06002242 err = vkGetPhysicalDeviceSurfaceSupportKHR(gpu(), 0, surface, &supported);
2243 pass = (err != VK_SUCCESS);
2244 ASSERT_TRUE(pass);
2245 m_errorMonitor->VerifyFound();
2246
2247 // Check surface capabilities:
2248 VkSurfaceCapabilitiesKHR capabilities = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002249 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
2250 err = vkGetPhysicalDeviceSurfaceCapabilitiesKHR(gpu(), surface, &capabilities);
Ian Elliott1c32c772016-04-28 14:47:13 -06002251 pass = (err != VK_SUCCESS);
2252 ASSERT_TRUE(pass);
2253 m_errorMonitor->VerifyFound();
2254
2255 // Check surface formats:
2256 uint32_t format_count = 0;
2257 VkSurfaceFormatKHR *formats = NULL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002258 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
2259 err = vkGetPhysicalDeviceSurfaceFormatsKHR(gpu(), surface, &format_count, formats);
Ian Elliott1c32c772016-04-28 14:47:13 -06002260 pass = (err != VK_SUCCESS);
2261 ASSERT_TRUE(pass);
2262 m_errorMonitor->VerifyFound();
2263
2264 // Check surface present modes:
2265 uint32_t present_mode_count = 0;
2266 VkSurfaceFormatKHR *present_modes = NULL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002267 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
2268 err = vkGetPhysicalDeviceSurfaceFormatsKHR(gpu(), surface, &present_mode_count, present_modes);
Ian Elliott1c32c772016-04-28 14:47:13 -06002269 pass = (err != VK_SUCCESS);
2270 ASSERT_TRUE(pass);
2271 m_errorMonitor->VerifyFound();
Ian Elliott489eec02016-05-05 14:12:44 -06002272#endif // NEED_TO_TEST_THIS_ON_PLATFORM
Ian Elliott1c32c772016-04-28 14:47:13 -06002273
Ian Elliott1c32c772016-04-28 14:47:13 -06002274 // Use the functions from the VK_KHR_swapchain extension without enabling
2275 // that extension:
2276
2277 // Create a swapchain:
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002278 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
Ian Elliott1c32c772016-04-28 14:47:13 -06002279 swapchain_create_info.sType = VK_STRUCTURE_TYPE_SWAPCHAIN_CREATE_INFO_KHR;
2280 swapchain_create_info.pNext = NULL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002281 err = vkCreateSwapchainKHR(m_device->device(), &swapchain_create_info, NULL, &swapchain);
Ian Elliott1c32c772016-04-28 14:47:13 -06002282 pass = (err != VK_SUCCESS);
2283 ASSERT_TRUE(pass);
2284 m_errorMonitor->VerifyFound();
2285
2286 // Get the images from the swapchain:
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002287 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
2288 err = vkGetSwapchainImagesKHR(m_device->device(), swapchain, &swapchain_image_count, NULL);
Ian Elliott1c32c772016-04-28 14:47:13 -06002289 pass = (err != VK_SUCCESS);
2290 ASSERT_TRUE(pass);
2291 m_errorMonitor->VerifyFound();
2292
Chris Forbeseb7d5502016-09-13 18:19:21 +12002293 // Add a fence to avoid (justifiable) error about not providing fence OR semaphore
2294 VkFenceCreateInfo fci = { VK_STRUCTURE_TYPE_FENCE_CREATE_INFO, nullptr, 0 };
2295 VkFence fence;
2296 err = vkCreateFence(m_device->device(), &fci, nullptr, &fence);
2297
Ian Elliott1c32c772016-04-28 14:47:13 -06002298 // Try to acquire an image:
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002299 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
Chris Forbeseb7d5502016-09-13 18:19:21 +12002300 err = vkAcquireNextImageKHR(m_device->device(), swapchain, 0, VK_NULL_HANDLE, fence, &image_index);
Ian Elliott1c32c772016-04-28 14:47:13 -06002301 pass = (err != VK_SUCCESS);
2302 ASSERT_TRUE(pass);
2303 m_errorMonitor->VerifyFound();
2304
Chris Forbeseb7d5502016-09-13 18:19:21 +12002305 vkDestroyFence(m_device->device(), fence, nullptr);
2306
Ian Elliott1c32c772016-04-28 14:47:13 -06002307 // Try to present an image:
Ian Elliott2c1daf52016-05-12 09:41:46 -06002308 //
2309 // NOTE: Currently can't test this because a real swapchain is needed (as
2310 // opposed to the fake one we created) in order for the layer to lookup the
2311 // VkDevice used to enable the extension:
Ian Elliott1c32c772016-04-28 14:47:13 -06002312
2313 // Destroy the swapchain:
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002314 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
Ian Elliott1c32c772016-04-28 14:47:13 -06002315 vkDestroySwapchainKHR(m_device->device(), swapchain, NULL);
2316 m_errorMonitor->VerifyFound();
2317}
2318
Ian Elliott2c1daf52016-05-12 09:41:46 -06002319TEST_F(VkWsiEnabledLayerTest, TestEnabledWsi) {
Ian Elliott2c1daf52016-05-12 09:41:46 -06002320
Dustin Graves6c6d8982016-05-17 10:09:21 -06002321#if defined(VK_USE_PLATFORM_XCB_KHR)
Ian Elliott2c1daf52016-05-12 09:41:46 -06002322 VkSurfaceKHR surface = VK_NULL_HANDLE;
Mark Lobodzinski085d27a2016-05-17 09:34:26 -06002323
Mark Lobodzinski085d27a2016-05-17 09:34:26 -06002324 VkResult err;
2325 bool pass;
Ian Elliott2c1daf52016-05-12 09:41:46 -06002326 VkSwapchainKHR swapchain = VK_NULL_HANDLE;
2327 VkSwapchainCreateInfoKHR swapchain_create_info = {};
Mark Lobodzinski085d27a2016-05-17 09:34:26 -06002328 // uint32_t swapchain_image_count = 0;
2329 // VkImage swapchain_images[1] = {VK_NULL_HANDLE};
2330 // uint32_t image_index = 0;
2331 // VkPresentInfoKHR present_info = {};
Ian Elliott2c1daf52016-05-12 09:41:46 -06002332
2333 ASSERT_NO_FATAL_FAILURE(InitState());
2334
2335 // Use the create function from one of the VK_KHR_*_surface extension in
2336 // order to create a surface, testing all known errors in the process,
2337 // before successfully creating a surface:
2338 // First, try to create a surface without a VkXcbSurfaceCreateInfoKHR:
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002339 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "required parameter pCreateInfo specified as NULL");
Ian Elliott2c1daf52016-05-12 09:41:46 -06002340 err = vkCreateXcbSurfaceKHR(instance(), NULL, NULL, &surface);
2341 pass = (err != VK_SUCCESS);
2342 ASSERT_TRUE(pass);
2343 m_errorMonitor->VerifyFound();
2344
2345 // Next, try to create a surface with the wrong
2346 // VkXcbSurfaceCreateInfoKHR::sType:
2347 VkXcbSurfaceCreateInfoKHR xcb_create_info = {};
2348 xcb_create_info.sType = VK_STRUCTURE_TYPE_APPLICATION_INFO;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002349 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "parameter pCreateInfo->sType must be");
Ian Elliott2c1daf52016-05-12 09:41:46 -06002350 err = vkCreateXcbSurfaceKHR(instance(), &xcb_create_info, NULL, &surface);
2351 pass = (err != VK_SUCCESS);
2352 ASSERT_TRUE(pass);
2353 m_errorMonitor->VerifyFound();
2354
Ian Elliott2c1daf52016-05-12 09:41:46 -06002355 // Create a native window, and then correctly create a surface:
2356 xcb_connection_t *connection;
2357 xcb_screen_t *screen;
2358 xcb_window_t xcb_window;
2359 xcb_intern_atom_reply_t *atom_wm_delete_window;
2360
2361 const xcb_setup_t *setup;
2362 xcb_screen_iterator_t iter;
2363 int scr;
2364 uint32_t value_mask, value_list[32];
2365 int width = 1;
2366 int height = 1;
2367
2368 connection = xcb_connect(NULL, &scr);
2369 ASSERT_TRUE(connection != NULL);
2370 setup = xcb_get_setup(connection);
2371 iter = xcb_setup_roots_iterator(setup);
2372 while (scr-- > 0)
2373 xcb_screen_next(&iter);
2374 screen = iter.data;
2375
2376 xcb_window = xcb_generate_id(connection);
2377
2378 value_mask = XCB_CW_BACK_PIXEL | XCB_CW_EVENT_MASK;
2379 value_list[0] = screen->black_pixel;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002380 value_list[1] = XCB_EVENT_MASK_KEY_RELEASE | XCB_EVENT_MASK_EXPOSURE | XCB_EVENT_MASK_STRUCTURE_NOTIFY;
Ian Elliott2c1daf52016-05-12 09:41:46 -06002381
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002382 xcb_create_window(connection, XCB_COPY_FROM_PARENT, xcb_window, screen->root, 0, 0, width, height, 0,
2383 XCB_WINDOW_CLASS_INPUT_OUTPUT, screen->root_visual, value_mask, value_list);
Ian Elliott2c1daf52016-05-12 09:41:46 -06002384
2385 /* Magic code that will send notification when window is destroyed */
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002386 xcb_intern_atom_cookie_t cookie = xcb_intern_atom(connection, 1, 12, "WM_PROTOCOLS");
2387 xcb_intern_atom_reply_t *reply = xcb_intern_atom_reply(connection, cookie, 0);
Ian Elliott2c1daf52016-05-12 09:41:46 -06002388
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002389 xcb_intern_atom_cookie_t cookie2 = xcb_intern_atom(connection, 0, 16, "WM_DELETE_WINDOW");
Mark Lobodzinski085d27a2016-05-17 09:34:26 -06002390 atom_wm_delete_window = xcb_intern_atom_reply(connection, cookie2, 0);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002391 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 -06002392 free(reply);
2393
2394 xcb_map_window(connection, xcb_window);
2395
2396 // Force the x/y coordinates to 100,100 results are identical in consecutive
2397 // runs
2398 const uint32_t coords[] = {100, 100};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002399 xcb_configure_window(connection, xcb_window, XCB_CONFIG_WINDOW_X | XCB_CONFIG_WINDOW_Y, coords);
Ian Elliott2c1daf52016-05-12 09:41:46 -06002400
Ian Elliott2c1daf52016-05-12 09:41:46 -06002401 // Finally, try to correctly create a surface:
2402 xcb_create_info.sType = VK_STRUCTURE_TYPE_XCB_SURFACE_CREATE_INFO_KHR;
2403 xcb_create_info.pNext = NULL;
2404 xcb_create_info.flags = 0;
2405 xcb_create_info.connection = connection;
2406 xcb_create_info.window = xcb_window;
2407 err = vkCreateXcbSurfaceKHR(instance(), &xcb_create_info, NULL, &surface);
2408 pass = (err == VK_SUCCESS);
2409 ASSERT_TRUE(pass);
2410
Ian Elliott2c1daf52016-05-12 09:41:46 -06002411 // Check if surface supports presentation:
2412
2413 // 1st, do so without having queried the queue families:
2414 VkBool32 supported = false;
2415 // TODO: Get the following error to come out:
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002416 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
2417 "called before calling the vkGetPhysicalDeviceQueueFamilyProperties "
2418 "function");
Ian Elliott2c1daf52016-05-12 09:41:46 -06002419 err = vkGetPhysicalDeviceSurfaceSupportKHR(gpu(), 0, surface, &supported);
2420 pass = (err != VK_SUCCESS);
Mark Lobodzinski085d27a2016-05-17 09:34:26 -06002421 // ASSERT_TRUE(pass);
2422 // m_errorMonitor->VerifyFound();
Ian Elliott2c1daf52016-05-12 09:41:46 -06002423
2424 // Next, query a queue family index that's too large:
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002425 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "called with a queueFamilyIndex that is too large");
2426 err = vkGetPhysicalDeviceSurfaceSupportKHR(gpu(), 100000, surface, &supported);
Ian Elliott2c1daf52016-05-12 09:41:46 -06002427 pass = (err != VK_SUCCESS);
2428 ASSERT_TRUE(pass);
2429 m_errorMonitor->VerifyFound();
2430
2431 // Finally, do so correctly:
Mark Lobodzinski085d27a2016-05-17 09:34:26 -06002432 // FIXME: THIS ISN'T CORRECT--MUST QUERY UNTIL WE FIND A QUEUE FAMILY THAT'S
2433 // SUPPORTED
Ian Elliott2c1daf52016-05-12 09:41:46 -06002434 err = vkGetPhysicalDeviceSurfaceSupportKHR(gpu(), 0, surface, &supported);
2435 pass = (err == VK_SUCCESS);
2436 ASSERT_TRUE(pass);
2437
Ian Elliott2c1daf52016-05-12 09:41:46 -06002438 // Before proceeding, try to create a swapchain without having called
2439 // vkGetPhysicalDeviceSurfaceCapabilitiesKHR():
2440 swapchain_create_info.sType = VK_STRUCTURE_TYPE_SWAPCHAIN_CREATE_INFO_KHR;
2441 swapchain_create_info.pNext = NULL;
2442 swapchain_create_info.flags = 0;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002443 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
2444 "called before calling vkGetPhysicalDeviceSurfaceCapabilitiesKHR().");
2445 err = vkCreateSwapchainKHR(m_device->device(), &swapchain_create_info, NULL, &swapchain);
Ian Elliott2c1daf52016-05-12 09:41:46 -06002446 pass = (err != VK_SUCCESS);
2447 ASSERT_TRUE(pass);
2448 m_errorMonitor->VerifyFound();
2449
Ian Elliott2c1daf52016-05-12 09:41:46 -06002450 // Get the surface capabilities:
2451 VkSurfaceCapabilitiesKHR surface_capabilities;
2452
2453 // Do so correctly (only error logged by this entrypoint is if the
2454 // extension isn't enabled):
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002455 err = vkGetPhysicalDeviceSurfaceCapabilitiesKHR(gpu(), surface, &surface_capabilities);
Ian Elliott2c1daf52016-05-12 09:41:46 -06002456 pass = (err == VK_SUCCESS);
2457 ASSERT_TRUE(pass);
2458
Ian Elliott2c1daf52016-05-12 09:41:46 -06002459 // Get the surface formats:
2460 uint32_t surface_format_count;
2461
2462 // First, try without a pointer to surface_format_count:
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002463 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "required parameter pSurfaceFormatCount "
2464 "specified as NULL");
Ian Elliott2c1daf52016-05-12 09:41:46 -06002465 vkGetPhysicalDeviceSurfaceFormatsKHR(gpu(), surface, NULL, NULL);
2466 pass = (err == VK_SUCCESS);
2467 ASSERT_TRUE(pass);
2468 m_errorMonitor->VerifyFound();
2469
2470 // Next, call with a non-NULL pSurfaceFormats, even though we haven't
2471 // correctly done a 1st try (to get the count):
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002472 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 -06002473 surface_format_count = 0;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002474 vkGetPhysicalDeviceSurfaceFormatsKHR(gpu(), surface, &surface_format_count, (VkSurfaceFormatKHR *)&surface_format_count);
Ian Elliott2c1daf52016-05-12 09:41:46 -06002475 pass = (err == VK_SUCCESS);
2476 ASSERT_TRUE(pass);
2477 m_errorMonitor->VerifyFound();
2478
2479 // Next, correctly do a 1st try (with a NULL pointer to surface_formats):
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002480 vkGetPhysicalDeviceSurfaceFormatsKHR(gpu(), surface, &surface_format_count, NULL);
Ian Elliott2c1daf52016-05-12 09:41:46 -06002481 pass = (err == VK_SUCCESS);
2482 ASSERT_TRUE(pass);
2483
2484 // Allocate memory for the correct number of VkSurfaceFormatKHR's:
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002485 VkSurfaceFormatKHR *surface_formats = (VkSurfaceFormatKHR *)malloc(surface_format_count * sizeof(VkSurfaceFormatKHR));
Ian Elliott2c1daf52016-05-12 09:41:46 -06002486
2487 // Next, do a 2nd try with surface_format_count being set too high:
2488 surface_format_count += 5;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002489 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "that is greater than the value");
2490 vkGetPhysicalDeviceSurfaceFormatsKHR(gpu(), surface, &surface_format_count, surface_formats);
Ian Elliott2c1daf52016-05-12 09:41:46 -06002491 pass = (err == VK_SUCCESS);
2492 ASSERT_TRUE(pass);
2493 m_errorMonitor->VerifyFound();
2494
2495 // Finally, do a correct 1st and 2nd try:
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002496 vkGetPhysicalDeviceSurfaceFormatsKHR(gpu(), surface, &surface_format_count, NULL);
Ian Elliott2c1daf52016-05-12 09:41:46 -06002497 pass = (err == VK_SUCCESS);
2498 ASSERT_TRUE(pass);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002499 vkGetPhysicalDeviceSurfaceFormatsKHR(gpu(), surface, &surface_format_count, surface_formats);
Ian Elliott2c1daf52016-05-12 09:41:46 -06002500 pass = (err == VK_SUCCESS);
2501 ASSERT_TRUE(pass);
2502
Ian Elliott2c1daf52016-05-12 09:41:46 -06002503 // Get the surface present modes:
2504 uint32_t surface_present_mode_count;
2505
2506 // First, try without a pointer to surface_format_count:
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002507 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "required parameter pPresentModeCount "
2508 "specified as NULL");
Mark Lobodzinskib02ea642016-08-17 13:03:57 -06002509
Ian Elliott2c1daf52016-05-12 09:41:46 -06002510 vkGetPhysicalDeviceSurfacePresentModesKHR(gpu(), surface, NULL, NULL);
2511 pass = (err == VK_SUCCESS);
2512 ASSERT_TRUE(pass);
2513 m_errorMonitor->VerifyFound();
2514
2515 // Next, call with a non-NULL VkPresentModeKHR, even though we haven't
2516 // correctly done a 1st try (to get the count):
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002517 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 -06002518 surface_present_mode_count = 0;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002519 vkGetPhysicalDeviceSurfacePresentModesKHR(gpu(), surface, &surface_present_mode_count,
2520 (VkPresentModeKHR *)&surface_present_mode_count);
Ian Elliott2c1daf52016-05-12 09:41:46 -06002521 pass = (err == VK_SUCCESS);
2522 ASSERT_TRUE(pass);
2523 m_errorMonitor->VerifyFound();
2524
2525 // Next, correctly do a 1st try (with a NULL pointer to surface_formats):
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002526 vkGetPhysicalDeviceSurfacePresentModesKHR(gpu(), surface, &surface_present_mode_count, NULL);
Ian Elliott2c1daf52016-05-12 09:41:46 -06002527 pass = (err == VK_SUCCESS);
2528 ASSERT_TRUE(pass);
2529
2530 // Allocate memory for the correct number of VkSurfaceFormatKHR's:
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002531 VkPresentModeKHR *surface_present_modes = (VkPresentModeKHR *)malloc(surface_present_mode_count * sizeof(VkPresentModeKHR));
Ian Elliott2c1daf52016-05-12 09:41:46 -06002532
2533 // Next, do a 2nd try with surface_format_count being set too high:
2534 surface_present_mode_count += 5;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002535 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "that is greater than the value");
2536 vkGetPhysicalDeviceSurfacePresentModesKHR(gpu(), surface, &surface_present_mode_count, surface_present_modes);
Ian Elliott2c1daf52016-05-12 09:41:46 -06002537 pass = (err == VK_SUCCESS);
2538 ASSERT_TRUE(pass);
2539 m_errorMonitor->VerifyFound();
2540
2541 // Finally, do a correct 1st and 2nd try:
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002542 vkGetPhysicalDeviceSurfacePresentModesKHR(gpu(), surface, &surface_present_mode_count, NULL);
Ian Elliott2c1daf52016-05-12 09:41:46 -06002543 pass = (err == VK_SUCCESS);
2544 ASSERT_TRUE(pass);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002545 vkGetPhysicalDeviceSurfacePresentModesKHR(gpu(), surface, &surface_present_mode_count, surface_present_modes);
Ian Elliott2c1daf52016-05-12 09:41:46 -06002546 pass = (err == VK_SUCCESS);
2547 ASSERT_TRUE(pass);
2548
Ian Elliott2c1daf52016-05-12 09:41:46 -06002549 // Create a swapchain:
2550
2551 // First, try without a pointer to swapchain_create_info:
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002552 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "required parameter pCreateInfo "
2553 "specified as NULL");
Mark Lobodzinskib02ea642016-08-17 13:03:57 -06002554
Ian Elliott2c1daf52016-05-12 09:41:46 -06002555 err = vkCreateSwapchainKHR(m_device->device(), NULL, NULL, &swapchain);
2556 pass = (err != VK_SUCCESS);
2557 ASSERT_TRUE(pass);
2558 m_errorMonitor->VerifyFound();
2559
2560 // Next, call with a non-NULL swapchain_create_info, that has the wrong
2561 // sType:
2562 swapchain_create_info.sType = VK_STRUCTURE_TYPE_APPLICATION_INFO;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002563 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "parameter pCreateInfo->sType must be");
Mark Lobodzinskib02ea642016-08-17 13:03:57 -06002564
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002565 err = vkCreateSwapchainKHR(m_device->device(), &swapchain_create_info, NULL, &swapchain);
Ian Elliott2c1daf52016-05-12 09:41:46 -06002566 pass = (err != VK_SUCCESS);
2567 ASSERT_TRUE(pass);
2568 m_errorMonitor->VerifyFound();
2569
2570 // Next, call with a NULL swapchain pointer:
2571 swapchain_create_info.sType = VK_STRUCTURE_TYPE_SWAPCHAIN_CREATE_INFO_KHR;
2572 swapchain_create_info.pNext = NULL;
2573 swapchain_create_info.flags = 0;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002574 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "required parameter pSwapchain "
2575 "specified as NULL");
Mark Lobodzinskib02ea642016-08-17 13:03:57 -06002576
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002577 err = vkCreateSwapchainKHR(m_device->device(), &swapchain_create_info, NULL, NULL);
Ian Elliott2c1daf52016-05-12 09:41:46 -06002578 pass = (err != VK_SUCCESS);
2579 ASSERT_TRUE(pass);
2580 m_errorMonitor->VerifyFound();
2581
Mark Lobodzinski085d27a2016-05-17 09:34:26 -06002582 // TODO: Enhance swapchain layer so that
2583 // swapchain_create_info.queueFamilyIndexCount is checked against something?
Ian Elliott2c1daf52016-05-12 09:41:46 -06002584
2585 // Next, call with a queue family index that's too large:
2586 uint32_t queueFamilyIndex[2] = {100000, 0};
2587 swapchain_create_info.imageSharingMode = VK_SHARING_MODE_CONCURRENT;
2588 swapchain_create_info.queueFamilyIndexCount = 2;
2589 swapchain_create_info.pQueueFamilyIndices = queueFamilyIndex;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002590 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "called with a queueFamilyIndex that is too large");
2591 err = vkCreateSwapchainKHR(m_device->device(), &swapchain_create_info, NULL, &swapchain);
Ian Elliott2c1daf52016-05-12 09:41:46 -06002592 pass = (err != VK_SUCCESS);
2593 ASSERT_TRUE(pass);
2594 m_errorMonitor->VerifyFound();
2595
2596 // Next, call a queueFamilyIndexCount that's too small for CONCURRENT:
2597 swapchain_create_info.imageSharingMode = VK_SHARING_MODE_CONCURRENT;
2598 swapchain_create_info.queueFamilyIndexCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002599 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
2600 "but with a bad value(s) for pCreateInfo->queueFamilyIndexCount or "
2601 "pCreateInfo->pQueueFamilyIndices).");
2602 err = vkCreateSwapchainKHR(m_device->device(), &swapchain_create_info, NULL, &swapchain);
Ian Elliott2c1daf52016-05-12 09:41:46 -06002603 pass = (err != VK_SUCCESS);
2604 ASSERT_TRUE(pass);
2605 m_errorMonitor->VerifyFound();
2606
2607 // Next, call with an invalid imageSharingMode:
2608 swapchain_create_info.imageSharingMode = VK_SHARING_MODE_MAX_ENUM;
2609 swapchain_create_info.queueFamilyIndexCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002610 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
2611 "called with a non-supported pCreateInfo->imageSharingMode (i.e.");
2612 err = vkCreateSwapchainKHR(m_device->device(), &swapchain_create_info, NULL, &swapchain);
Ian Elliott2c1daf52016-05-12 09:41:46 -06002613 pass = (err != VK_SUCCESS);
2614 ASSERT_TRUE(pass);
2615 m_errorMonitor->VerifyFound();
2616 // Fix for the future:
Mark Lobodzinski085d27a2016-05-17 09:34:26 -06002617 // FIXME: THIS ISN'T CORRECT--MUST QUERY UNTIL WE FIND A QUEUE FAMILY THAT'S
2618 // SUPPORTED
Ian Elliott2c1daf52016-05-12 09:41:46 -06002619 swapchain_create_info.queueFamilyIndexCount = 0;
2620 queueFamilyIndex[0] = 0;
2621 swapchain_create_info.imageSharingMode = VK_SHARING_MODE_EXCLUSIVE;
2622
Mark Lobodzinski085d27a2016-05-17 09:34:26 -06002623 // TODO: CONTINUE TESTING VALIDATION OF vkCreateSwapchainKHR() ...
Ian Elliott2c1daf52016-05-12 09:41:46 -06002624 // Get the images from a swapchain:
Ian Elliott2c1daf52016-05-12 09:41:46 -06002625 // Acquire an image from a swapchain:
Ian Elliott2c1daf52016-05-12 09:41:46 -06002626 // Present an image to a swapchain:
Ian Elliott2c1daf52016-05-12 09:41:46 -06002627 // Destroy the swapchain:
2628
Mark Lobodzinski085d27a2016-05-17 09:34:26 -06002629 // TODOs:
2630 //
2631 // - Try destroying the device without first destroying the swapchain
2632 //
2633 // - Try destroying the device without first destroying the surface
2634 //
2635 // - Try destroying the surface without first destroying the swapchain
Ian Elliott2c1daf52016-05-12 09:41:46 -06002636
2637 // Destroy the surface:
2638 vkDestroySurfaceKHR(instance(), surface, NULL);
2639
Ian Elliott2c1daf52016-05-12 09:41:46 -06002640 // Tear down the window:
2641 xcb_destroy_window(connection, xcb_window);
2642 xcb_disconnect(connection);
2643
2644#else // VK_USE_PLATFORM_XCB_KHR
Mark Lobodzinski085d27a2016-05-17 09:34:26 -06002645 return;
Ian Elliott2c1daf52016-05-12 09:41:46 -06002646#endif // VK_USE_PLATFORM_XCB_KHR
2647}
2648
Karl Schultz6addd812016-02-02 17:17:23 -07002649TEST_F(VkLayerTest, MapMemWithoutHostVisibleBit) {
2650 VkResult err;
2651 bool pass;
Mark Lobodzinski3780e142015-05-14 15:08:13 -05002652
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002653 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
2654 "Mapping Memory without VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06002655
Mark Lobodzinski3780e142015-05-14 15:08:13 -05002656 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinski3780e142015-05-14 15:08:13 -05002657
2658 // Create an image, allocate memory, free it, and then try to bind it
Karl Schultz6addd812016-02-02 17:17:23 -07002659 VkImage image;
2660 VkDeviceMemory mem;
2661 VkMemoryRequirements mem_reqs;
Mark Lobodzinski3780e142015-05-14 15:08:13 -05002662
Karl Schultz6addd812016-02-02 17:17:23 -07002663 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
2664 const int32_t tex_width = 32;
2665 const int32_t tex_height = 32;
Mark Lobodzinski3780e142015-05-14 15:08:13 -05002666
Tony Barboureb254902015-07-15 12:50:33 -06002667 VkImageCreateInfo image_create_info = {};
2668 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
Karl Schultz6addd812016-02-02 17:17:23 -07002669 image_create_info.pNext = NULL;
2670 image_create_info.imageType = VK_IMAGE_TYPE_2D;
2671 image_create_info.format = tex_format;
2672 image_create_info.extent.width = tex_width;
2673 image_create_info.extent.height = tex_height;
2674 image_create_info.extent.depth = 1;
2675 image_create_info.mipLevels = 1;
2676 image_create_info.arrayLayers = 1;
2677 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
2678 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
2679 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
2680 image_create_info.flags = 0;
Chris Forbese65e4d02016-09-13 17:39:18 +12002681 image_create_info.initialLayout = VK_IMAGE_LAYOUT_PREINITIALIZED;
Mark Lobodzinski5fcc4212015-09-14 17:43:42 -06002682
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002683 VkMemoryAllocateInfo mem_alloc = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08002684 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
Karl Schultz6addd812016-02-02 17:17:23 -07002685 mem_alloc.pNext = NULL;
2686 mem_alloc.allocationSize = 0;
Mark Lobodzinski3780e142015-05-14 15:08:13 -05002687
Chia-I Wuf7458c52015-10-26 21:10:41 +08002688 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
Mark Lobodzinski3780e142015-05-14 15:08:13 -05002689 ASSERT_VK_SUCCESS(err);
2690
Karl Schultz6addd812016-02-02 17:17:23 -07002691 vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs);
Mark Lobodzinski3780e142015-05-14 15:08:13 -05002692
Mark Lobodzinski23065352015-05-29 09:32:35 -05002693 mem_alloc.allocationSize = mem_reqs.size;
Mark Lobodzinski3780e142015-05-14 15:08:13 -05002694
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002695 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 -07002696 if (!pass) { // If we can't find any unmappable memory this test doesn't
2697 // make sense
Chia-I Wuf7458c52015-10-26 21:10:41 +08002698 vkDestroyImage(m_device->device(), image, NULL);
Tony Barbour02fdc7d2015-08-04 16:13:01 -06002699 return;
Mike Stroyand1c84a52015-08-18 14:40:24 -06002700 }
Mike Stroyan713b2d72015-08-04 10:49:29 -06002701
Mark Lobodzinski3780e142015-05-14 15:08:13 -05002702 // allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002703 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem);
Mark Lobodzinski3780e142015-05-14 15:08:13 -05002704 ASSERT_VK_SUCCESS(err);
2705
2706 // Try to bind free memory that has been freed
Tony Barbour67e99152015-07-10 14:10:27 -06002707 err = vkBindImageMemory(m_device->device(), image, mem, 0);
Mark Lobodzinski3780e142015-05-14 15:08:13 -05002708 ASSERT_VK_SUCCESS(err);
2709
2710 // Map memory as if to initialize the image
2711 void *mappedAddress = NULL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002712 err = vkMapMemory(m_device->device(), mem, 0, VK_WHOLE_SIZE, 0, &mappedAddress);
Mark Lobodzinski3780e142015-05-14 15:08:13 -05002713
Chris Forbes8f36a8a2016-04-07 13:21:07 +12002714 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06002715
Chia-I Wuf7458c52015-10-26 21:10:41 +08002716 vkDestroyImage(m_device->device(), image, NULL);
Tony Barbourdf4c0042016-06-01 15:55:43 -06002717 vkFreeMemory(m_device->device(), mem, NULL);
Mark Lobodzinski3780e142015-05-14 15:08:13 -05002718}
2719
Karl Schultz6addd812016-02-02 17:17:23 -07002720TEST_F(VkLayerTest, RebindMemory) {
2721 VkResult err;
2722 bool pass;
Mark Lobodzinski944aab12015-06-05 13:59:04 -05002723
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002724 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "which has already been bound to mem object");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06002725
Mark Lobodzinski944aab12015-06-05 13:59:04 -05002726 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinski944aab12015-06-05 13:59:04 -05002727
2728 // Create an image, allocate memory, free it, and then try to bind it
Karl Schultz6addd812016-02-02 17:17:23 -07002729 VkImage image;
2730 VkDeviceMemory mem1;
2731 VkDeviceMemory mem2;
2732 VkMemoryRequirements mem_reqs;
Mark Lobodzinski944aab12015-06-05 13:59:04 -05002733
Karl Schultz6addd812016-02-02 17:17:23 -07002734 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
2735 const int32_t tex_width = 32;
2736 const int32_t tex_height = 32;
Mark Lobodzinski944aab12015-06-05 13:59:04 -05002737
Tony Barboureb254902015-07-15 12:50:33 -06002738 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -07002739 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
2740 image_create_info.pNext = NULL;
2741 image_create_info.imageType = VK_IMAGE_TYPE_2D;
2742 image_create_info.format = tex_format;
2743 image_create_info.extent.width = tex_width;
2744 image_create_info.extent.height = tex_height;
2745 image_create_info.extent.depth = 1;
2746 image_create_info.mipLevels = 1;
2747 image_create_info.arrayLayers = 1;
2748 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
2749 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
2750 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
2751 image_create_info.flags = 0;
Mark Lobodzinski944aab12015-06-05 13:59:04 -05002752
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002753 VkMemoryAllocateInfo mem_alloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -07002754 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
2755 mem_alloc.pNext = NULL;
2756 mem_alloc.allocationSize = 0;
2757 mem_alloc.memoryTypeIndex = 0;
Tony Barboureb254902015-07-15 12:50:33 -06002758
Karl Schultz6addd812016-02-02 17:17:23 -07002759 // Introduce failure, do NOT set memProps to
2760 // VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT
Tony Barboureb254902015-07-15 12:50:33 -06002761 mem_alloc.memoryTypeIndex = 1;
Chia-I Wuf7458c52015-10-26 21:10:41 +08002762 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
Mark Lobodzinski944aab12015-06-05 13:59:04 -05002763 ASSERT_VK_SUCCESS(err);
2764
Karl Schultz6addd812016-02-02 17:17:23 -07002765 vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs);
Mark Lobodzinski944aab12015-06-05 13:59:04 -05002766
2767 mem_alloc.allocationSize = mem_reqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002768 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -06002769 ASSERT_TRUE(pass);
Mark Lobodzinski944aab12015-06-05 13:59:04 -05002770
2771 // allocate 2 memory objects
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002772 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem1);
Mark Lobodzinski944aab12015-06-05 13:59:04 -05002773 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002774 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem2);
Mark Lobodzinski944aab12015-06-05 13:59:04 -05002775 ASSERT_VK_SUCCESS(err);
2776
2777 // Bind first memory object to Image object
Tony Barbour67e99152015-07-10 14:10:27 -06002778 err = vkBindImageMemory(m_device->device(), image, mem1, 0);
Mark Lobodzinski944aab12015-06-05 13:59:04 -05002779 ASSERT_VK_SUCCESS(err);
2780
Karl Schultz6addd812016-02-02 17:17:23 -07002781 // Introduce validation failure, try to bind a different memory object to
2782 // the same image object
Tony Barbour67e99152015-07-10 14:10:27 -06002783 err = vkBindImageMemory(m_device->device(), image, mem2, 0);
Mark Lobodzinski944aab12015-06-05 13:59:04 -05002784
Chris Forbes8f36a8a2016-04-07 13:21:07 +12002785 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06002786
Chia-I Wuf7458c52015-10-26 21:10:41 +08002787 vkDestroyImage(m_device->device(), image, NULL);
2788 vkFreeMemory(m_device->device(), mem1, NULL);
2789 vkFreeMemory(m_device->device(), mem2, NULL);
Mark Lobodzinski944aab12015-06-05 13:59:04 -05002790}
Mark Lobodzinski3780e142015-05-14 15:08:13 -05002791
Karl Schultz6addd812016-02-02 17:17:23 -07002792TEST_F(VkLayerTest, SubmitSignaledFence) {
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06002793 vk_testing::Fence testFence;
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06002794
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002795 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "submitted in SIGNALED state. Fences "
2796 "must be reset before being submitted");
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06002797
2798 VkFenceCreateInfo fenceInfo = {};
Tony Barbour0b4d9562015-04-09 10:48:04 -06002799 fenceInfo.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
2800 fenceInfo.pNext = NULL;
2801 fenceInfo.flags = VK_FENCE_CREATE_SIGNALED_BIT;
Tony Barbour300a6082015-04-07 13:44:53 -06002802
Tony Barbour300a6082015-04-07 13:44:53 -06002803 ASSERT_NO_FATAL_FAILURE(InitState());
2804 ASSERT_NO_FATAL_FAILURE(InitViewport());
2805 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
2806
Tony Barbourfe3351b2015-07-28 10:17:20 -06002807 BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002808 m_commandBuffer->ClearAllBuffers(m_clear_color, m_depth_clear_color, m_stencil_clear_color, NULL);
Tony Barbourfe3351b2015-07-28 10:17:20 -06002809 EndCommandBuffer();
Tony Barbour300a6082015-04-07 13:44:53 -06002810
2811 testFence.init(*m_device, fenceInfo);
Mark Lobodzinski5fcc4212015-09-14 17:43:42 -06002812
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06002813 VkSubmitInfo submit_info;
Chia-I Wuf9be13c2015-10-26 20:37:06 +08002814 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
2815 submit_info.pNext = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08002816 submit_info.waitSemaphoreCount = 0;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06002817 submit_info.pWaitSemaphores = NULL;
Jon Ashburn7f9716c2015-12-30 16:42:50 -07002818 submit_info.pWaitDstStageMask = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08002819 submit_info.commandBufferCount = 1;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002820 submit_info.pCommandBuffers = &m_commandBuffer->handle();
Chia-I Wud50a7d72015-10-26 20:48:51 +08002821 submit_info.signalSemaphoreCount = 0;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06002822 submit_info.pSignalSemaphores = NULL;
Courtney Goeltzenleuchter646b9072015-10-20 18:04:07 -06002823
2824 vkQueueSubmit(m_device->m_queue, 1, &submit_info, testFence.handle());
Karl Schultz6addd812016-02-02 17:17:23 -07002825 vkQueueWaitIdle(m_device->m_queue);
Mark Lobodzinski5fcc4212015-09-14 17:43:42 -06002826
Chris Forbes8f36a8a2016-04-07 13:21:07 +12002827 m_errorMonitor->VerifyFound();
Tony Barbour0b4d9562015-04-09 10:48:04 -06002828}
Tobin Ehlisaff7ae92016-04-18 15:45:20 -06002829// This is a positive test. We used to expect error in this case but spec now
2830// allows it
Karl Schultz6addd812016-02-02 17:17:23 -07002831TEST_F(VkLayerTest, ResetUnsignaledFence) {
Tobin Ehlisaff7ae92016-04-18 15:45:20 -06002832 m_errorMonitor->ExpectSuccess();
Tony Barbour0b4d9562015-04-09 10:48:04 -06002833 vk_testing::Fence testFence;
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06002834 VkFenceCreateInfo fenceInfo = {};
Tony Barbour0b4d9562015-04-09 10:48:04 -06002835 fenceInfo.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
2836 fenceInfo.pNext = NULL;
2837
Tony Barbour0b4d9562015-04-09 10:48:04 -06002838 ASSERT_NO_FATAL_FAILURE(InitState());
2839 testFence.init(*m_device, fenceInfo);
Chia-I Wud9e8e822015-07-03 11:45:55 +08002840 VkFence fences[1] = {testFence.handle()};
Tobin Ehlisaff7ae92016-04-18 15:45:20 -06002841 VkResult result = vkResetFences(m_device->device(), 1, fences);
2842 ASSERT_VK_SUCCESS(result);
Tony Barbour300a6082015-04-07 13:44:53 -06002843
Tobin Ehlisaff7ae92016-04-18 15:45:20 -06002844 m_errorMonitor->VerifyNotFound();
Tony Barbour300a6082015-04-07 13:44:53 -06002845}
Tobin Ehlis56ab9022016-08-17 17:59:31 -06002846#if 0 // A few devices have issues with this test so disabling for now
Chris Forbese70b7d32016-06-15 15:49:12 +12002847TEST_F(VkLayerTest, LongFenceChain)
2848{
2849 m_errorMonitor->ExpectSuccess();
2850
2851 ASSERT_NO_FATAL_FAILURE(InitState());
2852 VkResult err;
2853
2854 std::vector<VkFence> fences;
2855
2856 const int chainLength = 32768;
2857
2858 for (int i = 0; i < chainLength; i++) {
2859 VkFenceCreateInfo fci = { VK_STRUCTURE_TYPE_FENCE_CREATE_INFO, nullptr, 0 };
2860 VkFence fence;
2861 err = vkCreateFence(m_device->device(), &fci, nullptr, &fence);
2862 ASSERT_VK_SUCCESS(err);
2863
2864 fences.push_back(fence);
2865
2866 VkSubmitInfo si = { VK_STRUCTURE_TYPE_SUBMIT_INFO, nullptr, 0, nullptr, nullptr,
2867 0, nullptr, 0, nullptr };
2868 err = vkQueueSubmit(m_device->m_queue, 1, &si, fence);
2869 ASSERT_VK_SUCCESS(err);
2870
2871 }
2872
2873 // BOOM, stack overflow.
2874 vkWaitForFences(m_device->device(), 1, &fences.back(), VK_TRUE, UINT64_MAX);
2875
2876 for (auto fence : fences)
2877 vkDestroyFence(m_device->device(), fence, nullptr);
2878
2879 m_errorMonitor->VerifyNotFound();
2880}
Tobin Ehlis56ab9022016-08-17 17:59:31 -06002881#endif
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002882TEST_F(VkLayerTest, CommandBufferSimultaneousUseSync) {
Chris Forbes18127d12016-06-08 16:52:28 +12002883 m_errorMonitor->ExpectSuccess();
2884
2885 ASSERT_NO_FATAL_FAILURE(InitState());
2886 VkResult err;
2887
2888 // Record (empty!) command buffer that can be submitted multiple times
2889 // simultaneously.
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002890 VkCommandBufferBeginInfo cbbi = {VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO, nullptr,
2891 VK_COMMAND_BUFFER_USAGE_SIMULTANEOUS_USE_BIT, nullptr};
Chris Forbes18127d12016-06-08 16:52:28 +12002892 m_commandBuffer->BeginCommandBuffer(&cbbi);
2893 m_commandBuffer->EndCommandBuffer();
2894
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002895 VkFenceCreateInfo fci = {VK_STRUCTURE_TYPE_FENCE_CREATE_INFO, nullptr, 0};
Chris Forbes18127d12016-06-08 16:52:28 +12002896 VkFence fence;
2897 err = vkCreateFence(m_device->device(), &fci, nullptr, &fence);
2898 ASSERT_VK_SUCCESS(err);
2899
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002900 VkSemaphoreCreateInfo sci = {VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO, nullptr, 0};
Chris Forbes18127d12016-06-08 16:52:28 +12002901 VkSemaphore s1, s2;
2902 err = vkCreateSemaphore(m_device->device(), &sci, nullptr, &s1);
2903 ASSERT_VK_SUCCESS(err);
2904 err = vkCreateSemaphore(m_device->device(), &sci, nullptr, &s2);
2905 ASSERT_VK_SUCCESS(err);
2906
2907 // Submit CB once signaling s1, with fence so we can roll forward to its retirement.
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002908 VkSubmitInfo si = {VK_STRUCTURE_TYPE_SUBMIT_INFO, nullptr, 0, nullptr, nullptr, 1, &m_commandBuffer->handle(), 1, &s1};
Chris Forbes18127d12016-06-08 16:52:28 +12002909 err = vkQueueSubmit(m_device->m_queue, 1, &si, fence);
2910 ASSERT_VK_SUCCESS(err);
2911
2912 // Submit CB again, signaling s2.
2913 si.pSignalSemaphores = &s2;
2914 err = vkQueueSubmit(m_device->m_queue, 1, &si, VK_NULL_HANDLE);
2915 ASSERT_VK_SUCCESS(err);
2916
2917 // Wait for fence.
2918 err = vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
2919 ASSERT_VK_SUCCESS(err);
2920
2921 // CB is still in flight from second submission, but semaphore s1 is no
2922 // longer in flight. delete it.
2923 vkDestroySemaphore(m_device->device(), s1, nullptr);
2924
2925 m_errorMonitor->VerifyNotFound();
2926
2927 // Force device idle and clean up remaining objects
2928 vkDeviceWaitIdle(m_device->device());
2929 vkDestroySemaphore(m_device->device(), s2, nullptr);
2930 vkDestroyFence(m_device->device(), fence, nullptr);
2931}
2932
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002933TEST_F(VkLayerTest, FenceCreateSignaledWaitHandling) {
Chris Forbes4e44c912016-06-16 10:20:00 +12002934 m_errorMonitor->ExpectSuccess();
2935
2936 ASSERT_NO_FATAL_FAILURE(InitState());
2937 VkResult err;
2938
2939 // A fence created signaled
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002940 VkFenceCreateInfo fci1 = {VK_STRUCTURE_TYPE_FENCE_CREATE_INFO, nullptr, VK_FENCE_CREATE_SIGNALED_BIT};
Chris Forbes4e44c912016-06-16 10:20:00 +12002941 VkFence f1;
2942 err = vkCreateFence(m_device->device(), &fci1, nullptr, &f1);
2943 ASSERT_VK_SUCCESS(err);
2944
2945 // A fence created not
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002946 VkFenceCreateInfo fci2 = {VK_STRUCTURE_TYPE_FENCE_CREATE_INFO, nullptr, 0};
Chris Forbes4e44c912016-06-16 10:20:00 +12002947 VkFence f2;
2948 err = vkCreateFence(m_device->device(), &fci2, nullptr, &f2);
2949 ASSERT_VK_SUCCESS(err);
2950
2951 // Submit the unsignaled fence
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002952 VkSubmitInfo si = {VK_STRUCTURE_TYPE_SUBMIT_INFO, nullptr, 0, nullptr, nullptr, 0, nullptr, 0, nullptr};
Chris Forbes4e44c912016-06-16 10:20:00 +12002953 err = vkQueueSubmit(m_device->m_queue, 1, &si, f2);
2954
2955 // Wait on both fences, with signaled first.
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002956 VkFence fences[] = {f1, f2};
Chris Forbes4e44c912016-06-16 10:20:00 +12002957 vkWaitForFences(m_device->device(), 2, fences, VK_TRUE, UINT64_MAX);
2958
2959 // Should have both retired!
2960 vkDestroyFence(m_device->device(), f1, nullptr);
2961 vkDestroyFence(m_device->device(), f2, nullptr);
2962
2963 m_errorMonitor->VerifyNotFound();
2964}
2965
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002966TEST_F(VkLayerTest, InvalidUsageBits) {
2967 TEST_DESCRIPTION("Specify wrong usage for image then create conflicting view of image "
2968 "Initialize buffer with wrong usage then perform copy expecting errors "
2969 "from both the image and the buffer (2 calls)");
2970 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Invalid usage flag for image ");
Tobin Ehlis41376e12015-07-03 08:45:14 -06002971
2972 ASSERT_NO_FATAL_FAILURE(InitState());
Tony Barbourf92621a2016-05-02 14:28:12 -06002973 VkImageObj image(m_device);
Tony Barbour75d79f02016-08-30 09:39:07 -06002974 // Initialize image with USAGE_TRANSIENT_ATTACHMENT
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002975 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 -06002976 ASSERT_TRUE(image.initialized());
Tobin Ehlis41376e12015-07-03 08:45:14 -06002977
Tony Barbourf92621a2016-05-02 14:28:12 -06002978 VkImageView dsv;
2979 VkImageViewCreateInfo dsvci = {};
2980 dsvci.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
2981 dsvci.image = image.handle();
2982 dsvci.viewType = VK_IMAGE_VIEW_TYPE_2D;
2983 dsvci.format = VK_FORMAT_D32_SFLOAT_S8_UINT;
2984 dsvci.subresourceRange.layerCount = 1;
2985 dsvci.subresourceRange.baseMipLevel = 0;
2986 dsvci.subresourceRange.levelCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002987 dsvci.subresourceRange.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT;
Tobin Ehlis41376e12015-07-03 08:45:14 -06002988
Tony Barbourf92621a2016-05-02 14:28:12 -06002989 // Create a view with depth / stencil aspect for image with different usage
2990 vkCreateImageView(m_device->device(), &dsvci, NULL, &dsv);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06002991
Chris Forbes8f36a8a2016-04-07 13:21:07 +12002992 m_errorMonitor->VerifyFound();
Tony Barbourf92621a2016-05-02 14:28:12 -06002993
2994 // Initialize buffer with TRANSFER_DST usage
2995 vk_testing::Buffer buffer;
2996 VkMemoryPropertyFlags reqs = 0;
2997 buffer.init_as_dst(*m_device, 128 * 128, reqs);
2998 VkBufferImageCopy region = {};
2999 region.bufferRowLength = 128;
3000 region.bufferImageHeight = 128;
3001 region.imageSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
3002 region.imageSubresource.layerCount = 1;
3003 region.imageExtent.height = 16;
3004 region.imageExtent.width = 16;
3005 region.imageExtent.depth = 1;
3006
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003007 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Invalid usage flag for buffer ");
Tony Barbourf92621a2016-05-02 14:28:12 -06003008 // Buffer usage not set to TRANSFER_SRC and image usage not set to
3009 // TRANSFER_DST
3010 BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003011 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer.handle(), image.handle(),
3012 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, &region);
Tony Barbourf92621a2016-05-02 14:28:12 -06003013 m_errorMonitor->VerifyFound();
3014
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003015 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Invalid usage flag for image ");
3016 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer.handle(), image.handle(),
3017 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, &region);
Tony Barbourf92621a2016-05-02 14:28:12 -06003018 m_errorMonitor->VerifyFound();
Tobin Ehlis41376e12015-07-03 08:45:14 -06003019}
Tony Barbour75d79f02016-08-30 09:39:07 -06003020
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003021TEST_F(VkLayerTest, ValidUsage) {
3022 TEST_DESCRIPTION("Verify that creating an image view from an image with valid usage "
3023 "doesn't generate validation errors");
Tony Barbour75d79f02016-08-30 09:39:07 -06003024
3025 ASSERT_NO_FATAL_FAILURE(InitState());
3026
3027 m_errorMonitor->ExpectSuccess();
3028 // Verify that we can create a view with usage INPUT_ATTACHMENT
3029 VkImageObj image(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003030 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 -06003031 ASSERT_TRUE(image.initialized());
3032 VkImageView imageView;
3033 VkImageViewCreateInfo ivci = {};
3034 ivci.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
3035 ivci.image = image.handle();
3036 ivci.viewType = VK_IMAGE_VIEW_TYPE_2D;
3037 ivci.format = VK_FORMAT_R8G8B8A8_UNORM;
3038 ivci.subresourceRange.layerCount = 1;
3039 ivci.subresourceRange.baseMipLevel = 0;
3040 ivci.subresourceRange.levelCount = 1;
3041 ivci.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
3042
3043 vkCreateImageView(m_device->device(), &ivci, NULL, &imageView);
3044 m_errorMonitor->VerifyNotFound();
3045 vkDestroyImageView(m_device->device(), imageView, NULL);
3046}
Mark Lobodzinski209b5292015-09-17 09:44:05 -06003047#endif // MEM_TRACKER_TESTS
3048
Tobin Ehlis4bf96d12015-06-25 11:58:41 -06003049#if OBJ_TRACKER_TESTS
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06003050
3051TEST_F(VkLayerTest, LeakAnObject) {
3052 VkResult err;
3053
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003054 TEST_DESCRIPTION("Create a fence and destroy its device without first destroying the fence.");
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06003055
3056 // Note that we have to create a new device since destroying the
3057 // framework's device causes Teardown() to fail and just calling Teardown
3058 // will destroy the errorMonitor.
3059
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003060 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "has not been destroyed.");
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06003061
3062 ASSERT_NO_FATAL_FAILURE(InitState());
3063
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003064 const std::vector<VkQueueFamilyProperties> queue_props = m_device->queue_props;
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06003065 std::vector<VkDeviceQueueCreateInfo> queue_info;
3066 queue_info.reserve(queue_props.size());
3067 std::vector<std::vector<float>> queue_priorities;
3068 for (uint32_t i = 0; i < (uint32_t)queue_props.size(); i++) {
3069 VkDeviceQueueCreateInfo qi = {};
3070 qi.sType = VK_STRUCTURE_TYPE_DEVICE_QUEUE_CREATE_INFO;
3071 qi.pNext = NULL;
3072 qi.queueFamilyIndex = i;
3073 qi.queueCount = queue_props[i].queueCount;
3074 queue_priorities.emplace_back(qi.queueCount, 0.0f);
3075 qi.pQueuePriorities = queue_priorities[i].data();
3076 queue_info.push_back(qi);
3077 }
3078
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06003079 std::vector<const char *> device_extension_names;
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06003080
3081 // The sacrificial device object
3082 VkDevice testDevice;
3083 VkDeviceCreateInfo device_create_info = {};
3084 auto features = m_device->phy().features();
3085 device_create_info.sType = VK_STRUCTURE_TYPE_DEVICE_CREATE_INFO;
3086 device_create_info.pNext = NULL;
3087 device_create_info.queueCreateInfoCount = queue_info.size();
3088 device_create_info.pQueueCreateInfos = queue_info.data();
Tony Barbour4c70d102016-08-08 16:06:56 -06003089 device_create_info.enabledLayerCount = 0;
3090 device_create_info.ppEnabledLayerNames = NULL;
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06003091 device_create_info.pEnabledFeatures = &features;
3092 err = vkCreateDevice(gpu(), &device_create_info, NULL, &testDevice);
3093 ASSERT_VK_SUCCESS(err);
3094
3095 VkFence fence;
3096 VkFenceCreateInfo fence_create_info = {};
3097 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
3098 fence_create_info.pNext = NULL;
3099 fence_create_info.flags = 0;
3100 err = vkCreateFence(testDevice, &fence_create_info, NULL, &fence);
3101 ASSERT_VK_SUCCESS(err);
3102
3103 // Induce failure by not calling vkDestroyFence
3104 vkDestroyDevice(testDevice, NULL);
3105 m_errorMonitor->VerifyFound();
3106}
3107
3108TEST_F(VkLayerTest, InvalidCommandPoolConsistency) {
3109
3110 TEST_DESCRIPTION("Allocate command buffers from one command pool and "
3111 "attempt to delete them from another.");
3112
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003113 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "FreeCommandBuffers is attempting to free Command Buffer");
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06003114
Cody Northropc31a84f2016-08-22 10:41:47 -06003115 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06003116 VkCommandPool command_pool_one;
3117 VkCommandPool command_pool_two;
3118
3119 VkCommandPoolCreateInfo pool_create_info{};
3120 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
3121 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
3122 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
3123
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003124 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool_one);
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06003125
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003126 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool_two);
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06003127
3128 VkCommandBuffer command_buffer[9];
3129 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003130 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06003131 command_buffer_allocate_info.commandPool = command_pool_one;
3132 command_buffer_allocate_info.commandBufferCount = 9;
3133 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003134 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, command_buffer);
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06003135
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003136 vkFreeCommandBuffers(m_device->device(), command_pool_two, 4, &command_buffer[3]);
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06003137
3138 m_errorMonitor->VerifyFound();
3139
3140 vkDestroyCommandPool(m_device->device(), command_pool_one, NULL);
3141 vkDestroyCommandPool(m_device->device(), command_pool_two, NULL);
3142}
3143
3144TEST_F(VkLayerTest, InvalidDescriptorPoolConsistency) {
3145 VkResult err;
3146
3147 TEST_DESCRIPTION("Allocate descriptor sets from one DS pool and "
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003148 "attempt to delete them from another.");
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06003149
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003150 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "FreeDescriptorSets is attempting to free descriptorSet");
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06003151
3152 ASSERT_NO_FATAL_FAILURE(InitState());
3153 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
3154
3155 VkDescriptorPoolSize ds_type_count = {};
3156 ds_type_count.type = VK_DESCRIPTOR_TYPE_SAMPLER;
3157 ds_type_count.descriptorCount = 1;
3158
3159 VkDescriptorPoolCreateInfo ds_pool_ci = {};
3160 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
3161 ds_pool_ci.pNext = NULL;
3162 ds_pool_ci.flags = 0;
3163 ds_pool_ci.maxSets = 1;
3164 ds_pool_ci.poolSizeCount = 1;
3165 ds_pool_ci.pPoolSizes = &ds_type_count;
3166
3167 VkDescriptorPool ds_pool_one;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003168 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool_one);
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06003169 ASSERT_VK_SUCCESS(err);
3170
3171 // Create a second descriptor pool
3172 VkDescriptorPool ds_pool_two;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003173 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool_two);
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06003174 ASSERT_VK_SUCCESS(err);
3175
3176 VkDescriptorSetLayoutBinding dsl_binding = {};
3177 dsl_binding.binding = 0;
3178 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
3179 dsl_binding.descriptorCount = 1;
3180 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
3181 dsl_binding.pImmutableSamplers = NULL;
3182
3183 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
3184 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
3185 ds_layout_ci.pNext = NULL;
3186 ds_layout_ci.bindingCount = 1;
3187 ds_layout_ci.pBindings = &dsl_binding;
3188
3189 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003190 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06003191 ASSERT_VK_SUCCESS(err);
3192
3193 VkDescriptorSet descriptorSet;
3194 VkDescriptorSetAllocateInfo alloc_info = {};
3195 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
3196 alloc_info.descriptorSetCount = 1;
3197 alloc_info.descriptorPool = ds_pool_one;
3198 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003199 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06003200 ASSERT_VK_SUCCESS(err);
3201
3202 err = vkFreeDescriptorSets(m_device->device(), ds_pool_two, 1, &descriptorSet);
3203
3204 m_errorMonitor->VerifyFound();
3205
3206 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
3207 vkDestroyDescriptorPool(m_device->device(), ds_pool_one, NULL);
3208 vkDestroyDescriptorPool(m_device->device(), ds_pool_two, NULL);
3209}
3210
3211TEST_F(VkLayerTest, CreateUnknownObject) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003212 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Invalid Image Object ");
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06003213
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003214 TEST_DESCRIPTION("Pass an invalid image object handle into a Vulkan API call.");
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06003215
3216 ASSERT_NO_FATAL_FAILURE(InitState());
3217
3218 // Pass bogus handle into GetImageMemoryRequirements
3219 VkMemoryRequirements mem_reqs;
3220 uint64_t fakeImageHandle = 0xCADECADE;
3221 VkImage fauxImage = reinterpret_cast<VkImage &>(fakeImageHandle);
3222
3223 vkGetImageMemoryRequirements(m_device->device(), fauxImage, &mem_reqs);
3224
3225 m_errorMonitor->VerifyFound();
3226}
3227
Karl Schultz6addd812016-02-02 17:17:23 -07003228TEST_F(VkLayerTest, PipelineNotBound) {
3229 VkResult err;
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06003230
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003231 TEST_DESCRIPTION("Pass in an invalid pipeline object handle into a Vulkan API call.");
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06003232
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003233 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Invalid Pipeline Object ");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06003234
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06003235 ASSERT_NO_FATAL_FAILURE(InitState());
3236 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06003237
Chia-I Wu1b99bb22015-10-27 19:25:11 +08003238 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07003239 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
3240 ds_type_count.descriptorCount = 1;
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06003241
3242 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07003243 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
3244 ds_pool_ci.pNext = NULL;
3245 ds_pool_ci.maxSets = 1;
3246 ds_pool_ci.poolSizeCount = 1;
3247 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06003248
3249 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003250 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06003251 ASSERT_VK_SUCCESS(err);
3252
3253 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07003254 dsl_binding.binding = 0;
3255 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
3256 dsl_binding.descriptorCount = 1;
3257 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
3258 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06003259
3260 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07003261 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
3262 ds_layout_ci.pNext = NULL;
3263 ds_layout_ci.bindingCount = 1;
3264 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06003265
3266 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003267 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06003268 ASSERT_VK_SUCCESS(err);
3269
3270 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08003271 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08003272 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07003273 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06003274 alloc_info.descriptorPool = ds_pool;
3275 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003276 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06003277 ASSERT_VK_SUCCESS(err);
3278
3279 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07003280 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
3281 pipeline_layout_ci.pNext = NULL;
3282 pipeline_layout_ci.setLayoutCount = 1;
3283 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06003284
3285 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003286 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06003287 ASSERT_VK_SUCCESS(err);
3288
Mark Youngad779052016-01-06 14:26:04 -07003289 VkPipeline badPipeline = (VkPipeline)((size_t)0xbaadb1be);
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06003290
3291 BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003292 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, badPipeline);
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06003293
Chris Forbes8f36a8a2016-04-07 13:21:07 +12003294 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06003295
Chia-I Wuf7458c52015-10-26 21:10:41 +08003296 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
3297 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
3298 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlisec598302015-09-15 15:02:17 -06003299}
Mike Stroyan80fc6c32016-06-20 15:42:29 -06003300
Mark Lobodzinskibc185762016-06-15 16:28:53 -06003301TEST_F(VkLayerTest, BindImageInvalidMemoryType) {
3302 VkResult err;
3303
3304 TEST_DESCRIPTION("Test validation check for an invalid memory type index "
3305 "during bind[Buffer|Image]Memory time");
3306
Mark Lobodzinskibc185762016-06-15 16:28:53 -06003307 ASSERT_NO_FATAL_FAILURE(InitState());
3308
3309 // Create an image, allocate memory, set a bad typeIndex and then try to
3310 // bind it
3311 VkImage image;
3312 VkDeviceMemory mem;
3313 VkMemoryRequirements mem_reqs;
3314 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
3315 const int32_t tex_width = 32;
3316 const int32_t tex_height = 32;
3317
3318 VkImageCreateInfo image_create_info = {};
3319 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
3320 image_create_info.pNext = NULL;
3321 image_create_info.imageType = VK_IMAGE_TYPE_2D;
3322 image_create_info.format = tex_format;
3323 image_create_info.extent.width = tex_width;
3324 image_create_info.extent.height = tex_height;
3325 image_create_info.extent.depth = 1;
3326 image_create_info.mipLevels = 1;
3327 image_create_info.arrayLayers = 1;
3328 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
3329 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
3330 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
3331 image_create_info.flags = 0;
3332
3333 VkMemoryAllocateInfo mem_alloc = {};
3334 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
3335 mem_alloc.pNext = NULL;
3336 mem_alloc.allocationSize = 0;
3337 mem_alloc.memoryTypeIndex = 0;
3338
3339 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
3340 ASSERT_VK_SUCCESS(err);
3341
3342 vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs);
3343 mem_alloc.allocationSize = mem_reqs.size;
Mike Stroyan80fc6c32016-06-20 15:42:29 -06003344
3345 // Introduce Failure, select invalid TypeIndex
3346 VkPhysicalDeviceMemoryProperties memory_info;
3347
3348 vkGetPhysicalDeviceMemoryProperties(gpu(), &memory_info);
3349 unsigned int i;
3350 for (i = 0; i < memory_info.memoryTypeCount; i++) {
3351 if ((mem_reqs.memoryTypeBits & (1 << i)) == 0) {
3352 mem_alloc.memoryTypeIndex = i;
3353 break;
3354 }
3355 }
3356 if (i >= memory_info.memoryTypeCount) {
3357 printf("No invalid memory type index could be found; skipped.\n");
3358 vkDestroyImage(m_device->device(), image, NULL);
3359 return;
3360 }
3361
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003362 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 -06003363
3364 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem);
3365 ASSERT_VK_SUCCESS(err);
3366
3367 err = vkBindImageMemory(m_device->device(), image, mem, 0);
3368 (void)err;
3369
3370 m_errorMonitor->VerifyFound();
3371
3372 vkDestroyImage(m_device->device(), image, NULL);
3373 vkFreeMemory(m_device->device(), mem, NULL);
3374}
Mike Stroyan80fc6c32016-06-20 15:42:29 -06003375
Karl Schultz6addd812016-02-02 17:17:23 -07003376TEST_F(VkLayerTest, BindInvalidMemory) {
3377 VkResult err;
3378 bool pass;
Tobin Ehlisec598302015-09-15 15:02:17 -06003379
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003380 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Invalid Device Memory Object ");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06003381
Tobin Ehlisec598302015-09-15 15:02:17 -06003382 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisec598302015-09-15 15:02:17 -06003383
3384 // Create an image, allocate memory, free it, and then try to bind it
Karl Schultz6addd812016-02-02 17:17:23 -07003385 VkImage image;
3386 VkDeviceMemory mem;
3387 VkMemoryRequirements mem_reqs;
Tobin Ehlisec598302015-09-15 15:02:17 -06003388
Karl Schultz6addd812016-02-02 17:17:23 -07003389 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
3390 const int32_t tex_width = 32;
3391 const int32_t tex_height = 32;
Tobin Ehlisec598302015-09-15 15:02:17 -06003392
3393 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -07003394 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
3395 image_create_info.pNext = NULL;
3396 image_create_info.imageType = VK_IMAGE_TYPE_2D;
3397 image_create_info.format = tex_format;
3398 image_create_info.extent.width = tex_width;
3399 image_create_info.extent.height = tex_height;
3400 image_create_info.extent.depth = 1;
3401 image_create_info.mipLevels = 1;
3402 image_create_info.arrayLayers = 1;
3403 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
3404 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
3405 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
3406 image_create_info.flags = 0;
Tobin Ehlisec598302015-09-15 15:02:17 -06003407
Chia-I Wu3432a0c2015-10-27 18:04:07 +08003408 VkMemoryAllocateInfo mem_alloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -07003409 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
3410 mem_alloc.pNext = NULL;
3411 mem_alloc.allocationSize = 0;
3412 mem_alloc.memoryTypeIndex = 0;
Tobin Ehlisec598302015-09-15 15:02:17 -06003413
Chia-I Wuf7458c52015-10-26 21:10:41 +08003414 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
Tobin Ehlisec598302015-09-15 15:02:17 -06003415 ASSERT_VK_SUCCESS(err);
3416
Karl Schultz6addd812016-02-02 17:17:23 -07003417 vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs);
Tobin Ehlisec598302015-09-15 15:02:17 -06003418
3419 mem_alloc.allocationSize = mem_reqs.size;
3420
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003421 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -06003422 ASSERT_TRUE(pass);
Tobin Ehlisec598302015-09-15 15:02:17 -06003423
3424 // allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +08003425 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem);
Tobin Ehlisec598302015-09-15 15:02:17 -06003426 ASSERT_VK_SUCCESS(err);
3427
3428 // Introduce validation failure, free memory before binding
Chia-I Wuf7458c52015-10-26 21:10:41 +08003429 vkFreeMemory(m_device->device(), mem, NULL);
Tobin Ehlisec598302015-09-15 15:02:17 -06003430
3431 // Try to bind free memory that has been freed
3432 err = vkBindImageMemory(m_device->device(), image, mem, 0);
3433 // This may very well return an error.
3434 (void)err;
3435
Chris Forbes8f36a8a2016-04-07 13:21:07 +12003436 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06003437
Chia-I Wuf7458c52015-10-26 21:10:41 +08003438 vkDestroyImage(m_device->device(), image, NULL);
Tobin Ehlisec598302015-09-15 15:02:17 -06003439}
3440
Karl Schultz6addd812016-02-02 17:17:23 -07003441TEST_F(VkLayerTest, BindMemoryToDestroyedObject) {
3442 VkResult err;
3443 bool pass;
Tobin Ehlisec598302015-09-15 15:02:17 -06003444
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003445 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Invalid Image Object ");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06003446
Tobin Ehlisec598302015-09-15 15:02:17 -06003447 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisec598302015-09-15 15:02:17 -06003448
Karl Schultz6addd812016-02-02 17:17:23 -07003449 // Create an image object, allocate memory, destroy the object and then try
3450 // to bind it
3451 VkImage image;
3452 VkDeviceMemory mem;
3453 VkMemoryRequirements mem_reqs;
Tobin Ehlisec598302015-09-15 15:02:17 -06003454
Karl Schultz6addd812016-02-02 17:17:23 -07003455 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
3456 const int32_t tex_width = 32;
3457 const int32_t tex_height = 32;
Tobin Ehlisec598302015-09-15 15:02:17 -06003458
3459 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -07003460 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
3461 image_create_info.pNext = NULL;
3462 image_create_info.imageType = VK_IMAGE_TYPE_2D;
3463 image_create_info.format = tex_format;
3464 image_create_info.extent.width = tex_width;
3465 image_create_info.extent.height = tex_height;
3466 image_create_info.extent.depth = 1;
3467 image_create_info.mipLevels = 1;
3468 image_create_info.arrayLayers = 1;
3469 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
3470 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
3471 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
3472 image_create_info.flags = 0;
Tobin Ehlisec598302015-09-15 15:02:17 -06003473
Chia-I Wu3432a0c2015-10-27 18:04:07 +08003474 VkMemoryAllocateInfo mem_alloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -07003475 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
3476 mem_alloc.pNext = NULL;
3477 mem_alloc.allocationSize = 0;
3478 mem_alloc.memoryTypeIndex = 0;
Tobin Ehlisec598302015-09-15 15:02:17 -06003479
Chia-I Wuf7458c52015-10-26 21:10:41 +08003480 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
Tobin Ehlisec598302015-09-15 15:02:17 -06003481 ASSERT_VK_SUCCESS(err);
3482
Karl Schultz6addd812016-02-02 17:17:23 -07003483 vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs);
Tobin Ehlisec598302015-09-15 15:02:17 -06003484
3485 mem_alloc.allocationSize = mem_reqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003486 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -06003487 ASSERT_TRUE(pass);
Tobin Ehlisec598302015-09-15 15:02:17 -06003488
3489 // Allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +08003490 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem);
Tobin Ehlisec598302015-09-15 15:02:17 -06003491 ASSERT_VK_SUCCESS(err);
3492
3493 // Introduce validation failure, destroy Image object before binding
Chia-I Wuf7458c52015-10-26 21:10:41 +08003494 vkDestroyImage(m_device->device(), image, NULL);
Tobin Ehlisec598302015-09-15 15:02:17 -06003495 ASSERT_VK_SUCCESS(err);
3496
3497 // Now Try to bind memory to this destroyed object
3498 err = vkBindImageMemory(m_device->device(), image, mem, 0);
3499 // This may very well return an error.
Karl Schultz6addd812016-02-02 17:17:23 -07003500 (void)err;
Tobin Ehlisec598302015-09-15 15:02:17 -06003501
Chris Forbes8f36a8a2016-04-07 13:21:07 +12003502 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06003503
Chia-I Wuf7458c52015-10-26 21:10:41 +08003504 vkFreeMemory(m_device->device(), mem, NULL);
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06003505}
Tobin Ehlisa1c28562015-10-23 16:00:08 -06003506
Mark Lobodzinski209b5292015-09-17 09:44:05 -06003507#endif // OBJ_TRACKER_TESTS
3508
Tobin Ehlis0788f522015-05-26 16:11:58 -06003509#if DRAW_STATE_TESTS
Mark Lobodzinskic808d442016-04-14 10:57:23 -06003510
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06003511TEST_F(VkLayerTest, ImageSampleCounts) {
3512
3513 TEST_DESCRIPTION("Use bad sample counts in image transfer calls to trigger "
3514 "validation errors.");
3515 ASSERT_NO_FATAL_FAILURE(InitState());
3516
3517 VkMemoryPropertyFlags reqs = 0;
3518 VkImageCreateInfo image_create_info = {};
3519 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
3520 image_create_info.pNext = NULL;
3521 image_create_info.imageType = VK_IMAGE_TYPE_2D;
3522 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
3523 image_create_info.extent.width = 256;
3524 image_create_info.extent.height = 256;
3525 image_create_info.extent.depth = 1;
3526 image_create_info.mipLevels = 1;
3527 image_create_info.arrayLayers = 1;
3528 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
3529 image_create_info.flags = 0;
3530
3531 VkImageBlit blit_region = {};
3532 blit_region.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
3533 blit_region.srcSubresource.baseArrayLayer = 0;
3534 blit_region.srcSubresource.layerCount = 1;
3535 blit_region.srcSubresource.mipLevel = 0;
3536 blit_region.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
3537 blit_region.dstSubresource.baseArrayLayer = 0;
3538 blit_region.dstSubresource.layerCount = 1;
3539 blit_region.dstSubresource.mipLevel = 0;
3540
3541 // Create two images, the source with sampleCount = 2, and attempt to blit
3542 // between them
3543 {
3544 image_create_info.samples = VK_SAMPLE_COUNT_2_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003545 image_create_info.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06003546 vk_testing::Image src_image;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003547 src_image.init(*m_device, (const VkImageCreateInfo &)image_create_info, reqs);
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06003548 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003549 image_create_info.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT;
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06003550 vk_testing::Image dst_image;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003551 dst_image.init(*m_device, (const VkImageCreateInfo &)image_create_info, reqs);
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06003552 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003553 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "was created with a sample count "
3554 "of VK_SAMPLE_COUNT_2_BIT but "
3555 "must be VK_SAMPLE_COUNT_1_BIT");
3556 vkCmdBlitImage(m_commandBuffer->GetBufferHandle(), src_image.handle(), VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
3557 dst_image.handle(), VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL, 1, &blit_region, VK_FILTER_NEAREST);
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06003558 m_errorMonitor->VerifyFound();
3559 m_commandBuffer->EndCommandBuffer();
3560 }
3561
3562 // Create two images, the dest with sampleCount = 4, and attempt to blit
3563 // between them
3564 {
3565 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003566 image_create_info.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06003567 vk_testing::Image src_image;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003568 src_image.init(*m_device, (const VkImageCreateInfo &)image_create_info, reqs);
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06003569 image_create_info.samples = VK_SAMPLE_COUNT_4_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003570 image_create_info.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT;
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06003571 vk_testing::Image dst_image;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003572 dst_image.init(*m_device, (const VkImageCreateInfo &)image_create_info, reqs);
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06003573 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003574 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "was created with a sample count "
3575 "of VK_SAMPLE_COUNT_4_BIT but "
3576 "must be VK_SAMPLE_COUNT_1_BIT");
3577 vkCmdBlitImage(m_commandBuffer->GetBufferHandle(), src_image.handle(), VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
3578 dst_image.handle(), VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL, 1, &blit_region, VK_FILTER_NEAREST);
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06003579 m_errorMonitor->VerifyFound();
3580 m_commandBuffer->EndCommandBuffer();
3581 }
3582
3583 VkBufferImageCopy copy_region = {};
3584 copy_region.bufferRowLength = 128;
3585 copy_region.bufferImageHeight = 128;
3586 copy_region.imageSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
3587 copy_region.imageSubresource.layerCount = 1;
3588 copy_region.imageExtent.height = 64;
3589 copy_region.imageExtent.width = 64;
3590 copy_region.imageExtent.depth = 1;
3591
3592 // Create src buffer and dst image with sampleCount = 4 and attempt to copy
3593 // buffer to image
3594 {
3595 vk_testing::Buffer src_buffer;
3596 VkMemoryPropertyFlags reqs = 0;
3597 src_buffer.init_as_src(*m_device, 128 * 128 * 4, reqs);
3598 image_create_info.samples = VK_SAMPLE_COUNT_8_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003599 image_create_info.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT;
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06003600 vk_testing::Image dst_image;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003601 dst_image.init(*m_device, (const VkImageCreateInfo &)image_create_info, reqs);
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06003602 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003603 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "was created with a sample count "
3604 "of VK_SAMPLE_COUNT_8_BIT but "
3605 "must be VK_SAMPLE_COUNT_1_BIT");
3606 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), src_buffer.handle(), dst_image.handle(),
3607 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, &copy_region);
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06003608 m_errorMonitor->VerifyFound();
3609 m_commandBuffer->EndCommandBuffer();
3610 }
3611
3612 // Create dst buffer and src image with sampleCount = 2 and attempt to copy
3613 // image to buffer
3614 {
3615 vk_testing::Buffer dst_buffer;
3616 dst_buffer.init_as_dst(*m_device, 128 * 128 * 4, reqs);
3617 image_create_info.samples = VK_SAMPLE_COUNT_2_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003618 image_create_info.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06003619 vk_testing::Image src_image;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003620 src_image.init(*m_device, (const VkImageCreateInfo &)image_create_info, reqs);
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06003621 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003622 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "was created with a sample count "
3623 "of VK_SAMPLE_COUNT_2_BIT but "
3624 "must be VK_SAMPLE_COUNT_1_BIT");
3625 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), src_image.handle(), VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL,
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06003626 dst_buffer.handle(), 1, &copy_region);
3627 m_errorMonitor->VerifyFound();
3628 m_commandBuffer->EndCommandBuffer();
3629 }
3630}
3631
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06003632TEST_F(VkLayerTest, DSImageTransferGranularityTests) {
3633 VkResult err;
3634 bool pass;
3635
3636 TEST_DESCRIPTION("Tests for validaiton of Queue Family property minImageTransferGranularity.");
3637 ASSERT_NO_FATAL_FAILURE(InitState());
3638
3639 // If w/d/h granularity is 1, test is not meaningful
3640 // TODO: When virtual device limits are available, create a set of limits for this test that
3641 // will always have a granularity of > 1 for w, h, and d
3642 auto index = m_device->graphics_queue_node_index_;
3643 auto queue_family_properties = m_device->phy().queue_properties();
3644
3645 if ((queue_family_properties[index].minImageTransferGranularity.depth < 4) ||
3646 (queue_family_properties[index].minImageTransferGranularity.width < 4) ||
3647 (queue_family_properties[index].minImageTransferGranularity.height < 4)) {
3648 return;
3649 }
3650
3651 // Create two images of different types and try to copy between them
3652 VkImage srcImage;
3653 VkImage dstImage;
3654 VkDeviceMemory srcMem;
3655 VkDeviceMemory destMem;
3656 VkMemoryRequirements memReqs;
3657
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06003658 VkImageCreateInfo image_create_info = {};
3659 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
3660 image_create_info.pNext = NULL;
3661 image_create_info.imageType = VK_IMAGE_TYPE_2D;
3662 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
3663 image_create_info.extent.width = 32;
3664 image_create_info.extent.height = 32;
3665 image_create_info.extent.depth = 1;
3666 image_create_info.mipLevels = 1;
3667 image_create_info.arrayLayers = 4;
3668 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
3669 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
3670 image_create_info.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT;
3671 image_create_info.flags = 0;
3672
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003673 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06003674 ASSERT_VK_SUCCESS(err);
3675
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003676 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06003677 ASSERT_VK_SUCCESS(err);
3678
3679 // Allocate memory
3680 VkMemoryAllocateInfo memAlloc = {};
3681 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
3682 memAlloc.pNext = NULL;
3683 memAlloc.allocationSize = 0;
3684 memAlloc.memoryTypeIndex = 0;
3685
3686 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
3687 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003688 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06003689 ASSERT_TRUE(pass);
3690 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
3691 ASSERT_VK_SUCCESS(err);
3692
3693 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
3694 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003695 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06003696 ASSERT_VK_SUCCESS(err);
3697 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
3698 ASSERT_VK_SUCCESS(err);
3699
3700 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
3701 ASSERT_VK_SUCCESS(err);
3702 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
3703 ASSERT_VK_SUCCESS(err);
3704
3705 BeginCommandBuffer();
3706 VkImageCopy copyRegion;
3707 copyRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
3708 copyRegion.srcSubresource.mipLevel = 0;
3709 copyRegion.srcSubresource.baseArrayLayer = 0;
3710 copyRegion.srcSubresource.layerCount = 1;
3711 copyRegion.srcOffset.x = 0;
3712 copyRegion.srcOffset.y = 0;
3713 copyRegion.srcOffset.z = 0;
3714 copyRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
3715 copyRegion.dstSubresource.mipLevel = 0;
3716 copyRegion.dstSubresource.baseArrayLayer = 0;
3717 copyRegion.dstSubresource.layerCount = 1;
3718 copyRegion.dstOffset.x = 0;
3719 copyRegion.dstOffset.y = 0;
3720 copyRegion.dstOffset.z = 0;
3721 copyRegion.extent.width = 1;
3722 copyRegion.extent.height = 1;
3723 copyRegion.extent.depth = 1;
3724
3725 // Introduce failure by setting srcOffset to a bad granularity value
3726 copyRegion.srcOffset.y = 3;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003727 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "queue family image transfer granularity");
3728 m_commandBuffer->CopyImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, VK_IMAGE_LAYOUT_GENERAL, 1, &copyRegion);
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06003729 m_errorMonitor->VerifyFound();
3730
3731 // Introduce failure by setting extent to a bad granularity value
3732 copyRegion.srcOffset.y = 0;
3733 copyRegion.extent.width = 3;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003734 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "queue family image transfer granularity");
3735 m_commandBuffer->CopyImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, VK_IMAGE_LAYOUT_GENERAL, 1, &copyRegion);
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06003736 m_errorMonitor->VerifyFound();
3737
3738 // Now do some buffer/image copies
3739 vk_testing::Buffer buffer;
3740 VkMemoryPropertyFlags reqs = 0;
3741 buffer.init_as_dst(*m_device, 128 * 128, reqs);
3742 VkBufferImageCopy region = {};
3743 region.bufferOffset = 0;
3744 region.bufferRowLength = 3;
3745 region.bufferImageHeight = 128;
3746 region.imageSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
3747 region.imageSubresource.layerCount = 1;
3748 region.imageExtent.height = 16;
3749 region.imageExtent.width = 16;
3750 region.imageExtent.depth = 1;
3751 region.imageOffset.x = 0;
3752 region.imageOffset.y = 0;
3753 region.imageOffset.z = 0;
3754
3755 // Introduce failure by setting bufferRowLength to a bad granularity value
3756 region.bufferRowLength = 3;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003757 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "queue family image transfer granularity");
3758 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer.handle(), srcImage, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1,
3759 &region);
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06003760 m_errorMonitor->VerifyFound();
3761 region.bufferRowLength = 128;
3762
3763 // Introduce failure by setting bufferOffset to a bad granularity value
3764 region.bufferOffset = 3;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003765 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "queue family image transfer granularity");
3766 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), srcImage, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, buffer.handle(), 1,
3767 &region);
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06003768 m_errorMonitor->VerifyFound();
3769 region.bufferOffset = 0;
3770
3771 // Introduce failure by setting bufferImageHeight to a bad granularity value
3772 region.bufferImageHeight = 3;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003773 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "queue family image transfer granularity");
3774 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), srcImage, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, buffer.handle(), 1,
3775 &region);
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06003776 m_errorMonitor->VerifyFound();
3777 region.bufferImageHeight = 128;
3778
3779 // Introduce failure by setting imageExtent to a bad granularity value
3780 region.imageExtent.width = 3;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003781 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "queue family image transfer granularity");
3782 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), srcImage, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, buffer.handle(), 1,
3783 &region);
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06003784 m_errorMonitor->VerifyFound();
3785 region.imageExtent.width = 16;
3786
3787 // Introduce failure by setting imageOffset to a bad granularity value
3788 region.imageOffset.z = 3;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003789 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "queue family image transfer granularity");
3790 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer.handle(), srcImage, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1,
3791 &region);
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06003792 m_errorMonitor->VerifyFound();
3793
3794 EndCommandBuffer();
3795
3796 vkDestroyImage(m_device->device(), srcImage, NULL);
3797 vkDestroyImage(m_device->device(), dstImage, NULL);
3798 vkFreeMemory(m_device->device(), srcMem, NULL);
3799 vkFreeMemory(m_device->device(), destMem, NULL);
3800}
3801
Mark Lobodzinski570efc62016-08-09 16:43:19 -06003802TEST_F(VkLayerTest, MismatchedQueueFamiliesOnSubmit) {
Mark Lobodzinski570efc62016-08-09 16:43:19 -06003803 TEST_DESCRIPTION("Submit command buffer created using one queue family and "
3804 "attempt to submit them on a queue created in a different "
3805 "queue family.");
3806
Cody Northropc31a84f2016-08-22 10:41:47 -06003807 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinski570efc62016-08-09 16:43:19 -06003808 // This test is meaningless unless we have multiple queue families
3809 auto queue_family_properties = m_device->phy().queue_properties();
3810 if (queue_family_properties.size() < 2) {
3811 return;
3812 }
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003813 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " is being submitted on queue ");
Mark Lobodzinski570efc62016-08-09 16:43:19 -06003814 // Get safe index of another queue family
3815 uint32_t other_queue_family = (m_device->graphics_queue_node_index_ == 0) ? 1 : 0;
3816 ASSERT_NO_FATAL_FAILURE(InitState());
3817 // Create a second queue using a different queue family
3818 VkQueue other_queue;
3819 vkGetDeviceQueue(m_device->device(), other_queue_family, 0, &other_queue);
3820
3821 // Record an empty cmd buffer
3822 VkCommandBufferBeginInfo cmdBufBeginDesc = {};
3823 cmdBufBeginDesc.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
3824 vkBeginCommandBuffer(m_commandBuffer->handle(), &cmdBufBeginDesc);
3825 vkEndCommandBuffer(m_commandBuffer->handle());
3826
3827 // And submit on the wrong queue
3828 VkSubmitInfo submit_info = {};
3829 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
3830 submit_info.commandBufferCount = 1;
3831 submit_info.pCommandBuffers = &m_commandBuffer->handle();
Tobin Ehlisfd213ea2016-08-10 17:10:46 -06003832 vkQueueSubmit(other_queue, 1, &submit_info, VK_NULL_HANDLE);
Mark Lobodzinski570efc62016-08-09 16:43:19 -06003833
3834 m_errorMonitor->VerifyFound();
Mark Lobodzinski570efc62016-08-09 16:43:19 -06003835}
3836
Chris Forbes48a53902016-06-30 11:46:27 +12003837TEST_F(VkLayerTest, RenderPassInitialLayoutUndefined) {
3838 TEST_DESCRIPTION("Ensure that CmdBeginRenderPass with an attachment's "
3839 "initialLayout of VK_IMAGE_LAYOUT_UNDEFINED works when "
3840 "the command buffer has prior knowledge of that "
3841 "attachment's layout.");
3842
3843 m_errorMonitor->ExpectSuccess();
3844
3845 ASSERT_NO_FATAL_FAILURE(InitState());
3846
3847 // A renderpass with one color attachment.
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003848 VkAttachmentDescription attachment = {0,
3849 VK_FORMAT_R8G8B8A8_UNORM,
3850 VK_SAMPLE_COUNT_1_BIT,
3851 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
3852 VK_ATTACHMENT_STORE_OP_STORE,
3853 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
3854 VK_ATTACHMENT_STORE_OP_DONT_CARE,
3855 VK_IMAGE_LAYOUT_UNDEFINED,
3856 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL};
Chris Forbes48a53902016-06-30 11:46:27 +12003857
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003858 VkAttachmentReference att_ref = {0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL};
Chris Forbes48a53902016-06-30 11:46:27 +12003859
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003860 VkSubpassDescription subpass = {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 1, &att_ref, nullptr, nullptr, 0, nullptr};
Chris Forbes48a53902016-06-30 11:46:27 +12003861
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003862 VkRenderPassCreateInfo rpci = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 1, &attachment, 1, &subpass, 0, nullptr};
Chris Forbes48a53902016-06-30 11:46:27 +12003863
3864 VkRenderPass rp;
3865 VkResult err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
3866 ASSERT_VK_SUCCESS(err);
3867
3868 // A compatible framebuffer.
3869 VkImageObj image(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003870 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 +12003871 ASSERT_TRUE(image.initialized());
3872
3873 VkImageViewCreateInfo ivci = {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003874 VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO,
3875 nullptr,
3876 0,
3877 image.handle(),
3878 VK_IMAGE_VIEW_TYPE_2D,
3879 VK_FORMAT_R8G8B8A8_UNORM,
3880 {VK_COMPONENT_SWIZZLE_IDENTITY, VK_COMPONENT_SWIZZLE_IDENTITY, VK_COMPONENT_SWIZZLE_IDENTITY,
3881 VK_COMPONENT_SWIZZLE_IDENTITY},
3882 {VK_IMAGE_ASPECT_COLOR_BIT, 0, 1, 0, 1},
Chris Forbes48a53902016-06-30 11:46:27 +12003883 };
3884 VkImageView view;
3885 err = vkCreateImageView(m_device->device(), &ivci, nullptr, &view);
3886 ASSERT_VK_SUCCESS(err);
3887
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003888 VkFramebufferCreateInfo fci = {VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr, 0, rp, 1, &view, 32, 32, 1};
Chris Forbes48a53902016-06-30 11:46:27 +12003889 VkFramebuffer fb;
3890 err = vkCreateFramebuffer(m_device->device(), &fci, nullptr, &fb);
3891 ASSERT_VK_SUCCESS(err);
3892
3893 // Record a single command buffer which uses this renderpass twice. The
3894 // bug is triggered at the beginning of the second renderpass, when the
3895 // command buffer already has a layout recorded for the attachment.
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003896 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 +12003897 BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003898 vkCmdBeginRenderPass(m_commandBuffer->handle(), &rpbi, VK_SUBPASS_CONTENTS_INLINE);
Chris Forbes48a53902016-06-30 11:46:27 +12003899 vkCmdEndRenderPass(m_commandBuffer->handle());
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003900 vkCmdBeginRenderPass(m_commandBuffer->handle(), &rpbi, VK_SUBPASS_CONTENTS_INLINE);
Chris Forbes48a53902016-06-30 11:46:27 +12003901
3902 m_errorMonitor->VerifyNotFound();
3903
3904 vkCmdEndRenderPass(m_commandBuffer->handle());
3905 EndCommandBuffer();
3906
3907 vkDestroyFramebuffer(m_device->device(), fb, nullptr);
3908 vkDestroyRenderPass(m_device->device(), rp, nullptr);
3909 vkDestroyImageView(m_device->device(), view, nullptr);
3910}
3911
Tobin Ehlis75ac37b2016-07-29 10:55:41 -06003912TEST_F(VkLayerTest, FramebufferBindingDestroyCommandPool) {
3913 TEST_DESCRIPTION("This test should pass. Create a Framebuffer and "
3914 "command buffer, bind them together, then destroy "
3915 "command pool and framebuffer and verify there are no "
3916 "errors.");
3917
3918 m_errorMonitor->ExpectSuccess();
3919
3920 ASSERT_NO_FATAL_FAILURE(InitState());
3921
3922 // A renderpass with one color attachment.
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003923 VkAttachmentDescription attachment = {0,
3924 VK_FORMAT_R8G8B8A8_UNORM,
3925 VK_SAMPLE_COUNT_1_BIT,
3926 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
3927 VK_ATTACHMENT_STORE_OP_STORE,
3928 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
3929 VK_ATTACHMENT_STORE_OP_DONT_CARE,
3930 VK_IMAGE_LAYOUT_UNDEFINED,
3931 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL};
Tobin Ehlis75ac37b2016-07-29 10:55:41 -06003932
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003933 VkAttachmentReference att_ref = {0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL};
Tobin Ehlis75ac37b2016-07-29 10:55:41 -06003934
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003935 VkSubpassDescription subpass = {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 1, &att_ref, nullptr, nullptr, 0, nullptr};
Tobin Ehlis75ac37b2016-07-29 10:55:41 -06003936
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003937 VkRenderPassCreateInfo rpci = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 1, &attachment, 1, &subpass, 0, nullptr};
Tobin Ehlis75ac37b2016-07-29 10:55:41 -06003938
3939 VkRenderPass rp;
3940 VkResult err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
3941 ASSERT_VK_SUCCESS(err);
3942
3943 // A compatible framebuffer.
3944 VkImageObj image(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003945 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 -06003946 ASSERT_TRUE(image.initialized());
3947
3948 VkImageViewCreateInfo ivci = {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003949 VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO,
3950 nullptr,
3951 0,
3952 image.handle(),
3953 VK_IMAGE_VIEW_TYPE_2D,
3954 VK_FORMAT_R8G8B8A8_UNORM,
3955 {VK_COMPONENT_SWIZZLE_IDENTITY, VK_COMPONENT_SWIZZLE_IDENTITY, VK_COMPONENT_SWIZZLE_IDENTITY,
3956 VK_COMPONENT_SWIZZLE_IDENTITY},
3957 {VK_IMAGE_ASPECT_COLOR_BIT, 0, 1, 0, 1},
Tobin Ehlis75ac37b2016-07-29 10:55:41 -06003958 };
3959 VkImageView view;
3960 err = vkCreateImageView(m_device->device(), &ivci, nullptr, &view);
3961 ASSERT_VK_SUCCESS(err);
3962
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003963 VkFramebufferCreateInfo fci = {VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr, 0, rp, 1, &view, 32, 32, 1};
Tobin Ehlis75ac37b2016-07-29 10:55:41 -06003964 VkFramebuffer fb;
3965 err = vkCreateFramebuffer(m_device->device(), &fci, nullptr, &fb);
3966 ASSERT_VK_SUCCESS(err);
3967
3968 // Explicitly create a command buffer to bind the FB to so that we can then
3969 // destroy the command pool in order to implicitly free command buffer
3970 VkCommandPool command_pool;
3971 VkCommandPoolCreateInfo pool_create_info{};
3972 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
3973 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
3974 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003975 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
Tobin Ehlis75ac37b2016-07-29 10:55:41 -06003976
3977 VkCommandBuffer command_buffer;
3978 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003979 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
Tobin Ehlis75ac37b2016-07-29 10:55:41 -06003980 command_buffer_allocate_info.commandPool = command_pool;
3981 command_buffer_allocate_info.commandBufferCount = 1;
3982 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003983 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, &command_buffer);
Tobin Ehlis75ac37b2016-07-29 10:55:41 -06003984
3985 // Begin our cmd buffer with renderpass using our framebuffer
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003986 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 -06003987 VkCommandBufferBeginInfo begin_info{};
3988 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
3989 vkBeginCommandBuffer(command_buffer, &begin_info);
3990
3991 vkCmdBeginRenderPass(command_buffer, &rpbi, VK_SUBPASS_CONTENTS_INLINE);
3992 vkCmdEndRenderPass(command_buffer);
3993 vkEndCommandBuffer(command_buffer);
Mark Lobodzinski7d10a822016-08-03 14:08:40 -06003994 vkDestroyImageView(m_device->device(), view, nullptr);
Tobin Ehlis75ac37b2016-07-29 10:55:41 -06003995 // Destroy command pool to implicitly free command buffer
3996 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
3997 vkDestroyFramebuffer(m_device->device(), fb, nullptr);
3998 vkDestroyRenderPass(m_device->device(), rp, nullptr);
3999 m_errorMonitor->VerifyNotFound();
4000}
4001
Chris Forbes51bf7c92016-06-30 15:22:08 +12004002TEST_F(VkLayerTest, RenderPassSubpassZeroTransitionsApplied) {
4003 TEST_DESCRIPTION("Ensure that CmdBeginRenderPass applies the layout "
4004 "transitions for the first subpass");
4005
4006 m_errorMonitor->ExpectSuccess();
4007
4008 ASSERT_NO_FATAL_FAILURE(InitState());
4009
4010 // A renderpass with one color attachment.
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004011 VkAttachmentDescription attachment = {0,
4012 VK_FORMAT_R8G8B8A8_UNORM,
4013 VK_SAMPLE_COUNT_1_BIT,
4014 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
4015 VK_ATTACHMENT_STORE_OP_STORE,
4016 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
4017 VK_ATTACHMENT_STORE_OP_DONT_CARE,
4018 VK_IMAGE_LAYOUT_UNDEFINED,
4019 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL};
Chris Forbes51bf7c92016-06-30 15:22:08 +12004020
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004021 VkAttachmentReference att_ref = {0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL};
Chris Forbes51bf7c92016-06-30 15:22:08 +12004022
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004023 VkSubpassDescription subpass = {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 1, &att_ref, nullptr, nullptr, 0, nullptr};
Chris Forbes51bf7c92016-06-30 15:22:08 +12004024
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004025 VkSubpassDependency dep = {0,
4026 0,
4027 VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT,
4028 VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT,
4029 VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT,
4030 VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT,
4031 VK_DEPENDENCY_BY_REGION_BIT};
Chris Forbes51bf7c92016-06-30 15:22:08 +12004032
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004033 VkRenderPassCreateInfo rpci = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 1, &attachment, 1, &subpass, 1, &dep};
Chris Forbes51bf7c92016-06-30 15:22:08 +12004034
4035 VkResult err;
4036 VkRenderPass rp;
4037 err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
4038 ASSERT_VK_SUCCESS(err);
4039
4040 // A compatible framebuffer.
4041 VkImageObj image(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004042 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 +12004043 ASSERT_TRUE(image.initialized());
4044
4045 VkImageViewCreateInfo ivci = {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004046 VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO,
4047 nullptr,
4048 0,
4049 image.handle(),
4050 VK_IMAGE_VIEW_TYPE_2D,
4051 VK_FORMAT_R8G8B8A8_UNORM,
4052 {VK_COMPONENT_SWIZZLE_IDENTITY, VK_COMPONENT_SWIZZLE_IDENTITY, VK_COMPONENT_SWIZZLE_IDENTITY,
4053 VK_COMPONENT_SWIZZLE_IDENTITY},
4054 {VK_IMAGE_ASPECT_COLOR_BIT, 0, 1, 0, 1},
Chris Forbes51bf7c92016-06-30 15:22:08 +12004055 };
4056 VkImageView view;
4057 err = vkCreateImageView(m_device->device(), &ivci, nullptr, &view);
4058 ASSERT_VK_SUCCESS(err);
4059
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004060 VkFramebufferCreateInfo fci = {VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr, 0, rp, 1, &view, 32, 32, 1};
Chris Forbes51bf7c92016-06-30 15:22:08 +12004061 VkFramebuffer fb;
4062 err = vkCreateFramebuffer(m_device->device(), &fci, nullptr, &fb);
4063 ASSERT_VK_SUCCESS(err);
4064
4065 // Record a single command buffer which issues a pipeline barrier w/
4066 // image memory barrier for the attachment. This detects the previously
4067 // missing tracking of the subpass layout by throwing a validation error
4068 // if it doesn't occur.
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004069 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 +12004070 BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004071 vkCmdBeginRenderPass(m_commandBuffer->handle(), &rpbi, VK_SUBPASS_CONTENTS_INLINE);
Chris Forbes51bf7c92016-06-30 15:22:08 +12004072
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004073 VkImageMemoryBarrier imb = {VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER,
4074 nullptr,
4075 VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT,
4076 VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT,
4077 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
4078 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
4079 VK_QUEUE_FAMILY_IGNORED,
4080 VK_QUEUE_FAMILY_IGNORED,
4081 image.handle(),
4082 {VK_IMAGE_ASPECT_COLOR_BIT, 0, 1, 0, 1}};
4083 vkCmdPipelineBarrier(m_commandBuffer->handle(), VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT,
4084 VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT, VK_DEPENDENCY_BY_REGION_BIT, 0, nullptr, 0, nullptr, 1,
4085 &imb);
Chris Forbes51bf7c92016-06-30 15:22:08 +12004086
4087 vkCmdEndRenderPass(m_commandBuffer->handle());
4088 m_errorMonitor->VerifyNotFound();
4089 EndCommandBuffer();
4090
4091 vkDestroyFramebuffer(m_device->device(), fb, nullptr);
4092 vkDestroyRenderPass(m_device->device(), rp, nullptr);
4093 vkDestroyImageView(m_device->device(), view, nullptr);
4094}
4095
Mark Lobodzinski77a5d6f2016-08-05 09:38:18 -06004096TEST_F(VkLayerTest, DepthStencilLayoutTransitionForDepthOnlyImageview) {
4097 TEST_DESCRIPTION("Validate that when an imageView of a depth/stencil image "
4098 "is used as a depth/stencil framebuffer attachment, the "
4099 "aspectMask is ignored and both depth and stencil image "
4100 "subresources are used.");
4101
4102 VkFormatProperties format_properties;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004103 vkGetPhysicalDeviceFormatProperties(gpu(), VK_FORMAT_D32_SFLOAT_S8_UINT, &format_properties);
4104 if (!(format_properties.optimalTilingFeatures & VK_FORMAT_FEATURE_SAMPLED_IMAGE_BIT)) {
Mark Lobodzinski77a5d6f2016-08-05 09:38:18 -06004105 return;
4106 }
4107
4108 m_errorMonitor->ExpectSuccess();
4109
4110 ASSERT_NO_FATAL_FAILURE(InitState());
4111
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004112 VkAttachmentDescription attachment = {0,
4113 VK_FORMAT_D32_SFLOAT_S8_UINT,
4114 VK_SAMPLE_COUNT_1_BIT,
4115 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
4116 VK_ATTACHMENT_STORE_OP_STORE,
4117 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
4118 VK_ATTACHMENT_STORE_OP_DONT_CARE,
4119 VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL,
4120 VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL};
Mark Lobodzinski77a5d6f2016-08-05 09:38:18 -06004121
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004122 VkAttachmentReference att_ref = {0, VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL};
Mark Lobodzinski77a5d6f2016-08-05 09:38:18 -06004123
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004124 VkSubpassDescription subpass = {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 0, nullptr, nullptr, &att_ref, 0, nullptr};
Mark Lobodzinski77a5d6f2016-08-05 09:38:18 -06004125
4126 VkSubpassDependency dep = {0,
4127 0,
4128 VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT,
4129 VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT,
4130 VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT,
4131 VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT,
4132 VK_DEPENDENCY_BY_REGION_BIT};
4133
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004134 VkRenderPassCreateInfo rpci = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 1, &attachment, 1, &subpass, 1, &dep};
Mark Lobodzinski77a5d6f2016-08-05 09:38:18 -06004135
4136 VkResult err;
4137 VkRenderPass rp;
4138 err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
4139 ASSERT_VK_SUCCESS(err);
4140
4141 VkImageObj image(m_device);
4142 image.init_no_layout(32, 32, VK_FORMAT_D32_SFLOAT_S8_UINT,
4143 0x26, // usage
4144 VK_IMAGE_TILING_OPTIMAL, 0);
4145 ASSERT_TRUE(image.initialized());
4146 image.SetLayout(0x6, VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL);
4147
4148 VkImageViewCreateInfo ivci = {
4149 VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO,
4150 nullptr,
4151 0,
4152 image.handle(),
4153 VK_IMAGE_VIEW_TYPE_2D,
4154 VK_FORMAT_D32_SFLOAT_S8_UINT,
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004155 {VK_COMPONENT_SWIZZLE_R, VK_COMPONENT_SWIZZLE_G, VK_COMPONENT_SWIZZLE_B, VK_COMPONENT_SWIZZLE_A},
Mark Lobodzinski77a5d6f2016-08-05 09:38:18 -06004156 {0x2, 0, 1, 0, 1},
4157 };
4158 VkImageView view;
4159 err = vkCreateImageView(m_device->device(), &ivci, nullptr, &view);
4160 ASSERT_VK_SUCCESS(err);
4161
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004162 VkFramebufferCreateInfo fci = {VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr, 0, rp, 1, &view, 32, 32, 1};
Mark Lobodzinski77a5d6f2016-08-05 09:38:18 -06004163 VkFramebuffer fb;
4164 err = vkCreateFramebuffer(m_device->device(), &fci, nullptr, &fb);
4165 ASSERT_VK_SUCCESS(err);
4166
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004167 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 -06004168 BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004169 vkCmdBeginRenderPass(m_commandBuffer->handle(), &rpbi, VK_SUBPASS_CONTENTS_INLINE);
Mark Lobodzinski77a5d6f2016-08-05 09:38:18 -06004170
4171 VkImageMemoryBarrier imb = {};
4172 imb.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
4173 imb.pNext = nullptr;
4174 imb.srcAccessMask = VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_WRITE_BIT;
4175 imb.dstAccessMask = VK_ACCESS_SHADER_READ_BIT;
4176 imb.oldLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
4177 imb.newLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
4178 imb.srcQueueFamilyIndex = 0;
4179 imb.dstQueueFamilyIndex = 0;
4180 imb.image = image.handle();
4181 imb.subresourceRange.aspectMask = 0x6;
4182 imb.subresourceRange.baseMipLevel = 0;
4183 imb.subresourceRange.levelCount = 0x1;
4184 imb.subresourceRange.baseArrayLayer = 0;
4185 imb.subresourceRange.layerCount = 0x1;
4186
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004187 vkCmdPipelineBarrier(m_commandBuffer->handle(), VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT,
4188 VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT, VK_DEPENDENCY_BY_REGION_BIT, 0, nullptr, 0, nullptr, 1,
Mark Lobodzinski77a5d6f2016-08-05 09:38:18 -06004189 &imb);
4190
4191 vkCmdEndRenderPass(m_commandBuffer->handle());
4192 EndCommandBuffer();
4193 QueueCommandBuffer(false);
4194 m_errorMonitor->VerifyNotFound();
4195
4196 vkDestroyFramebuffer(m_device->device(), fb, nullptr);
4197 vkDestroyRenderPass(m_device->device(), rp, nullptr);
4198 vkDestroyImageView(m_device->device(), view, nullptr);
4199}
Tony Barbourd5f7b822016-08-02 15:39:33 -06004200
Tony Barbour4e919972016-08-09 13:27:40 -06004201TEST_F(VkLayerTest, RenderPassInvalidRenderArea) {
4202 TEST_DESCRIPTION("Generate INVALID_RENDER_AREA error by beginning renderpass"
4203 "with extent outside of framebuffer");
4204 ASSERT_NO_FATAL_FAILURE(InitState());
4205 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
4206
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004207 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Cannot execute a render pass with renderArea "
4208 "not within the bound of the framebuffer.");
Tony Barbour4e919972016-08-09 13:27:40 -06004209
4210 // Framebuffer for render target is 256x256, exceed that for INVALID_RENDER_AREA
4211 m_renderPassBeginInfo.renderArea.extent.width = 257;
4212 m_renderPassBeginInfo.renderArea.extent.height = 257;
4213 BeginCommandBuffer();
4214 m_errorMonitor->VerifyFound();
4215}
4216
4217TEST_F(VkLayerTest, DisabledIndependentBlend) {
4218 TEST_DESCRIPTION("Generate INDEPENDENT_BLEND by disabling independent "
4219 "blend and then specifying different blend states for two "
4220 "attachements");
Cody Northrop5703cc72016-08-19 09:57:10 -06004221 VkPhysicalDeviceFeatures features = {};
4222 features.independentBlend = VK_FALSE;
Cody Northropc31a84f2016-08-22 10:41:47 -06004223 ASSERT_NO_FATAL_FAILURE(InitState(&features));
Tony Barbour4e919972016-08-09 13:27:40 -06004224
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004225 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
4226 "Invalid Pipeline CreateInfo: If independent blend feature not "
4227 "enabled, all elements of pAttachments must be identical");
Tony Barbour4e919972016-08-09 13:27:40 -06004228
Cody Northropc31a84f2016-08-22 10:41:47 -06004229 VkDescriptorSetObj descriptorSet(m_device);
4230 descriptorSet.AppendDummy();
4231 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Tony Barbour4e919972016-08-09 13:27:40 -06004232
Cody Northropc31a84f2016-08-22 10:41:47 -06004233 VkPipelineObj pipeline(m_device);
4234 VkRenderpassObj renderpass(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004235 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
Cody Northropc31a84f2016-08-22 10:41:47 -06004236 pipeline.AddShader(&vs);
Cody Northrop5703cc72016-08-19 09:57:10 -06004237
Cody Northropc31a84f2016-08-22 10:41:47 -06004238 VkPipelineColorBlendAttachmentState att_state1 = {}, att_state2 = {};
4239 att_state1.dstAlphaBlendFactor = VK_BLEND_FACTOR_CONSTANT_COLOR;
4240 att_state1.blendEnable = VK_TRUE;
4241 att_state2.dstAlphaBlendFactor = VK_BLEND_FACTOR_CONSTANT_COLOR;
4242 att_state2.blendEnable = VK_FALSE;
4243 pipeline.AddColorAttachment(0, &att_state1);
4244 pipeline.AddColorAttachment(1, &att_state2);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004245 pipeline.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderpass.handle());
Cody Northropc31a84f2016-08-22 10:41:47 -06004246 m_errorMonitor->VerifyFound();
Tony Barbour4e919972016-08-09 13:27:40 -06004247}
4248
4249TEST_F(VkLayerTest, RenderPassDepthStencilAttachmentUnused) {
4250 TEST_DESCRIPTION("Specify no depth attachement in renderpass then specify "
4251 "depth attachments in subpass");
Cody Northropc31a84f2016-08-22 10:41:47 -06004252 ASSERT_NO_FATAL_FAILURE(InitState());
Tony Barbour4e919972016-08-09 13:27:40 -06004253
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004254 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
4255 "vkCreateRenderPass has no depth/stencil attachment, yet subpass");
Tony Barbour4e919972016-08-09 13:27:40 -06004256
4257 // Create a renderPass with a single color attachment
4258 VkAttachmentReference attach = {};
4259 attach.layout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
4260 VkSubpassDescription subpass = {};
4261 VkRenderPassCreateInfo rpci = {};
4262 rpci.subpassCount = 1;
4263 rpci.pSubpasses = &subpass;
4264 rpci.attachmentCount = 1;
4265 VkAttachmentDescription attach_desc = {};
4266 attach_desc.format = VK_FORMAT_B8G8R8A8_UNORM;
4267 attach_desc.samples = VK_SAMPLE_COUNT_1_BIT;
4268 rpci.pAttachments = &attach_desc;
4269 rpci.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
4270 VkRenderPass rp;
4271 subpass.pDepthStencilAttachment = &attach;
4272 subpass.pColorAttachments = NULL;
4273 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
4274 m_errorMonitor->VerifyFound();
4275}
4276
Chris Forbes6b3d3f42016-06-30 16:09:47 +12004277TEST_F(VkLayerTest, RenderPassTransitionsAttachmentUnused) {
4278 TEST_DESCRIPTION("Ensure that layout transitions work correctly without "
4279 "errors, when an attachment reference is "
4280 "VK_ATTACHMENT_UNUSED");
4281
4282 m_errorMonitor->ExpectSuccess();
4283
4284 ASSERT_NO_FATAL_FAILURE(InitState());
4285
4286 // A renderpass with no attachments
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004287 VkAttachmentReference att_ref = {VK_ATTACHMENT_UNUSED, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL};
Chris Forbes6b3d3f42016-06-30 16:09:47 +12004288
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004289 VkSubpassDescription subpass = {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 1, &att_ref, nullptr, nullptr, 0, nullptr};
Chris Forbes6b3d3f42016-06-30 16:09:47 +12004290
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004291 VkRenderPassCreateInfo rpci = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 0, nullptr, 1, &subpass, 0, nullptr};
Chris Forbes6b3d3f42016-06-30 16:09:47 +12004292
4293 VkRenderPass rp;
4294 VkResult err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
4295 ASSERT_VK_SUCCESS(err);
4296
4297 // A compatible framebuffer.
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004298 VkFramebufferCreateInfo fci = {VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr, 0, rp, 0, nullptr, 32, 32, 1};
Chris Forbes6b3d3f42016-06-30 16:09:47 +12004299 VkFramebuffer fb;
4300 err = vkCreateFramebuffer(m_device->device(), &fci, nullptr, &fb);
4301 ASSERT_VK_SUCCESS(err);
4302
4303 // Record a command buffer which just begins and ends the renderpass. The
4304 // bug manifests in BeginRenderPass.
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004305 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 +12004306 BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004307 vkCmdBeginRenderPass(m_commandBuffer->handle(), &rpbi, VK_SUBPASS_CONTENTS_INLINE);
Chris Forbes6b3d3f42016-06-30 16:09:47 +12004308 vkCmdEndRenderPass(m_commandBuffer->handle());
4309 m_errorMonitor->VerifyNotFound();
4310 EndCommandBuffer();
4311
4312 vkDestroyFramebuffer(m_device->device(), fb, nullptr);
4313 vkDestroyRenderPass(m_device->device(), rp, nullptr);
4314}
4315
Mark Lobodzinskice7eee72016-06-14 16:33:29 -06004316// This is a positive test. No errors are expected.
4317TEST_F(VkLayerTest, StencilLoadOp) {
4318 TEST_DESCRIPTION("Create a stencil-only attachment with a LOAD_OP set to "
4319 "CLEAR. stencil[Load|Store]Op used to be ignored.");
4320 VkResult result = VK_SUCCESS;
4321 VkImageFormatProperties formatProps;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004322 vkGetPhysicalDeviceImageFormatProperties(gpu(), VK_FORMAT_D24_UNORM_S8_UINT, VK_IMAGE_TYPE_2D, VK_IMAGE_TILING_OPTIMAL,
4323 VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_SRC_BIT, 0,
4324 &formatProps);
Mark Lobodzinskice7eee72016-06-14 16:33:29 -06004325 if (formatProps.maxExtent.width < 100 || formatProps.maxExtent.height < 100) {
4326 return;
4327 }
4328
4329 ASSERT_NO_FATAL_FAILURE(InitState());
4330 VkFormat depth_stencil_fmt = VK_FORMAT_D24_UNORM_S8_UINT;
4331 m_depthStencil->Init(m_device, 100, 100, depth_stencil_fmt,
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004332 VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_SRC_BIT);
Mark Lobodzinskice7eee72016-06-14 16:33:29 -06004333 VkAttachmentDescription att = {};
4334 VkAttachmentReference ref = {};
4335 att.format = depth_stencil_fmt;
Chris Forbes787b4532016-09-16 16:45:16 +12004336 att.samples = VK_SAMPLE_COUNT_1_BIT;
Mark Lobodzinskice7eee72016-06-14 16:33:29 -06004337 att.loadOp = VK_ATTACHMENT_LOAD_OP_DONT_CARE;
4338 att.storeOp = VK_ATTACHMENT_STORE_OP_DONT_CARE;
4339 att.stencilLoadOp = VK_ATTACHMENT_LOAD_OP_CLEAR;
4340 att.stencilStoreOp = VK_ATTACHMENT_STORE_OP_STORE;
4341 att.initialLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
4342 att.finalLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
4343
4344 VkClearValue clear;
4345 clear.depthStencil.depth = 1.0;
4346 clear.depthStencil.stencil = 0;
4347 ref.attachment = 0;
4348 ref.layout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
4349
4350 VkSubpassDescription subpass = {};
4351 subpass.pipelineBindPoint = VK_PIPELINE_BIND_POINT_GRAPHICS;
4352 subpass.flags = 0;
4353 subpass.inputAttachmentCount = 0;
4354 subpass.pInputAttachments = NULL;
4355 subpass.colorAttachmentCount = 0;
4356 subpass.pColorAttachments = NULL;
4357 subpass.pResolveAttachments = NULL;
4358 subpass.pDepthStencilAttachment = &ref;
4359 subpass.preserveAttachmentCount = 0;
4360 subpass.pPreserveAttachments = NULL;
4361
4362 VkRenderPass rp;
4363 VkRenderPassCreateInfo rp_info = {};
4364 rp_info.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
4365 rp_info.attachmentCount = 1;
4366 rp_info.pAttachments = &att;
4367 rp_info.subpassCount = 1;
4368 rp_info.pSubpasses = &subpass;
4369 result = vkCreateRenderPass(device(), &rp_info, NULL, &rp);
4370 ASSERT_VK_SUCCESS(result);
4371
4372 VkImageView *depthView = m_depthStencil->BindInfo();
4373 VkFramebufferCreateInfo fb_info = {};
4374 fb_info.sType = VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO;
4375 fb_info.pNext = NULL;
4376 fb_info.renderPass = rp;
4377 fb_info.attachmentCount = 1;
4378 fb_info.pAttachments = depthView;
4379 fb_info.width = 100;
4380 fb_info.height = 100;
4381 fb_info.layers = 1;
4382 VkFramebuffer fb;
4383 result = vkCreateFramebuffer(device(), &fb_info, NULL, &fb);
4384 ASSERT_VK_SUCCESS(result);
4385
Mark Lobodzinskice7eee72016-06-14 16:33:29 -06004386 VkRenderPassBeginInfo rpbinfo = {};
4387 rpbinfo.clearValueCount = 1;
4388 rpbinfo.pClearValues = &clear;
4389 rpbinfo.pNext = NULL;
4390 rpbinfo.renderPass = rp;
4391 rpbinfo.sType = VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO;
4392 rpbinfo.renderArea.extent.width = 100;
4393 rpbinfo.renderArea.extent.height = 100;
4394 rpbinfo.renderArea.offset.x = 0;
4395 rpbinfo.renderArea.offset.y = 0;
4396 rpbinfo.framebuffer = fb;
4397
4398 VkFence fence = {};
4399 VkFenceCreateInfo fence_ci = {};
4400 fence_ci.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
4401 fence_ci.pNext = nullptr;
4402 fence_ci.flags = 0;
4403 result = vkCreateFence(m_device->device(), &fence_ci, nullptr, &fence);
4404 ASSERT_VK_SUCCESS(result);
4405
Mark Lobodzinskice7eee72016-06-14 16:33:29 -06004406 m_commandBuffer->BeginCommandBuffer();
4407 m_commandBuffer->BeginRenderPass(rpbinfo);
4408 m_commandBuffer->EndRenderPass();
4409 m_commandBuffer->EndCommandBuffer();
4410 m_commandBuffer->QueueCommandBuffer(fence);
4411
4412 VkImageObj destImage(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004413 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 -06004414 VK_IMAGE_TILING_OPTIMAL, 0);
4415 VkImageMemoryBarrier barrier = {};
4416 VkImageSubresourceRange range;
4417 barrier.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004418 barrier.srcAccessMask = VK_ACCESS_TRANSFER_WRITE_BIT | VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_WRITE_BIT;
4419 barrier.dstAccessMask = VK_ACCESS_TRANSFER_READ_BIT | VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_READ_BIT;
Mark Lobodzinskice7eee72016-06-14 16:33:29 -06004420 barrier.oldLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
4421 barrier.newLayout = VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL;
4422 barrier.image = m_depthStencil->handle();
4423 range.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT;
4424 range.baseMipLevel = 0;
4425 range.levelCount = 1;
4426 range.baseArrayLayer = 0;
4427 range.layerCount = 1;
4428 barrier.subresourceRange = range;
4429 vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
4430 VkCommandBufferObj cmdbuf(m_device, m_commandPool);
4431 cmdbuf.BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004432 cmdbuf.PipelineBarrier(VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0, nullptr, 0, nullptr, 1,
4433 &barrier);
Mark Lobodzinskice7eee72016-06-14 16:33:29 -06004434 barrier.srcAccessMask = 0;
4435 barrier.oldLayout = VK_IMAGE_LAYOUT_UNDEFINED;
4436 barrier.newLayout = VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL;
4437 barrier.image = destImage.handle();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004438 barrier.dstAccessMask = VK_ACCESS_TRANSFER_WRITE_BIT | VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_WRITE_BIT;
4439 cmdbuf.PipelineBarrier(VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0, nullptr, 0, nullptr, 1,
4440 &barrier);
Mark Lobodzinskice7eee72016-06-14 16:33:29 -06004441 VkImageCopy cregion;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004442 cregion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT;
Mark Lobodzinskice7eee72016-06-14 16:33:29 -06004443 cregion.srcSubresource.mipLevel = 0;
4444 cregion.srcSubresource.baseArrayLayer = 0;
4445 cregion.srcSubresource.layerCount = 1;
4446 cregion.srcOffset.x = 0;
4447 cregion.srcOffset.y = 0;
4448 cregion.srcOffset.z = 0;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004449 cregion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT;
Mark Lobodzinskice7eee72016-06-14 16:33:29 -06004450 cregion.dstSubresource.mipLevel = 0;
4451 cregion.dstSubresource.baseArrayLayer = 0;
4452 cregion.dstSubresource.layerCount = 1;
4453 cregion.dstOffset.x = 0;
4454 cregion.dstOffset.y = 0;
4455 cregion.dstOffset.z = 0;
4456 cregion.extent.width = 100;
4457 cregion.extent.height = 100;
4458 cregion.extent.depth = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004459 cmdbuf.CopyImage(m_depthStencil->handle(), VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL, destImage.handle(),
Mark Lobodzinskice7eee72016-06-14 16:33:29 -06004460 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, &cregion);
4461 cmdbuf.EndCommandBuffer();
4462
4463 VkSubmitInfo submit_info;
4464 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
4465 submit_info.pNext = NULL;
4466 submit_info.waitSemaphoreCount = 0;
4467 submit_info.pWaitSemaphores = NULL;
4468 submit_info.pWaitDstStageMask = NULL;
4469 submit_info.commandBufferCount = 1;
4470 submit_info.pCommandBuffers = &cmdbuf.handle();
4471 submit_info.signalSemaphoreCount = 0;
4472 submit_info.pSignalSemaphores = NULL;
4473
4474 m_errorMonitor->ExpectSuccess();
4475 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
4476 m_errorMonitor->VerifyNotFound();
4477
Mark Lobodzinskid0440da2016-06-17 15:10:03 -06004478 vkQueueWaitIdle(m_device->m_queue);
Mark Lobodzinskice7eee72016-06-14 16:33:29 -06004479 vkDestroyFence(m_device->device(), fence, nullptr);
4480 vkDestroyRenderPass(m_device->device(), rp, nullptr);
4481 vkDestroyFramebuffer(m_device->device(), fb, nullptr);
4482}
4483
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06004484TEST_F(VkLayerTest, UnusedPreserveAttachment) {
4485 TEST_DESCRIPTION("Create a framebuffer where a subpass has a preserve "
4486 "attachment reference of VK_ATTACHMENT_UNUSED");
4487
4488 ASSERT_NO_FATAL_FAILURE(InitState());
4489 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
4490
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004491 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "must not be VK_ATTACHMENT_UNUSED");
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06004492
4493 VkAttachmentReference color_attach = {};
4494 color_attach.layout = VK_IMAGE_LAYOUT_GENERAL;
4495 color_attach.attachment = 0;
4496 uint32_t preserve_attachment = VK_ATTACHMENT_UNUSED;
4497 VkSubpassDescription subpass = {};
4498 subpass.colorAttachmentCount = 1;
4499 subpass.pColorAttachments = &color_attach;
4500 subpass.preserveAttachmentCount = 1;
4501 subpass.pPreserveAttachments = &preserve_attachment;
4502
4503 VkRenderPassCreateInfo rpci = {};
4504 rpci.subpassCount = 1;
4505 rpci.pSubpasses = &subpass;
4506 rpci.attachmentCount = 1;
4507 VkAttachmentDescription attach_desc = {};
4508 attach_desc.format = VK_FORMAT_UNDEFINED;
4509 rpci.pAttachments = &attach_desc;
4510 rpci.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
4511 VkRenderPass rp;
Mark Lobodzinskia4feeeb2016-06-17 12:00:46 -06004512 VkResult result = vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06004513
4514 m_errorMonitor->VerifyFound();
4515
Mark Lobodzinskia4feeeb2016-06-17 12:00:46 -06004516 if (result == VK_SUCCESS) {
4517 vkDestroyRenderPass(m_device->device(), rp, NULL);
4518 }
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06004519}
4520
Chris Forbesc5389742016-06-29 11:49:23 +12004521TEST_F(VkLayerTest, CreateRenderPassResolveRequiresColorMsaa) {
Chris Forbes6655bb32016-07-01 18:27:30 +12004522 TEST_DESCRIPTION("Ensure that CreateRenderPass produces a validation error "
4523 "when the source of a subpass multisample resolve "
4524 "does not have multiple samples.");
4525
Chris Forbesc5389742016-06-29 11:49:23 +12004526 ASSERT_NO_FATAL_FAILURE(InitState());
4527
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004528 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
4529 "Subpass 0 requests multisample resolve from attachment 0 which has "
4530 "VK_SAMPLE_COUNT_1_BIT");
Chris Forbesc5389742016-06-29 11:49:23 +12004531
4532 VkAttachmentDescription attachments[] = {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004533 {0, VK_FORMAT_R8G8B8A8_UNORM, VK_SAMPLE_COUNT_1_BIT, VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE,
4534 VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
4535 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL},
4536 {0, VK_FORMAT_R8G8B8A8_UNORM, VK_SAMPLE_COUNT_1_BIT, VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE,
4537 VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
4538 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL},
Chris Forbesc5389742016-06-29 11:49:23 +12004539 };
4540
4541 VkAttachmentReference color = {
4542 0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
4543 };
4544
4545 VkAttachmentReference resolve = {
4546 0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
4547 };
4548
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004549 VkSubpassDescription subpass = {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 1, &color, &resolve, nullptr, 0, nullptr};
Chris Forbesc5389742016-06-29 11:49:23 +12004550
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004551 VkRenderPassCreateInfo rpci = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 2, attachments, 1, &subpass, 0, nullptr};
Chris Forbesc5389742016-06-29 11:49:23 +12004552
4553 VkRenderPass rp;
4554 VkResult err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
4555
4556 m_errorMonitor->VerifyFound();
4557
4558 if (err == VK_SUCCESS)
4559 vkDestroyRenderPass(m_device->device(), rp, nullptr);
4560}
4561
4562TEST_F(VkLayerTest, CreateRenderPassResolveRequiresSingleSampleDest) {
Chris Forbes6655bb32016-07-01 18:27:30 +12004563 TEST_DESCRIPTION("Ensure CreateRenderPass produces a validation error "
4564 "when a subpass multisample resolve operation is "
4565 "requested, and the destination of that resolve has "
4566 "multiple samples.");
4567
Chris Forbesc5389742016-06-29 11:49:23 +12004568 ASSERT_NO_FATAL_FAILURE(InitState());
4569
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004570 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
4571 "Subpass 0 requests multisample resolve into attachment 1, which "
4572 "must have VK_SAMPLE_COUNT_1_BIT but has VK_SAMPLE_COUNT_4_BIT");
Chris Forbesc5389742016-06-29 11:49:23 +12004573
4574 VkAttachmentDescription attachments[] = {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004575 {0, VK_FORMAT_R8G8B8A8_UNORM, VK_SAMPLE_COUNT_4_BIT, VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE,
4576 VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
4577 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL},
4578 {0, VK_FORMAT_R8G8B8A8_UNORM, VK_SAMPLE_COUNT_4_BIT, VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE,
4579 VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
4580 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL},
Chris Forbesc5389742016-06-29 11:49:23 +12004581 };
4582
4583 VkAttachmentReference color = {
4584 0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
4585 };
4586
4587 VkAttachmentReference resolve = {
4588 1, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
4589 };
4590
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004591 VkSubpassDescription subpass = {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 1, &color, &resolve, nullptr, 0, nullptr};
Chris Forbesc5389742016-06-29 11:49:23 +12004592
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004593 VkRenderPassCreateInfo rpci = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 2, attachments, 1, &subpass, 0, nullptr};
Chris Forbesc5389742016-06-29 11:49:23 +12004594
4595 VkRenderPass rp;
4596 VkResult err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
4597
4598 m_errorMonitor->VerifyFound();
4599
4600 if (err == VK_SUCCESS)
4601 vkDestroyRenderPass(m_device->device(), rp, nullptr);
4602}
4603
Chris Forbes3f128ef2016-06-29 14:58:53 +12004604TEST_F(VkLayerTest, CreateRenderPassSubpassSampleCountConsistency) {
Chris Forbes6655bb32016-07-01 18:27:30 +12004605 TEST_DESCRIPTION("Ensure CreateRenderPass produces a validation error "
4606 "when the color and depth attachments used by a subpass "
4607 "have inconsistent sample counts");
4608
Chris Forbes3f128ef2016-06-29 14:58:53 +12004609 ASSERT_NO_FATAL_FAILURE(InitState());
4610
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004611 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
4612 "Subpass 0 attempts to render to attachments with inconsistent sample counts");
Chris Forbes3f128ef2016-06-29 14:58:53 +12004613
4614 VkAttachmentDescription attachments[] = {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004615 {0, VK_FORMAT_R8G8B8A8_UNORM, VK_SAMPLE_COUNT_1_BIT, VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE,
4616 VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
4617 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL},
4618 {0, VK_FORMAT_R8G8B8A8_UNORM, VK_SAMPLE_COUNT_4_BIT, VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE,
4619 VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
4620 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL},
Chris Forbes3f128ef2016-06-29 14:58:53 +12004621 };
4622
4623 VkAttachmentReference color[] = {
4624 {
4625 0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
4626 },
4627 {
4628 1, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
4629 },
4630 };
4631
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004632 VkSubpassDescription subpass = {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 2, color, nullptr, nullptr, 0, nullptr};
Chris Forbes3f128ef2016-06-29 14:58:53 +12004633
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004634 VkRenderPassCreateInfo rpci = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 2, attachments, 1, &subpass, 0, nullptr};
Chris Forbes3f128ef2016-06-29 14:58:53 +12004635
4636 VkRenderPass rp;
4637 VkResult err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
4638
4639 m_errorMonitor->VerifyFound();
4640
4641 if (err == VK_SUCCESS)
4642 vkDestroyRenderPass(m_device->device(), rp, nullptr);
4643}
4644
Tobin Ehlis2545e6f2016-06-22 10:42:19 -06004645TEST_F(VkLayerTest, FramebufferCreateErrors) {
4646 TEST_DESCRIPTION("Hit errors when attempting to create a framebuffer :\n"
4647 " 1. Mismatch between fb & renderPass attachmentCount\n"
Tobin Ehlisd3bb23a2016-06-22 13:34:46 -06004648 " 2. Use a color image as depthStencil attachment\n"
Tobin Ehlis77d717c2016-06-22 14:19:19 -06004649 " 3. Mismatch fb & renderPass attachment formats\n"
Tobin Ehlis6cfda642016-06-22 16:12:58 -06004650 " 4. Mismatch fb & renderPass attachment #samples\n"
Tobin Ehlis27f2ae82016-06-23 07:36:57 -06004651 " 5. FB attachment w/ non-1 mip-levels\n"
Tobin Ehlisb1f303b2016-06-23 08:19:55 -06004652 " 6. FB attachment where dimensions don't match\n"
Tobin Ehlis08d4b5e2016-06-23 08:52:39 -06004653 " 7. FB attachment w/o identity swizzle\n"
4654 " 8. FB dimensions exceed physical device limits\n");
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06004655
4656 ASSERT_NO_FATAL_FAILURE(InitState());
4657 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
4658
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004659 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
4660 "vkCreateFramebuffer(): VkFramebufferCreateInfo attachmentCount of 2 "
4661 "does not match attachmentCount of 1 of ");
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06004662
Tobin Ehlis2545e6f2016-06-22 10:42:19 -06004663 // Create a renderPass with a single color attachment
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06004664 VkAttachmentReference attach = {};
4665 attach.layout = VK_IMAGE_LAYOUT_GENERAL;
4666 VkSubpassDescription subpass = {};
Tobin Ehlis2545e6f2016-06-22 10:42:19 -06004667 subpass.pColorAttachments = &attach;
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06004668 VkRenderPassCreateInfo rpci = {};
4669 rpci.subpassCount = 1;
4670 rpci.pSubpasses = &subpass;
4671 rpci.attachmentCount = 1;
4672 VkAttachmentDescription attach_desc = {};
Tobin Ehlisd3bb23a2016-06-22 13:34:46 -06004673 attach_desc.format = VK_FORMAT_B8G8R8A8_UNORM;
Tobin Ehlis77d717c2016-06-22 14:19:19 -06004674 attach_desc.samples = VK_SAMPLE_COUNT_1_BIT;
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06004675 rpci.pAttachments = &attach_desc;
4676 rpci.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
4677 VkRenderPass rp;
4678 VkResult err = vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
4679 ASSERT_VK_SUCCESS(err);
4680
Tobin Ehlis2545e6f2016-06-22 10:42:19 -06004681 VkImageView ivs[2];
4682 ivs[0] = m_renderTargets[0]->targetView(VK_FORMAT_B8G8R8A8_UNORM);
4683 ivs[1] = m_renderTargets[0]->targetView(VK_FORMAT_B8G8R8A8_UNORM);
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06004684 VkFramebufferCreateInfo fb_info = {};
4685 fb_info.sType = VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO;
4686 fb_info.pNext = NULL;
4687 fb_info.renderPass = rp;
Tobin Ehlis2545e6f2016-06-22 10:42:19 -06004688 // Set mis-matching attachmentCount
4689 fb_info.attachmentCount = 2;
4690 fb_info.pAttachments = ivs;
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06004691 fb_info.width = 100;
4692 fb_info.height = 100;
4693 fb_info.layers = 1;
4694
4695 VkFramebuffer fb;
4696 err = vkCreateFramebuffer(device(), &fb_info, NULL, &fb);
4697
4698 m_errorMonitor->VerifyFound();
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06004699 if (err == VK_SUCCESS) {
4700 vkDestroyFramebuffer(m_device->device(), fb, NULL);
4701 }
4702 vkDestroyRenderPass(m_device->device(), rp, NULL);
Tobin Ehlis2545e6f2016-06-22 10:42:19 -06004703
4704 // Create a renderPass with a depth-stencil attachment created with
4705 // IMAGE_USAGE_COLOR_ATTACHMENT
4706 // Add our color attachment to pDepthStencilAttachment
4707 subpass.pDepthStencilAttachment = &attach;
4708 subpass.pColorAttachments = NULL;
4709 VkRenderPass rp_ds;
4710 err = vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp_ds);
4711 ASSERT_VK_SUCCESS(err);
4712 // Set correct attachment count, but attachment has COLOR usage bit set
4713 fb_info.attachmentCount = 1;
4714 fb_info.renderPass = rp_ds;
4715
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004716 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " conflicts with the image's IMAGE_USAGE flags ");
Tobin Ehlis2545e6f2016-06-22 10:42:19 -06004717 err = vkCreateFramebuffer(device(), &fb_info, NULL, &fb);
4718
4719 m_errorMonitor->VerifyFound();
4720 if (err == VK_SUCCESS) {
4721 vkDestroyFramebuffer(m_device->device(), fb, NULL);
4722 }
4723 vkDestroyRenderPass(m_device->device(), rp_ds, NULL);
Tobin Ehlisd3bb23a2016-06-22 13:34:46 -06004724
4725 // Create new renderpass with alternate attachment format from fb
4726 attach_desc.format = VK_FORMAT_R8G8B8A8_UNORM;
4727 subpass.pDepthStencilAttachment = NULL;
4728 subpass.pColorAttachments = &attach;
4729 err = vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
4730 ASSERT_VK_SUCCESS(err);
4731
4732 // Cause error due to mis-matched formats between rp & fb
4733 // rp attachment 0 now has RGBA8 but corresponding fb attach is BGRA8
4734 fb_info.renderPass = rp;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004735 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
4736 " has format of VK_FORMAT_B8G8R8A8_UNORM that does not match ");
Tobin Ehlisd3bb23a2016-06-22 13:34:46 -06004737 err = vkCreateFramebuffer(device(), &fb_info, NULL, &fb);
4738
4739 m_errorMonitor->VerifyFound();
4740 if (err == VK_SUCCESS) {
4741 vkDestroyFramebuffer(m_device->device(), fb, NULL);
4742 }
Tobin Ehlis77d717c2016-06-22 14:19:19 -06004743 vkDestroyRenderPass(m_device->device(), rp, NULL);
4744
4745 // Create new renderpass with alternate sample count from fb
4746 attach_desc.format = VK_FORMAT_B8G8R8A8_UNORM;
4747 attach_desc.samples = VK_SAMPLE_COUNT_4_BIT;
4748 err = vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
4749 ASSERT_VK_SUCCESS(err);
4750
4751 // Cause error due to mis-matched sample count between rp & fb
4752 fb_info.renderPass = rp;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004753 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " has VK_SAMPLE_COUNT_1_BIT samples "
4754 "that do not match the "
4755 "VK_SAMPLE_COUNT_4_BIT ");
Tobin Ehlis77d717c2016-06-22 14:19:19 -06004756 err = vkCreateFramebuffer(device(), &fb_info, NULL, &fb);
4757
4758 m_errorMonitor->VerifyFound();
4759 if (err == VK_SUCCESS) {
4760 vkDestroyFramebuffer(m_device->device(), fb, NULL);
4761 }
Tobin Ehlisd3bb23a2016-06-22 13:34:46 -06004762
4763 vkDestroyRenderPass(m_device->device(), rp, NULL);
Tobin Ehlis6cfda642016-06-22 16:12:58 -06004764
4765 // Create a custom imageView with non-1 mip levels
4766 VkImageObj image(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004767 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 -06004768 ASSERT_TRUE(image.initialized());
4769
4770 VkImageView view;
4771 VkImageViewCreateInfo ivci = {};
4772 ivci.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
4773 ivci.image = image.handle();
4774 ivci.viewType = VK_IMAGE_VIEW_TYPE_2D;
4775 ivci.format = VK_FORMAT_B8G8R8A8_UNORM;
4776 ivci.subresourceRange.layerCount = 1;
4777 ivci.subresourceRange.baseMipLevel = 0;
4778 // Set level count 2 (only 1 is allowed for FB attachment)
4779 ivci.subresourceRange.levelCount = 2;
4780 ivci.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
4781 err = vkCreateImageView(m_device->device(), &ivci, NULL, &view);
4782 ASSERT_VK_SUCCESS(err);
4783 // Re-create renderpass to have matching sample count
4784 attach_desc.samples = VK_SAMPLE_COUNT_1_BIT;
4785 err = vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
4786 ASSERT_VK_SUCCESS(err);
4787
4788 fb_info.renderPass = rp;
4789 fb_info.pAttachments = &view;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004790 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " has mip levelCount of 2 but only ");
Tobin Ehlis6cfda642016-06-22 16:12:58 -06004791 err = vkCreateFramebuffer(device(), &fb_info, NULL, &fb);
4792
4793 m_errorMonitor->VerifyFound();
4794 if (err == VK_SUCCESS) {
4795 vkDestroyFramebuffer(m_device->device(), fb, NULL);
4796 }
Tobin Ehlis6cfda642016-06-22 16:12:58 -06004797 vkDestroyImageView(m_device->device(), view, NULL);
Tobin Ehlis27f2ae82016-06-23 07:36:57 -06004798 // Update view to original color buffer and grow FB dimensions too big
4799 fb_info.pAttachments = ivs;
4800 fb_info.height = 1024;
4801 fb_info.width = 1024;
4802 fb_info.layers = 2;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004803 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " Attachment dimensions must be at "
4804 "least as large. ");
Tobin Ehlis27f2ae82016-06-23 07:36:57 -06004805 err = vkCreateFramebuffer(device(), &fb_info, NULL, &fb);
4806
4807 m_errorMonitor->VerifyFound();
4808 if (err == VK_SUCCESS) {
4809 vkDestroyFramebuffer(m_device->device(), fb, NULL);
4810 }
Tobin Ehlisb1f303b2016-06-23 08:19:55 -06004811 // Create view attachment with non-identity swizzle
4812 ivci.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
4813 ivci.image = image.handle();
4814 ivci.viewType = VK_IMAGE_VIEW_TYPE_2D;
4815 ivci.format = VK_FORMAT_B8G8R8A8_UNORM;
4816 ivci.subresourceRange.layerCount = 1;
4817 ivci.subresourceRange.baseMipLevel = 0;
4818 ivci.subresourceRange.levelCount = 1;
4819 ivci.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
4820 ivci.components.r = VK_COMPONENT_SWIZZLE_G;
4821 ivci.components.g = VK_COMPONENT_SWIZZLE_R;
4822 ivci.components.b = VK_COMPONENT_SWIZZLE_A;
4823 ivci.components.a = VK_COMPONENT_SWIZZLE_B;
4824 err = vkCreateImageView(m_device->device(), &ivci, NULL, &view);
4825 ASSERT_VK_SUCCESS(err);
4826
4827 fb_info.pAttachments = &view;
4828 fb_info.height = 100;
4829 fb_info.width = 100;
4830 fb_info.layers = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004831 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " has non-identy swizzle. All "
4832 "framebuffer attachments must have "
4833 "been created with the identity "
4834 "swizzle. ");
Tobin Ehlisb1f303b2016-06-23 08:19:55 -06004835 err = vkCreateFramebuffer(device(), &fb_info, NULL, &fb);
4836
4837 m_errorMonitor->VerifyFound();
4838 if (err == VK_SUCCESS) {
4839 vkDestroyFramebuffer(m_device->device(), fb, NULL);
4840 }
4841 vkDestroyImageView(m_device->device(), view, NULL);
Tobin Ehlis08d4b5e2016-06-23 08:52:39 -06004842 // Request fb that exceeds max dimensions
4843 // reset attachment to color attachment
4844 fb_info.pAttachments = ivs;
4845 fb_info.width = m_device->props.limits.maxFramebufferWidth + 1;
4846 fb_info.height = m_device->props.limits.maxFramebufferHeight + 1;
4847 fb_info.layers = m_device->props.limits.maxFramebufferLayers + 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004848 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " Requested VkFramebufferCreateInfo "
4849 "dimensions exceed physical device "
4850 "limits. ");
Tobin Ehlis08d4b5e2016-06-23 08:52:39 -06004851 err = vkCreateFramebuffer(device(), &fb_info, NULL, &fb);
4852
4853 m_errorMonitor->VerifyFound();
4854 if (err == VK_SUCCESS) {
4855 vkDestroyFramebuffer(m_device->device(), fb, NULL);
4856 }
Tobin Ehlis27f2ae82016-06-23 07:36:57 -06004857
Tobin Ehlis6cfda642016-06-22 16:12:58 -06004858 vkDestroyRenderPass(m_device->device(), rp, NULL);
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06004859}
4860
Mark Lobodzinskic808d442016-04-14 10:57:23 -06004861// This is a positive test. No errors should be generated.
Michael Lentine860b0fe2016-05-20 10:14:00 -05004862TEST_F(VkLayerTest, WaitEventThenSet) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004863 TEST_DESCRIPTION("Wait on a event then set it after the wait has been submitted.");
Michael Lentine860b0fe2016-05-20 10:14:00 -05004864
Michael Lentine860b0fe2016-05-20 10:14:00 -05004865 m_errorMonitor->ExpectSuccess();
Cody Northropc31a84f2016-08-22 10:41:47 -06004866 ASSERT_NO_FATAL_FAILURE(InitState());
Michael Lentine860b0fe2016-05-20 10:14:00 -05004867
4868 VkEvent event;
4869 VkEventCreateInfo event_create_info{};
4870 event_create_info.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO;
4871 vkCreateEvent(m_device->device(), &event_create_info, nullptr, &event);
4872
4873 VkCommandPool command_pool;
4874 VkCommandPoolCreateInfo pool_create_info{};
4875 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
4876 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
4877 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004878 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
Michael Lentine860b0fe2016-05-20 10:14:00 -05004879
4880 VkCommandBuffer command_buffer;
4881 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004882 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
Michael Lentine860b0fe2016-05-20 10:14:00 -05004883 command_buffer_allocate_info.commandPool = command_pool;
4884 command_buffer_allocate_info.commandBufferCount = 1;
4885 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004886 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, &command_buffer);
Michael Lentine860b0fe2016-05-20 10:14:00 -05004887
4888 VkQueue queue = VK_NULL_HANDLE;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004889 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 0, &queue);
Michael Lentine860b0fe2016-05-20 10:14:00 -05004890
4891 {
4892 VkCommandBufferBeginInfo begin_info{};
4893 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
4894 vkBeginCommandBuffer(command_buffer, &begin_info);
4895
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004896 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 -05004897 nullptr, 0, nullptr);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004898 vkCmdResetEvent(command_buffer, event, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT);
Michael Lentine860b0fe2016-05-20 10:14:00 -05004899 vkEndCommandBuffer(command_buffer);
4900 }
4901 {
4902 VkSubmitInfo submit_info{};
4903 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
4904 submit_info.commandBufferCount = 1;
4905 submit_info.pCommandBuffers = &command_buffer;
4906 submit_info.signalSemaphoreCount = 0;
4907 submit_info.pSignalSemaphores = nullptr;
4908 vkQueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE);
4909 }
4910 { vkSetEvent(m_device->device(), event); }
4911
4912 vkQueueWaitIdle(queue);
4913
4914 vkDestroyEvent(m_device->device(), event, nullptr);
4915 vkFreeCommandBuffers(m_device->device(), command_pool, 1, &command_buffer);
4916 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
4917
4918 m_errorMonitor->VerifyNotFound();
4919}
Michael Lentine5627e692016-05-20 17:45:02 -05004920// This is a positive test. No errors should be generated.
Michael Lentinef01fb382016-07-21 17:24:56 -05004921TEST_F(VkLayerTest, QueryAndCopySecondaryCommandBuffers) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004922 TEST_DESCRIPTION("Issue a query on a secondary command buffery and copy it on a primary.");
Michael Lentinef01fb382016-07-21 17:24:56 -05004923
Cody Northropc31a84f2016-08-22 10:41:47 -06004924 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004925 if ((m_device->queue_props.empty()) || (m_device->queue_props[0].queueCount < 2))
Michael Lentinef01fb382016-07-21 17:24:56 -05004926 return;
4927
4928 m_errorMonitor->ExpectSuccess();
4929
4930 VkQueryPool query_pool;
4931 VkQueryPoolCreateInfo query_pool_create_info{};
4932 query_pool_create_info.sType = VK_STRUCTURE_TYPE_QUERY_POOL_CREATE_INFO;
4933 query_pool_create_info.queryType = VK_QUERY_TYPE_TIMESTAMP;
4934 query_pool_create_info.queryCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004935 vkCreateQueryPool(m_device->device(), &query_pool_create_info, nullptr, &query_pool);
Michael Lentinef01fb382016-07-21 17:24:56 -05004936
4937 VkCommandPool command_pool;
4938 VkCommandPoolCreateInfo pool_create_info{};
4939 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
4940 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
4941 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004942 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
Michael Lentinef01fb382016-07-21 17:24:56 -05004943
4944 VkCommandBuffer command_buffer;
4945 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004946 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
Michael Lentinef01fb382016-07-21 17:24:56 -05004947 command_buffer_allocate_info.commandPool = command_pool;
4948 command_buffer_allocate_info.commandBufferCount = 1;
4949 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004950 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, &command_buffer);
Michael Lentinef01fb382016-07-21 17:24:56 -05004951
4952 VkCommandBuffer secondary_command_buffer;
4953 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_SECONDARY;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004954 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, &secondary_command_buffer);
Michael Lentinef01fb382016-07-21 17:24:56 -05004955
4956 VkQueue queue = VK_NULL_HANDLE;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004957 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 1, &queue);
Michael Lentinef01fb382016-07-21 17:24:56 -05004958
4959 uint32_t qfi = 0;
4960 VkBufferCreateInfo buff_create_info = {};
4961 buff_create_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
4962 buff_create_info.size = 1024;
4963 buff_create_info.usage = VK_BUFFER_USAGE_TRANSFER_DST_BIT;
4964 buff_create_info.queueFamilyIndexCount = 1;
4965 buff_create_info.pQueueFamilyIndices = &qfi;
4966
4967 VkResult err;
4968 VkBuffer buffer;
4969 err = vkCreateBuffer(m_device->device(), &buff_create_info, NULL, &buffer);
4970 ASSERT_VK_SUCCESS(err);
4971 VkMemoryAllocateInfo mem_alloc = {};
4972 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
4973 mem_alloc.pNext = NULL;
4974 mem_alloc.allocationSize = 1024;
4975 mem_alloc.memoryTypeIndex = 0;
4976
4977 VkMemoryRequirements memReqs;
4978 vkGetBufferMemoryRequirements(m_device->device(), buffer, &memReqs);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004979 bool pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &mem_alloc, 0);
Michael Lentinef01fb382016-07-21 17:24:56 -05004980 if (!pass) {
4981 vkDestroyBuffer(m_device->device(), buffer, NULL);
4982 return;
4983 }
4984
4985 VkDeviceMemory mem;
4986 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem);
4987 ASSERT_VK_SUCCESS(err);
4988 err = vkBindBufferMemory(m_device->device(), buffer, mem, 0);
4989 ASSERT_VK_SUCCESS(err);
4990
4991 VkCommandBufferInheritanceInfo hinfo = {};
4992 hinfo.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_INHERITANCE_INFO;
4993 hinfo.renderPass = VK_NULL_HANDLE;
4994 hinfo.subpass = 0;
4995 hinfo.framebuffer = VK_NULL_HANDLE;
4996 hinfo.occlusionQueryEnable = VK_FALSE;
4997 hinfo.queryFlags = 0;
4998 hinfo.pipelineStatistics = 0;
4999
5000 {
5001 VkCommandBufferBeginInfo begin_info{};
5002 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
5003 begin_info.pInheritanceInfo = &hinfo;
5004 vkBeginCommandBuffer(secondary_command_buffer, &begin_info);
5005
5006 vkCmdResetQueryPool(secondary_command_buffer, query_pool, 0, 1);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005007 vkCmdWriteTimestamp(secondary_command_buffer, VK_PIPELINE_STAGE_ALL_GRAPHICS_BIT, query_pool, 0);
Michael Lentinef01fb382016-07-21 17:24:56 -05005008
5009 vkEndCommandBuffer(secondary_command_buffer);
5010
5011 begin_info.pInheritanceInfo = nullptr;
5012 vkBeginCommandBuffer(command_buffer, &begin_info);
5013
5014 vkCmdExecuteCommands(command_buffer, 1, &secondary_command_buffer);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005015 vkCmdCopyQueryPoolResults(command_buffer, query_pool, 0, 1, buffer, 0, 0, 0);
Michael Lentinef01fb382016-07-21 17:24:56 -05005016
5017 vkEndCommandBuffer(command_buffer);
5018 }
5019 {
5020 VkSubmitInfo submit_info{};
5021 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
5022 submit_info.commandBufferCount = 1;
5023 submit_info.pCommandBuffers = &command_buffer;
5024 submit_info.signalSemaphoreCount = 0;
5025 submit_info.pSignalSemaphores = nullptr;
5026 vkQueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE);
5027 }
5028
5029 vkQueueWaitIdle(queue);
5030
5031 vkDestroyQueryPool(m_device->device(), query_pool, nullptr);
5032 vkFreeCommandBuffers(m_device->device(), command_pool, 1, &command_buffer);
5033 vkFreeCommandBuffers(m_device->device(), command_pool, 1, &secondary_command_buffer);
5034 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
5035 vkDestroyBuffer(m_device->device(), buffer, NULL);
5036 vkFreeMemory(m_device->device(), mem, NULL);
5037
5038 m_errorMonitor->VerifyNotFound();
5039}
5040
5041// This is a positive test. No errors should be generated.
Michael Lentine5627e692016-05-20 17:45:02 -05005042TEST_F(VkLayerTest, QueryAndCopyMultipleCommandBuffers) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005043 TEST_DESCRIPTION("Issue a query and copy from it on a second command buffer.");
Michael Lentine5627e692016-05-20 17:45:02 -05005044
Cody Northropc31a84f2016-08-22 10:41:47 -06005045 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005046 if ((m_device->queue_props.empty()) || (m_device->queue_props[0].queueCount < 2))
Michael Lentine5627e692016-05-20 17:45:02 -05005047 return;
5048
5049 m_errorMonitor->ExpectSuccess();
5050
5051 VkQueryPool query_pool;
5052 VkQueryPoolCreateInfo query_pool_create_info{};
5053 query_pool_create_info.sType = VK_STRUCTURE_TYPE_QUERY_POOL_CREATE_INFO;
5054 query_pool_create_info.queryType = VK_QUERY_TYPE_TIMESTAMP;
5055 query_pool_create_info.queryCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005056 vkCreateQueryPool(m_device->device(), &query_pool_create_info, nullptr, &query_pool);
Michael Lentine5627e692016-05-20 17:45:02 -05005057
5058 VkCommandPool command_pool;
5059 VkCommandPoolCreateInfo pool_create_info{};
5060 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
5061 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
5062 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005063 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
Michael Lentine5627e692016-05-20 17:45:02 -05005064
5065 VkCommandBuffer command_buffer[2];
5066 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005067 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
Michael Lentine5627e692016-05-20 17:45:02 -05005068 command_buffer_allocate_info.commandPool = command_pool;
5069 command_buffer_allocate_info.commandBufferCount = 2;
5070 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005071 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, command_buffer);
Michael Lentine5627e692016-05-20 17:45:02 -05005072
5073 VkQueue queue = VK_NULL_HANDLE;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005074 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 1, &queue);
Michael Lentine5627e692016-05-20 17:45:02 -05005075
5076 uint32_t qfi = 0;
5077 VkBufferCreateInfo buff_create_info = {};
5078 buff_create_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
5079 buff_create_info.size = 1024;
5080 buff_create_info.usage = VK_BUFFER_USAGE_TRANSFER_DST_BIT;
5081 buff_create_info.queueFamilyIndexCount = 1;
5082 buff_create_info.pQueueFamilyIndices = &qfi;
5083
5084 VkResult err;
5085 VkBuffer buffer;
5086 err = vkCreateBuffer(m_device->device(), &buff_create_info, NULL, &buffer);
5087 ASSERT_VK_SUCCESS(err);
5088 VkMemoryAllocateInfo mem_alloc = {};
5089 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
5090 mem_alloc.pNext = NULL;
5091 mem_alloc.allocationSize = 1024;
5092 mem_alloc.memoryTypeIndex = 0;
5093
5094 VkMemoryRequirements memReqs;
5095 vkGetBufferMemoryRequirements(m_device->device(), buffer, &memReqs);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005096 bool pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &mem_alloc, 0);
Michael Lentine5627e692016-05-20 17:45:02 -05005097 if (!pass) {
5098 vkDestroyBuffer(m_device->device(), buffer, NULL);
5099 return;
5100 }
5101
5102 VkDeviceMemory mem;
5103 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem);
5104 ASSERT_VK_SUCCESS(err);
5105 err = vkBindBufferMemory(m_device->device(), buffer, mem, 0);
5106 ASSERT_VK_SUCCESS(err);
5107
5108 {
5109 VkCommandBufferBeginInfo begin_info{};
5110 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
5111 vkBeginCommandBuffer(command_buffer[0], &begin_info);
5112
5113 vkCmdResetQueryPool(command_buffer[0], query_pool, 0, 1);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005114 vkCmdWriteTimestamp(command_buffer[0], VK_PIPELINE_STAGE_ALL_GRAPHICS_BIT, query_pool, 0);
Michael Lentine5627e692016-05-20 17:45:02 -05005115
5116 vkEndCommandBuffer(command_buffer[0]);
5117
5118 vkBeginCommandBuffer(command_buffer[1], &begin_info);
5119
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005120 vkCmdCopyQueryPoolResults(command_buffer[1], query_pool, 0, 1, buffer, 0, 0, 0);
Michael Lentine5627e692016-05-20 17:45:02 -05005121
5122 vkEndCommandBuffer(command_buffer[1]);
5123 }
5124 {
5125 VkSubmitInfo submit_info{};
5126 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
5127 submit_info.commandBufferCount = 2;
5128 submit_info.pCommandBuffers = command_buffer;
5129 submit_info.signalSemaphoreCount = 0;
5130 submit_info.pSignalSemaphores = nullptr;
5131 vkQueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE);
5132 }
5133
5134 vkQueueWaitIdle(queue);
5135
5136 vkDestroyQueryPool(m_device->device(), query_pool, nullptr);
5137 vkFreeCommandBuffers(m_device->device(), command_pool, 2, command_buffer);
5138 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
Tony Barbourdf4c0042016-06-01 15:55:43 -06005139 vkDestroyBuffer(m_device->device(), buffer, NULL);
5140 vkFreeMemory(m_device->device(), mem, NULL);
Michael Lentine5627e692016-05-20 17:45:02 -05005141
5142 m_errorMonitor->VerifyNotFound();
5143}
Michael Lentine860b0fe2016-05-20 10:14:00 -05005144
5145TEST_F(VkLayerTest, ResetEventThenSet) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005146 TEST_DESCRIPTION("Reset an event then set it after the reset has been submitted.");
Michael Lentine860b0fe2016-05-20 10:14:00 -05005147
Michael Lentine860b0fe2016-05-20 10:14:00 -05005148 m_errorMonitor->ExpectSuccess();
5149
Cody Northropc31a84f2016-08-22 10:41:47 -06005150 ASSERT_NO_FATAL_FAILURE(InitState());
Michael Lentine860b0fe2016-05-20 10:14:00 -05005151 VkEvent event;
5152 VkEventCreateInfo event_create_info{};
5153 event_create_info.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO;
5154 vkCreateEvent(m_device->device(), &event_create_info, nullptr, &event);
5155
5156 VkCommandPool command_pool;
5157 VkCommandPoolCreateInfo pool_create_info{};
5158 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
5159 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
5160 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005161 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
Michael Lentine860b0fe2016-05-20 10:14:00 -05005162
5163 VkCommandBuffer command_buffer;
5164 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005165 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
Michael Lentine860b0fe2016-05-20 10:14:00 -05005166 command_buffer_allocate_info.commandPool = command_pool;
5167 command_buffer_allocate_info.commandBufferCount = 1;
5168 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005169 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, &command_buffer);
Michael Lentine860b0fe2016-05-20 10:14:00 -05005170
5171 VkQueue queue = VK_NULL_HANDLE;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005172 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 0, &queue);
Michael Lentine860b0fe2016-05-20 10:14:00 -05005173
5174 {
5175 VkCommandBufferBeginInfo begin_info{};
5176 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
5177 vkBeginCommandBuffer(command_buffer, &begin_info);
5178
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005179 vkCmdResetEvent(command_buffer, event, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT);
5180 vkCmdWaitEvents(command_buffer, 1, &event, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0,
5181 nullptr, 0, nullptr, 0, nullptr);
Michael Lentine860b0fe2016-05-20 10:14:00 -05005182 vkEndCommandBuffer(command_buffer);
5183 }
5184 {
5185 VkSubmitInfo submit_info{};
5186 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
5187 submit_info.commandBufferCount = 1;
5188 submit_info.pCommandBuffers = &command_buffer;
5189 submit_info.signalSemaphoreCount = 0;
5190 submit_info.pSignalSemaphores = nullptr;
5191 vkQueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE);
5192 }
5193 {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005194 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "that is already in use by a "
5195 "command buffer.");
Michael Lentine860b0fe2016-05-20 10:14:00 -05005196 vkSetEvent(m_device->device(), event);
5197 m_errorMonitor->VerifyFound();
5198 }
5199
5200 vkQueueWaitIdle(queue);
5201
5202 vkDestroyEvent(m_device->device(), event, nullptr);
5203 vkFreeCommandBuffers(m_device->device(), command_pool, 1, &command_buffer);
5204 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
5205}
5206
5207// This is a positive test. No errors should be generated.
Tobin Ehlis0bb263b2016-05-10 12:13:02 -06005208TEST_F(VkLayerTest, TwoFencesThreeFrames) {
5209 TEST_DESCRIPTION("Two command buffers with two separate fences are each "
5210 "run through a Submit & WaitForFences cycle 3 times. This "
5211 "previously revealed a bug so running this positive test "
5212 "to prevent a regression.");
5213 m_errorMonitor->ExpectSuccess();
5214
5215 ASSERT_NO_FATAL_FAILURE(InitState());
5216 VkQueue queue = VK_NULL_HANDLE;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005217 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 0, &queue);
Tobin Ehlis0bb263b2016-05-10 12:13:02 -06005218
5219 static const uint32_t NUM_OBJECTS = 2;
5220 static const uint32_t NUM_FRAMES = 3;
5221 VkCommandBuffer cmd_buffers[NUM_OBJECTS] = {};
5222 VkFence fences[NUM_OBJECTS] = {};
5223
5224 VkCommandPool cmd_pool;
5225 VkCommandPoolCreateInfo cmd_pool_ci = {};
5226 cmd_pool_ci.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
5227 cmd_pool_ci.queueFamilyIndex = m_device->graphics_queue_node_index_;
5228 cmd_pool_ci.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005229 VkResult err = vkCreateCommandPool(m_device->device(), &cmd_pool_ci, nullptr, &cmd_pool);
Tobin Ehlis0bb263b2016-05-10 12:13:02 -06005230 ASSERT_VK_SUCCESS(err);
5231
5232 VkCommandBufferAllocateInfo cmd_buf_info = {};
5233 cmd_buf_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
5234 cmd_buf_info.commandPool = cmd_pool;
5235 cmd_buf_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
5236 cmd_buf_info.commandBufferCount = 1;
5237
5238 VkFenceCreateInfo fence_ci = {};
5239 fence_ci.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
5240 fence_ci.pNext = nullptr;
5241 fence_ci.flags = 0;
5242
5243 for (uint32_t i = 0; i < NUM_OBJECTS; ++i) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005244 err = vkAllocateCommandBuffers(m_device->device(), &cmd_buf_info, &cmd_buffers[i]);
Tobin Ehlis0bb263b2016-05-10 12:13:02 -06005245 ASSERT_VK_SUCCESS(err);
5246 err = vkCreateFence(m_device->device(), &fence_ci, nullptr, &fences[i]);
5247 ASSERT_VK_SUCCESS(err);
5248 }
5249
5250 for (uint32_t frame = 0; frame < NUM_FRAMES; ++frame) {
Tobin Ehlisf9025162016-05-26 06:55:21 -06005251 for (uint32_t obj = 0; obj < NUM_OBJECTS; ++obj) {
5252 // Create empty cmd buffer
5253 VkCommandBufferBeginInfo cmdBufBeginDesc = {};
5254 cmdBufBeginDesc.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
Tobin Ehlis0bb263b2016-05-10 12:13:02 -06005255
Tobin Ehlisf9025162016-05-26 06:55:21 -06005256 err = vkBeginCommandBuffer(cmd_buffers[obj], &cmdBufBeginDesc);
5257 ASSERT_VK_SUCCESS(err);
5258 err = vkEndCommandBuffer(cmd_buffers[obj]);
5259 ASSERT_VK_SUCCESS(err);
Tobin Ehlis0bb263b2016-05-10 12:13:02 -06005260
Tobin Ehlisf9025162016-05-26 06:55:21 -06005261 VkSubmitInfo submit_info = {};
5262 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
5263 submit_info.commandBufferCount = 1;
5264 submit_info.pCommandBuffers = &cmd_buffers[obj];
5265 // Submit cmd buffer and wait for fence
5266 err = vkQueueSubmit(queue, 1, &submit_info, fences[obj]);
5267 ASSERT_VK_SUCCESS(err);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005268 err = vkWaitForFences(m_device->device(), 1, &fences[obj], VK_TRUE, UINT64_MAX);
Tobin Ehlisf9025162016-05-26 06:55:21 -06005269 ASSERT_VK_SUCCESS(err);
5270 err = vkResetFences(m_device->device(), 1, &fences[obj]);
5271 ASSERT_VK_SUCCESS(err);
5272 }
Tobin Ehlis0bb263b2016-05-10 12:13:02 -06005273 }
5274 m_errorMonitor->VerifyNotFound();
Tony Barbourdf4c0042016-06-01 15:55:43 -06005275 vkDestroyCommandPool(m_device->device(), cmd_pool, NULL);
5276 for (uint32_t i = 0; i < NUM_OBJECTS; ++i) {
5277 vkDestroyFence(m_device->device(), fences[i], nullptr);
5278 }
Tobin Ehlis0bb263b2016-05-10 12:13:02 -06005279}
5280// This is a positive test. No errors should be generated.
Mark Lobodzinskic808d442016-04-14 10:57:23 -06005281TEST_F(VkLayerTest, TwoQueueSubmitsSeparateQueuesWithSemaphoreAndOneFenceQWI) {
5282
5283 TEST_DESCRIPTION("Two command buffers, each in a separate QueueSubmit call "
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005284 "submitted on separate queues followed by a QueueWaitIdle.");
Mark Lobodzinskic808d442016-04-14 10:57:23 -06005285
Cody Northropc31a84f2016-08-22 10:41:47 -06005286 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005287 if ((m_device->queue_props.empty()) || (m_device->queue_props[0].queueCount < 2))
Tony Barbourdc18b262016-04-22 14:49:48 -06005288 return;
5289
Mark Lobodzinskic808d442016-04-14 10:57:23 -06005290 m_errorMonitor->ExpectSuccess();
5291
5292 VkSemaphore semaphore;
5293 VkSemaphoreCreateInfo semaphore_create_info{};
5294 semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005295 vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr, &semaphore);
Mark Lobodzinskic808d442016-04-14 10:57:23 -06005296
5297 VkCommandPool command_pool;
5298 VkCommandPoolCreateInfo pool_create_info{};
5299 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
5300 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
5301 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005302 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
Mark Lobodzinskic808d442016-04-14 10:57:23 -06005303
5304 VkCommandBuffer command_buffer[2];
5305 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005306 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
Mark Lobodzinskic808d442016-04-14 10:57:23 -06005307 command_buffer_allocate_info.commandPool = command_pool;
5308 command_buffer_allocate_info.commandBufferCount = 2;
5309 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005310 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, command_buffer);
Mark Lobodzinskic808d442016-04-14 10:57:23 -06005311
5312 VkQueue queue = VK_NULL_HANDLE;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005313 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 1, &queue);
Mark Lobodzinskic808d442016-04-14 10:57:23 -06005314
5315 {
5316 VkCommandBufferBeginInfo begin_info{};
5317 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
5318 vkBeginCommandBuffer(command_buffer[0], &begin_info);
5319
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005320 vkCmdPipelineBarrier(command_buffer[0], VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0,
5321 nullptr, 0, nullptr, 0, nullptr);
Mark Lobodzinskic808d442016-04-14 10:57:23 -06005322
5323 VkViewport viewport{};
5324 viewport.maxDepth = 1.0f;
5325 viewport.minDepth = 0.0f;
5326 viewport.width = 512;
5327 viewport.height = 512;
5328 viewport.x = 0;
5329 viewport.y = 0;
5330 vkCmdSetViewport(command_buffer[0], 0, 1, &viewport);
5331 vkEndCommandBuffer(command_buffer[0]);
5332 }
5333 {
5334 VkCommandBufferBeginInfo begin_info{};
5335 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
5336 vkBeginCommandBuffer(command_buffer[1], &begin_info);
5337
5338 VkViewport viewport{};
5339 viewport.maxDepth = 1.0f;
5340 viewport.minDepth = 0.0f;
5341 viewport.width = 512;
5342 viewport.height = 512;
5343 viewport.x = 0;
5344 viewport.y = 0;
5345 vkCmdSetViewport(command_buffer[1], 0, 1, &viewport);
5346 vkEndCommandBuffer(command_buffer[1]);
5347 }
5348 {
5349 VkSubmitInfo submit_info{};
5350 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
5351 submit_info.commandBufferCount = 1;
5352 submit_info.pCommandBuffers = &command_buffer[0];
5353 submit_info.signalSemaphoreCount = 1;
5354 submit_info.pSignalSemaphores = &semaphore;
5355 vkQueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE);
5356 }
5357 {
5358 VkPipelineStageFlags flags[]{VK_PIPELINE_STAGE_ALL_COMMANDS_BIT};
5359 VkSubmitInfo submit_info{};
5360 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
5361 submit_info.commandBufferCount = 1;
5362 submit_info.pCommandBuffers = &command_buffer[1];
5363 submit_info.waitSemaphoreCount = 1;
5364 submit_info.pWaitSemaphores = &semaphore;
5365 submit_info.pWaitDstStageMask = flags;
5366 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
5367 }
5368
5369 vkQueueWaitIdle(m_device->m_queue);
5370
5371 vkDestroySemaphore(m_device->device(), semaphore, nullptr);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005372 vkFreeCommandBuffers(m_device->device(), command_pool, 2, &command_buffer[0]);
Mark Lobodzinskic808d442016-04-14 10:57:23 -06005373 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
5374
5375 m_errorMonitor->VerifyNotFound();
5376}
5377
5378// This is a positive test. No errors should be generated.
5379TEST_F(VkLayerTest, TwoQueueSubmitsSeparateQueuesWithSemaphoreAndOneFenceQWIFence) {
5380
5381 TEST_DESCRIPTION("Two command buffers, each in a separate QueueSubmit call "
5382 "submitted on separate queues, the second having a fence"
5383 "followed by a QueueWaitIdle.");
5384
Cody Northropc31a84f2016-08-22 10:41:47 -06005385 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005386 if ((m_device->queue_props.empty()) || (m_device->queue_props[0].queueCount < 2))
Tony Barbourdc18b262016-04-22 14:49:48 -06005387 return;
5388
Mark Lobodzinskic808d442016-04-14 10:57:23 -06005389 m_errorMonitor->ExpectSuccess();
5390
5391 VkFence fence;
5392 VkFenceCreateInfo fence_create_info{};
5393 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
5394 vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence);
5395
5396 VkSemaphore semaphore;
5397 VkSemaphoreCreateInfo semaphore_create_info{};
5398 semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005399 vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr, &semaphore);
Mark Lobodzinskic808d442016-04-14 10:57:23 -06005400
5401 VkCommandPool command_pool;
5402 VkCommandPoolCreateInfo pool_create_info{};
5403 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
5404 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
5405 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005406 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
Mark Lobodzinskic808d442016-04-14 10:57:23 -06005407
5408 VkCommandBuffer command_buffer[2];
5409 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005410 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
Mark Lobodzinskic808d442016-04-14 10:57:23 -06005411 command_buffer_allocate_info.commandPool = command_pool;
5412 command_buffer_allocate_info.commandBufferCount = 2;
5413 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005414 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, command_buffer);
Mark Lobodzinskic808d442016-04-14 10:57:23 -06005415
5416 VkQueue queue = VK_NULL_HANDLE;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005417 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 1, &queue);
Mark Lobodzinskic808d442016-04-14 10:57:23 -06005418
5419 {
5420 VkCommandBufferBeginInfo begin_info{};
5421 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
5422 vkBeginCommandBuffer(command_buffer[0], &begin_info);
5423
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005424 vkCmdPipelineBarrier(command_buffer[0], VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0,
5425 nullptr, 0, nullptr, 0, nullptr);
Mark Lobodzinskic808d442016-04-14 10:57:23 -06005426
5427 VkViewport viewport{};
5428 viewport.maxDepth = 1.0f;
5429 viewport.minDepth = 0.0f;
5430 viewport.width = 512;
5431 viewport.height = 512;
5432 viewport.x = 0;
5433 viewport.y = 0;
5434 vkCmdSetViewport(command_buffer[0], 0, 1, &viewport);
5435 vkEndCommandBuffer(command_buffer[0]);
5436 }
5437 {
5438 VkCommandBufferBeginInfo begin_info{};
5439 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
5440 vkBeginCommandBuffer(command_buffer[1], &begin_info);
5441
5442 VkViewport viewport{};
5443 viewport.maxDepth = 1.0f;
5444 viewport.minDepth = 0.0f;
5445 viewport.width = 512;
5446 viewport.height = 512;
5447 viewport.x = 0;
5448 viewport.y = 0;
5449 vkCmdSetViewport(command_buffer[1], 0, 1, &viewport);
5450 vkEndCommandBuffer(command_buffer[1]);
5451 }
5452 {
5453 VkSubmitInfo submit_info{};
5454 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
5455 submit_info.commandBufferCount = 1;
5456 submit_info.pCommandBuffers = &command_buffer[0];
5457 submit_info.signalSemaphoreCount = 1;
5458 submit_info.pSignalSemaphores = &semaphore;
5459 vkQueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE);
5460 }
5461 {
5462 VkPipelineStageFlags flags[]{VK_PIPELINE_STAGE_ALL_COMMANDS_BIT};
5463 VkSubmitInfo submit_info{};
5464 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
5465 submit_info.commandBufferCount = 1;
5466 submit_info.pCommandBuffers = &command_buffer[1];
5467 submit_info.waitSemaphoreCount = 1;
5468 submit_info.pWaitSemaphores = &semaphore;
5469 submit_info.pWaitDstStageMask = flags;
5470 vkQueueSubmit(m_device->m_queue, 1, &submit_info, fence);
5471 }
5472
5473 vkQueueWaitIdle(m_device->m_queue);
5474
5475 vkDestroyFence(m_device->device(), fence, nullptr);
5476 vkDestroySemaphore(m_device->device(), semaphore, nullptr);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005477 vkFreeCommandBuffers(m_device->device(), command_pool, 2, &command_buffer[0]);
Mark Lobodzinskic808d442016-04-14 10:57:23 -06005478 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
5479
5480 m_errorMonitor->VerifyNotFound();
5481}
5482
5483// This is a positive test. No errors should be generated.
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005484TEST_F(VkLayerTest, TwoQueueSubmitsSeparateQueuesWithSemaphoreAndOneFenceTwoWFF) {
Mark Lobodzinskic808d442016-04-14 10:57:23 -06005485
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005486 TEST_DESCRIPTION("Two command buffers, each in a separate QueueSubmit call "
5487 "submitted on separate queues, the second having a fence"
5488 "followed by two consecutive WaitForFences calls on the same fence.");
Mark Lobodzinskic808d442016-04-14 10:57:23 -06005489
Cody Northropc31a84f2016-08-22 10:41:47 -06005490 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005491 if ((m_device->queue_props.empty()) || (m_device->queue_props[0].queueCount < 2))
Tony Barbourdc18b262016-04-22 14:49:48 -06005492 return;
5493
Mark Lobodzinskic808d442016-04-14 10:57:23 -06005494 m_errorMonitor->ExpectSuccess();
5495
5496 VkFence fence;
5497 VkFenceCreateInfo fence_create_info{};
5498 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
5499 vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence);
5500
5501 VkSemaphore semaphore;
5502 VkSemaphoreCreateInfo semaphore_create_info{};
5503 semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005504 vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr, &semaphore);
Mark Lobodzinskic808d442016-04-14 10:57:23 -06005505
5506 VkCommandPool command_pool;
5507 VkCommandPoolCreateInfo pool_create_info{};
5508 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
5509 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
5510 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005511 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
Mark Lobodzinskic808d442016-04-14 10:57:23 -06005512
5513 VkCommandBuffer command_buffer[2];
5514 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005515 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
Mark Lobodzinskic808d442016-04-14 10:57:23 -06005516 command_buffer_allocate_info.commandPool = command_pool;
5517 command_buffer_allocate_info.commandBufferCount = 2;
5518 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005519 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, command_buffer);
Mark Lobodzinskic808d442016-04-14 10:57:23 -06005520
5521 VkQueue queue = VK_NULL_HANDLE;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005522 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 1, &queue);
Mark Lobodzinskic808d442016-04-14 10:57:23 -06005523
5524 {
5525 VkCommandBufferBeginInfo begin_info{};
5526 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
5527 vkBeginCommandBuffer(command_buffer[0], &begin_info);
5528
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005529 vkCmdPipelineBarrier(command_buffer[0], VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0,
5530 nullptr, 0, nullptr, 0, nullptr);
Mark Lobodzinskic808d442016-04-14 10:57:23 -06005531
5532 VkViewport viewport{};
5533 viewport.maxDepth = 1.0f;
5534 viewport.minDepth = 0.0f;
5535 viewport.width = 512;
5536 viewport.height = 512;
5537 viewport.x = 0;
5538 viewport.y = 0;
5539 vkCmdSetViewport(command_buffer[0], 0, 1, &viewport);
5540 vkEndCommandBuffer(command_buffer[0]);
5541 }
5542 {
5543 VkCommandBufferBeginInfo begin_info{};
5544 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
5545 vkBeginCommandBuffer(command_buffer[1], &begin_info);
5546
5547 VkViewport viewport{};
5548 viewport.maxDepth = 1.0f;
5549 viewport.minDepth = 0.0f;
5550 viewport.width = 512;
5551 viewport.height = 512;
5552 viewport.x = 0;
5553 viewport.y = 0;
5554 vkCmdSetViewport(command_buffer[1], 0, 1, &viewport);
5555 vkEndCommandBuffer(command_buffer[1]);
5556 }
5557 {
5558 VkSubmitInfo submit_info{};
5559 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
5560 submit_info.commandBufferCount = 1;
5561 submit_info.pCommandBuffers = &command_buffer[0];
5562 submit_info.signalSemaphoreCount = 1;
5563 submit_info.pSignalSemaphores = &semaphore;
5564 vkQueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE);
5565 }
5566 {
5567 VkPipelineStageFlags flags[]{VK_PIPELINE_STAGE_ALL_COMMANDS_BIT};
5568 VkSubmitInfo submit_info{};
5569 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
5570 submit_info.commandBufferCount = 1;
5571 submit_info.pCommandBuffers = &command_buffer[1];
5572 submit_info.waitSemaphoreCount = 1;
5573 submit_info.pWaitSemaphores = &semaphore;
5574 submit_info.pWaitDstStageMask = flags;
5575 vkQueueSubmit(m_device->m_queue, 1, &submit_info, fence);
5576 }
5577
5578 vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
5579 vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
5580
5581 vkDestroyFence(m_device->device(), fence, nullptr);
5582 vkDestroySemaphore(m_device->device(), semaphore, nullptr);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005583 vkFreeCommandBuffers(m_device->device(), command_pool, 2, &command_buffer[0]);
Mark Lobodzinskic808d442016-04-14 10:57:23 -06005584 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
5585
5586 m_errorMonitor->VerifyNotFound();
5587}
5588
Chris Forbes0f8126b2016-06-20 17:48:22 +12005589TEST_F(VkLayerTest, TwoQueuesEnsureCorrectRetirementWithWorkStolen) {
Cody Northropc31a84f2016-08-22 10:41:47 -06005590
5591 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005592 if ((m_device->queue_props.empty()) || (m_device->queue_props[0].queueCount < 2)) {
Chris Forbes0f8126b2016-06-20 17:48:22 +12005593 printf("Test requires two queues, skipping\n");
5594 return;
5595 }
5596
5597 VkResult err;
5598
5599 m_errorMonitor->ExpectSuccess();
5600
5601 VkQueue q0 = m_device->m_queue;
5602 VkQueue q1 = nullptr;
5603 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 1, &q1);
5604 ASSERT_NE(q1, nullptr);
5605
5606 // An (empty) command buffer. We must have work in the first submission --
5607 // the layer treats unfenced work differently from fenced work.
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005608 VkCommandPoolCreateInfo cpci = {VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO, nullptr, 0, 0};
Chris Forbes0f8126b2016-06-20 17:48:22 +12005609 VkCommandPool pool;
5610 err = vkCreateCommandPool(m_device->device(), &cpci, nullptr, &pool);
5611 ASSERT_VK_SUCCESS(err);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005612 VkCommandBufferAllocateInfo cbai = {VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO, nullptr, pool,
5613 VK_COMMAND_BUFFER_LEVEL_PRIMARY, 1};
Chris Forbes0f8126b2016-06-20 17:48:22 +12005614 VkCommandBuffer cb;
5615 err = vkAllocateCommandBuffers(m_device->device(), &cbai, &cb);
5616 ASSERT_VK_SUCCESS(err);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005617 VkCommandBufferBeginInfo cbbi = {VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO, nullptr, 0, nullptr};
Chris Forbes0f8126b2016-06-20 17:48:22 +12005618 err = vkBeginCommandBuffer(cb, &cbbi);
5619 ASSERT_VK_SUCCESS(err);
5620 err = vkEndCommandBuffer(cb);
5621 ASSERT_VK_SUCCESS(err);
5622
5623 // A semaphore
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005624 VkSemaphoreCreateInfo sci = {VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO, nullptr, 0};
Chris Forbes0f8126b2016-06-20 17:48:22 +12005625 VkSemaphore s;
5626 err = vkCreateSemaphore(m_device->device(), &sci, nullptr, &s);
5627 ASSERT_VK_SUCCESS(err);
5628
5629 // First submission, to q0
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005630 VkSubmitInfo s0 = {VK_STRUCTURE_TYPE_SUBMIT_INFO, nullptr, 0, nullptr, nullptr, 1, &cb, 1, &s};
Chris Forbes0f8126b2016-06-20 17:48:22 +12005631
5632 err = vkQueueSubmit(q0, 1, &s0, VK_NULL_HANDLE);
5633 ASSERT_VK_SUCCESS(err);
5634
5635 // Second submission, to q1, waiting on s
5636 VkFlags waitmask = VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT; // doesn't really matter what this value is.
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005637 VkSubmitInfo s1 = {VK_STRUCTURE_TYPE_SUBMIT_INFO, nullptr, 1, &s, &waitmask, 0, nullptr, 0, nullptr};
Chris Forbes0f8126b2016-06-20 17:48:22 +12005638
5639 err = vkQueueSubmit(q1, 1, &s1, VK_NULL_HANDLE);
5640 ASSERT_VK_SUCCESS(err);
5641
5642 // Wait for q0 idle
5643 err = vkQueueWaitIdle(q0);
5644 ASSERT_VK_SUCCESS(err);
5645
5646 // Command buffer should have been completed (it was on q0); reset the pool.
5647 vkFreeCommandBuffers(m_device->device(), pool, 1, &cb);
5648
5649 m_errorMonitor->VerifyNotFound();
5650
5651 // Force device completely idle and clean up resources
5652 vkDeviceWaitIdle(m_device->device());
5653 vkDestroyCommandPool(m_device->device(), pool, nullptr);
5654 vkDestroySemaphore(m_device->device(), s, nullptr);
5655}
Chris Forbes0f8126b2016-06-20 17:48:22 +12005656
Mark Lobodzinskic808d442016-04-14 10:57:23 -06005657// This is a positive test. No errors should be generated.
5658TEST_F(VkLayerTest, TwoQueueSubmitsSeparateQueuesWithSemaphoreAndOneFence) {
5659
5660 TEST_DESCRIPTION("Two command buffers, each in a separate QueueSubmit call "
5661 "submitted on separate queues, the second having a fence, "
5662 "followed by a WaitForFences call.");
5663
Cody Northropc31a84f2016-08-22 10:41:47 -06005664 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005665 if ((m_device->queue_props.empty()) || (m_device->queue_props[0].queueCount < 2))
Tony Barbourdc18b262016-04-22 14:49:48 -06005666 return;
5667
Mark Lobodzinskic808d442016-04-14 10:57:23 -06005668 m_errorMonitor->ExpectSuccess();
5669
Cody Northropc31a84f2016-08-22 10:41:47 -06005670 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinskic808d442016-04-14 10:57:23 -06005671 VkFence fence;
5672 VkFenceCreateInfo fence_create_info{};
5673 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
5674 vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence);
5675
5676 VkSemaphore semaphore;
5677 VkSemaphoreCreateInfo semaphore_create_info{};
5678 semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005679 vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr, &semaphore);
Mark Lobodzinskic808d442016-04-14 10:57:23 -06005680
5681 VkCommandPool command_pool;
5682 VkCommandPoolCreateInfo pool_create_info{};
5683 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
5684 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
5685 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005686 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
Mark Lobodzinskic808d442016-04-14 10:57:23 -06005687
5688 VkCommandBuffer command_buffer[2];
5689 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005690 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
Mark Lobodzinskic808d442016-04-14 10:57:23 -06005691 command_buffer_allocate_info.commandPool = command_pool;
5692 command_buffer_allocate_info.commandBufferCount = 2;
5693 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005694 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, command_buffer);
Mark Lobodzinskic808d442016-04-14 10:57:23 -06005695
5696 VkQueue queue = VK_NULL_HANDLE;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005697 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 1, &queue);
Mark Lobodzinskic808d442016-04-14 10:57:23 -06005698
5699 {
5700 VkCommandBufferBeginInfo begin_info{};
5701 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
5702 vkBeginCommandBuffer(command_buffer[0], &begin_info);
5703
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005704 vkCmdPipelineBarrier(command_buffer[0], VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0,
5705 nullptr, 0, nullptr, 0, nullptr);
Mark Lobodzinskic808d442016-04-14 10:57:23 -06005706
5707 VkViewport viewport{};
5708 viewport.maxDepth = 1.0f;
5709 viewport.minDepth = 0.0f;
5710 viewport.width = 512;
5711 viewport.height = 512;
5712 viewport.x = 0;
5713 viewport.y = 0;
5714 vkCmdSetViewport(command_buffer[0], 0, 1, &viewport);
5715 vkEndCommandBuffer(command_buffer[0]);
5716 }
5717 {
5718 VkCommandBufferBeginInfo begin_info{};
5719 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
5720 vkBeginCommandBuffer(command_buffer[1], &begin_info);
5721
5722 VkViewport viewport{};
5723 viewport.maxDepth = 1.0f;
5724 viewport.minDepth = 0.0f;
5725 viewport.width = 512;
5726 viewport.height = 512;
5727 viewport.x = 0;
5728 viewport.y = 0;
5729 vkCmdSetViewport(command_buffer[1], 0, 1, &viewport);
5730 vkEndCommandBuffer(command_buffer[1]);
5731 }
5732 {
5733 VkSubmitInfo submit_info{};
5734 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
5735 submit_info.commandBufferCount = 1;
5736 submit_info.pCommandBuffers = &command_buffer[0];
5737 submit_info.signalSemaphoreCount = 1;
5738 submit_info.pSignalSemaphores = &semaphore;
5739 vkQueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE);
5740 }
5741 {
5742 VkPipelineStageFlags flags[]{VK_PIPELINE_STAGE_ALL_COMMANDS_BIT};
5743 VkSubmitInfo submit_info{};
5744 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
5745 submit_info.commandBufferCount = 1;
5746 submit_info.pCommandBuffers = &command_buffer[1];
5747 submit_info.waitSemaphoreCount = 1;
5748 submit_info.pWaitSemaphores = &semaphore;
5749 submit_info.pWaitDstStageMask = flags;
5750 vkQueueSubmit(m_device->m_queue, 1, &submit_info, fence);
5751 }
5752
5753 vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
5754
5755 vkDestroyFence(m_device->device(), fence, nullptr);
5756 vkDestroySemaphore(m_device->device(), semaphore, nullptr);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005757 vkFreeCommandBuffers(m_device->device(), command_pool, 2, &command_buffer[0]);
Mark Lobodzinskic808d442016-04-14 10:57:23 -06005758 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
5759
5760 m_errorMonitor->VerifyNotFound();
5761}
5762
5763// This is a positive test. No errors should be generated.
5764TEST_F(VkLayerTest, TwoQueueSubmitsOneQueueWithSemaphoreAndOneFence) {
5765
5766 TEST_DESCRIPTION("Two command buffers, each in a separate QueueSubmit call "
5767 "on the same queue, sharing a signal/wait semaphore, the "
5768 "second having a fence, "
5769 "followed by a WaitForFences call.");
5770
5771 m_errorMonitor->ExpectSuccess();
5772
Cody Northropc31a84f2016-08-22 10:41:47 -06005773 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinskic808d442016-04-14 10:57:23 -06005774 VkFence fence;
5775 VkFenceCreateInfo fence_create_info{};
5776 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
5777 vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence);
5778
5779 VkSemaphore semaphore;
5780 VkSemaphoreCreateInfo semaphore_create_info{};
5781 semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005782 vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr, &semaphore);
Mark Lobodzinskic808d442016-04-14 10:57:23 -06005783
5784 VkCommandPool command_pool;
5785 VkCommandPoolCreateInfo pool_create_info{};
5786 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
5787 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
5788 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005789 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
Mark Lobodzinskic808d442016-04-14 10:57:23 -06005790
5791 VkCommandBuffer command_buffer[2];
5792 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005793 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
Mark Lobodzinskic808d442016-04-14 10:57:23 -06005794 command_buffer_allocate_info.commandPool = command_pool;
5795 command_buffer_allocate_info.commandBufferCount = 2;
5796 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005797 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, command_buffer);
Mark Lobodzinskic808d442016-04-14 10:57:23 -06005798
5799 {
5800 VkCommandBufferBeginInfo begin_info{};
5801 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
5802 vkBeginCommandBuffer(command_buffer[0], &begin_info);
5803
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005804 vkCmdPipelineBarrier(command_buffer[0], VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0,
5805 nullptr, 0, nullptr, 0, nullptr);
Mark Lobodzinskic808d442016-04-14 10:57:23 -06005806
5807 VkViewport viewport{};
5808 viewport.maxDepth = 1.0f;
5809 viewport.minDepth = 0.0f;
5810 viewport.width = 512;
5811 viewport.height = 512;
5812 viewport.x = 0;
5813 viewport.y = 0;
5814 vkCmdSetViewport(command_buffer[0], 0, 1, &viewport);
5815 vkEndCommandBuffer(command_buffer[0]);
5816 }
5817 {
5818 VkCommandBufferBeginInfo begin_info{};
5819 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
5820 vkBeginCommandBuffer(command_buffer[1], &begin_info);
5821
5822 VkViewport viewport{};
5823 viewport.maxDepth = 1.0f;
5824 viewport.minDepth = 0.0f;
5825 viewport.width = 512;
5826 viewport.height = 512;
5827 viewport.x = 0;
5828 viewport.y = 0;
5829 vkCmdSetViewport(command_buffer[1], 0, 1, &viewport);
5830 vkEndCommandBuffer(command_buffer[1]);
5831 }
5832 {
5833 VkSubmitInfo submit_info{};
5834 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
5835 submit_info.commandBufferCount = 1;
5836 submit_info.pCommandBuffers = &command_buffer[0];
5837 submit_info.signalSemaphoreCount = 1;
5838 submit_info.pSignalSemaphores = &semaphore;
5839 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
5840 }
5841 {
5842 VkPipelineStageFlags flags[]{VK_PIPELINE_STAGE_ALL_COMMANDS_BIT};
5843 VkSubmitInfo submit_info{};
5844 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
5845 submit_info.commandBufferCount = 1;
5846 submit_info.pCommandBuffers = &command_buffer[1];
5847 submit_info.waitSemaphoreCount = 1;
5848 submit_info.pWaitSemaphores = &semaphore;
5849 submit_info.pWaitDstStageMask = flags;
5850 vkQueueSubmit(m_device->m_queue, 1, &submit_info, fence);
5851 }
5852
5853 vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
5854
5855 vkDestroyFence(m_device->device(), fence, nullptr);
5856 vkDestroySemaphore(m_device->device(), semaphore, nullptr);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005857 vkFreeCommandBuffers(m_device->device(), command_pool, 2, &command_buffer[0]);
Mark Lobodzinskic808d442016-04-14 10:57:23 -06005858 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
5859
5860 m_errorMonitor->VerifyNotFound();
5861}
5862
5863// This is a positive test. No errors should be generated.
5864TEST_F(VkLayerTest, TwoQueueSubmitsOneQueueNullQueueSubmitWithFence) {
5865
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005866 TEST_DESCRIPTION("Two command buffers, each in a separate QueueSubmit call "
5867 "on the same queue, no fences, followed by a third QueueSubmit with NO "
5868 "SubmitInfos but with a fence, followed by a WaitForFences call.");
Mark Lobodzinskic808d442016-04-14 10:57:23 -06005869
5870 m_errorMonitor->ExpectSuccess();
5871
Cody Northropc31a84f2016-08-22 10:41:47 -06005872 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinskic808d442016-04-14 10:57:23 -06005873 VkFence fence;
5874 VkFenceCreateInfo fence_create_info{};
5875 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
5876 vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence);
5877
5878 VkCommandPool command_pool;
5879 VkCommandPoolCreateInfo pool_create_info{};
5880 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
5881 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
5882 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005883 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
Mark Lobodzinskic808d442016-04-14 10:57:23 -06005884
5885 VkCommandBuffer command_buffer[2];
5886 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005887 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
Mark Lobodzinskic808d442016-04-14 10:57:23 -06005888 command_buffer_allocate_info.commandPool = command_pool;
5889 command_buffer_allocate_info.commandBufferCount = 2;
5890 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005891 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, command_buffer);
Mark Lobodzinskic808d442016-04-14 10:57:23 -06005892
5893 {
5894 VkCommandBufferBeginInfo begin_info{};
5895 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
5896 vkBeginCommandBuffer(command_buffer[0], &begin_info);
5897
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005898 vkCmdPipelineBarrier(command_buffer[0], VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0,
5899 nullptr, 0, nullptr, 0, nullptr);
Mark Lobodzinskic808d442016-04-14 10:57:23 -06005900
5901 VkViewport viewport{};
5902 viewport.maxDepth = 1.0f;
5903 viewport.minDepth = 0.0f;
5904 viewport.width = 512;
5905 viewport.height = 512;
5906 viewport.x = 0;
5907 viewport.y = 0;
5908 vkCmdSetViewport(command_buffer[0], 0, 1, &viewport);
5909 vkEndCommandBuffer(command_buffer[0]);
5910 }
5911 {
5912 VkCommandBufferBeginInfo begin_info{};
5913 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
5914 vkBeginCommandBuffer(command_buffer[1], &begin_info);
5915
5916 VkViewport viewport{};
5917 viewport.maxDepth = 1.0f;
5918 viewport.minDepth = 0.0f;
5919 viewport.width = 512;
5920 viewport.height = 512;
5921 viewport.x = 0;
5922 viewport.y = 0;
5923 vkCmdSetViewport(command_buffer[1], 0, 1, &viewport);
5924 vkEndCommandBuffer(command_buffer[1]);
5925 }
5926 {
5927 VkSubmitInfo submit_info{};
5928 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
5929 submit_info.commandBufferCount = 1;
5930 submit_info.pCommandBuffers = &command_buffer[0];
5931 submit_info.signalSemaphoreCount = 0;
5932 submit_info.pSignalSemaphores = VK_NULL_HANDLE;
5933 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
5934 }
5935 {
5936 VkPipelineStageFlags flags[]{VK_PIPELINE_STAGE_ALL_COMMANDS_BIT};
5937 VkSubmitInfo submit_info{};
5938 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
5939 submit_info.commandBufferCount = 1;
5940 submit_info.pCommandBuffers = &command_buffer[1];
5941 submit_info.waitSemaphoreCount = 0;
5942 submit_info.pWaitSemaphores = VK_NULL_HANDLE;
5943 submit_info.pWaitDstStageMask = flags;
5944 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
5945 }
5946
5947 vkQueueSubmit(m_device->m_queue, 0, NULL, fence);
5948
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005949 VkResult err = vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
Mike Stroyancd1c3e52016-06-21 09:20:01 -06005950 ASSERT_VK_SUCCESS(err);
Mark Lobodzinskic808d442016-04-14 10:57:23 -06005951
5952 vkDestroyFence(m_device->device(), fence, nullptr);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005953 vkFreeCommandBuffers(m_device->device(), command_pool, 2, &command_buffer[0]);
Mark Lobodzinskic808d442016-04-14 10:57:23 -06005954 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
5955
5956 m_errorMonitor->VerifyNotFound();
5957}
5958
5959// This is a positive test. No errors should be generated.
5960TEST_F(VkLayerTest, TwoQueueSubmitsOneQueueOneFence) {
5961
5962 TEST_DESCRIPTION("Two command buffers, each in a separate QueueSubmit call "
5963 "on the same queue, the second having a fence, followed "
5964 "by a WaitForFences call.");
5965
5966 m_errorMonitor->ExpectSuccess();
5967
Cody Northropc31a84f2016-08-22 10:41:47 -06005968 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinskic808d442016-04-14 10:57:23 -06005969 VkFence fence;
5970 VkFenceCreateInfo fence_create_info{};
5971 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
5972 vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence);
5973
5974 VkCommandPool command_pool;
5975 VkCommandPoolCreateInfo pool_create_info{};
5976 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
5977 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
5978 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005979 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
Mark Lobodzinskic808d442016-04-14 10:57:23 -06005980
5981 VkCommandBuffer command_buffer[2];
5982 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005983 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
Mark Lobodzinskic808d442016-04-14 10:57:23 -06005984 command_buffer_allocate_info.commandPool = command_pool;
5985 command_buffer_allocate_info.commandBufferCount = 2;
5986 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005987 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, command_buffer);
Mark Lobodzinskic808d442016-04-14 10:57:23 -06005988
5989 {
5990 VkCommandBufferBeginInfo begin_info{};
5991 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
5992 vkBeginCommandBuffer(command_buffer[0], &begin_info);
5993
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005994 vkCmdPipelineBarrier(command_buffer[0], VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0,
5995 nullptr, 0, nullptr, 0, nullptr);
Mark Lobodzinskic808d442016-04-14 10:57:23 -06005996
5997 VkViewport viewport{};
5998 viewport.maxDepth = 1.0f;
5999 viewport.minDepth = 0.0f;
6000 viewport.width = 512;
6001 viewport.height = 512;
6002 viewport.x = 0;
6003 viewport.y = 0;
6004 vkCmdSetViewport(command_buffer[0], 0, 1, &viewport);
6005 vkEndCommandBuffer(command_buffer[0]);
6006 }
6007 {
6008 VkCommandBufferBeginInfo begin_info{};
6009 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
6010 vkBeginCommandBuffer(command_buffer[1], &begin_info);
6011
6012 VkViewport viewport{};
6013 viewport.maxDepth = 1.0f;
6014 viewport.minDepth = 0.0f;
6015 viewport.width = 512;
6016 viewport.height = 512;
6017 viewport.x = 0;
6018 viewport.y = 0;
6019 vkCmdSetViewport(command_buffer[1], 0, 1, &viewport);
6020 vkEndCommandBuffer(command_buffer[1]);
6021 }
6022 {
6023 VkSubmitInfo submit_info{};
6024 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
6025 submit_info.commandBufferCount = 1;
6026 submit_info.pCommandBuffers = &command_buffer[0];
6027 submit_info.signalSemaphoreCount = 0;
6028 submit_info.pSignalSemaphores = VK_NULL_HANDLE;
6029 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
6030 }
6031 {
6032 VkPipelineStageFlags flags[]{VK_PIPELINE_STAGE_ALL_COMMANDS_BIT};
6033 VkSubmitInfo submit_info{};
6034 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
6035 submit_info.commandBufferCount = 1;
6036 submit_info.pCommandBuffers = &command_buffer[1];
6037 submit_info.waitSemaphoreCount = 0;
6038 submit_info.pWaitSemaphores = VK_NULL_HANDLE;
6039 submit_info.pWaitDstStageMask = flags;
6040 vkQueueSubmit(m_device->m_queue, 1, &submit_info, fence);
6041 }
6042
6043 vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
6044
6045 vkDestroyFence(m_device->device(), fence, nullptr);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006046 vkFreeCommandBuffers(m_device->device(), command_pool, 2, &command_buffer[0]);
Mark Lobodzinskic808d442016-04-14 10:57:23 -06006047 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
6048
6049 m_errorMonitor->VerifyNotFound();
6050}
6051
6052// This is a positive test. No errors should be generated.
6053TEST_F(VkLayerTest, TwoSubmitInfosWithSemaphoreOneQueueSubmitsOneFence) {
6054
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006055 TEST_DESCRIPTION("Two command buffers each in a separate SubmitInfo sent in a single "
6056 "QueueSubmit call followed by a WaitForFences call.");
Cody Northropc31a84f2016-08-22 10:41:47 -06006057 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinskic808d442016-04-14 10:57:23 -06006058
6059 m_errorMonitor->ExpectSuccess();
6060
6061 VkFence fence;
6062 VkFenceCreateInfo fence_create_info{};
6063 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
6064 vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence);
6065
6066 VkSemaphore semaphore;
6067 VkSemaphoreCreateInfo semaphore_create_info{};
6068 semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006069 vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr, &semaphore);
Mark Lobodzinskic808d442016-04-14 10:57:23 -06006070
6071 VkCommandPool command_pool;
6072 VkCommandPoolCreateInfo pool_create_info{};
6073 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
6074 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
6075 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006076 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
Mark Lobodzinskic808d442016-04-14 10:57:23 -06006077
6078 VkCommandBuffer command_buffer[2];
6079 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006080 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
Mark Lobodzinskic808d442016-04-14 10:57:23 -06006081 command_buffer_allocate_info.commandPool = command_pool;
6082 command_buffer_allocate_info.commandBufferCount = 2;
6083 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006084 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, command_buffer);
Mark Lobodzinskic808d442016-04-14 10:57:23 -06006085
6086 {
6087 VkCommandBufferBeginInfo begin_info{};
6088 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
6089 vkBeginCommandBuffer(command_buffer[0], &begin_info);
6090
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006091 vkCmdPipelineBarrier(command_buffer[0], VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0,
6092 nullptr, 0, nullptr, 0, nullptr);
Mark Lobodzinskic808d442016-04-14 10:57:23 -06006093
6094 VkViewport viewport{};
6095 viewport.maxDepth = 1.0f;
6096 viewport.minDepth = 0.0f;
6097 viewport.width = 512;
6098 viewport.height = 512;
6099 viewport.x = 0;
6100 viewport.y = 0;
6101 vkCmdSetViewport(command_buffer[0], 0, 1, &viewport);
6102 vkEndCommandBuffer(command_buffer[0]);
6103 }
6104 {
6105 VkCommandBufferBeginInfo begin_info{};
6106 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
6107 vkBeginCommandBuffer(command_buffer[1], &begin_info);
6108
6109 VkViewport viewport{};
6110 viewport.maxDepth = 1.0f;
6111 viewport.minDepth = 0.0f;
6112 viewport.width = 512;
6113 viewport.height = 512;
6114 viewport.x = 0;
6115 viewport.y = 0;
6116 vkCmdSetViewport(command_buffer[1], 0, 1, &viewport);
6117 vkEndCommandBuffer(command_buffer[1]);
6118 }
6119 {
6120 VkSubmitInfo submit_info[2];
6121 VkPipelineStageFlags flags[]{VK_PIPELINE_STAGE_ALL_COMMANDS_BIT};
6122
6123 submit_info[0].sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
6124 submit_info[0].pNext = NULL;
6125 submit_info[0].commandBufferCount = 1;
6126 submit_info[0].pCommandBuffers = &command_buffer[0];
6127 submit_info[0].signalSemaphoreCount = 1;
6128 submit_info[0].pSignalSemaphores = &semaphore;
6129 submit_info[0].waitSemaphoreCount = 0;
6130 submit_info[0].pWaitSemaphores = NULL;
6131 submit_info[0].pWaitDstStageMask = 0;
6132
6133 submit_info[1].sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
6134 submit_info[1].pNext = NULL;
6135 submit_info[1].commandBufferCount = 1;
6136 submit_info[1].pCommandBuffers = &command_buffer[1];
6137 submit_info[1].waitSemaphoreCount = 1;
6138 submit_info[1].pWaitSemaphores = &semaphore;
6139 submit_info[1].pWaitDstStageMask = flags;
6140 submit_info[1].signalSemaphoreCount = 0;
6141 submit_info[1].pSignalSemaphores = NULL;
6142 vkQueueSubmit(m_device->m_queue, 2, &submit_info[0], fence);
6143 }
6144
6145 vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
6146
6147 vkDestroyFence(m_device->device(), fence, nullptr);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006148 vkFreeCommandBuffers(m_device->device(), command_pool, 2, &command_buffer[0]);
Mark Lobodzinskic808d442016-04-14 10:57:23 -06006149 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
Tony Barbourdf4c0042016-06-01 15:55:43 -06006150 vkDestroySemaphore(m_device->device(), semaphore, nullptr);
Mark Lobodzinskic808d442016-04-14 10:57:23 -06006151
6152 m_errorMonitor->VerifyNotFound();
6153}
6154
Tobin Ehlisb1a87992016-05-25 16:42:47 -06006155TEST_F(VkLayerTest, DynamicDepthBiasNotBound) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006156 TEST_DESCRIPTION("Run a simple draw calls to validate failure when Depth Bias dynamic "
6157 "state is required but not correctly bound.");
Tobin Ehlisb1a87992016-05-25 16:42:47 -06006158
Cody Northropc31a84f2016-08-22 10:41:47 -06006159 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisb1a87992016-05-25 16:42:47 -06006160 // Dynamic depth bias
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006161 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Dynamic depth bias state not set for this command buffer");
6162 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailDepthBias);
Tobin Ehlisb1a87992016-05-25 16:42:47 -06006163 m_errorMonitor->VerifyFound();
6164}
6165
6166TEST_F(VkLayerTest, DynamicLineWidthNotBound) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006167 TEST_DESCRIPTION("Run a simple draw calls to validate failure when Line Width dynamic "
6168 "state is required but not correctly bound.");
Tobin Ehlisa5200ef2016-05-03 10:34:08 -06006169
Cody Northropc31a84f2016-08-22 10:41:47 -06006170 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisa5200ef2016-05-03 10:34:08 -06006171 // Dynamic line width
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006172 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Dynamic line width state not set for this command buffer");
6173 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailLineWidth);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006174 m_errorMonitor->VerifyFound();
Tobin Ehlisb1a87992016-05-25 16:42:47 -06006175}
6176
6177TEST_F(VkLayerTest, DynamicViewportNotBound) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006178 TEST_DESCRIPTION("Run a simple draw calls to validate failure when Viewport dynamic "
6179 "state is required but not correctly bound.");
Tobin Ehlisb1a87992016-05-25 16:42:47 -06006180
Cody Northropc31a84f2016-08-22 10:41:47 -06006181 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisa5200ef2016-05-03 10:34:08 -06006182 // Dynamic viewport state
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006183 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Dynamic viewport state not set for this command buffer");
6184 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailViewport);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006185 m_errorMonitor->VerifyFound();
Tobin Ehlisb1a87992016-05-25 16:42:47 -06006186}
6187
6188TEST_F(VkLayerTest, DynamicScissorNotBound) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006189 TEST_DESCRIPTION("Run a simple draw calls to validate failure when Scissor dynamic "
6190 "state is required but not correctly bound.");
Tobin Ehlisb1a87992016-05-25 16:42:47 -06006191
Cody Northropc31a84f2016-08-22 10:41:47 -06006192 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisa5200ef2016-05-03 10:34:08 -06006193 // Dynamic scissor state
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006194 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Dynamic scissor state not set for this command buffer");
6195 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailScissor);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006196 m_errorMonitor->VerifyFound();
Tobin Ehlisb1a87992016-05-25 16:42:47 -06006197}
6198
Cortd713fe82016-07-27 09:51:27 -07006199TEST_F(VkLayerTest, DynamicBlendConstantsNotBound) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006200 TEST_DESCRIPTION("Run a simple draw calls to validate failure when Blend Constants "
6201 "dynamic state is required but not correctly bound.");
Cody Northropc31a84f2016-08-22 10:41:47 -06006202
6203 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlis21c88352016-05-26 06:15:45 -06006204 // Dynamic blend constant state
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006205 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
6206 "Dynamic blend constants state not set for this command buffer");
6207 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailBlend);
Tobin Ehlis21c88352016-05-26 06:15:45 -06006208 m_errorMonitor->VerifyFound();
6209}
6210
6211TEST_F(VkLayerTest, DynamicDepthBoundsNotBound) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006212 TEST_DESCRIPTION("Run a simple draw calls to validate failure when Depth Bounds dynamic "
6213 "state is required but not correctly bound.");
Cody Northropc31a84f2016-08-22 10:41:47 -06006214
6215 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlis21c88352016-05-26 06:15:45 -06006216 if (!m_device->phy().features().depthBounds) {
6217 printf("Device does not support depthBounds test; skipped.\n");
6218 return;
6219 }
6220 // Dynamic depth bounds
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006221 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
6222 "Dynamic depth bounds state not set for this command buffer");
6223 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailDepthBounds);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006224 m_errorMonitor->VerifyFound();
Tobin Ehlisb1a87992016-05-25 16:42:47 -06006225}
6226
6227TEST_F(VkLayerTest, DynamicStencilReadNotBound) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006228 TEST_DESCRIPTION("Run a simple draw calls to validate failure when Stencil Read dynamic "
6229 "state is required but not correctly bound.");
Cody Northropc31a84f2016-08-22 10:41:47 -06006230
6231 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisa5200ef2016-05-03 10:34:08 -06006232 // Dynamic stencil read mask
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006233 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
6234 "Dynamic stencil read mask state not set for this command buffer");
6235 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailStencilReadMask);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006236 m_errorMonitor->VerifyFound();
Tobin Ehlisb1a87992016-05-25 16:42:47 -06006237}
6238
6239TEST_F(VkLayerTest, DynamicStencilWriteNotBound) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006240 TEST_DESCRIPTION("Run a simple draw calls to validate failure when Stencil Write dynamic"
6241 " state is required but not correctly bound.");
Cody Northropc31a84f2016-08-22 10:41:47 -06006242
6243 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisa5200ef2016-05-03 10:34:08 -06006244 // Dynamic stencil write mask
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006245 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
6246 "Dynamic stencil write mask state not set for this command buffer");
6247 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailStencilWriteMask);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006248 m_errorMonitor->VerifyFound();
Tobin Ehlisb1a87992016-05-25 16:42:47 -06006249}
6250
6251TEST_F(VkLayerTest, DynamicStencilRefNotBound) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006252 TEST_DESCRIPTION("Run a simple draw calls to validate failure when Stencil Ref dynamic "
6253 "state is required but not correctly bound.");
Cody Northropc31a84f2016-08-22 10:41:47 -06006254
6255 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisa5200ef2016-05-03 10:34:08 -06006256 // Dynamic stencil reference
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006257 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
6258 "Dynamic stencil reference state not set for this command buffer");
6259 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailStencilReference);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006260 m_errorMonitor->VerifyFound();
Tobin Ehlis963a4042015-09-29 08:18:34 -06006261}
6262
Tobin Ehlis379ba3b2016-07-19 11:22:29 -06006263TEST_F(VkLayerTest, IndexBufferNotBound) {
6264 TEST_DESCRIPTION("Run an indexed draw call without an index buffer bound.");
Cody Northropc31a84f2016-08-22 10:41:47 -06006265
6266 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006267 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
6268 "Index buffer object not bound to this command buffer when Indexed ");
6269 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailIndexBuffer);
Tobin Ehlis379ba3b2016-07-19 11:22:29 -06006270 m_errorMonitor->VerifyFound();
6271}
6272
Karl Schultz6addd812016-02-02 17:17:23 -07006273TEST_F(VkLayerTest, CommandBufferTwoSubmits) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006274 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
6275 "was begun w/ VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT set, but has "
6276 "been submitted");
Tobin Ehlis59278bf2015-08-18 07:10:58 -06006277
Tobin Ehlis59278bf2015-08-18 07:10:58 -06006278 ASSERT_NO_FATAL_FAILURE(InitState());
6279 ASSERT_NO_FATAL_FAILURE(InitViewport());
6280 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
6281
Karl Schultz6addd812016-02-02 17:17:23 -07006282 // We luck out b/c by default the framework creates CB w/ the
6283 // VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT set
Tobin Ehlis59278bf2015-08-18 07:10:58 -06006284 BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006285 m_commandBuffer->ClearAllBuffers(m_clear_color, m_depth_clear_color, m_stencil_clear_color, NULL);
Tobin Ehlis59278bf2015-08-18 07:10:58 -06006286 EndCommandBuffer();
6287
Tobin Ehlis59278bf2015-08-18 07:10:58 -06006288 // Bypass framework since it does the waits automatically
6289 VkResult err = VK_SUCCESS;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06006290 VkSubmitInfo submit_info;
Chia-I Wuf9be13c2015-10-26 20:37:06 +08006291 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
6292 submit_info.pNext = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08006293 submit_info.waitSemaphoreCount = 0;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06006294 submit_info.pWaitSemaphores = NULL;
Jon Ashburn7f9716c2015-12-30 16:42:50 -07006295 submit_info.pWaitDstStageMask = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08006296 submit_info.commandBufferCount = 1;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08006297 submit_info.pCommandBuffers = &m_commandBuffer->handle();
Chia-I Wud50a7d72015-10-26 20:48:51 +08006298 submit_info.signalSemaphoreCount = 0;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06006299 submit_info.pSignalSemaphores = NULL;
6300
Chris Forbes40028e22016-06-13 09:59:34 +12006301 err = vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
Karl Schultz6addd812016-02-02 17:17:23 -07006302 ASSERT_VK_SUCCESS(err);
Tobin Ehlis59278bf2015-08-18 07:10:58 -06006303
Karl Schultz6addd812016-02-02 17:17:23 -07006304 // Cause validation error by re-submitting cmd buffer that should only be
6305 // submitted once
Chris Forbes40028e22016-06-13 09:59:34 +12006306 err = vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
Tobin Ehlis59278bf2015-08-18 07:10:58 -06006307
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006308 m_errorMonitor->VerifyFound();
Tobin Ehlis59278bf2015-08-18 07:10:58 -06006309}
6310
Karl Schultz6addd812016-02-02 17:17:23 -07006311TEST_F(VkLayerTest, AllocDescriptorFromEmptyPool) {
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06006312 // Initiate Draw w/o a PSO bound
Karl Schultz6addd812016-02-02 17:17:23 -07006313 VkResult err;
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06006314
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006315 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Unable to allocate 1 descriptors of "
6316 "type "
6317 "VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER ");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06006318
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06006319 ASSERT_NO_FATAL_FAILURE(InitState());
6320 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06006321
Karl Schultz6addd812016-02-02 17:17:23 -07006322 // Create Pool w/ 1 Sampler descriptor, but try to alloc Uniform Buffer
6323 // descriptor from it
Chia-I Wu1b99bb22015-10-27 19:25:11 +08006324 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006325 ds_type_count.type = VK_DESCRIPTOR_TYPE_SAMPLER;
6326 ds_type_count.descriptorCount = 1;
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06006327
6328 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006329 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
6330 ds_pool_ci.pNext = NULL;
6331 ds_pool_ci.flags = 0;
6332 ds_pool_ci.maxSets = 1;
6333 ds_pool_ci.poolSizeCount = 1;
6334 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06006335
6336 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006337 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06006338 ASSERT_VK_SUCCESS(err);
6339
6340 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006341 dsl_binding.binding = 0;
6342 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
6343 dsl_binding.descriptorCount = 1;
6344 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
6345 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06006346
6347 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006348 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
6349 ds_layout_ci.pNext = NULL;
6350 ds_layout_ci.bindingCount = 1;
6351 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06006352
6353 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006354 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06006355 ASSERT_VK_SUCCESS(err);
6356
6357 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08006358 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08006359 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07006360 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06006361 alloc_info.descriptorPool = ds_pool;
6362 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006363 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06006364
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006365 m_errorMonitor->VerifyFound();
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06006366
Chia-I Wuf7458c52015-10-26 21:10:41 +08006367 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
6368 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06006369}
6370
Karl Schultz6addd812016-02-02 17:17:23 -07006371TEST_F(VkLayerTest, FreeDescriptorFromOneShotPool) {
6372 VkResult err;
Tobin Ehlise735c692015-10-08 13:13:50 -06006373
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006374 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
6375 "It is invalid to call vkFreeDescriptorSets() with a pool created "
6376 "without setting VK_DESCRIPTOR_POOL_CREATE_FREE_DESCRIPTOR_SET_BIT.");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06006377
Tobin Ehlise735c692015-10-08 13:13:50 -06006378 ASSERT_NO_FATAL_FAILURE(InitState());
6379 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlise735c692015-10-08 13:13:50 -06006380
Chia-I Wu1b99bb22015-10-27 19:25:11 +08006381 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006382 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
6383 ds_type_count.descriptorCount = 1;
Tobin Ehlise735c692015-10-08 13:13:50 -06006384
6385 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006386 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
6387 ds_pool_ci.pNext = NULL;
6388 ds_pool_ci.maxSets = 1;
6389 ds_pool_ci.poolSizeCount = 1;
6390 ds_pool_ci.flags = 0;
6391 // Not specifying VK_DESCRIPTOR_POOL_CREATE_FREE_DESCRIPTOR_SET_BIT means
6392 // app can only call vkResetDescriptorPool on this pool.;
6393 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlise735c692015-10-08 13:13:50 -06006394
6395 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006396 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlise735c692015-10-08 13:13:50 -06006397 ASSERT_VK_SUCCESS(err);
6398
6399 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006400 dsl_binding.binding = 0;
6401 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
6402 dsl_binding.descriptorCount = 1;
6403 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
6404 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlise735c692015-10-08 13:13:50 -06006405
6406 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006407 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
6408 ds_layout_ci.pNext = NULL;
6409 ds_layout_ci.bindingCount = 1;
6410 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlise735c692015-10-08 13:13:50 -06006411
6412 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006413 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlise735c692015-10-08 13:13:50 -06006414 ASSERT_VK_SUCCESS(err);
6415
6416 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08006417 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08006418 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07006419 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06006420 alloc_info.descriptorPool = ds_pool;
6421 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006422 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlise735c692015-10-08 13:13:50 -06006423 ASSERT_VK_SUCCESS(err);
6424
6425 err = vkFreeDescriptorSets(m_device->device(), ds_pool, 1, &descriptorSet);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006426 m_errorMonitor->VerifyFound();
Tobin Ehlise735c692015-10-08 13:13:50 -06006427
Chia-I Wuf7458c52015-10-26 21:10:41 +08006428 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
6429 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlise735c692015-10-08 13:13:50 -06006430}
6431
Karl Schultz6addd812016-02-02 17:17:23 -07006432TEST_F(VkLayerTest, InvalidDescriptorPool) {
Karl Schultzbdb75952016-04-19 11:36:49 -06006433 // Attempt to clear Descriptor Pool with bad object.
6434 // ObjectTracker should catch this.
Cody Northropc31a84f2016-08-22 10:41:47 -06006435
6436 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006437 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Invalid Descriptor Pool Object 0xbaad6001");
Mark Lobodzinski02bf89d2016-05-10 14:45:13 -06006438 uint64_t fake_pool_handle = 0xbaad6001;
6439 VkDescriptorPool bad_pool = reinterpret_cast<VkDescriptorPool &>(fake_pool_handle);
6440 vkResetDescriptorPool(device(), bad_pool, 0);
Karl Schultzbdb75952016-04-19 11:36:49 -06006441 m_errorMonitor->VerifyFound();
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06006442}
6443
Karl Schultz6addd812016-02-02 17:17:23 -07006444TEST_F(VkLayerTest, InvalidDescriptorSet) {
Karl Schultzbdb75952016-04-19 11:36:49 -06006445 // Attempt to bind an invalid Descriptor Set to a valid Command Buffer
6446 // ObjectTracker should catch this.
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06006447 // Create a valid cmd buffer
Karl Schultzbdb75952016-04-19 11:36:49 -06006448 // call vkCmdBindDescriptorSets w/ false Descriptor Set
Mark Lobodzinski02bf89d2016-05-10 14:45:13 -06006449
6450 uint64_t fake_set_handle = 0xbaad6001;
6451 VkDescriptorSet bad_set = reinterpret_cast<VkDescriptorSet &>(fake_set_handle);
Karl Schultzbdb75952016-04-19 11:36:49 -06006452 VkResult err;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006453 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Invalid Descriptor Set Object 0xbaad6001");
Karl Schultzbdb75952016-04-19 11:36:49 -06006454
6455 ASSERT_NO_FATAL_FAILURE(InitState());
6456
6457 VkDescriptorSetLayoutBinding layout_bindings[1] = {};
6458 layout_bindings[0].binding = 0;
6459 layout_bindings[0].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
6460 layout_bindings[0].descriptorCount = 1;
6461 layout_bindings[0].stageFlags = VK_SHADER_STAGE_VERTEX_BIT;
6462 layout_bindings[0].pImmutableSamplers = NULL;
6463
6464 VkDescriptorSetLayout descriptor_set_layout;
6465 VkDescriptorSetLayoutCreateInfo dslci = {};
6466 dslci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
6467 dslci.pNext = NULL;
6468 dslci.bindingCount = 1;
6469 dslci.pBindings = layout_bindings;
6470 err = vkCreateDescriptorSetLayout(device(), &dslci, NULL, &descriptor_set_layout);
Karl Schultz5cb21112016-04-21 17:17:40 -06006471 ASSERT_VK_SUCCESS(err);
Karl Schultzbdb75952016-04-19 11:36:49 -06006472
6473 VkPipelineLayout pipeline_layout;
6474 VkPipelineLayoutCreateInfo plci = {};
6475 plci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
6476 plci.pNext = NULL;
6477 plci.setLayoutCount = 1;
6478 plci.pSetLayouts = &descriptor_set_layout;
6479 err = vkCreatePipelineLayout(device(), &plci, NULL, &pipeline_layout);
Karl Schultz5cb21112016-04-21 17:17:40 -06006480 ASSERT_VK_SUCCESS(err);
Karl Schultzbdb75952016-04-19 11:36:49 -06006481
6482 BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006483 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1, &bad_set, 0,
6484 NULL);
Karl Schultzbdb75952016-04-19 11:36:49 -06006485 m_errorMonitor->VerifyFound();
6486 EndCommandBuffer();
6487 vkDestroyPipelineLayout(device(), pipeline_layout, NULL);
6488 vkDestroyDescriptorSetLayout(device(), descriptor_set_layout, NULL);
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06006489}
6490
Karl Schultz6addd812016-02-02 17:17:23 -07006491TEST_F(VkLayerTest, InvalidDescriptorSetLayout) {
Karl Schultzbdb75952016-04-19 11:36:49 -06006492 // Attempt to create a Pipeline Layout with an invalid Descriptor Set Layout.
6493 // ObjectTracker should catch this.
Mark Lobodzinski02bf89d2016-05-10 14:45:13 -06006494 uint64_t fake_layout_handle = 0xbaad6001;
6495 VkDescriptorSetLayout bad_layout = reinterpret_cast<VkDescriptorSetLayout &>(fake_layout_handle);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006496 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Invalid Descriptor Set Layout Object 0xbaad6001");
Cody Northropc31a84f2016-08-22 10:41:47 -06006497 ASSERT_NO_FATAL_FAILURE(InitState());
Karl Schultzbdb75952016-04-19 11:36:49 -06006498 VkPipelineLayout pipeline_layout;
6499 VkPipelineLayoutCreateInfo plci = {};
6500 plci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
6501 plci.pNext = NULL;
6502 plci.setLayoutCount = 1;
6503 plci.pSetLayouts = &bad_layout;
6504 vkCreatePipelineLayout(device(), &plci, NULL, &pipeline_layout);
6505
6506 m_errorMonitor->VerifyFound();
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06006507}
6508
Mark Muellerd4914412016-06-13 17:52:06 -06006509TEST_F(VkLayerTest, WriteDescriptorSetIntegrityCheck) {
6510 TEST_DESCRIPTION("This test verifies some requirements of chapter 13.2.3 of the Vulkan Spec "
6511 "1) A uniform buffer update must have a valid buffer index."
6512 "2) When using an array of descriptors in a single WriteDescriptor,"
6513 " the descriptor types and stageflags must all be the same."
6514 "3) Immutable Sampler state must match across descriptors");
6515
6516 const char *invalid_BufferInfo_ErrorMessage =
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006517 "vkUpdateDescriptorSets: if pDescriptorWrites[0].descriptorType is VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, "
6518 "VK_DESCRIPTOR_TYPE_STORAGE_BUFFER, VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC or "
6519 "VK_DESCRIPTOR_TYPE_STORAGE_BUFFER_DYNAMIC, pDescriptorWrites[0].pBufferInfo must not be NULL";
6520 const char *stateFlag_ErrorMessage = "Attempting write update to descriptor set ";
6521 const char *immutable_ErrorMessage = "Attempting write update to descriptor set ";
Mark Muellerd4914412016-06-13 17:52:06 -06006522
Mark Muellerd4914412016-06-13 17:52:06 -06006523 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, invalid_BufferInfo_ErrorMessage);
6524
6525 ASSERT_NO_FATAL_FAILURE(InitState());
6526 VkDescriptorPoolSize ds_type_count[4] = {};
6527 ds_type_count[0].type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
6528 ds_type_count[0].descriptorCount = 1;
6529 ds_type_count[1].type = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
6530 ds_type_count[1].descriptorCount = 1;
6531 ds_type_count[2].type = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
6532 ds_type_count[2].descriptorCount = 1;
6533 ds_type_count[3].type = VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT;
6534 ds_type_count[3].descriptorCount = 1;
6535
6536 VkDescriptorPoolCreateInfo ds_pool_ci = {};
6537 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
6538 ds_pool_ci.maxSets = 1;
6539 ds_pool_ci.poolSizeCount = sizeof(ds_type_count) / sizeof(VkDescriptorPoolSize);
6540 ds_pool_ci.pPoolSizes = ds_type_count;
6541
6542 VkDescriptorPool ds_pool;
6543 VkResult err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
6544 ASSERT_VK_SUCCESS(err);
6545
Mark Muellerb9896722016-06-16 09:54:29 -06006546 VkDescriptorSetLayoutBinding layout_binding[3] = {};
Mark Muellerd4914412016-06-13 17:52:06 -06006547 layout_binding[0].binding = 0;
6548 layout_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
6549 layout_binding[0].descriptorCount = 1;
6550 layout_binding[0].stageFlags = VK_SHADER_STAGE_ALL;
6551 layout_binding[0].pImmutableSamplers = NULL;
6552
6553 layout_binding[1].binding = 1;
6554 layout_binding[1].descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
6555 layout_binding[1].descriptorCount = 1;
6556 layout_binding[1].stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
6557 layout_binding[1].pImmutableSamplers = NULL;
6558
6559 VkSamplerCreateInfo sampler_ci = {};
6560 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
6561 sampler_ci.pNext = NULL;
6562 sampler_ci.magFilter = VK_FILTER_NEAREST;
6563 sampler_ci.minFilter = VK_FILTER_NEAREST;
6564 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
6565 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
6566 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
6567 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
6568 sampler_ci.mipLodBias = 1.0;
6569 sampler_ci.anisotropyEnable = VK_FALSE;
6570 sampler_ci.maxAnisotropy = 1;
6571 sampler_ci.compareEnable = VK_FALSE;
6572 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
6573 sampler_ci.minLod = 1.0;
6574 sampler_ci.maxLod = 1.0;
6575 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
6576 sampler_ci.unnormalizedCoordinates = VK_FALSE;
6577 VkSampler sampler;
6578
6579 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
6580 ASSERT_VK_SUCCESS(err);
6581
6582 layout_binding[2].binding = 2;
6583 layout_binding[2].descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
6584 layout_binding[2].descriptorCount = 1;
6585 layout_binding[2].stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
6586 layout_binding[2].pImmutableSamplers = static_cast<VkSampler *>(&sampler);
6587
Mark Muellerd4914412016-06-13 17:52:06 -06006588 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
6589 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
6590 ds_layout_ci.bindingCount = sizeof(layout_binding) / sizeof(VkDescriptorSetLayoutBinding);
6591 ds_layout_ci.pBindings = layout_binding;
6592 VkDescriptorSetLayout ds_layout;
6593 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
6594 ASSERT_VK_SUCCESS(err);
6595
6596 VkDescriptorSetAllocateInfo alloc_info = {};
6597 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
6598 alloc_info.descriptorSetCount = 1;
6599 alloc_info.descriptorPool = ds_pool;
6600 alloc_info.pSetLayouts = &ds_layout;
6601 VkDescriptorSet descriptorSet;
6602 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
6603 ASSERT_VK_SUCCESS(err);
6604
6605 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
6606 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
6607 pipeline_layout_ci.pNext = NULL;
6608 pipeline_layout_ci.setLayoutCount = 1;
6609 pipeline_layout_ci.pSetLayouts = &ds_layout;
6610
6611 VkPipelineLayout pipeline_layout;
6612 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
6613 ASSERT_VK_SUCCESS(err);
6614
Mark Mueller5c838ce2016-06-16 09:54:29 -06006615 VkWriteDescriptorSet descriptor_write = {};
Mark Muellerd4914412016-06-13 17:52:06 -06006616 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
6617 descriptor_write.dstSet = descriptorSet;
6618 descriptor_write.dstBinding = 0;
6619 descriptor_write.descriptorCount = 1;
6620 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
6621
Mark Mueller5c838ce2016-06-16 09:54:29 -06006622 // 1) The uniform buffer is intentionally invalid here
Mark Muellerd4914412016-06-13 17:52:06 -06006623 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
6624 m_errorMonitor->VerifyFound();
6625
6626 // Create a buffer to update the descriptor with
6627 uint32_t qfi = 0;
6628 VkBufferCreateInfo buffCI = {};
6629 buffCI.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
6630 buffCI.size = 1024;
6631 buffCI.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
6632 buffCI.queueFamilyIndexCount = 1;
6633 buffCI.pQueueFamilyIndices = &qfi;
6634
6635 VkBuffer dyub;
6636 err = vkCreateBuffer(m_device->device(), &buffCI, NULL, &dyub);
6637 ASSERT_VK_SUCCESS(err);
6638 VkDescriptorBufferInfo buffInfo = {};
6639 buffInfo.buffer = dyub;
6640 buffInfo.offset = 0;
6641 buffInfo.range = 1024;
6642
6643 descriptor_write.pBufferInfo = &buffInfo;
6644 descriptor_write.descriptorCount = 2;
6645
Mark Mueller5c838ce2016-06-16 09:54:29 -06006646 // 2) The stateFlags don't match between the first and second descriptor
Mark Muellerd4914412016-06-13 17:52:06 -06006647 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, stateFlag_ErrorMessage);
6648 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
6649 m_errorMonitor->VerifyFound();
6650
Mark Mueller5c838ce2016-06-16 09:54:29 -06006651 // 3) The second descriptor has a null_ptr pImmutableSamplers and
6652 // the third descriptor contains an immutable sampler
Mark Muellerd4914412016-06-13 17:52:06 -06006653 descriptor_write.dstBinding = 1;
6654 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
Mark Mueller5c838ce2016-06-16 09:54:29 -06006655
Mark Mueller5c838ce2016-06-16 09:54:29 -06006656 // Make pImageInfo index non-null to avoid complaints of it missing
6657 VkDescriptorImageInfo imageInfo = {};
6658 imageInfo.imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
6659 descriptor_write.pImageInfo = &imageInfo;
Mark Muellerd4914412016-06-13 17:52:06 -06006660 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, immutable_ErrorMessage);
6661 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
6662 m_errorMonitor->VerifyFound();
6663
Mark Muellerd4914412016-06-13 17:52:06 -06006664 vkDestroyBuffer(m_device->device(), dyub, NULL);
6665 vkDestroySampler(m_device->device(), sampler, NULL);
6666 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
6667 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
6668 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
6669}
6670
Tobin Ehlis0283c4d2016-06-28 17:57:07 -06006671TEST_F(VkLayerTest, InvalidCmdBufferBufferDestroyed) {
6672 TEST_DESCRIPTION("Attempt to draw with a command buffer that is invalid "
6673 "due to a buffer dependency being destroyed.");
6674 ASSERT_NO_FATAL_FAILURE(InitState());
6675
6676 VkImageObj image(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006677 image.init(128, 128, VK_FORMAT_B8G8R8A8_UNORM, VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT,
Tobin Ehlis0283c4d2016-06-28 17:57:07 -06006678 VK_IMAGE_TILING_OPTIMAL, 0);
6679 ASSERT_TRUE(image.initialized());
6680
6681 VkBuffer buffer;
6682 VkDeviceMemory mem;
6683 VkMemoryRequirements mem_reqs;
6684
6685 VkBufferCreateInfo buf_info = {};
6686 buf_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
6687 buf_info.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
6688 buf_info.size = 256;
6689 buf_info.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
6690 VkResult err = vkCreateBuffer(m_device->device(), &buf_info, NULL, &buffer);
6691 ASSERT_VK_SUCCESS(err);
6692
6693 vkGetBufferMemoryRequirements(m_device->device(), buffer, &mem_reqs);
6694
6695 VkMemoryAllocateInfo alloc_info = {};
6696 alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
6697 alloc_info.allocationSize = 256;
6698 bool pass = false;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006699 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 -06006700 if (!pass) {
6701 vkDestroyBuffer(m_device->device(), buffer, NULL);
6702 return;
6703 }
6704 err = vkAllocateMemory(m_device->device(), &alloc_info, NULL, &mem);
6705 ASSERT_VK_SUCCESS(err);
6706
6707 err = vkBindBufferMemory(m_device->device(), buffer, mem, 0);
6708 ASSERT_VK_SUCCESS(err);
6709
6710 VkBufferImageCopy region = {};
6711 region.bufferRowLength = 128;
6712 region.bufferImageHeight = 128;
6713 region.imageSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
6714
6715 region.imageSubresource.layerCount = 1;
6716 region.imageExtent.height = 4;
6717 region.imageExtent.width = 4;
6718 region.imageExtent.depth = 1;
6719 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006720 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer, image.handle(), VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1,
6721 &region);
Tobin Ehlis0283c4d2016-06-28 17:57:07 -06006722 m_commandBuffer->EndCommandBuffer();
6723
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006724 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " that is invalid because bound buffer ");
Tobin Ehlis0283c4d2016-06-28 17:57:07 -06006725 // Destroy buffer dependency prior to submit to cause ERROR
6726 vkDestroyBuffer(m_device->device(), buffer, NULL);
6727
6728 VkSubmitInfo submit_info = {};
6729 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
6730 submit_info.commandBufferCount = 1;
6731 submit_info.pCommandBuffers = &m_commandBuffer->handle();
6732 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
6733
6734 m_errorMonitor->VerifyFound();
6735 vkFreeMemory(m_device->handle(), mem, NULL);
6736}
6737
Tobin Ehlis11c8cea2016-06-28 17:44:21 -06006738TEST_F(VkLayerTest, InvalidCmdBufferImageDestroyed) {
6739 TEST_DESCRIPTION("Attempt to draw with a command buffer that is invalid "
6740 "due to an image dependency being destroyed.");
6741 ASSERT_NO_FATAL_FAILURE(InitState());
6742
6743 VkImage image;
6744 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
6745 VkImageCreateInfo image_create_info = {};
6746 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
6747 image_create_info.pNext = NULL;
6748 image_create_info.imageType = VK_IMAGE_TYPE_2D;
6749 image_create_info.format = tex_format;
6750 image_create_info.extent.width = 32;
6751 image_create_info.extent.height = 32;
6752 image_create_info.extent.depth = 1;
6753 image_create_info.mipLevels = 1;
6754 image_create_info.arrayLayers = 1;
6755 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
6756 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006757 image_create_info.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT;
Tobin Ehlis11c8cea2016-06-28 17:44:21 -06006758 image_create_info.flags = 0;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006759 VkResult err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
Tobin Ehlis11c8cea2016-06-28 17:44:21 -06006760 ASSERT_VK_SUCCESS(err);
Tobin Ehlis3d09fd52016-07-06 08:12:56 -06006761 // Have to bind memory to image before recording cmd in cmd buffer using it
6762 VkMemoryRequirements mem_reqs;
6763 VkDeviceMemory image_mem;
6764 bool pass;
6765 VkMemoryAllocateInfo mem_alloc = {};
6766 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
6767 mem_alloc.pNext = NULL;
6768 mem_alloc.memoryTypeIndex = 0;
6769 vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs);
6770 mem_alloc.allocationSize = mem_reqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006771 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0);
Tobin Ehlis3d09fd52016-07-06 08:12:56 -06006772 ASSERT_TRUE(pass);
6773 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &image_mem);
6774 ASSERT_VK_SUCCESS(err);
6775 err = vkBindImageMemory(m_device->device(), image, image_mem, 0);
6776 ASSERT_VK_SUCCESS(err);
Tobin Ehlis11c8cea2016-06-28 17:44:21 -06006777
Tobin Ehlis11c8cea2016-06-28 17:44:21 -06006778 m_commandBuffer->BeginCommandBuffer();
Tobin Ehlis764d7072016-07-01 12:54:29 -06006779 VkClearColorValue ccv;
6780 ccv.float32[0] = 1.0f;
6781 ccv.float32[1] = 1.0f;
6782 ccv.float32[2] = 1.0f;
6783 ccv.float32[3] = 1.0f;
6784 VkImageSubresourceRange isr = {};
6785 isr.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Tobin Ehlis3d09fd52016-07-06 08:12:56 -06006786 isr.baseArrayLayer = 0;
6787 isr.baseMipLevel = 0;
Tobin Ehlis764d7072016-07-01 12:54:29 -06006788 isr.layerCount = 1;
6789 isr.levelCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006790 vkCmdClearColorImage(m_commandBuffer->GetBufferHandle(), image, VK_IMAGE_LAYOUT_GENERAL, &ccv, 1, &isr);
Tobin Ehlis11c8cea2016-06-28 17:44:21 -06006791 m_commandBuffer->EndCommandBuffer();
6792
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006793 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " that is invalid because bound image ");
Tobin Ehlis11c8cea2016-06-28 17:44:21 -06006794 // Destroy image dependency prior to submit to cause ERROR
6795 vkDestroyImage(m_device->device(), image, NULL);
6796
6797 VkSubmitInfo submit_info = {};
6798 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
6799 submit_info.commandBufferCount = 1;
6800 submit_info.pCommandBuffers = &m_commandBuffer->handle();
6801 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
6802
6803 m_errorMonitor->VerifyFound();
Tobin Ehlis3d09fd52016-07-06 08:12:56 -06006804 vkFreeMemory(m_device->device(), image_mem, nullptr);
Tobin Ehlis11c8cea2016-06-28 17:44:21 -06006805}
6806
Tobin Ehlis59f68ab2016-09-06 21:59:07 -06006807TEST_F(VkLayerTest, InvalidCmdBufferFramebufferImageDestroyed) {
6808 TEST_DESCRIPTION("Attempt to draw with a command buffer that is invalid "
6809 "due to a framebuffer image dependency being destroyed.");
6810 VkFormatProperties format_properties;
6811 VkResult err = VK_SUCCESS;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006812 vkGetPhysicalDeviceFormatProperties(gpu(), VK_FORMAT_B8G8R8A8_UNORM, &format_properties);
6813 if (!(format_properties.optimalTilingFeatures & VK_FORMAT_FEATURE_SAMPLED_IMAGE_BIT)) {
Tobin Ehlis59f68ab2016-09-06 21:59:07 -06006814 return;
6815 }
6816
6817 ASSERT_NO_FATAL_FAILURE(InitState());
6818 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
6819
6820 VkImageCreateInfo image_ci = {};
6821 image_ci.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
6822 image_ci.pNext = NULL;
6823 image_ci.imageType = VK_IMAGE_TYPE_2D;
6824 image_ci.format = VK_FORMAT_B8G8R8A8_UNORM;
6825 image_ci.extent.width = 32;
6826 image_ci.extent.height = 32;
6827 image_ci.extent.depth = 1;
6828 image_ci.mipLevels = 1;
6829 image_ci.arrayLayers = 1;
6830 image_ci.samples = VK_SAMPLE_COUNT_1_BIT;
6831 image_ci.tiling = VK_IMAGE_TILING_OPTIMAL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006832 image_ci.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_SAMPLED_BIT;
Tobin Ehlis59f68ab2016-09-06 21:59:07 -06006833 image_ci.initialLayout = VK_IMAGE_LAYOUT_UNDEFINED;
6834 image_ci.flags = 0;
6835 VkImage image;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006836 ASSERT_VK_SUCCESS(vkCreateImage(m_device->handle(), &image_ci, NULL, &image));
Tobin Ehlis59f68ab2016-09-06 21:59:07 -06006837
6838 VkMemoryRequirements memory_reqs;
6839 VkDeviceMemory image_memory;
6840 bool pass;
6841 VkMemoryAllocateInfo memory_info = {};
6842 memory_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
6843 memory_info.pNext = NULL;
6844 memory_info.allocationSize = 0;
6845 memory_info.memoryTypeIndex = 0;
6846 vkGetImageMemoryRequirements(m_device->device(), image, &memory_reqs);
6847 memory_info.allocationSize = memory_reqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006848 pass = m_device->phy().set_memory_type(memory_reqs.memoryTypeBits, &memory_info, 0);
Tobin Ehlis59f68ab2016-09-06 21:59:07 -06006849 ASSERT_TRUE(pass);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006850 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &image_memory);
Tobin Ehlis59f68ab2016-09-06 21:59:07 -06006851 ASSERT_VK_SUCCESS(err);
6852 err = vkBindImageMemory(m_device->device(), image, image_memory, 0);
6853 ASSERT_VK_SUCCESS(err);
6854
6855 VkImageViewCreateInfo ivci = {
6856 VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO,
6857 nullptr,
6858 0,
6859 image,
6860 VK_IMAGE_VIEW_TYPE_2D,
6861 VK_FORMAT_B8G8R8A8_UNORM,
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006862 {VK_COMPONENT_SWIZZLE_R, VK_COMPONENT_SWIZZLE_G, VK_COMPONENT_SWIZZLE_B, VK_COMPONENT_SWIZZLE_A},
Tobin Ehlis59f68ab2016-09-06 21:59:07 -06006863 {VK_IMAGE_ASPECT_COLOR_BIT, 0, 1, 0, 1},
6864 };
6865 VkImageView view;
6866 err = vkCreateImageView(m_device->device(), &ivci, nullptr, &view);
6867 ASSERT_VK_SUCCESS(err);
6868
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006869 VkFramebufferCreateInfo fci = {VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr, 0, m_renderPass, 1, &view, 32, 32, 1};
Tobin Ehlis59f68ab2016-09-06 21:59:07 -06006870 VkFramebuffer fb;
6871 err = vkCreateFramebuffer(m_device->device(), &fci, nullptr, &fb);
6872 ASSERT_VK_SUCCESS(err);
6873
6874 // Just use default renderpass with our framebuffer
6875 m_renderPassBeginInfo.framebuffer = fb;
6876 // Create Null cmd buffer for submit
6877 BeginCommandBuffer();
6878 EndCommandBuffer();
6879 // Destroy image attached to framebuffer to invalidate cmd buffer
6880 vkDestroyImage(m_device->device(), image, NULL);
6881 // Now attempt to submit cmd buffer and verify error
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006882 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " that is invalid because bound image ");
Tobin Ehlis59f68ab2016-09-06 21:59:07 -06006883 QueueCommandBuffer(false);
6884 m_errorMonitor->VerifyFound();
6885
6886 vkDestroyFramebuffer(m_device->device(), fb, nullptr);
6887 vkDestroyImageView(m_device->device(), view, nullptr);
6888 vkFreeMemory(m_device->device(), image_memory, nullptr);
6889}
6890
Mark Lobodzinskia4df3632016-07-14 09:57:41 -06006891TEST_F(VkLayerTest, ImageMemoryNotBound) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006892 TEST_DESCRIPTION("Attempt to draw with an image which has not had memory bound to it.");
Mark Lobodzinskia4df3632016-07-14 09:57:41 -06006893 ASSERT_NO_FATAL_FAILURE(InitState());
6894
6895 VkImage image;
6896 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
6897 VkImageCreateInfo image_create_info = {};
6898 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
6899 image_create_info.pNext = NULL;
6900 image_create_info.imageType = VK_IMAGE_TYPE_2D;
6901 image_create_info.format = tex_format;
6902 image_create_info.extent.width = 32;
6903 image_create_info.extent.height = 32;
6904 image_create_info.extent.depth = 1;
6905 image_create_info.mipLevels = 1;
6906 image_create_info.arrayLayers = 1;
6907 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
6908 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006909 image_create_info.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT;
Mark Lobodzinskia4df3632016-07-14 09:57:41 -06006910 image_create_info.flags = 0;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006911 VkResult err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
Mark Lobodzinskia4df3632016-07-14 09:57:41 -06006912 ASSERT_VK_SUCCESS(err);
6913 // Have to bind memory to image before recording cmd in cmd buffer using it
6914 VkMemoryRequirements mem_reqs;
6915 VkDeviceMemory image_mem;
6916 bool pass;
6917 VkMemoryAllocateInfo mem_alloc = {};
6918 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
6919 mem_alloc.pNext = NULL;
6920 mem_alloc.memoryTypeIndex = 0;
6921 vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs);
6922 mem_alloc.allocationSize = mem_reqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006923 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0);
Mark Lobodzinskia4df3632016-07-14 09:57:41 -06006924 ASSERT_TRUE(pass);
6925 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &image_mem);
6926 ASSERT_VK_SUCCESS(err);
6927
6928 // Introduce error, do not call vkBindImageMemory(m_device->device(), image,
6929 // image_mem, 0);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006930 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "used without first calling vkBindImageMemory");
Mark Lobodzinskia4df3632016-07-14 09:57:41 -06006931
6932 m_commandBuffer->BeginCommandBuffer();
6933 VkClearColorValue ccv;
6934 ccv.float32[0] = 1.0f;
6935 ccv.float32[1] = 1.0f;
6936 ccv.float32[2] = 1.0f;
6937 ccv.float32[3] = 1.0f;
6938 VkImageSubresourceRange isr = {};
6939 isr.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
6940 isr.baseArrayLayer = 0;
6941 isr.baseMipLevel = 0;
6942 isr.layerCount = 1;
6943 isr.levelCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006944 vkCmdClearColorImage(m_commandBuffer->GetBufferHandle(), image, VK_IMAGE_LAYOUT_GENERAL, &ccv, 1, &isr);
Mark Lobodzinskia4df3632016-07-14 09:57:41 -06006945 m_commandBuffer->EndCommandBuffer();
6946
6947 m_errorMonitor->VerifyFound();
6948 vkDestroyImage(m_device->device(), image, NULL);
6949 vkFreeMemory(m_device->device(), image_mem, nullptr);
6950}
6951
6952TEST_F(VkLayerTest, BufferMemoryNotBound) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006953 TEST_DESCRIPTION("Attempt to copy from a buffer which has not had memory bound to it.");
Mark Lobodzinskia4df3632016-07-14 09:57:41 -06006954 ASSERT_NO_FATAL_FAILURE(InitState());
6955
6956 VkImageObj image(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006957 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 -06006958 VK_IMAGE_TILING_OPTIMAL, 0);
6959 ASSERT_TRUE(image.initialized());
6960
6961 VkBuffer buffer;
6962 VkDeviceMemory mem;
6963 VkMemoryRequirements mem_reqs;
6964
6965 VkBufferCreateInfo buf_info = {};
6966 buf_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
6967 buf_info.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
6968 buf_info.size = 256;
6969 buf_info.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
6970 VkResult err = vkCreateBuffer(m_device->device(), &buf_info, NULL, &buffer);
6971 ASSERT_VK_SUCCESS(err);
6972
6973 vkGetBufferMemoryRequirements(m_device->device(), buffer, &mem_reqs);
6974
6975 VkMemoryAllocateInfo alloc_info = {};
6976 alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
6977 alloc_info.allocationSize = 256;
6978 bool pass = false;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006979 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 -06006980 if (!pass) {
6981 vkDestroyBuffer(m_device->device(), buffer, NULL);
6982 return;
6983 }
6984 err = vkAllocateMemory(m_device->device(), &alloc_info, NULL, &mem);
6985 ASSERT_VK_SUCCESS(err);
6986
6987 // Introduce failure by not calling vkBindBufferMemory(m_device->device(),
6988 // buffer, mem, 0);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006989 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "used without first calling vkBindBufferMemory");
Mark Lobodzinskia4df3632016-07-14 09:57:41 -06006990 VkBufferImageCopy region = {};
6991 region.bufferRowLength = 128;
6992 region.bufferImageHeight = 128;
6993 region.imageSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
6994
6995 region.imageSubresource.layerCount = 1;
6996 region.imageExtent.height = 4;
6997 region.imageExtent.width = 4;
6998 region.imageExtent.depth = 1;
6999 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007000 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer, image.handle(), VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1,
7001 &region);
Mark Lobodzinskia4df3632016-07-14 09:57:41 -06007002 m_commandBuffer->EndCommandBuffer();
7003
7004 m_errorMonitor->VerifyFound();
7005
7006 vkDestroyBuffer(m_device->device(), buffer, NULL);
7007 vkFreeMemory(m_device->handle(), mem, NULL);
7008}
7009
Tobin Ehlis85940f52016-07-07 16:57:21 -06007010TEST_F(VkLayerTest, InvalidCmdBufferEventDestroyed) {
7011 TEST_DESCRIPTION("Attempt to draw with a command buffer that is invalid "
7012 "due to an event dependency being destroyed.");
7013 ASSERT_NO_FATAL_FAILURE(InitState());
7014
7015 VkEvent event;
7016 VkEventCreateInfo evci = {};
7017 evci.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO;
7018 VkResult result = vkCreateEvent(m_device->device(), &evci, NULL, &event);
7019 ASSERT_VK_SUCCESS(result);
7020
7021 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007022 vkCmdSetEvent(m_commandBuffer->GetBufferHandle(), event, VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT);
Tobin Ehlis85940f52016-07-07 16:57:21 -06007023 m_commandBuffer->EndCommandBuffer();
7024
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007025 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " that is invalid because bound event ");
Tobin Ehlis85940f52016-07-07 16:57:21 -06007026 // Destroy event dependency prior to submit to cause ERROR
7027 vkDestroyEvent(m_device->device(), event, NULL);
7028
7029 VkSubmitInfo submit_info = {};
7030 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
7031 submit_info.commandBufferCount = 1;
7032 submit_info.pCommandBuffers = &m_commandBuffer->handle();
7033 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
7034
7035 m_errorMonitor->VerifyFound();
7036}
7037
Tobin Ehlisdbea7552016-07-08 14:33:31 -06007038TEST_F(VkLayerTest, InvalidCmdBufferQueryPoolDestroyed) {
7039 TEST_DESCRIPTION("Attempt to draw with a command buffer that is invalid "
7040 "due to a query pool dependency being destroyed.");
7041 ASSERT_NO_FATAL_FAILURE(InitState());
7042
7043 VkQueryPool query_pool;
7044 VkQueryPoolCreateInfo qpci{};
7045 qpci.sType = VK_STRUCTURE_TYPE_QUERY_POOL_CREATE_INFO;
7046 qpci.queryType = VK_QUERY_TYPE_TIMESTAMP;
7047 qpci.queryCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007048 VkResult result = vkCreateQueryPool(m_device->device(), &qpci, nullptr, &query_pool);
Tobin Ehlisdbea7552016-07-08 14:33:31 -06007049 ASSERT_VK_SUCCESS(result);
7050
7051 m_commandBuffer->BeginCommandBuffer();
7052 vkCmdResetQueryPool(m_commandBuffer->GetBufferHandle(), query_pool, 0, 1);
7053 m_commandBuffer->EndCommandBuffer();
7054
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007055 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " that is invalid because bound query pool ");
Tobin Ehlisdbea7552016-07-08 14:33:31 -06007056 // Destroy query pool dependency prior to submit to cause ERROR
7057 vkDestroyQueryPool(m_device->device(), query_pool, NULL);
7058
7059 VkSubmitInfo submit_info = {};
7060 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
7061 submit_info.commandBufferCount = 1;
7062 submit_info.pCommandBuffers = &m_commandBuffer->handle();
7063 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
7064
7065 m_errorMonitor->VerifyFound();
7066}
7067
Tobin Ehlis24130d92016-07-08 15:50:53 -06007068TEST_F(VkLayerTest, InvalidCmdBufferPipelineDestroyed) {
7069 TEST_DESCRIPTION("Attempt to draw with a command buffer that is invalid "
7070 "due to a pipeline dependency being destroyed.");
7071 ASSERT_NO_FATAL_FAILURE(InitState());
7072 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
7073
7074 VkResult err;
7075
7076 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
7077 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
7078
7079 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007080 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis24130d92016-07-08 15:50:53 -06007081 ASSERT_VK_SUCCESS(err);
7082
7083 VkPipelineViewportStateCreateInfo vp_state_ci = {};
7084 vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
7085 vp_state_ci.viewportCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007086 VkViewport vp = {}; // Just need dummy vp to point to
Tobin Ehlis52b504f2016-07-19 13:25:12 -06007087 vp_state_ci.pViewports = &vp;
Tobin Ehlis24130d92016-07-08 15:50:53 -06007088 vp_state_ci.scissorCount = 1;
7089 VkRect2D scissors = {}; // Dummy scissors to point to
7090 vp_state_ci.pScissors = &scissors;
7091 // No dynamic state
7092 VkPipelineDynamicStateCreateInfo dyn_state_ci = {};
7093 dyn_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_DYNAMIC_STATE_CREATE_INFO;
7094
7095 VkPipelineShaderStageCreateInfo shaderStages[2];
7096 memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo));
7097
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007098 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
7099 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this); // We shouldn't need a fragment shader
7100 // but add it to be able to run on more devices
Tobin Ehlis24130d92016-07-08 15:50:53 -06007101 shaderStages[0] = vs.GetStageCreateInfo();
7102 shaderStages[1] = fs.GetStageCreateInfo();
7103
7104 VkPipelineVertexInputStateCreateInfo vi_ci = {};
7105 vi_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
7106
7107 VkPipelineInputAssemblyStateCreateInfo ia_ci = {};
7108 ia_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
7109 ia_ci.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP;
7110
7111 VkPipelineRasterizationStateCreateInfo rs_ci = {};
7112 rs_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
7113
7114 VkPipelineColorBlendAttachmentState att = {};
7115 att.blendEnable = VK_FALSE;
7116 att.colorWriteMask = 0xf;
7117
7118 VkPipelineColorBlendStateCreateInfo cb_ci = {};
7119 cb_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO;
7120 cb_ci.attachmentCount = 1;
7121 cb_ci.pAttachments = &att;
7122
7123 VkGraphicsPipelineCreateInfo gp_ci = {};
7124 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
7125 gp_ci.stageCount = 2;
7126 gp_ci.pStages = shaderStages;
7127 gp_ci.pVertexInputState = &vi_ci;
7128 gp_ci.pInputAssemblyState = &ia_ci;
7129 gp_ci.pViewportState = &vp_state_ci;
7130 gp_ci.pRasterizationState = &rs_ci;
7131 gp_ci.pColorBlendState = &cb_ci;
7132 gp_ci.pDynamicState = &dyn_state_ci;
7133 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
7134 gp_ci.layout = pipeline_layout;
7135 gp_ci.renderPass = renderPass();
7136
7137 VkPipelineCacheCreateInfo pc_ci = {};
7138 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
7139
7140 VkPipeline pipeline;
7141 VkPipelineCache pipelineCache;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007142 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Tobin Ehlis24130d92016-07-08 15:50:53 -06007143 ASSERT_VK_SUCCESS(err);
7144
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007145 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Tobin Ehlis24130d92016-07-08 15:50:53 -06007146 ASSERT_VK_SUCCESS(err);
7147
7148 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007149 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline);
Tobin Ehlis24130d92016-07-08 15:50:53 -06007150 m_commandBuffer->EndCommandBuffer();
7151 // Now destroy pipeline in order to cause error when submitting
7152 vkDestroyPipeline(m_device->device(), pipeline, nullptr);
7153
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007154 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " that is invalid because bound pipeline ");
Tobin Ehlis24130d92016-07-08 15:50:53 -06007155
7156 VkSubmitInfo submit_info = {};
7157 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
7158 submit_info.commandBufferCount = 1;
7159 submit_info.pCommandBuffers = &m_commandBuffer->handle();
7160 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
7161
7162 m_errorMonitor->VerifyFound();
7163 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
7164 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
7165}
7166
Tobin Ehlis31289162016-08-17 14:57:58 -06007167TEST_F(VkLayerTest, InvalidCmdBufferDescriptorSetBufferDestroyed) {
7168 TEST_DESCRIPTION("Attempt to draw with a command buffer that is invalid "
7169 "due to a bound descriptor set with a buffer dependency "
7170 "being destroyed.");
7171 ASSERT_NO_FATAL_FAILURE(InitState());
7172 ASSERT_NO_FATAL_FAILURE(InitViewport());
7173 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
7174
7175 VkDescriptorPoolSize ds_type_count = {};
7176 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
7177 ds_type_count.descriptorCount = 1;
7178
7179 VkDescriptorPoolCreateInfo ds_pool_ci = {};
7180 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
7181 ds_pool_ci.pNext = NULL;
7182 ds_pool_ci.maxSets = 1;
7183 ds_pool_ci.poolSizeCount = 1;
7184 ds_pool_ci.pPoolSizes = &ds_type_count;
7185
7186 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007187 VkResult err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis31289162016-08-17 14:57:58 -06007188 ASSERT_VK_SUCCESS(err);
7189
7190 VkDescriptorSetLayoutBinding dsl_binding = {};
7191 dsl_binding.binding = 0;
7192 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
7193 dsl_binding.descriptorCount = 1;
7194 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
7195 dsl_binding.pImmutableSamplers = NULL;
7196
7197 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
7198 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
7199 ds_layout_ci.pNext = NULL;
7200 ds_layout_ci.bindingCount = 1;
7201 ds_layout_ci.pBindings = &dsl_binding;
7202 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007203 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis31289162016-08-17 14:57:58 -06007204 ASSERT_VK_SUCCESS(err);
7205
7206 VkDescriptorSet descriptorSet;
7207 VkDescriptorSetAllocateInfo alloc_info = {};
7208 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
7209 alloc_info.descriptorSetCount = 1;
7210 alloc_info.descriptorPool = ds_pool;
7211 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007212 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis31289162016-08-17 14:57:58 -06007213 ASSERT_VK_SUCCESS(err);
7214
7215 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
7216 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
7217 pipeline_layout_ci.pNext = NULL;
7218 pipeline_layout_ci.setLayoutCount = 1;
7219 pipeline_layout_ci.pSetLayouts = &ds_layout;
7220
7221 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007222 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis31289162016-08-17 14:57:58 -06007223 ASSERT_VK_SUCCESS(err);
7224
7225 // Create a buffer to update the descriptor with
7226 uint32_t qfi = 0;
7227 VkBufferCreateInfo buffCI = {};
7228 buffCI.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
7229 buffCI.size = 1024;
7230 buffCI.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
7231 buffCI.queueFamilyIndexCount = 1;
7232 buffCI.pQueueFamilyIndices = &qfi;
7233
7234 VkBuffer buffer;
7235 err = vkCreateBuffer(m_device->device(), &buffCI, NULL, &buffer);
7236 ASSERT_VK_SUCCESS(err);
7237 // Allocate memory and bind to buffer so we can make it to the appropriate
7238 // error
7239 VkMemoryAllocateInfo mem_alloc = {};
7240 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
7241 mem_alloc.pNext = NULL;
7242 mem_alloc.allocationSize = 1024;
7243 mem_alloc.memoryTypeIndex = 0;
7244
7245 VkMemoryRequirements memReqs;
7246 vkGetBufferMemoryRequirements(m_device->device(), buffer, &memReqs);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007247 bool pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &mem_alloc, 0);
Tobin Ehlis31289162016-08-17 14:57:58 -06007248 if (!pass) {
7249 vkDestroyBuffer(m_device->device(), buffer, NULL);
7250 return;
7251 }
7252
7253 VkDeviceMemory mem;
7254 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem);
7255 ASSERT_VK_SUCCESS(err);
7256 err = vkBindBufferMemory(m_device->device(), buffer, mem, 0);
7257 ASSERT_VK_SUCCESS(err);
7258 // Correctly update descriptor to avoid "NOT_UPDATED" error
7259 VkDescriptorBufferInfo buffInfo = {};
7260 buffInfo.buffer = buffer;
7261 buffInfo.offset = 0;
7262 buffInfo.range = 1024;
7263
7264 VkWriteDescriptorSet descriptor_write;
7265 memset(&descriptor_write, 0, sizeof(descriptor_write));
7266 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
7267 descriptor_write.dstSet = descriptorSet;
7268 descriptor_write.dstBinding = 0;
7269 descriptor_write.descriptorCount = 1;
7270 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
7271 descriptor_write.pBufferInfo = &buffInfo;
7272
7273 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
7274
7275 // Create PSO to be used for draw-time errors below
7276 char const *vsSource = "#version 450\n"
7277 "\n"
7278 "out gl_PerVertex { \n"
7279 " vec4 gl_Position;\n"
7280 "};\n"
7281 "void main(){\n"
7282 " gl_Position = vec4(1);\n"
7283 "}\n";
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007284 char const *fsSource = "#version 450\n"
7285 "\n"
7286 "layout(location=0) out vec4 x;\n"
7287 "layout(set=0) layout(binding=0) uniform foo { int x; int y; } bar;\n"
7288 "void main(){\n"
7289 " x = vec4(bar.y);\n"
7290 "}\n";
Tobin Ehlis31289162016-08-17 14:57:58 -06007291 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
7292 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
7293 VkPipelineObj pipe(m_device);
7294 pipe.AddShader(&vs);
7295 pipe.AddShader(&fs);
7296 pipe.AddColorAttachment();
7297 pipe.CreateVKPipeline(pipeline_layout, renderPass());
7298
7299 BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007300 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
7301 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
7302 &descriptorSet, 0, NULL);
Tobin Ehlis31289162016-08-17 14:57:58 -06007303 Draw(1, 0, 0, 0);
7304 EndCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007305 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " that is invalid because bound buffer ");
Tobin Ehlis31289162016-08-17 14:57:58 -06007306 // Destroy buffer should invalidate the cmd buffer, causing error on submit
7307 vkDestroyBuffer(m_device->device(), buffer, NULL);
7308 // Attempt to submit cmd buffer
7309 VkSubmitInfo submit_info = {};
7310 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
7311 submit_info.commandBufferCount = 1;
7312 submit_info.pCommandBuffers = &m_commandBuffer->handle();
7313 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
7314 m_errorMonitor->VerifyFound();
7315 // Cleanup
7316 vkFreeMemory(m_device->device(), mem, NULL);
7317
7318 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
7319 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
7320 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
7321}
7322
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06007323TEST_F(VkLayerTest, InvalidCmdBufferDescriptorSetImageSamplerDestroyed) {
7324 TEST_DESCRIPTION("Attempt to draw with a command buffer that is invalid "
7325 "due to a bound descriptor sets with a combined image "
7326 "sampler having their image, sampler, and descriptor set "
7327 "each respectively destroyed and then attempting to "
Mark Mueller917f6bc2016-08-30 10:57:19 -06007328 "submit associated cmd buffers. Attempt to destroy a "
7329 "DescriptorSet that is in use.");
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06007330 ASSERT_NO_FATAL_FAILURE(InitState());
7331 ASSERT_NO_FATAL_FAILURE(InitViewport());
7332 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
7333
7334 VkDescriptorPoolSize ds_type_count = {};
7335 ds_type_count.type = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
7336 ds_type_count.descriptorCount = 1;
7337
7338 VkDescriptorPoolCreateInfo ds_pool_ci = {};
7339 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
7340 ds_pool_ci.pNext = NULL;
7341 ds_pool_ci.maxSets = 1;
7342 ds_pool_ci.poolSizeCount = 1;
7343 ds_pool_ci.pPoolSizes = &ds_type_count;
7344
7345 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007346 VkResult err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06007347 ASSERT_VK_SUCCESS(err);
7348
7349 VkDescriptorSetLayoutBinding dsl_binding = {};
7350 dsl_binding.binding = 0;
7351 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
7352 dsl_binding.descriptorCount = 1;
7353 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
7354 dsl_binding.pImmutableSamplers = NULL;
7355
7356 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
7357 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
7358 ds_layout_ci.pNext = NULL;
7359 ds_layout_ci.bindingCount = 1;
7360 ds_layout_ci.pBindings = &dsl_binding;
7361 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007362 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06007363 ASSERT_VK_SUCCESS(err);
7364
7365 VkDescriptorSet descriptorSet;
7366 VkDescriptorSetAllocateInfo alloc_info = {};
7367 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
7368 alloc_info.descriptorSetCount = 1;
7369 alloc_info.descriptorPool = ds_pool;
7370 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007371 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06007372 ASSERT_VK_SUCCESS(err);
7373
7374 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
7375 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
7376 pipeline_layout_ci.pNext = NULL;
7377 pipeline_layout_ci.setLayoutCount = 1;
7378 pipeline_layout_ci.pSetLayouts = &ds_layout;
7379
7380 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007381 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06007382 ASSERT_VK_SUCCESS(err);
7383
7384 // Create images to update the descriptor with
7385 VkImage image;
7386 VkImage image2;
7387 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
7388 const int32_t tex_width = 32;
7389 const int32_t tex_height = 32;
7390 VkImageCreateInfo image_create_info = {};
7391 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
7392 image_create_info.pNext = NULL;
7393 image_create_info.imageType = VK_IMAGE_TYPE_2D;
7394 image_create_info.format = tex_format;
7395 image_create_info.extent.width = tex_width;
7396 image_create_info.extent.height = tex_height;
7397 image_create_info.extent.depth = 1;
7398 image_create_info.mipLevels = 1;
7399 image_create_info.arrayLayers = 1;
7400 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
7401 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
7402 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
7403 image_create_info.flags = 0;
7404 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
7405 ASSERT_VK_SUCCESS(err);
7406 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image2);
7407 ASSERT_VK_SUCCESS(err);
7408
7409 VkMemoryRequirements memory_reqs;
7410 VkDeviceMemory image_memory;
7411 bool pass;
7412 VkMemoryAllocateInfo memory_info = {};
7413 memory_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
7414 memory_info.pNext = NULL;
7415 memory_info.allocationSize = 0;
7416 memory_info.memoryTypeIndex = 0;
7417 vkGetImageMemoryRequirements(m_device->device(), image, &memory_reqs);
7418 // Allocate enough memory for both images
7419 memory_info.allocationSize = memory_reqs.size * 2;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007420 pass = m_device->phy().set_memory_type(memory_reqs.memoryTypeBits, &memory_info, 0);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06007421 ASSERT_TRUE(pass);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007422 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &image_memory);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06007423 ASSERT_VK_SUCCESS(err);
7424 err = vkBindImageMemory(m_device->device(), image, image_memory, 0);
7425 ASSERT_VK_SUCCESS(err);
7426 // Bind second image to memory right after first image
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007427 err = vkBindImageMemory(m_device->device(), image2, image_memory, memory_reqs.size);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06007428 ASSERT_VK_SUCCESS(err);
7429
7430 VkImageViewCreateInfo image_view_create_info = {};
7431 image_view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
7432 image_view_create_info.image = image;
7433 image_view_create_info.viewType = VK_IMAGE_VIEW_TYPE_2D;
7434 image_view_create_info.format = tex_format;
7435 image_view_create_info.subresourceRange.layerCount = 1;
7436 image_view_create_info.subresourceRange.baseMipLevel = 0;
7437 image_view_create_info.subresourceRange.levelCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007438 image_view_create_info.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06007439
7440 VkImageView view;
7441 VkImageView view2;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007442 err = vkCreateImageView(m_device->device(), &image_view_create_info, NULL, &view);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06007443 ASSERT_VK_SUCCESS(err);
7444 image_view_create_info.image = image2;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007445 err = vkCreateImageView(m_device->device(), &image_view_create_info, NULL, &view2);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06007446 ASSERT_VK_SUCCESS(err);
7447 // Create Samplers
7448 VkSamplerCreateInfo sampler_ci = {};
7449 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
7450 sampler_ci.pNext = NULL;
7451 sampler_ci.magFilter = VK_FILTER_NEAREST;
7452 sampler_ci.minFilter = VK_FILTER_NEAREST;
7453 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
7454 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
7455 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
7456 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
7457 sampler_ci.mipLodBias = 1.0;
7458 sampler_ci.anisotropyEnable = VK_FALSE;
7459 sampler_ci.maxAnisotropy = 1;
7460 sampler_ci.compareEnable = VK_FALSE;
7461 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
7462 sampler_ci.minLod = 1.0;
7463 sampler_ci.maxLod = 1.0;
7464 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
7465 sampler_ci.unnormalizedCoordinates = VK_FALSE;
7466 VkSampler sampler;
7467 VkSampler sampler2;
7468 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
7469 ASSERT_VK_SUCCESS(err);
7470 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler2);
7471 ASSERT_VK_SUCCESS(err);
7472 // Update descriptor with image and sampler
7473 VkDescriptorImageInfo img_info = {};
7474 img_info.sampler = sampler;
7475 img_info.imageView = view;
7476 img_info.imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
7477
7478 VkWriteDescriptorSet descriptor_write;
7479 memset(&descriptor_write, 0, sizeof(descriptor_write));
7480 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
7481 descriptor_write.dstSet = descriptorSet;
7482 descriptor_write.dstBinding = 0;
7483 descriptor_write.descriptorCount = 1;
7484 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
7485 descriptor_write.pImageInfo = &img_info;
7486
7487 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
7488
7489 // Create PSO to be used for draw-time errors below
7490 char const *vsSource = "#version 450\n"
7491 "\n"
7492 "out gl_PerVertex { \n"
7493 " vec4 gl_Position;\n"
7494 "};\n"
7495 "void main(){\n"
7496 " gl_Position = vec4(1);\n"
7497 "}\n";
7498 char const *fsSource = "#version 450\n"
7499 "\n"
7500 "layout(set=0, binding=0) uniform sampler2D s;\n"
7501 "layout(location=0) out vec4 x;\n"
7502 "void main(){\n"
7503 " x = texture(s, vec2(1));\n"
7504 "}\n";
7505 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
7506 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
7507 VkPipelineObj pipe(m_device);
7508 pipe.AddShader(&vs);
7509 pipe.AddShader(&fs);
7510 pipe.AddColorAttachment();
7511 pipe.CreateVKPipeline(pipeline_layout, renderPass());
7512
7513 // First error case is destroying sampler prior to cmd buffer submission
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007514 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Cannot submit cmd buffer using deleted sampler ");
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06007515 BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007516 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
7517 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
7518 &descriptorSet, 0, NULL);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06007519 Draw(1, 0, 0, 0);
7520 EndCommandBuffer();
7521 // Destroy sampler invalidates the cmd buffer, causing error on submit
7522 vkDestroySampler(m_device->device(), sampler, NULL);
7523 // Attempt to submit cmd buffer
7524 VkSubmitInfo submit_info = {};
7525 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
7526 submit_info.commandBufferCount = 1;
7527 submit_info.pCommandBuffers = &m_commandBuffer->handle();
7528 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
7529 m_errorMonitor->VerifyFound();
7530 // Now re-update descriptor with valid sampler and delete image
7531 img_info.sampler = sampler2;
7532 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007533 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " that is invalid because bound image ");
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06007534 BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007535 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
7536 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
7537 &descriptorSet, 0, NULL);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06007538 Draw(1, 0, 0, 0);
7539 EndCommandBuffer();
7540 // Destroy image invalidates the cmd buffer, causing error on submit
7541 vkDestroyImage(m_device->device(), image, NULL);
7542 // Attempt to submit cmd buffer
7543 submit_info = {};
7544 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
7545 submit_info.commandBufferCount = 1;
7546 submit_info.pCommandBuffers = &m_commandBuffer->handle();
7547 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
7548 m_errorMonitor->VerifyFound();
7549 // Now update descriptor to be valid, but then free descriptor
7550 img_info.imageView = view2;
7551 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007552 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " that is invalid because bound descriptor set ");
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06007553 BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007554 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
7555 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
7556 &descriptorSet, 0, NULL);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06007557 Draw(1, 0, 0, 0);
7558 EndCommandBuffer();
7559 // Destroy descriptor set invalidates the cb, causing error on submit
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007560 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Cannot call vkFreeDescriptorSets() on descriptor set 0x");
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06007561 vkFreeDescriptorSets(m_device->device(), ds_pool, 1, &descriptorSet);
Mark Mueller917f6bc2016-08-30 10:57:19 -06007562 m_errorMonitor->VerifyFound();
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06007563 // Attempt to submit cmd buffer
7564 submit_info = {};
7565 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
7566 submit_info.commandBufferCount = 1;
7567 submit_info.pCommandBuffers = &m_commandBuffer->handle();
7568 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
7569 m_errorMonitor->VerifyFound();
7570 // Cleanup
7571 vkFreeMemory(m_device->device(), image_memory, NULL);
7572 vkDestroySampler(m_device->device(), sampler2, NULL);
7573 vkDestroyImage(m_device->device(), image2, NULL);
7574 vkDestroyImageView(m_device->device(), view, NULL);
7575 vkDestroyImageView(m_device->device(), view2, NULL);
7576 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
7577 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
7578 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
7579}
7580
Karl Schultz6addd812016-02-02 17:17:23 -07007581TEST_F(VkLayerTest, InvalidPipeline) {
Karl Schultzbdb75952016-04-19 11:36:49 -06007582 // Attempt to bind an invalid Pipeline to a valid Command Buffer
7583 // ObjectTracker should catch this.
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06007584 // Create a valid cmd buffer
7585 // call vkCmdBindPipeline w/ false Pipeline
Mark Lobodzinski02bf89d2016-05-10 14:45:13 -06007586 uint64_t fake_pipeline_handle = 0xbaad6001;
7587 VkPipeline bad_pipeline = reinterpret_cast<VkPipeline &>(fake_pipeline_handle);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007588 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Invalid Pipeline Object 0xbaad6001");
Karl Schultzbdb75952016-04-19 11:36:49 -06007589 ASSERT_NO_FATAL_FAILURE(InitState());
7590 BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007591 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, bad_pipeline);
Karl Schultzbdb75952016-04-19 11:36:49 -06007592 m_errorMonitor->VerifyFound();
Tobin Ehlisb8b6b272016-05-02 13:26:06 -06007593 // Now issue a draw call with no pipeline bound
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007594 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "At Draw/Dispatch time no valid VkPipeline is bound!");
Tony Barbourdf4c0042016-06-01 15:55:43 -06007595
Tobin Ehlisb8b6b272016-05-02 13:26:06 -06007596 BeginCommandBuffer();
7597 Draw(1, 0, 0, 0);
7598 m_errorMonitor->VerifyFound();
7599 // Finally same check once more but with Dispatch/Compute
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007600 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 -06007601 BeginCommandBuffer();
7602 vkCmdDispatch(m_commandBuffer->GetBufferHandle(), 0, 0, 0);
7603 m_errorMonitor->VerifyFound();
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06007604}
7605
Karl Schultz6addd812016-02-02 17:17:23 -07007606TEST_F(VkLayerTest, DescriptorSetNotUpdated) {
Tobin Ehlis5a5f5ef2016-08-17 13:56:55 -06007607 TEST_DESCRIPTION("Bind a descriptor set that hasn't been updated.");
Karl Schultz6addd812016-02-02 17:17:23 -07007608 VkResult err;
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06007609
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007610 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT, " bound but it was never updated. ");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06007611
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06007612 ASSERT_NO_FATAL_FAILURE(InitState());
Mike Stroyan713b2d72015-08-04 10:49:29 -06007613 ASSERT_NO_FATAL_FAILURE(InitViewport());
7614 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chia-I Wu1b99bb22015-10-27 19:25:11 +08007615 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007616 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
7617 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -06007618
7619 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007620 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
7621 ds_pool_ci.pNext = NULL;
7622 ds_pool_ci.maxSets = 1;
7623 ds_pool_ci.poolSizeCount = 1;
7624 ds_pool_ci.pPoolSizes = &ds_type_count;
Mike Stroyan713b2d72015-08-04 10:49:29 -06007625
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06007626 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007627 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06007628 ASSERT_VK_SUCCESS(err);
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06007629
Tony Barboureb254902015-07-15 12:50:33 -06007630 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007631 dsl_binding.binding = 0;
7632 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
7633 dsl_binding.descriptorCount = 1;
7634 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
7635 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06007636
Tony Barboureb254902015-07-15 12:50:33 -06007637 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007638 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
7639 ds_layout_ci.pNext = NULL;
7640 ds_layout_ci.bindingCount = 1;
7641 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06007642 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007643 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06007644 ASSERT_VK_SUCCESS(err);
7645
7646 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08007647 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08007648 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07007649 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06007650 alloc_info.descriptorPool = ds_pool;
7651 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007652 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06007653 ASSERT_VK_SUCCESS(err);
7654
Tony Barboureb254902015-07-15 12:50:33 -06007655 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007656 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
7657 pipeline_layout_ci.pNext = NULL;
7658 pipeline_layout_ci.setLayoutCount = 1;
7659 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06007660
7661 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007662 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06007663 ASSERT_VK_SUCCESS(err);
7664
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007665 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
Karl Schultzbdb75952016-04-19 11:36:49 -06007666 // We shouldn't need a fragment shader but add it to be able to run
Karl Schultz6addd812016-02-02 17:17:23 -07007667 // on more devices
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007668 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06007669
Tony Barbourc95e4ac2015-08-04 17:05:26 -06007670 VkPipelineObj pipe(m_device);
7671 pipe.AddShader(&vs);
Tony Barbour1c94d372015-08-06 11:21:08 -06007672 pipe.AddShader(&fs);
Mark Youngc89c6312016-03-31 16:03:20 -06007673 pipe.AddColorAttachment();
Tony Barbourc95e4ac2015-08-04 17:05:26 -06007674 pipe.CreateVKPipeline(pipeline_layout, renderPass());
Tony Barbourfe3351b2015-07-28 10:17:20 -06007675
7676 BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007677 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
7678 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
7679 &descriptorSet, 0, NULL);
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06007680
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007681 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06007682
Chia-I Wuf7458c52015-10-26 21:10:41 +08007683 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
7684 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
7685 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06007686}
7687
Karl Schultz6addd812016-02-02 17:17:23 -07007688TEST_F(VkLayerTest, InvalidBufferViewObject) {
Tobin Ehlisba31cab2015-11-02 15:24:32 -07007689 // Create a single TEXEL_BUFFER descriptor and send it an invalid bufferView
Karl Schultz6addd812016-02-02 17:17:23 -07007690 VkResult err;
Tobin Ehlisba31cab2015-11-02 15:24:32 -07007691
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007692 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Attempted write update to texel buffer "
7693 "descriptor with invalid buffer view");
Tobin Ehlisba31cab2015-11-02 15:24:32 -07007694
7695 ASSERT_NO_FATAL_FAILURE(InitState());
7696 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007697 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER;
7698 ds_type_count.descriptorCount = 1;
Tobin Ehlisba31cab2015-11-02 15:24:32 -07007699
7700 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007701 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
7702 ds_pool_ci.pNext = NULL;
7703 ds_pool_ci.maxSets = 1;
7704 ds_pool_ci.poolSizeCount = 1;
7705 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlisba31cab2015-11-02 15:24:32 -07007706
7707 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007708 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlisba31cab2015-11-02 15:24:32 -07007709 ASSERT_VK_SUCCESS(err);
7710
7711 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007712 dsl_binding.binding = 0;
7713 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER;
7714 dsl_binding.descriptorCount = 1;
7715 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
7716 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlisba31cab2015-11-02 15:24:32 -07007717
7718 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007719 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
7720 ds_layout_ci.pNext = NULL;
7721 ds_layout_ci.bindingCount = 1;
7722 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlisba31cab2015-11-02 15:24:32 -07007723 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007724 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlisba31cab2015-11-02 15:24:32 -07007725 ASSERT_VK_SUCCESS(err);
7726
7727 VkDescriptorSet descriptorSet;
7728 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08007729 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07007730 alloc_info.descriptorSetCount = 1;
Tobin Ehlisba31cab2015-11-02 15:24:32 -07007731 alloc_info.descriptorPool = ds_pool;
7732 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007733 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlisba31cab2015-11-02 15:24:32 -07007734 ASSERT_VK_SUCCESS(err);
7735
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007736 VkBufferView view = (VkBufferView)((size_t)0xbaadbeef); // invalid bufferView object
Tobin Ehlisba31cab2015-11-02 15:24:32 -07007737 VkWriteDescriptorSet descriptor_write;
7738 memset(&descriptor_write, 0, sizeof(descriptor_write));
7739 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
7740 descriptor_write.dstSet = descriptorSet;
7741 descriptor_write.dstBinding = 0;
7742 descriptor_write.descriptorCount = 1;
7743 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER;
7744 descriptor_write.pTexelBufferView = &view;
7745
7746 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
7747
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007748 m_errorMonitor->VerifyFound();
Tobin Ehlisba31cab2015-11-02 15:24:32 -07007749
7750 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
7751 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
7752}
7753
Mark Youngd339ba32016-05-30 13:28:35 -06007754TEST_F(VkLayerTest, CreateBufferViewNoMemoryBoundToBuffer) {
7755 TEST_DESCRIPTION("Attempt to create a buffer view with a buffer that has"
7756 " no memory bound to it.");
7757
7758 VkResult err;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007759 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "used without first calling vkBindBufferMemory");
Mark Youngd339ba32016-05-30 13:28:35 -06007760
7761 ASSERT_NO_FATAL_FAILURE(InitState());
7762
7763 // Create a buffer with no bound memory and then attempt to create
7764 // a buffer view.
7765 VkBufferCreateInfo buff_ci = {};
7766 buff_ci.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
Chris Forbes4538d242016-09-13 18:13:58 +12007767 buff_ci.usage = VK_BUFFER_USAGE_UNIFORM_TEXEL_BUFFER_BIT;
Mark Youngd339ba32016-05-30 13:28:35 -06007768 buff_ci.size = 256;
7769 buff_ci.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
7770 VkBuffer buffer;
7771 err = vkCreateBuffer(m_device->device(), &buff_ci, NULL, &buffer);
7772 ASSERT_VK_SUCCESS(err);
7773
7774 VkBufferViewCreateInfo buff_view_ci = {};
7775 buff_view_ci.sType = VK_STRUCTURE_TYPE_BUFFER_VIEW_CREATE_INFO;
7776 buff_view_ci.buffer = buffer;
7777 buff_view_ci.format = VK_FORMAT_R8_UNORM;
7778 buff_view_ci.range = VK_WHOLE_SIZE;
7779 VkBufferView buff_view;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007780 err = vkCreateBufferView(m_device->device(), &buff_view_ci, NULL, &buff_view);
Mark Youngd339ba32016-05-30 13:28:35 -06007781
7782 m_errorMonitor->VerifyFound();
7783 vkDestroyBuffer(m_device->device(), buffer, NULL);
7784 // If last error is success, it still created the view, so delete it.
7785 if (err == VK_SUCCESS) {
7786 vkDestroyBufferView(m_device->device(), buff_view, NULL);
7787 }
7788}
7789
Karl Schultz6addd812016-02-02 17:17:23 -07007790TEST_F(VkLayerTest, InvalidDynamicOffsetCases) {
7791 // Create a descriptorSet w/ dynamic descriptor and then hit 3 offset error
7792 // cases:
Tobin Ehlisf6585052015-12-17 11:48:42 -07007793 // 1. No dynamicOffset supplied
7794 // 2. Too many dynamicOffsets supplied
7795 // 3. Dynamic offset oversteps buffer being updated
Karl Schultz6addd812016-02-02 17:17:23 -07007796 VkResult err;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007797 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " requires 1 dynamicOffsets, but only "
7798 "0 dynamicOffsets are left in "
7799 "pDynamicOffsets ");
Tobin Ehlis49f903e2015-11-04 13:30:34 -07007800
7801 ASSERT_NO_FATAL_FAILURE(InitState());
7802 ASSERT_NO_FATAL_FAILURE(InitViewport());
7803 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
7804
7805 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007806 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
7807 ds_type_count.descriptorCount = 1;
Tobin Ehlis49f903e2015-11-04 13:30:34 -07007808
7809 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007810 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
7811 ds_pool_ci.pNext = NULL;
7812 ds_pool_ci.maxSets = 1;
7813 ds_pool_ci.poolSizeCount = 1;
7814 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlis49f903e2015-11-04 13:30:34 -07007815
7816 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007817 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis49f903e2015-11-04 13:30:34 -07007818 ASSERT_VK_SUCCESS(err);
7819
7820 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007821 dsl_binding.binding = 0;
7822 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
7823 dsl_binding.descriptorCount = 1;
7824 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
7825 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis49f903e2015-11-04 13:30:34 -07007826
7827 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007828 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
7829 ds_layout_ci.pNext = NULL;
7830 ds_layout_ci.bindingCount = 1;
7831 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlis49f903e2015-11-04 13:30:34 -07007832 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007833 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis49f903e2015-11-04 13:30:34 -07007834 ASSERT_VK_SUCCESS(err);
7835
7836 VkDescriptorSet descriptorSet;
7837 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08007838 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07007839 alloc_info.descriptorSetCount = 1;
Tobin Ehlis49f903e2015-11-04 13:30:34 -07007840 alloc_info.descriptorPool = ds_pool;
7841 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007842 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis49f903e2015-11-04 13:30:34 -07007843 ASSERT_VK_SUCCESS(err);
7844
7845 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007846 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
7847 pipeline_layout_ci.pNext = NULL;
7848 pipeline_layout_ci.setLayoutCount = 1;
7849 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlis49f903e2015-11-04 13:30:34 -07007850
7851 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007852 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis49f903e2015-11-04 13:30:34 -07007853 ASSERT_VK_SUCCESS(err);
7854
7855 // Create a buffer to update the descriptor with
7856 uint32_t qfi = 0;
7857 VkBufferCreateInfo buffCI = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007858 buffCI.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
7859 buffCI.size = 1024;
7860 buffCI.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
7861 buffCI.queueFamilyIndexCount = 1;
7862 buffCI.pQueueFamilyIndices = &qfi;
Tobin Ehlis49f903e2015-11-04 13:30:34 -07007863
7864 VkBuffer dyub;
7865 err = vkCreateBuffer(m_device->device(), &buffCI, NULL, &dyub);
7866 ASSERT_VK_SUCCESS(err);
Tobin Ehlis0a43bde2016-05-03 08:31:08 -06007867 // Allocate memory and bind to buffer so we can make it to the appropriate
7868 // error
7869 VkMemoryAllocateInfo mem_alloc = {};
7870 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
7871 mem_alloc.pNext = NULL;
7872 mem_alloc.allocationSize = 1024;
Chris Forbesb6116cc2016-05-08 11:39:59 +12007873 mem_alloc.memoryTypeIndex = 0;
7874
7875 VkMemoryRequirements memReqs;
7876 vkGetBufferMemoryRequirements(m_device->device(), dyub, &memReqs);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007877 bool pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &mem_alloc, 0);
Chris Forbesb6116cc2016-05-08 11:39:59 +12007878 if (!pass) {
7879 vkDestroyBuffer(m_device->device(), dyub, NULL);
7880 return;
7881 }
7882
Tobin Ehlis0a43bde2016-05-03 08:31:08 -06007883 VkDeviceMemory mem;
7884 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem);
7885 ASSERT_VK_SUCCESS(err);
7886 err = vkBindBufferMemory(m_device->device(), dyub, mem, 0);
7887 ASSERT_VK_SUCCESS(err);
Tobin Ehlis49f903e2015-11-04 13:30:34 -07007888 // Correctly update descriptor to avoid "NOT_UPDATED" error
7889 VkDescriptorBufferInfo buffInfo = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007890 buffInfo.buffer = dyub;
7891 buffInfo.offset = 0;
7892 buffInfo.range = 1024;
Tobin Ehlis49f903e2015-11-04 13:30:34 -07007893
7894 VkWriteDescriptorSet descriptor_write;
7895 memset(&descriptor_write, 0, sizeof(descriptor_write));
7896 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
7897 descriptor_write.dstSet = descriptorSet;
7898 descriptor_write.dstBinding = 0;
7899 descriptor_write.descriptorCount = 1;
7900 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
7901 descriptor_write.pBufferInfo = &buffInfo;
7902
7903 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
7904
7905 BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007906 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
7907 &descriptorSet, 0, NULL);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007908 m_errorMonitor->VerifyFound();
Tobin Ehlisf6585052015-12-17 11:48:42 -07007909 uint32_t pDynOff[2] = {512, 756};
7910 // Now cause error b/c too many dynOffsets in array for # of dyn descriptors
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007911 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
7912 "Attempting to bind 1 descriptorSets with 1 dynamic descriptors, but ");
7913 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
7914 &descriptorSet, 2, pDynOff);
Chris Forbes7b342802016-04-07 13:20:10 +12007915 m_errorMonitor->VerifyFound();
Tobin Ehlisf6585052015-12-17 11:48:42 -07007916 // Finally cause error due to dynamicOffset being too big
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007917 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " dynamic offset 512 combined with "
7918 "offset 0 and range 1024 that "
7919 "oversteps the buffer size of 1024");
Tobin Ehlisf6585052015-12-17 11:48:42 -07007920 // Create PSO to be used for draw-time errors below
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007921 char const *vsSource = "#version 450\n"
7922 "\n"
7923 "out gl_PerVertex { \n"
7924 " vec4 gl_Position;\n"
7925 "};\n"
7926 "void main(){\n"
7927 " gl_Position = vec4(1);\n"
7928 "}\n";
7929 char const *fsSource = "#version 450\n"
7930 "\n"
7931 "layout(location=0) out vec4 x;\n"
7932 "layout(set=0) layout(binding=0) uniform foo { int x; int y; } bar;\n"
7933 "void main(){\n"
7934 " x = vec4(bar.y);\n"
7935 "}\n";
Tobin Ehlisf6585052015-12-17 11:48:42 -07007936 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
7937 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
7938 VkPipelineObj pipe(m_device);
7939 pipe.AddShader(&vs);
7940 pipe.AddShader(&fs);
7941 pipe.AddColorAttachment();
7942 pipe.CreateVKPipeline(pipeline_layout, renderPass());
7943
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007944 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Karl Schultz6addd812016-02-02 17:17:23 -07007945 // This update should succeed, but offset size of 512 will overstep buffer
7946 // /w range 1024 & size 1024
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007947 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
7948 &descriptorSet, 1, pDynOff);
Tobin Ehlisf6585052015-12-17 11:48:42 -07007949 Draw(1, 0, 0, 0);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007950 m_errorMonitor->VerifyFound();
Tobin Ehlis49f903e2015-11-04 13:30:34 -07007951
Tobin Ehlis0a43bde2016-05-03 08:31:08 -06007952 vkDestroyBuffer(m_device->device(), dyub, NULL);
Tobin Ehlis512098e2016-05-05 09:06:12 -06007953 vkFreeMemory(m_device->device(), mem, NULL);
Tobin Ehlis0a43bde2016-05-03 08:31:08 -06007954
Tobin Ehlis49f903e2015-11-04 13:30:34 -07007955 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
Tony Barbourdf4c0042016-06-01 15:55:43 -06007956 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
Tobin Ehlis49f903e2015-11-04 13:30:34 -07007957 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
7958}
7959
Tobin Ehlis8ef479c2016-07-20 16:14:49 -06007960TEST_F(VkLayerTest, DescriptorBufferUpdateNoMemoryBound) {
7961 TEST_DESCRIPTION("Attempt to update a descriptor with a non-sparse buffer "
7962 "that doesn't have memory bound");
7963 VkResult err;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007964 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " used without first calling vkBindBufferMemory.");
Tobin Ehlis8ef479c2016-07-20 16:14:49 -06007965
7966 ASSERT_NO_FATAL_FAILURE(InitState());
7967 ASSERT_NO_FATAL_FAILURE(InitViewport());
7968 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
7969
7970 VkDescriptorPoolSize ds_type_count = {};
7971 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
7972 ds_type_count.descriptorCount = 1;
7973
7974 VkDescriptorPoolCreateInfo ds_pool_ci = {};
7975 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
7976 ds_pool_ci.pNext = NULL;
7977 ds_pool_ci.maxSets = 1;
7978 ds_pool_ci.poolSizeCount = 1;
7979 ds_pool_ci.pPoolSizes = &ds_type_count;
7980
7981 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007982 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis8ef479c2016-07-20 16:14:49 -06007983 ASSERT_VK_SUCCESS(err);
7984
7985 VkDescriptorSetLayoutBinding dsl_binding = {};
7986 dsl_binding.binding = 0;
7987 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
7988 dsl_binding.descriptorCount = 1;
7989 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
7990 dsl_binding.pImmutableSamplers = NULL;
7991
7992 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
7993 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
7994 ds_layout_ci.pNext = NULL;
7995 ds_layout_ci.bindingCount = 1;
7996 ds_layout_ci.pBindings = &dsl_binding;
7997 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007998 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis8ef479c2016-07-20 16:14:49 -06007999 ASSERT_VK_SUCCESS(err);
8000
8001 VkDescriptorSet descriptorSet;
8002 VkDescriptorSetAllocateInfo alloc_info = {};
8003 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
8004 alloc_info.descriptorSetCount = 1;
8005 alloc_info.descriptorPool = ds_pool;
8006 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008007 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis8ef479c2016-07-20 16:14:49 -06008008 ASSERT_VK_SUCCESS(err);
8009
8010 // Create a buffer to update the descriptor with
8011 uint32_t qfi = 0;
8012 VkBufferCreateInfo buffCI = {};
8013 buffCI.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
8014 buffCI.size = 1024;
8015 buffCI.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
8016 buffCI.queueFamilyIndexCount = 1;
8017 buffCI.pQueueFamilyIndices = &qfi;
8018
8019 VkBuffer dyub;
8020 err = vkCreateBuffer(m_device->device(), &buffCI, NULL, &dyub);
8021 ASSERT_VK_SUCCESS(err);
8022
8023 // Attempt to update descriptor without binding memory to it
8024 VkDescriptorBufferInfo buffInfo = {};
8025 buffInfo.buffer = dyub;
8026 buffInfo.offset = 0;
8027 buffInfo.range = 1024;
8028
8029 VkWriteDescriptorSet descriptor_write;
8030 memset(&descriptor_write, 0, sizeof(descriptor_write));
8031 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
8032 descriptor_write.dstSet = descriptorSet;
8033 descriptor_write.dstBinding = 0;
8034 descriptor_write.descriptorCount = 1;
8035 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
8036 descriptor_write.pBufferInfo = &buffInfo;
8037
8038 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
8039 m_errorMonitor->VerifyFound();
8040
8041 vkDestroyBuffer(m_device->device(), dyub, NULL);
8042 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
8043 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
8044}
8045
Tobin Ehlis3a23b6a2016-02-17 10:35:18 -07008046TEST_F(VkLayerTest, InvalidPushConstants) {
Tobin Ehlis3a23b6a2016-02-17 10:35:18 -07008047 VkResult err;
Tobin Ehlis3a23b6a2016-02-17 10:35:18 -07008048 ASSERT_NO_FATAL_FAILURE(InitState());
8049 ASSERT_NO_FATAL_FAILURE(InitViewport());
8050 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
8051
Karl Schultzfc8eaf12016-05-06 13:56:42 -06008052 VkPipelineLayout pipeline_layout;
Tobin Ehlis3a23b6a2016-02-17 10:35:18 -07008053 VkPushConstantRange pc_range = {};
Tobin Ehlis3a23b6a2016-02-17 10:35:18 -07008054 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
8055 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
8056 pipeline_layout_ci.pushConstantRangeCount = 1;
8057 pipeline_layout_ci.pPushConstantRanges = &pc_range;
8058
Karl Schultzfc8eaf12016-05-06 13:56:42 -06008059 //
8060 // Check for invalid push constant ranges in pipeline layouts.
8061 //
8062 struct PipelineLayoutTestCase {
Karl Schultzc81037d2016-05-12 08:11:23 -06008063 VkPushConstantRange const range;
Karl Schultzfc8eaf12016-05-06 13:56:42 -06008064 char const *msg;
8065 };
Tobin Ehlis3a23b6a2016-02-17 10:35:18 -07008066
Karl Schultzc81037d2016-05-12 08:11:23 -06008067 const uint32_t too_big = m_device->props.limits.maxPushConstantsSize + 0x4;
8068 const std::array<PipelineLayoutTestCase, 10> range_tests = {{
8069 {{VK_SHADER_STAGE_VERTEX_BIT, 0, 0},
8070 "vkCreatePipelineLayout() call has push constants index 0 with "
8071 "size 0."},
8072 {{VK_SHADER_STAGE_VERTEX_BIT, 0, 1},
8073 "vkCreatePipelineLayout() call has push constants index 0 with "
8074 "size 1."},
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06008075 {{VK_SHADER_STAGE_VERTEX_BIT, 4, 1},
Karl Schultzc81037d2016-05-12 08:11:23 -06008076 "vkCreatePipelineLayout() call has push constants index 0 with "
8077 "size 1."},
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06008078 {{VK_SHADER_STAGE_VERTEX_BIT, 4, 0},
Karl Schultzc81037d2016-05-12 08:11:23 -06008079 "vkCreatePipelineLayout() call has push constants index 0 with "
8080 "size 0."},
8081 {{VK_SHADER_STAGE_VERTEX_BIT, 1, 4},
8082 "vkCreatePipelineLayout() call has push constants index 0 with "
8083 "offset 1. Offset must"},
8084 {{VK_SHADER_STAGE_VERTEX_BIT, 0, too_big},
8085 "vkCreatePipelineLayout() call has push constants index 0 "
8086 "with offset "},
8087 {{VK_SHADER_STAGE_VERTEX_BIT, too_big, too_big},
8088 "vkCreatePipelineLayout() call has push constants "
8089 "index 0 with offset "},
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06008090 {{VK_SHADER_STAGE_VERTEX_BIT, too_big, 4},
Karl Schultzc81037d2016-05-12 08:11:23 -06008091 "vkCreatePipelineLayout() call has push constants index 0 "
8092 "with offset "},
8093 {{VK_SHADER_STAGE_VERTEX_BIT, 0xFFFFFFF0, 0x00000020},
8094 "vkCreatePipelineLayout() call has push "
8095 "constants index 0 with offset "},
8096 {{VK_SHADER_STAGE_VERTEX_BIT, 0x00000020, 0xFFFFFFF0},
8097 "vkCreatePipelineLayout() call has push "
8098 "constants index 0 with offset "},
Karl Schultzfc8eaf12016-05-06 13:56:42 -06008099 }};
8100
8101 // Check for invalid offset and size
Karl Schultzc81037d2016-05-12 08:11:23 -06008102 for (const auto &iter : range_tests) {
8103 pc_range = iter.range;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008104 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, iter.msg);
8105 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Karl Schultzfc8eaf12016-05-06 13:56:42 -06008106 m_errorMonitor->VerifyFound();
8107 if (VK_SUCCESS == err) {
8108 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
8109 }
8110 }
8111
8112 // Check for invalid stage flag
8113 pc_range.offset = 0;
8114 pc_range.size = 16;
8115 pc_range.stageFlags = 0;
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06008116 m_errorMonitor->SetDesiredFailureMsg(
8117 VK_DEBUG_REPORT_ERROR_BIT_EXT,
8118 "vkCreatePipelineLayout: value of pCreateInfo->pPushConstantRanges[0].stageFlags must not be 0");
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008119 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008120 m_errorMonitor->VerifyFound();
Karl Schultzfc8eaf12016-05-06 13:56:42 -06008121 if (VK_SUCCESS == err) {
8122 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
8123 }
8124
8125 // Check for overlapping ranges
Karl Schultzc81037d2016-05-12 08:11:23 -06008126 const uint32_t ranges_per_test = 5;
Karl Schultzfc8eaf12016-05-06 13:56:42 -06008127 struct OverlappingRangeTestCase {
Karl Schultzc81037d2016-05-12 08:11:23 -06008128 VkPushConstantRange const ranges[ranges_per_test];
Karl Schultzfc8eaf12016-05-06 13:56:42 -06008129 char const *msg;
8130 };
8131
Karl Schultzc81037d2016-05-12 08:11:23 -06008132 const std::array<OverlappingRangeTestCase, 5> overlapping_range_tests = {
Karl Schultzfc8eaf12016-05-06 13:56:42 -06008133 {{{{VK_SHADER_STAGE_VERTEX_BIT, 0, 4},
8134 {VK_SHADER_STAGE_VERTEX_BIT, 0, 4},
8135 {VK_SHADER_STAGE_VERTEX_BIT, 0, 4},
8136 {VK_SHADER_STAGE_VERTEX_BIT, 0, 4},
8137 {VK_SHADER_STAGE_VERTEX_BIT, 0, 4}},
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06008138 "vkCreatePipelineLayout() call has push constants with overlapping ranges:"},
Karl Schultzfc8eaf12016-05-06 13:56:42 -06008139 {
8140 {{VK_SHADER_STAGE_VERTEX_BIT, 0, 4},
8141 {VK_SHADER_STAGE_VERTEX_BIT, 4, 4},
8142 {VK_SHADER_STAGE_VERTEX_BIT, 8, 4},
8143 {VK_SHADER_STAGE_VERTEX_BIT, 12, 8},
8144 {VK_SHADER_STAGE_VERTEX_BIT, 16, 4}},
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06008145 "vkCreatePipelineLayout() call has push constants with overlapping ranges: 3:[12, 20), 4:[16, 20)",
Karl Schultzfc8eaf12016-05-06 13:56:42 -06008146 },
8147 {
8148 {{VK_SHADER_STAGE_VERTEX_BIT, 16, 4},
8149 {VK_SHADER_STAGE_VERTEX_BIT, 12, 8},
8150 {VK_SHADER_STAGE_VERTEX_BIT, 8, 4},
8151 {VK_SHADER_STAGE_VERTEX_BIT, 4, 4},
8152 {VK_SHADER_STAGE_VERTEX_BIT, 0, 4}},
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06008153 "vkCreatePipelineLayout() call has push constants with overlapping ranges: 0:[16, 20), 1:[12, 20)",
Karl Schultzfc8eaf12016-05-06 13:56:42 -06008154 },
8155 {
8156 {{VK_SHADER_STAGE_VERTEX_BIT, 16, 4},
8157 {VK_SHADER_STAGE_VERTEX_BIT, 8, 4},
8158 {VK_SHADER_STAGE_VERTEX_BIT, 4, 4},
8159 {VK_SHADER_STAGE_VERTEX_BIT, 12, 8},
8160 {VK_SHADER_STAGE_VERTEX_BIT, 0, 4}},
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06008161 "vkCreatePipelineLayout() call has push constants with overlapping ranges: 0:[16, 20), 3:[12, 20)",
Karl Schultzfc8eaf12016-05-06 13:56:42 -06008162 },
8163 {
8164 {{VK_SHADER_STAGE_VERTEX_BIT, 16, 4},
8165 {VK_SHADER_STAGE_VERTEX_BIT, 32, 4},
8166 {VK_SHADER_STAGE_VERTEX_BIT, 4, 96},
8167 {VK_SHADER_STAGE_VERTEX_BIT, 40, 8},
8168 {VK_SHADER_STAGE_VERTEX_BIT, 52, 4}},
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06008169 "vkCreatePipelineLayout() call has push constants with overlapping ranges:",
Karl Schultzfc8eaf12016-05-06 13:56:42 -06008170 }}};
Karl Schultzfc8eaf12016-05-06 13:56:42 -06008171
Karl Schultzc81037d2016-05-12 08:11:23 -06008172 for (const auto &iter : overlapping_range_tests) {
Karl Schultzfc8eaf12016-05-06 13:56:42 -06008173 pipeline_layout_ci.pPushConstantRanges = iter.ranges;
Karl Schultzc81037d2016-05-12 08:11:23 -06008174 pipeline_layout_ci.pushConstantRangeCount = ranges_per_test;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008175 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT, iter.msg);
8176 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Karl Schultzfc8eaf12016-05-06 13:56:42 -06008177 m_errorMonitor->VerifyFound();
8178 if (VK_SUCCESS == err) {
8179 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
8180 }
8181 }
8182
8183 // Run some positive tests to make sure overlap checking in the layer is OK
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008184 const std::array<OverlappingRangeTestCase, 2> overlapping_range_tests_pos = {{{{{VK_SHADER_STAGE_VERTEX_BIT, 0, 4},
8185 {VK_SHADER_STAGE_VERTEX_BIT, 4, 4},
8186 {VK_SHADER_STAGE_VERTEX_BIT, 8, 4},
8187 {VK_SHADER_STAGE_VERTEX_BIT, 12, 4},
8188 {VK_SHADER_STAGE_VERTEX_BIT, 16, 4}},
8189 ""},
8190 {{{VK_SHADER_STAGE_VERTEX_BIT, 92, 24},
8191 {VK_SHADER_STAGE_VERTEX_BIT, 80, 4},
8192 {VK_SHADER_STAGE_VERTEX_BIT, 64, 8},
8193 {VK_SHADER_STAGE_VERTEX_BIT, 4, 16},
8194 {VK_SHADER_STAGE_VERTEX_BIT, 0, 4}},
8195 ""}}};
Karl Schultzc81037d2016-05-12 08:11:23 -06008196 for (const auto &iter : overlapping_range_tests_pos) {
Karl Schultzfc8eaf12016-05-06 13:56:42 -06008197 pipeline_layout_ci.pPushConstantRanges = iter.ranges;
8198 m_errorMonitor->ExpectSuccess();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008199 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Karl Schultzfc8eaf12016-05-06 13:56:42 -06008200 m_errorMonitor->VerifyNotFound();
8201 if (VK_SUCCESS == err) {
8202 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
8203 }
8204 }
8205
8206 //
8207 // CmdPushConstants tests
8208 //
Karl Schultzc81037d2016-05-12 08:11:23 -06008209 const uint8_t dummy_values[100] = {};
Karl Schultzfc8eaf12016-05-06 13:56:42 -06008210
8211 // Check for invalid offset and size and if range is within layout range(s)
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06008212 const std::array<PipelineLayoutTestCase, 11> cmd_range_tests = {{
8213 {{VK_SHADER_STAGE_VERTEX_BIT, 0, 0}, "vkCmdPushConstants: parameter size must be greater than 0"},
Karl Schultzc81037d2016-05-12 08:11:23 -06008214 {{VK_SHADER_STAGE_VERTEX_BIT, 0, 1},
8215 "vkCmdPushConstants() call has push constants with size 1. Size "
8216 "must be greater than zero and a multiple of 4."},
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06008217 {{VK_SHADER_STAGE_VERTEX_BIT, 4, 1},
Karl Schultzc81037d2016-05-12 08:11:23 -06008218 "vkCmdPushConstants() call has push constants with size 1. Size "
8219 "must be greater than zero and a multiple of 4."},
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06008220 {{VK_SHADER_STAGE_VERTEX_BIT, 1, 4},
Karl Schultzc81037d2016-05-12 08:11:23 -06008221 "vkCmdPushConstants() call has push constants with offset 1. "
8222 "Offset must be a multiple of 4."},
8223 {{VK_SHADER_STAGE_VERTEX_BIT, 1, 4},
8224 "vkCmdPushConstants() call has push constants with offset 1. "
8225 "Offset must be a multiple of 4."},
8226 {{VK_SHADER_STAGE_VERTEX_BIT, 0, 20},
8227 "vkCmdPushConstants() Push constant range [0, 20) with stageFlags = "
8228 "0x1 not within flag-matching ranges in pipeline layout"},
8229 {{VK_SHADER_STAGE_VERTEX_BIT, 60, 8},
8230 "vkCmdPushConstants() Push constant range [60, 68) with stageFlags = "
8231 "0x1 not within flag-matching ranges in pipeline layout"},
8232 {{VK_SHADER_STAGE_VERTEX_BIT, 76, 8},
8233 "vkCmdPushConstants() Push constant range [76, 84) with stageFlags = "
8234 "0x1 not within flag-matching ranges in pipeline layout"},
8235 {{VK_SHADER_STAGE_VERTEX_BIT, 0, 80},
8236 "vkCmdPushConstants() Push constant range [0, 80) with stageFlags = "
8237 "0x1 not within flag-matching ranges in pipeline layout"},
8238 {{VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT, 0, 4},
8239 "vkCmdPushConstants() stageFlags = 0x2 do not match the stageFlags in "
8240 "any of the ranges in pipeline layout"},
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008241 {{VK_SHADER_STAGE_VERTEX_BIT | VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT, 0, 16},
Karl Schultzc81037d2016-05-12 08:11:23 -06008242 "vkCmdPushConstants() stageFlags = 0x3 do not match the stageFlags in "
8243 "any of the ranges in pipeline layout"},
Karl Schultzfc8eaf12016-05-06 13:56:42 -06008244 }};
8245
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06008246 BeginCommandBuffer();
8247
8248 // Setup ranges: [0,16) [64,80)
Karl Schultzc81037d2016-05-12 08:11:23 -06008249 const VkPushConstantRange pc_range2[] = {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008250 {VK_SHADER_STAGE_VERTEX_BIT, 64, 16}, {VK_SHADER_STAGE_VERTEX_BIT, 0, 16},
Karl Schultzfc8eaf12016-05-06 13:56:42 -06008251 };
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008252 pipeline_layout_ci.pushConstantRangeCount = sizeof(pc_range2) / sizeof(VkPushConstantRange);
Karl Schultzfc8eaf12016-05-06 13:56:42 -06008253 pipeline_layout_ci.pPushConstantRanges = pc_range2;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008254 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis3a23b6a2016-02-17 10:35:18 -07008255 ASSERT_VK_SUCCESS(err);
Karl Schultzc81037d2016-05-12 08:11:23 -06008256 for (const auto &iter : cmd_range_tests) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008257 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, iter.msg);
8258 vkCmdPushConstants(m_commandBuffer->GetBufferHandle(), pipeline_layout, iter.range.stageFlags, iter.range.offset,
Karl Schultzc81037d2016-05-12 08:11:23 -06008259 iter.range.size, dummy_values);
Karl Schultzfc8eaf12016-05-06 13:56:42 -06008260 m_errorMonitor->VerifyFound();
8261 }
8262
8263 // Check for invalid stage flag
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06008264 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "vkCmdPushConstants: value of stageFlags must not be 0");
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008265 vkCmdPushConstants(m_commandBuffer->GetBufferHandle(), pipeline_layout, 0, 0, 16, dummy_values);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008266 m_errorMonitor->VerifyFound();
Karl Schultzc81037d2016-05-12 08:11:23 -06008267 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
Karl Schultzfc8eaf12016-05-06 13:56:42 -06008268
Karl Schultzc81037d2016-05-12 08:11:23 -06008269 // overlapping range tests with cmd
8270 const std::array<PipelineLayoutTestCase, 3> cmd_overlap_tests = {{
8271 {{VK_SHADER_STAGE_VERTEX_BIT, 0, 20},
8272 "vkCmdPushConstants() Push constant range [0, 20) with stageFlags = "
8273 "0x1 not within flag-matching ranges in pipeline layout"},
8274 {{VK_SHADER_STAGE_VERTEX_BIT, 16, 4},
8275 "vkCmdPushConstants() Push constant range [16, 20) with stageFlags = "
8276 "0x1 not within flag-matching ranges in pipeline layout"},
8277 {{VK_SHADER_STAGE_VERTEX_BIT, 40, 16},
8278 "vkCmdPushConstants() Push constant range [40, 56) with stageFlags = "
8279 "0x1 not within flag-matching ranges in pipeline layout"},
8280 }};
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06008281 // Setup ranges: [0,16), [20,36), [36,44), [44,52), [80,92)
Karl Schultzc81037d2016-05-12 08:11:23 -06008282 const VkPushConstantRange pc_range3[] = {
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06008283 {VK_SHADER_STAGE_VERTEX_BIT, 20, 16}, {VK_SHADER_STAGE_VERTEX_BIT, 0, 16}, {VK_SHADER_STAGE_VERTEX_BIT, 44, 8},
8284 {VK_SHADER_STAGE_VERTEX_BIT, 80, 12}, {VK_SHADER_STAGE_VERTEX_BIT, 36, 8},
Karl Schultzc81037d2016-05-12 08:11:23 -06008285 };
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008286 pipeline_layout_ci.pushConstantRangeCount = sizeof(pc_range3) / sizeof(VkPushConstantRange);
Karl Schultzc81037d2016-05-12 08:11:23 -06008287 pipeline_layout_ci.pPushConstantRanges = pc_range3;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008288 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Karl Schultzc81037d2016-05-12 08:11:23 -06008289 ASSERT_VK_SUCCESS(err);
Karl Schultzc81037d2016-05-12 08:11:23 -06008290 for (const auto &iter : cmd_overlap_tests) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008291 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, iter.msg);
8292 vkCmdPushConstants(m_commandBuffer->GetBufferHandle(), pipeline_layout, iter.range.stageFlags, iter.range.offset,
Karl Schultzc81037d2016-05-12 08:11:23 -06008293 iter.range.size, dummy_values);
8294 m_errorMonitor->VerifyFound();
8295 }
Karl Schultzc81037d2016-05-12 08:11:23 -06008296 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
8297
8298 // positive overlapping range tests with cmd
8299 const std::array<PipelineLayoutTestCase, 4> cmd_overlap_tests_pos = {{
8300 {{VK_SHADER_STAGE_VERTEX_BIT, 0, 16}, ""},
8301 {{VK_SHADER_STAGE_VERTEX_BIT, 0, 4}, ""},
8302 {{VK_SHADER_STAGE_VERTEX_BIT, 20, 12}, ""},
8303 {{VK_SHADER_STAGE_VERTEX_BIT, 56, 36}, ""},
8304 }};
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06008305 // Setup ranges: [0,16) [20,36) [36,44) [44,52) [56,80) [80,92)
Karl Schultzc81037d2016-05-12 08:11:23 -06008306 const VkPushConstantRange pc_range4[] = {
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06008307 {VK_SHADER_STAGE_VERTEX_BIT, 20, 16}, {VK_SHADER_STAGE_VERTEX_BIT, 0, 16}, {VK_SHADER_STAGE_VERTEX_BIT, 44, 8},
8308 {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 -06008309 };
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008310 pipeline_layout_ci.pushConstantRangeCount = sizeof(pc_range4) / sizeof(VkPushConstantRange);
Karl Schultzc81037d2016-05-12 08:11:23 -06008311 pipeline_layout_ci.pPushConstantRanges = pc_range4;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008312 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Karl Schultzc81037d2016-05-12 08:11:23 -06008313 ASSERT_VK_SUCCESS(err);
Karl Schultzc81037d2016-05-12 08:11:23 -06008314 for (const auto &iter : cmd_overlap_tests_pos) {
8315 m_errorMonitor->ExpectSuccess();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008316 vkCmdPushConstants(m_commandBuffer->GetBufferHandle(), pipeline_layout, iter.range.stageFlags, iter.range.offset,
Karl Schultzc81037d2016-05-12 08:11:23 -06008317 iter.range.size, dummy_values);
8318 m_errorMonitor->VerifyNotFound();
8319 }
Tobin Ehlis3a23b6a2016-02-17 10:35:18 -07008320 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06008321
8322 EndCommandBuffer();
Tobin Ehlis3a23b6a2016-02-17 10:35:18 -07008323}
8324
Karl Schultz6addd812016-02-02 17:17:23 -07008325TEST_F(VkLayerTest, DescriptorSetCompatibility) {
Tobin Ehlis559c6382015-11-05 09:52:49 -07008326 // Test various desriptorSet errors with bad binding combinations
Karl Schultz6addd812016-02-02 17:17:23 -07008327 VkResult err;
Tobin Ehlis559c6382015-11-05 09:52:49 -07008328
8329 ASSERT_NO_FATAL_FAILURE(InitState());
8330 ASSERT_NO_FATAL_FAILURE(InitViewport());
8331 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
8332
Mike Stroyanb8a61002016-06-20 16:00:28 -06008333 const VkFormat tex_format = VK_FORMAT_R8G8B8A8_UNORM;
8334 VkImageTiling tiling;
8335 VkFormatProperties format_properties;
8336 vkGetPhysicalDeviceFormatProperties(gpu(), tex_format, &format_properties);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008337 if (format_properties.linearTilingFeatures & VK_FORMAT_FEATURE_STORAGE_IMAGE_BIT) {
Mike Stroyanb8a61002016-06-20 16:00:28 -06008338 tiling = VK_IMAGE_TILING_LINEAR;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008339 } else if (format_properties.optimalTilingFeatures & VK_FORMAT_FEATURE_STORAGE_IMAGE_BIT) {
Mike Stroyanb8a61002016-06-20 16:00:28 -06008340 tiling = VK_IMAGE_TILING_OPTIMAL;
8341 } else {
8342 printf("Device does not support VK_FORMAT_FEATURE_STORAGE_IMAGE_BIT; "
8343 "skipped.\n");
8344 return;
8345 }
8346
Tobin Ehlis559c6382015-11-05 09:52:49 -07008347 static const uint32_t NUM_DESCRIPTOR_TYPES = 5;
8348 VkDescriptorPoolSize ds_type_count[NUM_DESCRIPTOR_TYPES] = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008349 ds_type_count[0].type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
8350 ds_type_count[0].descriptorCount = 10;
8351 ds_type_count[1].type = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE;
8352 ds_type_count[1].descriptorCount = 2;
8353 ds_type_count[2].type = VK_DESCRIPTOR_TYPE_STORAGE_IMAGE;
8354 ds_type_count[2].descriptorCount = 2;
8355 ds_type_count[3].type = VK_DESCRIPTOR_TYPE_SAMPLER;
8356 ds_type_count[3].descriptorCount = 5;
8357 // TODO : LunarG ILO driver currently asserts in desc.c w/ INPUT_ATTACHMENT
8358 // type
8359 // ds_type_count[4].type = VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT;
8360 ds_type_count[4].type = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
8361 ds_type_count[4].descriptorCount = 2;
Tobin Ehlis559c6382015-11-05 09:52:49 -07008362
8363 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008364 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
8365 ds_pool_ci.pNext = NULL;
8366 ds_pool_ci.maxSets = 5;
8367 ds_pool_ci.poolSizeCount = NUM_DESCRIPTOR_TYPES;
8368 ds_pool_ci.pPoolSizes = ds_type_count;
Tobin Ehlis559c6382015-11-05 09:52:49 -07008369
8370 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008371 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis559c6382015-11-05 09:52:49 -07008372 ASSERT_VK_SUCCESS(err);
8373
8374 static const uint32_t MAX_DS_TYPES_IN_LAYOUT = 2;
8375 VkDescriptorSetLayoutBinding dsl_binding[MAX_DS_TYPES_IN_LAYOUT] = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008376 dsl_binding[0].binding = 0;
8377 dsl_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
8378 dsl_binding[0].descriptorCount = 5;
8379 dsl_binding[0].stageFlags = VK_SHADER_STAGE_ALL;
8380 dsl_binding[0].pImmutableSamplers = NULL;
Tobin Ehlis559c6382015-11-05 09:52:49 -07008381
Tobin Ehlis8fab6562015-12-01 09:57:09 -07008382 // Create layout identical to set0 layout but w/ different stageFlags
8383 VkDescriptorSetLayoutBinding dsl_fs_stage_only = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008384 dsl_fs_stage_only.binding = 0;
8385 dsl_fs_stage_only.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
8386 dsl_fs_stage_only.descriptorCount = 5;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008387 dsl_fs_stage_only.stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT; // Different stageFlags to cause error at
8388 // bind time
Karl Schultz6addd812016-02-02 17:17:23 -07008389 dsl_fs_stage_only.pImmutableSamplers = NULL;
Tobin Ehlis559c6382015-11-05 09:52:49 -07008390 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008391 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
8392 ds_layout_ci.pNext = NULL;
8393 ds_layout_ci.bindingCount = 1;
8394 ds_layout_ci.pBindings = dsl_binding;
Tobin Ehlis559c6382015-11-05 09:52:49 -07008395 static const uint32_t NUM_LAYOUTS = 4;
8396 VkDescriptorSetLayout ds_layout[NUM_LAYOUTS] = {};
Tobin Ehlis8fab6562015-12-01 09:57:09 -07008397 VkDescriptorSetLayout ds_layout_fs_only = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008398 // Create 4 unique layouts for full pipelineLayout, and 1 special fs-only
8399 // layout for error case
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008400 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout[0]);
Tobin Ehlis559c6382015-11-05 09:52:49 -07008401 ASSERT_VK_SUCCESS(err);
Jon Ashburn6e23c1f2015-12-30 18:01:16 -07008402 ds_layout_ci.pBindings = &dsl_fs_stage_only;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008403 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout_fs_only);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07008404 ASSERT_VK_SUCCESS(err);
Tobin Ehlis559c6382015-11-05 09:52:49 -07008405 dsl_binding[0].binding = 0;
8406 dsl_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE;
Tobin Ehlis8fab6562015-12-01 09:57:09 -07008407 dsl_binding[0].descriptorCount = 2;
Mike Stroyan9c70cdb2016-01-06 14:14:17 -07008408 dsl_binding[1].binding = 1;
8409 dsl_binding[1].descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_IMAGE;
8410 dsl_binding[1].descriptorCount = 2;
8411 dsl_binding[1].stageFlags = VK_SHADER_STAGE_ALL;
8412 dsl_binding[1].pImmutableSamplers = NULL;
Jon Ashburn6e23c1f2015-12-30 18:01:16 -07008413 ds_layout_ci.pBindings = dsl_binding;
Tobin Ehlis559c6382015-11-05 09:52:49 -07008414 ds_layout_ci.bindingCount = 2;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008415 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout[1]);
Tobin Ehlis559c6382015-11-05 09:52:49 -07008416 ASSERT_VK_SUCCESS(err);
8417 dsl_binding[0].binding = 0;
8418 dsl_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
Tobin Ehlis8fab6562015-12-01 09:57:09 -07008419 dsl_binding[0].descriptorCount = 5;
Tobin Ehlis559c6382015-11-05 09:52:49 -07008420 ds_layout_ci.bindingCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008421 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout[2]);
Tobin Ehlis559c6382015-11-05 09:52:49 -07008422 ASSERT_VK_SUCCESS(err);
8423 dsl_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
Tobin Ehlis8fab6562015-12-01 09:57:09 -07008424 dsl_binding[0].descriptorCount = 2;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008425 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout[3]);
Tobin Ehlis559c6382015-11-05 09:52:49 -07008426 ASSERT_VK_SUCCESS(err);
8427
8428 static const uint32_t NUM_SETS = 4;
8429 VkDescriptorSet descriptorSet[NUM_SETS] = {};
8430 VkDescriptorSetAllocateInfo alloc_info = {};
Tobin Ehlis8fab6562015-12-01 09:57:09 -07008431 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07008432 alloc_info.descriptorSetCount = NUM_LAYOUTS;
Tobin Ehlis559c6382015-11-05 09:52:49 -07008433 alloc_info.descriptorPool = ds_pool;
8434 alloc_info.pSetLayouts = ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008435 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, descriptorSet);
Tobin Ehlis559c6382015-11-05 09:52:49 -07008436 ASSERT_VK_SUCCESS(err);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07008437 VkDescriptorSet ds0_fs_only = {};
Jon Ashburnf19916e2016-01-11 13:12:43 -07008438 alloc_info.descriptorSetCount = 1;
Tobin Ehlis8fab6562015-12-01 09:57:09 -07008439 alloc_info.pSetLayouts = &ds_layout_fs_only;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008440 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &ds0_fs_only);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07008441 ASSERT_VK_SUCCESS(err);
Tobin Ehlis559c6382015-11-05 09:52:49 -07008442
8443 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008444 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
8445 pipeline_layout_ci.pNext = NULL;
8446 pipeline_layout_ci.setLayoutCount = NUM_LAYOUTS;
8447 pipeline_layout_ci.pSetLayouts = ds_layout;
Tobin Ehlis559c6382015-11-05 09:52:49 -07008448
8449 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008450 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis559c6382015-11-05 09:52:49 -07008451 ASSERT_VK_SUCCESS(err);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07008452 // Create pipelineLayout with only one setLayout
8453 pipeline_layout_ci.setLayoutCount = 1;
8454 VkPipelineLayout single_pipe_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008455 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &single_pipe_layout);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07008456 ASSERT_VK_SUCCESS(err);
8457 // Create pipelineLayout with 2 descriptor setLayout at index 0
8458 pipeline_layout_ci.pSetLayouts = &ds_layout[3];
8459 VkPipelineLayout pipe_layout_one_desc;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008460 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipe_layout_one_desc);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07008461 ASSERT_VK_SUCCESS(err);
8462 // Create pipelineLayout with 5 SAMPLER descriptor setLayout at index 0
8463 pipeline_layout_ci.pSetLayouts = &ds_layout[2];
8464 VkPipelineLayout pipe_layout_five_samp;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008465 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipe_layout_five_samp);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07008466 ASSERT_VK_SUCCESS(err);
8467 // Create pipelineLayout with UB type, but stageFlags for FS only
8468 pipeline_layout_ci.pSetLayouts = &ds_layout_fs_only;
8469 VkPipelineLayout pipe_layout_fs_only;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008470 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipe_layout_fs_only);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07008471 ASSERT_VK_SUCCESS(err);
8472 // Create pipelineLayout w/ incompatible set0 layout, but set1 is fine
8473 VkDescriptorSetLayout pl_bad_s0[2] = {};
8474 pl_bad_s0[0] = ds_layout_fs_only;
8475 pl_bad_s0[1] = ds_layout[1];
8476 pipeline_layout_ci.setLayoutCount = 2;
8477 pipeline_layout_ci.pSetLayouts = pl_bad_s0;
8478 VkPipelineLayout pipe_layout_bad_set0;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008479 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipe_layout_bad_set0);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07008480 ASSERT_VK_SUCCESS(err);
Tobin Ehlis559c6382015-11-05 09:52:49 -07008481
8482 // Create a buffer to update the descriptor with
8483 uint32_t qfi = 0;
8484 VkBufferCreateInfo buffCI = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008485 buffCI.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
8486 buffCI.size = 1024;
8487 buffCI.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
8488 buffCI.queueFamilyIndexCount = 1;
8489 buffCI.pQueueFamilyIndices = &qfi;
Tobin Ehlis559c6382015-11-05 09:52:49 -07008490
8491 VkBuffer dyub;
8492 err = vkCreateBuffer(m_device->device(), &buffCI, NULL, &dyub);
8493 ASSERT_VK_SUCCESS(err);
8494 // Correctly update descriptor to avoid "NOT_UPDATED" error
8495 static const uint32_t NUM_BUFFS = 5;
8496 VkDescriptorBufferInfo buffInfo[NUM_BUFFS] = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008497 for (uint32_t i = 0; i < NUM_BUFFS; ++i) {
Tobin Ehlis559c6382015-11-05 09:52:49 -07008498 buffInfo[i].buffer = dyub;
8499 buffInfo[i].offset = 0;
8500 buffInfo[i].range = 1024;
8501 }
Karl Schultz6addd812016-02-02 17:17:23 -07008502 VkImage image;
Karl Schultz6addd812016-02-02 17:17:23 -07008503 const int32_t tex_width = 32;
8504 const int32_t tex_height = 32;
Tobin Ehlis8fab6562015-12-01 09:57:09 -07008505 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008506 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
8507 image_create_info.pNext = NULL;
8508 image_create_info.imageType = VK_IMAGE_TYPE_2D;
8509 image_create_info.format = tex_format;
8510 image_create_info.extent.width = tex_width;
8511 image_create_info.extent.height = tex_height;
8512 image_create_info.extent.depth = 1;
8513 image_create_info.mipLevels = 1;
8514 image_create_info.arrayLayers = 1;
8515 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
Mike Stroyanb8a61002016-06-20 16:00:28 -06008516 image_create_info.tiling = tiling;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008517 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT | VK_IMAGE_USAGE_STORAGE_BIT;
Karl Schultz6addd812016-02-02 17:17:23 -07008518 image_create_info.flags = 0;
Tobin Ehlis8fab6562015-12-01 09:57:09 -07008519 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
8520 ASSERT_VK_SUCCESS(err);
Tobin Ehlis559c6382015-11-05 09:52:49 -07008521
Karl Schultz6addd812016-02-02 17:17:23 -07008522 VkMemoryRequirements memReqs;
8523 VkDeviceMemory imageMem;
8524 bool pass;
Mike Stroyan9c70cdb2016-01-06 14:14:17 -07008525 VkMemoryAllocateInfo memAlloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008526 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
8527 memAlloc.pNext = NULL;
8528 memAlloc.allocationSize = 0;
8529 memAlloc.memoryTypeIndex = 0;
Mike Stroyan9c70cdb2016-01-06 14:14:17 -07008530 vkGetImageMemoryRequirements(m_device->device(), image, &memReqs);
8531 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008532 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Mike Stroyan9c70cdb2016-01-06 14:14:17 -07008533 ASSERT_TRUE(pass);
8534 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &imageMem);
8535 ASSERT_VK_SUCCESS(err);
8536 err = vkBindImageMemory(m_device->device(), image, imageMem, 0);
8537 ASSERT_VK_SUCCESS(err);
8538
Tobin Ehlis8fab6562015-12-01 09:57:09 -07008539 VkImageViewCreateInfo image_view_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008540 image_view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
8541 image_view_create_info.image = image;
8542 image_view_create_info.viewType = VK_IMAGE_VIEW_TYPE_2D;
8543 image_view_create_info.format = tex_format;
8544 image_view_create_info.subresourceRange.layerCount = 1;
8545 image_view_create_info.subresourceRange.baseMipLevel = 0;
8546 image_view_create_info.subresourceRange.levelCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008547 image_view_create_info.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Tobin Ehlis559c6382015-11-05 09:52:49 -07008548
Tobin Ehlis8fab6562015-12-01 09:57:09 -07008549 VkImageView view;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008550 err = vkCreateImageView(m_device->device(), &image_view_create_info, NULL, &view);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07008551 ASSERT_VK_SUCCESS(err);
Tobin Ehlis991d45a2016-01-06 08:48:41 -07008552 VkDescriptorImageInfo imageInfo[4] = {};
Tobin Ehlis8fab6562015-12-01 09:57:09 -07008553 imageInfo[0].imageView = view;
8554 imageInfo[0].imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
8555 imageInfo[1].imageView = view;
8556 imageInfo[1].imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
Tobin Ehlis991d45a2016-01-06 08:48:41 -07008557 imageInfo[2].imageView = view;
8558 imageInfo[2].imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
8559 imageInfo[3].imageView = view;
8560 imageInfo[3].imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
Tobin Ehlis8fab6562015-12-01 09:57:09 -07008561
8562 static const uint32_t NUM_SET_UPDATES = 3;
8563 VkWriteDescriptorSet descriptor_write[NUM_SET_UPDATES] = {};
8564 descriptor_write[0].sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
8565 descriptor_write[0].dstSet = descriptorSet[0];
8566 descriptor_write[0].dstBinding = 0;
8567 descriptor_write[0].descriptorCount = 5;
8568 descriptor_write[0].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
8569 descriptor_write[0].pBufferInfo = buffInfo;
8570 descriptor_write[1].sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
8571 descriptor_write[1].dstSet = descriptorSet[1];
8572 descriptor_write[1].dstBinding = 0;
8573 descriptor_write[1].descriptorCount = 2;
8574 descriptor_write[1].descriptorType = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE;
8575 descriptor_write[1].pImageInfo = imageInfo;
8576 descriptor_write[2].sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
8577 descriptor_write[2].dstSet = descriptorSet[1];
8578 descriptor_write[2].dstBinding = 1;
8579 descriptor_write[2].descriptorCount = 2;
8580 descriptor_write[2].descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_IMAGE;
Tobin Ehlis991d45a2016-01-06 08:48:41 -07008581 descriptor_write[2].pImageInfo = &imageInfo[2];
Tobin Ehlis8fab6562015-12-01 09:57:09 -07008582
8583 vkUpdateDescriptorSets(m_device->device(), 3, descriptor_write, 0, NULL);
Tobin Ehlis559c6382015-11-05 09:52:49 -07008584
Tobin Ehlis88452832015-12-03 09:40:56 -07008585 // Create PSO to be used for draw-time errors below
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008586 char const *vsSource = "#version 450\n"
8587 "\n"
8588 "out gl_PerVertex {\n"
8589 " vec4 gl_Position;\n"
8590 "};\n"
8591 "void main(){\n"
8592 " gl_Position = vec4(1);\n"
8593 "}\n";
8594 char const *fsSource = "#version 450\n"
8595 "\n"
8596 "layout(location=0) out vec4 x;\n"
8597 "layout(set=0) layout(binding=0) uniform foo { int x; int y; } bar;\n"
8598 "void main(){\n"
8599 " x = vec4(bar.y);\n"
8600 "}\n";
Tobin Ehlis88452832015-12-03 09:40:56 -07008601 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
8602 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Tobin Ehlis559c6382015-11-05 09:52:49 -07008603 VkPipelineObj pipe(m_device);
8604 pipe.AddShader(&vs);
8605 pipe.AddShader(&fs);
Tobin Ehlis88452832015-12-03 09:40:56 -07008606 pipe.AddColorAttachment();
8607 pipe.CreateVKPipeline(pipe_layout_fs_only, renderPass());
Tobin Ehlis559c6382015-11-05 09:52:49 -07008608
8609 BeginCommandBuffer();
Tobin Ehlis88452832015-12-03 09:40:56 -07008610
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008611 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Karl Schultz6addd812016-02-02 17:17:23 -07008612 // NOTE : I believe LunarG ilo driver has bug (LX#189) that requires binding
8613 // of PSO
8614 // here before binding DSs. Otherwise we assert in cmd_copy_dset_data() of
8615 // cmd_pipeline.c
8616 // due to the fact that cmd_alloc_dset_data() has not been called in
8617 // cmd_bind_graphics_pipeline()
8618 // TODO : Want to cause various binding incompatibility issues here to test
8619 // DrawState
Tobin Ehlis559c6382015-11-05 09:52:49 -07008620 // First cause various verify_layout_compatibility() fails
8621 // Second disturb early and late sets and verify INFO msgs
Tobin Ehlis8fab6562015-12-01 09:57:09 -07008622 // verify_set_layout_compatibility fail cases:
8623 // 1. invalid VkPipelineLayout (layout) passed into vkCmdBindDescriptorSets
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008624 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Invalid Pipeline Layout Object ");
8625 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS,
8626 (VkPipelineLayout)((size_t)0xbaadb1be), 0, 1, &descriptorSet[0], 0, NULL);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008627 m_errorMonitor->VerifyFound();
8628
Tobin Ehlis8fab6562015-12-01 09:57:09 -07008629 // 2. layoutIndex exceeds # of layouts in layout
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008630 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " attempting to bind set to index 1");
8631 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, single_pipe_layout, 0, 2,
8632 &descriptorSet[0], 0, NULL);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008633 m_errorMonitor->VerifyFound();
8634
Tobin Ehlis8fab6562015-12-01 09:57:09 -07008635 vkDestroyPipelineLayout(m_device->device(), single_pipe_layout, NULL);
Karl Schultz6addd812016-02-02 17:17:23 -07008636 // 3. Pipeline setLayout[0] has 2 descriptors, but set being bound has 5
8637 // descriptors
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008638 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " has 2 descriptors, but DescriptorSetLayout ");
8639 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe_layout_one_desc, 0, 1,
8640 &descriptorSet[0], 0, NULL);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008641 m_errorMonitor->VerifyFound();
8642
Tobin Ehlis8fab6562015-12-01 09:57:09 -07008643 vkDestroyPipelineLayout(m_device->device(), pipe_layout_one_desc, NULL);
8644 // 4. same # of descriptors but mismatch in type
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008645 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " is type 'VK_DESCRIPTOR_TYPE_SAMPLER' but binding ");
8646 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe_layout_five_samp, 0, 1,
8647 &descriptorSet[0], 0, NULL);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008648 m_errorMonitor->VerifyFound();
8649
Tobin Ehlis8fab6562015-12-01 09:57:09 -07008650 vkDestroyPipelineLayout(m_device->device(), pipe_layout_five_samp, NULL);
8651 // 5. same # of descriptors but mismatch in stageFlags
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008652 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
8653 " has stageFlags 16 but binding 0 for DescriptorSetLayout ");
8654 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe_layout_fs_only, 0, 1,
8655 &descriptorSet[0], 0, NULL);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008656 m_errorMonitor->VerifyFound();
8657
Tobin Ehlis8fab6562015-12-01 09:57:09 -07008658 // Cause INFO messages due to disturbing previously bound Sets
8659 // First bind sets 0 & 1
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008660 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 2,
8661 &descriptorSet[0], 0, NULL);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07008662 // 1. Disturb bound set0 by re-binding set1 w/ updated pipelineLayout
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008663 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT, " previously bound as set #0 was disturbed ");
8664 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe_layout_bad_set0, 1, 1,
8665 &descriptorSet[1], 0, NULL);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008666 m_errorMonitor->VerifyFound();
8667
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008668 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 2,
8669 &descriptorSet[0], 0, NULL);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07008670 // 2. Disturb set after last bound set
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008671 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT, " newly bound as set #0 so set #1 and "
8672 "any subsequent sets were disturbed ");
8673 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe_layout_fs_only, 0, 1,
8674 &ds0_fs_only, 0, NULL);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008675 m_errorMonitor->VerifyFound();
8676
Tobin Ehlis10fad692016-07-07 12:00:36 -06008677 // Now that we're done actively using the pipelineLayout that gfx pipeline
8678 // was created with, we should be able to delete it. Do that now to verify
8679 // that validation obeys pipelineLayout lifetime
8680 vkDestroyPipelineLayout(m_device->device(), pipe_layout_fs_only, NULL);
8681
Tobin Ehlis88452832015-12-03 09:40:56 -07008682 // Cause draw-time errors due to PSO incompatibilities
Karl Schultz6addd812016-02-02 17:17:23 -07008683 // 1. Error due to not binding required set (we actually use same code as
8684 // above to disturb set0)
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008685 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 2,
8686 &descriptorSet[0], 0, NULL);
8687 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe_layout_bad_set0, 1, 1,
8688 &descriptorSet[1], 0, NULL);
8689 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 -07008690 Draw(1, 0, 0, 0);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008691 m_errorMonitor->VerifyFound();
8692
Tobin Ehlis991d45a2016-01-06 08:48:41 -07008693 vkDestroyPipelineLayout(m_device->device(), pipe_layout_bad_set0, NULL);
Karl Schultz6addd812016-02-02 17:17:23 -07008694 // 2. Error due to bound set not being compatible with PSO's
8695 // VkPipelineLayout (diff stageFlags in this case)
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008696 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 2,
8697 &descriptorSet[0], 0, NULL);
8698 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " bound as set #0 is not compatible with ");
Tobin Ehlis88452832015-12-03 09:40:56 -07008699 Draw(1, 0, 0, 0);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008700 m_errorMonitor->VerifyFound();
8701
Tobin Ehlis8fab6562015-12-01 09:57:09 -07008702 // Remaining clean-up
Karl Schultz6addd812016-02-02 17:17:23 -07008703 for (uint32_t i = 0; i < NUM_LAYOUTS; ++i) {
Tobin Ehlis8fab6562015-12-01 09:57:09 -07008704 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout[i], NULL);
8705 }
8706 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout_fs_only, NULL);
Tobin Ehlis9bfd4492016-05-05 15:09:11 -06008707 vkFreeDescriptorSets(m_device->device(), ds_pool, 1, &ds0_fs_only);
8708 vkFreeDescriptorSets(m_device->device(), ds_pool, NUM_SETS, descriptorSet);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07008709 vkDestroyBuffer(m_device->device(), dyub, NULL);
Tobin Ehlis559c6382015-11-05 09:52:49 -07008710 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
8711 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tony Barbourdf4c0042016-06-01 15:55:43 -06008712 vkFreeMemory(m_device->device(), imageMem, NULL);
8713 vkDestroyImage(m_device->device(), image, NULL);
8714 vkDestroyImageView(m_device->device(), view, NULL);
Tobin Ehlis559c6382015-11-05 09:52:49 -07008715}
Tobin Ehlis559c6382015-11-05 09:52:49 -07008716
Karl Schultz6addd812016-02-02 17:17:23 -07008717TEST_F(VkLayerTest, NoBeginCommandBuffer) {
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06008718
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008719 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
8720 "You must call vkBeginCommandBuffer() before this call to ");
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06008721
8722 ASSERT_NO_FATAL_FAILURE(InitState());
Chia-I Wu3432a0c2015-10-27 18:04:07 +08008723 VkCommandBufferObj commandBuffer(m_device, m_commandPool);
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06008724 // Call EndCommandBuffer() w/o calling BeginCommandBuffer()
Chia-I Wu3432a0c2015-10-27 18:04:07 +08008725 vkEndCommandBuffer(commandBuffer.GetBufferHandle());
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06008726
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008727 m_errorMonitor->VerifyFound();
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06008728}
8729
Karl Schultz6addd812016-02-02 17:17:23 -07008730TEST_F(VkLayerTest, SecondaryCommandBufferNullRenderpass) {
8731 VkResult err;
8732 VkCommandBuffer draw_cmd;
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06008733
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008734 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " must specify a valid renderpass parameter.");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06008735
Mark Lobodzinskid9139a62015-08-04 16:24:20 -06008736 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinskid9139a62015-08-04 16:24:20 -06008737
Chia-I Wu3432a0c2015-10-27 18:04:07 +08008738 VkCommandBufferAllocateInfo cmd = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08008739 cmd.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
Cody Northropb4569702015-08-04 17:35:57 -06008740 cmd.pNext = NULL;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08008741 cmd.commandPool = m_commandPool;
8742 cmd.level = VK_COMMAND_BUFFER_LEVEL_SECONDARY;
Jon Ashburnf19916e2016-01-11 13:12:43 -07008743 cmd.commandBufferCount = 1;
Cody Northropb4569702015-08-04 17:35:57 -06008744
Chia-I Wu3432a0c2015-10-27 18:04:07 +08008745 err = vkAllocateCommandBuffers(m_device->device(), &cmd, &draw_cmd);
Mike Stroyand1c84a52015-08-18 14:40:24 -06008746 ASSERT_VK_SUCCESS(err);
Mark Lobodzinskid9139a62015-08-04 16:24:20 -06008747
8748 // Force the failure by not setting the Renderpass and Framebuffer fields
Chia-I Wu3432a0c2015-10-27 18:04:07 +08008749 VkCommandBufferBeginInfo cmd_buf_info = {};
Jon Ashburnf19916e2016-01-11 13:12:43 -07008750 VkCommandBufferInheritanceInfo cmd_buf_hinfo = {};
Chia-I Wu3432a0c2015-10-27 18:04:07 +08008751 cmd_buf_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
Cody Northropb4569702015-08-04 17:35:57 -06008752 cmd_buf_info.pNext = NULL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008753 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 -07008754 cmd_buf_info.pInheritanceInfo = &cmd_buf_hinfo;
Mark Lobodzinskid9139a62015-08-04 16:24:20 -06008755
8756 // The error should be caught by validation of the BeginCommandBuffer call
8757 vkBeginCommandBuffer(draw_cmd, &cmd_buf_info);
8758
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008759 m_errorMonitor->VerifyFound();
Chia-I Wu3432a0c2015-10-27 18:04:07 +08008760 vkFreeCommandBuffers(m_device->device(), m_commandPool, 1, &draw_cmd);
Mark Lobodzinskid9139a62015-08-04 16:24:20 -06008761}
8762
Karl Schultz6addd812016-02-02 17:17:23 -07008763TEST_F(VkLayerTest, CommandBufferResetErrors) {
Tobin Ehlisac0ef842015-12-14 13:46:38 -07008764 // Cause error due to Begin while recording CB
8765 // Then cause 2 errors for attempting to reset CB w/o having
8766 // VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT set for the pool from
8767 // which CBs were allocated. Note that this bit is off by default.
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008768 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Cannot call Begin on CB");
Tobin Ehlisac0ef842015-12-14 13:46:38 -07008769
8770 ASSERT_NO_FATAL_FAILURE(InitState());
8771
8772 // Calls AllocateCommandBuffers
8773 VkCommandBufferObj commandBuffer(m_device, m_commandPool);
8774
Karl Schultz6addd812016-02-02 17:17:23 -07008775 // Force the failure by setting the Renderpass and Framebuffer fields with
8776 // (fake) data
Tobin Ehlisac0ef842015-12-14 13:46:38 -07008777 VkCommandBufferBeginInfo cmd_buf_info = {};
Jon Ashburnf19916e2016-01-11 13:12:43 -07008778 VkCommandBufferInheritanceInfo cmd_buf_hinfo = {};
Tobin Ehlisac0ef842015-12-14 13:46:38 -07008779 cmd_buf_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
8780 cmd_buf_info.pNext = NULL;
8781 cmd_buf_info.flags = VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT;
Jon Ashburnf19916e2016-01-11 13:12:43 -07008782 cmd_buf_info.pInheritanceInfo = &cmd_buf_hinfo;
Tobin Ehlisac0ef842015-12-14 13:46:38 -07008783
8784 // Begin CB to transition to recording state
8785 vkBeginCommandBuffer(commandBuffer.GetBufferHandle(), &cmd_buf_info);
8786 // Can't re-begin. This should trigger error
8787 vkBeginCommandBuffer(commandBuffer.GetBufferHandle(), &cmd_buf_info);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008788 m_errorMonitor->VerifyFound();
8789
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008790 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Attempt to reset command buffer ");
Tobin Ehlisac0ef842015-12-14 13:46:38 -07008791 VkCommandBufferResetFlags flags = 0; // Don't care about flags for this test
8792 // Reset attempt will trigger error due to incorrect CommandPool state
8793 vkResetCommandBuffer(commandBuffer.GetBufferHandle(), flags);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008794 m_errorMonitor->VerifyFound();
8795
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008796 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " attempts to implicitly reset cmdBuffer created from ");
Tobin Ehlisac0ef842015-12-14 13:46:38 -07008797 // Transition CB to RECORDED state
8798 vkEndCommandBuffer(commandBuffer.GetBufferHandle());
8799 // Now attempting to Begin will implicitly reset, which triggers error
8800 vkBeginCommandBuffer(commandBuffer.GetBufferHandle(), &cmd_buf_info);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008801 m_errorMonitor->VerifyFound();
Tobin Ehlisac0ef842015-12-14 13:46:38 -07008802}
8803
Karl Schultz6addd812016-02-02 17:17:23 -07008804TEST_F(VkLayerTest, InvalidPipelineCreateState) {
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06008805 // Attempt to Create Gfx Pipeline w/o a VS
Karl Schultz6addd812016-02-02 17:17:23 -07008806 VkResult err;
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06008807
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008808 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Invalid Pipeline CreateInfo State: Vtx Shader required");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06008809
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06008810 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06008811 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Mark Lobodzinski209b5292015-09-17 09:44:05 -06008812
Chia-I Wu1b99bb22015-10-27 19:25:11 +08008813 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008814 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
8815 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -06008816
8817 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008818 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
8819 ds_pool_ci.pNext = NULL;
8820 ds_pool_ci.maxSets = 1;
8821 ds_pool_ci.poolSizeCount = 1;
8822 ds_pool_ci.pPoolSizes = &ds_type_count;
Mark Lobodzinski209b5292015-09-17 09:44:05 -06008823
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06008824 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008825 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06008826 ASSERT_VK_SUCCESS(err);
8827
Tony Barboureb254902015-07-15 12:50:33 -06008828 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008829 dsl_binding.binding = 0;
8830 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
8831 dsl_binding.descriptorCount = 1;
8832 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
8833 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06008834
Tony Barboureb254902015-07-15 12:50:33 -06008835 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008836 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
8837 ds_layout_ci.pNext = NULL;
8838 ds_layout_ci.bindingCount = 1;
8839 ds_layout_ci.pBindings = &dsl_binding;
Tony Barboureb254902015-07-15 12:50:33 -06008840
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06008841 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008842 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06008843 ASSERT_VK_SUCCESS(err);
8844
8845 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08008846 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08008847 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07008848 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06008849 alloc_info.descriptorPool = ds_pool;
8850 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008851 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06008852 ASSERT_VK_SUCCESS(err);
8853
Tony Barboureb254902015-07-15 12:50:33 -06008854 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008855 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
8856 pipeline_layout_ci.setLayoutCount = 1;
8857 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06008858
8859 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008860 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06008861 ASSERT_VK_SUCCESS(err);
8862
Tobin Ehlise68360f2015-10-01 11:15:13 -06008863 VkViewport vp = {}; // Just need dummy vp to point to
Karl Schultz6addd812016-02-02 17:17:23 -07008864 VkRect2D sc = {}; // dummy scissor to point to
Tobin Ehlise68360f2015-10-01 11:15:13 -06008865
8866 VkPipelineViewportStateCreateInfo vp_state_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008867 vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
8868 vp_state_ci.scissorCount = 1;
8869 vp_state_ci.pScissors = &sc;
8870 vp_state_ci.viewportCount = 1;
8871 vp_state_ci.pViewports = &vp;
Tobin Ehlise68360f2015-10-01 11:15:13 -06008872
Karl Schultzdfdb8d42016-03-08 10:30:21 -07008873 VkPipelineRasterizationStateCreateInfo rs_state_ci = {};
8874 rs_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
8875 rs_state_ci.polygonMode = VK_POLYGON_MODE_FILL;
8876 rs_state_ci.cullMode = VK_CULL_MODE_BACK_BIT;
8877 rs_state_ci.frontFace = VK_FRONT_FACE_COUNTER_CLOCKWISE;
8878 rs_state_ci.depthClampEnable = VK_FALSE;
8879 rs_state_ci.rasterizerDiscardEnable = VK_FALSE;
8880 rs_state_ci.depthBiasEnable = VK_FALSE;
8881
Tony Barboureb254902015-07-15 12:50:33 -06008882 VkGraphicsPipelineCreateInfo gp_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008883 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
8884 gp_ci.pViewportState = &vp_state_ci;
Karl Schultzdfdb8d42016-03-08 10:30:21 -07008885 gp_ci.pRasterizationState = &rs_state_ci;
Karl Schultz6addd812016-02-02 17:17:23 -07008886 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
8887 gp_ci.layout = pipeline_layout;
8888 gp_ci.renderPass = renderPass();
Tony Barboureb254902015-07-15 12:50:33 -06008889
8890 VkPipelineCacheCreateInfo pc_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008891 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
8892 pc_ci.initialDataSize = 0;
8893 pc_ci.pInitialData = 0;
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06008894
8895 VkPipeline pipeline;
Jon Ashburnc669cc62015-07-09 15:02:25 -06008896 VkPipelineCache pipelineCache;
8897
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008898 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Jon Ashburnc669cc62015-07-09 15:02:25 -06008899 ASSERT_VK_SUCCESS(err);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008900 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06008901
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008902 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06008903
Chia-I Wuf7458c52015-10-26 21:10:41 +08008904 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
8905 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
8906 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
8907 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06008908}
Tobin Ehlis912df022015-09-17 08:46:18 -06008909/*// TODO : This test should be good, but needs Tess support in compiler to run
8910TEST_F(VkLayerTest, InvalidPatchControlPoints)
8911{
8912 // Attempt to Create Gfx Pipeline w/o a VS
Tobin Ehlis912df022015-09-17 08:46:18 -06008913 VkResult err;
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06008914
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07008915 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Karl Schultz6addd812016-02-02 17:17:23 -07008916 "Invalid Pipeline CreateInfo State: VK_PRIMITIVE_TOPOLOGY_PATCH
8917primitive ");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06008918
Tobin Ehlis912df022015-09-17 08:46:18 -06008919 ASSERT_NO_FATAL_FAILURE(InitState());
8920 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlis912df022015-09-17 08:46:18 -06008921
Chia-I Wu1b99bb22015-10-27 19:25:11 +08008922 VkDescriptorPoolSize ds_type_count = {};
Tobin Ehlis912df022015-09-17 08:46:18 -06008923 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Chia-I Wud50a7d72015-10-26 20:48:51 +08008924 ds_type_count.descriptorCount = 1;
Tobin Ehlis912df022015-09-17 08:46:18 -06008925
8926 VkDescriptorPoolCreateInfo ds_pool_ci = {};
8927 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
8928 ds_pool_ci.pNext = NULL;
Chia-I Wu1b99bb22015-10-27 19:25:11 +08008929 ds_pool_ci.poolSizeCount = 1;
8930 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlis912df022015-09-17 08:46:18 -06008931
8932 VkDescriptorPool ds_pool;
Karl Schultz6addd812016-02-02 17:17:23 -07008933 err = vkCreateDescriptorPool(m_device->device(),
8934VK_DESCRIPTOR_POOL_USAGE_NON_FREE, 1, &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis912df022015-09-17 08:46:18 -06008935 ASSERT_VK_SUCCESS(err);
8936
8937 VkDescriptorSetLayoutBinding dsl_binding = {};
Chia-I Wud46e6ae2015-10-31 00:31:16 +08008938 dsl_binding.binding = 0;
Tobin Ehlis912df022015-09-17 08:46:18 -06008939 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Chia-I Wu02124482015-11-06 06:42:02 +08008940 dsl_binding.descriptorCount = 1;
Tobin Ehlis912df022015-09-17 08:46:18 -06008941 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
8942 dsl_binding.pImmutableSamplers = NULL;
8943
8944 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008945 ds_layout_ci.sType =
8946VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
Tobin Ehlis912df022015-09-17 08:46:18 -06008947 ds_layout_ci.pNext = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08008948 ds_layout_ci.bindingCount = 1;
Jon Ashburn6e23c1f2015-12-30 18:01:16 -07008949 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlis912df022015-09-17 08:46:18 -06008950
8951 VkDescriptorSetLayout ds_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07008952 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL,
8953&ds_layout);
Tobin Ehlis912df022015-09-17 08:46:18 -06008954 ASSERT_VK_SUCCESS(err);
8955
8956 VkDescriptorSet descriptorSet;
Karl Schultz6addd812016-02-02 17:17:23 -07008957 err = vkAllocateDescriptorSets(m_device->device(), ds_pool,
8958VK_DESCRIPTOR_SET_USAGE_NON_FREE, 1, &ds_layout, &descriptorSet);
Tobin Ehlis912df022015-09-17 08:46:18 -06008959 ASSERT_VK_SUCCESS(err);
8960
8961 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008962 pipeline_layout_ci.sType =
8963VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
Tobin Ehlis912df022015-09-17 08:46:18 -06008964 pipeline_layout_ci.pNext = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08008965 pipeline_layout_ci.setLayoutCount = 1;
Tobin Ehlis912df022015-09-17 08:46:18 -06008966 pipeline_layout_ci.pSetLayouts = &ds_layout;
8967
8968 VkPipelineLayout pipeline_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07008969 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL,
8970&pipeline_layout);
Tobin Ehlis912df022015-09-17 08:46:18 -06008971 ASSERT_VK_SUCCESS(err);
8972
8973 VkPipelineShaderStageCreateInfo shaderStages[3];
8974 memset(&shaderStages, 0, 3 * sizeof(VkPipelineShaderStageCreateInfo));
8975
Karl Schultz6addd812016-02-02 17:17:23 -07008976 VkShaderObj vs(m_device,bindStateVertShaderText,VK_SHADER_STAGE_VERTEX_BIT,
8977this);
Tobin Ehlis912df022015-09-17 08:46:18 -06008978 // Just using VS txt for Tess shaders as we don't care about functionality
Karl Schultz6addd812016-02-02 17:17:23 -07008979 VkShaderObj
8980tc(m_device,bindStateVertShaderText,VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT,
8981this);
8982 VkShaderObj
8983te(m_device,bindStateVertShaderText,VK_SHADER_STAGE_TESSELLATION_EVALUATION_BIT,
8984this);
Tobin Ehlis912df022015-09-17 08:46:18 -06008985
Karl Schultz6addd812016-02-02 17:17:23 -07008986 shaderStages[0].sType =
8987VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO;
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -06008988 shaderStages[0].stage = VK_SHADER_STAGE_VERTEX_BIT;
Tobin Ehlis912df022015-09-17 08:46:18 -06008989 shaderStages[0].shader = vs.handle();
Karl Schultz6addd812016-02-02 17:17:23 -07008990 shaderStages[1].sType =
8991VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO;
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -06008992 shaderStages[1].stage = VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT;
Tobin Ehlis912df022015-09-17 08:46:18 -06008993 shaderStages[1].shader = tc.handle();
Karl Schultz6addd812016-02-02 17:17:23 -07008994 shaderStages[2].sType =
8995VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO;
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -06008996 shaderStages[2].stage = VK_SHADER_STAGE_TESSELLATION_EVALUATION_BIT;
Tobin Ehlis912df022015-09-17 08:46:18 -06008997 shaderStages[2].shader = te.handle();
8998
8999 VkPipelineInputAssemblyStateCreateInfo iaCI = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009000 iaCI.sType =
9001VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
Chia-I Wu515eb8f2015-10-31 00:31:16 +08009002 iaCI.topology = VK_PRIMITIVE_TOPOLOGY_PATCH_LIST;
Tobin Ehlis912df022015-09-17 08:46:18 -06009003
9004 VkPipelineTessellationStateCreateInfo tsCI = {};
9005 tsCI.sType = VK_STRUCTURE_TYPE_PIPELINE_TESSELLATION_STATE_CREATE_INFO;
9006 tsCI.patchControlPoints = 0; // This will cause an error
9007
9008 VkGraphicsPipelineCreateInfo gp_ci = {};
9009 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
9010 gp_ci.pNext = NULL;
9011 gp_ci.stageCount = 3;
9012 gp_ci.pStages = shaderStages;
9013 gp_ci.pVertexInputState = NULL;
9014 gp_ci.pInputAssemblyState = &iaCI;
9015 gp_ci.pTessellationState = &tsCI;
9016 gp_ci.pViewportState = NULL;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009017 gp_ci.pRasterizationState = NULL;
Tobin Ehlis912df022015-09-17 08:46:18 -06009018 gp_ci.pMultisampleState = NULL;
9019 gp_ci.pDepthStencilState = NULL;
9020 gp_ci.pColorBlendState = NULL;
9021 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
9022 gp_ci.layout = pipeline_layout;
9023 gp_ci.renderPass = renderPass();
9024
9025 VkPipelineCacheCreateInfo pc_ci = {};
9026 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
9027 pc_ci.pNext = NULL;
9028 pc_ci.initialSize = 0;
9029 pc_ci.initialData = 0;
9030 pc_ci.maxSize = 0;
9031
9032 VkPipeline pipeline;
9033 VkPipelineCache pipelineCache;
9034
Karl Schultz6addd812016-02-02 17:17:23 -07009035 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL,
9036&pipelineCache);
Tobin Ehlis912df022015-09-17 08:46:18 -06009037 ASSERT_VK_SUCCESS(err);
Karl Schultz6addd812016-02-02 17:17:23 -07009038 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1,
9039&gp_ci, NULL, &pipeline);
Tobin Ehlis912df022015-09-17 08:46:18 -06009040
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009041 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06009042
Chia-I Wuf7458c52015-10-26 21:10:41 +08009043 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
9044 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
9045 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
9046 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis912df022015-09-17 08:46:18 -06009047}
9048*/
Tobin Ehlise68360f2015-10-01 11:15:13 -06009049// Set scissor and viewport counts to different numbers
Karl Schultz6addd812016-02-02 17:17:23 -07009050TEST_F(VkLayerTest, PSOViewportScissorCountMismatch) {
Karl Schultz6addd812016-02-02 17:17:23 -07009051 VkResult err;
Tobin Ehlise68360f2015-10-01 11:15:13 -06009052
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009053 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
9054 "Gfx Pipeline viewport count (1) must match scissor count (0).");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06009055
Tobin Ehlise68360f2015-10-01 11:15:13 -06009056 ASSERT_NO_FATAL_FAILURE(InitState());
9057 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlise68360f2015-10-01 11:15:13 -06009058
Chia-I Wu1b99bb22015-10-27 19:25:11 +08009059 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009060 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
9061 ds_type_count.descriptorCount = 1;
Tobin Ehlise68360f2015-10-01 11:15:13 -06009062
9063 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009064 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
9065 ds_pool_ci.maxSets = 1;
9066 ds_pool_ci.poolSizeCount = 1;
9067 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlise68360f2015-10-01 11:15:13 -06009068
9069 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009070 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlise68360f2015-10-01 11:15:13 -06009071 ASSERT_VK_SUCCESS(err);
9072
9073 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009074 dsl_binding.binding = 0;
9075 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
9076 dsl_binding.descriptorCount = 1;
9077 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
Tobin Ehlise68360f2015-10-01 11:15:13 -06009078
9079 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009080 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
9081 ds_layout_ci.bindingCount = 1;
9082 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlise68360f2015-10-01 11:15:13 -06009083
9084 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009085 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlise68360f2015-10-01 11:15:13 -06009086 ASSERT_VK_SUCCESS(err);
9087
9088 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009089 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08009090 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07009091 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06009092 alloc_info.descriptorPool = ds_pool;
9093 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009094 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlise68360f2015-10-01 11:15:13 -06009095 ASSERT_VK_SUCCESS(err);
9096
9097 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009098 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
9099 pipeline_layout_ci.setLayoutCount = 1;
9100 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlise68360f2015-10-01 11:15:13 -06009101
9102 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009103 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlise68360f2015-10-01 11:15:13 -06009104 ASSERT_VK_SUCCESS(err);
9105
9106 VkViewport vp = {}; // Just need dummy vp to point to
9107
9108 VkPipelineViewportStateCreateInfo vp_state_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009109 vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
9110 vp_state_ci.scissorCount = 0;
9111 vp_state_ci.viewportCount = 1; // Count mismatch should cause error
9112 vp_state_ci.pViewports = &vp;
Tobin Ehlise68360f2015-10-01 11:15:13 -06009113
Karl Schultzdfdb8d42016-03-08 10:30:21 -07009114 VkPipelineRasterizationStateCreateInfo rs_state_ci = {};
9115 rs_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
9116 rs_state_ci.polygonMode = VK_POLYGON_MODE_FILL;
9117 rs_state_ci.cullMode = VK_CULL_MODE_BACK_BIT;
9118 rs_state_ci.frontFace = VK_FRONT_FACE_COUNTER_CLOCKWISE;
9119 rs_state_ci.depthClampEnable = VK_FALSE;
9120 rs_state_ci.rasterizerDiscardEnable = VK_FALSE;
9121 rs_state_ci.depthBiasEnable = VK_FALSE;
9122
Cody Northropeb3a6c12015-10-05 14:44:45 -06009123 VkPipelineShaderStageCreateInfo shaderStages[2];
Karl Schultz6addd812016-02-02 17:17:23 -07009124 memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo));
Tobin Ehlise68360f2015-10-01 11:15:13 -06009125
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009126 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
9127 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this); // We shouldn't need a fragment shader
9128 // but add it to be able to run on more devices
Chia-I Wu28e06912015-10-31 00:31:16 +08009129 shaderStages[0] = vs.GetStageCreateInfo();
9130 shaderStages[1] = fs.GetStageCreateInfo();
Tobin Ehlise68360f2015-10-01 11:15:13 -06009131
9132 VkGraphicsPipelineCreateInfo gp_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009133 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
9134 gp_ci.stageCount = 2;
9135 gp_ci.pStages = shaderStages;
9136 gp_ci.pViewportState = &vp_state_ci;
Karl Schultzdfdb8d42016-03-08 10:30:21 -07009137 gp_ci.pRasterizationState = &rs_state_ci;
Karl Schultz6addd812016-02-02 17:17:23 -07009138 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
9139 gp_ci.layout = pipeline_layout;
9140 gp_ci.renderPass = renderPass();
Tobin Ehlise68360f2015-10-01 11:15:13 -06009141
9142 VkPipelineCacheCreateInfo pc_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009143 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
Tobin Ehlise68360f2015-10-01 11:15:13 -06009144
9145 VkPipeline pipeline;
9146 VkPipelineCache pipelineCache;
9147
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009148 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Tobin Ehlise68360f2015-10-01 11:15:13 -06009149 ASSERT_VK_SUCCESS(err);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009150 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Tobin Ehlise68360f2015-10-01 11:15:13 -06009151
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009152 m_errorMonitor->VerifyFound();
Tobin Ehlise68360f2015-10-01 11:15:13 -06009153
Chia-I Wuf7458c52015-10-26 21:10:41 +08009154 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
9155 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
9156 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
9157 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlise68360f2015-10-01 11:15:13 -06009158}
Karl Schultz6addd812016-02-02 17:17:23 -07009159// Don't set viewport state in PSO. This is an error b/c we always need this
9160// state
Tobin Ehlisd332f282015-10-02 11:00:56 -06009161// for the counts even if the data is going to be set dynamically.
Karl Schultz6addd812016-02-02 17:17:23 -07009162TEST_F(VkLayerTest, PSOViewportStateNotSet) {
Tobin Ehlise68360f2015-10-01 11:15:13 -06009163 // Attempt to Create Gfx Pipeline w/o a VS
Karl Schultz6addd812016-02-02 17:17:23 -07009164 VkResult err;
Tobin Ehlise68360f2015-10-01 11:15:13 -06009165
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009166 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Gfx Pipeline pViewportState is null. Even if ");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06009167
Tobin Ehlise68360f2015-10-01 11:15:13 -06009168 ASSERT_NO_FATAL_FAILURE(InitState());
9169 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlise68360f2015-10-01 11:15:13 -06009170
Chia-I Wu1b99bb22015-10-27 19:25:11 +08009171 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009172 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
9173 ds_type_count.descriptorCount = 1;
Tobin Ehlise68360f2015-10-01 11:15:13 -06009174
9175 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009176 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
9177 ds_pool_ci.maxSets = 1;
9178 ds_pool_ci.poolSizeCount = 1;
9179 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlise68360f2015-10-01 11:15:13 -06009180
9181 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009182 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlise68360f2015-10-01 11:15:13 -06009183 ASSERT_VK_SUCCESS(err);
9184
9185 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009186 dsl_binding.binding = 0;
9187 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
9188 dsl_binding.descriptorCount = 1;
9189 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
Tobin Ehlise68360f2015-10-01 11:15:13 -06009190
9191 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009192 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
9193 ds_layout_ci.bindingCount = 1;
9194 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlise68360f2015-10-01 11:15:13 -06009195
9196 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009197 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlise68360f2015-10-01 11:15:13 -06009198 ASSERT_VK_SUCCESS(err);
9199
9200 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009201 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08009202 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07009203 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06009204 alloc_info.descriptorPool = ds_pool;
9205 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009206 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlise68360f2015-10-01 11:15:13 -06009207 ASSERT_VK_SUCCESS(err);
9208
9209 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009210 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
9211 pipeline_layout_ci.setLayoutCount = 1;
9212 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlise68360f2015-10-01 11:15:13 -06009213
9214 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009215 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlise68360f2015-10-01 11:15:13 -06009216 ASSERT_VK_SUCCESS(err);
9217
9218 VkDynamicState sc_state = VK_DYNAMIC_STATE_SCISSOR;
9219 // Set scissor as dynamic to avoid second error
9220 VkPipelineDynamicStateCreateInfo dyn_state_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009221 dyn_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_DYNAMIC_STATE_CREATE_INFO;
9222 dyn_state_ci.dynamicStateCount = 1;
9223 dyn_state_ci.pDynamicStates = &sc_state;
Tobin Ehlise68360f2015-10-01 11:15:13 -06009224
Cody Northropeb3a6c12015-10-05 14:44:45 -06009225 VkPipelineShaderStageCreateInfo shaderStages[2];
Karl Schultz6addd812016-02-02 17:17:23 -07009226 memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo));
Tobin Ehlise68360f2015-10-01 11:15:13 -06009227
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009228 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
9229 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this); // We shouldn't need a fragment shader
9230 // but add it to be able to run on more devices
Chia-I Wu28e06912015-10-31 00:31:16 +08009231 shaderStages[0] = vs.GetStageCreateInfo();
9232 shaderStages[1] = fs.GetStageCreateInfo();
Tobin Ehlise68360f2015-10-01 11:15:13 -06009233
Karl Schultzdfdb8d42016-03-08 10:30:21 -07009234 VkPipelineRasterizationStateCreateInfo rs_state_ci = {};
9235 rs_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
9236 rs_state_ci.polygonMode = VK_POLYGON_MODE_FILL;
9237 rs_state_ci.cullMode = VK_CULL_MODE_BACK_BIT;
9238 rs_state_ci.frontFace = VK_FRONT_FACE_COUNTER_CLOCKWISE;
9239 rs_state_ci.depthClampEnable = VK_FALSE;
9240 rs_state_ci.rasterizerDiscardEnable = VK_FALSE;
9241 rs_state_ci.depthBiasEnable = VK_FALSE;
9242
Tobin Ehlise68360f2015-10-01 11:15:13 -06009243 VkGraphicsPipelineCreateInfo gp_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009244 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
9245 gp_ci.stageCount = 2;
9246 gp_ci.pStages = shaderStages;
Karl Schultzdfdb8d42016-03-08 10:30:21 -07009247 gp_ci.pRasterizationState = &rs_state_ci;
Karl Schultz6addd812016-02-02 17:17:23 -07009248 gp_ci.pViewportState = NULL; // Not setting VP state w/o dynamic vp state
9249 // should cause validation error
9250 gp_ci.pDynamicState = &dyn_state_ci;
9251 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
9252 gp_ci.layout = pipeline_layout;
9253 gp_ci.renderPass = renderPass();
Tobin Ehlise68360f2015-10-01 11:15:13 -06009254
9255 VkPipelineCacheCreateInfo pc_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009256 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
Tobin Ehlise68360f2015-10-01 11:15:13 -06009257
9258 VkPipeline pipeline;
9259 VkPipelineCache pipelineCache;
9260
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009261 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Tobin Ehlise68360f2015-10-01 11:15:13 -06009262 ASSERT_VK_SUCCESS(err);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009263 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Tobin Ehlise68360f2015-10-01 11:15:13 -06009264
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009265 m_errorMonitor->VerifyFound();
Tobin Ehlise68360f2015-10-01 11:15:13 -06009266
Chia-I Wuf7458c52015-10-26 21:10:41 +08009267 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
9268 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
9269 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
9270 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlise68360f2015-10-01 11:15:13 -06009271}
9272// Create PSO w/o non-zero viewportCount but no viewport data
Karl Schultz6addd812016-02-02 17:17:23 -07009273// Then run second test where dynamic scissor count doesn't match PSO scissor
9274// count
9275TEST_F(VkLayerTest, PSOViewportCountWithoutDataAndDynScissorMismatch) {
9276 VkResult err;
Tobin Ehlise68360f2015-10-01 11:15:13 -06009277
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009278 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
9279 "Gfx Pipeline viewportCount is 1, but pViewports is NULL. ");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06009280
Tobin Ehlise68360f2015-10-01 11:15:13 -06009281 ASSERT_NO_FATAL_FAILURE(InitState());
Chris Forbesc08a6ca2016-07-28 14:14:07 +12009282
9283 if (!m_device->phy().features().multiViewport) {
9284 printf("Device does not support multiple viewports/scissors; skipped.\n");
9285 return;
9286 }
9287
Tobin Ehlise68360f2015-10-01 11:15:13 -06009288 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlise68360f2015-10-01 11:15:13 -06009289
Chia-I Wu1b99bb22015-10-27 19:25:11 +08009290 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009291 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
9292 ds_type_count.descriptorCount = 1;
Tobin Ehlise68360f2015-10-01 11:15:13 -06009293
9294 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009295 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
9296 ds_pool_ci.maxSets = 1;
9297 ds_pool_ci.poolSizeCount = 1;
9298 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlise68360f2015-10-01 11:15:13 -06009299
9300 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009301 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlise68360f2015-10-01 11:15:13 -06009302 ASSERT_VK_SUCCESS(err);
9303
9304 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009305 dsl_binding.binding = 0;
9306 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
9307 dsl_binding.descriptorCount = 1;
9308 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
Tobin Ehlise68360f2015-10-01 11:15:13 -06009309
9310 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009311 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
9312 ds_layout_ci.bindingCount = 1;
9313 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlise68360f2015-10-01 11:15:13 -06009314
9315 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009316 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlise68360f2015-10-01 11:15:13 -06009317 ASSERT_VK_SUCCESS(err);
9318
9319 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009320 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08009321 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07009322 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06009323 alloc_info.descriptorPool = ds_pool;
9324 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009325 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlise68360f2015-10-01 11:15:13 -06009326 ASSERT_VK_SUCCESS(err);
9327
9328 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009329 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
9330 pipeline_layout_ci.setLayoutCount = 1;
9331 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlise68360f2015-10-01 11:15:13 -06009332
9333 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009334 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlise68360f2015-10-01 11:15:13 -06009335 ASSERT_VK_SUCCESS(err);
9336
9337 VkPipelineViewportStateCreateInfo vp_state_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009338 vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
9339 vp_state_ci.viewportCount = 1;
9340 vp_state_ci.pViewports = NULL; // Null vp w/ count of 1 should cause error
9341 vp_state_ci.scissorCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009342 vp_state_ci.pScissors = NULL; // Scissor is dynamic (below) so this won't cause error
Tobin Ehlise68360f2015-10-01 11:15:13 -06009343
9344 VkDynamicState sc_state = VK_DYNAMIC_STATE_SCISSOR;
9345 // Set scissor as dynamic to avoid that error
9346 VkPipelineDynamicStateCreateInfo dyn_state_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009347 dyn_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_DYNAMIC_STATE_CREATE_INFO;
9348 dyn_state_ci.dynamicStateCount = 1;
9349 dyn_state_ci.pDynamicStates = &sc_state;
Tobin Ehlise68360f2015-10-01 11:15:13 -06009350
Cody Northropeb3a6c12015-10-05 14:44:45 -06009351 VkPipelineShaderStageCreateInfo shaderStages[2];
Karl Schultz6addd812016-02-02 17:17:23 -07009352 memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo));
Tobin Ehlise68360f2015-10-01 11:15:13 -06009353
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009354 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
9355 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this); // We shouldn't need a fragment shader
9356 // but add it to be able to run on more devices
Chia-I Wu28e06912015-10-31 00:31:16 +08009357 shaderStages[0] = vs.GetStageCreateInfo();
9358 shaderStages[1] = fs.GetStageCreateInfo();
Tobin Ehlise68360f2015-10-01 11:15:13 -06009359
Cody Northropf6622dc2015-10-06 10:33:21 -06009360 VkPipelineVertexInputStateCreateInfo vi_ci = {};
9361 vi_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
9362 vi_ci.pNext = nullptr;
Chia-I Wud50a7d72015-10-26 20:48:51 +08009363 vi_ci.vertexBindingDescriptionCount = 0;
Cody Northropf6622dc2015-10-06 10:33:21 -06009364 vi_ci.pVertexBindingDescriptions = nullptr;
Chia-I Wud50a7d72015-10-26 20:48:51 +08009365 vi_ci.vertexAttributeDescriptionCount = 0;
Cody Northropf6622dc2015-10-06 10:33:21 -06009366 vi_ci.pVertexAttributeDescriptions = nullptr;
9367
9368 VkPipelineInputAssemblyStateCreateInfo ia_ci = {};
9369 ia_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
9370 ia_ci.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP;
9371
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009372 VkPipelineRasterizationStateCreateInfo rs_ci = {};
Chia-I Wu1b99bb22015-10-27 19:25:11 +08009373 rs_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
Cody Northropf6622dc2015-10-06 10:33:21 -06009374 rs_ci.pNext = nullptr;
9375
Mark Youngc89c6312016-03-31 16:03:20 -06009376 VkPipelineColorBlendAttachmentState att = {};
9377 att.blendEnable = VK_FALSE;
9378 att.colorWriteMask = 0xf;
9379
Cody Northropf6622dc2015-10-06 10:33:21 -06009380 VkPipelineColorBlendStateCreateInfo cb_ci = {};
9381 cb_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO;
9382 cb_ci.pNext = nullptr;
Mark Youngc89c6312016-03-31 16:03:20 -06009383 cb_ci.attachmentCount = 1;
9384 cb_ci.pAttachments = &att;
Cody Northropf6622dc2015-10-06 10:33:21 -06009385
Tobin Ehlise68360f2015-10-01 11:15:13 -06009386 VkGraphicsPipelineCreateInfo gp_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009387 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
9388 gp_ci.stageCount = 2;
9389 gp_ci.pStages = shaderStages;
9390 gp_ci.pVertexInputState = &vi_ci;
9391 gp_ci.pInputAssemblyState = &ia_ci;
9392 gp_ci.pViewportState = &vp_state_ci;
9393 gp_ci.pRasterizationState = &rs_ci;
9394 gp_ci.pColorBlendState = &cb_ci;
9395 gp_ci.pDynamicState = &dyn_state_ci;
9396 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
9397 gp_ci.layout = pipeline_layout;
9398 gp_ci.renderPass = renderPass();
Tobin Ehlise68360f2015-10-01 11:15:13 -06009399
9400 VkPipelineCacheCreateInfo pc_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009401 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
Tobin Ehlise68360f2015-10-01 11:15:13 -06009402
9403 VkPipeline pipeline;
9404 VkPipelineCache pipelineCache;
9405
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009406 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Tobin Ehlise68360f2015-10-01 11:15:13 -06009407 ASSERT_VK_SUCCESS(err);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009408 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Tobin Ehlise68360f2015-10-01 11:15:13 -06009409
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009410 m_errorMonitor->VerifyFound();
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06009411
Tobin Ehlisd332f282015-10-02 11:00:56 -06009412 // Now hit second fail case where we set scissor w/ different count than PSO
Karl Schultz6addd812016-02-02 17:17:23 -07009413 // First need to successfully create the PSO from above by setting
9414 // pViewports
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009415 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Dynamic scissor(s) 0 are used by PSO, ");
Karl Schultz6addd812016-02-02 17:17:23 -07009416
9417 VkViewport vp = {}; // Just need dummy vp to point to
9418 vp_state_ci.pViewports = &vp;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009419 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Karl Schultz6addd812016-02-02 17:17:23 -07009420 ASSERT_VK_SUCCESS(err);
9421 BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009422 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline);
Chris Forbesc08a6ca2016-07-28 14:14:07 +12009423 VkRect2D scissors[1] = {}; // don't care about data
Karl Schultz6addd812016-02-02 17:17:23 -07009424 // Count of 2 doesn't match PSO count of 1
Chris Forbesc08a6ca2016-07-28 14:14:07 +12009425 vkCmdSetScissor(m_commandBuffer->GetBufferHandle(), 1, 1, scissors);
Karl Schultz6addd812016-02-02 17:17:23 -07009426 Draw(1, 0, 0, 0);
9427
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009428 m_errorMonitor->VerifyFound();
Karl Schultz6addd812016-02-02 17:17:23 -07009429
9430 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
9431 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
9432 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
9433 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tony Barbourdf4c0042016-06-01 15:55:43 -06009434 vkDestroyPipeline(m_device->device(), pipeline, NULL);
Karl Schultz6addd812016-02-02 17:17:23 -07009435}
9436// Create PSO w/o non-zero scissorCount but no scissor data
9437// Then run second test where dynamic viewportCount doesn't match PSO
9438// viewportCount
9439TEST_F(VkLayerTest, PSOScissorCountWithoutDataAndDynViewportMismatch) {
9440 VkResult err;
9441
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009442 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 -07009443
9444 ASSERT_NO_FATAL_FAILURE(InitState());
Chris Forbesc08a6ca2016-07-28 14:14:07 +12009445
9446 if (!m_device->phy().features().multiViewport) {
9447 printf("Device does not support multiple viewports/scissors; skipped.\n");
9448 return;
9449 }
9450
Karl Schultz6addd812016-02-02 17:17:23 -07009451 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
9452
9453 VkDescriptorPoolSize ds_type_count = {};
9454 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
9455 ds_type_count.descriptorCount = 1;
9456
9457 VkDescriptorPoolCreateInfo ds_pool_ci = {};
9458 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
9459 ds_pool_ci.maxSets = 1;
9460 ds_pool_ci.poolSizeCount = 1;
9461 ds_pool_ci.pPoolSizes = &ds_type_count;
9462
9463 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009464 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Karl Schultz6addd812016-02-02 17:17:23 -07009465 ASSERT_VK_SUCCESS(err);
9466
9467 VkDescriptorSetLayoutBinding dsl_binding = {};
9468 dsl_binding.binding = 0;
9469 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
9470 dsl_binding.descriptorCount = 1;
9471 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
9472
9473 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
9474 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
9475 ds_layout_ci.bindingCount = 1;
9476 ds_layout_ci.pBindings = &dsl_binding;
9477
9478 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009479 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Karl Schultz6addd812016-02-02 17:17:23 -07009480 ASSERT_VK_SUCCESS(err);
9481
9482 VkDescriptorSet descriptorSet;
9483 VkDescriptorSetAllocateInfo alloc_info = {};
9484 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
9485 alloc_info.descriptorSetCount = 1;
9486 alloc_info.descriptorPool = ds_pool;
9487 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009488 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Karl Schultz6addd812016-02-02 17:17:23 -07009489 ASSERT_VK_SUCCESS(err);
9490
9491 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
9492 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
9493 pipeline_layout_ci.setLayoutCount = 1;
9494 pipeline_layout_ci.pSetLayouts = &ds_layout;
9495
9496 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009497 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Karl Schultz6addd812016-02-02 17:17:23 -07009498 ASSERT_VK_SUCCESS(err);
9499
9500 VkPipelineViewportStateCreateInfo vp_state_ci = {};
9501 vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
9502 vp_state_ci.scissorCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009503 vp_state_ci.pScissors = NULL; // Null scissor w/ count of 1 should cause error
Karl Schultz6addd812016-02-02 17:17:23 -07009504 vp_state_ci.viewportCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009505 vp_state_ci.pViewports = NULL; // vp is dynamic (below) so this won't cause error
Karl Schultz6addd812016-02-02 17:17:23 -07009506
9507 VkDynamicState vp_state = VK_DYNAMIC_STATE_VIEWPORT;
9508 // Set scissor as dynamic to avoid that error
9509 VkPipelineDynamicStateCreateInfo dyn_state_ci = {};
9510 dyn_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_DYNAMIC_STATE_CREATE_INFO;
9511 dyn_state_ci.dynamicStateCount = 1;
9512 dyn_state_ci.pDynamicStates = &vp_state;
9513
9514 VkPipelineShaderStageCreateInfo shaderStages[2];
9515 memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo));
9516
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009517 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
9518 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this); // We shouldn't need a fragment shader
9519 // but add it to be able to run on more devices
Karl Schultz6addd812016-02-02 17:17:23 -07009520 shaderStages[0] = vs.GetStageCreateInfo();
9521 shaderStages[1] = fs.GetStageCreateInfo();
9522
9523 VkPipelineVertexInputStateCreateInfo vi_ci = {};
9524 vi_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
9525 vi_ci.pNext = nullptr;
9526 vi_ci.vertexBindingDescriptionCount = 0;
9527 vi_ci.pVertexBindingDescriptions = nullptr;
9528 vi_ci.vertexAttributeDescriptionCount = 0;
9529 vi_ci.pVertexAttributeDescriptions = nullptr;
9530
9531 VkPipelineInputAssemblyStateCreateInfo ia_ci = {};
9532 ia_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
9533 ia_ci.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP;
9534
9535 VkPipelineRasterizationStateCreateInfo rs_ci = {};
9536 rs_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
9537 rs_ci.pNext = nullptr;
9538
Mark Youngc89c6312016-03-31 16:03:20 -06009539 VkPipelineColorBlendAttachmentState att = {};
9540 att.blendEnable = VK_FALSE;
9541 att.colorWriteMask = 0xf;
9542
Karl Schultz6addd812016-02-02 17:17:23 -07009543 VkPipelineColorBlendStateCreateInfo cb_ci = {};
9544 cb_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO;
9545 cb_ci.pNext = nullptr;
Mark Youngc89c6312016-03-31 16:03:20 -06009546 cb_ci.attachmentCount = 1;
9547 cb_ci.pAttachments = &att;
Karl Schultz6addd812016-02-02 17:17:23 -07009548
9549 VkGraphicsPipelineCreateInfo gp_ci = {};
9550 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
9551 gp_ci.stageCount = 2;
9552 gp_ci.pStages = shaderStages;
9553 gp_ci.pVertexInputState = &vi_ci;
9554 gp_ci.pInputAssemblyState = &ia_ci;
9555 gp_ci.pViewportState = &vp_state_ci;
9556 gp_ci.pRasterizationState = &rs_ci;
9557 gp_ci.pColorBlendState = &cb_ci;
9558 gp_ci.pDynamicState = &dyn_state_ci;
9559 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
9560 gp_ci.layout = pipeline_layout;
9561 gp_ci.renderPass = renderPass();
9562
9563 VkPipelineCacheCreateInfo pc_ci = {};
9564 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
9565
9566 VkPipeline pipeline;
9567 VkPipelineCache pipelineCache;
9568
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009569 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Karl Schultz6addd812016-02-02 17:17:23 -07009570 ASSERT_VK_SUCCESS(err);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009571 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Karl Schultz6addd812016-02-02 17:17:23 -07009572
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009573 m_errorMonitor->VerifyFound();
Karl Schultz6addd812016-02-02 17:17:23 -07009574
9575 // Now hit second fail case where we set scissor w/ different count than PSO
9576 // First need to successfully create the PSO from above by setting
9577 // pViewports
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009578 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Dynamic viewport(s) 0 are used by PSO, ");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06009579
Tobin Ehlisd332f282015-10-02 11:00:56 -06009580 VkRect2D sc = {}; // Just need dummy vp to point to
9581 vp_state_ci.pScissors = &sc;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009582 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Tobin Ehlisd332f282015-10-02 11:00:56 -06009583 ASSERT_VK_SUCCESS(err);
9584 BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009585 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline);
Chris Forbesc08a6ca2016-07-28 14:14:07 +12009586 VkViewport viewports[1] = {}; // don't care about data
Tobin Ehlisd332f282015-10-02 11:00:56 -06009587 // Count of 2 doesn't match PSO count of 1
Chris Forbesc08a6ca2016-07-28 14:14:07 +12009588 vkCmdSetViewport(m_commandBuffer->GetBufferHandle(), 1, 1, viewports);
Tobin Ehlisd332f282015-10-02 11:00:56 -06009589 Draw(1, 0, 0, 0);
9590
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009591 m_errorMonitor->VerifyFound();
Tobin Ehlise68360f2015-10-01 11:15:13 -06009592
Chia-I Wuf7458c52015-10-26 21:10:41 +08009593 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
9594 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
9595 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
9596 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tony Barbourdf4c0042016-06-01 15:55:43 -06009597 vkDestroyPipeline(m_device->device(), pipeline, NULL);
Tobin Ehlise68360f2015-10-01 11:15:13 -06009598}
9599
Mark Young7394fdd2016-03-31 14:56:43 -06009600TEST_F(VkLayerTest, PSOLineWidthInvalid) {
9601 VkResult err;
9602
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009603 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Attempt to set lineWidth to -1");
Mark Young7394fdd2016-03-31 14:56:43 -06009604
9605 ASSERT_NO_FATAL_FAILURE(InitState());
9606 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
9607
9608 VkDescriptorPoolSize ds_type_count = {};
9609 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
9610 ds_type_count.descriptorCount = 1;
9611
9612 VkDescriptorPoolCreateInfo ds_pool_ci = {};
9613 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
9614 ds_pool_ci.maxSets = 1;
9615 ds_pool_ci.poolSizeCount = 1;
9616 ds_pool_ci.pPoolSizes = &ds_type_count;
9617
9618 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009619 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Mark Young7394fdd2016-03-31 14:56:43 -06009620 ASSERT_VK_SUCCESS(err);
9621
9622 VkDescriptorSetLayoutBinding dsl_binding = {};
9623 dsl_binding.binding = 0;
9624 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
9625 dsl_binding.descriptorCount = 1;
9626 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
9627
9628 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
9629 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
9630 ds_layout_ci.bindingCount = 1;
9631 ds_layout_ci.pBindings = &dsl_binding;
9632
9633 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009634 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Mark Young7394fdd2016-03-31 14:56:43 -06009635 ASSERT_VK_SUCCESS(err);
9636
9637 VkDescriptorSet descriptorSet;
9638 VkDescriptorSetAllocateInfo alloc_info = {};
9639 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
9640 alloc_info.descriptorSetCount = 1;
9641 alloc_info.descriptorPool = ds_pool;
9642 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009643 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Mark Young7394fdd2016-03-31 14:56:43 -06009644 ASSERT_VK_SUCCESS(err);
9645
9646 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
9647 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
9648 pipeline_layout_ci.setLayoutCount = 1;
9649 pipeline_layout_ci.pSetLayouts = &ds_layout;
9650
9651 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009652 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Mark Young7394fdd2016-03-31 14:56:43 -06009653 ASSERT_VK_SUCCESS(err);
9654
9655 VkPipelineViewportStateCreateInfo vp_state_ci = {};
9656 vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
9657 vp_state_ci.scissorCount = 1;
9658 vp_state_ci.pScissors = NULL;
9659 vp_state_ci.viewportCount = 1;
9660 vp_state_ci.pViewports = NULL;
9661
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009662 VkDynamicState dynamic_states[3] = {VK_DYNAMIC_STATE_VIEWPORT, VK_DYNAMIC_STATE_SCISSOR, VK_DYNAMIC_STATE_LINE_WIDTH};
Mark Young7394fdd2016-03-31 14:56:43 -06009663 // Set scissor as dynamic to avoid that error
9664 VkPipelineDynamicStateCreateInfo dyn_state_ci = {};
9665 dyn_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_DYNAMIC_STATE_CREATE_INFO;
9666 dyn_state_ci.dynamicStateCount = 2;
9667 dyn_state_ci.pDynamicStates = dynamic_states;
9668
9669 VkPipelineShaderStageCreateInfo shaderStages[2];
9670 memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo));
9671
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009672 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
9673 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT,
Mark Young7394fdd2016-03-31 14:56:43 -06009674 this); // TODO - We shouldn't need a fragment shader
9675 // but add it to be able to run on more devices
9676 shaderStages[0] = vs.GetStageCreateInfo();
9677 shaderStages[1] = fs.GetStageCreateInfo();
9678
9679 VkPipelineVertexInputStateCreateInfo vi_ci = {};
9680 vi_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
9681 vi_ci.pNext = nullptr;
9682 vi_ci.vertexBindingDescriptionCount = 0;
9683 vi_ci.pVertexBindingDescriptions = nullptr;
9684 vi_ci.vertexAttributeDescriptionCount = 0;
9685 vi_ci.pVertexAttributeDescriptions = nullptr;
9686
9687 VkPipelineInputAssemblyStateCreateInfo ia_ci = {};
9688 ia_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
9689 ia_ci.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP;
9690
9691 VkPipelineRasterizationStateCreateInfo rs_ci = {};
9692 rs_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
9693 rs_ci.pNext = nullptr;
9694
Mark Young47107952016-05-02 15:59:55 -06009695 // Check too low (line width of -1.0f).
9696 rs_ci.lineWidth = -1.0f;
Mark Young7394fdd2016-03-31 14:56:43 -06009697
9698 VkPipelineColorBlendAttachmentState att = {};
9699 att.blendEnable = VK_FALSE;
9700 att.colorWriteMask = 0xf;
9701
9702 VkPipelineColorBlendStateCreateInfo cb_ci = {};
9703 cb_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO;
9704 cb_ci.pNext = nullptr;
9705 cb_ci.attachmentCount = 1;
9706 cb_ci.pAttachments = &att;
9707
9708 VkGraphicsPipelineCreateInfo gp_ci = {};
9709 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
9710 gp_ci.stageCount = 2;
9711 gp_ci.pStages = shaderStages;
9712 gp_ci.pVertexInputState = &vi_ci;
9713 gp_ci.pInputAssemblyState = &ia_ci;
9714 gp_ci.pViewportState = &vp_state_ci;
9715 gp_ci.pRasterizationState = &rs_ci;
9716 gp_ci.pColorBlendState = &cb_ci;
9717 gp_ci.pDynamicState = &dyn_state_ci;
9718 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
9719 gp_ci.layout = pipeline_layout;
9720 gp_ci.renderPass = renderPass();
9721
9722 VkPipelineCacheCreateInfo pc_ci = {};
9723 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
9724
9725 VkPipeline pipeline;
9726 VkPipelineCache pipelineCache;
9727
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009728 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Mark Young7394fdd2016-03-31 14:56:43 -06009729 ASSERT_VK_SUCCESS(err);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009730 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Mark Young7394fdd2016-03-31 14:56:43 -06009731
9732 m_errorMonitor->VerifyFound();
Tony Barbourdf4c0042016-06-01 15:55:43 -06009733 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
Mark Young7394fdd2016-03-31 14:56:43 -06009734
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009735 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Attempt to set lineWidth to 65536");
Mark Young7394fdd2016-03-31 14:56:43 -06009736
9737 // Check too high (line width of 65536.0f).
9738 rs_ci.lineWidth = 65536.0f;
9739
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009740 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Mark Young7394fdd2016-03-31 14:56:43 -06009741 ASSERT_VK_SUCCESS(err);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009742 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Mark Young7394fdd2016-03-31 14:56:43 -06009743
9744 m_errorMonitor->VerifyFound();
Tony Barbourdf4c0042016-06-01 15:55:43 -06009745 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
Mark Young7394fdd2016-03-31 14:56:43 -06009746
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009747 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Attempt to set lineWidth to -1");
Mark Young7394fdd2016-03-31 14:56:43 -06009748
9749 dyn_state_ci.dynamicStateCount = 3;
9750
9751 rs_ci.lineWidth = 1.0f;
9752
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009753 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Mark Young7394fdd2016-03-31 14:56:43 -06009754 ASSERT_VK_SUCCESS(err);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009755 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Mark Young7394fdd2016-03-31 14:56:43 -06009756 BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009757 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline);
Mark Young7394fdd2016-03-31 14:56:43 -06009758
9759 // Check too low with dynamic setting.
Mark Young47107952016-05-02 15:59:55 -06009760 vkCmdSetLineWidth(m_commandBuffer->GetBufferHandle(), -1.0f);
Mark Young7394fdd2016-03-31 14:56:43 -06009761 m_errorMonitor->VerifyFound();
9762
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009763 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Attempt to set lineWidth to 65536");
Mark Young7394fdd2016-03-31 14:56:43 -06009764
9765 // Check too high with dynamic setting.
9766 vkCmdSetLineWidth(m_commandBuffer->GetBufferHandle(), 65536.0f);
9767 m_errorMonitor->VerifyFound();
9768 EndCommandBuffer();
9769
9770 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
9771 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
9772 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
9773 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tony Barbourdf4c0042016-06-01 15:55:43 -06009774 vkDestroyPipeline(m_device->device(), pipeline, NULL);
Mark Young7394fdd2016-03-31 14:56:43 -06009775}
9776
Karl Schultz6addd812016-02-02 17:17:23 -07009777TEST_F(VkLayerTest, NullRenderPass) {
Tobin Ehlis98aa0ed2015-06-25 16:27:19 -06009778 // Bind a NULL RenderPass
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009779 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
9780 "You cannot use a NULL RenderPass object in vkCmdBeginRenderPass()");
Tobin Ehlis98aa0ed2015-06-25 16:27:19 -06009781
9782 ASSERT_NO_FATAL_FAILURE(InitState());
9783 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlis98aa0ed2015-06-25 16:27:19 -06009784
Tony Barbourfe3351b2015-07-28 10:17:20 -06009785 BeginCommandBuffer();
Karl Schultz6addd812016-02-02 17:17:23 -07009786 // Don't care about RenderPass handle b/c error should be flagged before
9787 // that
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009788 vkCmdBeginRenderPass(m_commandBuffer->GetBufferHandle(), NULL, VK_SUBPASS_CONTENTS_INLINE);
Tobin Ehlis98aa0ed2015-06-25 16:27:19 -06009789
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009790 m_errorMonitor->VerifyFound();
Tobin Ehlis98aa0ed2015-06-25 16:27:19 -06009791}
9792
Karl Schultz6addd812016-02-02 17:17:23 -07009793TEST_F(VkLayerTest, RenderPassWithinRenderPass) {
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06009794 // Bind a BeginRenderPass within an active RenderPass
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009795 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
9796 "It is invalid to issue this call inside an active render pass");
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06009797
9798 ASSERT_NO_FATAL_FAILURE(InitState());
9799 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06009800
Tony Barbourfe3351b2015-07-28 10:17:20 -06009801 BeginCommandBuffer();
Karl Schultz6addd812016-02-02 17:17:23 -07009802 // Just create a dummy Renderpass that's non-NULL so we can get to the
9803 // proper error
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009804 vkCmdBeginRenderPass(m_commandBuffer->GetBufferHandle(), &m_renderPassBeginInfo, VK_SUBPASS_CONTENTS_INLINE);
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06009805
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009806 m_errorMonitor->VerifyFound();
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06009807}
9808
Chris Forbes2eeabe32016-06-21 20:52:34 +12009809TEST_F(VkLayerTest, RenderPassSecondaryCommandBuffersMultipleTimes) {
9810 m_errorMonitor->ExpectSuccess();
9811
9812 ASSERT_NO_FATAL_FAILURE(InitState());
9813 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
9814
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009815 BeginCommandBuffer(); // framework implicitly begins the renderpass.
Chris Forbes2eeabe32016-06-21 20:52:34 +12009816 vkCmdEndRenderPass(m_commandBuffer->GetBufferHandle()); // end implicit.
9817
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009818 vkCmdBeginRenderPass(m_commandBuffer->GetBufferHandle(), &m_renderPassBeginInfo, VK_SUBPASS_CONTENTS_SECONDARY_COMMAND_BUFFERS);
Chris Forbes2eeabe32016-06-21 20:52:34 +12009819 vkCmdEndRenderPass(m_commandBuffer->GetBufferHandle());
9820 m_errorMonitor->VerifyNotFound();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009821 vkCmdBeginRenderPass(m_commandBuffer->GetBufferHandle(), &m_renderPassBeginInfo, VK_SUBPASS_CONTENTS_INLINE);
Chris Forbes2eeabe32016-06-21 20:52:34 +12009822 m_errorMonitor->VerifyNotFound();
9823 vkCmdEndRenderPass(m_commandBuffer->GetBufferHandle());
9824 m_errorMonitor->VerifyNotFound();
9825
9826 m_commandBuffer->EndCommandBuffer();
9827 m_errorMonitor->VerifyNotFound();
9828}
9829
Tobin Ehlis5a1c0332016-05-31 13:59:26 -06009830TEST_F(VkLayerTest, RenderPassClearOpMismatch) {
9831 TEST_DESCRIPTION("Begin a renderPass where clearValueCount is less than"
9832 "the number of renderPass attachments that use loadOp"
9833 "VK_ATTACHMENT_LOAD_OP_CLEAR.");
9834
9835 ASSERT_NO_FATAL_FAILURE(InitState());
9836 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
9837
9838 // Create a renderPass with a single attachment that uses loadOp CLEAR
9839 VkAttachmentReference attach = {};
9840 attach.layout = VK_IMAGE_LAYOUT_GENERAL;
9841 VkSubpassDescription subpass = {};
9842 subpass.inputAttachmentCount = 1;
9843 subpass.pInputAttachments = &attach;
9844 VkRenderPassCreateInfo rpci = {};
9845 rpci.subpassCount = 1;
9846 rpci.pSubpasses = &subpass;
9847 rpci.attachmentCount = 1;
9848 VkAttachmentDescription attach_desc = {};
9849 attach_desc.format = VK_FORMAT_UNDEFINED;
9850 // Set loadOp to CLEAR
9851 attach_desc.loadOp = VK_ATTACHMENT_LOAD_OP_CLEAR;
9852 rpci.pAttachments = &attach_desc;
9853 rpci.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
9854 VkRenderPass rp;
9855 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
9856
9857 VkCommandBufferInheritanceInfo hinfo = {};
9858 hinfo.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_INHERITANCE_INFO;
9859 hinfo.renderPass = VK_NULL_HANDLE;
9860 hinfo.subpass = 0;
9861 hinfo.framebuffer = VK_NULL_HANDLE;
9862 hinfo.occlusionQueryEnable = VK_FALSE;
9863 hinfo.queryFlags = 0;
9864 hinfo.pipelineStatistics = 0;
9865 VkCommandBufferBeginInfo info = {};
9866 info.flags = VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT;
9867 info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
9868 info.pInheritanceInfo = &hinfo;
9869
9870 vkBeginCommandBuffer(m_commandBuffer->handle(), &info);
9871 VkRenderPassBeginInfo rp_begin = {};
9872 rp_begin.sType = VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO;
9873 rp_begin.pNext = NULL;
9874 rp_begin.renderPass = renderPass();
9875 rp_begin.framebuffer = framebuffer();
9876 rp_begin.clearValueCount = 0; // Should be 1
9877
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009878 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " has a clearValueCount of 0 but "
9879 "there must be at least 1 entries in "
9880 "pClearValues array to account for ");
Tobin Ehlis5a1c0332016-05-31 13:59:26 -06009881
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009882 vkCmdBeginRenderPass(m_commandBuffer->GetBufferHandle(), &rp_begin, VK_SUBPASS_CONTENTS_INLINE);
Tobin Ehlis5a1c0332016-05-31 13:59:26 -06009883
9884 m_errorMonitor->VerifyFound();
Mark Lobodzinski5c70ebd2016-06-09 13:45:00 -06009885
9886 vkDestroyRenderPass(m_device->device(), rp, NULL);
Tobin Ehlis5a1c0332016-05-31 13:59:26 -06009887}
9888
Cody Northrop3bb4d962016-05-09 16:15:57 -06009889TEST_F(VkLayerTest, EndCommandBufferWithinRenderPass) {
9890
9891 TEST_DESCRIPTION("End a command buffer with an active render pass");
9892
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009893 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
9894 "It is invalid to issue this call inside an active render pass");
Cody Northrop3bb4d962016-05-09 16:15:57 -06009895
9896 ASSERT_NO_FATAL_FAILURE(InitState());
9897 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
9898
9899 // The framework's BeginCommandBuffer calls CreateRenderPass
9900 BeginCommandBuffer();
9901
9902 // Call directly into vkEndCommandBuffer instead of the
9903 // the framework's EndCommandBuffer, which inserts a
9904 // vkEndRenderPass
9905 vkEndCommandBuffer(m_commandBuffer->GetBufferHandle());
9906
9907 m_errorMonitor->VerifyFound();
9908
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009909 // TODO: Add test for VK_COMMAND_BUFFER_LEVEL_SECONDARY
9910 // TODO: Add test for VK_COMMAND_BUFFER_USAGE_RENDER_PASS_CONTINUE_BIT
Cody Northrop3bb4d962016-05-09 16:15:57 -06009911}
9912
Karl Schultz6addd812016-02-02 17:17:23 -07009913TEST_F(VkLayerTest, FillBufferWithinRenderPass) {
Mark Lobodzinskid5639502015-09-24 09:51:47 -06009914 // Call CmdFillBuffer within an active renderpass
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009915 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
9916 "It is invalid to issue this call inside an active render pass");
Mark Lobodzinskid5639502015-09-24 09:51:47 -06009917
9918 ASSERT_NO_FATAL_FAILURE(InitState());
9919 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Mark Lobodzinskid5639502015-09-24 09:51:47 -06009920
9921 // Renderpass is started here
9922 BeginCommandBuffer();
9923
9924 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009925 vk_testing::Buffer dstBuffer;
9926 dstBuffer.init_as_dst(*m_device, (VkDeviceSize)1024, reqs);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06009927
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009928 m_commandBuffer->FillBuffer(dstBuffer.handle(), 0, 4, 0x11111111);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06009929
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009930 m_errorMonitor->VerifyFound();
Mark Lobodzinskid5639502015-09-24 09:51:47 -06009931}
9932
Karl Schultz6addd812016-02-02 17:17:23 -07009933TEST_F(VkLayerTest, UpdateBufferWithinRenderPass) {
Mark Lobodzinskid5639502015-09-24 09:51:47 -06009934 // Call CmdUpdateBuffer within an active renderpass
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009935 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
9936 "It is invalid to issue this call inside an active render pass");
Mark Lobodzinskid5639502015-09-24 09:51:47 -06009937
9938 ASSERT_NO_FATAL_FAILURE(InitState());
9939 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Mark Lobodzinskid5639502015-09-24 09:51:47 -06009940
9941 // Renderpass is started here
9942 BeginCommandBuffer();
9943
9944 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009945 vk_testing::Buffer dstBuffer;
9946 dstBuffer.init_as_dst(*m_device, (VkDeviceSize)1024, reqs);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06009947
Karl Schultz6addd812016-02-02 17:17:23 -07009948 VkDeviceSize dstOffset = 0;
9949 VkDeviceSize dataSize = 1024;
Karl Schultzee344492016-07-11 15:09:57 -06009950 const void *pData = NULL;
Mark Lobodzinskid5639502015-09-24 09:51:47 -06009951
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009952 vkCmdUpdateBuffer(m_commandBuffer->GetBufferHandle(), dstBuffer.handle(), dstOffset, dataSize, pData);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06009953
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009954 m_errorMonitor->VerifyFound();
Mark Lobodzinskid5639502015-09-24 09:51:47 -06009955}
9956
Karl Schultz6addd812016-02-02 17:17:23 -07009957TEST_F(VkLayerTest, ClearColorImageWithinRenderPass) {
Mark Lobodzinskid5639502015-09-24 09:51:47 -06009958 // Call CmdClearColorImage within an active RenderPass
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009959 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
9960 "It is invalid to issue this call inside an active render pass");
Mark Lobodzinskid5639502015-09-24 09:51:47 -06009961
9962 ASSERT_NO_FATAL_FAILURE(InitState());
9963 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Mark Lobodzinskid5639502015-09-24 09:51:47 -06009964
9965 // Renderpass is started here
9966 BeginCommandBuffer();
9967
Michael Lentine0a369f62016-02-03 16:51:46 -06009968 VkClearColorValue clear_color;
9969 memset(clear_color.uint32, 0, sizeof(uint32_t) * 4);
Karl Schultz6addd812016-02-02 17:17:23 -07009970 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
9971 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
9972 const int32_t tex_width = 32;
9973 const int32_t tex_height = 32;
9974 VkImageCreateInfo image_create_info = {};
9975 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
9976 image_create_info.pNext = NULL;
9977 image_create_info.imageType = VK_IMAGE_TYPE_2D;
9978 image_create_info.format = tex_format;
9979 image_create_info.extent.width = tex_width;
9980 image_create_info.extent.height = tex_height;
9981 image_create_info.extent.depth = 1;
9982 image_create_info.mipLevels = 1;
9983 image_create_info.arrayLayers = 1;
9984 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
9985 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
9986 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
Mark Lobodzinskid5639502015-09-24 09:51:47 -06009987
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009988 vk_testing::Image dstImage;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009989 dstImage.init(*m_device, (const VkImageCreateInfo &)image_create_info, reqs);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06009990
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009991 const VkImageSubresourceRange range = vk_testing::Image::subresource_range(image_create_info, VK_IMAGE_ASPECT_COLOR_BIT);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06009992
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009993 vkCmdClearColorImage(m_commandBuffer->GetBufferHandle(), dstImage.handle(), VK_IMAGE_LAYOUT_GENERAL, &clear_color, 1, &range);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06009994
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009995 m_errorMonitor->VerifyFound();
Mark Lobodzinskid5639502015-09-24 09:51:47 -06009996}
9997
Karl Schultz6addd812016-02-02 17:17:23 -07009998TEST_F(VkLayerTest, ClearDepthStencilImageWithinRenderPass) {
Mark Lobodzinskid5639502015-09-24 09:51:47 -06009999 // Call CmdClearDepthStencilImage within an active RenderPass
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010000 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
10001 "It is invalid to issue this call inside an active render pass");
Mark Lobodzinskid5639502015-09-24 09:51:47 -060010002
10003 ASSERT_NO_FATAL_FAILURE(InitState());
10004 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Mark Lobodzinskid5639502015-09-24 09:51:47 -060010005
10006 // Renderpass is started here
10007 BeginCommandBuffer();
10008
10009 VkClearDepthStencilValue clear_value = {0};
Dustin Gravesa2e5c942016-02-11 18:28:06 -070010010 VkMemoryPropertyFlags reqs = 0;
Karl Schultz6addd812016-02-02 17:17:23 -070010011 VkImageCreateInfo image_create_info = vk_testing::Image::create_info();
10012 image_create_info.imageType = VK_IMAGE_TYPE_2D;
10013 image_create_info.format = VK_FORMAT_D24_UNORM_S8_UINT;
10014 image_create_info.extent.width = 64;
10015 image_create_info.extent.height = 64;
10016 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
10017 image_create_info.usage = VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT;
Mark Lobodzinskid5639502015-09-24 09:51:47 -060010018
Chia-I Wu3432a0c2015-10-27 18:04:07 +080010019 vk_testing::Image dstImage;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010020 dstImage.init(*m_device, (const VkImageCreateInfo &)image_create_info, reqs);
Mark Lobodzinskid5639502015-09-24 09:51:47 -060010021
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010022 const VkImageSubresourceRange range = vk_testing::Image::subresource_range(image_create_info, VK_IMAGE_ASPECT_DEPTH_BIT);
Mark Lobodzinskid5639502015-09-24 09:51:47 -060010023
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010024 vkCmdClearDepthStencilImage(m_commandBuffer->GetBufferHandle(), dstImage.handle(),
10025 VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL, &clear_value, 1, &range);
Mark Lobodzinskid5639502015-09-24 09:51:47 -060010026
Chris Forbes8f36a8a2016-04-07 13:21:07 +120010027 m_errorMonitor->VerifyFound();
Mark Lobodzinskid5639502015-09-24 09:51:47 -060010028}
10029
Karl Schultz6addd812016-02-02 17:17:23 -070010030TEST_F(VkLayerTest, ClearColorAttachmentsOutsideRenderPass) {
Courtney Goeltzenleuchterc9323e02015-10-15 16:51:05 -060010031 // Call CmdClearAttachmentss outside of an active RenderPass
Karl Schultz6addd812016-02-02 17:17:23 -070010032 VkResult err;
Mark Lobodzinskid5639502015-09-24 09:51:47 -060010033
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010034 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "vkCmdClearAttachments(): This call "
10035 "must be issued inside an active "
10036 "render pass");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060010037
Mark Lobodzinskid5639502015-09-24 09:51:47 -060010038 ASSERT_NO_FATAL_FAILURE(InitState());
10039 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Mark Lobodzinskid5639502015-09-24 09:51:47 -060010040
10041 // Start no RenderPass
Chia-I Wu3432a0c2015-10-27 18:04:07 +080010042 err = m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskid5639502015-09-24 09:51:47 -060010043 ASSERT_VK_SUCCESS(err);
10044
Courtney Goeltzenleuchterc9323e02015-10-15 16:51:05 -060010045 VkClearAttachment color_attachment;
10046 color_attachment.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
10047 color_attachment.clearValue.color.float32[0] = 0;
10048 color_attachment.clearValue.color.float32[1] = 0;
10049 color_attachment.clearValue.color.float32[2] = 0;
10050 color_attachment.clearValue.color.float32[3] = 0;
10051 color_attachment.colorAttachment = 0;
Karl Schultz6addd812016-02-02 17:17:23 -070010052 VkClearRect clear_rect = {{{0, 0}, {32, 32}}};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010053 vkCmdClearAttachments(m_commandBuffer->GetBufferHandle(), 1, &color_attachment, 1, &clear_rect);
Mark Lobodzinskid5639502015-09-24 09:51:47 -060010054
Chris Forbes8f36a8a2016-04-07 13:21:07 +120010055 m_errorMonitor->VerifyFound();
Mark Lobodzinskid5639502015-09-24 09:51:47 -060010056}
10057
Chris Forbes3b97e932016-09-07 11:29:24 +120010058TEST_F(VkLayerTest, RenderPassExcessiveNextSubpass) {
10059 TEST_DESCRIPTION("Test that an error is produced when CmdNextSubpass is "
10060 "called too many times in a renderpass instance");
10061
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010062 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "vkCmdNextSubpass(): Attempted to advance "
10063 "beyond final subpass");
Chris Forbes3b97e932016-09-07 11:29:24 +120010064
10065 ASSERT_NO_FATAL_FAILURE(InitState());
10066 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
10067
10068 BeginCommandBuffer();
10069
10070 // error here.
10071 vkCmdNextSubpass(m_commandBuffer->GetBufferHandle(), VK_SUBPASS_CONTENTS_INLINE);
10072 m_errorMonitor->VerifyFound();
10073
10074 EndCommandBuffer();
10075}
10076
Chris Forbes6d624702016-09-07 13:57:05 +120010077TEST_F(VkLayerTest, RenderPassEndedBeforeFinalSubpass) {
10078 TEST_DESCRIPTION("Test that an error is produced when CmdEndRenderPass is "
10079 "called before the final subpass has been reached");
10080
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010081 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "vkCmdEndRenderPass(): Called before reaching "
10082 "final subpass");
Chris Forbes6d624702016-09-07 13:57:05 +120010083
10084 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010085 VkSubpassDescription sd[2] = {{0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 0, nullptr, nullptr, nullptr, 0, nullptr},
10086 {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 0, nullptr, nullptr, nullptr, 0, nullptr}};
Chris Forbes6d624702016-09-07 13:57:05 +120010087
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010088 VkRenderPassCreateInfo rcpi = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 0, nullptr, 2, sd, 0, nullptr};
Chris Forbes6d624702016-09-07 13:57:05 +120010089
10090 VkRenderPass rp;
10091 VkResult err = vkCreateRenderPass(m_device->device(), &rcpi, nullptr, &rp);
10092 ASSERT_VK_SUCCESS(err);
10093
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010094 VkFramebufferCreateInfo fbci = {VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr, 0, rp, 0, nullptr, 16, 16, 1};
Chris Forbes6d624702016-09-07 13:57:05 +120010095
10096 VkFramebuffer fb;
10097 err = vkCreateFramebuffer(m_device->device(), &fbci, nullptr, &fb);
10098 ASSERT_VK_SUCCESS(err);
10099
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010100 m_commandBuffer->BeginCommandBuffer(); // no implicit RP begin
Chris Forbes6d624702016-09-07 13:57:05 +120010101
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010102 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 +120010103
10104 vkCmdBeginRenderPass(m_commandBuffer->GetBufferHandle(), &rpbi, VK_SUBPASS_CONTENTS_INLINE);
10105
10106 // Error here.
10107 vkCmdEndRenderPass(m_commandBuffer->GetBufferHandle());
10108 m_errorMonitor->VerifyFound();
10109
10110 // Clean up.
10111 vkDestroyFramebuffer(m_device->device(), fb, nullptr);
10112 vkDestroyRenderPass(m_device->device(), rp, nullptr);
10113}
10114
Karl Schultz9e66a292016-04-21 15:57:51 -060010115TEST_F(VkLayerTest, BufferMemoryBarrierNoBuffer) {
10116 // Try to add a buffer memory barrier with no buffer.
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010117 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
10118 "required parameter pBufferMemoryBarriers[0].buffer specified as VK_NULL_HANDLE");
Karl Schultz9e66a292016-04-21 15:57:51 -060010119
10120 ASSERT_NO_FATAL_FAILURE(InitState());
10121 BeginCommandBuffer();
10122
10123 VkBufferMemoryBarrier buf_barrier = {};
10124 buf_barrier.sType = VK_STRUCTURE_TYPE_BUFFER_MEMORY_BARRIER;
10125 buf_barrier.srcAccessMask = VK_ACCESS_HOST_WRITE_BIT;
10126 buf_barrier.dstAccessMask = VK_ACCESS_SHADER_READ_BIT;
10127 buf_barrier.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
10128 buf_barrier.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
10129 buf_barrier.buffer = VK_NULL_HANDLE;
10130 buf_barrier.offset = 0;
10131 buf_barrier.size = VK_WHOLE_SIZE;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010132 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
10133 nullptr, 1, &buf_barrier, 0, nullptr);
Karl Schultz9e66a292016-04-21 15:57:51 -060010134
10135 m_errorMonitor->VerifyFound();
10136}
10137
Tony Barbour7fd5c0f2016-05-03 16:11:53 -060010138TEST_F(VkLayerTest, InvalidBarriers) {
10139 TEST_DESCRIPTION("A variety of ways to get VK_INVALID_BARRIER ");
10140
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010141 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Barriers cannot be set during subpass");
Tony Barbour7fd5c0f2016-05-03 16:11:53 -060010142
10143 ASSERT_NO_FATAL_FAILURE(InitState());
10144 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
10145
10146 VkMemoryBarrier mem_barrier = {};
10147 mem_barrier.sType = VK_STRUCTURE_TYPE_MEMORY_BARRIER;
10148 mem_barrier.pNext = NULL;
10149 mem_barrier.srcAccessMask = VK_ACCESS_HOST_WRITE_BIT;
10150 mem_barrier.dstAccessMask = VK_ACCESS_SHADER_READ_BIT;
10151 BeginCommandBuffer();
10152 // BeginCommandBuffer() starts a render pass
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010153 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 1,
Tony Barbour7fd5c0f2016-05-03 16:11:53 -060010154 &mem_barrier, 0, nullptr, 0, nullptr);
10155 m_errorMonitor->VerifyFound();
10156
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010157 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Image Layout cannot be transitioned to UNDEFINED");
Tony Barbour7fd5c0f2016-05-03 16:11:53 -060010158 VkImageObj image(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010159 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 -060010160 ASSERT_TRUE(image.initialized());
10161 VkImageMemoryBarrier img_barrier = {};
10162 img_barrier.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
10163 img_barrier.pNext = NULL;
10164 img_barrier.srcAccessMask = VK_ACCESS_HOST_WRITE_BIT;
10165 img_barrier.dstAccessMask = VK_ACCESS_SHADER_READ_BIT;
10166 img_barrier.oldLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
10167 // New layout can't be UNDEFINED
10168 img_barrier.newLayout = VK_IMAGE_LAYOUT_UNDEFINED;
10169 img_barrier.image = image.handle();
10170 img_barrier.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
10171 img_barrier.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
10172 img_barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
10173 img_barrier.subresourceRange.baseArrayLayer = 0;
10174 img_barrier.subresourceRange.baseMipLevel = 0;
10175 img_barrier.subresourceRange.layerCount = 1;
10176 img_barrier.subresourceRange.levelCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010177 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
10178 nullptr, 0, nullptr, 1, &img_barrier);
Tony Barbour7fd5c0f2016-05-03 16:11:53 -060010179 m_errorMonitor->VerifyFound();
10180 img_barrier.newLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
10181
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010182 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Subresource must have the sum of the "
10183 "baseArrayLayer");
Tony Barbour7fd5c0f2016-05-03 16:11:53 -060010184 // baseArrayLayer + layerCount must be <= image's arrayLayers
10185 img_barrier.subresourceRange.baseArrayLayer = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010186 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
10187 nullptr, 0, nullptr, 1, &img_barrier);
Tony Barbour7fd5c0f2016-05-03 16:11:53 -060010188 m_errorMonitor->VerifyFound();
10189 img_barrier.subresourceRange.baseArrayLayer = 0;
10190
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010191 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Subresource must have the sum of the baseMipLevel");
Tony Barbour7fd5c0f2016-05-03 16:11:53 -060010192 // baseMipLevel + levelCount must be <= image's mipLevels
10193 img_barrier.subresourceRange.baseMipLevel = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010194 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
10195 nullptr, 0, nullptr, 1, &img_barrier);
Tony Barbour7fd5c0f2016-05-03 16:11:53 -060010196 m_errorMonitor->VerifyFound();
10197 img_barrier.subresourceRange.baseMipLevel = 0;
10198
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010199 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 -060010200 vk_testing::Buffer buffer;
10201 buffer.init(*m_device, 256);
10202 VkBufferMemoryBarrier buf_barrier = {};
10203 buf_barrier.sType = VK_STRUCTURE_TYPE_BUFFER_MEMORY_BARRIER;
10204 buf_barrier.pNext = NULL;
10205 buf_barrier.srcAccessMask = VK_ACCESS_HOST_WRITE_BIT;
10206 buf_barrier.dstAccessMask = VK_ACCESS_SHADER_READ_BIT;
10207 buf_barrier.buffer = buffer.handle();
10208 buf_barrier.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
10209 buf_barrier.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
10210 buf_barrier.offset = 0;
10211 buf_barrier.size = VK_WHOLE_SIZE;
10212 // Can't send buffer barrier during a render pass
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010213 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
10214 nullptr, 1, &buf_barrier, 0, nullptr);
Tony Barbour7fd5c0f2016-05-03 16:11:53 -060010215 m_errorMonitor->VerifyFound();
10216 vkCmdEndRenderPass(m_commandBuffer->GetBufferHandle());
10217
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010218 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "which is not less than total size");
Tony Barbour7fd5c0f2016-05-03 16:11:53 -060010219 buf_barrier.offset = 257;
10220 // Offset greater than total size
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010221 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
10222 nullptr, 1, &buf_barrier, 0, nullptr);
Tony Barbour7fd5c0f2016-05-03 16:11:53 -060010223 m_errorMonitor->VerifyFound();
10224 buf_barrier.offset = 0;
10225
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010226 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "whose sum is greater than total size");
Tony Barbour7fd5c0f2016-05-03 16:11:53 -060010227 buf_barrier.size = 257;
10228 // Size greater than total size
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010229 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
10230 nullptr, 1, &buf_barrier, 0, nullptr);
Tony Barbour7fd5c0f2016-05-03 16:11:53 -060010231 m_errorMonitor->VerifyFound();
Tony Barbour7fd5c0f2016-05-03 16:11:53 -060010232
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -060010233 // Now exercise barrier aspect bit errors, first DS
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010234 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Image is a depth and stencil format and thus must "
10235 "have either one or both of VK_IMAGE_ASPECT_DEPTH_BIT and "
10236 "VK_IMAGE_ASPECT_STENCIL_BIT set.");
Tony Barbour7fd5c0f2016-05-03 16:11:53 -060010237 VkDepthStencilObj ds_image(m_device);
10238 ds_image.Init(m_device, 128, 128, VK_FORMAT_D24_UNORM_S8_UINT);
10239 ASSERT_TRUE(ds_image.initialized());
Tobin Ehlis15684a02016-07-21 14:55:26 -060010240 img_barrier.oldLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
10241 img_barrier.newLayout = VK_IMAGE_LAYOUT_GENERAL;
Tony Barbour7fd5c0f2016-05-03 16:11:53 -060010242 img_barrier.image = ds_image.handle();
Tobin Ehlis15684a02016-07-21 14:55:26 -060010243 // Use of COLOR aspect on DS image is error
10244 img_barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010245 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
10246 nullptr, 0, nullptr, 1, &img_barrier);
Tony Barbour7fd5c0f2016-05-03 16:11:53 -060010247 m_errorMonitor->VerifyFound();
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -060010248 // Now test depth-only
10249 VkFormatProperties format_props;
10250
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010251 vkGetPhysicalDeviceFormatProperties(m_device->phy().handle(), VK_FORMAT_D16_UNORM, &format_props);
10252 if (format_props.optimalTilingFeatures & VK_FORMAT_FEATURE_DEPTH_STENCIL_ATTACHMENT_BIT) {
10253 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Image is a depth-only format and thus must "
10254 "have VK_IMAGE_ASPECT_DEPTH_BIT set.");
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -060010255 VkDepthStencilObj d_image(m_device);
10256 d_image.Init(m_device, 128, 128, VK_FORMAT_D16_UNORM);
10257 ASSERT_TRUE(d_image.initialized());
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010258 img_barrier.oldLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
Tobin Ehlis15684a02016-07-21 14:55:26 -060010259 img_barrier.newLayout = VK_IMAGE_LAYOUT_GENERAL;
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -060010260 img_barrier.image = d_image.handle();
Tobin Ehlis15684a02016-07-21 14:55:26 -060010261 // Use of COLOR aspect on depth image is error
10262 img_barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010263 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0,
10264 0, nullptr, 0, nullptr, 1, &img_barrier);
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -060010265 m_errorMonitor->VerifyFound();
10266 }
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010267 vkGetPhysicalDeviceFormatProperties(m_device->phy().handle(), VK_FORMAT_S8_UINT, &format_props);
10268 if (format_props.optimalTilingFeatures & VK_FORMAT_FEATURE_DEPTH_STENCIL_ATTACHMENT_BIT) {
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -060010269 // Now test stencil-only
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010270 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Image is a stencil-only format and thus must "
10271 "have VK_IMAGE_ASPECT_STENCIL_BIT set.");
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -060010272 VkDepthStencilObj s_image(m_device);
10273 s_image.Init(m_device, 128, 128, VK_FORMAT_S8_UINT);
10274 ASSERT_TRUE(s_image.initialized());
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010275 img_barrier.oldLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
Tobin Ehlis15684a02016-07-21 14:55:26 -060010276 img_barrier.newLayout = VK_IMAGE_LAYOUT_GENERAL;
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -060010277 img_barrier.image = s_image.handle();
Tobin Ehlis15684a02016-07-21 14:55:26 -060010278 // Use of COLOR aspect on depth image is error
10279 img_barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010280 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0,
10281 0, nullptr, 0, nullptr, 1, &img_barrier);
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -060010282 m_errorMonitor->VerifyFound();
10283 }
10284 // Finally test color
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010285 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Image is a color format and thus must "
10286 "have VK_IMAGE_ASPECT_COLOR_BIT set.");
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -060010287 VkImageObj c_image(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010288 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 -060010289 ASSERT_TRUE(c_image.initialized());
10290 img_barrier.oldLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
10291 img_barrier.newLayout = VK_IMAGE_LAYOUT_GENERAL;
10292 img_barrier.image = c_image.handle();
10293 // Set aspect to depth (non-color)
10294 img_barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010295 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
10296 nullptr, 0, nullptr, 1, &img_barrier);
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -060010297 m_errorMonitor->VerifyFound();
Tony Barbour7fd5c0f2016-05-03 16:11:53 -060010298}
10299
Karl Schultz6addd812016-02-02 17:17:23 -070010300TEST_F(VkLayerTest, IdxBufferAlignmentError) {
Tobin Ehlisc4c23182015-09-17 12:24:13 -060010301 // Bind a BeginRenderPass within an active RenderPass
Karl Schultz6addd812016-02-02 17:17:23 -070010302 VkResult err;
Tobin Ehlisc4c23182015-09-17 12:24:13 -060010303
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010304 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "vkCmdBindIndexBuffer() offset (0x7) does not fall on ");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060010305
Tobin Ehlisc4c23182015-09-17 12:24:13 -060010306 ASSERT_NO_FATAL_FAILURE(InitState());
10307 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlisc4c23182015-09-17 12:24:13 -060010308 uint32_t qfi = 0;
10309 VkBufferCreateInfo buffCI = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010310 buffCI.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
10311 buffCI.size = 1024;
10312 buffCI.usage = VK_BUFFER_USAGE_INDEX_BUFFER_BIT;
10313 buffCI.queueFamilyIndexCount = 1;
10314 buffCI.pQueueFamilyIndices = &qfi;
Tobin Ehlisc4c23182015-09-17 12:24:13 -060010315
10316 VkBuffer ib;
Chia-I Wuf7458c52015-10-26 21:10:41 +080010317 err = vkCreateBuffer(m_device->device(), &buffCI, NULL, &ib);
Tobin Ehlisc4c23182015-09-17 12:24:13 -060010318 ASSERT_VK_SUCCESS(err);
10319
10320 BeginCommandBuffer();
10321 ASSERT_VK_SUCCESS(err);
Karl Schultz6addd812016-02-02 17:17:23 -070010322 // vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(),
10323 // VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Tobin Ehlisc4c23182015-09-17 12:24:13 -060010324 // Should error before calling to driver so don't care about actual data
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010325 vkCmdBindIndexBuffer(m_commandBuffer->GetBufferHandle(), ib, 7, VK_INDEX_TYPE_UINT16);
Tobin Ehlisc4c23182015-09-17 12:24:13 -060010326
Chris Forbes8f36a8a2016-04-07 13:21:07 +120010327 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -060010328
Chia-I Wuf7458c52015-10-26 21:10:41 +080010329 vkDestroyBuffer(m_device->device(), ib, NULL);
Tobin Ehlisc4c23182015-09-17 12:24:13 -060010330}
10331
Mark Lobodzinski52a6e7d2016-02-25 15:09:52 -070010332TEST_F(VkLayerTest, InvalidQueueFamilyIndex) {
10333 // Create an out-of-range queueFamilyIndex
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010334 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
10335 "vkCreateBuffer: pCreateInfo->pQueueFamilyIndices[0] (777) must be one "
10336 "of the indices specified when the device was created, via the "
10337 "VkDeviceQueueCreateInfo structure.");
Mark Lobodzinski52a6e7d2016-02-25 15:09:52 -070010338
10339 ASSERT_NO_FATAL_FAILURE(InitState());
10340 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
10341 VkBufferCreateInfo buffCI = {};
10342 buffCI.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
10343 buffCI.size = 1024;
10344 buffCI.usage = VK_BUFFER_USAGE_INDEX_BUFFER_BIT;
10345 buffCI.queueFamilyIndexCount = 1;
10346 // Introduce failure by specifying invalid queue_family_index
10347 uint32_t qfi = 777;
10348 buffCI.pQueueFamilyIndices = &qfi;
Tobin Ehlis24aab042016-03-24 10:54:18 -060010349 buffCI.sharingMode = VK_SHARING_MODE_CONCURRENT; // qfi only matters in CONCURRENT mode
Mark Lobodzinski52a6e7d2016-02-25 15:09:52 -070010350
10351 VkBuffer ib;
10352 vkCreateBuffer(m_device->device(), &buffCI, NULL, &ib);
10353
Chris Forbes8f36a8a2016-04-07 13:21:07 +120010354 m_errorMonitor->VerifyFound();
Tony Barbourdf4c0042016-06-01 15:55:43 -060010355 vkDestroyBuffer(m_device->device(), ib, NULL);
Mark Lobodzinski52a6e7d2016-02-25 15:09:52 -070010356}
10357
Karl Schultz6addd812016-02-02 17:17:23 -070010358TEST_F(VkLayerTest, ExecuteCommandsPrimaryCB) {
Tobin Ehlis0c94db02016-07-19 10:49:32 -060010359 TEST_DESCRIPTION("Attempt vkCmdExecuteCommands w/ a primary cmd buffer"
10360 " (should only be secondary)");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060010361
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010362 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "vkCmdExecuteCommands() called w/ Primary Cmd Buffer ");
Tobin Ehlis4b34ddc2015-09-17 14:18:16 -060010363
10364 ASSERT_NO_FATAL_FAILURE(InitState());
10365 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlis4b34ddc2015-09-17 14:18:16 -060010366
10367 BeginCommandBuffer();
Tobin Ehlis0c94db02016-07-19 10:49:32 -060010368
Chia-I Wu3432a0c2015-10-27 18:04:07 +080010369 VkCommandBuffer primCB = m_commandBuffer->GetBufferHandle();
10370 vkCmdExecuteCommands(m_commandBuffer->GetBufferHandle(), 1, &primCB);
Tobin Ehlis4b34ddc2015-09-17 14:18:16 -060010371
Chris Forbes8f36a8a2016-04-07 13:21:07 +120010372 m_errorMonitor->VerifyFound();
Tobin Ehlis4b34ddc2015-09-17 14:18:16 -060010373}
10374
Tobin Ehlis17826bd2016-05-25 11:12:50 -060010375TEST_F(VkLayerTest, DSUsageBitsErrors) {
10376 TEST_DESCRIPTION("Attempt to update descriptor sets for images and buffers "
10377 "that do not have correct usage bits sets.");
10378 VkResult err;
10379
10380 ASSERT_NO_FATAL_FAILURE(InitState());
10381 VkDescriptorPoolSize ds_type_count[VK_DESCRIPTOR_TYPE_RANGE_SIZE] = {};
10382 for (uint32_t i = 0; i < VK_DESCRIPTOR_TYPE_RANGE_SIZE; ++i) {
10383 ds_type_count[i].type = VkDescriptorType(i);
10384 ds_type_count[i].descriptorCount = 1;
10385 }
10386 VkDescriptorPoolCreateInfo ds_pool_ci = {};
10387 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
10388 ds_pool_ci.pNext = NULL;
10389 ds_pool_ci.maxSets = VK_DESCRIPTOR_TYPE_RANGE_SIZE;
10390 ds_pool_ci.poolSizeCount = VK_DESCRIPTOR_TYPE_RANGE_SIZE;
10391 ds_pool_ci.pPoolSizes = ds_type_count;
10392
10393 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010394 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis17826bd2016-05-25 11:12:50 -060010395 ASSERT_VK_SUCCESS(err);
10396
10397 // Create 10 layouts where each has a single descriptor of different type
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010398 VkDescriptorSetLayoutBinding dsl_binding[VK_DESCRIPTOR_TYPE_RANGE_SIZE] = {};
Tobin Ehlis17826bd2016-05-25 11:12:50 -060010399 for (uint32_t i = 0; i < VK_DESCRIPTOR_TYPE_RANGE_SIZE; ++i) {
10400 dsl_binding[i].binding = 0;
10401 dsl_binding[i].descriptorType = VkDescriptorType(i);
10402 dsl_binding[i].descriptorCount = 1;
10403 dsl_binding[i].stageFlags = VK_SHADER_STAGE_ALL;
10404 dsl_binding[i].pImmutableSamplers = NULL;
10405 }
10406
10407 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
10408 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
10409 ds_layout_ci.pNext = NULL;
10410 ds_layout_ci.bindingCount = 1;
10411 VkDescriptorSetLayout ds_layouts[VK_DESCRIPTOR_TYPE_RANGE_SIZE];
10412 for (uint32_t i = 0; i < VK_DESCRIPTOR_TYPE_RANGE_SIZE; ++i) {
10413 ds_layout_ci.pBindings = dsl_binding + i;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010414 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, ds_layouts + i);
Tobin Ehlis17826bd2016-05-25 11:12:50 -060010415 ASSERT_VK_SUCCESS(err);
10416 }
10417 VkDescriptorSet descriptor_sets[VK_DESCRIPTOR_TYPE_RANGE_SIZE] = {};
10418 VkDescriptorSetAllocateInfo alloc_info = {};
10419 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
10420 alloc_info.descriptorSetCount = VK_DESCRIPTOR_TYPE_RANGE_SIZE;
10421 alloc_info.descriptorPool = ds_pool;
10422 alloc_info.pSetLayouts = ds_layouts;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010423 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, descriptor_sets);
Tobin Ehlis17826bd2016-05-25 11:12:50 -060010424 ASSERT_VK_SUCCESS(err);
10425
10426 // Create a buffer & bufferView to be used for invalid updates
10427 VkBufferCreateInfo buff_ci = {};
10428 buff_ci.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
10429 // This usage is not valid for any descriptor type
10430 buff_ci.usage = VK_BUFFER_USAGE_TRANSFER_SRC_BIT;
10431 buff_ci.size = 256;
10432 buff_ci.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
10433 VkBuffer buffer;
10434 err = vkCreateBuffer(m_device->device(), &buff_ci, NULL, &buffer);
10435 ASSERT_VK_SUCCESS(err);
10436
10437 VkBufferViewCreateInfo buff_view_ci = {};
10438 buff_view_ci.sType = VK_STRUCTURE_TYPE_BUFFER_VIEW_CREATE_INFO;
10439 buff_view_ci.buffer = buffer;
10440 buff_view_ci.format = VK_FORMAT_R8_UNORM;
10441 buff_view_ci.range = VK_WHOLE_SIZE;
10442 VkBufferView buff_view;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010443 err = vkCreateBufferView(m_device->device(), &buff_view_ci, NULL, &buff_view);
Tobin Ehlis17826bd2016-05-25 11:12:50 -060010444 ASSERT_VK_SUCCESS(err);
10445
10446 // Create an image to be used for invalid updates
10447 VkImageCreateInfo image_ci = {};
10448 image_ci.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
10449 image_ci.imageType = VK_IMAGE_TYPE_2D;
10450 image_ci.format = VK_FORMAT_R8G8B8A8_UNORM;
10451 image_ci.extent.width = 64;
10452 image_ci.extent.height = 64;
10453 image_ci.extent.depth = 1;
10454 image_ci.mipLevels = 1;
10455 image_ci.arrayLayers = 1;
10456 image_ci.samples = VK_SAMPLE_COUNT_1_BIT;
10457 image_ci.tiling = VK_IMAGE_TILING_LINEAR;
10458 image_ci.initialLayout = VK_IMAGE_LAYOUT_PREINITIALIZED;
10459 // This usage is not valid for any descriptor type
10460 image_ci.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
10461 image_ci.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
10462 VkImage image;
10463 err = vkCreateImage(m_device->device(), &image_ci, NULL, &image);
10464 ASSERT_VK_SUCCESS(err);
10465 // Bind memory to image
10466 VkMemoryRequirements mem_reqs;
10467 VkDeviceMemory image_mem;
10468 bool pass;
10469 VkMemoryAllocateInfo mem_alloc = {};
10470 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
10471 mem_alloc.pNext = NULL;
10472 mem_alloc.allocationSize = 0;
10473 mem_alloc.memoryTypeIndex = 0;
10474 vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs);
10475 mem_alloc.allocationSize = mem_reqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010476 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0);
Tobin Ehlis17826bd2016-05-25 11:12:50 -060010477 ASSERT_TRUE(pass);
10478 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &image_mem);
10479 ASSERT_VK_SUCCESS(err);
10480 err = vkBindImageMemory(m_device->device(), image, image_mem, 0);
10481 ASSERT_VK_SUCCESS(err);
10482 // Now create view for image
10483 VkImageViewCreateInfo image_view_ci = {};
10484 image_view_ci.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
10485 image_view_ci.image = image;
10486 image_view_ci.format = VK_FORMAT_R8G8B8A8_UNORM;
10487 image_view_ci.viewType = VK_IMAGE_VIEW_TYPE_2D;
10488 image_view_ci.subresourceRange.layerCount = 1;
10489 image_view_ci.subresourceRange.baseArrayLayer = 0;
10490 image_view_ci.subresourceRange.levelCount = 1;
10491 image_view_ci.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
10492 VkImageView image_view;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010493 err = vkCreateImageView(m_device->device(), &image_view_ci, NULL, &image_view);
Tobin Ehlis17826bd2016-05-25 11:12:50 -060010494 ASSERT_VK_SUCCESS(err);
10495
10496 VkDescriptorBufferInfo buff_info = {};
10497 buff_info.buffer = buffer;
10498 VkDescriptorImageInfo img_info = {};
10499 img_info.imageView = image_view;
10500 VkWriteDescriptorSet descriptor_write = {};
10501 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
10502 descriptor_write.dstBinding = 0;
10503 descriptor_write.descriptorCount = 1;
10504 descriptor_write.pTexelBufferView = &buff_view;
10505 descriptor_write.pBufferInfo = &buff_info;
10506 descriptor_write.pImageInfo = &img_info;
10507
10508 // These error messages align with VkDescriptorType struct
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010509 const char *error_msgs[] = {"", // placeholder, no error for SAMPLER descriptor
10510 " does not have VK_IMAGE_USAGE_SAMPLED_BIT set.",
10511 " does not have VK_IMAGE_USAGE_SAMPLED_BIT set.",
10512 " does not have VK_IMAGE_USAGE_STORAGE_BIT set.",
10513 " does not have VK_BUFFER_USAGE_UNIFORM_TEXEL_BUFFER_BIT set.",
10514 " does not have VK_BUFFER_USAGE_STORAGE_TEXEL_BUFFER_BIT set.",
10515 " does not have VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT set.",
10516 " does not have VK_BUFFER_USAGE_STORAGE_BUFFER_BIT set.",
10517 " does not have VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT set.",
10518 " does not have VK_BUFFER_USAGE_STORAGE_BUFFER_BIT set.",
10519 " does not have VK_IMAGE_USAGE_INPUT_ATTACHMENT_BIT set."};
Tobin Ehlis17826bd2016-05-25 11:12:50 -060010520 // Start loop at 1 as SAMPLER desc type has no usage bit error
10521 for (uint32_t i = 1; i < VK_DESCRIPTOR_TYPE_RANGE_SIZE; ++i) {
10522 descriptor_write.descriptorType = VkDescriptorType(i);
10523 descriptor_write.dstSet = descriptor_sets[i];
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010524 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, error_msgs[i]);
Tobin Ehlis17826bd2016-05-25 11:12:50 -060010525
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010526 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
Tobin Ehlis17826bd2016-05-25 11:12:50 -060010527
10528 m_errorMonitor->VerifyFound();
10529 vkDestroyDescriptorSetLayout(m_device->device(), ds_layouts[i], NULL);
10530 }
10531 vkDestroyDescriptorSetLayout(m_device->device(), ds_layouts[0], NULL);
10532 vkDestroyImage(m_device->device(), image, NULL);
Tony Barbourdf4c0042016-06-01 15:55:43 -060010533 vkFreeMemory(m_device->device(), image_mem, NULL);
Tobin Ehlis17826bd2016-05-25 11:12:50 -060010534 vkDestroyImageView(m_device->device(), image_view, NULL);
10535 vkDestroyBuffer(m_device->device(), buffer, NULL);
10536 vkDestroyBufferView(m_device->device(), buff_view, NULL);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010537 vkFreeDescriptorSets(m_device->device(), ds_pool, VK_DESCRIPTOR_TYPE_RANGE_SIZE, descriptor_sets);
Tobin Ehlis17826bd2016-05-25 11:12:50 -060010538 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
10539}
10540
Tobin Ehlis585f66d2016-07-01 18:23:58 -060010541TEST_F(VkLayerTest, DSBufferInfoErrors) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010542 TEST_DESCRIPTION("Attempt to update buffer descriptor set that has incorrect "
10543 "parameters in VkDescriptorBufferInfo struct. This includes:\n"
10544 "1. offset value greater than buffer size\n"
10545 "2. range value of 0\n"
10546 "3. range value greater than buffer (size - offset)");
Tobin Ehlis585f66d2016-07-01 18:23:58 -060010547 VkResult err;
10548
10549 ASSERT_NO_FATAL_FAILURE(InitState());
10550 VkDescriptorPoolSize ds_type_count = {};
10551 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
10552 ds_type_count.descriptorCount = 1;
10553
10554 VkDescriptorPoolCreateInfo ds_pool_ci = {};
10555 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
10556 ds_pool_ci.pNext = NULL;
10557 ds_pool_ci.maxSets = 1;
10558 ds_pool_ci.poolSizeCount = 1;
10559 ds_pool_ci.pPoolSizes = &ds_type_count;
10560
10561 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010562 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis585f66d2016-07-01 18:23:58 -060010563 ASSERT_VK_SUCCESS(err);
10564
10565 // Create layout with single uniform buffer descriptor
10566 VkDescriptorSetLayoutBinding dsl_binding = {};
10567 dsl_binding.binding = 0;
10568 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
10569 dsl_binding.descriptorCount = 1;
10570 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
10571 dsl_binding.pImmutableSamplers = NULL;
10572
10573 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
10574 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
10575 ds_layout_ci.pNext = NULL;
10576 ds_layout_ci.bindingCount = 1;
10577 ds_layout_ci.pBindings = &dsl_binding;
10578 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010579 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis585f66d2016-07-01 18:23:58 -060010580 ASSERT_VK_SUCCESS(err);
10581
10582 VkDescriptorSet descriptor_set = {};
10583 VkDescriptorSetAllocateInfo alloc_info = {};
10584 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
10585 alloc_info.descriptorSetCount = 1;
10586 alloc_info.descriptorPool = ds_pool;
10587 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010588 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
Tobin Ehlis585f66d2016-07-01 18:23:58 -060010589 ASSERT_VK_SUCCESS(err);
10590
10591 // Create a buffer to be used for invalid updates
10592 VkBufferCreateInfo buff_ci = {};
10593 buff_ci.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
10594 buff_ci.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
10595 buff_ci.size = 256;
10596 buff_ci.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
10597 VkBuffer buffer;
10598 err = vkCreateBuffer(m_device->device(), &buff_ci, NULL, &buffer);
10599 ASSERT_VK_SUCCESS(err);
10600 // Have to bind memory to buffer before descriptor update
10601 VkMemoryAllocateInfo mem_alloc = {};
10602 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
10603 mem_alloc.pNext = NULL;
10604 mem_alloc.allocationSize = 256;
10605 mem_alloc.memoryTypeIndex = 0;
10606
10607 VkMemoryRequirements mem_reqs;
10608 vkGetBufferMemoryRequirements(m_device->device(), buffer, &mem_reqs);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010609 bool pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0);
Tobin Ehlis585f66d2016-07-01 18:23:58 -060010610 if (!pass) {
10611 vkDestroyBuffer(m_device->device(), buffer, NULL);
10612 return;
10613 }
10614
10615 VkDeviceMemory mem;
10616 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem);
10617 ASSERT_VK_SUCCESS(err);
10618 err = vkBindBufferMemory(m_device->device(), buffer, mem, 0);
10619 ASSERT_VK_SUCCESS(err);
10620
10621 VkDescriptorBufferInfo buff_info = {};
10622 buff_info.buffer = buffer;
10623 // First make offset 1 larger than buffer size
10624 buff_info.offset = 257;
10625 buff_info.range = VK_WHOLE_SIZE;
10626 VkWriteDescriptorSet descriptor_write = {};
10627 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
10628 descriptor_write.dstBinding = 0;
10629 descriptor_write.descriptorCount = 1;
10630 descriptor_write.pTexelBufferView = nullptr;
10631 descriptor_write.pBufferInfo = &buff_info;
10632 descriptor_write.pImageInfo = nullptr;
10633
10634 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
10635 descriptor_write.dstSet = descriptor_set;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010636 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " offset of 257 is greater than buffer ");
Tobin Ehlis585f66d2016-07-01 18:23:58 -060010637
10638 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
10639
10640 m_errorMonitor->VerifyFound();
10641 // Now cause error due to range of 0
10642 buff_info.offset = 0;
10643 buff_info.range = 0;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010644 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
10645 " range is not VK_WHOLE_SIZE and is zero, which is not allowed.");
Tobin Ehlis585f66d2016-07-01 18:23:58 -060010646
10647 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
10648
10649 m_errorMonitor->VerifyFound();
10650 // Now cause error due to range exceeding buffer size - offset
10651 buff_info.offset = 128;
10652 buff_info.range = 200;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010653 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 -060010654
10655 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
10656
10657 m_errorMonitor->VerifyFound();
Mark Lobodzinski4bb54092016-07-06 14:27:19 -060010658 vkFreeMemory(m_device->device(), mem, NULL);
Tobin Ehlis585f66d2016-07-01 18:23:58 -060010659 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
10660 vkDestroyBuffer(m_device->device(), buffer, NULL);
10661 vkFreeDescriptorSets(m_device->device(), ds_pool, 1, &descriptor_set);
10662 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
10663}
10664
Tobin Ehlis2fc296b2016-06-15 14:05:27 -060010665TEST_F(VkLayerTest, DSAspectBitsErrors) {
10666 // TODO : Initially only catching case where DEPTH & STENCIL aspect bits
10667 // are set, but could expand this test to hit more cases.
10668 TEST_DESCRIPTION("Attempt to update descriptor sets for images "
10669 "that do not have correct aspect bits sets.");
10670 VkResult err;
10671
10672 ASSERT_NO_FATAL_FAILURE(InitState());
10673 VkDescriptorPoolSize ds_type_count = {};
10674 ds_type_count.type = VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT;
10675 ds_type_count.descriptorCount = 1;
10676
10677 VkDescriptorPoolCreateInfo ds_pool_ci = {};
10678 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
10679 ds_pool_ci.pNext = NULL;
10680 ds_pool_ci.maxSets = 5;
10681 ds_pool_ci.poolSizeCount = 1;
10682 ds_pool_ci.pPoolSizes = &ds_type_count;
10683
10684 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010685 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis2fc296b2016-06-15 14:05:27 -060010686 ASSERT_VK_SUCCESS(err);
10687
10688 VkDescriptorSetLayoutBinding dsl_binding = {};
10689 dsl_binding.binding = 0;
10690 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT;
10691 dsl_binding.descriptorCount = 1;
10692 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
10693 dsl_binding.pImmutableSamplers = NULL;
10694
10695 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
10696 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
10697 ds_layout_ci.pNext = NULL;
10698 ds_layout_ci.bindingCount = 1;
10699 ds_layout_ci.pBindings = &dsl_binding;
10700 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010701 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis2fc296b2016-06-15 14:05:27 -060010702 ASSERT_VK_SUCCESS(err);
10703
10704 VkDescriptorSet descriptor_set = {};
10705 VkDescriptorSetAllocateInfo alloc_info = {};
10706 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
10707 alloc_info.descriptorSetCount = 1;
10708 alloc_info.descriptorPool = ds_pool;
10709 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010710 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
Tobin Ehlis2fc296b2016-06-15 14:05:27 -060010711 ASSERT_VK_SUCCESS(err);
10712
10713 // Create an image to be used for invalid updates
10714 VkImageCreateInfo image_ci = {};
10715 image_ci.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
10716 image_ci.imageType = VK_IMAGE_TYPE_2D;
10717 image_ci.format = VK_FORMAT_D24_UNORM_S8_UINT;
10718 image_ci.extent.width = 64;
10719 image_ci.extent.height = 64;
10720 image_ci.extent.depth = 1;
10721 image_ci.mipLevels = 1;
10722 image_ci.arrayLayers = 1;
10723 image_ci.samples = VK_SAMPLE_COUNT_1_BIT;
10724 image_ci.tiling = VK_IMAGE_TILING_LINEAR;
10725 image_ci.initialLayout = VK_IMAGE_LAYOUT_PREINITIALIZED;
10726 image_ci.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
10727 image_ci.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
10728 VkImage image;
10729 err = vkCreateImage(m_device->device(), &image_ci, NULL, &image);
10730 ASSERT_VK_SUCCESS(err);
10731 // Bind memory to image
10732 VkMemoryRequirements mem_reqs;
10733 VkDeviceMemory image_mem;
10734 bool pass;
10735 VkMemoryAllocateInfo mem_alloc = {};
10736 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
10737 mem_alloc.pNext = NULL;
10738 mem_alloc.allocationSize = 0;
10739 mem_alloc.memoryTypeIndex = 0;
10740 vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs);
10741 mem_alloc.allocationSize = mem_reqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010742 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0);
Tobin Ehlis2fc296b2016-06-15 14:05:27 -060010743 ASSERT_TRUE(pass);
10744 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &image_mem);
10745 ASSERT_VK_SUCCESS(err);
10746 err = vkBindImageMemory(m_device->device(), image, image_mem, 0);
10747 ASSERT_VK_SUCCESS(err);
10748 // Now create view for image
10749 VkImageViewCreateInfo image_view_ci = {};
10750 image_view_ci.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
10751 image_view_ci.image = image;
10752 image_view_ci.format = VK_FORMAT_D24_UNORM_S8_UINT;
10753 image_view_ci.viewType = VK_IMAGE_VIEW_TYPE_2D;
10754 image_view_ci.subresourceRange.layerCount = 1;
10755 image_view_ci.subresourceRange.baseArrayLayer = 0;
10756 image_view_ci.subresourceRange.levelCount = 1;
10757 // Setting both depth & stencil aspect bits is illegal for descriptor
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010758 image_view_ci.subresourceRange.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT;
Tobin Ehlis2fc296b2016-06-15 14:05:27 -060010759
10760 VkImageView image_view;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010761 err = vkCreateImageView(m_device->device(), &image_view_ci, NULL, &image_view);
Tobin Ehlis2fc296b2016-06-15 14:05:27 -060010762 ASSERT_VK_SUCCESS(err);
10763
10764 VkDescriptorImageInfo img_info = {};
10765 img_info.imageView = image_view;
10766 VkWriteDescriptorSet descriptor_write = {};
10767 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
10768 descriptor_write.dstBinding = 0;
10769 descriptor_write.descriptorCount = 1;
10770 descriptor_write.pTexelBufferView = NULL;
10771 descriptor_write.pBufferInfo = NULL;
10772 descriptor_write.pImageInfo = &img_info;
10773 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT;
10774 descriptor_write.dstSet = descriptor_set;
10775 const char *error_msg = " please only set either VK_IMAGE_ASPECT_DEPTH_BIT "
10776 "or VK_IMAGE_ASPECT_STENCIL_BIT ";
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010777 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, error_msg);
Tobin Ehlis2fc296b2016-06-15 14:05:27 -060010778
10779 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
10780
10781 m_errorMonitor->VerifyFound();
10782 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
10783 vkDestroyImage(m_device->device(), image, NULL);
10784 vkFreeMemory(m_device->device(), image_mem, NULL);
10785 vkDestroyImageView(m_device->device(), image_view, NULL);
10786 vkFreeDescriptorSets(m_device->device(), ds_pool, 1, &descriptor_set);
10787 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
10788}
10789
Karl Schultz6addd812016-02-02 17:17:23 -070010790TEST_F(VkLayerTest, DSTypeMismatch) {
Tobin Ehlis49eb23d2015-05-22 12:38:55 -060010791 // Create DS w/ layout of one type and attempt Update w/ mis-matched type
Karl Schultz6addd812016-02-02 17:17:23 -070010792 VkResult err;
Tobin Ehlis3b780662015-05-28 12:11:26 -060010793
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010794 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
10795 " binding #0 with type VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER but update "
10796 "type is VK_DESCRIPTOR_TYPE_SAMPLER");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060010797
Tobin Ehlis3b780662015-05-28 12:11:26 -060010798 ASSERT_NO_FATAL_FAILURE(InitState());
Karl Schultz6addd812016-02-02 17:17:23 -070010799 // VkDescriptorSetObj descriptorSet(m_device);
Chia-I Wu1b99bb22015-10-27 19:25:11 +080010800 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010801 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
10802 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -060010803
10804 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010805 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
10806 ds_pool_ci.pNext = NULL;
10807 ds_pool_ci.maxSets = 1;
10808 ds_pool_ci.poolSizeCount = 1;
10809 ds_pool_ci.pPoolSizes = &ds_type_count;
Tony Barboureb254902015-07-15 12:50:33 -060010810
Tobin Ehlis3b780662015-05-28 12:11:26 -060010811 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010812 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis3b780662015-05-28 12:11:26 -060010813 ASSERT_VK_SUCCESS(err);
Tony Barboureb254902015-07-15 12:50:33 -060010814 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010815 dsl_binding.binding = 0;
10816 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
10817 dsl_binding.descriptorCount = 1;
10818 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
10819 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis3b780662015-05-28 12:11:26 -060010820
Tony Barboureb254902015-07-15 12:50:33 -060010821 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010822 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
10823 ds_layout_ci.pNext = NULL;
10824 ds_layout_ci.bindingCount = 1;
10825 ds_layout_ci.pBindings = &dsl_binding;
Tony Barboureb254902015-07-15 12:50:33 -060010826
Tobin Ehlis3b780662015-05-28 12:11:26 -060010827 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010828 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis3b780662015-05-28 12:11:26 -060010829 ASSERT_VK_SUCCESS(err);
10830
10831 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080010832 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +080010833 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -070010834 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -060010835 alloc_info.descriptorPool = ds_pool;
10836 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010837 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis3b780662015-05-28 12:11:26 -060010838 ASSERT_VK_SUCCESS(err);
Tobin Ehlis3b780662015-05-28 12:11:26 -060010839
Tobin Ehlis30db8f82016-05-05 08:19:48 -060010840 VkSamplerCreateInfo sampler_ci = {};
10841 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
10842 sampler_ci.pNext = NULL;
10843 sampler_ci.magFilter = VK_FILTER_NEAREST;
10844 sampler_ci.minFilter = VK_FILTER_NEAREST;
10845 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
10846 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
10847 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
10848 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
10849 sampler_ci.mipLodBias = 1.0;
10850 sampler_ci.anisotropyEnable = VK_FALSE;
10851 sampler_ci.maxAnisotropy = 1;
10852 sampler_ci.compareEnable = VK_FALSE;
10853 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
10854 sampler_ci.minLod = 1.0;
10855 sampler_ci.maxLod = 1.0;
10856 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
10857 sampler_ci.unnormalizedCoordinates = VK_FALSE;
10858 VkSampler sampler;
10859 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
10860 ASSERT_VK_SUCCESS(err);
10861
10862 VkDescriptorImageInfo info = {};
10863 info.sampler = sampler;
Chia-I Wu9d00ed72015-05-25 16:27:55 +080010864
10865 VkWriteDescriptorSet descriptor_write;
10866 memset(&descriptor_write, 0, sizeof(descriptor_write));
10867 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080010868 descriptor_write.dstSet = descriptorSet;
Chia-I Wud50a7d72015-10-26 20:48:51 +080010869 descriptor_write.descriptorCount = 1;
Tobin Ehlis3b780662015-05-28 12:11:26 -060010870 // This is a mismatched type for the layout which expects BUFFER
Chia-I Wu9d00ed72015-05-25 16:27:55 +080010871 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
Courtney Goeltzenleuchter4cb6d922015-10-23 13:38:14 -060010872 descriptor_write.pImageInfo = &info;
Chia-I Wu9d00ed72015-05-25 16:27:55 +080010873
10874 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
10875
Chris Forbes8f36a8a2016-04-07 13:21:07 +120010876 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -060010877
Chia-I Wuf7458c52015-10-26 21:10:41 +080010878 vkDestroySampler(m_device->device(), sampler, NULL);
10879 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
10880 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis49eb23d2015-05-22 12:38:55 -060010881}
10882
Karl Schultz6addd812016-02-02 17:17:23 -070010883TEST_F(VkLayerTest, DSUpdateOutOfBounds) {
Tobin Ehlis49eb23d2015-05-22 12:38:55 -060010884 // For overlapping Update, have arrayIndex exceed that of layout
Karl Schultz6addd812016-02-02 17:17:23 -070010885 VkResult err;
Tobin Ehlis3b780662015-05-28 12:11:26 -060010886
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010887 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
10888 " binding #0 with 1 total descriptors but update of 1 descriptors "
10889 "starting at binding offset of 0 combined with update array element "
10890 "offset of 1 oversteps the size of this descriptor set.");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060010891
Tobin Ehlis3b780662015-05-28 12:11:26 -060010892 ASSERT_NO_FATAL_FAILURE(InitState());
Karl Schultz6addd812016-02-02 17:17:23 -070010893 // VkDescriptorSetObj descriptorSet(m_device);
Chia-I Wu1b99bb22015-10-27 19:25:11 +080010894 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010895 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
10896 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -060010897
10898 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010899 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
10900 ds_pool_ci.pNext = NULL;
10901 ds_pool_ci.maxSets = 1;
10902 ds_pool_ci.poolSizeCount = 1;
10903 ds_pool_ci.pPoolSizes = &ds_type_count;
Tony Barboureb254902015-07-15 12:50:33 -060010904
Tobin Ehlis3b780662015-05-28 12:11:26 -060010905 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010906 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis3b780662015-05-28 12:11:26 -060010907 ASSERT_VK_SUCCESS(err);
Tobin Ehlis3b780662015-05-28 12:11:26 -060010908
Tony Barboureb254902015-07-15 12:50:33 -060010909 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010910 dsl_binding.binding = 0;
10911 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
10912 dsl_binding.descriptorCount = 1;
10913 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
10914 dsl_binding.pImmutableSamplers = NULL;
Tony Barboureb254902015-07-15 12:50:33 -060010915
10916 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010917 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
10918 ds_layout_ci.pNext = NULL;
10919 ds_layout_ci.bindingCount = 1;
10920 ds_layout_ci.pBindings = &dsl_binding;
Tony Barboureb254902015-07-15 12:50:33 -060010921
Tobin Ehlis3b780662015-05-28 12:11:26 -060010922 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010923 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis3b780662015-05-28 12:11:26 -060010924 ASSERT_VK_SUCCESS(err);
10925
10926 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080010927 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +080010928 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -070010929 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -060010930 alloc_info.descriptorPool = ds_pool;
10931 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010932 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis3b780662015-05-28 12:11:26 -060010933 ASSERT_VK_SUCCESS(err);
Tobin Ehlis3b780662015-05-28 12:11:26 -060010934
Tobin Ehlis30db8f82016-05-05 08:19:48 -060010935 // Correctly update descriptor to avoid "NOT_UPDATED" error
10936 VkDescriptorBufferInfo buff_info = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010937 buff_info.buffer = VkBuffer(0); // Don't care about buffer handle for this test
Tobin Ehlis30db8f82016-05-05 08:19:48 -060010938 buff_info.offset = 0;
10939 buff_info.range = 1024;
Chia-I Wu9d00ed72015-05-25 16:27:55 +080010940
10941 VkWriteDescriptorSet descriptor_write;
10942 memset(&descriptor_write, 0, sizeof(descriptor_write));
10943 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080010944 descriptor_write.dstSet = descriptorSet;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010945 descriptor_write.dstArrayElement = 1; /* This index out of bounds for the update */
Chia-I Wud50a7d72015-10-26 20:48:51 +080010946 descriptor_write.descriptorCount = 1;
Tobin Ehlis0a43bde2016-05-03 08:31:08 -060010947 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
10948 descriptor_write.pBufferInfo = &buff_info;
Chia-I Wu9d00ed72015-05-25 16:27:55 +080010949
10950 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
10951
Chris Forbes8f36a8a2016-04-07 13:21:07 +120010952 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -060010953
Chia-I Wuf7458c52015-10-26 21:10:41 +080010954 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
10955 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis49eb23d2015-05-22 12:38:55 -060010956}
10957
Karl Schultz6addd812016-02-02 17:17:23 -070010958TEST_F(VkLayerTest, InvalidDSUpdateIndex) {
10959 // Create layout w/ count of 1 and attempt update to that layout w/ binding
10960 // index 2
10961 VkResult err;
Tobin Ehlis3b780662015-05-28 12:11:26 -060010962
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010963 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " does not have binding 2.");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060010964
Tobin Ehlis3b780662015-05-28 12:11:26 -060010965 ASSERT_NO_FATAL_FAILURE(InitState());
Karl Schultz6addd812016-02-02 17:17:23 -070010966 // VkDescriptorSetObj descriptorSet(m_device);
Chia-I Wu1b99bb22015-10-27 19:25:11 +080010967 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010968 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
10969 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -060010970
10971 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010972 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
10973 ds_pool_ci.pNext = NULL;
10974 ds_pool_ci.maxSets = 1;
10975 ds_pool_ci.poolSizeCount = 1;
10976 ds_pool_ci.pPoolSizes = &ds_type_count;
Courtney Goeltzenleuchterfe908d32015-09-16 16:12:45 -060010977
Tobin Ehlis3b780662015-05-28 12:11:26 -060010978 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010979 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis3b780662015-05-28 12:11:26 -060010980 ASSERT_VK_SUCCESS(err);
Tobin Ehlis3b780662015-05-28 12:11:26 -060010981
Tony Barboureb254902015-07-15 12:50:33 -060010982 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010983 dsl_binding.binding = 0;
10984 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
10985 dsl_binding.descriptorCount = 1;
10986 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
10987 dsl_binding.pImmutableSamplers = NULL;
Tony Barboureb254902015-07-15 12:50:33 -060010988
10989 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010990 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
10991 ds_layout_ci.pNext = NULL;
10992 ds_layout_ci.bindingCount = 1;
10993 ds_layout_ci.pBindings = &dsl_binding;
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
Tony Barboureb254902015-07-15 12:50:33 -060011007 VkSamplerCreateInfo sampler_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011008 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
11009 sampler_ci.pNext = NULL;
11010 sampler_ci.magFilter = VK_FILTER_NEAREST;
11011 sampler_ci.minFilter = VK_FILTER_NEAREST;
11012 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
11013 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
11014 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
11015 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
11016 sampler_ci.mipLodBias = 1.0;
11017 sampler_ci.anisotropyEnable = VK_FALSE;
11018 sampler_ci.maxAnisotropy = 1;
11019 sampler_ci.compareEnable = VK_FALSE;
11020 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
11021 sampler_ci.minLod = 1.0;
11022 sampler_ci.maxLod = 1.0;
11023 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
11024 sampler_ci.unnormalizedCoordinates = VK_FALSE;
Tony Barboureb254902015-07-15 12:50:33 -060011025
Tobin Ehlis3b780662015-05-28 12:11:26 -060011026 VkSampler sampler;
Chia-I Wuf7458c52015-10-26 21:10:41 +080011027 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
Tobin Ehlis3b780662015-05-28 12:11:26 -060011028 ASSERT_VK_SUCCESS(err);
Chia-I Wu9d00ed72015-05-25 16:27:55 +080011029
Courtney Goeltzenleuchter4cb6d922015-10-23 13:38:14 -060011030 VkDescriptorImageInfo info = {};
11031 info.sampler = sampler;
Chia-I Wu9d00ed72015-05-25 16:27:55 +080011032
11033 VkWriteDescriptorSet descriptor_write;
11034 memset(&descriptor_write, 0, sizeof(descriptor_write));
11035 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080011036 descriptor_write.dstSet = descriptorSet;
11037 descriptor_write.dstBinding = 2;
Chia-I Wud50a7d72015-10-26 20:48:51 +080011038 descriptor_write.descriptorCount = 1;
Tobin Ehlis3b780662015-05-28 12:11:26 -060011039 // This is the wrong type, but out of bounds will be flagged first
Chia-I Wu9d00ed72015-05-25 16:27:55 +080011040 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
Courtney Goeltzenleuchter4cb6d922015-10-23 13:38:14 -060011041 descriptor_write.pImageInfo = &info;
Chia-I Wu9d00ed72015-05-25 16:27:55 +080011042
11043 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
11044
Chris Forbes8f36a8a2016-04-07 13:21:07 +120011045 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -060011046
Chia-I Wuf7458c52015-10-26 21:10:41 +080011047 vkDestroySampler(m_device->device(), sampler, NULL);
11048 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
11049 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis49eb23d2015-05-22 12:38:55 -060011050}
11051
Karl Schultz6addd812016-02-02 17:17:23 -070011052TEST_F(VkLayerTest, InvalidDSUpdateStruct) {
11053 // Call UpdateDS w/ struct type other than valid VK_STRUCTUR_TYPE_UPDATE_*
11054 // types
11055 VkResult err;
Tobin Ehlis3b780662015-05-28 12:11:26 -060011056
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011057 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 -060011058
Tobin Ehlis3b780662015-05-28 12:11:26 -060011059 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinski209b5292015-09-17 09:44:05 -060011060
Chia-I Wu1b99bb22015-10-27 19:25:11 +080011061 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011062 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
11063 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -060011064
11065 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011066 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
11067 ds_pool_ci.pNext = NULL;
11068 ds_pool_ci.maxSets = 1;
11069 ds_pool_ci.poolSizeCount = 1;
11070 ds_pool_ci.pPoolSizes = &ds_type_count;
Courtney Goeltzenleuchterfe908d32015-09-16 16:12:45 -060011071
Tobin Ehlis3b780662015-05-28 12:11:26 -060011072 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011073 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis3b780662015-05-28 12:11:26 -060011074 ASSERT_VK_SUCCESS(err);
Tony Barboureb254902015-07-15 12:50:33 -060011075 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011076 dsl_binding.binding = 0;
11077 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
11078 dsl_binding.descriptorCount = 1;
11079 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
11080 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis3b780662015-05-28 12:11:26 -060011081
Tony Barboureb254902015-07-15 12:50:33 -060011082 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011083 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
11084 ds_layout_ci.pNext = NULL;
11085 ds_layout_ci.bindingCount = 1;
11086 ds_layout_ci.pBindings = &dsl_binding;
Tony Barboureb254902015-07-15 12:50:33 -060011087
Tobin Ehlis3b780662015-05-28 12:11:26 -060011088 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011089 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis3b780662015-05-28 12:11:26 -060011090 ASSERT_VK_SUCCESS(err);
11091
11092 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080011093 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +080011094 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -070011095 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -060011096 alloc_info.descriptorPool = ds_pool;
11097 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011098 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis3b780662015-05-28 12:11:26 -060011099 ASSERT_VK_SUCCESS(err);
Tobin Ehlis3b780662015-05-28 12:11:26 -060011100
Tony Barboureb254902015-07-15 12:50:33 -060011101 VkSamplerCreateInfo sampler_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011102 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
11103 sampler_ci.pNext = NULL;
11104 sampler_ci.magFilter = VK_FILTER_NEAREST;
11105 sampler_ci.minFilter = VK_FILTER_NEAREST;
11106 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
11107 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
11108 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
11109 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
11110 sampler_ci.mipLodBias = 1.0;
11111 sampler_ci.anisotropyEnable = VK_FALSE;
11112 sampler_ci.maxAnisotropy = 1;
11113 sampler_ci.compareEnable = VK_FALSE;
11114 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
11115 sampler_ci.minLod = 1.0;
11116 sampler_ci.maxLod = 1.0;
11117 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
11118 sampler_ci.unnormalizedCoordinates = VK_FALSE;
Tobin Ehlis3b780662015-05-28 12:11:26 -060011119 VkSampler sampler;
Chia-I Wuf7458c52015-10-26 21:10:41 +080011120 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
Tobin Ehlis3b780662015-05-28 12:11:26 -060011121 ASSERT_VK_SUCCESS(err);
Chia-I Wu9d00ed72015-05-25 16:27:55 +080011122
Courtney Goeltzenleuchter4cb6d922015-10-23 13:38:14 -060011123 VkDescriptorImageInfo info = {};
11124 info.sampler = sampler;
Chia-I Wu9d00ed72015-05-25 16:27:55 +080011125
11126 VkWriteDescriptorSet descriptor_write;
11127 memset(&descriptor_write, 0, sizeof(descriptor_write));
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011128 descriptor_write.sType = (VkStructureType)0x99999999; /* Intentionally broken struct type */
Chia-I Wu3432a0c2015-10-27 18:04:07 +080011129 descriptor_write.dstSet = descriptorSet;
Chia-I Wud50a7d72015-10-26 20:48:51 +080011130 descriptor_write.descriptorCount = 1;
Tobin Ehlis3b780662015-05-28 12:11:26 -060011131 // This is the wrong type, but out of bounds will be flagged first
Chia-I Wu9d00ed72015-05-25 16:27:55 +080011132 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
Courtney Goeltzenleuchter4cb6d922015-10-23 13:38:14 -060011133 descriptor_write.pImageInfo = &info;
Chia-I Wu9d00ed72015-05-25 16:27:55 +080011134
11135 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
11136
Chris Forbes8f36a8a2016-04-07 13:21:07 +120011137 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -060011138
Chia-I Wuf7458c52015-10-26 21:10:41 +080011139 vkDestroySampler(m_device->device(), sampler, NULL);
11140 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
11141 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis49eb23d2015-05-22 12:38:55 -060011142}
11143
Karl Schultz6addd812016-02-02 17:17:23 -070011144TEST_F(VkLayerTest, SampleDescriptorUpdateError) {
Tobin Ehlisa1c28562015-10-23 16:00:08 -060011145 // Create a single Sampler descriptor and send it an invalid Sampler
Karl Schultz6addd812016-02-02 17:17:23 -070011146 VkResult err;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060011147
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011148 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
11149 "Attempted write update to sampler descriptor with invalid sampler");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060011150
Tobin Ehlisa1c28562015-10-23 16:00:08 -060011151 ASSERT_NO_FATAL_FAILURE(InitState());
Karl Schultz6addd812016-02-02 17:17:23 -070011152 // TODO : Farm Descriptor setup code to helper function(s) to reduce copied
11153 // code
Chia-I Wu1b99bb22015-10-27 19:25:11 +080011154 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011155 ds_type_count.type = VK_DESCRIPTOR_TYPE_SAMPLER;
11156 ds_type_count.descriptorCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060011157
11158 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011159 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
11160 ds_pool_ci.pNext = NULL;
11161 ds_pool_ci.maxSets = 1;
11162 ds_pool_ci.poolSizeCount = 1;
11163 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060011164
11165 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011166 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060011167 ASSERT_VK_SUCCESS(err);
11168
11169 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011170 dsl_binding.binding = 0;
11171 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
11172 dsl_binding.descriptorCount = 1;
11173 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
11174 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060011175
11176 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011177 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
11178 ds_layout_ci.pNext = NULL;
11179 ds_layout_ci.bindingCount = 1;
11180 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060011181 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011182 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060011183 ASSERT_VK_SUCCESS(err);
11184
11185 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080011186 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +080011187 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -070011188 alloc_info.descriptorSetCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060011189 alloc_info.descriptorPool = ds_pool;
11190 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011191 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060011192 ASSERT_VK_SUCCESS(err);
11193
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011194 VkSampler sampler = (VkSampler)((size_t)0xbaadbeef); // Sampler with invalid handle
Tobin Ehlisa1c28562015-10-23 16:00:08 -060011195
11196 VkDescriptorImageInfo descriptor_info;
11197 memset(&descriptor_info, 0, sizeof(VkDescriptorImageInfo));
11198 descriptor_info.sampler = sampler;
11199
11200 VkWriteDescriptorSet descriptor_write;
11201 memset(&descriptor_write, 0, sizeof(descriptor_write));
11202 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080011203 descriptor_write.dstSet = descriptorSet;
11204 descriptor_write.dstBinding = 0;
Chia-I Wud50a7d72015-10-26 20:48:51 +080011205 descriptor_write.descriptorCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060011206 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
11207 descriptor_write.pImageInfo = &descriptor_info;
11208
11209 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
11210
Chris Forbes8f36a8a2016-04-07 13:21:07 +120011211 m_errorMonitor->VerifyFound();
Tobin Ehlisa1c28562015-10-23 16:00:08 -060011212
Chia-I Wuf7458c52015-10-26 21:10:41 +080011213 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
11214 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060011215}
11216
Karl Schultz6addd812016-02-02 17:17:23 -070011217TEST_F(VkLayerTest, ImageViewDescriptorUpdateError) {
11218 // Create a single combined Image/Sampler descriptor and send it an invalid
11219 // imageView
11220 VkResult err;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060011221
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011222 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Attempted write update to combined "
11223 "image sampler descriptor failed due "
11224 "to: Invalid VkImageView:");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060011225
Tobin Ehlisa1c28562015-10-23 16:00:08 -060011226 ASSERT_NO_FATAL_FAILURE(InitState());
Chia-I Wu1b99bb22015-10-27 19:25:11 +080011227 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011228 ds_type_count.type = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
11229 ds_type_count.descriptorCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060011230
11231 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011232 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
11233 ds_pool_ci.pNext = NULL;
11234 ds_pool_ci.maxSets = 1;
11235 ds_pool_ci.poolSizeCount = 1;
11236 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060011237
11238 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011239 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060011240 ASSERT_VK_SUCCESS(err);
11241
11242 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011243 dsl_binding.binding = 0;
11244 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
11245 dsl_binding.descriptorCount = 1;
11246 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
11247 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060011248
11249 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011250 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
11251 ds_layout_ci.pNext = NULL;
11252 ds_layout_ci.bindingCount = 1;
11253 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060011254 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011255 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060011256 ASSERT_VK_SUCCESS(err);
11257
11258 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080011259 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +080011260 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -070011261 alloc_info.descriptorSetCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060011262 alloc_info.descriptorPool = ds_pool;
11263 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011264 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060011265 ASSERT_VK_SUCCESS(err);
11266
11267 VkSamplerCreateInfo sampler_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011268 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
11269 sampler_ci.pNext = NULL;
11270 sampler_ci.magFilter = VK_FILTER_NEAREST;
11271 sampler_ci.minFilter = VK_FILTER_NEAREST;
11272 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
11273 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
11274 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
11275 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
11276 sampler_ci.mipLodBias = 1.0;
11277 sampler_ci.anisotropyEnable = VK_FALSE;
11278 sampler_ci.maxAnisotropy = 1;
11279 sampler_ci.compareEnable = VK_FALSE;
11280 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
11281 sampler_ci.minLod = 1.0;
11282 sampler_ci.maxLod = 1.0;
11283 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
11284 sampler_ci.unnormalizedCoordinates = VK_FALSE;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060011285
11286 VkSampler sampler;
Chia-I Wuf7458c52015-10-26 21:10:41 +080011287 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060011288 ASSERT_VK_SUCCESS(err);
11289
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011290 VkImageView view = (VkImageView)((size_t)0xbaadbeef); // invalid imageView object
Tobin Ehlisa1c28562015-10-23 16:00:08 -060011291
11292 VkDescriptorImageInfo descriptor_info;
11293 memset(&descriptor_info, 0, sizeof(VkDescriptorImageInfo));
11294 descriptor_info.sampler = sampler;
11295 descriptor_info.imageView = view;
11296
11297 VkWriteDescriptorSet descriptor_write;
11298 memset(&descriptor_write, 0, sizeof(descriptor_write));
11299 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080011300 descriptor_write.dstSet = descriptorSet;
11301 descriptor_write.dstBinding = 0;
Chia-I Wud50a7d72015-10-26 20:48:51 +080011302 descriptor_write.descriptorCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060011303 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
11304 descriptor_write.pImageInfo = &descriptor_info;
11305
11306 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
11307
Chris Forbes8f36a8a2016-04-07 13:21:07 +120011308 m_errorMonitor->VerifyFound();
Tobin Ehlisa1c28562015-10-23 16:00:08 -060011309
Chia-I Wuf7458c52015-10-26 21:10:41 +080011310 vkDestroySampler(m_device->device(), sampler, NULL);
11311 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
11312 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060011313}
11314
Karl Schultz6addd812016-02-02 17:17:23 -070011315TEST_F(VkLayerTest, CopyDescriptorUpdateErrors) {
11316 // Create DS w/ layout of 2 types, write update 1 and attempt to copy-update
11317 // into the other
11318 VkResult err;
Tobin Ehlis04356f92015-10-27 16:35:27 -060011319
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011320 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " binding #1 with type "
11321 "VK_DESCRIPTOR_TYPE_SAMPLER. Types do "
11322 "not match.");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060011323
Tobin Ehlis04356f92015-10-27 16:35:27 -060011324 ASSERT_NO_FATAL_FAILURE(InitState());
Karl Schultz6addd812016-02-02 17:17:23 -070011325 // VkDescriptorSetObj descriptorSet(m_device);
Chia-I Wu1b99bb22015-10-27 19:25:11 +080011326 VkDescriptorPoolSize ds_type_count[2] = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011327 ds_type_count[0].type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
11328 ds_type_count[0].descriptorCount = 1;
11329 ds_type_count[1].type = VK_DESCRIPTOR_TYPE_SAMPLER;
11330 ds_type_count[1].descriptorCount = 1;
Tobin Ehlis04356f92015-10-27 16:35:27 -060011331
11332 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011333 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
11334 ds_pool_ci.pNext = NULL;
11335 ds_pool_ci.maxSets = 1;
11336 ds_pool_ci.poolSizeCount = 2;
11337 ds_pool_ci.pPoolSizes = ds_type_count;
Tobin Ehlis04356f92015-10-27 16:35:27 -060011338
11339 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011340 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis04356f92015-10-27 16:35:27 -060011341 ASSERT_VK_SUCCESS(err);
11342 VkDescriptorSetLayoutBinding dsl_binding[2] = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011343 dsl_binding[0].binding = 0;
11344 dsl_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
11345 dsl_binding[0].descriptorCount = 1;
11346 dsl_binding[0].stageFlags = VK_SHADER_STAGE_ALL;
11347 dsl_binding[0].pImmutableSamplers = NULL;
11348 dsl_binding[1].binding = 1;
11349 dsl_binding[1].descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
11350 dsl_binding[1].descriptorCount = 1;
11351 dsl_binding[1].stageFlags = VK_SHADER_STAGE_ALL;
11352 dsl_binding[1].pImmutableSamplers = NULL;
Tobin Ehlis04356f92015-10-27 16:35:27 -060011353
11354 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011355 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
11356 ds_layout_ci.pNext = NULL;
11357 ds_layout_ci.bindingCount = 2;
11358 ds_layout_ci.pBindings = dsl_binding;
Tobin Ehlis04356f92015-10-27 16:35:27 -060011359
11360 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011361 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis04356f92015-10-27 16:35:27 -060011362 ASSERT_VK_SUCCESS(err);
11363
11364 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080011365 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +080011366 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -070011367 alloc_info.descriptorSetCount = 1;
Tobin Ehlis04356f92015-10-27 16:35:27 -060011368 alloc_info.descriptorPool = ds_pool;
11369 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011370 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis04356f92015-10-27 16:35:27 -060011371 ASSERT_VK_SUCCESS(err);
11372
11373 VkSamplerCreateInfo sampler_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011374 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
11375 sampler_ci.pNext = NULL;
11376 sampler_ci.magFilter = VK_FILTER_NEAREST;
11377 sampler_ci.minFilter = VK_FILTER_NEAREST;
11378 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
11379 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
11380 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
11381 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
11382 sampler_ci.mipLodBias = 1.0;
11383 sampler_ci.anisotropyEnable = VK_FALSE;
11384 sampler_ci.maxAnisotropy = 1;
11385 sampler_ci.compareEnable = VK_FALSE;
11386 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
11387 sampler_ci.minLod = 1.0;
11388 sampler_ci.maxLod = 1.0;
11389 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
11390 sampler_ci.unnormalizedCoordinates = VK_FALSE;
Tobin Ehlis04356f92015-10-27 16:35:27 -060011391
11392 VkSampler sampler;
Chia-I Wuf7458c52015-10-26 21:10:41 +080011393 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
Tobin Ehlis04356f92015-10-27 16:35:27 -060011394 ASSERT_VK_SUCCESS(err);
11395
11396 VkDescriptorImageInfo info = {};
11397 info.sampler = sampler;
11398
11399 VkWriteDescriptorSet descriptor_write;
11400 memset(&descriptor_write, 0, sizeof(VkWriteDescriptorSet));
11401 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080011402 descriptor_write.dstSet = descriptorSet;
11403 descriptor_write.dstBinding = 1; // SAMPLER binding from layout above
Chia-I Wud50a7d72015-10-26 20:48:51 +080011404 descriptor_write.descriptorCount = 1;
Tobin Ehlis04356f92015-10-27 16:35:27 -060011405 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
11406 descriptor_write.pImageInfo = &info;
11407 // This write update should succeed
11408 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
11409 // Now perform a copy update that fails due to type mismatch
11410 VkCopyDescriptorSet copy_ds_update;
11411 memset(&copy_ds_update, 0, sizeof(VkCopyDescriptorSet));
11412 copy_ds_update.sType = VK_STRUCTURE_TYPE_COPY_DESCRIPTOR_SET;
11413 copy_ds_update.srcSet = descriptorSet;
Mark Young29927482016-05-04 14:38:51 -060011414 copy_ds_update.srcBinding = 1; // Copy from SAMPLER binding
Chia-I Wu3432a0c2015-10-27 18:04:07 +080011415 copy_ds_update.dstSet = descriptorSet;
Karl Schultz6addd812016-02-02 17:17:23 -070011416 copy_ds_update.dstBinding = 0; // ERROR : copy to UNIFORM binding
Chia-I Wud50a7d72015-10-26 20:48:51 +080011417 copy_ds_update.descriptorCount = 1; // copy 1 descriptor
Tobin Ehlis04356f92015-10-27 16:35:27 -060011418 vkUpdateDescriptorSets(m_device->device(), 0, NULL, 1, &copy_ds_update);
11419
Chris Forbes8f36a8a2016-04-07 13:21:07 +120011420 m_errorMonitor->VerifyFound();
Tobin Ehlis04356f92015-10-27 16:35:27 -060011421 // Now perform a copy update that fails due to binding out of bounds
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011422 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 -060011423 memset(&copy_ds_update, 0, sizeof(VkCopyDescriptorSet));
11424 copy_ds_update.sType = VK_STRUCTURE_TYPE_COPY_DESCRIPTOR_SET;
11425 copy_ds_update.srcSet = descriptorSet;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011426 copy_ds_update.srcBinding = 3; // ERROR : Invalid binding for matching layout
Chia-I Wu3432a0c2015-10-27 18:04:07 +080011427 copy_ds_update.dstSet = descriptorSet;
11428 copy_ds_update.dstBinding = 0;
Mark Young29927482016-05-04 14:38:51 -060011429 copy_ds_update.descriptorCount = 1; // Copy 1 descriptor
Tobin Ehlis04356f92015-10-27 16:35:27 -060011430 vkUpdateDescriptorSets(m_device->device(), 0, NULL, 1, &copy_ds_update);
11431
Chris Forbes8f36a8a2016-04-07 13:21:07 +120011432 m_errorMonitor->VerifyFound();
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060011433
Tobin Ehlis04356f92015-10-27 16:35:27 -060011434 // Now perform a copy update that fails due to binding out of bounds
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011435 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " binding#1 with offset index of 1 plus "
11436 "update array offset of 0 and update of "
11437 "5 descriptors oversteps total number "
11438 "of descriptors in set: 2.");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060011439
Tobin Ehlis04356f92015-10-27 16:35:27 -060011440 memset(&copy_ds_update, 0, sizeof(VkCopyDescriptorSet));
11441 copy_ds_update.sType = VK_STRUCTURE_TYPE_COPY_DESCRIPTOR_SET;
11442 copy_ds_update.srcSet = descriptorSet;
11443 copy_ds_update.srcBinding = 1;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080011444 copy_ds_update.dstSet = descriptorSet;
11445 copy_ds_update.dstBinding = 0;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011446 copy_ds_update.descriptorCount = 5; // ERROR copy 5 descriptors (out of bounds for layout)
Tobin Ehlis04356f92015-10-27 16:35:27 -060011447 vkUpdateDescriptorSets(m_device->device(), 0, NULL, 1, &copy_ds_update);
11448
Chris Forbes8f36a8a2016-04-07 13:21:07 +120011449 m_errorMonitor->VerifyFound();
Tobin Ehlis04356f92015-10-27 16:35:27 -060011450
Chia-I Wuf7458c52015-10-26 21:10:41 +080011451 vkDestroySampler(m_device->device(), sampler, NULL);
11452 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
11453 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis04356f92015-10-27 16:35:27 -060011454}
11455
Karl Schultz6addd812016-02-02 17:17:23 -070011456TEST_F(VkLayerTest, NumSamplesMismatch) {
11457 // Create CommandBuffer where MSAA samples doesn't match RenderPass
11458 // sampleCount
11459 VkResult err;
Tobin Ehlis3b780662015-05-28 12:11:26 -060011460
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011461 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Num samples mismatch! ");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060011462
Tobin Ehlis3b780662015-05-28 12:11:26 -060011463 ASSERT_NO_FATAL_FAILURE(InitState());
11464 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chia-I Wu1b99bb22015-10-27 19:25:11 +080011465 VkDescriptorPoolSize ds_type_count = {};
Tony Barboureb254902015-07-15 12:50:33 -060011466 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Chia-I Wud50a7d72015-10-26 20:48:51 +080011467 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -060011468
11469 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011470 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
11471 ds_pool_ci.pNext = NULL;
11472 ds_pool_ci.maxSets = 1;
11473 ds_pool_ci.poolSizeCount = 1;
11474 ds_pool_ci.pPoolSizes = &ds_type_count;
Courtney Goeltzenleuchterfe908d32015-09-16 16:12:45 -060011475
Tobin Ehlis3b780662015-05-28 12:11:26 -060011476 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011477 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis3b780662015-05-28 12:11:26 -060011478 ASSERT_VK_SUCCESS(err);
Tobin Ehlis3b780662015-05-28 12:11:26 -060011479
Tony Barboureb254902015-07-15 12:50:33 -060011480 VkDescriptorSetLayoutBinding dsl_binding = {};
Chia-I Wud46e6ae2015-10-31 00:31:16 +080011481 dsl_binding.binding = 0;
Tony Barboureb254902015-07-15 12:50:33 -060011482 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Chia-I Wu02124482015-11-06 06:42:02 +080011483 dsl_binding.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -060011484 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
11485 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis3b780662015-05-28 12:11:26 -060011486
Tony Barboureb254902015-07-15 12:50:33 -060011487 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
11488 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
11489 ds_layout_ci.pNext = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +080011490 ds_layout_ci.bindingCount = 1;
Jon Ashburn6e23c1f2015-12-30 18:01:16 -070011491 ds_layout_ci.pBindings = &dsl_binding;
Tony Barboureb254902015-07-15 12:50:33 -060011492
Tobin Ehlis3b780662015-05-28 12:11:26 -060011493 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011494 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis3b780662015-05-28 12:11:26 -060011495 ASSERT_VK_SUCCESS(err);
11496
11497 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080011498 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +080011499 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -070011500 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -060011501 alloc_info.descriptorPool = ds_pool;
11502 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011503 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis3b780662015-05-28 12:11:26 -060011504 ASSERT_VK_SUCCESS(err);
11505
Tony Barboureb254902015-07-15 12:50:33 -060011506 VkPipelineMultisampleStateCreateInfo pipe_ms_state_ci = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011507 pipe_ms_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
Karl Schultz6addd812016-02-02 17:17:23 -070011508 pipe_ms_state_ci.pNext = NULL;
11509 pipe_ms_state_ci.rasterizationSamples = VK_SAMPLE_COUNT_4_BIT;
11510 pipe_ms_state_ci.sampleShadingEnable = 0;
11511 pipe_ms_state_ci.minSampleShading = 1.0;
11512 pipe_ms_state_ci.pSampleMask = NULL;
Tobin Ehlis3b780662015-05-28 12:11:26 -060011513
Tony Barboureb254902015-07-15 12:50:33 -060011514 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011515 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
11516 pipeline_layout_ci.pNext = NULL;
11517 pipeline_layout_ci.setLayoutCount = 1;
11518 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlis3b780662015-05-28 12:11:26 -060011519
11520 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011521 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis3b780662015-05-28 12:11:26 -060011522 ASSERT_VK_SUCCESS(err);
11523
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011524 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
11525 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this); // We shouldn't need a fragment shader
11526 // but add it to be able to run on more devices
Tony Barbour62e1a5b2015-08-06 10:16:07 -060011527 VkPipelineObj pipe(m_device);
11528 pipe.AddShader(&vs);
Tony Barbour1c94d372015-08-06 11:21:08 -060011529 pipe.AddShader(&fs);
Mark Youngc89c6312016-03-31 16:03:20 -060011530 pipe.AddColorAttachment();
Tony Barbour62e1a5b2015-08-06 10:16:07 -060011531 pipe.SetMSAA(&pipe_ms_state_ci);
11532 pipe.CreateVKPipeline(pipeline_layout, renderPass());
Tobin Ehlis3b780662015-05-28 12:11:26 -060011533
Tony Barbourfe3351b2015-07-28 10:17:20 -060011534 BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011535 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Tobin Ehlis3b780662015-05-28 12:11:26 -060011536
Mark Young29927482016-05-04 14:38:51 -060011537 // Render triangle (the error should trigger on the attempt to draw).
11538 Draw(3, 1, 0, 0);
11539
11540 // Finalize recording of the command buffer
11541 EndCommandBuffer();
11542
Chris Forbes8f36a8a2016-04-07 13:21:07 +120011543 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -060011544
Chia-I Wuf7458c52015-10-26 21:10:41 +080011545 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
11546 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
11547 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis49eb23d2015-05-22 12:38:55 -060011548}
Mark Young29927482016-05-04 14:38:51 -060011549
Tobin Ehlis85aa15a2016-06-15 10:52:37 -060011550TEST_F(VkLayerTest, RenderPassIncompatible) {
11551 TEST_DESCRIPTION("Hit RenderPass incompatible cases. "
11552 "Initial case is drawing with an active renderpass that's "
11553 "not compatible with the bound PSO's creation renderpass");
11554 VkResult err;
11555
11556 ASSERT_NO_FATAL_FAILURE(InitState());
11557 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
11558
11559 VkDescriptorSetLayoutBinding dsl_binding = {};
11560 dsl_binding.binding = 0;
11561 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
11562 dsl_binding.descriptorCount = 1;
11563 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
11564 dsl_binding.pImmutableSamplers = NULL;
11565
11566 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
11567 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
11568 ds_layout_ci.pNext = NULL;
11569 ds_layout_ci.bindingCount = 1;
11570 ds_layout_ci.pBindings = &dsl_binding;
11571
11572 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011573 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis85aa15a2016-06-15 10:52:37 -060011574 ASSERT_VK_SUCCESS(err);
11575
11576 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
11577 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
11578 pipeline_layout_ci.pNext = NULL;
11579 pipeline_layout_ci.setLayoutCount = 1;
11580 pipeline_layout_ci.pSetLayouts = &ds_layout;
11581
11582 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011583 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis85aa15a2016-06-15 10:52:37 -060011584 ASSERT_VK_SUCCESS(err);
11585
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011586 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
11587 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this); // We shouldn't need a fragment shader
11588 // but add it to be able to run on more devices
Tobin Ehlis85aa15a2016-06-15 10:52:37 -060011589 // Create a renderpass that will be incompatible with default renderpass
11590 VkAttachmentReference attach = {};
11591 attach.layout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
11592 VkAttachmentReference color_att = {};
11593 color_att.layout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
11594 VkSubpassDescription subpass = {};
11595 subpass.inputAttachmentCount = 1;
11596 subpass.pInputAttachments = &attach;
11597 subpass.colorAttachmentCount = 1;
11598 subpass.pColorAttachments = &color_att;
11599 VkRenderPassCreateInfo rpci = {};
11600 rpci.subpassCount = 1;
11601 rpci.pSubpasses = &subpass;
11602 rpci.attachmentCount = 1;
11603 VkAttachmentDescription attach_desc = {};
11604 attach_desc.samples = VK_SAMPLE_COUNT_1_BIT;
Cody Northropbd16af12016-06-21 09:25:48 -060011605 // Format incompatible with PSO RP color attach format B8G8R8A8_UNORM
11606 attach_desc.format = VK_FORMAT_R8G8B8A8_UNORM;
Tobin Ehlis85aa15a2016-06-15 10:52:37 -060011607 rpci.pAttachments = &attach_desc;
11608 rpci.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
11609 VkRenderPass rp;
11610 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
11611 VkPipelineObj pipe(m_device);
11612 pipe.AddShader(&vs);
11613 pipe.AddShader(&fs);
11614 pipe.AddColorAttachment();
11615 VkViewport view_port = {};
11616 m_viewports.push_back(view_port);
11617 pipe.SetViewport(m_viewports);
11618 VkRect2D rect = {};
11619 m_scissors.push_back(rect);
11620 pipe.SetScissor(m_scissors);
11621 pipe.CreateVKPipeline(pipeline_layout, renderPass());
11622
11623 VkCommandBufferInheritanceInfo cbii = {};
11624 cbii.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_INHERITANCE_INFO;
11625 cbii.renderPass = rp;
11626 cbii.subpass = 0;
11627 VkCommandBufferBeginInfo cbbi = {};
11628 cbbi.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
11629 cbbi.pInheritanceInfo = &cbii;
11630 vkBeginCommandBuffer(m_commandBuffer->handle(), &cbbi);
11631 VkRenderPassBeginInfo rpbi = {};
11632 rpbi.sType = VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO;
11633 rpbi.framebuffer = m_framebuffer;
11634 rpbi.renderPass = rp;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011635 vkCmdBeginRenderPass(m_commandBuffer->GetBufferHandle(), &rpbi, VK_SUBPASS_CONTENTS_INLINE);
11636 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Tobin Ehlis85aa15a2016-06-15 10:52:37 -060011637
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011638 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " is incompatible w/ gfx pipeline ");
Tobin Ehlis85aa15a2016-06-15 10:52:37 -060011639 // Render triangle (the error should trigger on the attempt to draw).
11640 Draw(3, 1, 0, 0);
11641
11642 // Finalize recording of the command buffer
11643 EndCommandBuffer();
11644
11645 m_errorMonitor->VerifyFound();
11646
11647 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
11648 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
11649 vkDestroyRenderPass(m_device->device(), rp, NULL);
11650}
11651
Mark Youngc89c6312016-03-31 16:03:20 -060011652TEST_F(VkLayerTest, NumBlendAttachMismatch) {
11653 // Create Pipeline where the number of blend attachments doesn't match the
11654 // number of color attachments. In this case, we don't add any color
11655 // blend attachments even though we have a color attachment.
11656 VkResult err;
11657
11658 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011659 "Render pass subpass 0 mismatch with blending state defined and blend state attachment");
Mark Youngc89c6312016-03-31 16:03:20 -060011660
11661 ASSERT_NO_FATAL_FAILURE(InitState());
11662 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
11663 VkDescriptorPoolSize ds_type_count = {};
11664 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
11665 ds_type_count.descriptorCount = 1;
11666
11667 VkDescriptorPoolCreateInfo ds_pool_ci = {};
11668 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
11669 ds_pool_ci.pNext = NULL;
11670 ds_pool_ci.maxSets = 1;
11671 ds_pool_ci.poolSizeCount = 1;
11672 ds_pool_ci.pPoolSizes = &ds_type_count;
11673
11674 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011675 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Mark Youngc89c6312016-03-31 16:03:20 -060011676 ASSERT_VK_SUCCESS(err);
11677
11678 VkDescriptorSetLayoutBinding dsl_binding = {};
11679 dsl_binding.binding = 0;
11680 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
11681 dsl_binding.descriptorCount = 1;
11682 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
11683 dsl_binding.pImmutableSamplers = NULL;
11684
11685 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
11686 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
11687 ds_layout_ci.pNext = NULL;
11688 ds_layout_ci.bindingCount = 1;
11689 ds_layout_ci.pBindings = &dsl_binding;
11690
11691 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011692 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Mark Youngc89c6312016-03-31 16:03:20 -060011693 ASSERT_VK_SUCCESS(err);
11694
11695 VkDescriptorSet descriptorSet;
11696 VkDescriptorSetAllocateInfo alloc_info = {};
11697 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
11698 alloc_info.descriptorSetCount = 1;
11699 alloc_info.descriptorPool = ds_pool;
11700 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011701 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Mark Youngc89c6312016-03-31 16:03:20 -060011702 ASSERT_VK_SUCCESS(err);
11703
11704 VkPipelineMultisampleStateCreateInfo pipe_ms_state_ci = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011705 pipe_ms_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
Mark Youngc89c6312016-03-31 16:03:20 -060011706 pipe_ms_state_ci.pNext = NULL;
11707 pipe_ms_state_ci.rasterizationSamples = VK_SAMPLE_COUNT_1_BIT;
11708 pipe_ms_state_ci.sampleShadingEnable = 0;
11709 pipe_ms_state_ci.minSampleShading = 1.0;
11710 pipe_ms_state_ci.pSampleMask = NULL;
11711
11712 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
11713 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
11714 pipeline_layout_ci.pNext = NULL;
11715 pipeline_layout_ci.setLayoutCount = 1;
11716 pipeline_layout_ci.pSetLayouts = &ds_layout;
11717
11718 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011719 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Mark Youngc89c6312016-03-31 16:03:20 -060011720 ASSERT_VK_SUCCESS(err);
11721
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011722 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
11723 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this); // We shouldn't need a fragment shader
11724 // but add it to be able to run on more devices
Mark Youngc89c6312016-03-31 16:03:20 -060011725 VkPipelineObj pipe(m_device);
11726 pipe.AddShader(&vs);
11727 pipe.AddShader(&fs);
11728 pipe.SetMSAA(&pipe_ms_state_ci);
11729 pipe.CreateVKPipeline(pipeline_layout, renderPass());
11730
11731 BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011732 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Mark Youngc89c6312016-03-31 16:03:20 -060011733
Mark Young29927482016-05-04 14:38:51 -060011734 // Render triangle (the error should trigger on the attempt to draw).
11735 Draw(3, 1, 0, 0);
11736
11737 // Finalize recording of the command buffer
11738 EndCommandBuffer();
11739
Chris Forbes8f36a8a2016-04-07 13:21:07 +120011740 m_errorMonitor->VerifyFound();
Mark Youngc89c6312016-03-31 16:03:20 -060011741
11742 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
11743 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
11744 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
11745}
Mark Young29927482016-05-04 14:38:51 -060011746
Mark Muellerd4914412016-06-13 17:52:06 -060011747TEST_F(VkLayerTest, MissingClearAttachment) {
11748 TEST_DESCRIPTION("Points to a wrong colorAttachment index in a VkClearAttachment "
11749 "structure passed to vkCmdClearAttachments");
Cody Northropc31a84f2016-08-22 10:41:47 -060011750 ASSERT_NO_FATAL_FAILURE(InitState());
Chris Forbesda6ae6f2016-09-09 14:36:33 +120011751 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Chris Forbesef5e2842016-09-08 15:25:24 +120011752 "vkCmdClearAttachments() color attachment index 1 out of range for active subpass 0; ignored");
Mark Muellerd4914412016-06-13 17:52:06 -060011753
11754 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailCmdClearAttachments);
11755 m_errorMonitor->VerifyFound();
11756}
11757
Karl Schultz6addd812016-02-02 17:17:23 -070011758TEST_F(VkLayerTest, ClearCmdNoDraw) {
11759 // Create CommandBuffer where we add ClearCmd for FB Color attachment prior
11760 // to issuing a Draw
11761 VkResult err;
Tobin Ehlis53eddda2015-07-01 16:46:13 -060011762
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011763 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
11764 "vkCmdClearAttachments() issued on CB object ");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060011765
Tobin Ehlis53eddda2015-07-01 16:46:13 -060011766 ASSERT_NO_FATAL_FAILURE(InitState());
11767 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barboureb254902015-07-15 12:50:33 -060011768
Chia-I Wu1b99bb22015-10-27 19:25:11 +080011769 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011770 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
11771 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -060011772
11773 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011774 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
11775 ds_pool_ci.pNext = NULL;
11776 ds_pool_ci.maxSets = 1;
11777 ds_pool_ci.poolSizeCount = 1;
11778 ds_pool_ci.pPoolSizes = &ds_type_count;
Tony Barboureb254902015-07-15 12:50:33 -060011779
Tobin Ehlis53eddda2015-07-01 16:46:13 -060011780 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011781 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis53eddda2015-07-01 16:46:13 -060011782 ASSERT_VK_SUCCESS(err);
11783
Tony Barboureb254902015-07-15 12:50:33 -060011784 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011785 dsl_binding.binding = 0;
11786 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
11787 dsl_binding.descriptorCount = 1;
11788 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
11789 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis53eddda2015-07-01 16:46:13 -060011790
Tony Barboureb254902015-07-15 12:50:33 -060011791 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011792 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
11793 ds_layout_ci.pNext = NULL;
11794 ds_layout_ci.bindingCount = 1;
11795 ds_layout_ci.pBindings = &dsl_binding;
Mark Lobodzinski209b5292015-09-17 09:44:05 -060011796
Tobin Ehlis53eddda2015-07-01 16:46:13 -060011797 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011798 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis53eddda2015-07-01 16:46:13 -060011799 ASSERT_VK_SUCCESS(err);
11800
11801 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080011802 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +080011803 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -070011804 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -060011805 alloc_info.descriptorPool = ds_pool;
11806 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011807 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis53eddda2015-07-01 16:46:13 -060011808 ASSERT_VK_SUCCESS(err);
11809
Tony Barboureb254902015-07-15 12:50:33 -060011810 VkPipelineMultisampleStateCreateInfo pipe_ms_state_ci = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011811 pipe_ms_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
Karl Schultz6addd812016-02-02 17:17:23 -070011812 pipe_ms_state_ci.pNext = NULL;
11813 pipe_ms_state_ci.rasterizationSamples = VK_SAMPLE_COUNT_4_BIT;
11814 pipe_ms_state_ci.sampleShadingEnable = 0;
11815 pipe_ms_state_ci.minSampleShading = 1.0;
11816 pipe_ms_state_ci.pSampleMask = NULL;
Tobin Ehlis53eddda2015-07-01 16:46:13 -060011817
Tony Barboureb254902015-07-15 12:50:33 -060011818 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011819 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
11820 pipeline_layout_ci.pNext = NULL;
11821 pipeline_layout_ci.setLayoutCount = 1;
11822 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlis53eddda2015-07-01 16:46:13 -060011823
11824 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011825 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis53eddda2015-07-01 16:46:13 -060011826 ASSERT_VK_SUCCESS(err);
Mark Lobodzinski209b5292015-09-17 09:44:05 -060011827
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011828 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
Karl Schultzbdb75952016-04-19 11:36:49 -060011829 // We shouldn't need a fragment shader but add it to be able to run
Karl Schultz6addd812016-02-02 17:17:23 -070011830 // on more devices
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011831 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060011832
Tony Barbour62e1a5b2015-08-06 10:16:07 -060011833 VkPipelineObj pipe(m_device);
11834 pipe.AddShader(&vs);
Tony Barbour1c94d372015-08-06 11:21:08 -060011835 pipe.AddShader(&fs);
Tony Barbour62e1a5b2015-08-06 10:16:07 -060011836 pipe.SetMSAA(&pipe_ms_state_ci);
11837 pipe.CreateVKPipeline(pipeline_layout, renderPass());
Tony Barbourfe3351b2015-07-28 10:17:20 -060011838
11839 BeginCommandBuffer();
Tobin Ehlis53eddda2015-07-01 16:46:13 -060011840
Karl Schultz6addd812016-02-02 17:17:23 -070011841 // Main thing we care about for this test is that the VkImage obj we're
11842 // clearing matches Color Attachment of FB
Tobin Ehlis53eddda2015-07-01 16:46:13 -060011843 // Also pass down other dummy params to keep driver and paramchecker happy
Courtney Goeltzenleuchterc9323e02015-10-15 16:51:05 -060011844 VkClearAttachment color_attachment;
11845 color_attachment.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
11846 color_attachment.clearValue.color.float32[0] = 1.0;
11847 color_attachment.clearValue.color.float32[1] = 1.0;
11848 color_attachment.clearValue.color.float32[2] = 1.0;
11849 color_attachment.clearValue.color.float32[3] = 1.0;
11850 color_attachment.colorAttachment = 0;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011851 VkClearRect clear_rect = {{{0, 0}, {(uint32_t)m_width, (uint32_t)m_height}}};
Tobin Ehlis53eddda2015-07-01 16:46:13 -060011852
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011853 vkCmdClearAttachments(m_commandBuffer->GetBufferHandle(), 1, &color_attachment, 1, &clear_rect);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060011854
Chris Forbes8f36a8a2016-04-07 13:21:07 +120011855 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -060011856
Chia-I Wuf7458c52015-10-26 21:10:41 +080011857 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
11858 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
11859 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis53eddda2015-07-01 16:46:13 -060011860}
11861
Karl Schultz6addd812016-02-02 17:17:23 -070011862TEST_F(VkLayerTest, VtxBufferBadIndex) {
11863 VkResult err;
Tobin Ehlis502480b2015-06-24 15:53:07 -060011864
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011865 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
11866 "but no vertex buffers are attached to this Pipeline State Object");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060011867
Tobin Ehlis502480b2015-06-24 15:53:07 -060011868 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisd332f282015-10-02 11:00:56 -060011869 ASSERT_NO_FATAL_FAILURE(InitViewport());
Tobin Ehlis502480b2015-06-24 15:53:07 -060011870 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barboureb254902015-07-15 12:50:33 -060011871
Chia-I Wu1b99bb22015-10-27 19:25:11 +080011872 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011873 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
11874 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -060011875
11876 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011877 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
11878 ds_pool_ci.pNext = NULL;
11879 ds_pool_ci.maxSets = 1;
11880 ds_pool_ci.poolSizeCount = 1;
11881 ds_pool_ci.pPoolSizes = &ds_type_count;
Tony Barboureb254902015-07-15 12:50:33 -060011882
Courtney Goeltzenleuchterfe908d32015-09-16 16:12:45 -060011883 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011884 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis502480b2015-06-24 15:53:07 -060011885 ASSERT_VK_SUCCESS(err);
11886
Tony Barboureb254902015-07-15 12:50:33 -060011887 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011888 dsl_binding.binding = 0;
11889 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
11890 dsl_binding.descriptorCount = 1;
11891 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
11892 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis502480b2015-06-24 15:53:07 -060011893
Tony Barboureb254902015-07-15 12:50:33 -060011894 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011895 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
11896 ds_layout_ci.pNext = NULL;
11897 ds_layout_ci.bindingCount = 1;
11898 ds_layout_ci.pBindings = &dsl_binding;
Tony Barboureb254902015-07-15 12:50:33 -060011899
Tobin Ehlis502480b2015-06-24 15:53:07 -060011900 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011901 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis502480b2015-06-24 15:53:07 -060011902 ASSERT_VK_SUCCESS(err);
11903
11904 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080011905 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +080011906 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -070011907 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -060011908 alloc_info.descriptorPool = ds_pool;
11909 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011910 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis502480b2015-06-24 15:53:07 -060011911 ASSERT_VK_SUCCESS(err);
11912
Tony Barboureb254902015-07-15 12:50:33 -060011913 VkPipelineMultisampleStateCreateInfo pipe_ms_state_ci = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011914 pipe_ms_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
Karl Schultz6addd812016-02-02 17:17:23 -070011915 pipe_ms_state_ci.pNext = NULL;
11916 pipe_ms_state_ci.rasterizationSamples = VK_SAMPLE_COUNT_1_BIT;
11917 pipe_ms_state_ci.sampleShadingEnable = 0;
11918 pipe_ms_state_ci.minSampleShading = 1.0;
11919 pipe_ms_state_ci.pSampleMask = NULL;
Tobin Ehlis502480b2015-06-24 15:53:07 -060011920
Tony Barboureb254902015-07-15 12:50:33 -060011921 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011922 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
11923 pipeline_layout_ci.pNext = NULL;
11924 pipeline_layout_ci.setLayoutCount = 1;
11925 pipeline_layout_ci.pSetLayouts = &ds_layout;
11926 VkPipelineLayout pipeline_layout;
Tobin Ehlis502480b2015-06-24 15:53:07 -060011927
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011928 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis502480b2015-06-24 15:53:07 -060011929 ASSERT_VK_SUCCESS(err);
11930
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011931 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
11932 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this); // We shouldn't need a fragment shader
11933 // but add it to be able to run on more devices
Tony Barbour62e1a5b2015-08-06 10:16:07 -060011934 VkPipelineObj pipe(m_device);
11935 pipe.AddShader(&vs);
Tony Barbour1c94d372015-08-06 11:21:08 -060011936 pipe.AddShader(&fs);
Mark Youngc89c6312016-03-31 16:03:20 -060011937 pipe.AddColorAttachment();
Tony Barbour62e1a5b2015-08-06 10:16:07 -060011938 pipe.SetMSAA(&pipe_ms_state_ci);
Tobin Ehlisd332f282015-10-02 11:00:56 -060011939 pipe.SetViewport(m_viewports);
11940 pipe.SetScissor(m_scissors);
Tony Barbour62e1a5b2015-08-06 10:16:07 -060011941 pipe.CreateVKPipeline(pipeline_layout, renderPass());
Tony Barbourfe3351b2015-07-28 10:17:20 -060011942
11943 BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011944 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Tobin Ehlisf7bf4502015-09-09 15:12:35 -060011945 // Don't care about actual data, just need to get to draw to flag error
11946 static const float vbo_data[3] = {1.f, 0.f, 1.f};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011947 VkConstantBufferObj vbo(m_device, sizeof(vbo_data), sizeof(float), (const void *)&vbo_data);
Tobin Ehlisf7bf4502015-09-09 15:12:35 -060011948 BindVertexBuffer(&vbo, (VkDeviceSize)0, 1); // VBO idx 1, but no VBO in PSO
Courtney Goeltzenleuchter08c26372015-09-23 12:31:50 -060011949 Draw(1, 0, 0, 0);
Tobin Ehlis502480b2015-06-24 15:53:07 -060011950
Chris Forbes8f36a8a2016-04-07 13:21:07 +120011951 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -060011952
Chia-I Wuf7458c52015-10-26 21:10:41 +080011953 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
11954 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
11955 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis502480b2015-06-24 15:53:07 -060011956}
Mark Muellerdfe37552016-07-07 14:47:42 -060011957
Mark Mueller2ee294f2016-08-04 12:59:48 -060011958TEST_F(VkLayerTest, MismatchCountQueueCreateRequestedFeature) {
11959 TEST_DESCRIPTION("Use an invalid count in a vkEnumeratePhysicalDevices call."
11960 "Use invalid Queue Family Index in vkCreateDevice");
Cody Northropc31a84f2016-08-22 10:41:47 -060011961 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Mueller2ee294f2016-08-04 12:59:48 -060011962
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011963 const char *mismatch_count_message = "Call to vkEnumeratePhysicalDevices() "
11964 "w/ pPhysicalDeviceCount value ";
Mark Mueller2ee294f2016-08-04 12:59:48 -060011965
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011966 const char *invalid_queueFamilyIndex_message = "Invalid queue create request in vkCreateDevice(). Invalid "
11967 "queueFamilyIndex ";
Mark Mueller2ee294f2016-08-04 12:59:48 -060011968
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011969 const char *unavailable_feature_message = "While calling vkCreateDevice(), requesting feature #";
Mark Mueller2ee294f2016-08-04 12:59:48 -060011970
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011971 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT, mismatch_count_message);
Mark Mueller880fce52016-08-17 15:23:23 -060011972 // The following test fails with recent NVidia drivers.
11973 // By the time core_validation is reached, the NVidia
11974 // driver has sanitized the invalid condition and core_validation
11975 // is not introduced to the failure condition. This is not the case
11976 // with AMD and Mesa drivers. Futher investigation is required
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011977 // uint32_t count = static_cast<uint32_t>(~0);
11978 // VkPhysicalDevice physical_device;
11979 // vkEnumeratePhysicalDevices(instance(), &count, &physical_device);
11980 // m_errorMonitor->VerifyFound();
Mark Mueller2ee294f2016-08-04 12:59:48 -060011981
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011982 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, invalid_queueFamilyIndex_message);
Mark Mueller2ee294f2016-08-04 12:59:48 -060011983 float queue_priority = 0.0;
11984
11985 VkDeviceQueueCreateInfo queue_create_info = {};
11986 queue_create_info.sType = VK_STRUCTURE_TYPE_DEVICE_QUEUE_CREATE_INFO;
11987 queue_create_info.queueCount = 1;
11988 queue_create_info.pQueuePriorities = &queue_priority;
11989 queue_create_info.queueFamilyIndex = static_cast<uint32_t>(~0);
11990
11991 VkPhysicalDeviceFeatures features = m_device->phy().features();
11992 VkDevice testDevice;
11993 VkDeviceCreateInfo device_create_info = {};
11994 device_create_info.sType = VK_STRUCTURE_TYPE_DEVICE_CREATE_INFO;
11995 device_create_info.queueCreateInfoCount = 1;
11996 device_create_info.pQueueCreateInfos = &queue_create_info;
11997 device_create_info.pEnabledFeatures = &features;
11998 vkCreateDevice(gpu(), &device_create_info, nullptr, &testDevice);
11999 m_errorMonitor->VerifyFound();
12000
12001 queue_create_info.queueFamilyIndex = 1;
12002
12003 unsigned feature_count = sizeof(VkPhysicalDeviceFeatures) / sizeof(VkBool32);
12004 VkBool32 *feature_array = reinterpret_cast<VkBool32 *>(&features);
12005 for (unsigned i = 0; i < feature_count; i++) {
12006 if (VK_FALSE == feature_array[i]) {
12007 feature_array[i] = VK_TRUE;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012008 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, unavailable_feature_message);
Mark Mueller2ee294f2016-08-04 12:59:48 -060012009 device_create_info.pEnabledFeatures = &features;
12010 vkCreateDevice(gpu(), &device_create_info, nullptr, &testDevice);
12011 m_errorMonitor->VerifyFound();
12012 break;
12013 }
12014 }
12015}
12016
12017TEST_F(VkLayerTest, InvalidQueueIndexInvalidQuery) {
12018 TEST_DESCRIPTION("Use an invalid queue index in a vkCmdWaitEvents call."
12019 "End a command buffer with a query still in progress.");
12020
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012021 const char *invalid_queue_index = "was created with sharingMode of VK_SHARING_MODE_EXCLUSIVE. If one "
12022 "of src- or dstQueueFamilyIndex is VK_QUEUE_FAMILY_IGNORED, both "
12023 "must be.";
Mark Mueller2ee294f2016-08-04 12:59:48 -060012024
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012025 const char *invalid_query = "Ending command buffer with in progress query: queryPool 0x";
Mark Mueller2ee294f2016-08-04 12:59:48 -060012026
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012027 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, invalid_queue_index);
Mark Mueller2ee294f2016-08-04 12:59:48 -060012028
12029 ASSERT_NO_FATAL_FAILURE(InitState());
12030
12031 VkEvent event;
12032 VkEventCreateInfo event_create_info{};
12033 event_create_info.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO;
12034 vkCreateEvent(m_device->device(), &event_create_info, nullptr, &event);
12035
Mark Mueller2ee294f2016-08-04 12:59:48 -060012036 VkQueue queue = VK_NULL_HANDLE;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012037 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 0, &queue);
Mark Mueller2ee294f2016-08-04 12:59:48 -060012038
12039 BeginCommandBuffer();
12040
12041 VkImageObj image(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012042 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 -060012043 ASSERT_TRUE(image.initialized());
12044 VkImageMemoryBarrier img_barrier = {};
12045 img_barrier.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
12046 img_barrier.pNext = NULL;
12047 img_barrier.srcAccessMask = VK_ACCESS_HOST_WRITE_BIT;
12048 img_barrier.dstAccessMask = VK_ACCESS_SHADER_READ_BIT;
12049 img_barrier.oldLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
12050 img_barrier.newLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
12051 img_barrier.image = image.handle();
12052 img_barrier.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
Mark Lobodzinski2a74c5c2016-08-17 13:26:28 -060012053
12054 // QueueFamilyIndex must be VK_QUEUE_FAMILY_IGNORED, this verifies
12055 // that layer validation catches the case when it is not.
12056 img_barrier.dstQueueFamilyIndex = 0;
Mark Mueller2ee294f2016-08-04 12:59:48 -060012057 img_barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
12058 img_barrier.subresourceRange.baseArrayLayer = 0;
12059 img_barrier.subresourceRange.baseMipLevel = 0;
12060 img_barrier.subresourceRange.layerCount = 1;
12061 img_barrier.subresourceRange.levelCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012062 vkCmdWaitEvents(m_commandBuffer->handle(), 1, &event, VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0,
12063 nullptr, 0, nullptr, 1, &img_barrier);
Mark Mueller2ee294f2016-08-04 12:59:48 -060012064 m_errorMonitor->VerifyFound();
12065
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012066 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, invalid_query);
Mark Mueller2ee294f2016-08-04 12:59:48 -060012067
12068 VkQueryPool query_pool;
12069 VkQueryPoolCreateInfo query_pool_create_info = {};
12070 query_pool_create_info.sType = VK_STRUCTURE_TYPE_QUERY_POOL_CREATE_INFO;
12071 query_pool_create_info.queryType = VK_QUERY_TYPE_OCCLUSION;
12072 query_pool_create_info.queryCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012073 vkCreateQueryPool(m_device->device(), &query_pool_create_info, nullptr, &query_pool);
Mark Mueller2ee294f2016-08-04 12:59:48 -060012074
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012075 vkCmdResetQueryPool(m_commandBuffer->handle(), query_pool, 0 /*startQuery*/, 1 /*queryCount*/);
Mark Mueller2ee294f2016-08-04 12:59:48 -060012076 vkCmdBeginQuery(m_commandBuffer->handle(), query_pool, 0, 0);
12077
12078 vkEndCommandBuffer(m_commandBuffer->handle());
12079 m_errorMonitor->VerifyFound();
12080
12081 vkDestroyQueryPool(m_device->device(), query_pool, nullptr);
12082 vkDestroyEvent(m_device->device(), event, nullptr);
12083}
12084
Mark Muellerdfe37552016-07-07 14:47:42 -060012085TEST_F(VkLayerTest, VertexBufferInvalid) {
12086 TEST_DESCRIPTION("Submit a command buffer using deleted vertex buffer, "
12087 "delete a buffer twice, use an invalid offset for each "
12088 "buffer type, and attempt to bind a null buffer");
12089
12090 const char *deleted_buffer_in_command_buffer = "Cannot submit cmd buffer "
12091 "using deleted buffer ";
12092 const char *double_destroy_message = "Cannot free buffer 0x";
12093 const char *invalid_offset_message = "vkBindBufferMemory(): "
12094 "memoryOffset is 0x";
12095 const char *invalid_storage_buffer_offset_message = "vkBindBufferMemory(): "
12096 "storage memoryOffset "
12097 "is 0x";
12098 const char *invalid_texel_buffer_offset_message = "vkBindBufferMemory(): "
12099 "texel memoryOffset "
12100 "is 0x";
12101 const char *invalid_uniform_buffer_offset_message = "vkBindBufferMemory(): "
12102 "uniform memoryOffset "
12103 "is 0x";
12104 const char *bind_null_buffer_message = "In vkBindBufferMemory, attempting"
12105 " to Bind Obj(0x";
12106 const char *free_invalid_buffer_message = "Request to delete memory "
12107 "object 0x";
12108
12109 ASSERT_NO_FATAL_FAILURE(InitState());
12110 ASSERT_NO_FATAL_FAILURE(InitViewport());
12111 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12112
12113 VkPipelineMultisampleStateCreateInfo pipe_ms_state_ci = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012114 pipe_ms_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
Mark Muellerdfe37552016-07-07 14:47:42 -060012115 pipe_ms_state_ci.pNext = NULL;
12116 pipe_ms_state_ci.rasterizationSamples = VK_SAMPLE_COUNT_1_BIT;
12117 pipe_ms_state_ci.sampleShadingEnable = 0;
12118 pipe_ms_state_ci.minSampleShading = 1.0;
12119 pipe_ms_state_ci.pSampleMask = nullptr;
12120
12121 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
12122 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
12123 VkPipelineLayout pipeline_layout;
12124
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012125 VkResult err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, nullptr, &pipeline_layout);
Mark Muellerdfe37552016-07-07 14:47:42 -060012126 ASSERT_VK_SUCCESS(err);
12127
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012128 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
12129 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Mark Muellerdfe37552016-07-07 14:47:42 -060012130 VkPipelineObj pipe(m_device);
12131 pipe.AddShader(&vs);
12132 pipe.AddShader(&fs);
12133 pipe.AddColorAttachment();
12134 pipe.SetMSAA(&pipe_ms_state_ci);
12135 pipe.SetViewport(m_viewports);
12136 pipe.SetScissor(m_scissors);
12137 pipe.CreateVKPipeline(pipeline_layout, renderPass());
12138
12139 BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012140 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Mark Muellerdfe37552016-07-07 14:47:42 -060012141
12142 {
12143 // Create and bind a vertex buffer in a reduced scope, which will cause
12144 // it to be deleted upon leaving this scope
12145 const float vbo_data[3] = {1.f, 0.f, 1.f};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012146 VkVerticesObj draw_verticies(m_device, 1, 1, sizeof(vbo_data), 3, vbo_data);
Mark Muellerdfe37552016-07-07 14:47:42 -060012147 draw_verticies.BindVertexBuffers(m_commandBuffer->handle());
12148 draw_verticies.AddVertexInputToPipe(pipe);
12149 }
12150
12151 Draw(1, 0, 0, 0);
12152
12153 EndCommandBuffer();
12154
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012155 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, deleted_buffer_in_command_buffer);
Mark Muellerdfe37552016-07-07 14:47:42 -060012156 QueueCommandBuffer(false);
12157 m_errorMonitor->VerifyFound();
12158
12159 {
12160 // Create and bind a vertex buffer in a reduced scope, and delete it
12161 // twice, the second through the destructor
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012162 VkBufferTest buffer_test(m_device, VK_BUFFER_USAGE_STORAGE_BUFFER_BIT, VkBufferTest::eDoubleDelete);
12163 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, double_destroy_message);
Mark Muellerdfe37552016-07-07 14:47:42 -060012164 buffer_test.TestDoubleDestroy();
12165 }
12166 m_errorMonitor->VerifyFound();
12167
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012168 if (VkBufferTest::GetTestConditionValid(m_device, VkBufferTest::eInvalidMemoryOffset)) {
Mark Muellerdfe37552016-07-07 14:47:42 -060012169 // Create and bind a memory buffer with an invalid offset.
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012170 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, invalid_offset_message);
12171 VkBufferTest buffer_test(m_device, VK_BUFFER_USAGE_UNIFORM_TEXEL_BUFFER_BIT, VkBufferTest::eInvalidMemoryOffset);
12172 (void)buffer_test;
Mark Muellerdfe37552016-07-07 14:47:42 -060012173 m_errorMonitor->VerifyFound();
12174 }
12175
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012176 if (VkBufferTest::GetTestConditionValid(m_device, VkBufferTest::eInvalidDeviceOffset,
12177 VK_BUFFER_USAGE_UNIFORM_TEXEL_BUFFER_BIT)) {
Mark Muellerdfe37552016-07-07 14:47:42 -060012178 // Create and bind a memory buffer with an invalid offset again,
12179 // but look for a texel buffer message.
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012180 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, invalid_texel_buffer_offset_message);
12181 VkBufferTest buffer_test(m_device, VK_BUFFER_USAGE_UNIFORM_TEXEL_BUFFER_BIT, VkBufferTest::eInvalidDeviceOffset);
12182 (void)buffer_test;
Mark Muellerdfe37552016-07-07 14:47:42 -060012183 m_errorMonitor->VerifyFound();
12184 }
12185
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012186 if (VkBufferTest::GetTestConditionValid(m_device, VkBufferTest::eInvalidDeviceOffset, VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT)) {
Mark Muellerdfe37552016-07-07 14:47:42 -060012187 // Create and bind a memory buffer with an invalid offset again, but
12188 // look for a uniform buffer message.
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012189 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, invalid_uniform_buffer_offset_message);
12190 VkBufferTest buffer_test(m_device, VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT, VkBufferTest::eInvalidDeviceOffset);
12191 (void)buffer_test;
Mark Muellerdfe37552016-07-07 14:47:42 -060012192 m_errorMonitor->VerifyFound();
12193 }
12194
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012195 if (VkBufferTest::GetTestConditionValid(m_device, VkBufferTest::eInvalidDeviceOffset, VK_BUFFER_USAGE_STORAGE_BUFFER_BIT)) {
Mark Muellerdfe37552016-07-07 14:47:42 -060012196 // Create and bind a memory buffer with an invalid offset again, but
12197 // look for a storage buffer message.
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012198 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, invalid_storage_buffer_offset_message);
12199 VkBufferTest buffer_test(m_device, VK_BUFFER_USAGE_STORAGE_BUFFER_BIT, VkBufferTest::eInvalidDeviceOffset);
12200 (void)buffer_test;
Mark Muellerdfe37552016-07-07 14:47:42 -060012201 m_errorMonitor->VerifyFound();
12202 }
12203
12204 {
12205 // Attempt to bind a null buffer.
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012206 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, bind_null_buffer_message);
12207 VkBufferTest buffer_test(m_device, VK_BUFFER_USAGE_STORAGE_BUFFER_BIT, VkBufferTest::eBindNullBuffer);
12208 (void)buffer_test;
Mark Muellerdfe37552016-07-07 14:47:42 -060012209 m_errorMonitor->VerifyFound();
12210 }
12211
12212 {
12213 // Attempt to use an invalid handle to delete a buffer.
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012214 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, free_invalid_buffer_message);
12215 VkBufferTest buffer_test(m_device, VK_BUFFER_USAGE_STORAGE_BUFFER_BIT, VkBufferTest::eFreeInvalidHandle);
12216 (void)buffer_test;
Mark Muellerdfe37552016-07-07 14:47:42 -060012217 }
12218 m_errorMonitor->VerifyFound();
12219
12220 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
12221}
12222
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060012223// INVALID_IMAGE_LAYOUT tests (one other case is hit by MapMemWithoutHostVisibleBit and not here)
12224TEST_F(VkLayerTest, InvalidImageLayout) {
12225 TEST_DESCRIPTION("Hit all possible validation checks associated with the "
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012226 "DRAWSTATE_INVALID_IMAGE_LAYOUT enum. Generally these involve having"
12227 "images in the wrong layout when they're copied or transitioned.");
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060012228 // 3 in ValidateCmdBufImageLayouts
12229 // * -1 Attempt to submit cmd buf w/ deleted image
12230 // * -2 Cmd buf submit of image w/ layout not matching first use w/ subresource
12231 // * -3 Cmd buf submit of image w/ layout not matching first use w/o subresource
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012232 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
12233 "Layout for input image should be TRANSFER_SRC_OPTIMAL instead of GENERAL.");
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060012234
12235 ASSERT_NO_FATAL_FAILURE(InitState());
12236 // Create src & dst images to use for copy operations
12237 VkImage src_image;
12238 VkImage dst_image;
12239
12240 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
12241 const int32_t tex_width = 32;
12242 const int32_t tex_height = 32;
12243
12244 VkImageCreateInfo image_create_info = {};
12245 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
12246 image_create_info.pNext = NULL;
12247 image_create_info.imageType = VK_IMAGE_TYPE_2D;
12248 image_create_info.format = tex_format;
12249 image_create_info.extent.width = tex_width;
12250 image_create_info.extent.height = tex_height;
12251 image_create_info.extent.depth = 1;
12252 image_create_info.mipLevels = 1;
12253 image_create_info.arrayLayers = 4;
12254 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
12255 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
12256 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
12257 image_create_info.flags = 0;
12258
12259 VkResult err = vkCreateImage(m_device->device(), &image_create_info, NULL, &src_image);
12260 ASSERT_VK_SUCCESS(err);
12261 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &dst_image);
12262 ASSERT_VK_SUCCESS(err);
12263
12264 BeginCommandBuffer();
12265 VkImageCopy copyRegion;
12266 copyRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
12267 copyRegion.srcSubresource.mipLevel = 0;
12268 copyRegion.srcSubresource.baseArrayLayer = 0;
12269 copyRegion.srcSubresource.layerCount = 1;
12270 copyRegion.srcOffset.x = 0;
12271 copyRegion.srcOffset.y = 0;
12272 copyRegion.srcOffset.z = 0;
12273 copyRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
12274 copyRegion.dstSubresource.mipLevel = 0;
12275 copyRegion.dstSubresource.baseArrayLayer = 0;
12276 copyRegion.dstSubresource.layerCount = 1;
12277 copyRegion.dstOffset.x = 0;
12278 copyRegion.dstOffset.y = 0;
12279 copyRegion.dstOffset.z = 0;
12280 copyRegion.extent.width = 1;
12281 copyRegion.extent.height = 1;
12282 copyRegion.extent.depth = 1;
12283 m_commandBuffer->CopyImage(src_image, VK_IMAGE_LAYOUT_GENERAL, dst_image, VK_IMAGE_LAYOUT_GENERAL, 1, &copyRegion);
12284 m_errorMonitor->VerifyFound();
12285 // Now cause error due to src image layout changing
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012286 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Cannot copy from an image whose source layout is "
12287 "VK_IMAGE_LAYOUT_UNDEFINED and doesn't match the current "
12288 "layout VK_IMAGE_LAYOUT_GENERAL.");
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060012289 m_commandBuffer->CopyImage(src_image, VK_IMAGE_LAYOUT_UNDEFINED, dst_image, VK_IMAGE_LAYOUT_GENERAL, 1, &copyRegion);
12290 m_errorMonitor->VerifyFound();
12291 // Final src error is due to bad layout type
12292 m_errorMonitor->SetDesiredFailureMsg(
12293 VK_DEBUG_REPORT_ERROR_BIT_EXT,
12294 "Layout for input image is VK_IMAGE_LAYOUT_UNDEFINED but can only be TRANSFER_SRC_OPTIMAL or GENERAL.");
12295 m_commandBuffer->CopyImage(src_image, VK_IMAGE_LAYOUT_UNDEFINED, dst_image, VK_IMAGE_LAYOUT_GENERAL, 1, &copyRegion);
12296 m_errorMonitor->VerifyFound();
12297 // Now verify same checks for dst
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012298 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
12299 "Layout for output image should be TRANSFER_DST_OPTIMAL instead of GENERAL.");
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060012300 m_commandBuffer->CopyImage(src_image, VK_IMAGE_LAYOUT_GENERAL, dst_image, VK_IMAGE_LAYOUT_GENERAL, 1, &copyRegion);
12301 m_errorMonitor->VerifyFound();
12302 // Now cause error due to src image layout changing
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012303 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Cannot copy from an image whose dest layout is "
12304 "VK_IMAGE_LAYOUT_UNDEFINED and doesn't match the current "
12305 "layout VK_IMAGE_LAYOUT_GENERAL.");
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060012306 m_commandBuffer->CopyImage(src_image, VK_IMAGE_LAYOUT_GENERAL, dst_image, VK_IMAGE_LAYOUT_UNDEFINED, 1, &copyRegion);
12307 m_errorMonitor->VerifyFound();
12308 m_errorMonitor->SetDesiredFailureMsg(
12309 VK_DEBUG_REPORT_ERROR_BIT_EXT,
12310 "Layout for output image is VK_IMAGE_LAYOUT_UNDEFINED but can only be TRANSFER_DST_OPTIMAL or GENERAL.");
12311 m_commandBuffer->CopyImage(src_image, VK_IMAGE_LAYOUT_GENERAL, dst_image, VK_IMAGE_LAYOUT_UNDEFINED, 1, &copyRegion);
12312 m_errorMonitor->VerifyFound();
12313 // Now cause error due to bad image layout transition in PipelineBarrier
12314 VkImageMemoryBarrier image_barrier[1] = {};
12315 image_barrier[0].oldLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL;
12316 image_barrier[0].image = src_image;
12317 image_barrier[0].subresourceRange.layerCount = 2;
12318 image_barrier[0].subresourceRange.levelCount = 2;
12319 image_barrier[0].subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012320 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "You cannot transition the layout from "
12321 "VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL when "
12322 "current layout is VK_IMAGE_LAYOUT_GENERAL.");
12323 vkCmdPipelineBarrier(m_commandBuffer->handle(), VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0,
12324 NULL, 0, NULL, 1, image_barrier);
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060012325 m_errorMonitor->VerifyFound();
12326
12327 // Finally some layout errors at RenderPass create time
12328 // Just hacking in specific state to get to the errors we want so don't copy this unless you know what you're doing.
12329 VkAttachmentReference attach = {};
12330 // perf warning for GENERAL layout w/ non-DS input attachment
12331 attach.layout = VK_IMAGE_LAYOUT_GENERAL;
12332 VkSubpassDescription subpass = {};
12333 subpass.inputAttachmentCount = 1;
12334 subpass.pInputAttachments = &attach;
12335 VkRenderPassCreateInfo rpci = {};
12336 rpci.subpassCount = 1;
12337 rpci.pSubpasses = &subpass;
12338 rpci.attachmentCount = 1;
12339 VkAttachmentDescription attach_desc = {};
12340 attach_desc.format = VK_FORMAT_UNDEFINED;
12341 rpci.pAttachments = &attach_desc;
Tobin Ehlis1efce022016-05-11 10:40:34 -060012342 rpci.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060012343 VkRenderPass rp;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012344 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
12345 "Layout for input attachment is GENERAL but should be READ_ONLY_OPTIMAL.");
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060012346 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
12347 m_errorMonitor->VerifyFound();
12348 // error w/ non-general layout
12349 attach.layout = VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL;
12350
12351 m_errorMonitor->SetDesiredFailureMsg(
12352 VK_DEBUG_REPORT_ERROR_BIT_EXT,
12353 "Layout for input attachment is VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL but can only be READ_ONLY_OPTIMAL or GENERAL.");
12354 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
12355 m_errorMonitor->VerifyFound();
12356 subpass.inputAttachmentCount = 0;
12357 subpass.colorAttachmentCount = 1;
12358 subpass.pColorAttachments = &attach;
12359 attach.layout = VK_IMAGE_LAYOUT_GENERAL;
12360 // perf warning for GENERAL layout on color attachment
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012361 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
12362 "Layout for color attachment is GENERAL but should be COLOR_ATTACHMENT_OPTIMAL.");
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060012363 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
12364 m_errorMonitor->VerifyFound();
12365 // error w/ non-color opt or GENERAL layout for color attachment
12366 attach.layout = VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL;
12367 m_errorMonitor->SetDesiredFailureMsg(
12368 VK_DEBUG_REPORT_ERROR_BIT_EXT,
12369 "Layout for color attachment is VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL but can only be COLOR_ATTACHMENT_OPTIMAL or GENERAL.");
12370 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
12371 m_errorMonitor->VerifyFound();
12372 subpass.colorAttachmentCount = 0;
12373 subpass.pDepthStencilAttachment = &attach;
12374 attach.layout = VK_IMAGE_LAYOUT_GENERAL;
12375 // perf warning for GENERAL layout on DS attachment
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012376 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
12377 "GENERAL layout for depth attachment may not give optimal performance.");
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060012378 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
12379 m_errorMonitor->VerifyFound();
12380 // error w/ non-ds opt or GENERAL layout for color attachment
12381 attach.layout = VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012382 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
12383 "Layout for depth attachment is VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL but can only be "
12384 "DEPTH_STENCIL_ATTACHMENT_OPTIMAL, DEPTH_STENCIL_READ_ONLY_OPTIMAL or GENERAL.");
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060012385 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
12386 m_errorMonitor->VerifyFound();
Tobin Ehlis1efce022016-05-11 10:40:34 -060012387 // For this error we need a valid renderpass so create default one
12388 attach.layout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL;
12389 attach.attachment = 0;
12390 attach_desc.format = VK_FORMAT_D24_UNORM_S8_UINT;
12391 attach_desc.samples = VK_SAMPLE_COUNT_1_BIT;
12392 attach_desc.storeOp = VK_ATTACHMENT_STORE_OP_STORE;
12393 attach_desc.stencilLoadOp = VK_ATTACHMENT_LOAD_OP_DONT_CARE;
12394 attach_desc.stencilStoreOp = VK_ATTACHMENT_STORE_OP_DONT_CARE;
12395 // Can't do a CLEAR load on READ_ONLY initialLayout
12396 attach_desc.loadOp = VK_ATTACHMENT_LOAD_OP_CLEAR;
12397 attach_desc.initialLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL;
12398 attach_desc.finalLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012399 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " with invalid first layout "
12400 "VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_"
12401 "ONLY_OPTIMAL");
Tobin Ehlis1efce022016-05-11 10:40:34 -060012402 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
12403 m_errorMonitor->VerifyFound();
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060012404
12405 vkDestroyImage(m_device->device(), src_image, NULL);
12406 vkDestroyImage(m_device->device(), dst_image, NULL);
12407}
Tobin Ehlisd8d89182016-07-18 20:13:11 -060012408
12409TEST_F(VkLayerTest, ValidRenderPassAttachmentLayoutWithLoadOp) {
12410 TEST_DESCRIPTION("Positive test where we create a renderpass with an "
12411 "attachment that uses LOAD_OP_CLEAR, the first subpass "
12412 "has a valid layout, and a second subpass then uses a "
12413 "valid *READ_ONLY* layout.");
12414 m_errorMonitor->ExpectSuccess();
12415 ASSERT_NO_FATAL_FAILURE(InitState());
12416
12417 VkAttachmentReference attach[2] = {};
12418 attach[0].attachment = 0;
12419 attach[0].layout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
12420 attach[1].attachment = 0;
12421 attach[1].layout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL;
12422 VkSubpassDescription subpasses[2] = {};
12423 // First subpass clears DS attach on load
12424 subpasses[0].pDepthStencilAttachment = &attach[0];
12425 // 2nd subpass reads in DS as input attachment
12426 subpasses[1].inputAttachmentCount = 1;
12427 subpasses[1].pInputAttachments = &attach[1];
12428 VkAttachmentDescription attach_desc = {};
12429 attach_desc.format = VK_FORMAT_D24_UNORM_S8_UINT;
12430 attach_desc.samples = VK_SAMPLE_COUNT_1_BIT;
12431 attach_desc.storeOp = VK_ATTACHMENT_STORE_OP_STORE;
12432 attach_desc.stencilStoreOp = VK_ATTACHMENT_STORE_OP_DONT_CARE;
12433 attach_desc.loadOp = VK_ATTACHMENT_LOAD_OP_CLEAR;
12434 attach_desc.stencilLoadOp = VK_ATTACHMENT_LOAD_OP_CLEAR;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012435 attach_desc.initialLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
Tobin Ehlisd8d89182016-07-18 20:13:11 -060012436 attach_desc.finalLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL;
12437 VkRenderPassCreateInfo rpci = {};
12438 rpci.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
12439 rpci.attachmentCount = 1;
12440 rpci.pAttachments = &attach_desc;
12441 rpci.subpassCount = 2;
12442 rpci.pSubpasses = subpasses;
12443
12444 // Now create RenderPass and verify no errors
12445 VkRenderPass rp;
12446 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
12447 m_errorMonitor->VerifyNotFound();
12448
12449 vkDestroyRenderPass(m_device->device(), rp, NULL);
12450}
Tobin Ehlis4af23302016-07-19 10:50:30 -060012451
Mark Mueller93b938f2016-08-18 10:27:40 -060012452TEST_F(VkLayerTest, SimultaneousUse) {
12453 TEST_DESCRIPTION("Use vkCmdExecuteCommands with invalid state "
12454 "in primary and secondary command buffers.");
12455
12456 ASSERT_NO_FATAL_FAILURE(InitState());
12457 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12458
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012459 const char *simultaneous_use_message1 = "w/o VK_COMMAND_BUFFER_USAGE_SIMULTANEOUS_USE_BIT set!";
12460 const char *simultaneous_use_message2 = "does not have VK_COMMAND_BUFFER_USAGE_SIMULTANEOUS_USE_BIT set and "
12461 "will cause primary command buffer";
Mark Mueller93b938f2016-08-18 10:27:40 -060012462
12463 VkCommandBufferAllocateInfo command_buffer_allocate_info = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012464 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
Mark Mueller93b938f2016-08-18 10:27:40 -060012465 command_buffer_allocate_info.commandPool = m_commandPool;
12466 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_SECONDARY;
12467 command_buffer_allocate_info.commandBufferCount = 1;
12468
12469 VkCommandBuffer secondary_command_buffer;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012470 ASSERT_VK_SUCCESS(vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, &secondary_command_buffer));
Mark Mueller93b938f2016-08-18 10:27:40 -060012471 VkCommandBufferBeginInfo command_buffer_begin_info = {};
12472 VkCommandBufferInheritanceInfo command_buffer_inheritance_info = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012473 command_buffer_inheritance_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_INHERITANCE_INFO;
Mark Mueller93b938f2016-08-18 10:27:40 -060012474 command_buffer_inheritance_info.renderPass = m_renderPass;
12475 command_buffer_inheritance_info.framebuffer = m_framebuffer;
12476 command_buffer_begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012477 command_buffer_begin_info.flags =
12478 VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT | VK_COMMAND_BUFFER_USAGE_RENDER_PASS_CONTINUE_BIT;
Mark Mueller93b938f2016-08-18 10:27:40 -060012479 command_buffer_begin_info.pInheritanceInfo = &command_buffer_inheritance_info;
12480
12481 vkBeginCommandBuffer(secondary_command_buffer, &command_buffer_begin_info);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012482 vkCmdBeginRenderPass(m_commandBuffer->handle(), &renderPassBeginInfo(), VK_SUBPASS_CONTENTS_SECONDARY_COMMAND_BUFFERS);
12483 vkCmdExecuteCommands(m_commandBuffer->handle(), 1, &secondary_command_buffer);
Mark Mueller4042b652016-09-05 22:52:21 -060012484 vkCmdEndRenderPass(m_commandBuffer->GetBufferHandle());
Mark Mueller93b938f2016-08-18 10:27:40 -060012485 vkEndCommandBuffer(secondary_command_buffer);
12486
Mark Mueller93b938f2016-08-18 10:27:40 -060012487 VkSubmitInfo submit_info = {};
12488 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
12489 submit_info.commandBufferCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012490 submit_info.pCommandBuffers = &m_commandBuffer->handle();
Mark Mueller4042b652016-09-05 22:52:21 -060012491 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
Mark Mueller93b938f2016-08-18 10:27:40 -060012492
Mark Mueller4042b652016-09-05 22:52:21 -060012493 vkBeginCommandBuffer(m_commandBuffer->handle(), &command_buffer_begin_info);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012494 vkCmdBeginRenderPass(m_commandBuffer->handle(), &renderPassBeginInfo(), VK_SUBPASS_CONTENTS_SECONDARY_COMMAND_BUFFERS);
12495 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, simultaneous_use_message1);
12496 vkCmdExecuteCommands(m_commandBuffer->handle(), 1, &secondary_command_buffer);
Mark Mueller93b938f2016-08-18 10:27:40 -060012497 m_errorMonitor->VerifyFound();
Mark Mueller4042b652016-09-05 22:52:21 -060012498 vkCmdEndRenderPass(m_commandBuffer->GetBufferHandle());
12499 vkEndCommandBuffer(m_commandBuffer->handle());
Mark Mueller93b938f2016-08-18 10:27:40 -060012500
12501 m_errorMonitor->SetDesiredFailureMsg(0, "");
Mark Mueller93b938f2016-08-18 10:27:40 -060012502 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
12503
Mark Mueller4042b652016-09-05 22:52:21 -060012504 command_buffer_begin_info.flags = VK_COMMAND_BUFFER_USAGE_SIMULTANEOUS_USE_BIT;
Mark Mueller93b938f2016-08-18 10:27:40 -060012505 vkBeginCommandBuffer(m_commandBuffer->handle(), &command_buffer_begin_info);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012506 vkCmdBeginRenderPass(m_commandBuffer->handle(), &renderPassBeginInfo(), VK_SUBPASS_CONTENTS_SECONDARY_COMMAND_BUFFERS);
Mark Mueller4042b652016-09-05 22:52:21 -060012507
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012508 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT, simultaneous_use_message2);
12509 vkCmdExecuteCommands(m_commandBuffer->handle(), 1, &secondary_command_buffer);
Mark Mueller93b938f2016-08-18 10:27:40 -060012510 m_errorMonitor->VerifyFound();
Mark Mueller4042b652016-09-05 22:52:21 -060012511 vkCmdEndRenderPass(m_commandBuffer->GetBufferHandle());
12512 vkEndCommandBuffer(m_commandBuffer->handle());
Mark Mueller93b938f2016-08-18 10:27:40 -060012513}
12514
Mark Mueller917f6bc2016-08-30 10:57:19 -060012515TEST_F(VkLayerTest, InUseDestroyedSignaled) {
12516 TEST_DESCRIPTION("Use vkCmdExecuteCommands with invalid state "
12517 "in primary and secondary command buffers. "
Mark Muellerc8d441e2016-08-23 17:36:00 -060012518 "Delete objects that are inuse. Call VkQueueSubmit "
12519 "with an event that has been deleted.");
Mark Mueller917f6bc2016-08-30 10:57:19 -060012520
12521 ASSERT_NO_FATAL_FAILURE(InitState());
12522 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12523
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012524 const char *submit_with_deleted_event_message = "Cannot submit cmd buffer using deleted event 0x";
12525 const char *cannot_delete_event_message = "Cannot delete event 0x";
12526 const char *cannot_delete_semaphore_message = "Cannot delete semaphore 0x";
12527 const char *cannot_destroy_fence_message = "Fence 0x";
Mark Mueller917f6bc2016-08-30 10:57:19 -060012528
12529 BeginCommandBuffer();
12530
12531 VkEvent event;
12532 VkEventCreateInfo event_create_info = {};
12533 event_create_info.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO;
12534 vkCreateEvent(m_device->device(), &event_create_info, nullptr, &event);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012535 vkCmdSetEvent(m_commandBuffer->handle(), event, VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT);
Mark Mueller917f6bc2016-08-30 10:57:19 -060012536
Mark Muellerc8d441e2016-08-23 17:36:00 -060012537 EndCommandBuffer();
12538 vkDestroyEvent(m_device->device(), event, nullptr);
12539
12540 VkSubmitInfo submit_info = {};
12541 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
12542 submit_info.commandBufferCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012543 submit_info.pCommandBuffers = &m_commandBuffer->handle();
12544 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, submit_with_deleted_event_message);
Mark Muellerc8d441e2016-08-23 17:36:00 -060012545 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
12546 m_errorMonitor->VerifyFound();
12547
12548 m_errorMonitor->SetDesiredFailureMsg(0, "");
12549 vkResetCommandBuffer(m_commandBuffer->handle(), 0);
12550
12551 vkCreateEvent(m_device->device(), &event_create_info, nullptr, &event);
12552
Mark Mueller917f6bc2016-08-30 10:57:19 -060012553 VkSemaphoreCreateInfo semaphore_create_info = {};
12554 semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
12555 VkSemaphore semaphore;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012556 ASSERT_VK_SUCCESS(vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr, &semaphore));
Mark Mueller917f6bc2016-08-30 10:57:19 -060012557 VkFenceCreateInfo fence_create_info = {};
12558 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
12559 VkFence fence;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012560 ASSERT_VK_SUCCESS(vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence));
Mark Mueller917f6bc2016-08-30 10:57:19 -060012561
12562 VkDescriptorPoolSize descriptor_pool_type_count = {};
Mark Mueller4042b652016-09-05 22:52:21 -060012563 descriptor_pool_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Mark Mueller917f6bc2016-08-30 10:57:19 -060012564 descriptor_pool_type_count.descriptorCount = 1;
12565
12566 VkDescriptorPoolCreateInfo descriptor_pool_create_info = {};
12567 descriptor_pool_create_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
12568 descriptor_pool_create_info.maxSets = 1;
12569 descriptor_pool_create_info.poolSizeCount = 1;
12570 descriptor_pool_create_info.pPoolSizes = &descriptor_pool_type_count;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012571 descriptor_pool_create_info.flags = VK_DESCRIPTOR_POOL_CREATE_FREE_DESCRIPTOR_SET_BIT;
Mark Mueller917f6bc2016-08-30 10:57:19 -060012572
12573 VkDescriptorPool descriptorset_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012574 ASSERT_VK_SUCCESS(vkCreateDescriptorPool(m_device->device(), &descriptor_pool_create_info, nullptr, &descriptorset_pool));
Mark Mueller917f6bc2016-08-30 10:57:19 -060012575
12576 VkDescriptorSetLayoutBinding descriptorset_layout_binding = {};
Mark Mueller4042b652016-09-05 22:52:21 -060012577 descriptorset_layout_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Mark Mueller917f6bc2016-08-30 10:57:19 -060012578 descriptorset_layout_binding.descriptorCount = 1;
12579 descriptorset_layout_binding.stageFlags = VK_SHADER_STAGE_ALL;
12580
12581 VkDescriptorSetLayoutCreateInfo descriptorset_layout_create_info = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012582 descriptorset_layout_create_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
Mark Mueller917f6bc2016-08-30 10:57:19 -060012583 descriptorset_layout_create_info.bindingCount = 1;
12584 descriptorset_layout_create_info.pBindings = &descriptorset_layout_binding;
12585
12586 VkDescriptorSetLayout descriptorset_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012587 ASSERT_VK_SUCCESS(
12588 vkCreateDescriptorSetLayout(m_device->device(), &descriptorset_layout_create_info, nullptr, &descriptorset_layout));
Mark Mueller917f6bc2016-08-30 10:57:19 -060012589
12590 VkDescriptorSet descriptorset;
12591 VkDescriptorSetAllocateInfo descriptorset_allocate_info = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012592 descriptorset_allocate_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Mark Mueller917f6bc2016-08-30 10:57:19 -060012593 descriptorset_allocate_info.descriptorSetCount = 1;
12594 descriptorset_allocate_info.descriptorPool = descriptorset_pool;
12595 descriptorset_allocate_info.pSetLayouts = &descriptorset_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012596 ASSERT_VK_SUCCESS(vkAllocateDescriptorSets(m_device->device(), &descriptorset_allocate_info, &descriptorset));
Mark Mueller917f6bc2016-08-30 10:57:19 -060012597
Mark Mueller4042b652016-09-05 22:52:21 -060012598 VkBufferTest buffer_test(m_device, VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT);
12599
12600 VkDescriptorBufferInfo buffer_info = {};
12601 buffer_info.buffer = buffer_test.GetBuffer();
12602 buffer_info.offset = 0;
12603 buffer_info.range = 1024;
12604
12605 VkWriteDescriptorSet write_descriptor_set = {};
12606 write_descriptor_set.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
12607 write_descriptor_set.dstSet = descriptorset;
12608 write_descriptor_set.descriptorCount = 1;
12609 write_descriptor_set.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
12610 write_descriptor_set.pBufferInfo = &buffer_info;
12611
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012612 vkUpdateDescriptorSets(m_device->device(), 1, &write_descriptor_set, 0, nullptr);
Mark Mueller4042b652016-09-05 22:52:21 -060012613
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012614 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
12615 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Mark Mueller917f6bc2016-08-30 10:57:19 -060012616
12617 VkPipelineObj pipe(m_device);
12618 pipe.AddColorAttachment();
12619 pipe.AddShader(&vs);
12620 pipe.AddShader(&fs);
12621
12622 VkPipelineLayoutCreateInfo pipeline_layout_create_info = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012623 pipeline_layout_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
Mark Mueller917f6bc2016-08-30 10:57:19 -060012624 pipeline_layout_create_info.setLayoutCount = 1;
12625 pipeline_layout_create_info.pSetLayouts = &descriptorset_layout;
12626
12627 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012628 ASSERT_VK_SUCCESS(vkCreatePipelineLayout(m_device->device(), &pipeline_layout_create_info, nullptr, &pipeline_layout));
Mark Mueller917f6bc2016-08-30 10:57:19 -060012629
12630 pipe.CreateVKPipeline(pipeline_layout, m_renderPass);
12631
Mark Muellerc8d441e2016-08-23 17:36:00 -060012632 BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012633 vkCmdSetEvent(m_commandBuffer->handle(), event, VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT);
Mark Muellerc8d441e2016-08-23 17:36:00 -060012634
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012635 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
12636 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
12637 &descriptorset, 0, NULL);
Mark Mueller917f6bc2016-08-30 10:57:19 -060012638
Mark Muellerc8d441e2016-08-23 17:36:00 -060012639 EndCommandBuffer();
Mark Mueller917f6bc2016-08-30 10:57:19 -060012640
Mark Mueller917f6bc2016-08-30 10:57:19 -060012641 submit_info.signalSemaphoreCount = 1;
12642 submit_info.pSignalSemaphores = &semaphore;
12643 vkQueueSubmit(m_device->m_queue, 1, &submit_info, fence);
Mark Muellerc8d441e2016-08-23 17:36:00 -060012644
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012645 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, cannot_delete_event_message);
Mark Mueller917f6bc2016-08-30 10:57:19 -060012646 vkDestroyEvent(m_device->device(), event, nullptr);
12647 m_errorMonitor->VerifyFound();
12648
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012649 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, cannot_delete_semaphore_message);
Mark Mueller917f6bc2016-08-30 10:57:19 -060012650 vkDestroySemaphore(m_device->device(), semaphore, nullptr);
12651 m_errorMonitor->VerifyFound();
12652
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012653 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, cannot_destroy_fence_message);
Mark Mueller917f6bc2016-08-30 10:57:19 -060012654 vkDestroyFence(m_device->device(), fence, nullptr);
12655 m_errorMonitor->VerifyFound();
12656
Tobin Ehlis122207b2016-09-01 08:50:06 -070012657 vkQueueWaitIdle(m_device->m_queue);
Mark Mueller917f6bc2016-08-30 10:57:19 -060012658 vkDestroySemaphore(m_device->device(), semaphore, nullptr);
12659 vkDestroyFence(m_device->device(), fence, nullptr);
12660 vkDestroyEvent(m_device->device(), event, nullptr);
12661 vkDestroyDescriptorPool(m_device->device(), descriptorset_pool, nullptr);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012662 vkDestroyDescriptorSetLayout(m_device->device(), descriptorset_layout, nullptr);
Mark Mueller917f6bc2016-08-30 10:57:19 -060012663 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, nullptr);
12664}
12665
Tobin Ehlis2adda372016-09-01 08:51:06 -070012666TEST_F(VkLayerTest, QueryPoolInUseDestroyedSignaled) {
12667 TEST_DESCRIPTION("Delete in-use query pool.");
12668
12669 ASSERT_NO_FATAL_FAILURE(InitState());
12670 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12671
12672 VkQueryPool query_pool;
12673 VkQueryPoolCreateInfo query_pool_ci{};
12674 query_pool_ci.sType = VK_STRUCTURE_TYPE_QUERY_POOL_CREATE_INFO;
12675 query_pool_ci.queryType = VK_QUERY_TYPE_TIMESTAMP;
12676 query_pool_ci.queryCount = 1;
12677 vkCreateQueryPool(m_device->device(), &query_pool_ci, nullptr, &query_pool);
12678 BeginCommandBuffer();
12679 // Reset query pool to create binding with cmd buffer
12680 vkCmdResetQueryPool(m_commandBuffer->handle(), query_pool, 0, 1);
12681
12682 EndCommandBuffer();
12683
12684 VkSubmitInfo submit_info = {};
12685 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
12686 submit_info.commandBufferCount = 1;
12687 submit_info.pCommandBuffers = &m_commandBuffer->handle();
12688 // Submit cmd buffer and then destroy query pool while in-flight
12689 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
12690
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012691 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Cannot delete query pool 0x");
Tobin Ehlis2adda372016-09-01 08:51:06 -070012692 vkDestroyQueryPool(m_device->handle(), query_pool, NULL);
12693 m_errorMonitor->VerifyFound();
12694
12695 vkQueueWaitIdle(m_device->m_queue);
12696 // Now that cmd buffer done we can safely destroy query_pool
12697 vkDestroyQueryPool(m_device->handle(), query_pool, NULL);
12698}
12699
Tobin Ehlisfafab2d2016-09-07 13:51:24 -060012700TEST_F(VkLayerTest, PipelineInUseDestroyedSignaled) {
12701 TEST_DESCRIPTION("Delete in-use pipeline.");
12702
12703 ASSERT_NO_FATAL_FAILURE(InitState());
12704 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12705
12706 // Empty pipeline layout used for binding PSO
12707 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
12708 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
12709 pipeline_layout_ci.setLayoutCount = 0;
12710 pipeline_layout_ci.pSetLayouts = NULL;
12711
12712 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012713 VkResult err = vkCreatePipelineLayout(m_device->handle(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlisfafab2d2016-09-07 13:51:24 -060012714 ASSERT_VK_SUCCESS(err);
12715
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012716 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Cannot delete pipeline 0x");
Tobin Ehlisfafab2d2016-09-07 13:51:24 -060012717 // Create PSO to be used for draw-time errors below
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012718 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
12719 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Tobin Ehlisfafab2d2016-09-07 13:51:24 -060012720 // Store pipeline handle so we can actually delete it before test finishes
12721 VkPipeline delete_this_pipeline;
12722 { // Scope pipeline so it will be auto-deleted
12723 VkPipelineObj pipe(m_device);
12724 pipe.AddShader(&vs);
12725 pipe.AddShader(&fs);
12726 pipe.AddColorAttachment();
12727 pipe.CreateVKPipeline(pipeline_layout, renderPass());
12728 delete_this_pipeline = pipe.handle();
12729
12730 BeginCommandBuffer();
12731 // Bind pipeline to cmd buffer
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012732 vkCmdBindPipeline(m_commandBuffer->handle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Tobin Ehlisfafab2d2016-09-07 13:51:24 -060012733
12734 EndCommandBuffer();
12735
12736 VkSubmitInfo submit_info = {};
12737 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
12738 submit_info.commandBufferCount = 1;
12739 submit_info.pCommandBuffers = &m_commandBuffer->handle();
12740 // Submit cmd buffer and then pipeline destroyed while in-flight
12741 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
12742 } // Pipeline deletion triggered here
12743 m_errorMonitor->VerifyFound();
12744 // Make sure queue finished and then actually delete pipeline
12745 vkQueueWaitIdle(m_device->m_queue);
12746 vkDestroyPipeline(m_device->handle(), delete_this_pipeline, nullptr);
12747 vkDestroyPipelineLayout(m_device->handle(), pipeline_layout, nullptr);
12748}
12749
Tobin Ehlis209532e2016-09-07 13:52:18 -060012750TEST_F(VkLayerTest, SamplerInUseDestroyedSignaled) {
12751 TEST_DESCRIPTION("Delete in-use sampler.");
12752
12753 ASSERT_NO_FATAL_FAILURE(InitState());
12754 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12755
12756 VkDescriptorPoolSize ds_type_count;
12757 ds_type_count.type = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
12758 ds_type_count.descriptorCount = 1;
12759
12760 VkDescriptorPoolCreateInfo ds_pool_ci = {};
12761 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
12762 ds_pool_ci.maxSets = 1;
12763 ds_pool_ci.poolSizeCount = 1;
12764 ds_pool_ci.pPoolSizes = &ds_type_count;
12765
12766 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012767 VkResult err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis209532e2016-09-07 13:52:18 -060012768 ASSERT_VK_SUCCESS(err);
12769
12770 VkSamplerCreateInfo sampler_ci = {};
12771 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
12772 sampler_ci.pNext = NULL;
12773 sampler_ci.magFilter = VK_FILTER_NEAREST;
12774 sampler_ci.minFilter = VK_FILTER_NEAREST;
12775 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
12776 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
12777 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
12778 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
12779 sampler_ci.mipLodBias = 1.0;
12780 sampler_ci.anisotropyEnable = VK_FALSE;
12781 sampler_ci.maxAnisotropy = 1;
12782 sampler_ci.compareEnable = VK_FALSE;
12783 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
12784 sampler_ci.minLod = 1.0;
12785 sampler_ci.maxLod = 1.0;
12786 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
12787 sampler_ci.unnormalizedCoordinates = VK_FALSE;
12788 VkSampler sampler;
12789
12790 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
12791 ASSERT_VK_SUCCESS(err);
12792
12793 VkDescriptorSetLayoutBinding layout_binding;
12794 layout_binding.binding = 0;
12795 layout_binding.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
12796 layout_binding.descriptorCount = 1;
12797 layout_binding.stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
12798 layout_binding.pImmutableSamplers = NULL;
12799
12800 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
12801 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
12802 ds_layout_ci.bindingCount = 1;
12803 ds_layout_ci.pBindings = &layout_binding;
12804 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012805 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis209532e2016-09-07 13:52:18 -060012806 ASSERT_VK_SUCCESS(err);
12807
12808 VkDescriptorSetAllocateInfo alloc_info = {};
12809 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
12810 alloc_info.descriptorSetCount = 1;
12811 alloc_info.descriptorPool = ds_pool;
12812 alloc_info.pSetLayouts = &ds_layout;
12813 VkDescriptorSet descriptor_set;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012814 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
Tobin Ehlis209532e2016-09-07 13:52:18 -060012815 ASSERT_VK_SUCCESS(err);
12816
12817 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
12818 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
12819 pipeline_layout_ci.pNext = NULL;
12820 pipeline_layout_ci.setLayoutCount = 1;
12821 pipeline_layout_ci.pSetLayouts = &ds_layout;
12822
12823 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012824 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis209532e2016-09-07 13:52:18 -060012825 ASSERT_VK_SUCCESS(err);
12826
12827 VkImageObj image(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012828 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 -060012829 ASSERT_TRUE(image.initialized());
12830
12831 VkImageView view;
12832 VkImageViewCreateInfo ivci = {};
12833 ivci.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
12834 ivci.image = image.handle();
12835 ivci.viewType = VK_IMAGE_VIEW_TYPE_2D;
12836 ivci.format = VK_FORMAT_R8G8B8A8_UNORM;
12837 ivci.subresourceRange.layerCount = 1;
12838 ivci.subresourceRange.baseMipLevel = 0;
12839 ivci.subresourceRange.levelCount = 1;
12840 ivci.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
12841
12842 err = vkCreateImageView(m_device->device(), &ivci, NULL, &view);
12843 ASSERT_VK_SUCCESS(err);
12844
12845 VkDescriptorImageInfo image_info{};
12846 image_info.imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
12847 image_info.imageView = view;
12848 image_info.sampler = sampler;
12849
12850 VkWriteDescriptorSet descriptor_write = {};
12851 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
12852 descriptor_write.dstSet = descriptor_set;
12853 descriptor_write.dstBinding = 0;
12854 descriptor_write.descriptorCount = 1;
12855 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
12856 descriptor_write.pImageInfo = &image_info;
12857
12858 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
12859
12860 // Create PSO to use the sampler
12861 char const *vsSource = "#version 450\n"
12862 "\n"
12863 "out gl_PerVertex { \n"
12864 " vec4 gl_Position;\n"
12865 "};\n"
12866 "void main(){\n"
12867 " gl_Position = vec4(1);\n"
12868 "}\n";
12869 char const *fsSource = "#version 450\n"
12870 "\n"
12871 "layout(set=0, binding=0) uniform sampler2D s;\n"
12872 "layout(location=0) out vec4 x;\n"
12873 "void main(){\n"
12874 " x = texture(s, vec2(1));\n"
12875 "}\n";
12876 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
12877 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
12878 VkPipelineObj pipe(m_device);
12879 pipe.AddShader(&vs);
12880 pipe.AddShader(&fs);
12881 pipe.AddColorAttachment();
12882 pipe.CreateVKPipeline(pipeline_layout, renderPass());
12883
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012884 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Cannot delete sampler 0x");
Tobin Ehlis209532e2016-09-07 13:52:18 -060012885
12886 BeginCommandBuffer();
12887 // Bind pipeline to cmd buffer
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012888 vkCmdBindPipeline(m_commandBuffer->handle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
12889 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
12890 &descriptor_set, 0, nullptr);
Tobin Ehlis209532e2016-09-07 13:52:18 -060012891 Draw(1, 0, 0, 0);
12892 EndCommandBuffer();
12893 // Submit cmd buffer then destroy sampler
12894 VkSubmitInfo submit_info = {};
12895 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
12896 submit_info.commandBufferCount = 1;
12897 submit_info.pCommandBuffers = &m_commandBuffer->handle();
12898 // Submit cmd buffer and then destroy sampler while in-flight
12899 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
12900
12901 vkDestroySampler(m_device->device(), sampler, nullptr);
12902 m_errorMonitor->VerifyFound();
12903 vkQueueWaitIdle(m_device->m_queue);
12904 // Now we can actually destroy sampler
12905 vkDestroySampler(m_device->device(), sampler, nullptr);
12906 vkDestroyImageView(m_device->device(), view, NULL);
12907 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
12908 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
12909 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
12910}
12911
Mark Mueller1cd9f412016-08-25 13:23:52 -060012912TEST_F(VkLayerTest, QueueForwardProgressFenceWait) {
Mark Mueller96a56d52016-08-24 10:28:05 -060012913 TEST_DESCRIPTION("Call VkQueueSubmit with a semaphore that is already "
Mark Mueller1cd9f412016-08-25 13:23:52 -060012914 "signaled but not waited on by the queue. Wait on a "
12915 "fence that has not yet been submitted to a queue.");
Mark Mueller96a56d52016-08-24 10:28:05 -060012916
12917 ASSERT_NO_FATAL_FAILURE(InitState());
12918 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12919
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012920 const char *queue_forward_progress_message = " that has already been signaled but not waited on by queue 0x";
12921 const char *invalid_fence_wait_message = " which has not been submitted on a Queue or during "
12922 "acquire next image.";
Mark Mueller96a56d52016-08-24 10:28:05 -060012923
12924 BeginCommandBuffer();
12925 EndCommandBuffer();
12926
12927 VkSemaphoreCreateInfo semaphore_create_info = {};
12928 semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
12929 VkSemaphore semaphore;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012930 ASSERT_VK_SUCCESS(vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr, &semaphore));
Mark Mueller96a56d52016-08-24 10:28:05 -060012931 VkSubmitInfo submit_info = {};
12932 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
12933 submit_info.commandBufferCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012934 submit_info.pCommandBuffers = &m_commandBuffer->handle();
Mark Mueller96a56d52016-08-24 10:28:05 -060012935 submit_info.signalSemaphoreCount = 1;
12936 submit_info.pSignalSemaphores = &semaphore;
12937 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
12938 m_errorMonitor->SetDesiredFailureMsg(0, "");
12939 vkResetCommandBuffer(m_commandBuffer->handle(), 0);
12940 BeginCommandBuffer();
12941 EndCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012942 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, queue_forward_progress_message);
Mark Mueller96a56d52016-08-24 10:28:05 -060012943 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
12944 m_errorMonitor->VerifyFound();
12945
Mark Mueller1cd9f412016-08-25 13:23:52 -060012946 VkFenceCreateInfo fence_create_info = {};
12947 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
12948 VkFence fence;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012949 ASSERT_VK_SUCCESS(vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence));
Mark Mueller1cd9f412016-08-25 13:23:52 -060012950
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012951 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT, invalid_fence_wait_message);
Mark Mueller1cd9f412016-08-25 13:23:52 -060012952 vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
12953 m_errorMonitor->VerifyFound();
12954
Mark Mueller4042b652016-09-05 22:52:21 -060012955 vkDeviceWaitIdle(m_device->device());
Mark Mueller1cd9f412016-08-25 13:23:52 -060012956 vkDestroyFence(m_device->device(), fence, nullptr);
Mark Mueller96a56d52016-08-24 10:28:05 -060012957 vkDestroySemaphore(m_device->device(), semaphore, nullptr);
12958}
12959
Tobin Ehlis4af23302016-07-19 10:50:30 -060012960TEST_F(VkLayerTest, FramebufferIncompatible) {
12961 TEST_DESCRIPTION("Bind a secondary command buffer with with a framebuffer "
12962 "that does not match the framebuffer for the active "
12963 "renderpass.");
12964 ASSERT_NO_FATAL_FAILURE(InitState());
12965 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12966
12967 // A renderpass with one color attachment.
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012968 VkAttachmentDescription attachment = {0,
12969 VK_FORMAT_B8G8R8A8_UNORM,
12970 VK_SAMPLE_COUNT_1_BIT,
12971 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
12972 VK_ATTACHMENT_STORE_OP_STORE,
12973 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
12974 VK_ATTACHMENT_STORE_OP_DONT_CARE,
12975 VK_IMAGE_LAYOUT_UNDEFINED,
12976 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL};
Tobin Ehlis4af23302016-07-19 10:50:30 -060012977
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012978 VkAttachmentReference att_ref = {0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL};
Tobin Ehlis4af23302016-07-19 10:50:30 -060012979
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012980 VkSubpassDescription subpass = {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 1, &att_ref, nullptr, nullptr, 0, nullptr};
Tobin Ehlis4af23302016-07-19 10:50:30 -060012981
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012982 VkRenderPassCreateInfo rpci = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 1, &attachment, 1, &subpass, 0, nullptr};
Tobin Ehlis4af23302016-07-19 10:50:30 -060012983
12984 VkRenderPass rp;
12985 VkResult err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
12986 ASSERT_VK_SUCCESS(err);
12987
12988 // A compatible framebuffer.
12989 VkImageObj image(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012990 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 -060012991 ASSERT_TRUE(image.initialized());
12992
12993 VkImageViewCreateInfo ivci = {
12994 VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO,
12995 nullptr,
12996 0,
12997 image.handle(),
12998 VK_IMAGE_VIEW_TYPE_2D,
12999 VK_FORMAT_B8G8R8A8_UNORM,
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013000 {VK_COMPONENT_SWIZZLE_IDENTITY, VK_COMPONENT_SWIZZLE_IDENTITY, VK_COMPONENT_SWIZZLE_IDENTITY,
13001 VK_COMPONENT_SWIZZLE_IDENTITY},
Tobin Ehlis4af23302016-07-19 10:50:30 -060013002 {VK_IMAGE_ASPECT_COLOR_BIT, 0, 1, 0, 1},
13003 };
13004 VkImageView view;
13005 err = vkCreateImageView(m_device->device(), &ivci, nullptr, &view);
13006 ASSERT_VK_SUCCESS(err);
13007
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013008 VkFramebufferCreateInfo fci = {VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr, 0, rp, 1, &view, 32, 32, 1};
Tobin Ehlis4af23302016-07-19 10:50:30 -060013009 VkFramebuffer fb;
13010 err = vkCreateFramebuffer(m_device->device(), &fci, nullptr, &fb);
13011 ASSERT_VK_SUCCESS(err);
13012
13013 VkCommandBufferAllocateInfo cbai = {};
13014 cbai.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
13015 cbai.commandPool = m_commandPool;
13016 cbai.level = VK_COMMAND_BUFFER_LEVEL_SECONDARY;
13017 cbai.commandBufferCount = 1;
13018
13019 VkCommandBuffer sec_cb;
13020 err = vkAllocateCommandBuffers(m_device->device(), &cbai, &sec_cb);
13021 ASSERT_VK_SUCCESS(err);
13022 VkCommandBufferBeginInfo cbbi = {};
13023 VkCommandBufferInheritanceInfo cbii = {};
13024 cbii.renderPass = renderPass();
13025 cbii.framebuffer = fb;
13026 cbbi.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
13027 cbbi.pNext = NULL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013028 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 -060013029 cbbi.pInheritanceInfo = &cbii;
13030 vkBeginCommandBuffer(sec_cb, &cbbi);
13031 vkEndCommandBuffer(sec_cb);
13032
Chris Forbes3400bc52016-09-13 18:10:34 +120013033 VkCommandBufferBeginInfo cbbi2 = {
13034 VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO, nullptr,
13035 0, nullptr
13036 };
13037 vkBeginCommandBuffer(m_commandBuffer->GetBufferHandle(), &cbbi2);
13038 vkCmdBeginRenderPass(m_commandBuffer->GetBufferHandle(), &m_renderPassBeginInfo, VK_SUBPASS_CONTENTS_SECONDARY_COMMAND_BUFFERS);
Tobin Ehlis4af23302016-07-19 10:50:30 -060013039
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013040 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
13041 " that is not the same as the primaryCB's current active framebuffer ");
Tobin Ehlis4af23302016-07-19 10:50:30 -060013042 vkCmdExecuteCommands(m_commandBuffer->GetBufferHandle(), 1, &sec_cb);
13043 m_errorMonitor->VerifyFound();
13044 // Cleanup
13045 vkDestroyImageView(m_device->device(), view, NULL);
13046 vkDestroyRenderPass(m_device->device(), rp, NULL);
13047 vkDestroyFramebuffer(m_device->device(), fb, NULL);
13048}
Tobin Ehlis52b504f2016-07-19 13:25:12 -060013049
13050TEST_F(VkLayerTest, ColorBlendLogicOpTests) {
13051 TEST_DESCRIPTION("If logicOp is available on the device, set it to an "
13052 "invalid value. If logicOp is not available, attempt to "
13053 "use it and verify that we see the correct error.");
13054 ASSERT_NO_FATAL_FAILURE(InitState());
13055 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13056
13057 auto features = m_device->phy().features();
13058 // Set the expected error depending on whether or not logicOp available
13059 if (VK_FALSE == features.logicOp) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013060 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "If logic operations feature not "
13061 "enabled, logicOpEnable must be "
13062 "VK_FALSE");
Tobin Ehlis52b504f2016-07-19 13:25:12 -060013063 } else {
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013064 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, ", logicOp must be a valid VkLogicOp value");
Tobin Ehlis52b504f2016-07-19 13:25:12 -060013065 }
13066 // Create a pipeline using logicOp
13067 VkResult err;
13068
13069 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
13070 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
13071
13072 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013073 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis52b504f2016-07-19 13:25:12 -060013074 ASSERT_VK_SUCCESS(err);
13075
13076 VkPipelineViewportStateCreateInfo vp_state_ci = {};
13077 vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
13078 vp_state_ci.viewportCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013079 VkViewport vp = {}; // Just need dummy vp to point to
Tobin Ehlis52b504f2016-07-19 13:25:12 -060013080 vp_state_ci.pViewports = &vp;
13081 vp_state_ci.scissorCount = 1;
13082 VkRect2D scissors = {}; // Dummy scissors to point to
13083 vp_state_ci.pScissors = &scissors;
13084 // No dynamic state
13085 VkPipelineDynamicStateCreateInfo dyn_state_ci = {};
13086 dyn_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_DYNAMIC_STATE_CREATE_INFO;
13087
13088 VkPipelineShaderStageCreateInfo shaderStages[2];
13089 memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo));
13090
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013091 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
13092 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Tobin Ehlis52b504f2016-07-19 13:25:12 -060013093 shaderStages[0] = vs.GetStageCreateInfo();
13094 shaderStages[1] = fs.GetStageCreateInfo();
13095
13096 VkPipelineVertexInputStateCreateInfo vi_ci = {};
13097 vi_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
13098
13099 VkPipelineInputAssemblyStateCreateInfo ia_ci = {};
13100 ia_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
13101 ia_ci.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP;
13102
13103 VkPipelineRasterizationStateCreateInfo rs_ci = {};
13104 rs_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
13105
13106 VkPipelineColorBlendAttachmentState att = {};
13107 att.blendEnable = VK_FALSE;
13108 att.colorWriteMask = 0xf;
13109
13110 VkPipelineColorBlendStateCreateInfo cb_ci = {};
13111 cb_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO;
13112 // Enable logicOp & set logicOp to value 1 beyond allowed entries
13113 cb_ci.logicOpEnable = VK_TRUE;
13114 cb_ci.logicOp = VK_LOGIC_OP_RANGE_SIZE; // This should cause an error
13115 cb_ci.attachmentCount = 1;
13116 cb_ci.pAttachments = &att;
13117
13118 VkGraphicsPipelineCreateInfo gp_ci = {};
13119 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
13120 gp_ci.stageCount = 2;
13121 gp_ci.pStages = shaderStages;
13122 gp_ci.pVertexInputState = &vi_ci;
13123 gp_ci.pInputAssemblyState = &ia_ci;
13124 gp_ci.pViewportState = &vp_state_ci;
13125 gp_ci.pRasterizationState = &rs_ci;
13126 gp_ci.pColorBlendState = &cb_ci;
13127 gp_ci.pDynamicState = &dyn_state_ci;
13128 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
13129 gp_ci.layout = pipeline_layout;
13130 gp_ci.renderPass = renderPass();
13131
13132 VkPipelineCacheCreateInfo pc_ci = {};
13133 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
13134
13135 VkPipeline pipeline;
13136 VkPipelineCache pipelineCache;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013137 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Tobin Ehlis52b504f2016-07-19 13:25:12 -060013138 ASSERT_VK_SUCCESS(err);
13139
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013140 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Tobin Ehlis52b504f2016-07-19 13:25:12 -060013141 m_errorMonitor->VerifyFound();
13142 if (VK_SUCCESS == err) {
13143 vkDestroyPipeline(m_device->device(), pipeline, NULL);
13144 }
13145 m_errorMonitor->VerifyFound();
13146 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
13147 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
13148}
Mark Lobodzinski209b5292015-09-17 09:44:05 -060013149#endif // DRAW_STATE_TESTS
13150
Tobin Ehlis0788f522015-05-26 16:11:58 -060013151#if THREADING_TESTS
Mike Stroyanaccf7692015-05-12 16:00:45 -060013152#if GTEST_IS_THREADSAFE
13153struct thread_data_struct {
Chia-I Wu3432a0c2015-10-27 18:04:07 +080013154 VkCommandBuffer commandBuffer;
Mike Stroyanaccf7692015-05-12 16:00:45 -060013155 VkEvent event;
13156 bool bailout;
13157};
13158
Karl Schultz6addd812016-02-02 17:17:23 -070013159extern "C" void *AddToCommandBuffer(void *arg) {
13160 struct thread_data_struct *data = (struct thread_data_struct *)arg;
Mike Stroyanaccf7692015-05-12 16:00:45 -060013161
Mike Stroyana6d14942016-07-13 15:10:05 -060013162 for (int i = 0; i < 80000; i++) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013163 vkCmdSetEvent(data->commandBuffer, data->event, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT);
Mike Stroyanaccf7692015-05-12 16:00:45 -060013164 if (data->bailout) {
13165 break;
13166 }
13167 }
13168 return NULL;
13169}
13170
Karl Schultz6addd812016-02-02 17:17:23 -070013171TEST_F(VkLayerTest, ThreadCommandBufferCollision) {
Mike Stroyan4268d1f2015-07-13 14:45:35 -060013172 test_platform_thread thread;
Mike Stroyanaccf7692015-05-12 16:00:45 -060013173
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013174 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "THREADING ERROR");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060013175
Mike Stroyanaccf7692015-05-12 16:00:45 -060013176 ASSERT_NO_FATAL_FAILURE(InitState());
13177 ASSERT_NO_FATAL_FAILURE(InitViewport());
13178 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13179
Chia-I Wu3432a0c2015-10-27 18:04:07 +080013180 // Calls AllocateCommandBuffers
13181 VkCommandBufferObj commandBuffer(m_device, m_commandPool);
Mark Lobodzinski5495d132015-09-30 16:19:16 -060013182
13183 // Avoid creating RenderPass
Chia-I Wu3432a0c2015-10-27 18:04:07 +080013184 commandBuffer.BeginCommandBuffer();
Mike Stroyanaccf7692015-05-12 16:00:45 -060013185
13186 VkEventCreateInfo event_info;
13187 VkEvent event;
Mike Stroyanaccf7692015-05-12 16:00:45 -060013188 VkResult err;
13189
13190 memset(&event_info, 0, sizeof(event_info));
13191 event_info.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO;
13192
Chia-I Wuf7458c52015-10-26 21:10:41 +080013193 err = vkCreateEvent(device(), &event_info, NULL, &event);
Mike Stroyanaccf7692015-05-12 16:00:45 -060013194 ASSERT_VK_SUCCESS(err);
13195
Mike Stroyanaccf7692015-05-12 16:00:45 -060013196 err = vkResetEvent(device(), event);
13197 ASSERT_VK_SUCCESS(err);
13198
13199 struct thread_data_struct data;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080013200 data.commandBuffer = commandBuffer.GetBufferHandle();
Mike Stroyanaccf7692015-05-12 16:00:45 -060013201 data.event = event;
13202 data.bailout = false;
13203 m_errorMonitor->SetBailout(&data.bailout);
Mike Stroyana6d14942016-07-13 15:10:05 -060013204
13205 // First do some correct operations using multiple threads.
13206 // Add many entries to command buffer from another thread.
13207 test_platform_thread_create(&thread, AddToCommandBuffer, (void *)&data);
13208 // Make non-conflicting calls from this thread at the same time.
13209 for (int i = 0; i < 80000; i++) {
Mike Stroyand6343902016-07-14 08:56:16 -060013210 uint32_t count;
13211 vkEnumeratePhysicalDevices(instance(), &count, NULL);
Mike Stroyana6d14942016-07-13 15:10:05 -060013212 }
13213 test_platform_thread_join(thread, NULL);
13214
13215 // Then do some incorrect operations using multiple threads.
Mike Stroyanaccf7692015-05-12 16:00:45 -060013216 // Add many entries to command buffer from another thread.
Mike Stroyan4268d1f2015-07-13 14:45:35 -060013217 test_platform_thread_create(&thread, AddToCommandBuffer, (void *)&data);
Mike Stroyanaccf7692015-05-12 16:00:45 -060013218 // Add many entries to command buffer from this thread at the same time.
13219 AddToCommandBuffer(&data);
Mark Lobodzinski5495d132015-09-30 16:19:16 -060013220
Mike Stroyan4268d1f2015-07-13 14:45:35 -060013221 test_platform_thread_join(thread, NULL);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080013222 commandBuffer.EndCommandBuffer();
Mike Stroyanaccf7692015-05-12 16:00:45 -060013223
Mike Stroyan10b8cb72016-01-22 15:22:03 -070013224 m_errorMonitor->SetBailout(NULL);
13225
Chris Forbes8f36a8a2016-04-07 13:21:07 +120013226 m_errorMonitor->VerifyFound();
Mike Stroyanaccf7692015-05-12 16:00:45 -060013227
Chia-I Wuf7458c52015-10-26 21:10:41 +080013228 vkDestroyEvent(device(), event, NULL);
Mike Stroyanaccf7692015-05-12 16:00:45 -060013229}
Mark Lobodzinski209b5292015-09-17 09:44:05 -060013230#endif // GTEST_IS_THREADSAFE
13231#endif // THREADING_TESTS
13232
Chris Forbes9f7ff632015-05-25 11:13:08 +120013233#if SHADER_CHECKER_TESTS
Karl Schultz6addd812016-02-02 17:17:23 -070013234TEST_F(VkLayerTest, InvalidSPIRVCodeSize) {
Chris Forbes1cc79542016-07-20 11:13:44 +120013235 TEST_DESCRIPTION("Test that an error is produced for a spirv module "
13236 "with an impossible code size");
13237
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013238 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Invalid SPIR-V header");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060013239
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060013240 ASSERT_NO_FATAL_FAILURE(InitState());
13241 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13242
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060013243 VkShaderModule module;
13244 VkShaderModuleCreateInfo moduleCreateInfo;
13245 struct icd_spv_header spv;
13246
13247 spv.magic = ICD_SPV_MAGIC;
13248 spv.version = ICD_SPV_VERSION;
13249 spv.gen_magic = 0;
13250
13251 moduleCreateInfo.sType = VK_STRUCTURE_TYPE_SHADER_MODULE_CREATE_INFO;
13252 moduleCreateInfo.pNext = NULL;
Karl Schultz6addd812016-02-02 17:17:23 -070013253 moduleCreateInfo.pCode = (const uint32_t *)&spv;
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060013254 moduleCreateInfo.codeSize = 4;
13255 moduleCreateInfo.flags = 0;
Chia-I Wuf7458c52015-10-26 21:10:41 +080013256 vkCreateShaderModule(m_device->device(), &moduleCreateInfo, NULL, &module);
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060013257
Chris Forbes8f36a8a2016-04-07 13:21:07 +120013258 m_errorMonitor->VerifyFound();
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060013259}
13260
Karl Schultz6addd812016-02-02 17:17:23 -070013261TEST_F(VkLayerTest, InvalidSPIRVMagic) {
Chris Forbes1cc79542016-07-20 11:13:44 +120013262 TEST_DESCRIPTION("Test that an error is produced for a spirv module "
13263 "with a bad magic number");
13264
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013265 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Invalid SPIR-V magic number");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060013266
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060013267 ASSERT_NO_FATAL_FAILURE(InitState());
13268 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13269
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060013270 VkShaderModule module;
13271 VkShaderModuleCreateInfo moduleCreateInfo;
13272 struct icd_spv_header spv;
13273
13274 spv.magic = ~ICD_SPV_MAGIC;
13275 spv.version = ICD_SPV_VERSION;
13276 spv.gen_magic = 0;
13277
13278 moduleCreateInfo.sType = VK_STRUCTURE_TYPE_SHADER_MODULE_CREATE_INFO;
13279 moduleCreateInfo.pNext = NULL;
Karl Schultz6addd812016-02-02 17:17:23 -070013280 moduleCreateInfo.pCode = (const uint32_t *)&spv;
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060013281 moduleCreateInfo.codeSize = sizeof(spv) + 10;
13282 moduleCreateInfo.flags = 0;
Chia-I Wuf7458c52015-10-26 21:10:41 +080013283 vkCreateShaderModule(m_device->device(), &moduleCreateInfo, NULL, &module);
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060013284
Chris Forbes8f36a8a2016-04-07 13:21:07 +120013285 m_errorMonitor->VerifyFound();
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060013286}
13287
Chris Forbesb4afd0f2016-04-04 10:48:35 +120013288#if 0
13289// Not currently covered by SPIRV-Tools validator
Karl Schultz6addd812016-02-02 17:17:23 -070013290TEST_F(VkLayerTest, InvalidSPIRVVersion) {
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -070013291 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Chris Forbesb4afd0f2016-04-04 10:48:35 +120013292 "Invalid SPIR-V header");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060013293
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060013294 ASSERT_NO_FATAL_FAILURE(InitState());
13295 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13296
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060013297 VkShaderModule module;
13298 VkShaderModuleCreateInfo moduleCreateInfo;
13299 struct icd_spv_header spv;
13300
13301 spv.magic = ICD_SPV_MAGIC;
13302 spv.version = ~ICD_SPV_VERSION;
13303 spv.gen_magic = 0;
13304
13305 moduleCreateInfo.sType = VK_STRUCTURE_TYPE_SHADER_MODULE_CREATE_INFO;
13306 moduleCreateInfo.pNext = NULL;
13307
Karl Schultz6addd812016-02-02 17:17:23 -070013308 moduleCreateInfo.pCode = (const uint32_t *)&spv;
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060013309 moduleCreateInfo.codeSize = sizeof(spv) + 10;
13310 moduleCreateInfo.flags = 0;
Chia-I Wuf7458c52015-10-26 21:10:41 +080013311 vkCreateShaderModule(m_device->device(), &moduleCreateInfo, NULL, &module);
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060013312
Chris Forbes8f36a8a2016-04-07 13:21:07 +120013313 m_errorMonitor->VerifyFound();
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060013314}
Chris Forbesb4afd0f2016-04-04 10:48:35 +120013315#endif
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060013316
Karl Schultz6addd812016-02-02 17:17:23 -070013317TEST_F(VkLayerTest, CreatePipelineVertexOutputNotConsumed) {
Chris Forbes1cc79542016-07-20 11:13:44 +120013318 TEST_DESCRIPTION("Test that a warning is produced for a vertex output that "
13319 "is not consumed by the fragment stage");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013320 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT, "not consumed by fragment shader");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060013321
Chris Forbes9f7ff632015-05-25 11:13:08 +120013322 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -060013323 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbes9f7ff632015-05-25 11:13:08 +120013324
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013325 char const *vsSource = "#version 450\n"
13326 "\n"
13327 "layout(location=0) out float x;\n"
13328 "out gl_PerVertex {\n"
13329 " vec4 gl_Position;\n"
13330 "};\n"
13331 "void main(){\n"
13332 " gl_Position = vec4(1);\n"
13333 " x = 0;\n"
13334 "}\n";
13335 char const *fsSource = "#version 450\n"
13336 "\n"
13337 "layout(location=0) out vec4 color;\n"
13338 "void main(){\n"
13339 " color = vec4(1);\n"
13340 "}\n";
Chris Forbes9f7ff632015-05-25 11:13:08 +120013341
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060013342 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13343 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbes9f7ff632015-05-25 11:13:08 +120013344
13345 VkPipelineObj pipe(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +080013346 pipe.AddColorAttachment();
Chris Forbes9f7ff632015-05-25 11:13:08 +120013347 pipe.AddShader(&vs);
13348 pipe.AddShader(&fs);
13349
Chris Forbes9f7ff632015-05-25 11:13:08 +120013350 VkDescriptorSetObj descriptorSet(m_device);
13351 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080013352 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbes9f7ff632015-05-25 11:13:08 +120013353
Tony Barbour5781e8f2015-08-04 16:23:11 -060013354 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbes9f7ff632015-05-25 11:13:08 +120013355
Chris Forbes8f36a8a2016-04-07 13:21:07 +120013356 m_errorMonitor->VerifyFound();
Chris Forbes9f7ff632015-05-25 11:13:08 +120013357}
Chris Forbes9f7ff632015-05-25 11:13:08 +120013358
Karl Schultz6addd812016-02-02 17:17:23 -070013359TEST_F(VkLayerTest, CreatePipelineFragmentInputNotProvided) {
Chris Forbes1cc79542016-07-20 11:13:44 +120013360 TEST_DESCRIPTION("Test that an error is produced for a fragment shader input "
13361 "which is not present in the outputs of the previous stage");
13362
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013363 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "not written by vertex shader");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060013364
Chris Forbes59cb88d2015-05-25 11:13:13 +120013365 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -060013366 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbes59cb88d2015-05-25 11:13:13 +120013367
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013368 char const *vsSource = "#version 450\n"
13369 "\n"
13370 "out gl_PerVertex {\n"
13371 " vec4 gl_Position;\n"
13372 "};\n"
13373 "void main(){\n"
13374 " gl_Position = vec4(1);\n"
13375 "}\n";
13376 char const *fsSource = "#version 450\n"
13377 "\n"
13378 "layout(location=0) in float x;\n"
13379 "layout(location=0) out vec4 color;\n"
13380 "void main(){\n"
13381 " color = vec4(x);\n"
13382 "}\n";
Chris Forbes59cb88d2015-05-25 11:13:13 +120013383
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060013384 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13385 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbes59cb88d2015-05-25 11:13:13 +120013386
13387 VkPipelineObj pipe(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +080013388 pipe.AddColorAttachment();
Chris Forbes59cb88d2015-05-25 11:13:13 +120013389 pipe.AddShader(&vs);
13390 pipe.AddShader(&fs);
13391
Chris Forbes59cb88d2015-05-25 11:13:13 +120013392 VkDescriptorSetObj descriptorSet(m_device);
13393 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080013394 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbes59cb88d2015-05-25 11:13:13 +120013395
Tony Barbour5781e8f2015-08-04 16:23:11 -060013396 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbes59cb88d2015-05-25 11:13:13 +120013397
Chris Forbes8f36a8a2016-04-07 13:21:07 +120013398 m_errorMonitor->VerifyFound();
Chris Forbes59cb88d2015-05-25 11:13:13 +120013399}
13400
Karl Schultz6addd812016-02-02 17:17:23 -070013401TEST_F(VkLayerTest, CreatePipelineFragmentInputNotProvidedInBlock) {
Chris Forbes1cc79542016-07-20 11:13:44 +120013402 TEST_DESCRIPTION("Test that an error is produced for a fragment shader input "
13403 "within an interace block, which is not present in the outputs "
13404 "of the previous stage.");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013405 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "not written by vertex shader");
Chris Forbesa3e85f62016-01-15 14:53:11 +130013406
13407 ASSERT_NO_FATAL_FAILURE(InitState());
13408 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13409
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013410 char const *vsSource = "#version 450\n"
13411 "\n"
13412 "out gl_PerVertex {\n"
13413 " vec4 gl_Position;\n"
13414 "};\n"
13415 "void main(){\n"
13416 " gl_Position = vec4(1);\n"
13417 "}\n";
13418 char const *fsSource = "#version 450\n"
13419 "\n"
13420 "in block { layout(location=0) float x; } ins;\n"
13421 "layout(location=0) out vec4 color;\n"
13422 "void main(){\n"
13423 " color = vec4(ins.x);\n"
13424 "}\n";
Chris Forbesa3e85f62016-01-15 14:53:11 +130013425
13426 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13427 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
13428
13429 VkPipelineObj pipe(m_device);
13430 pipe.AddColorAttachment();
13431 pipe.AddShader(&vs);
13432 pipe.AddShader(&fs);
13433
13434 VkDescriptorSetObj descriptorSet(m_device);
13435 descriptorSet.AppendDummy();
13436 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
13437
13438 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
13439
Chris Forbes8f36a8a2016-04-07 13:21:07 +120013440 m_errorMonitor->VerifyFound();
Chris Forbesa3e85f62016-01-15 14:53:11 +130013441}
13442
Karl Schultz6addd812016-02-02 17:17:23 -070013443TEST_F(VkLayerTest, CreatePipelineVsFsTypeMismatchArraySize) {
Chris Forbes1cc79542016-07-20 11:13:44 +120013444 TEST_DESCRIPTION("Test that an error is produced for mismatched array sizes "
13445 "across the VS->FS interface");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013446 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Type mismatch on location 0.0: 'ptr to "
13447 "output arr[2] of float32' vs 'ptr to "
13448 "input arr[3] of float32'");
Chris Forbes0036fd12016-01-26 14:19:49 +130013449
13450 ASSERT_NO_FATAL_FAILURE(InitState());
13451 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13452
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013453 char const *vsSource = "#version 450\n"
13454 "\n"
13455 "layout(location=0) out float x[2];\n"
13456 "out gl_PerVertex {\n"
13457 " vec4 gl_Position;\n"
13458 "};\n"
13459 "void main(){\n"
13460 " x[0] = 0; x[1] = 0;\n"
13461 " gl_Position = vec4(1);\n"
13462 "}\n";
13463 char const *fsSource = "#version 450\n"
13464 "\n"
13465 "layout(location=0) in float x[3];\n"
13466 "layout(location=0) out vec4 color;\n"
13467 "void main(){\n"
13468 " color = vec4(x[0] + x[1] + x[2]);\n"
13469 "}\n";
Chris Forbes0036fd12016-01-26 14:19:49 +130013470
13471 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13472 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
13473
13474 VkPipelineObj pipe(m_device);
13475 pipe.AddColorAttachment();
13476 pipe.AddShader(&vs);
13477 pipe.AddShader(&fs);
13478
13479 VkDescriptorSetObj descriptorSet(m_device);
13480 descriptorSet.AppendDummy();
13481 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
13482
13483 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
13484
Chris Forbes8f36a8a2016-04-07 13:21:07 +120013485 m_errorMonitor->VerifyFound();
Chris Forbes0036fd12016-01-26 14:19:49 +130013486}
13487
Karl Schultz6addd812016-02-02 17:17:23 -070013488TEST_F(VkLayerTest, CreatePipelineVsFsTypeMismatch) {
Chris Forbes1cc79542016-07-20 11:13:44 +120013489 TEST_DESCRIPTION("Test that an error is produced for mismatched types across "
13490 "the VS->FS interface");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013491 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Type mismatch on location 0");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060013492
Chris Forbesb56af562015-05-25 11:13:17 +120013493 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -060013494 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbesb56af562015-05-25 11:13:17 +120013495
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013496 char const *vsSource = "#version 450\n"
13497 "\n"
13498 "layout(location=0) out int x;\n"
13499 "out gl_PerVertex {\n"
13500 " vec4 gl_Position;\n"
13501 "};\n"
13502 "void main(){\n"
13503 " x = 0;\n"
13504 " gl_Position = vec4(1);\n"
13505 "}\n";
13506 char const *fsSource = "#version 450\n"
13507 "\n"
13508 "layout(location=0) in float x;\n" /* VS writes int */
13509 "layout(location=0) out vec4 color;\n"
13510 "void main(){\n"
13511 " color = vec4(x);\n"
13512 "}\n";
Chris Forbesb56af562015-05-25 11:13:17 +120013513
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060013514 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13515 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbesb56af562015-05-25 11:13:17 +120013516
13517 VkPipelineObj pipe(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +080013518 pipe.AddColorAttachment();
Chris Forbesb56af562015-05-25 11:13:17 +120013519 pipe.AddShader(&vs);
13520 pipe.AddShader(&fs);
13521
Chris Forbesb56af562015-05-25 11:13:17 +120013522 VkDescriptorSetObj descriptorSet(m_device);
13523 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080013524 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbesb56af562015-05-25 11:13:17 +120013525
Tony Barbour5781e8f2015-08-04 16:23:11 -060013526 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbesb56af562015-05-25 11:13:17 +120013527
Chris Forbes8f36a8a2016-04-07 13:21:07 +120013528 m_errorMonitor->VerifyFound();
Chris Forbesb56af562015-05-25 11:13:17 +120013529}
13530
Karl Schultz6addd812016-02-02 17:17:23 -070013531TEST_F(VkLayerTest, CreatePipelineVsFsTypeMismatchInBlock) {
Chris Forbes1cc79542016-07-20 11:13:44 +120013532 TEST_DESCRIPTION("Test that an error is produced for mismatched types across "
13533 "the VS->FS interface, when the variable is contained within "
13534 "an interface block");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013535 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Type mismatch on location 0");
Chris Forbesa3e85f62016-01-15 14:53:11 +130013536
13537 ASSERT_NO_FATAL_FAILURE(InitState());
13538 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13539
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013540 char const *vsSource = "#version 450\n"
13541 "\n"
13542 "out block { layout(location=0) int x; } outs;\n"
13543 "out gl_PerVertex {\n"
13544 " vec4 gl_Position;\n"
13545 "};\n"
13546 "void main(){\n"
13547 " outs.x = 0;\n"
13548 " gl_Position = vec4(1);\n"
13549 "}\n";
13550 char const *fsSource = "#version 450\n"
13551 "\n"
13552 "in block { layout(location=0) float x; } ins;\n" /* VS writes int */
13553 "layout(location=0) out vec4 color;\n"
13554 "void main(){\n"
13555 " color = vec4(ins.x);\n"
13556 "}\n";
Chris Forbesa3e85f62016-01-15 14:53:11 +130013557
13558 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13559 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
13560
13561 VkPipelineObj pipe(m_device);
13562 pipe.AddColorAttachment();
13563 pipe.AddShader(&vs);
13564 pipe.AddShader(&fs);
13565
13566 VkDescriptorSetObj descriptorSet(m_device);
13567 descriptorSet.AppendDummy();
13568 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
13569
13570 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
13571
Chris Forbes8f36a8a2016-04-07 13:21:07 +120013572 m_errorMonitor->VerifyFound();
Chris Forbese9928822016-02-17 14:44:52 +130013573}
13574
13575TEST_F(VkLayerTest, CreatePipelineVsFsMismatchByLocation) {
Chris Forbes1cc79542016-07-20 11:13:44 +120013576 TEST_DESCRIPTION("Test that an error is produced for location mismatches across "
13577 "the VS->FS interface; This should manifest as a not-written/not-consumed "
13578 "pair, but flushes out broken walking of the interfaces");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013579 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 +130013580
13581 ASSERT_NO_FATAL_FAILURE(InitState());
13582 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13583
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013584 char const *vsSource = "#version 450\n"
13585 "\n"
13586 "out block { layout(location=1) float x; } outs;\n"
13587 "out gl_PerVertex {\n"
13588 " vec4 gl_Position;\n"
13589 "};\n"
13590 "void main(){\n"
13591 " outs.x = 0;\n"
13592 " gl_Position = vec4(1);\n"
13593 "}\n";
13594 char const *fsSource = "#version 450\n"
13595 "\n"
13596 "in block { layout(location=0) float x; } ins;\n"
13597 "layout(location=0) out vec4 color;\n"
13598 "void main(){\n"
13599 " color = vec4(ins.x);\n"
13600 "}\n";
Chris Forbese9928822016-02-17 14:44:52 +130013601
13602 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13603 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
13604
13605 VkPipelineObj pipe(m_device);
13606 pipe.AddColorAttachment();
13607 pipe.AddShader(&vs);
13608 pipe.AddShader(&fs);
13609
13610 VkDescriptorSetObj descriptorSet(m_device);
13611 descriptorSet.AppendDummy();
13612 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
13613
13614 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
13615
Chris Forbes8f36a8a2016-04-07 13:21:07 +120013616 m_errorMonitor->VerifyFound();
Chris Forbese9928822016-02-17 14:44:52 +130013617}
13618
13619TEST_F(VkLayerTest, CreatePipelineVsFsMismatchByComponent) {
Chris Forbes1cc79542016-07-20 11:13:44 +120013620 TEST_DESCRIPTION("Test that an error is produced for component mismatches across the "
13621 "VS->FS interface. It's not enough to have the same set of locations in "
13622 "use; matching is defined in terms of spirv variables.");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013623 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 +130013624
13625 ASSERT_NO_FATAL_FAILURE(InitState());
13626 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13627
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013628 char const *vsSource = "#version 450\n"
13629 "\n"
13630 "out block { layout(location=0, component=0) float x; } outs;\n"
13631 "out gl_PerVertex {\n"
13632 " vec4 gl_Position;\n"
13633 "};\n"
13634 "void main(){\n"
13635 " outs.x = 0;\n"
13636 " gl_Position = vec4(1);\n"
13637 "}\n";
13638 char const *fsSource = "#version 450\n"
13639 "\n"
13640 "in block { layout(location=0, component=1) float x; } ins;\n"
13641 "layout(location=0) out vec4 color;\n"
13642 "void main(){\n"
13643 " color = vec4(ins.x);\n"
13644 "}\n";
Chris Forbese9928822016-02-17 14:44:52 +130013645
13646 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13647 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
13648
13649 VkPipelineObj pipe(m_device);
13650 pipe.AddColorAttachment();
13651 pipe.AddShader(&vs);
13652 pipe.AddShader(&fs);
13653
13654 VkDescriptorSetObj descriptorSet(m_device);
13655 descriptorSet.AppendDummy();
13656 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
13657
13658 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
13659
Chris Forbes8f36a8a2016-04-07 13:21:07 +120013660 m_errorMonitor->VerifyFound();
Chris Forbesa3e85f62016-01-15 14:53:11 +130013661}
13662
Karl Schultz6addd812016-02-02 17:17:23 -070013663TEST_F(VkLayerTest, CreatePipelineAttribNotConsumed) {
Chris Forbes1cc79542016-07-20 11:13:44 +120013664 TEST_DESCRIPTION("Test that a warning is produced for a vertex attribute which is "
13665 "not consumed by the vertex shader");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013666 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT, "location 0 not consumed by VS");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060013667
Chris Forbesde136e02015-05-25 11:13:28 +120013668 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -060013669 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbesde136e02015-05-25 11:13:28 +120013670
13671 VkVertexInputBindingDescription input_binding;
13672 memset(&input_binding, 0, sizeof(input_binding));
13673
13674 VkVertexInputAttributeDescription input_attrib;
13675 memset(&input_attrib, 0, sizeof(input_attrib));
13676 input_attrib.format = VK_FORMAT_R32_SFLOAT;
13677
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013678 char const *vsSource = "#version 450\n"
13679 "\n"
13680 "out gl_PerVertex {\n"
13681 " vec4 gl_Position;\n"
13682 "};\n"
13683 "void main(){\n"
13684 " gl_Position = vec4(1);\n"
13685 "}\n";
13686 char const *fsSource = "#version 450\n"
13687 "\n"
13688 "layout(location=0) out vec4 color;\n"
13689 "void main(){\n"
13690 " color = vec4(1);\n"
13691 "}\n";
Chris Forbesde136e02015-05-25 11:13:28 +120013692
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060013693 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13694 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbesde136e02015-05-25 11:13:28 +120013695
13696 VkPipelineObj pipe(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +080013697 pipe.AddColorAttachment();
Chris Forbesde136e02015-05-25 11:13:28 +120013698 pipe.AddShader(&vs);
13699 pipe.AddShader(&fs);
13700
13701 pipe.AddVertexInputBindings(&input_binding, 1);
13702 pipe.AddVertexInputAttribs(&input_attrib, 1);
13703
Chris Forbesde136e02015-05-25 11:13:28 +120013704 VkDescriptorSetObj descriptorSet(m_device);
13705 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080013706 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbesde136e02015-05-25 11:13:28 +120013707
Tony Barbour5781e8f2015-08-04 16:23:11 -060013708 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbesde136e02015-05-25 11:13:28 +120013709
Chris Forbes8f36a8a2016-04-07 13:21:07 +120013710 m_errorMonitor->VerifyFound();
Chris Forbesde136e02015-05-25 11:13:28 +120013711}
13712
Karl Schultz6addd812016-02-02 17:17:23 -070013713TEST_F(VkLayerTest, CreatePipelineAttribLocationMismatch) {
Chris Forbes1cc79542016-07-20 11:13:44 +120013714 TEST_DESCRIPTION("Test that a warning is produced for a location mismatch on "
13715 "vertex attributes. This flushes out bad behavior in the interface walker");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013716 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT, "location 0 not consumed by VS");
Chris Forbes7d83cd52016-01-15 11:32:03 +130013717
13718 ASSERT_NO_FATAL_FAILURE(InitState());
13719 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13720
13721 VkVertexInputBindingDescription input_binding;
13722 memset(&input_binding, 0, sizeof(input_binding));
13723
13724 VkVertexInputAttributeDescription input_attrib;
13725 memset(&input_attrib, 0, sizeof(input_attrib));
13726 input_attrib.format = VK_FORMAT_R32_SFLOAT;
13727
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013728 char const *vsSource = "#version 450\n"
13729 "\n"
13730 "layout(location=1) in float x;\n"
13731 "out gl_PerVertex {\n"
13732 " vec4 gl_Position;\n"
13733 "};\n"
13734 "void main(){\n"
13735 " gl_Position = vec4(x);\n"
13736 "}\n";
13737 char const *fsSource = "#version 450\n"
13738 "\n"
13739 "layout(location=0) out vec4 color;\n"
13740 "void main(){\n"
13741 " color = vec4(1);\n"
13742 "}\n";
Chris Forbes7d83cd52016-01-15 11:32:03 +130013743
13744 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13745 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
13746
13747 VkPipelineObj pipe(m_device);
13748 pipe.AddColorAttachment();
13749 pipe.AddShader(&vs);
13750 pipe.AddShader(&fs);
13751
13752 pipe.AddVertexInputBindings(&input_binding, 1);
13753 pipe.AddVertexInputAttribs(&input_attrib, 1);
13754
13755 VkDescriptorSetObj descriptorSet(m_device);
13756 descriptorSet.AppendDummy();
13757 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
13758
13759 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
13760
Chris Forbes8f36a8a2016-04-07 13:21:07 +120013761 m_errorMonitor->VerifyFound();
Chris Forbes7d83cd52016-01-15 11:32:03 +130013762}
13763
Karl Schultz6addd812016-02-02 17:17:23 -070013764TEST_F(VkLayerTest, CreatePipelineAttribNotProvided) {
Chris Forbes1cc79542016-07-20 11:13:44 +120013765 TEST_DESCRIPTION("Test that an error is produced for a VS input which is not "
13766 "provided by a vertex attribute");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013767 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 -060013768
Chris Forbes62e8e502015-05-25 11:13:29 +120013769 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -060013770 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbes62e8e502015-05-25 11:13:29 +120013771
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013772 char const *vsSource = "#version 450\n"
13773 "\n"
13774 "layout(location=0) in vec4 x;\n" /* not provided */
13775 "out gl_PerVertex {\n"
13776 " vec4 gl_Position;\n"
13777 "};\n"
13778 "void main(){\n"
13779 " gl_Position = x;\n"
13780 "}\n";
13781 char const *fsSource = "#version 450\n"
13782 "\n"
13783 "layout(location=0) out vec4 color;\n"
13784 "void main(){\n"
13785 " color = vec4(1);\n"
13786 "}\n";
Chris Forbes62e8e502015-05-25 11:13:29 +120013787
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060013788 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13789 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbes62e8e502015-05-25 11:13:29 +120013790
13791 VkPipelineObj pipe(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +080013792 pipe.AddColorAttachment();
Chris Forbes62e8e502015-05-25 11:13:29 +120013793 pipe.AddShader(&vs);
13794 pipe.AddShader(&fs);
13795
Chris Forbes62e8e502015-05-25 11:13:29 +120013796 VkDescriptorSetObj descriptorSet(m_device);
13797 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080013798 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbes62e8e502015-05-25 11:13:29 +120013799
Tony Barbour5781e8f2015-08-04 16:23:11 -060013800 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbes62e8e502015-05-25 11:13:29 +120013801
Chris Forbes8f36a8a2016-04-07 13:21:07 +120013802 m_errorMonitor->VerifyFound();
Chris Forbes62e8e502015-05-25 11:13:29 +120013803}
13804
Karl Schultz6addd812016-02-02 17:17:23 -070013805TEST_F(VkLayerTest, CreatePipelineAttribTypeMismatch) {
Chris Forbes1cc79542016-07-20 11:13:44 +120013806 TEST_DESCRIPTION("Test that an error is produced for a mismatch between the "
13807 "fundamental type (float/int/uint) of an attribute and the "
13808 "VS input that consumes it");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013809 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "location 0 does not match VS input type");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060013810
Chris Forbesc97d98e2015-05-25 11:13:31 +120013811 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -060013812 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbesc97d98e2015-05-25 11:13:31 +120013813
13814 VkVertexInputBindingDescription input_binding;
13815 memset(&input_binding, 0, sizeof(input_binding));
13816
13817 VkVertexInputAttributeDescription input_attrib;
13818 memset(&input_attrib, 0, sizeof(input_attrib));
13819 input_attrib.format = VK_FORMAT_R32_SFLOAT;
13820
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013821 char const *vsSource = "#version 450\n"
13822 "\n"
13823 "layout(location=0) in int x;\n" /* attrib provided float */
13824 "out gl_PerVertex {\n"
13825 " vec4 gl_Position;\n"
13826 "};\n"
13827 "void main(){\n"
13828 " gl_Position = vec4(x);\n"
13829 "}\n";
13830 char const *fsSource = "#version 450\n"
13831 "\n"
13832 "layout(location=0) out vec4 color;\n"
13833 "void main(){\n"
13834 " color = vec4(1);\n"
13835 "}\n";
Chris Forbesc97d98e2015-05-25 11:13:31 +120013836
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060013837 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13838 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbesc97d98e2015-05-25 11:13:31 +120013839
13840 VkPipelineObj pipe(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +080013841 pipe.AddColorAttachment();
Chris Forbesc97d98e2015-05-25 11:13:31 +120013842 pipe.AddShader(&vs);
13843 pipe.AddShader(&fs);
13844
13845 pipe.AddVertexInputBindings(&input_binding, 1);
13846 pipe.AddVertexInputAttribs(&input_attrib, 1);
13847
Chris Forbesc97d98e2015-05-25 11:13:31 +120013848 VkDescriptorSetObj descriptorSet(m_device);
13849 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080013850 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbesc97d98e2015-05-25 11:13:31 +120013851
Tony Barbour5781e8f2015-08-04 16:23:11 -060013852 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbesc97d98e2015-05-25 11:13:31 +120013853
Chris Forbes8f36a8a2016-04-07 13:21:07 +120013854 m_errorMonitor->VerifyFound();
Chris Forbesc97d98e2015-05-25 11:13:31 +120013855}
13856
Chris Forbesc68b43c2016-04-06 11:18:47 +120013857TEST_F(VkLayerTest, CreatePipelineDuplicateStage) {
Chris Forbes1cc79542016-07-20 11:13:44 +120013858 TEST_DESCRIPTION("Test that an error is produced for a pipeline containing multiple "
13859 "shaders for the same stage");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013860 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
13861 "Multiple shaders provided for stage VK_SHADER_STAGE_VERTEX_BIT");
Chris Forbesc68b43c2016-04-06 11:18:47 +120013862
13863 ASSERT_NO_FATAL_FAILURE(InitState());
13864 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13865
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013866 char const *vsSource = "#version 450\n"
13867 "\n"
13868 "out gl_PerVertex {\n"
13869 " vec4 gl_Position;\n"
13870 "};\n"
13871 "void main(){\n"
13872 " gl_Position = vec4(1);\n"
13873 "}\n";
13874 char const *fsSource = "#version 450\n"
13875 "\n"
13876 "layout(location=0) out vec4 color;\n"
13877 "void main(){\n"
13878 " color = vec4(1);\n"
13879 "}\n";
Chris Forbesc68b43c2016-04-06 11:18:47 +120013880
13881 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13882 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
13883
13884 VkPipelineObj pipe(m_device);
13885 pipe.AddColorAttachment();
13886 pipe.AddShader(&vs);
13887 pipe.AddShader(&vs);
13888 pipe.AddShader(&fs);
13889
13890 VkDescriptorSetObj descriptorSet(m_device);
13891 descriptorSet.AppendDummy();
13892 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
13893
13894 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
13895
Chris Forbes8f36a8a2016-04-07 13:21:07 +120013896 m_errorMonitor->VerifyFound();
Chris Forbesc68b43c2016-04-06 11:18:47 +120013897}
13898
Karl Schultz6addd812016-02-02 17:17:23 -070013899TEST_F(VkLayerTest, CreatePipelineAttribMatrixType) {
Chris Forbes1cc79542016-07-20 11:13:44 +120013900 TEST_DESCRIPTION("Test that pipeline validation accepts matrices passed "
13901 "as vertex attributes");
Chris Forbes8f36a8a2016-04-07 13:21:07 +120013902 m_errorMonitor->ExpectSuccess();
Chris Forbes2682b242015-11-24 11:13:14 +130013903
13904 ASSERT_NO_FATAL_FAILURE(InitState());
13905 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13906
13907 VkVertexInputBindingDescription input_binding;
13908 memset(&input_binding, 0, sizeof(input_binding));
13909
13910 VkVertexInputAttributeDescription input_attribs[2];
13911 memset(input_attribs, 0, sizeof(input_attribs));
13912
13913 for (int i = 0; i < 2; i++) {
13914 input_attribs[i].format = VK_FORMAT_R32G32B32A32_SFLOAT;
13915 input_attribs[i].location = i;
13916 }
13917
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013918 char const *vsSource = "#version 450\n"
13919 "\n"
13920 "layout(location=0) in mat2x4 x;\n"
13921 "out gl_PerVertex {\n"
13922 " vec4 gl_Position;\n"
13923 "};\n"
13924 "void main(){\n"
13925 " gl_Position = x[0] + x[1];\n"
13926 "}\n";
13927 char const *fsSource = "#version 450\n"
13928 "\n"
13929 "layout(location=0) out vec4 color;\n"
13930 "void main(){\n"
13931 " color = vec4(1);\n"
13932 "}\n";
Chris Forbes2682b242015-11-24 11:13:14 +130013933
13934 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13935 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
13936
13937 VkPipelineObj pipe(m_device);
13938 pipe.AddColorAttachment();
13939 pipe.AddShader(&vs);
13940 pipe.AddShader(&fs);
13941
13942 pipe.AddVertexInputBindings(&input_binding, 1);
13943 pipe.AddVertexInputAttribs(input_attribs, 2);
13944
13945 VkDescriptorSetObj descriptorSet(m_device);
13946 descriptorSet.AppendDummy();
13947 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
13948
13949 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
13950
13951 /* expect success */
Chris Forbes8f36a8a2016-04-07 13:21:07 +120013952 m_errorMonitor->VerifyNotFound();
Chris Forbes2682b242015-11-24 11:13:14 +130013953}
13954
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013955TEST_F(VkLayerTest, CreatePipelineAttribArrayType) {
Chris Forbes8f36a8a2016-04-07 13:21:07 +120013956 m_errorMonitor->ExpectSuccess();
Chris Forbes2682b242015-11-24 11:13:14 +130013957
13958 ASSERT_NO_FATAL_FAILURE(InitState());
13959 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13960
13961 VkVertexInputBindingDescription input_binding;
13962 memset(&input_binding, 0, sizeof(input_binding));
13963
13964 VkVertexInputAttributeDescription input_attribs[2];
13965 memset(input_attribs, 0, sizeof(input_attribs));
13966
13967 for (int i = 0; i < 2; i++) {
13968 input_attribs[i].format = VK_FORMAT_R32G32B32A32_SFLOAT;
13969 input_attribs[i].location = i;
13970 }
13971
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013972 char const *vsSource = "#version 450\n"
13973 "\n"
13974 "layout(location=0) in vec4 x[2];\n"
13975 "out gl_PerVertex {\n"
13976 " vec4 gl_Position;\n"
13977 "};\n"
13978 "void main(){\n"
13979 " gl_Position = x[0] + x[1];\n"
13980 "}\n";
13981 char const *fsSource = "#version 450\n"
13982 "\n"
13983 "layout(location=0) out vec4 color;\n"
13984 "void main(){\n"
13985 " color = vec4(1);\n"
13986 "}\n";
Chris Forbes2682b242015-11-24 11:13:14 +130013987
13988 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13989 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
13990
13991 VkPipelineObj pipe(m_device);
13992 pipe.AddColorAttachment();
13993 pipe.AddShader(&vs);
13994 pipe.AddShader(&fs);
13995
13996 pipe.AddVertexInputBindings(&input_binding, 1);
13997 pipe.AddVertexInputAttribs(input_attribs, 2);
13998
13999 VkDescriptorSetObj descriptorSet(m_device);
14000 descriptorSet.AppendDummy();
14001 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
14002
14003 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
14004
Chris Forbes8f36a8a2016-04-07 13:21:07 +120014005 m_errorMonitor->VerifyNotFound();
Chris Forbes2682b242015-11-24 11:13:14 +130014006}
Chris Forbes2682b242015-11-24 11:13:14 +130014007
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014008TEST_F(VkLayerTest, CreatePipelineAttribComponents) {
Chris Forbes1cc79542016-07-20 11:13:44 +120014009 TEST_DESCRIPTION("Test that pipeline validation accepts consuming a vertex attribute "
14010 "through multiple VS inputs, each consuming a different subset of the "
14011 "components.");
Chris Forbesbc290ce2016-07-06 12:01:49 +120014012 m_errorMonitor->ExpectSuccess();
14013
14014 ASSERT_NO_FATAL_FAILURE(InitState());
14015 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
14016
14017 VkVertexInputBindingDescription input_binding;
14018 memset(&input_binding, 0, sizeof(input_binding));
14019
14020 VkVertexInputAttributeDescription input_attribs[3];
14021 memset(input_attribs, 0, sizeof(input_attribs));
14022
14023 for (int i = 0; i < 3; i++) {
14024 input_attribs[i].format = VK_FORMAT_R32G32B32A32_SFLOAT;
14025 input_attribs[i].location = i;
14026 }
14027
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014028 char const *vsSource = "#version 450\n"
14029 "\n"
14030 "layout(location=0) in vec4 x;\n"
14031 "layout(location=1) in vec3 y1;\n"
14032 "layout(location=1, component=3) in float y2;\n"
14033 "layout(location=2) in vec4 z;\n"
14034 "out gl_PerVertex {\n"
14035 " vec4 gl_Position;\n"
14036 "};\n"
14037 "void main(){\n"
14038 " gl_Position = x + vec4(y1, y2) + z;\n"
14039 "}\n";
14040 char const *fsSource = "#version 450\n"
14041 "\n"
14042 "layout(location=0) out vec4 color;\n"
14043 "void main(){\n"
14044 " color = vec4(1);\n"
14045 "}\n";
Chris Forbesbc290ce2016-07-06 12:01:49 +120014046
14047 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
14048 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
14049
14050 VkPipelineObj pipe(m_device);
14051 pipe.AddColorAttachment();
14052 pipe.AddShader(&vs);
14053 pipe.AddShader(&fs);
14054
14055 pipe.AddVertexInputBindings(&input_binding, 1);
14056 pipe.AddVertexInputAttribs(input_attribs, 3);
14057
14058 VkDescriptorSetObj descriptorSet(m_device);
14059 descriptorSet.AppendDummy();
14060 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
14061
14062 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
14063
14064 m_errorMonitor->VerifyNotFound();
14065}
14066
Chris Forbes82ff92a2016-09-09 10:50:24 +120014067TEST_F(VkLayerTest, CreatePipelineMissingEntrypoint) {
14068 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
14069 "No entrypoint found named `foo`");
14070
14071 ASSERT_NO_FATAL_FAILURE(InitState());
14072 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
14073
14074 char const *vsSource = "#version 450\n"
14075 "out gl_PerVertex {\n"
14076 " vec4 gl_Position;\n"
14077 "};\n"
14078 "void main(){\n"
14079 " gl_Position = vec4(0);\n"
14080 "}\n";
14081 char const *fsSource = "#version 450\n"
14082 "\n"
14083 "layout(location=0) out vec4 color;\n"
14084 "void main(){\n"
14085 " color = vec4(1);\n"
14086 "}\n";
14087
14088 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
14089 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this, "foo");
14090
14091 VkPipelineObj pipe(m_device);
14092 pipe.AddColorAttachment();
14093 pipe.AddShader(&vs);
14094 pipe.AddShader(&fs);
14095
14096 VkDescriptorSetObj descriptorSet(m_device);
14097 descriptorSet.AppendDummy();
14098 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
14099
14100 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
14101
14102 m_errorMonitor->VerifyFound();
14103}
14104
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014105TEST_F(VkLayerTest, CreatePipelineSimplePositive) {
Chris Forbes8f36a8a2016-04-07 13:21:07 +120014106 m_errorMonitor->ExpectSuccess();
Chris Forbes4ea14fc2016-04-04 18:52:54 +120014107
14108 ASSERT_NO_FATAL_FAILURE(InitState());
14109 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
14110
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014111 char const *vsSource = "#version 450\n"
14112 "out gl_PerVertex {\n"
14113 " vec4 gl_Position;\n"
14114 "};\n"
14115 "void main(){\n"
14116 " gl_Position = vec4(0);\n"
14117 "}\n";
14118 char const *fsSource = "#version 450\n"
14119 "\n"
14120 "layout(location=0) out vec4 color;\n"
14121 "void main(){\n"
14122 " color = vec4(1);\n"
14123 "}\n";
Chris Forbes4ea14fc2016-04-04 18:52:54 +120014124
14125 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
14126 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
14127
14128 VkPipelineObj pipe(m_device);
14129 pipe.AddColorAttachment();
14130 pipe.AddShader(&vs);
14131 pipe.AddShader(&fs);
14132
14133 VkDescriptorSetObj descriptorSet(m_device);
14134 descriptorSet.AppendDummy();
14135 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
14136
14137 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
14138
Chris Forbes8f36a8a2016-04-07 13:21:07 +120014139 m_errorMonitor->VerifyNotFound();
Chris Forbes4ea14fc2016-04-04 18:52:54 +120014140}
14141
Chris Forbesae9d8cd2016-09-13 16:32:57 +120014142TEST_F(VkLayerTest, CreatePipelineDepthStencilRequired) {
14143 m_errorMonitor->SetDesiredFailureMsg(
14144 VK_DEBUG_REPORT_ERROR_BIT_EXT,
14145 "pDepthStencilState is NULL when rasterization is enabled and subpass "
14146 "uses a depth/stencil attachment");
14147
14148 ASSERT_NO_FATAL_FAILURE(InitState());
14149 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
14150
14151 char const *vsSource = "#version 450\n"
14152 "void main(){ gl_Position = vec4(0); }\n";
14153 char const *fsSource = "#version 450\n"
14154 "\n"
14155 "layout(location=0) out vec4 color;\n"
14156 "void main(){\n"
14157 " color = vec4(1);\n"
14158 "}\n";
14159
14160 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
14161 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
14162
14163 VkPipelineObj pipe(m_device);
14164 pipe.AddColorAttachment();
14165 pipe.AddShader(&vs);
14166 pipe.AddShader(&fs);
14167
14168 VkDescriptorSetObj descriptorSet(m_device);
14169 descriptorSet.AppendDummy();
14170 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
14171
14172 VkAttachmentDescription attachments[] = {
14173 { 0, VK_FORMAT_B8G8R8A8_UNORM, VK_SAMPLE_COUNT_1_BIT,
14174 VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE,
14175 VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE,
14176 VK_IMAGE_LAYOUT_UNDEFINED, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
14177 },
14178 { 0, VK_FORMAT_D16_UNORM, VK_SAMPLE_COUNT_1_BIT,
14179 VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE,
14180 VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE,
14181 VK_IMAGE_LAYOUT_UNDEFINED, VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL,
14182 },
14183 };
14184 VkAttachmentReference refs[] = {
14185 { 0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL },
14186 { 1, VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL },
14187 };
14188 VkSubpassDescription subpass = {
14189 0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr,
14190 1, &refs[0], nullptr, &refs[1],
14191 0, nullptr
14192 };
14193 VkRenderPassCreateInfo rpci = {
14194 VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr,
14195 0, 2, attachments, 1, &subpass, 0, nullptr
14196 };
14197 VkRenderPass rp;
14198 VkResult err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
14199 ASSERT_VK_SUCCESS(err);
14200
14201 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), rp);
14202
14203 m_errorMonitor->VerifyFound();
14204
14205 vkDestroyRenderPass(m_device->device(), rp, nullptr);
14206}
14207
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014208TEST_F(VkLayerTest, CreatePipelineRelaxedTypeMatch) {
Chris Forbes1cc79542016-07-20 11:13:44 +120014209 TEST_DESCRIPTION("Test that pipeline validation accepts the relaxed type matching rules "
14210 "set out in 14.1.3: fundamental type must match, and producer side must "
14211 "have at least as many components");
Chris Forbes8f36a8a2016-04-07 13:21:07 +120014212 m_errorMonitor->ExpectSuccess();
Chris Forbes912c9192016-04-05 17:50:35 +120014213
14214 // VK 1.0.8 Specification, 14.1.3 "Additionally,..." block
14215
14216 ASSERT_NO_FATAL_FAILURE(InitState());
14217 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
14218
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014219 char const *vsSource = "#version 450\n"
14220 "out gl_PerVertex {\n"
14221 " vec4 gl_Position;\n"
14222 "};\n"
14223 "layout(location=0) out vec3 x;\n"
14224 "layout(location=1) out ivec3 y;\n"
14225 "layout(location=2) out vec3 z;\n"
14226 "void main(){\n"
14227 " gl_Position = vec4(0);\n"
14228 " x = vec3(0); y = ivec3(0); z = vec3(0);\n"
14229 "}\n";
14230 char const *fsSource = "#version 450\n"
14231 "\n"
14232 "layout(location=0) out vec4 color;\n"
14233 "layout(location=0) in float x;\n"
14234 "layout(location=1) flat in int y;\n"
14235 "layout(location=2) in vec2 z;\n"
14236 "void main(){\n"
14237 " color = vec4(1 + x + y + z.x);\n"
14238 "}\n";
Chris Forbes912c9192016-04-05 17:50:35 +120014239
14240 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
14241 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
14242
14243 VkPipelineObj pipe(m_device);
14244 pipe.AddColorAttachment();
14245 pipe.AddShader(&vs);
14246 pipe.AddShader(&fs);
14247
14248 VkDescriptorSetObj descriptorSet(m_device);
14249 descriptorSet.AppendDummy();
14250 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
14251
Mike Stroyan255e9582016-06-24 09:49:32 -060014252 VkResult err = VK_SUCCESS;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014253 err = pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Mike Stroyan255e9582016-06-24 09:49:32 -060014254 ASSERT_VK_SUCCESS(err);
14255
Chris Forbes8f36a8a2016-04-07 13:21:07 +120014256 m_errorMonitor->VerifyNotFound();
Chris Forbes912c9192016-04-05 17:50:35 +120014257}
14258
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014259TEST_F(VkLayerTest, CreatePipelineTessPerVertex) {
Chris Forbes1cc79542016-07-20 11:13:44 +120014260 TEST_DESCRIPTION("Test that pipeline validation accepts per-vertex variables "
14261 "passed between the TCS and TES stages");
Chris Forbes8f36a8a2016-04-07 13:21:07 +120014262 m_errorMonitor->ExpectSuccess();
Chris Forbes4ea14fc2016-04-04 18:52:54 +120014263
14264 ASSERT_NO_FATAL_FAILURE(InitState());
14265 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
14266
Chris Forbesc1e852d2016-04-04 19:26:42 +120014267 if (!m_device->phy().features().tessellationShader) {
14268 printf("Device does not support tessellation shaders; skipped.\n");
14269 return;
14270 }
14271
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014272 char const *vsSource = "#version 450\n"
14273 "void main(){}\n";
14274 char const *tcsSource = "#version 450\n"
14275 "layout(location=0) out int x[];\n"
14276 "layout(vertices=3) out;\n"
14277 "void main(){\n"
14278 " gl_TessLevelOuter[0] = gl_TessLevelOuter[1] = gl_TessLevelOuter[2] = 1;\n"
14279 " gl_TessLevelInner[0] = 1;\n"
14280 " x[gl_InvocationID] = gl_InvocationID;\n"
14281 "}\n";
14282 char const *tesSource = "#version 450\n"
14283 "layout(triangles, equal_spacing, cw) in;\n"
14284 "layout(location=0) in int x[];\n"
14285 "out gl_PerVertex { vec4 gl_Position; };\n"
14286 "void main(){\n"
14287 " gl_Position.xyz = gl_TessCoord;\n"
14288 " gl_Position.w = x[0] + x[1] + x[2];\n"
14289 "}\n";
14290 char const *fsSource = "#version 450\n"
14291 "layout(location=0) out vec4 color;\n"
14292 "void main(){\n"
14293 " color = vec4(1);\n"
14294 "}\n";
Chris Forbes4ea14fc2016-04-04 18:52:54 +120014295
14296 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
14297 VkShaderObj tcs(m_device, tcsSource, VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT, this);
14298 VkShaderObj tes(m_device, tesSource, VK_SHADER_STAGE_TESSELLATION_EVALUATION_BIT, this);
14299 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
14300
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014301 VkPipelineInputAssemblyStateCreateInfo iasci{VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO, nullptr, 0,
14302 VK_PRIMITIVE_TOPOLOGY_PATCH_LIST, VK_FALSE};
Chris Forbes4ea14fc2016-04-04 18:52:54 +120014303
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014304 VkPipelineTessellationStateCreateInfo tsci{VK_STRUCTURE_TYPE_PIPELINE_TESSELLATION_STATE_CREATE_INFO, nullptr, 0, 3};
Chris Forbesb4cacb62016-04-04 19:15:00 +120014305
Chris Forbes4ea14fc2016-04-04 18:52:54 +120014306 VkPipelineObj pipe(m_device);
14307 pipe.SetInputAssembly(&iasci);
Chris Forbesb4cacb62016-04-04 19:15:00 +120014308 pipe.SetTessellation(&tsci);
Chris Forbes4ea14fc2016-04-04 18:52:54 +120014309 pipe.AddColorAttachment();
14310 pipe.AddShader(&vs);
14311 pipe.AddShader(&tcs);
14312 pipe.AddShader(&tes);
14313 pipe.AddShader(&fs);
14314
14315 VkDescriptorSetObj descriptorSet(m_device);
14316 descriptorSet.AppendDummy();
14317 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
14318
14319 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
14320
Chris Forbes8f36a8a2016-04-07 13:21:07 +120014321 m_errorMonitor->VerifyNotFound();
Chris Forbes4ea14fc2016-04-04 18:52:54 +120014322}
14323
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014324TEST_F(VkLayerTest, CreatePipelineGeometryInputBlockPositive) {
Chris Forbes1cc79542016-07-20 11:13:44 +120014325 TEST_DESCRIPTION("Test that pipeline validation accepts a user-defined "
14326 "interface block passed into the geometry shader. This "
14327 "is interesting because the 'extra' array level is not "
14328 "present on the member type, but on the block instance.");
Chris Forbesa0ab8152016-04-20 13:34:27 +120014329 m_errorMonitor->ExpectSuccess();
14330
14331 ASSERT_NO_FATAL_FAILURE(InitState());
14332 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
14333
14334 if (!m_device->phy().features().geometryShader) {
14335 printf("Device does not support geometry shaders; skipped.\n");
14336 return;
14337 }
14338
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014339 char const *vsSource = "#version 450\n"
14340 "layout(location=0) out VertexData { vec4 x; } vs_out;\n"
14341 "void main(){\n"
14342 " vs_out.x = vec4(1);\n"
14343 "}\n";
14344 char const *gsSource = "#version 450\n"
14345 "layout(triangles) in;\n"
14346 "layout(triangle_strip, max_vertices=3) out;\n"
14347 "layout(location=0) in VertexData { vec4 x; } gs_in[];\n"
14348 "out gl_PerVertex { vec4 gl_Position; };\n"
14349 "void main() {\n"
14350 " gl_Position = gs_in[0].x;\n"
14351 " EmitVertex();\n"
14352 "}\n";
14353 char const *fsSource = "#version 450\n"
14354 "layout(location=0) out vec4 color;\n"
14355 "void main(){\n"
14356 " color = vec4(1);\n"
14357 "}\n";
Chris Forbesa0ab8152016-04-20 13:34:27 +120014358
14359 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
14360 VkShaderObj gs(m_device, gsSource, VK_SHADER_STAGE_GEOMETRY_BIT, this);
14361 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
14362
14363 VkPipelineObj pipe(m_device);
14364 pipe.AddColorAttachment();
14365 pipe.AddShader(&vs);
14366 pipe.AddShader(&gs);
14367 pipe.AddShader(&fs);
14368
14369 VkDescriptorSetObj descriptorSet(m_device);
14370 descriptorSet.AppendDummy();
14371 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
14372
14373 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
14374
14375 m_errorMonitor->VerifyNotFound();
14376}
14377
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014378TEST_F(VkLayerTest, CreatePipelineTessPatchDecorationMismatch) {
Chris Forbes1cc79542016-07-20 11:13:44 +120014379 TEST_DESCRIPTION("Test that an error is produced for a variable output from "
14380 "the TCS without the patch decoration, but consumed in the TES "
14381 "with the decoration.");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014382 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "is per-vertex in tessellation control shader stage "
14383 "but per-patch in tessellation evaluation shader stage");
Chris Forbesa0193bc2016-04-04 19:19:47 +120014384
14385 ASSERT_NO_FATAL_FAILURE(InitState());
14386 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
14387
Chris Forbesc1e852d2016-04-04 19:26:42 +120014388 if (!m_device->phy().features().tessellationShader) {
14389 printf("Device does not support tessellation shaders; skipped.\n");
14390 return;
14391 }
14392
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014393 char const *vsSource = "#version 450\n"
14394 "void main(){}\n";
14395 char const *tcsSource = "#version 450\n"
14396 "layout(location=0) out int x[];\n"
14397 "layout(vertices=3) out;\n"
14398 "void main(){\n"
14399 " gl_TessLevelOuter[0] = gl_TessLevelOuter[1] = gl_TessLevelOuter[2] = 1;\n"
14400 " gl_TessLevelInner[0] = 1;\n"
14401 " x[gl_InvocationID] = gl_InvocationID;\n"
14402 "}\n";
14403 char const *tesSource = "#version 450\n"
14404 "layout(triangles, equal_spacing, cw) in;\n"
14405 "layout(location=0) patch in int x;\n"
14406 "out gl_PerVertex { vec4 gl_Position; };\n"
14407 "void main(){\n"
14408 " gl_Position.xyz = gl_TessCoord;\n"
14409 " gl_Position.w = x;\n"
14410 "}\n";
14411 char const *fsSource = "#version 450\n"
14412 "layout(location=0) out vec4 color;\n"
14413 "void main(){\n"
14414 " color = vec4(1);\n"
14415 "}\n";
Chris Forbesa0193bc2016-04-04 19:19:47 +120014416
14417 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
14418 VkShaderObj tcs(m_device, tcsSource, VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT, this);
14419 VkShaderObj tes(m_device, tesSource, VK_SHADER_STAGE_TESSELLATION_EVALUATION_BIT, this);
14420 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
14421
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014422 VkPipelineInputAssemblyStateCreateInfo iasci{VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO, nullptr, 0,
14423 VK_PRIMITIVE_TOPOLOGY_PATCH_LIST, VK_FALSE};
Chris Forbesa0193bc2016-04-04 19:19:47 +120014424
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014425 VkPipelineTessellationStateCreateInfo tsci{VK_STRUCTURE_TYPE_PIPELINE_TESSELLATION_STATE_CREATE_INFO, nullptr, 0, 3};
Chris Forbesa0193bc2016-04-04 19:19:47 +120014426
14427 VkPipelineObj pipe(m_device);
14428 pipe.SetInputAssembly(&iasci);
14429 pipe.SetTessellation(&tsci);
14430 pipe.AddColorAttachment();
14431 pipe.AddShader(&vs);
14432 pipe.AddShader(&tcs);
14433 pipe.AddShader(&tes);
14434 pipe.AddShader(&fs);
14435
14436 VkDescriptorSetObj descriptorSet(m_device);
14437 descriptorSet.AppendDummy();
14438 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
14439
14440 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
14441
Chris Forbes8f36a8a2016-04-07 13:21:07 +120014442 m_errorMonitor->VerifyFound();
Chris Forbesa0193bc2016-04-04 19:19:47 +120014443}
14444
Karl Schultz6addd812016-02-02 17:17:23 -070014445TEST_F(VkLayerTest, CreatePipelineAttribBindingConflict) {
Chris Forbes1cc79542016-07-20 11:13:44 +120014446 TEST_DESCRIPTION("Test that an error is produced for a vertex attribute setup where multiple "
14447 "bindings provide the same location");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014448 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
14449 "Duplicate vertex input binding descriptions for binding 0");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060014450
Chris Forbes280ba2c2015-06-12 11:16:41 +120014451 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -060014452 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbes280ba2c2015-06-12 11:16:41 +120014453
14454 /* Two binding descriptions for binding 0 */
14455 VkVertexInputBindingDescription input_bindings[2];
14456 memset(input_bindings, 0, sizeof(input_bindings));
14457
14458 VkVertexInputAttributeDescription input_attrib;
14459 memset(&input_attrib, 0, sizeof(input_attrib));
14460 input_attrib.format = VK_FORMAT_R32_SFLOAT;
14461
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014462 char const *vsSource = "#version 450\n"
14463 "\n"
14464 "layout(location=0) in float x;\n" /* attrib provided float */
14465 "out gl_PerVertex {\n"
14466 " vec4 gl_Position;\n"
14467 "};\n"
14468 "void main(){\n"
14469 " gl_Position = vec4(x);\n"
14470 "}\n";
14471 char const *fsSource = "#version 450\n"
14472 "\n"
14473 "layout(location=0) out vec4 color;\n"
14474 "void main(){\n"
14475 " color = vec4(1);\n"
14476 "}\n";
Chris Forbes280ba2c2015-06-12 11:16:41 +120014477
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060014478 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
14479 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbes280ba2c2015-06-12 11:16:41 +120014480
14481 VkPipelineObj pipe(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +080014482 pipe.AddColorAttachment();
Chris Forbes280ba2c2015-06-12 11:16:41 +120014483 pipe.AddShader(&vs);
14484 pipe.AddShader(&fs);
14485
14486 pipe.AddVertexInputBindings(input_bindings, 2);
14487 pipe.AddVertexInputAttribs(&input_attrib, 1);
14488
Chris Forbes280ba2c2015-06-12 11:16:41 +120014489 VkDescriptorSetObj descriptorSet(m_device);
14490 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014491 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbes280ba2c2015-06-12 11:16:41 +120014492
Tony Barbour5781e8f2015-08-04 16:23:11 -060014493 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbes280ba2c2015-06-12 11:16:41 +120014494
Chris Forbes8f36a8a2016-04-07 13:21:07 +120014495 m_errorMonitor->VerifyFound();
Chris Forbes280ba2c2015-06-12 11:16:41 +120014496}
Chris Forbes8f68b562015-05-25 11:13:32 +120014497
Chris Forbes35efec72016-04-21 14:32:08 +120014498TEST_F(VkLayerTest, CreatePipeline64BitAttributesPositive) {
Chris Forbes1cc79542016-07-20 11:13:44 +120014499 TEST_DESCRIPTION("Test that pipeline validation accepts basic use of 64bit vertex "
14500 "attributes. This is interesting because they consume multiple "
14501 "locations.");
Chris Forbes35efec72016-04-21 14:32:08 +120014502 m_errorMonitor->ExpectSuccess();
14503
14504 ASSERT_NO_FATAL_FAILURE(InitState());
14505 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
14506
Chris Forbes91cf3a82016-06-28 17:51:35 +120014507 if (!m_device->phy().features().shaderFloat64) {
Chris Forbes35efec72016-04-21 14:32:08 +120014508 printf("Device does not support 64bit vertex attributes; skipped.\n");
14509 return;
14510 }
14511
14512 VkVertexInputBindingDescription input_bindings[1];
14513 memset(input_bindings, 0, sizeof(input_bindings));
14514
14515 VkVertexInputAttributeDescription input_attribs[4];
14516 memset(input_attribs, 0, sizeof(input_attribs));
14517 input_attribs[0].location = 0;
14518 input_attribs[0].offset = 0;
14519 input_attribs[0].format = VK_FORMAT_R64G64B64A64_SFLOAT;
14520 input_attribs[1].location = 2;
14521 input_attribs[1].offset = 32;
14522 input_attribs[1].format = VK_FORMAT_R64G64B64A64_SFLOAT;
14523 input_attribs[2].location = 4;
14524 input_attribs[2].offset = 64;
14525 input_attribs[2].format = VK_FORMAT_R64G64B64A64_SFLOAT;
14526 input_attribs[3].location = 6;
14527 input_attribs[3].offset = 96;
14528 input_attribs[3].format = VK_FORMAT_R64G64B64A64_SFLOAT;
14529
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014530 char const *vsSource = "#version 450\n"
14531 "\n"
14532 "layout(location=0) in dmat4 x;\n"
14533 "out gl_PerVertex {\n"
14534 " vec4 gl_Position;\n"
14535 "};\n"
14536 "void main(){\n"
14537 " gl_Position = vec4(x[0][0]);\n"
14538 "}\n";
14539 char const *fsSource = "#version 450\n"
14540 "\n"
14541 "layout(location=0) out vec4 color;\n"
14542 "void main(){\n"
14543 " color = vec4(1);\n"
14544 "}\n";
Chris Forbes35efec72016-04-21 14:32:08 +120014545
14546 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
14547 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
14548
14549 VkPipelineObj pipe(m_device);
14550 pipe.AddColorAttachment();
14551 pipe.AddShader(&vs);
14552 pipe.AddShader(&fs);
14553
14554 pipe.AddVertexInputBindings(input_bindings, 1);
14555 pipe.AddVertexInputAttribs(input_attribs, 4);
14556
14557 VkDescriptorSetObj descriptorSet(m_device);
14558 descriptorSet.AppendDummy();
14559 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
14560
14561 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
14562
14563 m_errorMonitor->VerifyNotFound();
14564}
14565
Karl Schultz6addd812016-02-02 17:17:23 -070014566TEST_F(VkLayerTest, CreatePipelineFragmentOutputNotWritten) {
Chris Forbes1cc79542016-07-20 11:13:44 +120014567 TEST_DESCRIPTION("Test that an error is produced for a FS which does not "
14568 "provide an output for one of the pipeline's color attachments");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014569 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Attachment 0 not written by FS");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060014570
Chris Forbes4d6d1e52015-05-25 11:13:40 +120014571 ASSERT_NO_FATAL_FAILURE(InitState());
Chris Forbes4d6d1e52015-05-25 11:13:40 +120014572
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014573 char const *vsSource = "#version 450\n"
14574 "\n"
14575 "out gl_PerVertex {\n"
14576 " vec4 gl_Position;\n"
14577 "};\n"
14578 "void main(){\n"
14579 " gl_Position = vec4(1);\n"
14580 "}\n";
14581 char const *fsSource = "#version 450\n"
14582 "\n"
14583 "void main(){\n"
14584 "}\n";
Chris Forbes4d6d1e52015-05-25 11:13:40 +120014585
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060014586 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
14587 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbes4d6d1e52015-05-25 11:13:40 +120014588
14589 VkPipelineObj pipe(m_device);
14590 pipe.AddShader(&vs);
14591 pipe.AddShader(&fs);
14592
Chia-I Wu08accc62015-07-07 11:50:03 +080014593 /* set up CB 0, not written */
14594 pipe.AddColorAttachment();
14595 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbes4d6d1e52015-05-25 11:13:40 +120014596
Chris Forbes4d6d1e52015-05-25 11:13:40 +120014597 VkDescriptorSetObj descriptorSet(m_device);
14598 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014599 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbes4d6d1e52015-05-25 11:13:40 +120014600
Tony Barbour5781e8f2015-08-04 16:23:11 -060014601 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbes4d6d1e52015-05-25 11:13:40 +120014602
Chris Forbes8f36a8a2016-04-07 13:21:07 +120014603 m_errorMonitor->VerifyFound();
Chris Forbes4d6d1e52015-05-25 11:13:40 +120014604}
14605
Karl Schultz6addd812016-02-02 17:17:23 -070014606TEST_F(VkLayerTest, CreatePipelineFragmentOutputNotConsumed) {
Chris Forbes1cc79542016-07-20 11:13:44 +120014607 TEST_DESCRIPTION("Test that a warning is produced for a FS which provides a spurious "
14608 "output with no matching attachment");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014609 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT,
14610 "FS writes to output location 1 with no matching attachment");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060014611
Chris Forbesf3fffaa2015-05-25 11:13:43 +120014612 ASSERT_NO_FATAL_FAILURE(InitState());
Chris Forbesf3fffaa2015-05-25 11:13:43 +120014613
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014614 char const *vsSource = "#version 450\n"
14615 "\n"
14616 "out gl_PerVertex {\n"
14617 " vec4 gl_Position;\n"
14618 "};\n"
14619 "void main(){\n"
14620 " gl_Position = vec4(1);\n"
14621 "}\n";
14622 char const *fsSource = "#version 450\n"
14623 "\n"
14624 "layout(location=0) out vec4 x;\n"
14625 "layout(location=1) out vec4 y;\n" /* no matching attachment for this */
14626 "void main(){\n"
14627 " x = vec4(1);\n"
14628 " y = vec4(1);\n"
14629 "}\n";
Chris Forbesf3fffaa2015-05-25 11:13:43 +120014630
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060014631 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
14632 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbesf3fffaa2015-05-25 11:13:43 +120014633
14634 VkPipelineObj pipe(m_device);
14635 pipe.AddShader(&vs);
14636 pipe.AddShader(&fs);
14637
Chia-I Wu08accc62015-07-07 11:50:03 +080014638 /* set up CB 0, not written */
14639 pipe.AddColorAttachment();
14640 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbesf3fffaa2015-05-25 11:13:43 +120014641 /* FS writes CB 1, but we don't configure it */
14642
Chris Forbesf3fffaa2015-05-25 11:13:43 +120014643 VkDescriptorSetObj descriptorSet(m_device);
14644 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014645 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbesf3fffaa2015-05-25 11:13:43 +120014646
Tony Barbour5781e8f2015-08-04 16:23:11 -060014647 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbesf3fffaa2015-05-25 11:13:43 +120014648
Chris Forbes8f36a8a2016-04-07 13:21:07 +120014649 m_errorMonitor->VerifyFound();
Chris Forbesf3fffaa2015-05-25 11:13:43 +120014650}
14651
Karl Schultz6addd812016-02-02 17:17:23 -070014652TEST_F(VkLayerTest, CreatePipelineFragmentOutputTypeMismatch) {
Chris Forbes1cc79542016-07-20 11:13:44 +120014653 TEST_DESCRIPTION("Test that an error is produced for a mismatch between the fundamental "
14654 "type of an FS output variable, and the format of the corresponding attachment");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014655 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "does not match FS output type");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060014656
Chris Forbesa36d69e2015-05-25 11:13:44 +120014657 ASSERT_NO_FATAL_FAILURE(InitState());
Chris Forbesa36d69e2015-05-25 11:13:44 +120014658
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014659 char const *vsSource = "#version 450\n"
14660 "\n"
14661 "out gl_PerVertex {\n"
14662 " vec4 gl_Position;\n"
14663 "};\n"
14664 "void main(){\n"
14665 " gl_Position = vec4(1);\n"
14666 "}\n";
14667 char const *fsSource = "#version 450\n"
14668 "\n"
14669 "layout(location=0) out ivec4 x;\n" /* not UNORM */
14670 "void main(){\n"
14671 " x = ivec4(1);\n"
14672 "}\n";
Chris Forbesa36d69e2015-05-25 11:13:44 +120014673
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060014674 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
14675 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbesa36d69e2015-05-25 11:13:44 +120014676
14677 VkPipelineObj pipe(m_device);
14678 pipe.AddShader(&vs);
14679 pipe.AddShader(&fs);
14680
Chia-I Wu08accc62015-07-07 11:50:03 +080014681 /* set up CB 0; type is UNORM by default */
14682 pipe.AddColorAttachment();
14683 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbesa36d69e2015-05-25 11:13:44 +120014684
Chris Forbesa36d69e2015-05-25 11:13:44 +120014685 VkDescriptorSetObj descriptorSet(m_device);
14686 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014687 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbesa36d69e2015-05-25 11:13:44 +120014688
Tony Barbour5781e8f2015-08-04 16:23:11 -060014689 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbesa36d69e2015-05-25 11:13:44 +120014690
Chris Forbes8f36a8a2016-04-07 13:21:07 +120014691 m_errorMonitor->VerifyFound();
Chris Forbesa36d69e2015-05-25 11:13:44 +120014692}
Chris Forbes7b1b8932015-06-05 14:43:36 +120014693
Karl Schultz6addd812016-02-02 17:17:23 -070014694TEST_F(VkLayerTest, CreatePipelineUniformBlockNotProvided) {
Chris Forbes1cc79542016-07-20 11:13:44 +120014695 TEST_DESCRIPTION("Test that an error is produced for a shader consuming a uniform "
14696 "block which has no corresponding binding in the pipeline layout");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014697 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "not declared in pipeline layout");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060014698
Chris Forbes556c76c2015-08-14 12:04:59 +120014699 ASSERT_NO_FATAL_FAILURE(InitState());
Chris Forbes556c76c2015-08-14 12:04:59 +120014700
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014701 char const *vsSource = "#version 450\n"
14702 "\n"
14703 "out gl_PerVertex {\n"
14704 " vec4 gl_Position;\n"
14705 "};\n"
14706 "void main(){\n"
14707 " gl_Position = vec4(1);\n"
14708 "}\n";
14709 char const *fsSource = "#version 450\n"
14710 "\n"
14711 "layout(location=0) out vec4 x;\n"
14712 "layout(set=0) layout(binding=0) uniform foo { int x; int y; } bar;\n"
14713 "void main(){\n"
14714 " x = vec4(bar.y);\n"
14715 "}\n";
Chris Forbes556c76c2015-08-14 12:04:59 +120014716
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060014717 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
14718 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbes556c76c2015-08-14 12:04:59 +120014719
Chris Forbes556c76c2015-08-14 12:04:59 +120014720 VkPipelineObj pipe(m_device);
14721 pipe.AddShader(&vs);
14722 pipe.AddShader(&fs);
14723
14724 /* set up CB 0; type is UNORM by default */
14725 pipe.AddColorAttachment();
14726 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
14727
14728 VkDescriptorSetObj descriptorSet(m_device);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014729 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbes556c76c2015-08-14 12:04:59 +120014730
14731 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
14732
Chris Forbes8f36a8a2016-04-07 13:21:07 +120014733 m_errorMonitor->VerifyFound();
Chris Forbes556c76c2015-08-14 12:04:59 +120014734}
14735
Chris Forbes5c59e902016-02-26 16:56:09 +130014736TEST_F(VkLayerTest, CreatePipelinePushConstantsNotInLayout) {
Chris Forbes1cc79542016-07-20 11:13:44 +120014737 TEST_DESCRIPTION("Test that an error is produced for a shader consuming push constants "
14738 "which are not provided in the pipeline layout");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014739 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "not declared in layout");
Chris Forbes5c59e902016-02-26 16:56:09 +130014740
14741 ASSERT_NO_FATAL_FAILURE(InitState());
14742
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014743 char const *vsSource = "#version 450\n"
14744 "\n"
14745 "layout(push_constant, std430) uniform foo { float x; } consts;\n"
14746 "out gl_PerVertex {\n"
14747 " vec4 gl_Position;\n"
14748 "};\n"
14749 "void main(){\n"
14750 " gl_Position = vec4(consts.x);\n"
14751 "}\n";
14752 char const *fsSource = "#version 450\n"
14753 "\n"
14754 "layout(location=0) out vec4 x;\n"
14755 "void main(){\n"
14756 " x = vec4(1);\n"
14757 "}\n";
Chris Forbes5c59e902016-02-26 16:56:09 +130014758
14759 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
14760 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
14761
14762 VkPipelineObj pipe(m_device);
14763 pipe.AddShader(&vs);
14764 pipe.AddShader(&fs);
14765
14766 /* set up CB 0; type is UNORM by default */
14767 pipe.AddColorAttachment();
14768 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
14769
14770 VkDescriptorSetObj descriptorSet(m_device);
14771 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
14772
14773 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
14774
14775 /* should have generated an error -- no push constant ranges provided! */
Chris Forbes8f36a8a2016-04-07 13:21:07 +120014776 m_errorMonitor->VerifyFound();
Chris Forbes5c59e902016-02-26 16:56:09 +130014777}
14778
Chris Forbes3fb17902016-08-22 14:57:55 +120014779TEST_F(VkLayerTest, CreatePipelineInputAttachmentMissing) {
14780 TEST_DESCRIPTION("Test that an error is produced for a shader consuming an input attachment "
14781 "which is not included in the subpass description");
14782 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
14783 "consumes input attachment index 0 but not provided in subpass");
14784
14785 ASSERT_NO_FATAL_FAILURE(InitState());
14786
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014787 char const *vsSource = "#version 450\n"
14788 "\n"
14789 "out gl_PerVertex {\n"
14790 " vec4 gl_Position;\n"
14791 "};\n"
14792 "void main(){\n"
14793 " gl_Position = vec4(1);\n"
14794 "}\n";
14795 char const *fsSource = "#version 450\n"
14796 "\n"
14797 "layout(input_attachment_index=0, set=0, binding=0) uniform subpassInput x;\n"
14798 "layout(location=0) out vec4 color;\n"
14799 "void main() {\n"
14800 " color = subpassLoad(x);\n"
14801 "}\n";
Chris Forbes3fb17902016-08-22 14:57:55 +120014802
14803 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
14804 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
14805
14806 VkPipelineObj pipe(m_device);
14807 pipe.AddShader(&vs);
14808 pipe.AddShader(&fs);
14809 pipe.AddColorAttachment();
14810 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
14811
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014812 VkDescriptorSetLayoutBinding dslb = {0, VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT, 1, VK_SHADER_STAGE_FRAGMENT_BIT, nullptr};
14813 VkDescriptorSetLayoutCreateInfo dslci = {VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dslb};
Chris Forbes3fb17902016-08-22 14:57:55 +120014814 VkDescriptorSetLayout dsl;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014815 VkResult err = vkCreateDescriptorSetLayout(m_device->device(), &dslci, nullptr, &dsl);
Chris Forbes3fb17902016-08-22 14:57:55 +120014816 ASSERT_VK_SUCCESS(err);
14817
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014818 VkPipelineLayoutCreateInfo plci = {VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dsl, 0, nullptr};
Chris Forbes3fb17902016-08-22 14:57:55 +120014819 VkPipelineLayout pl;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014820 err = vkCreatePipelineLayout(m_device->device(), &plci, nullptr, &pl);
Chris Forbes3fb17902016-08-22 14:57:55 +120014821 ASSERT_VK_SUCCESS(err);
14822
14823 // error here.
14824 pipe.CreateVKPipeline(pl, renderPass());
14825
14826 m_errorMonitor->VerifyFound();
14827
14828 vkDestroyPipelineLayout(m_device->device(), pl, nullptr);
14829 vkDestroyDescriptorSetLayout(m_device->device(), dsl, nullptr);
14830}
14831
Chris Forbes663b5a82016-08-22 16:14:06 +120014832TEST_F(VkLayerTest, CreatePipelineInputAttachmentPositive) {
14833 TEST_DESCRIPTION("Positive test for a correctly matched input attachment");
14834 m_errorMonitor->ExpectSuccess();
14835
14836 ASSERT_NO_FATAL_FAILURE(InitState());
14837
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014838 char const *vsSource = "#version 450\n"
14839 "\n"
14840 "out gl_PerVertex {\n"
14841 " vec4 gl_Position;\n"
14842 "};\n"
14843 "void main(){\n"
14844 " gl_Position = vec4(1);\n"
14845 "}\n";
14846 char const *fsSource = "#version 450\n"
14847 "\n"
14848 "layout(input_attachment_index=0, set=0, binding=0) uniform subpassInput x;\n"
14849 "layout(location=0) out vec4 color;\n"
14850 "void main() {\n"
14851 " color = subpassLoad(x);\n"
14852 "}\n";
Chris Forbes663b5a82016-08-22 16:14:06 +120014853
14854 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
14855 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
14856
14857 VkPipelineObj pipe(m_device);
14858 pipe.AddShader(&vs);
14859 pipe.AddShader(&fs);
14860 pipe.AddColorAttachment();
14861 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
14862
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014863 VkDescriptorSetLayoutBinding dslb = {0, VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT, 1, VK_SHADER_STAGE_FRAGMENT_BIT, nullptr};
14864 VkDescriptorSetLayoutCreateInfo dslci = {VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dslb};
Chris Forbes663b5a82016-08-22 16:14:06 +120014865 VkDescriptorSetLayout dsl;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014866 VkResult err = vkCreateDescriptorSetLayout(m_device->device(), &dslci, nullptr, &dsl);
Chris Forbes663b5a82016-08-22 16:14:06 +120014867 ASSERT_VK_SUCCESS(err);
14868
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014869 VkPipelineLayoutCreateInfo plci = {VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dsl, 0, nullptr};
Chris Forbes663b5a82016-08-22 16:14:06 +120014870 VkPipelineLayout pl;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014871 err = vkCreatePipelineLayout(m_device->device(), &plci, nullptr, &pl);
Chris Forbes663b5a82016-08-22 16:14:06 +120014872 ASSERT_VK_SUCCESS(err);
14873
14874 VkAttachmentDescription descs[2] = {
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014875 {0, VK_FORMAT_R8G8B8A8_UNORM, VK_SAMPLE_COUNT_1_BIT, VK_ATTACHMENT_LOAD_OP_LOAD, VK_ATTACHMENT_STORE_OP_STORE,
14876 VK_ATTACHMENT_LOAD_OP_LOAD, VK_ATTACHMENT_STORE_OP_STORE, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
14877 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL},
14878 {0, VK_FORMAT_R8G8B8A8_UNORM, VK_SAMPLE_COUNT_1_BIT, VK_ATTACHMENT_LOAD_OP_LOAD, VK_ATTACHMENT_STORE_OP_STORE,
14879 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 +120014880 };
14881 VkAttachmentReference color = {
14882 0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
14883 };
14884 VkAttachmentReference input = {
14885 1, VK_IMAGE_LAYOUT_GENERAL,
14886 };
14887
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014888 VkSubpassDescription sd = {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 1, &input, 1, &color, nullptr, nullptr, 0, nullptr};
Chris Forbes663b5a82016-08-22 16:14:06 +120014889
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014890 VkRenderPassCreateInfo rpci = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 2, descs, 1, &sd, 0, nullptr};
Chris Forbes663b5a82016-08-22 16:14:06 +120014891 VkRenderPass rp;
14892 err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
14893 ASSERT_VK_SUCCESS(err);
14894
14895 // should be OK. would go wrong here if it's going to...
14896 pipe.CreateVKPipeline(pl, rp);
14897
14898 m_errorMonitor->VerifyNotFound();
14899
14900 vkDestroyRenderPass(m_device->device(), rp, nullptr);
14901 vkDestroyPipelineLayout(m_device->device(), pl, nullptr);
14902 vkDestroyDescriptorSetLayout(m_device->device(), dsl, nullptr);
14903}
14904
Chris Forbes5a9a0472016-08-22 16:02:09 +120014905TEST_F(VkLayerTest, CreatePipelineInputAttachmentTypeMismatch) {
14906 TEST_DESCRIPTION("Test that an error is produced for a shader consuming an input attachment "
14907 "with a format having a different fundamental type");
14908 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
14909 "input attachment 0 format of VK_FORMAT_R8G8B8A8_UINT does not match");
14910
14911 ASSERT_NO_FATAL_FAILURE(InitState());
14912
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014913 char const *vsSource = "#version 450\n"
14914 "\n"
14915 "out gl_PerVertex {\n"
14916 " vec4 gl_Position;\n"
14917 "};\n"
14918 "void main(){\n"
14919 " gl_Position = vec4(1);\n"
14920 "}\n";
14921 char const *fsSource = "#version 450\n"
14922 "\n"
14923 "layout(input_attachment_index=0, set=0, binding=0) uniform subpassInput x;\n"
14924 "layout(location=0) out vec4 color;\n"
14925 "void main() {\n"
14926 " color = subpassLoad(x);\n"
14927 "}\n";
Chris Forbes5a9a0472016-08-22 16:02:09 +120014928
14929 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
14930 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
14931
14932 VkPipelineObj pipe(m_device);
14933 pipe.AddShader(&vs);
14934 pipe.AddShader(&fs);
14935 pipe.AddColorAttachment();
14936 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
14937
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014938 VkDescriptorSetLayoutBinding dslb = {0, VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT, 1, VK_SHADER_STAGE_FRAGMENT_BIT, nullptr};
14939 VkDescriptorSetLayoutCreateInfo dslci = {VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dslb};
Chris Forbes5a9a0472016-08-22 16:02:09 +120014940 VkDescriptorSetLayout dsl;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014941 VkResult err = vkCreateDescriptorSetLayout(m_device->device(), &dslci, nullptr, &dsl);
Chris Forbes5a9a0472016-08-22 16:02:09 +120014942 ASSERT_VK_SUCCESS(err);
14943
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014944 VkPipelineLayoutCreateInfo plci = {VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dsl, 0, nullptr};
Chris Forbes5a9a0472016-08-22 16:02:09 +120014945 VkPipelineLayout pl;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014946 err = vkCreatePipelineLayout(m_device->device(), &plci, nullptr, &pl);
Chris Forbes5a9a0472016-08-22 16:02:09 +120014947 ASSERT_VK_SUCCESS(err);
14948
14949 VkAttachmentDescription descs[2] = {
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014950 {0, VK_FORMAT_R8G8B8A8_UNORM, VK_SAMPLE_COUNT_1_BIT, VK_ATTACHMENT_LOAD_OP_LOAD, VK_ATTACHMENT_STORE_OP_STORE,
14951 VK_ATTACHMENT_LOAD_OP_LOAD, VK_ATTACHMENT_STORE_OP_STORE, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
14952 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL},
14953 {0, VK_FORMAT_R8G8B8A8_UINT, VK_SAMPLE_COUNT_1_BIT, VK_ATTACHMENT_LOAD_OP_LOAD, VK_ATTACHMENT_STORE_OP_STORE,
14954 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 +120014955 };
14956 VkAttachmentReference color = {
14957 0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
14958 };
14959 VkAttachmentReference input = {
14960 1, VK_IMAGE_LAYOUT_GENERAL,
14961 };
14962
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014963 VkSubpassDescription sd = {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 1, &input, 1, &color, nullptr, nullptr, 0, nullptr};
Chris Forbes5a9a0472016-08-22 16:02:09 +120014964
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014965 VkRenderPassCreateInfo rpci = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 2, descs, 1, &sd, 0, nullptr};
Chris Forbes5a9a0472016-08-22 16:02:09 +120014966 VkRenderPass rp;
14967 err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
14968 ASSERT_VK_SUCCESS(err);
14969
14970 // error here.
14971 pipe.CreateVKPipeline(pl, rp);
14972
14973 m_errorMonitor->VerifyFound();
14974
14975 vkDestroyRenderPass(m_device->device(), rp, nullptr);
14976 vkDestroyPipelineLayout(m_device->device(), pl, nullptr);
14977 vkDestroyDescriptorSetLayout(m_device->device(), dsl, nullptr);
14978}
14979
Chris Forbes541f7b02016-08-22 15:30:27 +120014980TEST_F(VkLayerTest, CreatePipelineInputAttachmentMissingArray) {
14981 TEST_DESCRIPTION("Test that an error is produced for a shader consuming an input attachment "
14982 "which is not included in the subpass description -- array case");
14983 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
14984 "consumes input attachment index 1 but not provided in subpass");
14985
14986 ASSERT_NO_FATAL_FAILURE(InitState());
14987
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014988 char const *vsSource = "#version 450\n"
14989 "\n"
14990 "out gl_PerVertex {\n"
14991 " vec4 gl_Position;\n"
14992 "};\n"
14993 "void main(){\n"
14994 " gl_Position = vec4(1);\n"
14995 "}\n";
14996 char const *fsSource = "#version 450\n"
14997 "\n"
14998 "layout(input_attachment_index=0, set=0, binding=0) uniform subpassInput xs[2];\n"
14999 "layout(location=0) out vec4 color;\n"
15000 "void main() {\n"
15001 " color = subpassLoad(xs[1]);\n"
15002 "}\n";
Chris Forbes541f7b02016-08-22 15:30:27 +120015003
15004 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
15005 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
15006
15007 VkPipelineObj pipe(m_device);
15008 pipe.AddShader(&vs);
15009 pipe.AddShader(&fs);
15010 pipe.AddColorAttachment();
15011 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
15012
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015013 VkDescriptorSetLayoutBinding dslb = {0, VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT, 2, VK_SHADER_STAGE_FRAGMENT_BIT, nullptr};
15014 VkDescriptorSetLayoutCreateInfo dslci = {VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dslb};
Chris Forbes541f7b02016-08-22 15:30:27 +120015015 VkDescriptorSetLayout dsl;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015016 VkResult err = vkCreateDescriptorSetLayout(m_device->device(), &dslci, nullptr, &dsl);
Chris Forbes541f7b02016-08-22 15:30:27 +120015017 ASSERT_VK_SUCCESS(err);
15018
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015019 VkPipelineLayoutCreateInfo plci = {VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dsl, 0, nullptr};
Chris Forbes541f7b02016-08-22 15:30:27 +120015020 VkPipelineLayout pl;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015021 err = vkCreatePipelineLayout(m_device->device(), &plci, nullptr, &pl);
Chris Forbes541f7b02016-08-22 15:30:27 +120015022 ASSERT_VK_SUCCESS(err);
15023
15024 // error here.
15025 pipe.CreateVKPipeline(pl, renderPass());
15026
15027 m_errorMonitor->VerifyFound();
15028
15029 vkDestroyPipelineLayout(m_device->device(), pl, nullptr);
15030 vkDestroyDescriptorSetLayout(m_device->device(), dsl, nullptr);
15031}
15032
Chris Forbes10eb9ae2016-05-31 16:09:42 +120015033TEST_F(VkLayerTest, CreateComputePipelineMissingDescriptor) {
Chris Forbes1cc79542016-07-20 11:13:44 +120015034 TEST_DESCRIPTION("Test that an error is produced for a compute pipeline consuming a "
15035 "descriptor which is not provided in the pipeline layout");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015036 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Shader uses descriptor slot 0.0");
Chris Forbes10eb9ae2016-05-31 16:09:42 +120015037
15038 ASSERT_NO_FATAL_FAILURE(InitState());
15039
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015040 char const *csSource = "#version 450\n"
15041 "\n"
15042 "layout(local_size_x=1) in;\n"
15043 "layout(set=0, binding=0) buffer block { vec4 x; };\n"
15044 "void main(){\n"
15045 " x = vec4(1);\n"
15046 "}\n";
Chris Forbes10eb9ae2016-05-31 16:09:42 +120015047
15048 VkShaderObj cs(m_device, csSource, VK_SHADER_STAGE_COMPUTE_BIT, this);
15049
15050 VkDescriptorSetObj descriptorSet(m_device);
15051 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
15052
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015053 VkComputePipelineCreateInfo cpci = {VK_STRUCTURE_TYPE_COMPUTE_PIPELINE_CREATE_INFO,
15054 nullptr,
15055 0,
15056 {VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO, nullptr, 0,
15057 VK_SHADER_STAGE_COMPUTE_BIT, cs.handle(), "main", nullptr},
15058 descriptorSet.GetPipelineLayout(),
15059 VK_NULL_HANDLE,
15060 -1};
Chris Forbes10eb9ae2016-05-31 16:09:42 +120015061
15062 VkPipeline pipe;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015063 VkResult err = vkCreateComputePipelines(m_device->device(), VK_NULL_HANDLE, 1, &cpci, nullptr, &pipe);
Chris Forbes10eb9ae2016-05-31 16:09:42 +120015064
15065 m_errorMonitor->VerifyFound();
15066
15067 if (err == VK_SUCCESS) {
15068 vkDestroyPipeline(m_device->device(), pipe, nullptr);
15069 }
15070}
15071
15072TEST_F(VkLayerTest, CreateComputePipelineMissingDescriptorUnusedPositive) {
Chris Forbes1cc79542016-07-20 11:13:44 +120015073 TEST_DESCRIPTION("Test that pipeline validation accepts a compute pipeline which declares a "
15074 "descriptor-backed resource which is not provided, but the shader does not "
15075 "statically use it. This is interesting because it requires compute pipelines "
15076 "to have a proper descriptor use walk, which they didn't for some time.");
Chris Forbes10eb9ae2016-05-31 16:09:42 +120015077 m_errorMonitor->ExpectSuccess();
15078
15079 ASSERT_NO_FATAL_FAILURE(InitState());
15080
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015081 char const *csSource = "#version 450\n"
15082 "\n"
15083 "layout(local_size_x=1) in;\n"
15084 "layout(set=0, binding=0) buffer block { vec4 x; };\n"
15085 "void main(){\n"
15086 " // x is not used.\n"
15087 "}\n";
Chris Forbes10eb9ae2016-05-31 16:09:42 +120015088
15089 VkShaderObj cs(m_device, csSource, VK_SHADER_STAGE_COMPUTE_BIT, this);
15090
15091 VkDescriptorSetObj descriptorSet(m_device);
15092 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
15093
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015094 VkComputePipelineCreateInfo cpci = {VK_STRUCTURE_TYPE_COMPUTE_PIPELINE_CREATE_INFO,
15095 nullptr,
15096 0,
15097 {VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO, nullptr, 0,
15098 VK_SHADER_STAGE_COMPUTE_BIT, cs.handle(), "main", nullptr},
15099 descriptorSet.GetPipelineLayout(),
15100 VK_NULL_HANDLE,
15101 -1};
Chris Forbes10eb9ae2016-05-31 16:09:42 +120015102
15103 VkPipeline pipe;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015104 VkResult err = vkCreateComputePipelines(m_device->device(), VK_NULL_HANDLE, 1, &cpci, nullptr, &pipe);
Chris Forbes10eb9ae2016-05-31 16:09:42 +120015105
15106 m_errorMonitor->VerifyNotFound();
15107
15108 if (err == VK_SUCCESS) {
15109 vkDestroyPipeline(m_device->device(), pipe, nullptr);
15110 }
15111}
15112
Chris Forbes22a9b092016-07-19 14:34:05 +120015113TEST_F(VkLayerTest, CreateComputePipelineDescriptorTypeMismatch) {
Chris Forbes1cc79542016-07-20 11:13:44 +120015114 TEST_DESCRIPTION("Test that an error is produced for a pipeline consuming a "
15115 "descriptor-backed resource of a mismatched type");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015116 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
15117 "but descriptor of type VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER");
Chris Forbes22a9b092016-07-19 14:34:05 +120015118
15119 ASSERT_NO_FATAL_FAILURE(InitState());
15120
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015121 VkDescriptorSetLayoutBinding binding = {0, VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, 1, VK_SHADER_STAGE_COMPUTE_BIT, nullptr};
15122 VkDescriptorSetLayoutCreateInfo dslci = {VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO, nullptr, 0, 1, &binding};
Chris Forbes22a9b092016-07-19 14:34:05 +120015123 VkDescriptorSetLayout dsl;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015124 VkResult err = vkCreateDescriptorSetLayout(m_device->device(), &dslci, nullptr, &dsl);
Chris Forbes22a9b092016-07-19 14:34:05 +120015125 ASSERT_VK_SUCCESS(err);
15126
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015127 VkPipelineLayoutCreateInfo plci = {VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dsl, 0, nullptr};
Chris Forbes22a9b092016-07-19 14:34:05 +120015128 VkPipelineLayout pl;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015129 err = vkCreatePipelineLayout(m_device->device(), &plci, nullptr, &pl);
Chris Forbes22a9b092016-07-19 14:34:05 +120015130 ASSERT_VK_SUCCESS(err);
15131
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015132 char const *csSource = "#version 450\n"
15133 "\n"
15134 "layout(local_size_x=1) in;\n"
15135 "layout(set=0, binding=0) buffer block { vec4 x; };\n"
15136 "void main() {\n"
15137 " x.x = 1.0f;\n"
15138 "}\n";
Chris Forbes22a9b092016-07-19 14:34:05 +120015139 VkShaderObj cs(m_device, csSource, VK_SHADER_STAGE_COMPUTE_BIT, this);
15140
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015141 VkComputePipelineCreateInfo cpci = {VK_STRUCTURE_TYPE_COMPUTE_PIPELINE_CREATE_INFO,
15142 nullptr,
15143 0,
15144 {VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO, nullptr, 0,
15145 VK_SHADER_STAGE_COMPUTE_BIT, cs.handle(), "main", nullptr},
15146 pl,
15147 VK_NULL_HANDLE,
15148 -1};
Chris Forbes22a9b092016-07-19 14:34:05 +120015149
15150 VkPipeline pipe;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015151 err = vkCreateComputePipelines(m_device->device(), VK_NULL_HANDLE, 1, &cpci, nullptr, &pipe);
Chris Forbes22a9b092016-07-19 14:34:05 +120015152
15153 m_errorMonitor->VerifyFound();
15154
15155 if (err == VK_SUCCESS) {
15156 vkDestroyPipeline(m_device->device(), pipe, nullptr);
15157 }
15158
15159 vkDestroyPipelineLayout(m_device->device(), pl, nullptr);
15160 vkDestroyDescriptorSetLayout(m_device->device(), dsl, nullptr);
15161}
15162
Chris Forbese10a51f2016-07-19 14:42:51 +120015163TEST_F(VkLayerTest, CreateComputePipelineCombinedImageSamplerConsumedAsSampler) {
Chris Forbes1cc79542016-07-20 11:13:44 +120015164 TEST_DESCRIPTION("Test that pipeline validation accepts a shader consuming only the "
15165 "sampler portion of a combined image + sampler");
Chris Forbese10a51f2016-07-19 14:42:51 +120015166 m_errorMonitor->ExpectSuccess();
15167
15168 ASSERT_NO_FATAL_FAILURE(InitState());
15169
15170 VkDescriptorSetLayoutBinding bindings[] = {
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015171 {0, VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, 1, VK_SHADER_STAGE_COMPUTE_BIT, nullptr},
15172 {1, VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE, 1, VK_SHADER_STAGE_COMPUTE_BIT, nullptr},
15173 {2, VK_DESCRIPTOR_TYPE_STORAGE_BUFFER, 1, VK_SHADER_STAGE_COMPUTE_BIT, nullptr},
Chris Forbese10a51f2016-07-19 14:42:51 +120015174 };
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015175 VkDescriptorSetLayoutCreateInfo dslci = {VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO, nullptr, 0, 3, bindings};
Chris Forbese10a51f2016-07-19 14:42:51 +120015176 VkDescriptorSetLayout dsl;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015177 VkResult err = vkCreateDescriptorSetLayout(m_device->device(), &dslci, nullptr, &dsl);
Chris Forbese10a51f2016-07-19 14:42:51 +120015178 ASSERT_VK_SUCCESS(err);
15179
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015180 VkPipelineLayoutCreateInfo plci = {VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dsl, 0, nullptr};
Chris Forbese10a51f2016-07-19 14:42:51 +120015181 VkPipelineLayout pl;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015182 err = vkCreatePipelineLayout(m_device->device(), &plci, nullptr, &pl);
Chris Forbese10a51f2016-07-19 14:42:51 +120015183 ASSERT_VK_SUCCESS(err);
15184
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015185 char const *csSource = "#version 450\n"
15186 "\n"
15187 "layout(local_size_x=1) in;\n"
15188 "layout(set=0, binding=0) uniform sampler s;\n"
15189 "layout(set=0, binding=1) uniform texture2D t;\n"
15190 "layout(set=0, binding=2) buffer block { vec4 x; };\n"
15191 "void main() {\n"
15192 " x = texture(sampler2D(t, s), vec2(0));\n"
15193 "}\n";
Chris Forbese10a51f2016-07-19 14:42:51 +120015194 VkShaderObj cs(m_device, csSource, VK_SHADER_STAGE_COMPUTE_BIT, this);
15195
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015196 VkComputePipelineCreateInfo cpci = {VK_STRUCTURE_TYPE_COMPUTE_PIPELINE_CREATE_INFO,
15197 nullptr,
15198 0,
15199 {VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO, nullptr, 0,
15200 VK_SHADER_STAGE_COMPUTE_BIT, cs.handle(), "main", nullptr},
15201 pl,
15202 VK_NULL_HANDLE,
15203 -1};
Chris Forbese10a51f2016-07-19 14:42:51 +120015204
15205 VkPipeline pipe;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015206 err = vkCreateComputePipelines(m_device->device(), VK_NULL_HANDLE, 1, &cpci, nullptr, &pipe);
Chris Forbese10a51f2016-07-19 14:42:51 +120015207
15208 m_errorMonitor->VerifyNotFound();
15209
15210 if (err == VK_SUCCESS) {
15211 vkDestroyPipeline(m_device->device(), pipe, nullptr);
15212 }
15213
15214 vkDestroyPipelineLayout(m_device->device(), pl, nullptr);
15215 vkDestroyDescriptorSetLayout(m_device->device(), dsl, nullptr);
15216}
15217
Chris Forbes91c3b2a2016-07-19 14:46:38 +120015218TEST_F(VkLayerTest, CreateComputePipelineCombinedImageSamplerConsumedAsImage) {
Chris Forbes1cc79542016-07-20 11:13:44 +120015219 TEST_DESCRIPTION("Test that pipeline validation accepts a shader consuming only the "
15220 "image portion of a combined image + sampler");
Chris Forbes91c3b2a2016-07-19 14:46:38 +120015221 m_errorMonitor->ExpectSuccess();
15222
15223 ASSERT_NO_FATAL_FAILURE(InitState());
15224
15225 VkDescriptorSetLayoutBinding bindings[] = {
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015226 {0, VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, 1, VK_SHADER_STAGE_COMPUTE_BIT, nullptr},
15227 {1, VK_DESCRIPTOR_TYPE_SAMPLER, 1, VK_SHADER_STAGE_COMPUTE_BIT, nullptr},
15228 {2, VK_DESCRIPTOR_TYPE_STORAGE_BUFFER, 1, VK_SHADER_STAGE_COMPUTE_BIT, nullptr},
Chris Forbes91c3b2a2016-07-19 14:46:38 +120015229 };
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015230 VkDescriptorSetLayoutCreateInfo dslci = {VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO, nullptr, 0, 3, bindings};
Chris Forbes91c3b2a2016-07-19 14:46:38 +120015231 VkDescriptorSetLayout dsl;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015232 VkResult err = vkCreateDescriptorSetLayout(m_device->device(), &dslci, nullptr, &dsl);
Chris Forbes91c3b2a2016-07-19 14:46:38 +120015233 ASSERT_VK_SUCCESS(err);
15234
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015235 VkPipelineLayoutCreateInfo plci = {VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dsl, 0, nullptr};
Chris Forbes91c3b2a2016-07-19 14:46:38 +120015236 VkPipelineLayout pl;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015237 err = vkCreatePipelineLayout(m_device->device(), &plci, nullptr, &pl);
Chris Forbes91c3b2a2016-07-19 14:46:38 +120015238 ASSERT_VK_SUCCESS(err);
15239
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015240 char const *csSource = "#version 450\n"
15241 "\n"
15242 "layout(local_size_x=1) in;\n"
15243 "layout(set=0, binding=0) uniform texture2D t;\n"
15244 "layout(set=0, binding=1) uniform sampler s;\n"
15245 "layout(set=0, binding=2) buffer block { vec4 x; };\n"
15246 "void main() {\n"
15247 " x = texture(sampler2D(t, s), vec2(0));\n"
15248 "}\n";
Chris Forbes91c3b2a2016-07-19 14:46:38 +120015249 VkShaderObj cs(m_device, csSource, VK_SHADER_STAGE_COMPUTE_BIT, this);
15250
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015251 VkComputePipelineCreateInfo cpci = {VK_STRUCTURE_TYPE_COMPUTE_PIPELINE_CREATE_INFO,
15252 nullptr,
15253 0,
15254 {VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO, nullptr, 0,
15255 VK_SHADER_STAGE_COMPUTE_BIT, cs.handle(), "main", nullptr},
15256 pl,
15257 VK_NULL_HANDLE,
15258 -1};
Chris Forbes91c3b2a2016-07-19 14:46:38 +120015259
15260 VkPipeline pipe;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015261 err = vkCreateComputePipelines(m_device->device(), VK_NULL_HANDLE, 1, &cpci, nullptr, &pipe);
Chris Forbes91c3b2a2016-07-19 14:46:38 +120015262
15263 m_errorMonitor->VerifyNotFound();
15264
15265 if (err == VK_SUCCESS) {
15266 vkDestroyPipeline(m_device->device(), pipe, nullptr);
15267 }
15268
15269 vkDestroyPipelineLayout(m_device->device(), pl, nullptr);
15270 vkDestroyDescriptorSetLayout(m_device->device(), dsl, nullptr);
15271}
15272
Chris Forbes6a4991a2016-07-19 15:07:32 +120015273TEST_F(VkLayerTest, CreateComputePipelineCombinedImageSamplerConsumedAsBoth) {
Chris Forbes1cc79542016-07-20 11:13:44 +120015274 TEST_DESCRIPTION("Test that pipeline validation accepts a shader consuming "
15275 "both the sampler and the image of a combined image+sampler "
15276 "but via separate variables");
Chris Forbes6a4991a2016-07-19 15:07:32 +120015277 m_errorMonitor->ExpectSuccess();
15278
15279 ASSERT_NO_FATAL_FAILURE(InitState());
15280
15281 VkDescriptorSetLayoutBinding bindings[] = {
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015282 {0, VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, 1, VK_SHADER_STAGE_COMPUTE_BIT, nullptr},
15283 {1, VK_DESCRIPTOR_TYPE_STORAGE_BUFFER, 1, VK_SHADER_STAGE_COMPUTE_BIT, nullptr},
Chris Forbes6a4991a2016-07-19 15:07:32 +120015284 };
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015285 VkDescriptorSetLayoutCreateInfo dslci = {VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO, nullptr, 0, 2, bindings};
Chris Forbes6a4991a2016-07-19 15:07:32 +120015286 VkDescriptorSetLayout dsl;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015287 VkResult err = vkCreateDescriptorSetLayout(m_device->device(), &dslci, nullptr, &dsl);
Chris Forbes6a4991a2016-07-19 15:07:32 +120015288 ASSERT_VK_SUCCESS(err);
15289
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015290 VkPipelineLayoutCreateInfo plci = {VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dsl, 0, nullptr};
Chris Forbes6a4991a2016-07-19 15:07:32 +120015291 VkPipelineLayout pl;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015292 err = vkCreatePipelineLayout(m_device->device(), &plci, nullptr, &pl);
Chris Forbes6a4991a2016-07-19 15:07:32 +120015293 ASSERT_VK_SUCCESS(err);
15294
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015295 char const *csSource = "#version 450\n"
15296 "\n"
15297 "layout(local_size_x=1) in;\n"
15298 "layout(set=0, binding=0) uniform texture2D t;\n"
15299 "layout(set=0, binding=0) uniform sampler s; // both binding 0!\n"
15300 "layout(set=0, binding=1) buffer block { vec4 x; };\n"
15301 "void main() {\n"
15302 " x = texture(sampler2D(t, s), vec2(0));\n"
15303 "}\n";
Chris Forbes6a4991a2016-07-19 15:07:32 +120015304 VkShaderObj cs(m_device, csSource, VK_SHADER_STAGE_COMPUTE_BIT, this);
15305
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015306 VkComputePipelineCreateInfo cpci = {VK_STRUCTURE_TYPE_COMPUTE_PIPELINE_CREATE_INFO,
15307 nullptr,
15308 0,
15309 {VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO, nullptr, 0,
15310 VK_SHADER_STAGE_COMPUTE_BIT, cs.handle(), "main", nullptr},
15311 pl,
15312 VK_NULL_HANDLE,
15313 -1};
Chris Forbes6a4991a2016-07-19 15:07:32 +120015314
15315 VkPipeline pipe;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015316 err = vkCreateComputePipelines(m_device->device(), VK_NULL_HANDLE, 1, &cpci, nullptr, &pipe);
Chris Forbes6a4991a2016-07-19 15:07:32 +120015317
15318 m_errorMonitor->VerifyNotFound();
15319
15320 if (err == VK_SUCCESS) {
15321 vkDestroyPipeline(m_device->device(), pipe, nullptr);
15322 }
15323
15324 vkDestroyPipelineLayout(m_device->device(), pl, nullptr);
15325 vkDestroyDescriptorSetLayout(m_device->device(), dsl, nullptr);
15326}
15327
Chris Forbes50020592016-07-27 13:52:41 +120015328TEST_F(VkLayerTest, DrawTimeImageViewTypeMismatchWithPipeline) {
15329 TEST_DESCRIPTION("Test that an error is produced when an image view type "
15330 "does not match the dimensionality declared in the shader");
15331
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015332 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 +120015333
15334 ASSERT_NO_FATAL_FAILURE(InitState());
15335 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
15336
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015337 char const *vsSource = "#version 450\n"
15338 "\n"
15339 "out gl_PerVertex { vec4 gl_Position; };\n"
15340 "void main() { gl_Position = vec4(0); }\n";
15341 char const *fsSource = "#version 450\n"
15342 "\n"
15343 "layout(set=0, binding=0) uniform sampler3D s;\n"
15344 "layout(location=0) out vec4 color;\n"
15345 "void main() {\n"
15346 " color = texture(s, vec3(0));\n"
15347 "}\n";
Chris Forbes50020592016-07-27 13:52:41 +120015348 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
15349 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
15350
15351 VkPipelineObj pipe(m_device);
15352 pipe.AddShader(&vs);
15353 pipe.AddShader(&fs);
15354 pipe.AddColorAttachment();
15355
15356 VkTextureObj texture(m_device, nullptr);
15357 VkSamplerObj sampler(m_device);
15358
15359 VkDescriptorSetObj descriptorSet(m_device);
15360 descriptorSet.AppendSamplerTexture(&sampler, &texture);
15361 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
15362
15363 VkResult err = pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
15364 ASSERT_VK_SUCCESS(err);
15365
15366 BeginCommandBuffer();
15367
15368 m_commandBuffer->BindPipeline(pipe);
15369 m_commandBuffer->BindDescriptorSet(descriptorSet);
15370
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015371 VkViewport viewport = {0, 0, 16, 16, 0, 1};
Chris Forbes50020592016-07-27 13:52:41 +120015372 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015373 VkRect2D scissor = {{0, 0}, {16, 16}};
Chris Forbes50020592016-07-27 13:52:41 +120015374 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
15375
15376 // error produced here.
15377 vkCmdDraw(m_commandBuffer->handle(), 3, 1, 0, 0);
15378
15379 m_errorMonitor->VerifyFound();
15380
15381 EndCommandBuffer();
15382}
15383
Chris Forbes5533bfc2016-07-27 14:12:34 +120015384TEST_F(VkLayerTest, DrawTimeImageMultisampleMismatchWithPipeline) {
15385 TEST_DESCRIPTION("Test that an error is produced when a multisampled images "
15386 "are consumed via singlesample images types in the shader, or vice versa.");
15387
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015388 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "requires bound image to have multiple samples");
Chris Forbes5533bfc2016-07-27 14:12:34 +120015389
15390 ASSERT_NO_FATAL_FAILURE(InitState());
15391 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
15392
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015393 char const *vsSource = "#version 450\n"
15394 "\n"
15395 "out gl_PerVertex { vec4 gl_Position; };\n"
15396 "void main() { gl_Position = vec4(0); }\n";
15397 char const *fsSource = "#version 450\n"
15398 "\n"
15399 "layout(set=0, binding=0) uniform sampler2DMS s;\n"
15400 "layout(location=0) out vec4 color;\n"
15401 "void main() {\n"
15402 " color = texelFetch(s, ivec2(0), 0);\n"
15403 "}\n";
Chris Forbes5533bfc2016-07-27 14:12:34 +120015404 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
15405 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
15406
15407 VkPipelineObj pipe(m_device);
15408 pipe.AddShader(&vs);
15409 pipe.AddShader(&fs);
15410 pipe.AddColorAttachment();
15411
15412 VkTextureObj texture(m_device, nullptr);
15413 VkSamplerObj sampler(m_device);
15414
15415 VkDescriptorSetObj descriptorSet(m_device);
15416 descriptorSet.AppendSamplerTexture(&sampler, &texture);
15417 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
15418
15419 VkResult err = pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
15420 ASSERT_VK_SUCCESS(err);
15421
15422 BeginCommandBuffer();
15423
15424 m_commandBuffer->BindPipeline(pipe);
15425 m_commandBuffer->BindDescriptorSet(descriptorSet);
15426
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015427 VkViewport viewport = {0, 0, 16, 16, 0, 1};
Chris Forbes5533bfc2016-07-27 14:12:34 +120015428 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015429 VkRect2D scissor = {{0, 0}, {16, 16}};
Chris Forbes5533bfc2016-07-27 14:12:34 +120015430 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
15431
15432 // error produced here.
15433 vkCmdDraw(m_commandBuffer->handle(), 3, 1, 0, 0);
15434
15435 m_errorMonitor->VerifyFound();
15436
15437 EndCommandBuffer();
15438}
15439
Mark Lobodzinski209b5292015-09-17 09:44:05 -060015440#endif // SHADER_CHECKER_TESTS
15441
15442#if DEVICE_LIMITS_TESTS
Mark Youngc48c4c12016-04-11 14:26:49 -060015443TEST_F(VkLayerTest, CreateImageLimitsViolationMaxWidth) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015444 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "CreateImage extents exceed allowable limits for format");
Mark Lobodzinski6f2274e2015-09-22 09:33:21 -060015445
15446 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinski6f2274e2015-09-22 09:33:21 -060015447
15448 // Create an image
15449 VkImage image;
15450
Karl Schultz6addd812016-02-02 17:17:23 -070015451 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
15452 const int32_t tex_width = 32;
15453 const int32_t tex_height = 32;
Mark Lobodzinski6f2274e2015-09-22 09:33:21 -060015454
15455 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070015456 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
15457 image_create_info.pNext = NULL;
15458 image_create_info.imageType = VK_IMAGE_TYPE_2D;
15459 image_create_info.format = tex_format;
15460 image_create_info.extent.width = tex_width;
Mark Lobodzinski6f2274e2015-09-22 09:33:21 -060015461 image_create_info.extent.height = tex_height;
Karl Schultz6addd812016-02-02 17:17:23 -070015462 image_create_info.extent.depth = 1;
15463 image_create_info.mipLevels = 1;
15464 image_create_info.arrayLayers = 1;
15465 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
15466 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
15467 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
15468 image_create_info.flags = 0;
Mark Lobodzinski6f2274e2015-09-22 09:33:21 -060015469
15470 // Introduce error by sending down a bogus width extent
15471 image_create_info.extent.width = 65536;
Chia-I Wuf7458c52015-10-26 21:10:41 +080015472 vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
Mark Lobodzinski6f2274e2015-09-22 09:33:21 -060015473
Chris Forbes8f36a8a2016-04-07 13:21:07 +120015474 m_errorMonitor->VerifyFound();
Mark Lobodzinski6f2274e2015-09-22 09:33:21 -060015475}
15476
Mark Youngc48c4c12016-04-11 14:26:49 -060015477TEST_F(VkLayerTest, CreateImageLimitsViolationMinWidth) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015478 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
15479 "CreateImage extents is 0 for at least one required dimension");
Mark Youngc48c4c12016-04-11 14:26:49 -060015480
15481 ASSERT_NO_FATAL_FAILURE(InitState());
15482
15483 // Create an image
15484 VkImage image;
15485
15486 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
15487 const int32_t tex_width = 32;
15488 const int32_t tex_height = 32;
15489
15490 VkImageCreateInfo image_create_info = {};
15491 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
15492 image_create_info.pNext = NULL;
15493 image_create_info.imageType = VK_IMAGE_TYPE_2D;
15494 image_create_info.format = tex_format;
15495 image_create_info.extent.width = tex_width;
15496 image_create_info.extent.height = tex_height;
15497 image_create_info.extent.depth = 1;
15498 image_create_info.mipLevels = 1;
15499 image_create_info.arrayLayers = 1;
15500 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
15501 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
15502 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
15503 image_create_info.flags = 0;
15504
15505 // Introduce error by sending down a bogus width extent
15506 image_create_info.extent.width = 0;
15507 vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
15508
15509 m_errorMonitor->VerifyFound();
15510}
Mark Lobodzinski209b5292015-09-17 09:44:05 -060015511#endif // DEVICE_LIMITS_TESTS
Chris Forbesa36d69e2015-05-25 11:13:44 +120015512
Tobin Ehliscde08892015-09-22 10:11:37 -060015513#if IMAGE_TESTS
Mark Lobodzinskidf4c57d2016-08-05 11:47:16 -060015514TEST_F(VkLayerTest, AttachmentDescriptionUndefinedFormat) {
15515 TEST_DESCRIPTION("Create a render pass with an attachment description "
15516 "format set to VK_FORMAT_UNDEFINED");
15517
15518 ASSERT_NO_FATAL_FAILURE(InitState());
15519 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
15520
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015521 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "format is VK_FORMAT_UNDEFINED");
Mark Lobodzinskidf4c57d2016-08-05 11:47:16 -060015522
15523 VkAttachmentReference color_attach = {};
15524 color_attach.layout = VK_IMAGE_LAYOUT_GENERAL;
15525 color_attach.attachment = 0;
15526 VkSubpassDescription subpass = {};
15527 subpass.colorAttachmentCount = 1;
15528 subpass.pColorAttachments = &color_attach;
15529
15530 VkRenderPassCreateInfo rpci = {};
15531 rpci.subpassCount = 1;
15532 rpci.pSubpasses = &subpass;
15533 rpci.attachmentCount = 1;
15534 VkAttachmentDescription attach_desc = {};
15535 attach_desc.format = VK_FORMAT_UNDEFINED;
15536 rpci.pAttachments = &attach_desc;
15537 rpci.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
15538 VkRenderPass rp;
15539 VkResult result = vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
15540
15541 m_errorMonitor->VerifyFound();
15542
15543 if (result == VK_SUCCESS) {
15544 vkDestroyRenderPass(m_device->device(), rp, NULL);
15545 }
15546}
15547
Karl Schultz6addd812016-02-02 17:17:23 -070015548TEST_F(VkLayerTest, InvalidImageView) {
15549 VkResult err;
Tobin Ehliscde08892015-09-22 10:11:37 -060015550
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015551 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "vkCreateImageView called with baseMipLevel 10 ");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060015552
Tobin Ehliscde08892015-09-22 10:11:37 -060015553 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehliscde08892015-09-22 10:11:37 -060015554
Mike Stroyana3082432015-09-25 13:39:21 -060015555 // Create an image and try to create a view with bad baseMipLevel
Karl Schultz6addd812016-02-02 17:17:23 -070015556 VkImage image;
Tobin Ehliscde08892015-09-22 10:11:37 -060015557
Karl Schultz6addd812016-02-02 17:17:23 -070015558 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
15559 const int32_t tex_width = 32;
15560 const int32_t tex_height = 32;
Tobin Ehliscde08892015-09-22 10:11:37 -060015561
15562 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070015563 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
15564 image_create_info.pNext = NULL;
15565 image_create_info.imageType = VK_IMAGE_TYPE_2D;
15566 image_create_info.format = tex_format;
15567 image_create_info.extent.width = tex_width;
15568 image_create_info.extent.height = tex_height;
15569 image_create_info.extent.depth = 1;
15570 image_create_info.mipLevels = 1;
15571 image_create_info.arrayLayers = 1;
15572 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
15573 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
15574 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
15575 image_create_info.flags = 0;
Tobin Ehliscde08892015-09-22 10:11:37 -060015576
Chia-I Wuf7458c52015-10-26 21:10:41 +080015577 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
Tobin Ehliscde08892015-09-22 10:11:37 -060015578 ASSERT_VK_SUCCESS(err);
15579
15580 VkImageViewCreateInfo image_view_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070015581 image_view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
15582 image_view_create_info.image = image;
15583 image_view_create_info.viewType = VK_IMAGE_VIEW_TYPE_2D;
15584 image_view_create_info.format = tex_format;
15585 image_view_create_info.subresourceRange.layerCount = 1;
15586 image_view_create_info.subresourceRange.baseMipLevel = 10; // cause an error
15587 image_view_create_info.subresourceRange.levelCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015588 image_view_create_info.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Tobin Ehliscde08892015-09-22 10:11:37 -060015589
15590 VkImageView view;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015591 err = vkCreateImageView(m_device->device(), &image_view_create_info, NULL, &view);
Tobin Ehliscde08892015-09-22 10:11:37 -060015592
Chris Forbes8f36a8a2016-04-07 13:21:07 +120015593 m_errorMonitor->VerifyFound();
Tony Barbourdf4c0042016-06-01 15:55:43 -060015594 vkDestroyImage(m_device->device(), image, NULL);
Tobin Ehliscde08892015-09-22 10:11:37 -060015595}
Mike Stroyana3082432015-09-25 13:39:21 -060015596
Mark Youngd339ba32016-05-30 13:28:35 -060015597TEST_F(VkLayerTest, CreateImageViewNoMemoryBoundToImage) {
15598 VkResult err;
15599
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015600 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "used without first calling vkBindImageMemory");
Mark Youngd339ba32016-05-30 13:28:35 -060015601
15602 ASSERT_NO_FATAL_FAILURE(InitState());
15603
15604 // Create an image and try to create a view with no memory backing the image
15605 VkImage image;
15606
15607 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
15608 const int32_t tex_width = 32;
15609 const int32_t tex_height = 32;
15610
15611 VkImageCreateInfo image_create_info = {};
15612 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
15613 image_create_info.pNext = NULL;
15614 image_create_info.imageType = VK_IMAGE_TYPE_2D;
15615 image_create_info.format = tex_format;
15616 image_create_info.extent.width = tex_width;
15617 image_create_info.extent.height = tex_height;
15618 image_create_info.extent.depth = 1;
15619 image_create_info.mipLevels = 1;
15620 image_create_info.arrayLayers = 1;
15621 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
15622 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
15623 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
15624 image_create_info.flags = 0;
15625
15626 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
15627 ASSERT_VK_SUCCESS(err);
15628
15629 VkImageViewCreateInfo image_view_create_info = {};
15630 image_view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
15631 image_view_create_info.image = image;
15632 image_view_create_info.viewType = VK_IMAGE_VIEW_TYPE_2D;
15633 image_view_create_info.format = tex_format;
15634 image_view_create_info.subresourceRange.layerCount = 1;
15635 image_view_create_info.subresourceRange.baseMipLevel = 0;
15636 image_view_create_info.subresourceRange.levelCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015637 image_view_create_info.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mark Youngd339ba32016-05-30 13:28:35 -060015638
15639 VkImageView view;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015640 err = vkCreateImageView(m_device->device(), &image_view_create_info, NULL, &view);
Mark Youngd339ba32016-05-30 13:28:35 -060015641
15642 m_errorMonitor->VerifyFound();
15643 vkDestroyImage(m_device->device(), image, NULL);
15644 // If last error is success, it still created the view, so delete it.
15645 if (err == VK_SUCCESS) {
15646 vkDestroyImageView(m_device->device(), view, NULL);
15647 }
Mark Youngd339ba32016-05-30 13:28:35 -060015648}
15649
Karl Schultz6addd812016-02-02 17:17:23 -070015650TEST_F(VkLayerTest, InvalidImageViewAspect) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015651 TEST_DESCRIPTION("Create an image and try to create a view with an invalid aspectMask");
15652 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "vkCreateImageView: Color image "
15653 "formats must have ONLY the "
15654 "VK_IMAGE_ASPECT_COLOR_BIT set");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060015655
Mark Lobodzinskidc86b852015-10-23 14:20:31 -060015656 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinskidc86b852015-10-23 14:20:31 -060015657
Karl Schultz6addd812016-02-02 17:17:23 -070015658 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
Tobin Ehlis1f567a22016-05-25 16:15:18 -060015659 VkImageObj image(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015660 image.init(32, 32, tex_format, VK_IMAGE_USAGE_SAMPLED_BIT, VK_IMAGE_TILING_LINEAR, 0);
Tobin Ehlis1f567a22016-05-25 16:15:18 -060015661 ASSERT_TRUE(image.initialized());
Mark Lobodzinskidc86b852015-10-23 14:20:31 -060015662
15663 VkImageViewCreateInfo image_view_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070015664 image_view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
Tobin Ehlis1f567a22016-05-25 16:15:18 -060015665 image_view_create_info.image = image.handle();
Karl Schultz6addd812016-02-02 17:17:23 -070015666 image_view_create_info.viewType = VK_IMAGE_VIEW_TYPE_2D;
15667 image_view_create_info.format = tex_format;
15668 image_view_create_info.subresourceRange.baseMipLevel = 0;
15669 image_view_create_info.subresourceRange.levelCount = 1;
15670 // Cause an error by setting an invalid image aspect
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015671 image_view_create_info.subresourceRange.aspectMask = VK_IMAGE_ASPECT_METADATA_BIT;
Mark Lobodzinskidc86b852015-10-23 14:20:31 -060015672
15673 VkImageView view;
Tobin Ehlis1f567a22016-05-25 16:15:18 -060015674 vkCreateImageView(m_device->device(), &image_view_create_info, NULL, &view);
Mark Lobodzinskidc86b852015-10-23 14:20:31 -060015675
Chris Forbes8f36a8a2016-04-07 13:21:07 +120015676 m_errorMonitor->VerifyFound();
Mark Lobodzinskidc86b852015-10-23 14:20:31 -060015677}
15678
Mark Lobodzinskidb117632016-03-31 10:45:56 -060015679TEST_F(VkLayerTest, CopyImageLayerCountMismatch) {
Karl Schultz6addd812016-02-02 17:17:23 -070015680 VkResult err;
15681 bool pass;
Mike Stroyana3082432015-09-25 13:39:21 -060015682
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015683 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
15684 "vkCmdCopyImage: number of layers in source and destination subresources for pRegions");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060015685
Mike Stroyana3082432015-09-25 13:39:21 -060015686 ASSERT_NO_FATAL_FAILURE(InitState());
Mike Stroyana3082432015-09-25 13:39:21 -060015687
15688 // Create two images of different types and try to copy between them
Karl Schultz6addd812016-02-02 17:17:23 -070015689 VkImage srcImage;
15690 VkImage dstImage;
15691 VkDeviceMemory srcMem;
15692 VkDeviceMemory destMem;
15693 VkMemoryRequirements memReqs;
Mike Stroyana3082432015-09-25 13:39:21 -060015694
15695 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070015696 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
15697 image_create_info.pNext = NULL;
15698 image_create_info.imageType = VK_IMAGE_TYPE_2D;
15699 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
15700 image_create_info.extent.width = 32;
15701 image_create_info.extent.height = 32;
15702 image_create_info.extent.depth = 1;
15703 image_create_info.mipLevels = 1;
Mark Lobodzinskidb117632016-03-31 10:45:56 -060015704 image_create_info.arrayLayers = 4;
Karl Schultz6addd812016-02-02 17:17:23 -070015705 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
15706 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
15707 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
15708 image_create_info.flags = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060015709
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015710 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
Mike Stroyana3082432015-09-25 13:39:21 -060015711 ASSERT_VK_SUCCESS(err);
15712
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015713 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
Mike Stroyana3082432015-09-25 13:39:21 -060015714 ASSERT_VK_SUCCESS(err);
15715
15716 // Allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015717 VkMemoryAllocateInfo memAlloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -070015718 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
15719 memAlloc.pNext = NULL;
15720 memAlloc.allocationSize = 0;
15721 memAlloc.memoryTypeIndex = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060015722
Courtney Goeltzenleuchter06d89472015-10-20 16:40:38 -060015723 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060015724 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015725 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060015726 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015727 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
Mike Stroyana3082432015-09-25 13:39:21 -060015728 ASSERT_VK_SUCCESS(err);
15729
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015730 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060015731 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015732 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Mike Stroyana3082432015-09-25 13:39:21 -060015733 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015734 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
Mike Stroyana3082432015-09-25 13:39:21 -060015735 ASSERT_VK_SUCCESS(err);
15736
15737 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
15738 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015739 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
Mike Stroyana3082432015-09-25 13:39:21 -060015740 ASSERT_VK_SUCCESS(err);
15741
15742 BeginCommandBuffer();
15743 VkImageCopy copyRegion;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080015744 copyRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060015745 copyRegion.srcSubresource.mipLevel = 0;
Courtney Goeltzenleuchter8367ce02015-10-16 09:46:00 -060015746 copyRegion.srcSubresource.baseArrayLayer = 0;
Mark Lobodzinskidb117632016-03-31 10:45:56 -060015747 copyRegion.srcSubresource.layerCount = 1;
Mike Stroyana3082432015-09-25 13:39:21 -060015748 copyRegion.srcOffset.x = 0;
15749 copyRegion.srcOffset.y = 0;
15750 copyRegion.srcOffset.z = 0;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080015751 copyRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015752 copyRegion.dstSubresource.mipLevel = 0;
15753 copyRegion.dstSubresource.baseArrayLayer = 0;
Mark Lobodzinskidb117632016-03-31 10:45:56 -060015754 // Introduce failure by forcing the dst layerCount to differ from src
15755 copyRegion.dstSubresource.layerCount = 3;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015756 copyRegion.dstOffset.x = 0;
15757 copyRegion.dstOffset.y = 0;
15758 copyRegion.dstOffset.z = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060015759 copyRegion.extent.width = 1;
15760 copyRegion.extent.height = 1;
15761 copyRegion.extent.depth = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015762 m_commandBuffer->CopyImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, VK_IMAGE_LAYOUT_GENERAL, 1, &copyRegion);
Mike Stroyana3082432015-09-25 13:39:21 -060015763 EndCommandBuffer();
15764
Chris Forbes8f36a8a2016-04-07 13:21:07 +120015765 m_errorMonitor->VerifyFound();
Mike Stroyana3082432015-09-25 13:39:21 -060015766
Chia-I Wuf7458c52015-10-26 21:10:41 +080015767 vkDestroyImage(m_device->device(), srcImage, NULL);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015768 vkDestroyImage(m_device->device(), dstImage, NULL);
Chia-I Wuf7458c52015-10-26 21:10:41 +080015769 vkFreeMemory(m_device->device(), srcMem, NULL);
15770 vkFreeMemory(m_device->device(), destMem, NULL);
Mike Stroyana3082432015-09-25 13:39:21 -060015771}
15772
Tony Barbourd6673642016-05-05 14:46:39 -060015773TEST_F(VkLayerTest, ImageLayerUnsupportedFormat) {
15774
15775 TEST_DESCRIPTION("Creating images with unsuported formats ");
15776
15777 ASSERT_NO_FATAL_FAILURE(InitState());
15778 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
15779 VkImageObj image(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015780 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 -060015781 VK_IMAGE_TILING_OPTIMAL, 0);
15782 ASSERT_TRUE(image.initialized());
15783
Mark Lobodzinskiba5c6862016-05-17 08:14:00 -060015784 // Create image with unsupported format - Expect FORMAT_UNSUPPORTED
15785 VkImageCreateInfo image_create_info;
15786 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
15787 image_create_info.pNext = NULL;
15788 image_create_info.imageType = VK_IMAGE_TYPE_2D;
15789 image_create_info.format = VK_FORMAT_UNDEFINED;
15790 image_create_info.extent.width = 32;
15791 image_create_info.extent.height = 32;
15792 image_create_info.extent.depth = 1;
15793 image_create_info.mipLevels = 1;
15794 image_create_info.arrayLayers = 1;
15795 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
15796 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
15797 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
15798 image_create_info.flags = 0;
15799
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015800 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
15801 "vkCreateImage: VkFormat for image must not be VK_FORMAT_UNDEFINED");
Mark Lobodzinskiba5c6862016-05-17 08:14:00 -060015802
15803 VkImage localImage;
15804 vkCreateImage(m_device->handle(), &image_create_info, NULL, &localImage);
15805 m_errorMonitor->VerifyFound();
15806
Tony Barbourd6673642016-05-05 14:46:39 -060015807 VkFormat unsupported = VK_FORMAT_UNDEFINED;
Mark Lobodzinskiba5c6862016-05-17 08:14:00 -060015808 // Look for a format that is COMPLETELY unsupported with this hardware
Tony Barbourd6673642016-05-05 14:46:39 -060015809 for (int f = VK_FORMAT_BEGIN_RANGE; f <= VK_FORMAT_END_RANGE; f++) {
15810 VkFormat format = static_cast<VkFormat>(f);
15811 VkFormatProperties fProps = m_device->format_properties(format);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015812 if (format != VK_FORMAT_UNDEFINED && fProps.linearTilingFeatures == 0 && fProps.optimalTilingFeatures == 0) {
Tony Barbourd6673642016-05-05 14:46:39 -060015813 unsupported = format;
15814 break;
15815 }
15816 }
Mark Lobodzinskiba5c6862016-05-17 08:14:00 -060015817
Tony Barbourd6673642016-05-05 14:46:39 -060015818 if (unsupported != VK_FORMAT_UNDEFINED) {
Tony Barbourd6673642016-05-05 14:46:39 -060015819 image_create_info.format = unsupported;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015820 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "is an unsupported format");
Tony Barbourd6673642016-05-05 14:46:39 -060015821
Mark Lobodzinskiba5c6862016-05-17 08:14:00 -060015822 vkCreateImage(m_device->handle(), &image_create_info, NULL, &localImage);
Tony Barbourd6673642016-05-05 14:46:39 -060015823 m_errorMonitor->VerifyFound();
15824 }
15825}
15826
15827TEST_F(VkLayerTest, ImageLayerViewTests) {
15828 VkResult ret;
15829 TEST_DESCRIPTION("Passing bad parameters to CreateImageView");
15830
15831 ASSERT_NO_FATAL_FAILURE(InitState());
15832
15833 VkImageObj image(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015834 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 -060015835 VK_IMAGE_TILING_OPTIMAL, 0);
15836 ASSERT_TRUE(image.initialized());
15837
15838 VkImageView imgView;
15839 VkImageViewCreateInfo imgViewInfo = {};
15840 imgViewInfo.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
15841 imgViewInfo.image = image.handle();
15842 imgViewInfo.viewType = VK_IMAGE_VIEW_TYPE_2D;
15843 imgViewInfo.format = VK_FORMAT_B8G8R8A8_UNORM;
15844 imgViewInfo.subresourceRange.layerCount = 1;
15845 imgViewInfo.subresourceRange.baseMipLevel = 0;
15846 imgViewInfo.subresourceRange.levelCount = 1;
15847 imgViewInfo.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
15848
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015849 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "vkCreateImageView called with baseMipLevel");
Tony Barbourd6673642016-05-05 14:46:39 -060015850 // View can't have baseMipLevel >= image's mipLevels - Expect
15851 // VIEW_CREATE_ERROR
15852 imgViewInfo.subresourceRange.baseMipLevel = 1;
15853 vkCreateImageView(m_device->handle(), &imgViewInfo, NULL, &imgView);
15854 m_errorMonitor->VerifyFound();
15855 imgViewInfo.subresourceRange.baseMipLevel = 0;
15856
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015857 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "vkCreateImageView called with baseArrayLayer");
Tony Barbourd6673642016-05-05 14:46:39 -060015858 // View can't have baseArrayLayer >= image's arraySize - Expect
15859 // VIEW_CREATE_ERROR
15860 imgViewInfo.subresourceRange.baseArrayLayer = 1;
15861 vkCreateImageView(m_device->handle(), &imgViewInfo, NULL, &imgView);
15862 m_errorMonitor->VerifyFound();
15863 imgViewInfo.subresourceRange.baseArrayLayer = 0;
15864
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015865 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "vkCreateImageView called with 0 in "
15866 "pCreateInfo->subresourceRange."
15867 "levelCount");
Tony Barbourd6673642016-05-05 14:46:39 -060015868 // View's levelCount can't be 0 - Expect VIEW_CREATE_ERROR
15869 imgViewInfo.subresourceRange.levelCount = 0;
15870 vkCreateImageView(m_device->handle(), &imgViewInfo, NULL, &imgView);
15871 m_errorMonitor->VerifyFound();
15872 imgViewInfo.subresourceRange.levelCount = 1;
15873
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015874 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "vkCreateImageView called with 0 in "
15875 "pCreateInfo->subresourceRange."
15876 "layerCount");
Tony Barbourd6673642016-05-05 14:46:39 -060015877 // View's layerCount can't be 0 - Expect VIEW_CREATE_ERROR
15878 imgViewInfo.subresourceRange.layerCount = 0;
15879 vkCreateImageView(m_device->handle(), &imgViewInfo, NULL, &imgView);
15880 m_errorMonitor->VerifyFound();
15881 imgViewInfo.subresourceRange.layerCount = 1;
15882
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015883 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "but both must be color formats");
Tony Barbourd6673642016-05-05 14:46:39 -060015884 // Can't use depth format for view into color image - Expect INVALID_FORMAT
15885 imgViewInfo.format = VK_FORMAT_D24_UNORM_S8_UINT;
15886 vkCreateImageView(m_device->handle(), &imgViewInfo, NULL, &imgView);
15887 m_errorMonitor->VerifyFound();
15888 imgViewInfo.format = VK_FORMAT_B8G8R8A8_UNORM;
15889
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015890 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Formats MUST be IDENTICAL unless "
15891 "VK_IMAGE_CREATE_MUTABLE_FORMAT BIT "
15892 "was set on image creation.");
Tony Barbourd6673642016-05-05 14:46:39 -060015893 // Same compatibility class but no MUTABLE_FORMAT bit - Expect
15894 // VIEW_CREATE_ERROR
15895 imgViewInfo.format = VK_FORMAT_B8G8R8A8_UINT;
15896 vkCreateImageView(m_device->handle(), &imgViewInfo, NULL, &imgView);
15897 m_errorMonitor->VerifyFound();
15898 imgViewInfo.format = VK_FORMAT_B8G8R8A8_UNORM;
15899
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015900 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "can support ImageViews with "
15901 "differing formats but they must be "
15902 "in the same compatibility class.");
Tony Barbourd6673642016-05-05 14:46:39 -060015903 // Have MUTABLE_FORMAT bit but not in same compatibility class - Expect
15904 // VIEW_CREATE_ERROR
15905 VkImageCreateInfo mutImgInfo = image.create_info();
15906 VkImage mutImage;
15907 mutImgInfo.format = VK_FORMAT_R8_UINT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015908 assert(m_device->format_properties(VK_FORMAT_R8_UINT).optimalTilingFeatures & VK_FORMAT_FEATURE_COLOR_ATTACHMENT_BIT);
Tony Barbourd6673642016-05-05 14:46:39 -060015909 mutImgInfo.flags = VK_IMAGE_CREATE_MUTABLE_FORMAT_BIT;
15910 mutImgInfo.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
15911 ret = vkCreateImage(m_device->handle(), &mutImgInfo, NULL, &mutImage);
15912 ASSERT_VK_SUCCESS(ret);
15913 imgViewInfo.image = mutImage;
15914 vkCreateImageView(m_device->handle(), &imgViewInfo, NULL, &imgView);
15915 m_errorMonitor->VerifyFound();
15916 imgViewInfo.image = image.handle();
15917 vkDestroyImage(m_device->handle(), mutImage, NULL);
15918}
15919
15920TEST_F(VkLayerTest, MiscImageLayerTests) {
15921
15922 TEST_DESCRIPTION("Image layer tests that don't belong elsewhare");
15923
15924 ASSERT_NO_FATAL_FAILURE(InitState());
15925
15926 VkImageObj image(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015927 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 -060015928 VK_IMAGE_TILING_OPTIMAL, 0);
15929 ASSERT_TRUE(image.initialized());
15930
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015931 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "number of layers in image subresource is zero");
Tony Barbourd6673642016-05-05 14:46:39 -060015932 vk_testing::Buffer buffer;
15933 VkMemoryPropertyFlags reqs = 0;
15934 buffer.init_as_src(*m_device, 128 * 128 * 4, reqs);
15935 VkBufferImageCopy region = {};
15936 region.bufferRowLength = 128;
15937 region.bufferImageHeight = 128;
15938 region.imageSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
15939 // layerCount can't be 0 - Expect MISMATCHED_IMAGE_ASPECT
15940 region.imageSubresource.layerCount = 0;
15941 region.imageExtent.height = 4;
15942 region.imageExtent.width = 4;
15943 region.imageExtent.depth = 1;
15944 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015945 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer.handle(), image.handle(),
15946 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, &region);
Tony Barbourd6673642016-05-05 14:46:39 -060015947 m_errorMonitor->VerifyFound();
15948 region.imageSubresource.layerCount = 1;
15949
Mark Lobodzinski7d8cf142016-08-19 10:53:26 -060015950 // BufferOffset must be a multiple of the calling command's VkImage parameter's texel size
15951 // Introduce failure by setting bufferOffset to 1 and 1/2 texels
15952 region.bufferOffset = 6;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015953 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "must be a multiple of this format's texel size");
15954 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer.handle(), image.handle(),
15955 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, &region);
Mark Lobodzinski7d8cf142016-08-19 10:53:26 -060015956 m_errorMonitor->VerifyFound();
15957
15958 // BufferOffset must be a multiple of 4
15959 // Introduce failure by setting bufferOffset to a value not divisible by 4
15960 region.bufferOffset = 6;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015961 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "must be a multiple of 4");
15962 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer.handle(), image.handle(),
15963 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, &region);
Mark Lobodzinski7d8cf142016-08-19 10:53:26 -060015964 m_errorMonitor->VerifyFound();
15965
15966 // BufferRowLength must be 0, or greater than or equal to the width member of imageExtent
15967 region.bufferOffset = 0;
15968 region.imageExtent.height = 128;
15969 region.imageExtent.width = 128;
15970 // Introduce failure by setting bufferRowLength > 0 but less than width
15971 region.bufferRowLength = 64;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015972 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
15973 "must be zero or greater-than-or-equal-to imageExtent.width");
15974 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer.handle(), image.handle(),
15975 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, &region);
Mark Lobodzinski7d8cf142016-08-19 10:53:26 -060015976 m_errorMonitor->VerifyFound();
15977
15978 // BufferImageHeight must be 0, or greater than or equal to the height member of imageExtent
15979 region.bufferRowLength = 128;
15980 // Introduce failure by setting bufferRowHeight > 0 but less than height
15981 region.bufferImageHeight = 64;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015982 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
15983 "must be zero or greater-than-or-equal-to imageExtent.height");
15984 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer.handle(), image.handle(),
15985 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, &region);
Mark Lobodzinski7d8cf142016-08-19 10:53:26 -060015986 m_errorMonitor->VerifyFound();
15987
15988 region.bufferImageHeight = 128;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015989 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "aspectMasks for each region must "
15990 "specify only COLOR or DEPTH or "
15991 "STENCIL");
Tony Barbourd6673642016-05-05 14:46:39 -060015992 // Expect MISMATCHED_IMAGE_ASPECT
15993 region.imageSubresource.aspectMask = VK_IMAGE_ASPECT_METADATA_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015994 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer.handle(), image.handle(),
15995 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, &region);
Tony Barbourd6673642016-05-05 14:46:39 -060015996 m_errorMonitor->VerifyFound();
15997 region.imageSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
15998
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015999 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
16000 "If the format of srcImage is a depth, stencil, depth stencil or "
16001 "integer-based format then filter must be VK_FILTER_NEAREST");
Tony Barbourd6673642016-05-05 14:46:39 -060016002 // Expect INVALID_FILTER
16003 VkImageObj intImage1(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016004 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 -060016005 VkImageObj intImage2(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016006 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 -060016007 VkImageBlit blitRegion = {};
16008 blitRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
16009 blitRegion.srcSubresource.baseArrayLayer = 0;
16010 blitRegion.srcSubresource.layerCount = 1;
16011 blitRegion.srcSubresource.mipLevel = 0;
16012 blitRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
16013 blitRegion.dstSubresource.baseArrayLayer = 0;
16014 blitRegion.dstSubresource.layerCount = 1;
16015 blitRegion.dstSubresource.mipLevel = 0;
16016
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016017 vkCmdBlitImage(m_commandBuffer->GetBufferHandle(), intImage1.handle(), intImage1.layout(), intImage2.handle(),
16018 intImage2.layout(), 16, &blitRegion, VK_FILTER_LINEAR);
Tony Barbourd6673642016-05-05 14:46:39 -060016019 m_errorMonitor->VerifyFound();
16020
Mark Lobodzinskib02ea642016-08-17 13:03:57 -060016021 // Look for NULL-blit warning
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016022 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT, "Offsets specify a zero-volume area.");
16023 vkCmdBlitImage(m_commandBuffer->GetBufferHandle(), intImage1.handle(), intImage1.layout(), intImage2.handle(),
16024 intImage2.layout(), 1, &blitRegion, VK_FILTER_LINEAR);
Mark Lobodzinskib02ea642016-08-17 13:03:57 -060016025 m_errorMonitor->VerifyFound();
16026
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016027 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "called with 0 in ppMemoryBarriers");
Tony Barbourd6673642016-05-05 14:46:39 -060016028 VkImageMemoryBarrier img_barrier;
16029 img_barrier.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
16030 img_barrier.pNext = NULL;
16031 img_barrier.srcAccessMask = VK_ACCESS_HOST_WRITE_BIT;
16032 img_barrier.dstAccessMask = VK_ACCESS_SHADER_READ_BIT;
16033 img_barrier.oldLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
16034 img_barrier.newLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
16035 img_barrier.image = image.handle();
16036 img_barrier.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
16037 img_barrier.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
16038 img_barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
16039 img_barrier.subresourceRange.baseArrayLayer = 0;
16040 img_barrier.subresourceRange.baseMipLevel = 0;
16041 // layerCount should not be 0 - Expect INVALID_IMAGE_RESOURCE
16042 img_barrier.subresourceRange.layerCount = 0;
16043 img_barrier.subresourceRange.levelCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016044 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
16045 nullptr, 0, nullptr, 1, &img_barrier);
Tony Barbourd6673642016-05-05 14:46:39 -060016046 m_errorMonitor->VerifyFound();
16047 img_barrier.subresourceRange.layerCount = 1;
16048}
16049
16050TEST_F(VkLayerTest, ImageFormatLimits) {
16051
16052 TEST_DESCRIPTION("Exceed the limits of image format ");
16053
Cody Northropc31a84f2016-08-22 10:41:47 -060016054 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016055 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "CreateImage extents exceed allowable limits for format");
Tony Barbourd6673642016-05-05 14:46:39 -060016056 VkImageCreateInfo image_create_info = {};
16057 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
16058 image_create_info.pNext = NULL;
16059 image_create_info.imageType = VK_IMAGE_TYPE_2D;
16060 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
16061 image_create_info.extent.width = 32;
16062 image_create_info.extent.height = 32;
16063 image_create_info.extent.depth = 1;
16064 image_create_info.mipLevels = 1;
16065 image_create_info.arrayLayers = 1;
16066 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
16067 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
16068 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
16069 image_create_info.initialLayout = VK_IMAGE_LAYOUT_UNDEFINED;
16070 image_create_info.flags = 0;
16071
16072 VkImage nullImg;
16073 VkImageFormatProperties imgFmtProps;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016074 vkGetPhysicalDeviceImageFormatProperties(gpu(), image_create_info.format, image_create_info.imageType, image_create_info.tiling,
16075 image_create_info.usage, image_create_info.flags, &imgFmtProps);
Tony Barbourd6673642016-05-05 14:46:39 -060016076 image_create_info.extent.depth = imgFmtProps.maxExtent.depth + 1;
16077 // Expect INVALID_FORMAT_LIMITS_VIOLATION
16078 vkCreateImage(m_device->handle(), &image_create_info, NULL, &nullImg);
16079 m_errorMonitor->VerifyFound();
16080 image_create_info.extent.depth = 1;
16081
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016082 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "exceeds allowable maximum supported by format of");
Tony Barbourd6673642016-05-05 14:46:39 -060016083 image_create_info.mipLevels = imgFmtProps.maxMipLevels + 1;
16084 // Expect INVALID_FORMAT_LIMITS_VIOLATION
16085 vkCreateImage(m_device->handle(), &image_create_info, NULL, &nullImg);
16086 m_errorMonitor->VerifyFound();
16087 image_create_info.mipLevels = 1;
16088
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016089 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "exceeds allowable maximum supported by format of");
Tony Barbourd6673642016-05-05 14:46:39 -060016090 image_create_info.arrayLayers = imgFmtProps.maxArrayLayers + 1;
16091 // Expect INVALID_FORMAT_LIMITS_VIOLATION
16092 vkCreateImage(m_device->handle(), &image_create_info, NULL, &nullImg);
16093 m_errorMonitor->VerifyFound();
16094 image_create_info.arrayLayers = 1;
16095
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016096 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "is not supported by format");
Tony Barbourd6673642016-05-05 14:46:39 -060016097 int samples = imgFmtProps.sampleCounts >> 1;
16098 image_create_info.samples = (VkSampleCountFlagBits)samples;
16099 // Expect INVALID_FORMAT_LIMITS_VIOLATION
16100 vkCreateImage(m_device->handle(), &image_create_info, NULL, &nullImg);
16101 m_errorMonitor->VerifyFound();
16102 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
16103
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016104 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "pCreateInfo->initialLayout, must be "
16105 "VK_IMAGE_LAYOUT_UNDEFINED or "
16106 "VK_IMAGE_LAYOUT_PREINITIALIZED");
Tony Barbourd6673642016-05-05 14:46:39 -060016107 image_create_info.initialLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
16108 // Expect INVALID_LAYOUT
16109 vkCreateImage(m_device->handle(), &image_create_info, NULL, &nullImg);
16110 m_errorMonitor->VerifyFound();
16111 image_create_info.initialLayout = VK_IMAGE_LAYOUT_UNDEFINED;
16112}
16113
Karl Schultz6addd812016-02-02 17:17:23 -070016114TEST_F(VkLayerTest, CopyImageFormatSizeMismatch) {
Karl Schultzbdb75952016-04-19 11:36:49 -060016115 VkResult err;
16116 bool pass;
16117
16118 // Create color images with different format sizes and try to copy between them
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016119 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
16120 "vkCmdCopyImage called with unmatched source and dest image format sizes");
Karl Schultzbdb75952016-04-19 11:36:49 -060016121
16122 ASSERT_NO_FATAL_FAILURE(InitState());
16123
16124 // Create two images of different types and try to copy between them
16125 VkImage srcImage;
16126 VkImage dstImage;
16127 VkDeviceMemory srcMem;
16128 VkDeviceMemory destMem;
16129 VkMemoryRequirements memReqs;
16130
16131 VkImageCreateInfo image_create_info = {};
16132 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
16133 image_create_info.pNext = NULL;
16134 image_create_info.imageType = VK_IMAGE_TYPE_2D;
16135 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
16136 image_create_info.extent.width = 32;
16137 image_create_info.extent.height = 32;
16138 image_create_info.extent.depth = 1;
16139 image_create_info.mipLevels = 1;
16140 image_create_info.arrayLayers = 1;
16141 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
16142 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
16143 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
16144 image_create_info.flags = 0;
16145
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016146 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
Karl Schultzbdb75952016-04-19 11:36:49 -060016147 ASSERT_VK_SUCCESS(err);
16148
16149 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT;
16150 // Introduce failure by creating second image with a different-sized format.
16151 image_create_info.format = VK_FORMAT_R5G5B5A1_UNORM_PACK16;
16152
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016153 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
Karl Schultzbdb75952016-04-19 11:36:49 -060016154 ASSERT_VK_SUCCESS(err);
16155
16156 // Allocate memory
16157 VkMemoryAllocateInfo memAlloc = {};
16158 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
16159 memAlloc.pNext = NULL;
16160 memAlloc.allocationSize = 0;
16161 memAlloc.memoryTypeIndex = 0;
16162
16163 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
16164 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016165 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Karl Schultzbdb75952016-04-19 11:36:49 -060016166 ASSERT_TRUE(pass);
16167 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
16168 ASSERT_VK_SUCCESS(err);
16169
16170 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
16171 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016172 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Karl Schultzbdb75952016-04-19 11:36:49 -060016173 ASSERT_TRUE(pass);
16174 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
16175 ASSERT_VK_SUCCESS(err);
16176
16177 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
16178 ASSERT_VK_SUCCESS(err);
16179 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
16180 ASSERT_VK_SUCCESS(err);
16181
16182 BeginCommandBuffer();
16183 VkImageCopy copyRegion;
16184 copyRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
16185 copyRegion.srcSubresource.mipLevel = 0;
16186 copyRegion.srcSubresource.baseArrayLayer = 0;
16187 copyRegion.srcSubresource.layerCount = 0;
16188 copyRegion.srcOffset.x = 0;
16189 copyRegion.srcOffset.y = 0;
16190 copyRegion.srcOffset.z = 0;
16191 copyRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
16192 copyRegion.dstSubresource.mipLevel = 0;
16193 copyRegion.dstSubresource.baseArrayLayer = 0;
16194 copyRegion.dstSubresource.layerCount = 0;
16195 copyRegion.dstOffset.x = 0;
16196 copyRegion.dstOffset.y = 0;
16197 copyRegion.dstOffset.z = 0;
16198 copyRegion.extent.width = 1;
16199 copyRegion.extent.height = 1;
16200 copyRegion.extent.depth = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016201 m_commandBuffer->CopyImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, VK_IMAGE_LAYOUT_GENERAL, 1, &copyRegion);
Karl Schultzbdb75952016-04-19 11:36:49 -060016202 EndCommandBuffer();
16203
16204 m_errorMonitor->VerifyFound();
16205
16206 vkDestroyImage(m_device->device(), srcImage, NULL);
16207 vkDestroyImage(m_device->device(), dstImage, NULL);
16208 vkFreeMemory(m_device->device(), srcMem, NULL);
16209 vkFreeMemory(m_device->device(), destMem, NULL);
Mike Stroyana3082432015-09-25 13:39:21 -060016210}
16211
Karl Schultz6addd812016-02-02 17:17:23 -070016212TEST_F(VkLayerTest, CopyImageDepthStencilFormatMismatch) {
16213 VkResult err;
16214 bool pass;
Mike Stroyana3082432015-09-25 13:39:21 -060016215
Mark Lobodzinskidb117632016-03-31 10:45:56 -060016216 // Create a color image and a depth/stencil image and try to copy between them
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016217 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
16218 "vkCmdCopyImage called with unmatched source and dest image depth");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060016219
Mike Stroyana3082432015-09-25 13:39:21 -060016220 ASSERT_NO_FATAL_FAILURE(InitState());
Mike Stroyana3082432015-09-25 13:39:21 -060016221
16222 // Create two images of different types and try to copy between them
Karl Schultz6addd812016-02-02 17:17:23 -070016223 VkImage srcImage;
16224 VkImage dstImage;
16225 VkDeviceMemory srcMem;
16226 VkDeviceMemory destMem;
16227 VkMemoryRequirements memReqs;
Mike Stroyana3082432015-09-25 13:39:21 -060016228
16229 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070016230 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
16231 image_create_info.pNext = NULL;
16232 image_create_info.imageType = VK_IMAGE_TYPE_2D;
16233 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
16234 image_create_info.extent.width = 32;
16235 image_create_info.extent.height = 32;
16236 image_create_info.extent.depth = 1;
16237 image_create_info.mipLevels = 1;
16238 image_create_info.arrayLayers = 1;
16239 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
16240 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
16241 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
16242 image_create_info.flags = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060016243
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016244 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
Mike Stroyana3082432015-09-25 13:39:21 -060016245 ASSERT_VK_SUCCESS(err);
16246
Karl Schultzbdb75952016-04-19 11:36:49 -060016247 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT;
16248
Mark Lobodzinskidb117632016-03-31 10:45:56 -060016249 // Introduce failure by creating second image with a depth/stencil format
Karl Schultz6addd812016-02-02 17:17:23 -070016250 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
Mark Lobodzinskidb117632016-03-31 10:45:56 -060016251 image_create_info.format = VK_FORMAT_D24_UNORM_S8_UINT;
16252 image_create_info.usage = VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060016253
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016254 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
Mike Stroyana3082432015-09-25 13:39:21 -060016255 ASSERT_VK_SUCCESS(err);
16256
16257 // Allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016258 VkMemoryAllocateInfo memAlloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -070016259 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
16260 memAlloc.pNext = NULL;
16261 memAlloc.allocationSize = 0;
16262 memAlloc.memoryTypeIndex = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060016263
Courtney Goeltzenleuchter06d89472015-10-20 16:40:38 -060016264 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060016265 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016266 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060016267 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016268 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
Mike Stroyana3082432015-09-25 13:39:21 -060016269 ASSERT_VK_SUCCESS(err);
16270
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016271 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060016272 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016273 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060016274 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016275 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
Mike Stroyana3082432015-09-25 13:39:21 -060016276 ASSERT_VK_SUCCESS(err);
16277
16278 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
16279 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016280 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
Mike Stroyana3082432015-09-25 13:39:21 -060016281 ASSERT_VK_SUCCESS(err);
16282
16283 BeginCommandBuffer();
16284 VkImageCopy copyRegion;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080016285 copyRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060016286 copyRegion.srcSubresource.mipLevel = 0;
Courtney Goeltzenleuchter8367ce02015-10-16 09:46:00 -060016287 copyRegion.srcSubresource.baseArrayLayer = 0;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016288 copyRegion.srcSubresource.layerCount = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060016289 copyRegion.srcOffset.x = 0;
16290 copyRegion.srcOffset.y = 0;
16291 copyRegion.srcOffset.z = 0;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080016292 copyRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016293 copyRegion.dstSubresource.mipLevel = 0;
16294 copyRegion.dstSubresource.baseArrayLayer = 0;
16295 copyRegion.dstSubresource.layerCount = 0;
16296 copyRegion.dstOffset.x = 0;
16297 copyRegion.dstOffset.y = 0;
16298 copyRegion.dstOffset.z = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060016299 copyRegion.extent.width = 1;
16300 copyRegion.extent.height = 1;
16301 copyRegion.extent.depth = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016302 m_commandBuffer->CopyImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, VK_IMAGE_LAYOUT_GENERAL, 1, &copyRegion);
Mike Stroyana3082432015-09-25 13:39:21 -060016303 EndCommandBuffer();
16304
Chris Forbes8f36a8a2016-04-07 13:21:07 +120016305 m_errorMonitor->VerifyFound();
Mike Stroyana3082432015-09-25 13:39:21 -060016306
Chia-I Wuf7458c52015-10-26 21:10:41 +080016307 vkDestroyImage(m_device->device(), srcImage, NULL);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016308 vkDestroyImage(m_device->device(), dstImage, NULL);
Chia-I Wuf7458c52015-10-26 21:10:41 +080016309 vkFreeMemory(m_device->device(), srcMem, NULL);
16310 vkFreeMemory(m_device->device(), destMem, NULL);
Mike Stroyana3082432015-09-25 13:39:21 -060016311}
16312
Karl Schultz6addd812016-02-02 17:17:23 -070016313TEST_F(VkLayerTest, ResolveImageLowSampleCount) {
16314 VkResult err;
16315 bool pass;
Mike Stroyana3082432015-09-25 13:39:21 -060016316
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016317 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
16318 "vkCmdResolveImage called with source sample count less than 2.");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060016319
Mike Stroyana3082432015-09-25 13:39:21 -060016320 ASSERT_NO_FATAL_FAILURE(InitState());
Mike Stroyana3082432015-09-25 13:39:21 -060016321
16322 // Create two images of sample count 1 and try to Resolve between them
Karl Schultz6addd812016-02-02 17:17:23 -070016323 VkImage srcImage;
16324 VkImage dstImage;
16325 VkDeviceMemory srcMem;
16326 VkDeviceMemory destMem;
16327 VkMemoryRequirements memReqs;
Mike Stroyana3082432015-09-25 13:39:21 -060016328
16329 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070016330 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
16331 image_create_info.pNext = NULL;
16332 image_create_info.imageType = VK_IMAGE_TYPE_2D;
16333 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
16334 image_create_info.extent.width = 32;
16335 image_create_info.extent.height = 1;
16336 image_create_info.extent.depth = 1;
16337 image_create_info.mipLevels = 1;
16338 image_create_info.arrayLayers = 1;
16339 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
16340 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
16341 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
16342 image_create_info.flags = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060016343
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016344 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
Mike Stroyana3082432015-09-25 13:39:21 -060016345 ASSERT_VK_SUCCESS(err);
16346
Karl Schultz6addd812016-02-02 17:17:23 -070016347 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060016348
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016349 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
Mike Stroyana3082432015-09-25 13:39:21 -060016350 ASSERT_VK_SUCCESS(err);
16351
16352 // Allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016353 VkMemoryAllocateInfo memAlloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -070016354 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
16355 memAlloc.pNext = NULL;
16356 memAlloc.allocationSize = 0;
16357 memAlloc.memoryTypeIndex = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060016358
Courtney Goeltzenleuchter06d89472015-10-20 16:40:38 -060016359 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060016360 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016361 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060016362 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016363 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
Mike Stroyana3082432015-09-25 13:39:21 -060016364 ASSERT_VK_SUCCESS(err);
16365
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016366 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060016367 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016368 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060016369 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016370 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
Mike Stroyana3082432015-09-25 13:39:21 -060016371 ASSERT_VK_SUCCESS(err);
16372
16373 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
16374 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016375 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
Mike Stroyana3082432015-09-25 13:39:21 -060016376 ASSERT_VK_SUCCESS(err);
16377
16378 BeginCommandBuffer();
16379 // Need memory barrier to VK_IMAGE_LAYOUT_GENERAL for source and dest?
Karl Schultz6addd812016-02-02 17:17:23 -070016380 // VK_IMAGE_LAYOUT_UNDEFINED = 0,
16381 // VK_IMAGE_LAYOUT_GENERAL = 1,
Mike Stroyana3082432015-09-25 13:39:21 -060016382 VkImageResolve resolveRegion;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080016383 resolveRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060016384 resolveRegion.srcSubresource.mipLevel = 0;
Courtney Goeltzenleuchter8367ce02015-10-16 09:46:00 -060016385 resolveRegion.srcSubresource.baseArrayLayer = 0;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016386 resolveRegion.srcSubresource.layerCount = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060016387 resolveRegion.srcOffset.x = 0;
16388 resolveRegion.srcOffset.y = 0;
16389 resolveRegion.srcOffset.z = 0;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080016390 resolveRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016391 resolveRegion.dstSubresource.mipLevel = 0;
16392 resolveRegion.dstSubresource.baseArrayLayer = 0;
16393 resolveRegion.dstSubresource.layerCount = 0;
16394 resolveRegion.dstOffset.x = 0;
16395 resolveRegion.dstOffset.y = 0;
16396 resolveRegion.dstOffset.z = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060016397 resolveRegion.extent.width = 1;
16398 resolveRegion.extent.height = 1;
16399 resolveRegion.extent.depth = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016400 m_commandBuffer->ResolveImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, VK_IMAGE_LAYOUT_GENERAL, 1, &resolveRegion);
Mike Stroyana3082432015-09-25 13:39:21 -060016401 EndCommandBuffer();
16402
Chris Forbes8f36a8a2016-04-07 13:21:07 +120016403 m_errorMonitor->VerifyFound();
Mike Stroyana3082432015-09-25 13:39:21 -060016404
Chia-I Wuf7458c52015-10-26 21:10:41 +080016405 vkDestroyImage(m_device->device(), srcImage, NULL);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016406 vkDestroyImage(m_device->device(), dstImage, NULL);
Chia-I Wuf7458c52015-10-26 21:10:41 +080016407 vkFreeMemory(m_device->device(), srcMem, NULL);
16408 vkFreeMemory(m_device->device(), destMem, NULL);
Mike Stroyana3082432015-09-25 13:39:21 -060016409}
16410
Karl Schultz6addd812016-02-02 17:17:23 -070016411TEST_F(VkLayerTest, ResolveImageHighSampleCount) {
16412 VkResult err;
16413 bool pass;
Mike Stroyana3082432015-09-25 13:39:21 -060016414
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016415 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
16416 "vkCmdResolveImage called with dest sample count greater than 1.");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060016417
Mike Stroyana3082432015-09-25 13:39:21 -060016418 ASSERT_NO_FATAL_FAILURE(InitState());
Mike Stroyana3082432015-09-25 13:39:21 -060016419
Chris Forbesa7530692016-05-08 12:35:39 +120016420 // Create two images of sample count 4 and try to Resolve between them
Karl Schultz6addd812016-02-02 17:17:23 -070016421 VkImage srcImage;
16422 VkImage dstImage;
16423 VkDeviceMemory srcMem;
16424 VkDeviceMemory destMem;
16425 VkMemoryRequirements memReqs;
Mike Stroyana3082432015-09-25 13:39:21 -060016426
16427 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070016428 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
16429 image_create_info.pNext = NULL;
16430 image_create_info.imageType = VK_IMAGE_TYPE_2D;
16431 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
16432 image_create_info.extent.width = 32;
16433 image_create_info.extent.height = 1;
16434 image_create_info.extent.depth = 1;
16435 image_create_info.mipLevels = 1;
16436 image_create_info.arrayLayers = 1;
Chris Forbesa7530692016-05-08 12:35:39 +120016437 image_create_info.samples = VK_SAMPLE_COUNT_4_BIT;
Karl Schultz6addd812016-02-02 17:17:23 -070016438 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
16439 // Note: Some implementations expect color attachment usage for any
16440 // multisample surface
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016441 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
Karl Schultz6addd812016-02-02 17:17:23 -070016442 image_create_info.flags = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060016443
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016444 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
Mike Stroyana3082432015-09-25 13:39:21 -060016445 ASSERT_VK_SUCCESS(err);
16446
Karl Schultz6addd812016-02-02 17:17:23 -070016447 // Note: Some implementations expect color attachment usage for any
16448 // multisample surface
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016449 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060016450
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016451 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
Mike Stroyana3082432015-09-25 13:39:21 -060016452 ASSERT_VK_SUCCESS(err);
16453
16454 // Allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016455 VkMemoryAllocateInfo memAlloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -070016456 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
16457 memAlloc.pNext = NULL;
16458 memAlloc.allocationSize = 0;
16459 memAlloc.memoryTypeIndex = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060016460
Courtney Goeltzenleuchter06d89472015-10-20 16:40:38 -060016461 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060016462 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016463 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060016464 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016465 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
Mike Stroyana3082432015-09-25 13:39:21 -060016466 ASSERT_VK_SUCCESS(err);
16467
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016468 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060016469 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016470 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060016471 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016472 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
Mike Stroyana3082432015-09-25 13:39:21 -060016473 ASSERT_VK_SUCCESS(err);
16474
16475 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
16476 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016477 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
Mike Stroyana3082432015-09-25 13:39:21 -060016478 ASSERT_VK_SUCCESS(err);
16479
16480 BeginCommandBuffer();
16481 // Need memory barrier to VK_IMAGE_LAYOUT_GENERAL for source and dest?
Karl Schultz6addd812016-02-02 17:17:23 -070016482 // VK_IMAGE_LAYOUT_UNDEFINED = 0,
16483 // VK_IMAGE_LAYOUT_GENERAL = 1,
Mike Stroyana3082432015-09-25 13:39:21 -060016484 VkImageResolve resolveRegion;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080016485 resolveRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060016486 resolveRegion.srcSubresource.mipLevel = 0;
Courtney Goeltzenleuchter8367ce02015-10-16 09:46:00 -060016487 resolveRegion.srcSubresource.baseArrayLayer = 0;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016488 resolveRegion.srcSubresource.layerCount = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060016489 resolveRegion.srcOffset.x = 0;
16490 resolveRegion.srcOffset.y = 0;
16491 resolveRegion.srcOffset.z = 0;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080016492 resolveRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016493 resolveRegion.dstSubresource.mipLevel = 0;
16494 resolveRegion.dstSubresource.baseArrayLayer = 0;
16495 resolveRegion.dstSubresource.layerCount = 0;
16496 resolveRegion.dstOffset.x = 0;
16497 resolveRegion.dstOffset.y = 0;
16498 resolveRegion.dstOffset.z = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060016499 resolveRegion.extent.width = 1;
16500 resolveRegion.extent.height = 1;
16501 resolveRegion.extent.depth = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016502 m_commandBuffer->ResolveImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, VK_IMAGE_LAYOUT_GENERAL, 1, &resolveRegion);
Mike Stroyana3082432015-09-25 13:39:21 -060016503 EndCommandBuffer();
16504
Chris Forbes8f36a8a2016-04-07 13:21:07 +120016505 m_errorMonitor->VerifyFound();
Mike Stroyana3082432015-09-25 13:39:21 -060016506
Chia-I Wuf7458c52015-10-26 21:10:41 +080016507 vkDestroyImage(m_device->device(), srcImage, NULL);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016508 vkDestroyImage(m_device->device(), dstImage, NULL);
Chia-I Wuf7458c52015-10-26 21:10:41 +080016509 vkFreeMemory(m_device->device(), srcMem, NULL);
16510 vkFreeMemory(m_device->device(), destMem, NULL);
Mike Stroyana3082432015-09-25 13:39:21 -060016511}
16512
Karl Schultz6addd812016-02-02 17:17:23 -070016513TEST_F(VkLayerTest, ResolveImageFormatMismatch) {
16514 VkResult err;
16515 bool pass;
Mike Stroyana3082432015-09-25 13:39:21 -060016516
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016517 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
16518 "vkCmdResolveImage called with unmatched source and dest formats.");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060016519
Mike Stroyana3082432015-09-25 13:39:21 -060016520 ASSERT_NO_FATAL_FAILURE(InitState());
Mike Stroyana3082432015-09-25 13:39:21 -060016521
16522 // Create two images of different types and try to copy between them
Karl Schultz6addd812016-02-02 17:17:23 -070016523 VkImage srcImage;
16524 VkImage dstImage;
16525 VkDeviceMemory srcMem;
16526 VkDeviceMemory destMem;
16527 VkMemoryRequirements memReqs;
Mike Stroyana3082432015-09-25 13:39:21 -060016528
16529 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070016530 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
16531 image_create_info.pNext = NULL;
16532 image_create_info.imageType = VK_IMAGE_TYPE_2D;
16533 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
16534 image_create_info.extent.width = 32;
16535 image_create_info.extent.height = 1;
16536 image_create_info.extent.depth = 1;
16537 image_create_info.mipLevels = 1;
16538 image_create_info.arrayLayers = 1;
16539 image_create_info.samples = VK_SAMPLE_COUNT_2_BIT;
16540 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
16541 // Note: Some implementations expect color attachment usage for any
16542 // multisample surface
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016543 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
Karl Schultz6addd812016-02-02 17:17:23 -070016544 image_create_info.flags = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060016545
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016546 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
Mike Stroyana3082432015-09-25 13:39:21 -060016547 ASSERT_VK_SUCCESS(err);
16548
Karl Schultz6addd812016-02-02 17:17:23 -070016549 // Set format to something other than source image
16550 image_create_info.format = VK_FORMAT_R32_SFLOAT;
16551 // Note: Some implementations expect color attachment usage for any
16552 // multisample surface
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016553 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
Karl Schultz6addd812016-02-02 17:17:23 -070016554 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060016555
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016556 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
Mike Stroyana3082432015-09-25 13:39:21 -060016557 ASSERT_VK_SUCCESS(err);
16558
16559 // Allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016560 VkMemoryAllocateInfo memAlloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -070016561 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
16562 memAlloc.pNext = NULL;
16563 memAlloc.allocationSize = 0;
16564 memAlloc.memoryTypeIndex = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060016565
Courtney Goeltzenleuchter06d89472015-10-20 16:40:38 -060016566 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060016567 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016568 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060016569 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016570 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
Mike Stroyana3082432015-09-25 13:39:21 -060016571 ASSERT_VK_SUCCESS(err);
16572
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016573 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060016574 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016575 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060016576 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016577 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
Mike Stroyana3082432015-09-25 13:39:21 -060016578 ASSERT_VK_SUCCESS(err);
16579
16580 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
16581 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016582 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
Mike Stroyana3082432015-09-25 13:39:21 -060016583 ASSERT_VK_SUCCESS(err);
16584
16585 BeginCommandBuffer();
16586 // Need memory barrier to VK_IMAGE_LAYOUT_GENERAL for source and dest?
Karl Schultz6addd812016-02-02 17:17:23 -070016587 // VK_IMAGE_LAYOUT_UNDEFINED = 0,
16588 // VK_IMAGE_LAYOUT_GENERAL = 1,
Mike Stroyana3082432015-09-25 13:39:21 -060016589 VkImageResolve resolveRegion;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080016590 resolveRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060016591 resolveRegion.srcSubresource.mipLevel = 0;
Courtney Goeltzenleuchter8367ce02015-10-16 09:46:00 -060016592 resolveRegion.srcSubresource.baseArrayLayer = 0;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016593 resolveRegion.srcSubresource.layerCount = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060016594 resolveRegion.srcOffset.x = 0;
16595 resolveRegion.srcOffset.y = 0;
16596 resolveRegion.srcOffset.z = 0;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080016597 resolveRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016598 resolveRegion.dstSubresource.mipLevel = 0;
16599 resolveRegion.dstSubresource.baseArrayLayer = 0;
16600 resolveRegion.dstSubresource.layerCount = 0;
16601 resolveRegion.dstOffset.x = 0;
16602 resolveRegion.dstOffset.y = 0;
16603 resolveRegion.dstOffset.z = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060016604 resolveRegion.extent.width = 1;
16605 resolveRegion.extent.height = 1;
16606 resolveRegion.extent.depth = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016607 m_commandBuffer->ResolveImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, VK_IMAGE_LAYOUT_GENERAL, 1, &resolveRegion);
Mike Stroyana3082432015-09-25 13:39:21 -060016608 EndCommandBuffer();
16609
Chris Forbes8f36a8a2016-04-07 13:21:07 +120016610 m_errorMonitor->VerifyFound();
Mike Stroyana3082432015-09-25 13:39:21 -060016611
Chia-I Wuf7458c52015-10-26 21:10:41 +080016612 vkDestroyImage(m_device->device(), srcImage, NULL);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016613 vkDestroyImage(m_device->device(), dstImage, NULL);
Chia-I Wuf7458c52015-10-26 21:10:41 +080016614 vkFreeMemory(m_device->device(), srcMem, NULL);
16615 vkFreeMemory(m_device->device(), destMem, NULL);
Mike Stroyana3082432015-09-25 13:39:21 -060016616}
16617
Karl Schultz6addd812016-02-02 17:17:23 -070016618TEST_F(VkLayerTest, ResolveImageTypeMismatch) {
16619 VkResult err;
16620 bool pass;
Mike Stroyana3082432015-09-25 13:39:21 -060016621
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016622 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
16623 "vkCmdResolveImage called with unmatched source and dest image types.");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060016624
Mike Stroyana3082432015-09-25 13:39:21 -060016625 ASSERT_NO_FATAL_FAILURE(InitState());
Mike Stroyana3082432015-09-25 13:39:21 -060016626
16627 // Create two images of different types and try to copy between them
Karl Schultz6addd812016-02-02 17:17:23 -070016628 VkImage srcImage;
16629 VkImage dstImage;
16630 VkDeviceMemory srcMem;
16631 VkDeviceMemory destMem;
16632 VkMemoryRequirements memReqs;
Mike Stroyana3082432015-09-25 13:39:21 -060016633
16634 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070016635 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
16636 image_create_info.pNext = NULL;
16637 image_create_info.imageType = VK_IMAGE_TYPE_2D;
16638 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
16639 image_create_info.extent.width = 32;
16640 image_create_info.extent.height = 1;
16641 image_create_info.extent.depth = 1;
16642 image_create_info.mipLevels = 1;
16643 image_create_info.arrayLayers = 1;
16644 image_create_info.samples = VK_SAMPLE_COUNT_2_BIT;
16645 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
16646 // Note: Some implementations expect color attachment usage for any
16647 // multisample surface
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016648 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
Karl Schultz6addd812016-02-02 17:17:23 -070016649 image_create_info.flags = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060016650
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016651 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
Mike Stroyana3082432015-09-25 13:39:21 -060016652 ASSERT_VK_SUCCESS(err);
16653
Karl Schultz6addd812016-02-02 17:17:23 -070016654 image_create_info.imageType = VK_IMAGE_TYPE_1D;
16655 // Note: Some implementations expect color attachment usage for any
16656 // multisample surface
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016657 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
Karl Schultz6addd812016-02-02 17:17:23 -070016658 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060016659
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016660 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
Mike Stroyana3082432015-09-25 13:39:21 -060016661 ASSERT_VK_SUCCESS(err);
16662
16663 // Allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016664 VkMemoryAllocateInfo memAlloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -070016665 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
16666 memAlloc.pNext = NULL;
16667 memAlloc.allocationSize = 0;
16668 memAlloc.memoryTypeIndex = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060016669
Courtney Goeltzenleuchter06d89472015-10-20 16:40:38 -060016670 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060016671 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016672 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060016673 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016674 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
Mike Stroyana3082432015-09-25 13:39:21 -060016675 ASSERT_VK_SUCCESS(err);
16676
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016677 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060016678 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016679 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060016680 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016681 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
Mike Stroyana3082432015-09-25 13:39:21 -060016682 ASSERT_VK_SUCCESS(err);
16683
16684 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
16685 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016686 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
Mike Stroyana3082432015-09-25 13:39:21 -060016687 ASSERT_VK_SUCCESS(err);
16688
16689 BeginCommandBuffer();
16690 // Need memory barrier to VK_IMAGE_LAYOUT_GENERAL for source and dest?
Karl Schultz6addd812016-02-02 17:17:23 -070016691 // VK_IMAGE_LAYOUT_UNDEFINED = 0,
16692 // VK_IMAGE_LAYOUT_GENERAL = 1,
Mike Stroyana3082432015-09-25 13:39:21 -060016693 VkImageResolve resolveRegion;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080016694 resolveRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060016695 resolveRegion.srcSubresource.mipLevel = 0;
Courtney Goeltzenleuchter8367ce02015-10-16 09:46:00 -060016696 resolveRegion.srcSubresource.baseArrayLayer = 0;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016697 resolveRegion.srcSubresource.layerCount = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060016698 resolveRegion.srcOffset.x = 0;
16699 resolveRegion.srcOffset.y = 0;
16700 resolveRegion.srcOffset.z = 0;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080016701 resolveRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016702 resolveRegion.dstSubresource.mipLevel = 0;
16703 resolveRegion.dstSubresource.baseArrayLayer = 0;
16704 resolveRegion.dstSubresource.layerCount = 0;
16705 resolveRegion.dstOffset.x = 0;
16706 resolveRegion.dstOffset.y = 0;
16707 resolveRegion.dstOffset.z = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060016708 resolveRegion.extent.width = 1;
16709 resolveRegion.extent.height = 1;
16710 resolveRegion.extent.depth = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016711 m_commandBuffer->ResolveImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, VK_IMAGE_LAYOUT_GENERAL, 1, &resolveRegion);
Mike Stroyana3082432015-09-25 13:39:21 -060016712 EndCommandBuffer();
16713
Chris Forbes8f36a8a2016-04-07 13:21:07 +120016714 m_errorMonitor->VerifyFound();
Mike Stroyana3082432015-09-25 13:39:21 -060016715
Chia-I Wuf7458c52015-10-26 21:10:41 +080016716 vkDestroyImage(m_device->device(), srcImage, NULL);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016717 vkDestroyImage(m_device->device(), dstImage, NULL);
Chia-I Wuf7458c52015-10-26 21:10:41 +080016718 vkFreeMemory(m_device->device(), srcMem, NULL);
16719 vkFreeMemory(m_device->device(), destMem, NULL);
Mike Stroyana3082432015-09-25 13:39:21 -060016720}
Tobin Ehlisa1c28562015-10-23 16:00:08 -060016721
Karl Schultz6addd812016-02-02 17:17:23 -070016722TEST_F(VkLayerTest, DepthStencilImageViewWithColorAspectBitError) {
Tobin Ehlisa1c28562015-10-23 16:00:08 -060016723 // Create a single Image descriptor and cause it to first hit an error due
Karl Schultz6addd812016-02-02 17:17:23 -070016724 // to using a DS format, then cause it to hit error due to COLOR_BIT not
16725 // set in aspect
Tobin Ehlisa1c28562015-10-23 16:00:08 -060016726 // The image format check comes 2nd in validation so we trigger it first,
16727 // then when we cause aspect fail next, bad format check will be preempted
Karl Schultz6addd812016-02-02 17:17:23 -070016728 VkResult err;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060016729
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016730 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
16731 "Combination depth/stencil image formats can have only the ");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060016732
Tobin Ehlisa1c28562015-10-23 16:00:08 -060016733 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060016734
Chia-I Wu1b99bb22015-10-27 19:25:11 +080016735 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -070016736 ds_type_count.type = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE;
16737 ds_type_count.descriptorCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060016738
16739 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070016740 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
16741 ds_pool_ci.pNext = NULL;
16742 ds_pool_ci.maxSets = 1;
16743 ds_pool_ci.poolSizeCount = 1;
16744 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060016745
16746 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016747 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060016748 ASSERT_VK_SUCCESS(err);
16749
16750 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -070016751 dsl_binding.binding = 0;
16752 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE;
16753 dsl_binding.descriptorCount = 1;
16754 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
16755 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060016756
16757 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070016758 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
16759 ds_layout_ci.pNext = NULL;
16760 ds_layout_ci.bindingCount = 1;
16761 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060016762 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016763 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060016764 ASSERT_VK_SUCCESS(err);
16765
16766 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016767 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +080016768 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -070016769 alloc_info.descriptorSetCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060016770 alloc_info.descriptorPool = ds_pool;
16771 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016772 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060016773 ASSERT_VK_SUCCESS(err);
16774
Karl Schultz6addd812016-02-02 17:17:23 -070016775 VkImage image_bad;
16776 VkImage image_good;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060016777 // One bad format and one good format for Color attachment
Tobin Ehlis269f0322016-05-25 16:24:21 -060016778 const VkFormat tex_format_bad = VK_FORMAT_D24_UNORM_S8_UINT;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060016779 const VkFormat tex_format_good = VK_FORMAT_B8G8R8A8_UNORM;
Karl Schultz6addd812016-02-02 17:17:23 -070016780 const int32_t tex_width = 32;
16781 const int32_t tex_height = 32;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060016782
16783 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070016784 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
16785 image_create_info.pNext = NULL;
16786 image_create_info.imageType = VK_IMAGE_TYPE_2D;
16787 image_create_info.format = tex_format_bad;
16788 image_create_info.extent.width = tex_width;
16789 image_create_info.extent.height = tex_height;
16790 image_create_info.extent.depth = 1;
16791 image_create_info.mipLevels = 1;
16792 image_create_info.arrayLayers = 1;
16793 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
16794 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016795 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT | VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT;
Karl Schultz6addd812016-02-02 17:17:23 -070016796 image_create_info.flags = 0;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060016797
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016798 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image_bad);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060016799 ASSERT_VK_SUCCESS(err);
16800 image_create_info.format = tex_format_good;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016801 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
16802 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image_good);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060016803 ASSERT_VK_SUCCESS(err);
16804
16805 VkImageViewCreateInfo image_view_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070016806 image_view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
16807 image_view_create_info.image = image_bad;
16808 image_view_create_info.viewType = VK_IMAGE_VIEW_TYPE_2D;
16809 image_view_create_info.format = tex_format_bad;
16810 image_view_create_info.subresourceRange.baseArrayLayer = 0;
16811 image_view_create_info.subresourceRange.baseMipLevel = 0;
16812 image_view_create_info.subresourceRange.layerCount = 1;
16813 image_view_create_info.subresourceRange.levelCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016814 image_view_create_info.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060016815
16816 VkImageView view;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016817 err = vkCreateImageView(m_device->device(), &image_view_create_info, NULL, &view);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060016818
Chris Forbes8f36a8a2016-04-07 13:21:07 +120016819 m_errorMonitor->VerifyFound();
Tobin Ehlisa1c28562015-10-23 16:00:08 -060016820
Chia-I Wuf7458c52015-10-26 21:10:41 +080016821 vkDestroyImage(m_device->device(), image_bad, NULL);
16822 vkDestroyImage(m_device->device(), image_good, NULL);
Chia-I Wuf7458c52015-10-26 21:10:41 +080016823 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
16824 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060016825}
Tobin Ehlis6e23d772016-05-19 11:08:34 -060016826
16827TEST_F(VkLayerTest, ClearImageErrors) {
16828 TEST_DESCRIPTION("Call ClearColorImage w/ a depth|stencil image and "
16829 "ClearDepthStencilImage with a color image.");
16830
16831 ASSERT_NO_FATAL_FAILURE(InitState());
16832 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
16833
16834 // Renderpass is started here so end it as Clear cmds can't be in renderpass
16835 BeginCommandBuffer();
16836 m_commandBuffer->EndRenderPass();
16837
16838 // Color image
16839 VkClearColorValue clear_color;
16840 memset(clear_color.uint32, 0, sizeof(uint32_t) * 4);
16841 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
16842 const VkFormat color_format = VK_FORMAT_B8G8R8A8_UNORM;
16843 const int32_t img_width = 32;
16844 const int32_t img_height = 32;
16845 VkImageCreateInfo image_create_info = {};
16846 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
16847 image_create_info.pNext = NULL;
16848 image_create_info.imageType = VK_IMAGE_TYPE_2D;
16849 image_create_info.format = color_format;
16850 image_create_info.extent.width = img_width;
16851 image_create_info.extent.height = img_height;
16852 image_create_info.extent.depth = 1;
16853 image_create_info.mipLevels = 1;
16854 image_create_info.arrayLayers = 1;
16855 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
16856 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
16857 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
16858
16859 vk_testing::Image color_image;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016860 color_image.init(*m_device, (const VkImageCreateInfo &)image_create_info, reqs);
Tobin Ehlis6e23d772016-05-19 11:08:34 -060016861
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016862 const VkImageSubresourceRange color_range = vk_testing::Image::subresource_range(image_create_info, VK_IMAGE_ASPECT_COLOR_BIT);
Tobin Ehlis6e23d772016-05-19 11:08:34 -060016863
16864 // Depth/Stencil image
16865 VkClearDepthStencilValue clear_value = {0};
16866 reqs = 0; // don't need HOST_VISIBLE DS image
16867 VkImageCreateInfo ds_image_create_info = vk_testing::Image::create_info();
16868 ds_image_create_info.imageType = VK_IMAGE_TYPE_2D;
16869 ds_image_create_info.format = VK_FORMAT_D24_UNORM_S8_UINT;
16870 ds_image_create_info.extent.width = 64;
16871 ds_image_create_info.extent.height = 64;
16872 ds_image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
16873 ds_image_create_info.usage = VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT;
16874
16875 vk_testing::Image ds_image;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016876 ds_image.init(*m_device, (const VkImageCreateInfo &)ds_image_create_info, reqs);
Tobin Ehlis6e23d772016-05-19 11:08:34 -060016877
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016878 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 -060016879
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016880 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "vkCmdClearColorImage called with depth/stencil image.");
Tobin Ehlis6e23d772016-05-19 11:08:34 -060016881
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016882 vkCmdClearColorImage(m_commandBuffer->GetBufferHandle(), ds_image.handle(), VK_IMAGE_LAYOUT_GENERAL, &clear_color, 1,
Tobin Ehlis6e23d772016-05-19 11:08:34 -060016883 &color_range);
16884
16885 m_errorMonitor->VerifyFound();
16886
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016887 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "vkCmdClearColorImage called with "
16888 "image created without "
16889 "VK_IMAGE_USAGE_TRANSFER_DST_BIT");
Tony Barbour26434b92016-06-02 09:43:50 -060016890
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016891 vkCmdClearColorImage(m_commandBuffer->GetBufferHandle(), ds_image.handle(), VK_IMAGE_LAYOUT_GENERAL, &clear_color, 1,
Tony Barbour26434b92016-06-02 09:43:50 -060016892 &color_range);
16893
16894 m_errorMonitor->VerifyFound();
16895
Tobin Ehlis6e23d772016-05-19 11:08:34 -060016896 // Call CmdClearDepthStencilImage with color image
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016897 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
16898 "vkCmdClearDepthStencilImage called without a depth/stencil image.");
Tobin Ehlis6e23d772016-05-19 11:08:34 -060016899
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016900 vkCmdClearDepthStencilImage(m_commandBuffer->GetBufferHandle(), color_image.handle(),
16901 VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL, &clear_value, 1, &ds_range);
Tobin Ehlis6e23d772016-05-19 11:08:34 -060016902
16903 m_errorMonitor->VerifyFound();
16904}
Tobin Ehliscde08892015-09-22 10:11:37 -060016905#endif // IMAGE_TESTS
16906
Cody Northrop1242dfd2016-07-13 17:24:59 -060016907#if defined(ANDROID) && defined(VALIDATION_APK)
16908static bool initialized = false;
16909static bool active = false;
16910
16911// Convert Intents to argv
16912// Ported from Hologram sample, only difference is flexible key
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016913std::vector<std::string> get_args(android_app &app, const char *intent_extra_data_key) {
Cody Northrop1242dfd2016-07-13 17:24:59 -060016914 std::vector<std::string> args;
16915 JavaVM &vm = *app.activity->vm;
16916 JNIEnv *p_env;
16917 if (vm.AttachCurrentThread(&p_env, nullptr) != JNI_OK)
16918 return args;
16919
16920 JNIEnv &env = *p_env;
16921 jobject activity = app.activity->clazz;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016922 jmethodID get_intent_method = env.GetMethodID(env.GetObjectClass(activity), "getIntent", "()Landroid/content/Intent;");
Cody Northrop1242dfd2016-07-13 17:24:59 -060016923 jobject intent = env.CallObjectMethod(activity, get_intent_method);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016924 jmethodID get_string_extra_method =
16925 env.GetMethodID(env.GetObjectClass(intent), "getStringExtra", "(Ljava/lang/String;)Ljava/lang/String;");
Cody Northrop1242dfd2016-07-13 17:24:59 -060016926 jvalue get_string_extra_args;
16927 get_string_extra_args.l = env.NewStringUTF(intent_extra_data_key);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016928 jstring extra_str = static_cast<jstring>(env.CallObjectMethodA(intent, get_string_extra_method, &get_string_extra_args));
Cody Northrop1242dfd2016-07-13 17:24:59 -060016929
16930 std::string args_str;
16931 if (extra_str) {
16932 const char *extra_utf = env.GetStringUTFChars(extra_str, nullptr);
16933 args_str = extra_utf;
16934 env.ReleaseStringUTFChars(extra_str, extra_utf);
16935 env.DeleteLocalRef(extra_str);
16936 }
16937
16938 env.DeleteLocalRef(get_string_extra_args.l);
16939 env.DeleteLocalRef(intent);
16940 vm.DetachCurrentThread();
16941
16942 // split args_str
16943 std::stringstream ss(args_str);
16944 std::string arg;
16945 while (std::getline(ss, arg, ' ')) {
16946 if (!arg.empty())
16947 args.push_back(arg);
16948 }
16949
16950 return args;
16951}
16952
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016953static int32_t processInput(struct android_app *app, AInputEvent *event) { return 0; }
Cody Northrop1242dfd2016-07-13 17:24:59 -060016954
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016955static void processCommand(struct android_app *app, int32_t cmd) {
16956 switch (cmd) {
16957 case APP_CMD_INIT_WINDOW: {
16958 if (app->window) {
16959 initialized = true;
Cody Northrop1242dfd2016-07-13 17:24:59 -060016960 }
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016961 break;
16962 }
16963 case APP_CMD_GAINED_FOCUS: {
16964 active = true;
16965 break;
16966 }
16967 case APP_CMD_LOST_FOCUS: {
16968 active = false;
16969 break;
16970 }
Cody Northrop1242dfd2016-07-13 17:24:59 -060016971 }
16972}
16973
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016974void android_main(struct android_app *app) {
Cody Northrop1242dfd2016-07-13 17:24:59 -060016975 app_dummy();
16976
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016977 const char *appTag = "VulkanLayerValidationTests";
Cody Northrop1242dfd2016-07-13 17:24:59 -060016978
16979 int vulkanSupport = InitVulkan();
16980 if (vulkanSupport == 0) {
16981 __android_log_print(ANDROID_LOG_INFO, appTag, "==== FAILED ==== No Vulkan support found");
16982 return;
16983 }
16984
16985 app->onAppCmd = processCommand;
16986 app->onInputEvent = processInput;
16987
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016988 while (1) {
Cody Northrop1242dfd2016-07-13 17:24:59 -060016989 int events;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016990 struct android_poll_source *source;
16991 while (ALooper_pollAll(active ? 0 : -1, NULL, &events, (void **)&source) >= 0) {
Cody Northrop1242dfd2016-07-13 17:24:59 -060016992 if (source) {
16993 source->process(app, source);
16994 }
16995
16996 if (app->destroyRequested != 0) {
16997 VkTestFramework::Finish();
16998 return;
16999 }
17000 }
17001
17002 if (initialized && active) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017003 // Use the following key to send arguments to gtest, i.e.
17004 // --es args "--gtest_filter=-VkLayerTest.foo"
17005 const char key[] = "args";
17006 std::vector<std::string> args = get_args(*app, key);
Cody Northrop1242dfd2016-07-13 17:24:59 -060017007
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017008 std::string filter = "";
17009 if (args.size() > 0) {
17010 __android_log_print(ANDROID_LOG_INFO, appTag, "Intent args = %s", args[0].c_str());
17011 filter += args[0];
17012 } else {
17013 __android_log_print(ANDROID_LOG_INFO, appTag, "No Intent args detected");
17014 }
Cody Northrop1242dfd2016-07-13 17:24:59 -060017015
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017016 int argc = 2;
17017 char *argv[] = {(char *)"foo", (char *)filter.c_str()};
17018 __android_log_print(ANDROID_LOG_DEBUG, appTag, "filter = %s", argv[1]);
Cody Northrop1242dfd2016-07-13 17:24:59 -060017019
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017020 // Route output to files until we can override the gtest output
17021 freopen("/sdcard/Android/data/com.example.VulkanLayerValidationTests/files/out.txt", "w", stdout);
17022 freopen("/sdcard/Android/data/com.example.VulkanLayerValidationTests/files/err.txt", "w", stderr);
Cody Northrop1242dfd2016-07-13 17:24:59 -060017023
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017024 ::testing::InitGoogleTest(&argc, argv);
17025 VkTestFramework::InitArgs(&argc, argv);
17026 ::testing::AddGlobalTestEnvironment(new TestEnvironment);
Cody Northrop1242dfd2016-07-13 17:24:59 -060017027
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017028 int result = RUN_ALL_TESTS();
Cody Northrop1242dfd2016-07-13 17:24:59 -060017029
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017030 if (result != 0) {
17031 __android_log_print(ANDROID_LOG_INFO, appTag, "==== Tests FAILED ====");
17032 } else {
17033 __android_log_print(ANDROID_LOG_INFO, appTag, "==== Tests PASSED ====");
17034 }
Cody Northrop1242dfd2016-07-13 17:24:59 -060017035
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017036 VkTestFramework::Finish();
Cody Northrop1242dfd2016-07-13 17:24:59 -060017037
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017038 fclose(stdout);
17039 fclose(stderr);
Cody Northrop1242dfd2016-07-13 17:24:59 -060017040
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017041 ANativeActivity_finish(app->activity);
Cody Northrop1242dfd2016-07-13 17:24:59 -060017042
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017043 return;
Cody Northrop1242dfd2016-07-13 17:24:59 -060017044 }
17045 }
17046}
17047#endif
17048
Tony Barbour300a6082015-04-07 13:44:53 -060017049int main(int argc, char **argv) {
17050 int result;
17051
Cody Northrop8e54a402016-03-08 22:25:52 -070017052#ifdef ANDROID
17053 int vulkanSupport = InitVulkan();
17054 if (vulkanSupport == 0)
17055 return 1;
17056#endif
17057
Tony Barbour300a6082015-04-07 13:44:53 -060017058 ::testing::InitGoogleTest(&argc, argv);
Tony Barbour6918cd52015-04-09 12:58:51 -060017059 VkTestFramework::InitArgs(&argc, argv);
Tony Barbour300a6082015-04-07 13:44:53 -060017060
17061 ::testing::AddGlobalTestEnvironment(new TestEnvironment);
17062
17063 result = RUN_ALL_TESTS();
17064
Tony Barbour6918cd52015-04-09 12:58:51 -060017065 VkTestFramework::Finish();
Tony Barbour300a6082015-04-07 13:44:53 -060017066 return result;
17067}