blob: bee23b0e96f9fdf0ce0e0ba8196737da6da0be1e [file] [log] [blame]
Karl Schultz6addd812016-02-02 17:17:23 -07001/*
2 * Copyright (c) 2015-2016 The Khronos Group Inc.
3 * Copyright (c) 2015-2016 Valve Corporation
4 * Copyright (c) 2015-2016 LunarG, Inc.
Michael Lentine0a369f62016-02-03 16:51:46 -06005 * Copyright (c) 2015-2016 Google, Inc.
Karl Schultz6addd812016-02-02 17:17:23 -07006 *
Jon Ashburn3ebf1252016-04-19 11:30:31 -06007 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
Karl Schultz6addd812016-02-02 17:17:23 -070010 *
Jon Ashburn3ebf1252016-04-19 11:30:31 -060011 * http://www.apache.org/licenses/LICENSE-2.0
Karl Schultz6addd812016-02-02 17:17:23 -070012 *
13 * Author: Chia-I Wu <olvaffe@gmail.com>
14 * Author: Chris Forbes <chrisf@ijw.co.nz>
15 * Author: Courtney Goeltzenleuchter <courtney@LunarG.com>
16 * Author: Mark Lobodzinski <mark@lunarg.com>
17 * Author: Mike Stroyan <mike@LunarG.com>
18 * Author: Tobin Ehlis <tobine@google.com>
19 * Author: Tony Barbour <tony@LunarG.com>
Cody Northrop1242dfd2016-07-13 17:24:59 -060020 * Author: Cody Northrop <cnorthrop@google.com>
Karl Schultz6addd812016-02-02 17:17:23 -070021 */
Tony Barbour65c48b32015-11-17 10:02:56 -070022
Cody Northrop8e54a402016-03-08 22:25:52 -070023#ifdef ANDROID
24#include "vulkan_wrapper.h"
25#else
David Pinedo9316d3b2015-11-06 12:54:48 -070026#include <vulkan/vulkan.h>
Cody Northrop8e54a402016-03-08 22:25:52 -070027#endif
Cody Northrop1242dfd2016-07-13 17:24:59 -060028
29#if defined(ANDROID) && defined(VALIDATION_APK)
30#include <android/log.h>
31#include <android_native_app_glue.h>
32#endif
33
Jon Ashburn7fa7e222016-02-02 12:08:10 -070034#include "icd-spv.h"
Mark Lobodzinskice751c62016-09-08 10:45:35 -060035#include "test_common.h"
36#include "vk_layer_config.h"
37#include "vkrenderframework.h"
Tony Barbour300a6082015-04-07 13:44:53 -060038
Mark Lobodzinski3780e142015-05-14 15:08:13 -050039#define GLM_FORCE_RADIANS
40#include "glm/glm.hpp"
41#include <glm/gtc/matrix_transform.hpp>
42
Dustin Gravesffa90fa2016-05-06 11:20:38 -060043#define PARAMETER_VALIDATION_TESTS 1
Tobin Ehlis0788f522015-05-26 16:11:58 -060044#define MEM_TRACKER_TESTS 1
45#define OBJ_TRACKER_TESTS 1
46#define DRAW_STATE_TESTS 1
47#define THREADING_TESTS 1
Chris Forbes9f7ff632015-05-25 11:13:08 +120048#define SHADER_CHECKER_TESTS 1
Mark Lobodzinski209b5292015-09-17 09:44:05 -060049#define DEVICE_LIMITS_TESTS 1
Tobin Ehliscde08892015-09-22 10:11:37 -060050#define IMAGE_TESTS 1
Tobin Ehlis0788f522015-05-26 16:11:58 -060051
Mark Lobodzinski3780e142015-05-14 15:08:13 -050052//--------------------------------------------------------------------------------------
53// Mesh and VertexFormat Data
54//--------------------------------------------------------------------------------------
Karl Schultz6addd812016-02-02 17:17:23 -070055struct Vertex {
56 float posX, posY, posZ, posW; // Position data
57 float r, g, b, a; // Color
Mark Lobodzinski3780e142015-05-14 15:08:13 -050058};
59
Karl Schultz6addd812016-02-02 17:17:23 -070060#define XYZ1(_x_, _y_, _z_) (_x_), (_y_), (_z_), 1.f
Mark Lobodzinski3780e142015-05-14 15:08:13 -050061
62typedef enum _BsoFailSelect {
Karl Schultz6addd812016-02-02 17:17:23 -070063 BsoFailNone = 0x00000000,
64 BsoFailLineWidth = 0x00000001,
65 BsoFailDepthBias = 0x00000002,
66 BsoFailViewport = 0x00000004,
67 BsoFailScissor = 0x00000008,
68 BsoFailBlend = 0x00000010,
69 BsoFailDepthBounds = 0x00000020,
70 BsoFailStencilReadMask = 0x00000040,
71 BsoFailStencilWriteMask = 0x00000080,
72 BsoFailStencilReference = 0x00000100,
Mark Muellerd4914412016-06-13 17:52:06 -060073 BsoFailCmdClearAttachments = 0x00000200,
Tobin Ehlis379ba3b2016-07-19 11:22:29 -060074 BsoFailIndexBuffer = 0x00000400,
Mark Lobodzinski3780e142015-05-14 15:08:13 -050075} BsoFailSelect;
76
77struct vktriangle_vs_uniform {
78 // Must start with MVP
Karl Schultz6addd812016-02-02 17:17:23 -070079 float mvp[4][4];
80 float position[3][4];
81 float color[3][4];
Mark Lobodzinski3780e142015-05-14 15:08:13 -050082};
83
Mark Lobodzinskice751c62016-09-08 10:45:35 -060084static const char bindStateVertShaderText[] = "#version 450\n"
85 "vec2 vertices[3];\n"
86 "out gl_PerVertex {\n"
87 " vec4 gl_Position;\n"
88 "};\n"
89 "void main() {\n"
90 " vertices[0] = vec2(-1.0, -1.0);\n"
91 " vertices[1] = vec2( 1.0, -1.0);\n"
92 " vertices[2] = vec2( 0.0, 1.0);\n"
93 " gl_Position = vec4(vertices[gl_VertexIndex % 3], 0.0, 1.0);\n"
94 "}\n";
Mark Lobodzinski3780e142015-05-14 15:08:13 -050095
Mark Lobodzinskice751c62016-09-08 10:45:35 -060096static const char bindStateFragShaderText[] = "#version 450\n"
97 "\n"
98 "layout(location = 0) out vec4 uFragColor;\n"
99 "void main(){\n"
100 " uFragColor = vec4(0,1,0,1);\n"
101 "}\n";
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500102
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600103static VKAPI_ATTR VkBool32 VKAPI_CALL myDbgFunc(VkFlags msgFlags, VkDebugReportObjectTypeEXT objType, uint64_t srcObject,
104 size_t location, int32_t msgCode, const char *pLayerPrefix, const char *pMsg,
105 void *pUserData);
Mark Lobodzinski7a588452016-08-03 14:04:26 -0600106
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600107// ********************************************************
108// ErrorMonitor Usage:
109//
110// Call SetDesiredFailureMsg with a string to be compared against all
111// encountered log messages. Passing NULL will match all log messages.
112// logMsg will return true for skipCall only if msg is matched or NULL.
113//
114// Call DesiredMsgFound to determine if the desired failure message
115// was encountered.
116
Tony Barbour300a6082015-04-07 13:44:53 -0600117class ErrorMonitor {
Karl Schultz6addd812016-02-02 17:17:23 -0700118 public:
119 ErrorMonitor() {
Mike Stroyan4268d1f2015-07-13 14:45:35 -0600120 test_platform_thread_create_mutex(&m_mutex);
121 test_platform_thread_lock_mutex(&m_mutex);
Chris Forbes17756132016-09-16 14:36:39 +1200122 m_msgFlags = VK_DEBUG_REPORT_ERROR_BIT_EXT;
Karl Schultz6addd812016-02-02 17:17:23 -0700123 m_bailout = NULL;
Chris Forbes17756132016-09-16 14:36:39 +1200124 m_desiredMsgSet = false;
Mike Stroyan4268d1f2015-07-13 14:45:35 -0600125 test_platform_thread_unlock_mutex(&m_mutex);
Tony Barbour300a6082015-04-07 13:44:53 -0600126 }
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600127
Dustin Graves48458142016-04-29 16:11:55 -0600128 ~ErrorMonitor() { test_platform_thread_delete_mutex(&m_mutex); }
129
Karl Schultz6addd812016-02-02 17:17:23 -0700130 void SetDesiredFailureMsg(VkFlags msgFlags, const char *msgString) {
Chris Forbes8f36a8a2016-04-07 13:21:07 +1200131 // also discard all collected messages to this point
Mike Stroyan4268d1f2015-07-13 14:45:35 -0600132 test_platform_thread_lock_mutex(&m_mutex);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600133 m_failureMsg.clear();
134 m_otherMsgs.clear();
135 m_desiredMsg = msgString;
Karl Schultz6addd812016-02-02 17:17:23 -0700136 m_msgFound = VK_FALSE;
137 m_msgFlags = msgFlags;
Chris Forbes17756132016-09-16 14:36:39 +1200138 m_desiredMsgSet = true;
Mike Stroyan4268d1f2015-07-13 14:45:35 -0600139 test_platform_thread_unlock_mutex(&m_mutex);
Tony Barbour300a6082015-04-07 13:44:53 -0600140 }
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600141
Mark Lobodzinski7a588452016-08-03 14:04:26 -0600142 VkBool32 CheckForDesiredMsg(const char *msgString) {
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600143 VkBool32 result = VK_FALSE;
Mike Stroyan4268d1f2015-07-13 14:45:35 -0600144 test_platform_thread_lock_mutex(&m_mutex);
Mike Stroyanaccf7692015-05-12 16:00:45 -0600145 if (m_bailout != NULL) {
146 *m_bailout = true;
147 }
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600148 string errorString(msgString);
Chris Forbes17756132016-09-16 14:36:39 +1200149 if (m_desiredMsgSet && errorString.find(m_desiredMsg) != string::npos) {
Mark Lobodzinski7a588452016-08-03 14:04:26 -0600150 if (m_msgFound) { // If multiple matches, don't lose all but the last!
151 m_otherMsgs.push_back(m_failureMsg);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600152 }
Mark Lobodzinski7a588452016-08-03 14:04:26 -0600153 m_failureMsg = errorString;
154 m_msgFound = VK_TRUE;
155 result = VK_TRUE;
156 } else {
Chris Forbes5b9442b2016-09-13 16:49:57 +1200157 printf("Unexpected: %s\n", msgString);
Mark Lobodzinski7a588452016-08-03 14:04:26 -0600158 m_otherMsgs.push_back(errorString);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600159 }
Mike Stroyan4268d1f2015-07-13 14:45:35 -0600160 test_platform_thread_unlock_mutex(&m_mutex);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600161 return result;
Mike Stroyanaccf7692015-05-12 16:00:45 -0600162 }
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600163
Karl Schultz6addd812016-02-02 17:17:23 -0700164 vector<string> GetOtherFailureMsgs(void) { return m_otherMsgs; }
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600165
Karl Schultz6addd812016-02-02 17:17:23 -0700166 string GetFailureMsg(void) { return m_failureMsg; }
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600167
Mark Lobodzinski7a588452016-08-03 14:04:26 -0600168 VkDebugReportFlagsEXT GetMessageFlags(void) { return m_msgFlags; }
169
Karl Schultz6addd812016-02-02 17:17:23 -0700170 VkBool32 DesiredMsgFound(void) { return m_msgFound; }
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600171
Karl Schultz6addd812016-02-02 17:17:23 -0700172 void SetBailout(bool *bailout) { m_bailout = bailout; }
Tony Barbour300a6082015-04-07 13:44:53 -0600173
Karl Schultz6addd812016-02-02 17:17:23 -0700174 void DumpFailureMsgs(void) {
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600175 vector<string> otherMsgs = GetOtherFailureMsgs();
176 cout << "Other error messages logged for this test were:" << endl;
177 for (auto iter = otherMsgs.begin(); iter != otherMsgs.end(); iter++) {
178 cout << " " << *iter << endl;
179 }
180 }
181
Mark Lobodzinski7a588452016-08-03 14:04:26 -0600182 // Helpers
Chris Forbes8f36a8a2016-04-07 13:21:07 +1200183
Mark Lobodzinski7a588452016-08-03 14:04:26 -0600184 // ExpectSuccess now takes an optional argument allowing a custom combination of debug flags
185 void ExpectSuccess(VkDebugReportFlagsEXT message_flag_mask = VK_DEBUG_REPORT_ERROR_BIT_EXT) {
186 m_msgFlags = message_flag_mask;
187 // Match ANY message matching specified type
188 SetDesiredFailureMsg(message_flag_mask, "");
Chris Forbes8f36a8a2016-04-07 13:21:07 +1200189 }
190
191 void VerifyFound() {
192 // Not seeing the desired message is a failure. /Before/ throwing, dump
193 // any other messages.
194 if (!DesiredMsgFound()) {
195 DumpFailureMsgs();
196 FAIL() << "Did not receive expected error '" << m_desiredMsg << "'";
197 }
198 }
199
200 void VerifyNotFound() {
201 // ExpectSuccess() configured us to match anything. Any error is a
202 // failure.
203 if (DesiredMsgFound()) {
204 DumpFailureMsgs();
205 FAIL() << "Expected to succeed but got error: " << GetFailureMsg();
206 }
207 }
208
Karl Schultz6addd812016-02-02 17:17:23 -0700209 private:
210 VkFlags m_msgFlags;
211 string m_desiredMsg;
212 string m_failureMsg;
213 vector<string> m_otherMsgs;
Mike Stroyan4268d1f2015-07-13 14:45:35 -0600214 test_platform_thread_mutex m_mutex;
Karl Schultz6addd812016-02-02 17:17:23 -0700215 bool *m_bailout;
216 VkBool32 m_msgFound;
Chris Forbes17756132016-09-16 14:36:39 +1200217 bool m_desiredMsgSet;
Tony Barbour300a6082015-04-07 13:44:53 -0600218};
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500219
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600220static VKAPI_ATTR VkBool32 VKAPI_CALL myDbgFunc(VkFlags msgFlags, VkDebugReportObjectTypeEXT objType, uint64_t srcObject,
221 size_t location, int32_t msgCode, const char *pLayerPrefix, const char *pMsg,
222 void *pUserData) {
Mark Lobodzinski7a588452016-08-03 14:04:26 -0600223 ErrorMonitor *errMonitor = (ErrorMonitor *)pUserData;
224 if (msgFlags & errMonitor->GetMessageFlags()) {
225 return errMonitor->CheckForDesiredMsg(pMsg);
Tony Barbour0b4d9562015-04-09 10:48:04 -0600226 }
Courtney Goeltzenleuchter06640832015-09-04 13:52:24 -0600227 return false;
Tony Barbour300a6082015-04-07 13:44:53 -0600228}
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500229
Karl Schultz6addd812016-02-02 17:17:23 -0700230class VkLayerTest : public VkRenderFramework {
231 public:
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800232 VkResult BeginCommandBuffer(VkCommandBufferObj &commandBuffer);
233 VkResult EndCommandBuffer(VkCommandBufferObj &commandBuffer);
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600234 void VKTriangleTest(const char *vertShaderText, const char *fragShaderText, BsoFailSelect failMask);
235 void GenericDrawPreparation(VkCommandBufferObj *commandBuffer, VkPipelineObj &pipelineobj, VkDescriptorSetObj &descriptorSet,
Karl Schultz6addd812016-02-02 17:17:23 -0700236 BsoFailSelect failMask);
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600237 void GenericDrawPreparation(VkPipelineObj &pipelineobj, VkDescriptorSetObj &descriptorSet, BsoFailSelect failMask) {
238 GenericDrawPreparation(m_commandBuffer, pipelineobj, descriptorSet, failMask);
Karl Schultz6addd812016-02-02 17:17:23 -0700239 }
Tony Barbour300a6082015-04-07 13:44:53 -0600240
Tony Barbourfe3351b2015-07-28 10:17:20 -0600241 /* Convenience functions that use built-in command buffer */
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600242 VkResult BeginCommandBuffer() { return BeginCommandBuffer(*m_commandBuffer); }
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800243 VkResult EndCommandBuffer() { return EndCommandBuffer(*m_commandBuffer); }
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600244 void Draw(uint32_t vertexCount, uint32_t instanceCount, uint32_t firstVertex, uint32_t firstInstance) {
245 m_commandBuffer->Draw(vertexCount, instanceCount, firstVertex, firstInstance);
Karl Schultz6addd812016-02-02 17:17:23 -0700246 }
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600247 void DrawIndexed(uint32_t indexCount, uint32_t instanceCount, uint32_t firstIndex, int32_t vertexOffset,
Karl Schultz6addd812016-02-02 17:17:23 -0700248 uint32_t firstInstance) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600249 m_commandBuffer->DrawIndexed(indexCount, instanceCount, firstIndex, vertexOffset, firstInstance);
Karl Schultz6addd812016-02-02 17:17:23 -0700250 }
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600251 void QueueCommandBuffer(bool checkSuccess = true) { m_commandBuffer->QueueCommandBuffer(checkSuccess); }
252 void QueueCommandBuffer(const VkFence &fence) { m_commandBuffer->QueueCommandBuffer(fence); }
253 void BindVertexBuffer(VkConstantBufferObj *vertexBuffer, VkDeviceSize offset, uint32_t binding) {
Karl Schultz6addd812016-02-02 17:17:23 -0700254 m_commandBuffer->BindVertexBuffer(vertexBuffer, offset, binding);
255 }
256 void BindIndexBuffer(VkIndexBufferObj *indexBuffer, VkDeviceSize offset) {
257 m_commandBuffer->BindIndexBuffer(indexBuffer, offset);
258 }
259
260 protected:
261 ErrorMonitor *m_errorMonitor;
Ian Elliott2c1daf52016-05-12 09:41:46 -0600262 bool m_enableWSI;
Tony Barbour300a6082015-04-07 13:44:53 -0600263
264 virtual void SetUp() {
Courtney Goeltzenleuchtercd69eee2015-07-06 09:10:47 -0600265 std::vector<const char *> instance_layer_names;
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -0600266 std::vector<const char *> instance_extension_names;
267 std::vector<const char *> device_extension_names;
Tony Barbour3fdff9e2015-04-23 12:55:36 -0600268
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -0700269 instance_extension_names.push_back(VK_EXT_DEBUG_REPORT_EXTENSION_NAME);
Courtney Goeltzenleuchterc2b06fe2015-06-16 15:59:11 -0600270 /*
271 * Since CreateDbgMsgCallback is an instance level extension call
272 * any extension / layer that utilizes that feature also needs
273 * to be enabled at create instance time.
274 */
Karl Schultz6addd812016-02-02 17:17:23 -0700275 // Use Threading layer first to protect others from
276 // ThreadCommandBufferCollision test
Courtney Goeltzenleuchter76885322016-02-06 17:11:22 -0700277 instance_layer_names.push_back("VK_LAYER_GOOGLE_threading");
Tobin Ehlis24aab042016-03-24 10:54:18 -0600278 instance_layer_names.push_back("VK_LAYER_LUNARG_parameter_validation");
Michael Lentine03107b42015-12-11 10:49:51 -0800279 instance_layer_names.push_back("VK_LAYER_LUNARG_object_tracker");
Tobin Ehlisc96f8062016-03-09 16:12:48 -0700280 instance_layer_names.push_back("VK_LAYER_LUNARG_core_validation");
Michael Lentine03107b42015-12-11 10:49:51 -0800281 instance_layer_names.push_back("VK_LAYER_LUNARG_image");
Ian Elliotte48a1382016-04-28 14:22:58 -0600282 instance_layer_names.push_back("VK_LAYER_LUNARG_swapchain");
Dustin Graveseaa78cd2016-01-26 16:30:22 -0700283 instance_layer_names.push_back("VK_LAYER_GOOGLE_unique_objects");
Courtney Goeltzenleuchterd971b612015-06-17 20:51:59 -0600284
Ian Elliott2c1daf52016-05-12 09:41:46 -0600285 if (m_enableWSI) {
286 instance_extension_names.push_back(VK_KHR_SURFACE_EXTENSION_NAME);
287 device_extension_names.push_back(VK_KHR_SWAPCHAIN_EXTENSION_NAME);
288#ifdef NEED_TO_TEST_THIS_ON_PLATFORM
289#if defined(VK_USE_PLATFORM_ANDROID_KHR)
290 instance_extension_names.push_back(VK_KHR_ANDROID_SURFACE_EXTENSION_NAME);
291#endif // VK_USE_PLATFORM_ANDROID_KHR
292#if defined(VK_USE_PLATFORM_MIR_KHR)
293 instance_extension_names.push_back(VK_KHR_MIR_SURFACE_EXTENSION_NAME);
294#endif // VK_USE_PLATFORM_MIR_KHR
295#if defined(VK_USE_PLATFORM_WAYLAND_KHR)
296 instance_extension_names.push_back(VK_KHR_WAYLAND_SURFACE_EXTENSION_NAME);
297#endif // VK_USE_PLATFORM_WAYLAND_KHR
298#if defined(VK_USE_PLATFORM_WIN32_KHR)
299 instance_extension_names.push_back(VK_KHR_WIN32_SURFACE_EXTENSION_NAME);
300#endif // VK_USE_PLATFORM_WIN32_KHR
301#endif // NEED_TO_TEST_THIS_ON_PLATFORM
302#if defined(VK_USE_PLATFORM_XCB_KHR)
303 instance_extension_names.push_back(VK_KHR_XCB_SURFACE_EXTENSION_NAME);
304#elif defined(VK_USE_PLATFORM_XLIB_KHR)
305 instance_extension_names.push_back(VK_KHR_XLIB_SURFACE_EXTENSION_NAME);
306#endif // VK_USE_PLATFORM_XLIB_KHR
307 }
308
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600309 this->app_info.sType = VK_STRUCTURE_TYPE_APPLICATION_INFO;
Tony Barbour300a6082015-04-07 13:44:53 -0600310 this->app_info.pNext = NULL;
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800311 this->app_info.pApplicationName = "layer_tests";
312 this->app_info.applicationVersion = 1;
Tony Barbour300a6082015-04-07 13:44:53 -0600313 this->app_info.pEngineName = "unittest";
314 this->app_info.engineVersion = 1;
Jon Ashburnc5012ff2016-03-22 13:57:46 -0600315 this->app_info.apiVersion = VK_API_VERSION_1_0;
Tony Barbour300a6082015-04-07 13:44:53 -0600316
Tony Barbour15524c32015-04-29 17:34:29 -0600317 m_errorMonitor = new ErrorMonitor;
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600318 InitFramework(instance_layer_names, instance_extension_names, device_extension_names, myDbgFunc, m_errorMonitor);
Tony Barbour300a6082015-04-07 13:44:53 -0600319 }
320
321 virtual void TearDown() {
322 // Clean up resources before we reset
Tony Barbour300a6082015-04-07 13:44:53 -0600323 ShutdownFramework();
Tony Barbour0b4d9562015-04-09 10:48:04 -0600324 delete m_errorMonitor;
Tony Barbour300a6082015-04-07 13:44:53 -0600325 }
Ian Elliott2c1daf52016-05-12 09:41:46 -0600326
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600327 VkLayerTest() { m_enableWSI = false; }
Tony Barbour300a6082015-04-07 13:44:53 -0600328};
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500329
Karl Schultz6addd812016-02-02 17:17:23 -0700330VkResult VkLayerTest::BeginCommandBuffer(VkCommandBufferObj &commandBuffer) {
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600331 VkResult result;
Tony Barbour300a6082015-04-07 13:44:53 -0600332
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800333 result = commandBuffer.BeginCommandBuffer();
Tony Barbour300a6082015-04-07 13:44:53 -0600334
335 /*
336 * For render test all drawing happens in a single render pass
337 * on a single command buffer.
338 */
Chris Forbes76a5eeb2015-06-16 14:05:59 +1200339 if (VK_SUCCESS == result && renderPass()) {
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800340 commandBuffer.BeginRenderPass(renderPassBeginInfo());
Tony Barbour300a6082015-04-07 13:44:53 -0600341 }
342
343 return result;
344}
345
Karl Schultz6addd812016-02-02 17:17:23 -0700346VkResult VkLayerTest::EndCommandBuffer(VkCommandBufferObj &commandBuffer) {
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600347 VkResult result;
Tony Barbour300a6082015-04-07 13:44:53 -0600348
Chris Forbes76a5eeb2015-06-16 14:05:59 +1200349 if (renderPass()) {
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800350 commandBuffer.EndRenderPass();
Chris Forbes76a5eeb2015-06-16 14:05:59 +1200351 }
Tony Barbour300a6082015-04-07 13:44:53 -0600352
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800353 result = commandBuffer.EndCommandBuffer();
Tony Barbour300a6082015-04-07 13:44:53 -0600354
355 return result;
356}
357
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600358void VkLayerTest::VKTriangleTest(const char *vertShaderText, const char *fragShaderText, BsoFailSelect failMask) {
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500359 // Create identity matrix
360 int i;
361 struct vktriangle_vs_uniform data;
362
363 glm::mat4 Projection = glm::mat4(1.0f);
Karl Schultz6addd812016-02-02 17:17:23 -0700364 glm::mat4 View = glm::mat4(1.0f);
365 glm::mat4 Model = glm::mat4(1.0f);
366 glm::mat4 MVP = Projection * View * Model;
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500367 const int matrixSize = sizeof(MVP);
Karl Schultz6addd812016-02-02 17:17:23 -0700368 const int bufSize = sizeof(vktriangle_vs_uniform) / sizeof(float);
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500369
370 memcpy(&data.mvp, &MVP[0][0], matrixSize);
371
Karl Schultz6addd812016-02-02 17:17:23 -0700372 static const Vertex tri_data[] = {
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600373 {XYZ1(-1, -1, 0), XYZ1(1.f, 0.f, 0.f)}, {XYZ1(1, -1, 0), XYZ1(0.f, 1.f, 0.f)}, {XYZ1(0, 1, 0), XYZ1(0.f, 0.f, 1.f)},
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500374 };
375
Karl Schultz6addd812016-02-02 17:17:23 -0700376 for (i = 0; i < 3; i++) {
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500377 data.position[i][0] = tri_data[i].posX;
378 data.position[i][1] = tri_data[i].posY;
379 data.position[i][2] = tri_data[i].posZ;
380 data.position[i][3] = tri_data[i].posW;
Karl Schultz6addd812016-02-02 17:17:23 -0700381 data.color[i][0] = tri_data[i].r;
382 data.color[i][1] = tri_data[i].g;
383 data.color[i][2] = tri_data[i].b;
384 data.color[i][3] = tri_data[i].a;
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500385 }
386
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500387 ASSERT_NO_FATAL_FAILURE(InitViewport());
388
Chris Forbesbcfaadd2016-09-16 14:13:53 +1200389 VkConstantBufferObj constantBuffer(m_device, bufSize * 2, sizeof(float), (const void *)&data,
390 VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT);
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500391
Karl Schultz6addd812016-02-02 17:17:23 -0700392 VkShaderObj vs(m_device, vertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600393 VkShaderObj ps(m_device, fragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500394
395 VkPipelineObj pipelineobj(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +0800396 pipelineobj.AddColorAttachment();
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500397 pipelineobj.AddShader(&vs);
398 pipelineobj.AddShader(&ps);
Courtney Goeltzenleuchter507ba972015-09-30 16:16:57 -0600399 if (failMask & BsoFailLineWidth) {
400 pipelineobj.MakeDynamic(VK_DYNAMIC_STATE_LINE_WIDTH);
Tobin Ehlis7a1d2352016-03-28 11:18:19 -0600401 VkPipelineInputAssemblyStateCreateInfo ia_state = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600402 ia_state.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
Tobin Ehlis7a1d2352016-03-28 11:18:19 -0600403 ia_state.topology = VK_PRIMITIVE_TOPOLOGY_LINE_LIST;
404 pipelineobj.SetInputAssembly(&ia_state);
Courtney Goeltzenleuchter507ba972015-09-30 16:16:57 -0600405 }
406 if (failMask & BsoFailDepthBias) {
407 pipelineobj.MakeDynamic(VK_DYNAMIC_STATE_DEPTH_BIAS);
Tobin Ehlis7a1d2352016-03-28 11:18:19 -0600408 VkPipelineRasterizationStateCreateInfo rs_state = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600409 rs_state.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
Tobin Ehlis7a1d2352016-03-28 11:18:19 -0600410 rs_state.depthBiasEnable = VK_TRUE;
Mark Young7394fdd2016-03-31 14:56:43 -0600411 rs_state.lineWidth = 1.0f;
Tobin Ehlis7a1d2352016-03-28 11:18:19 -0600412 pipelineobj.SetRasterization(&rs_state);
Courtney Goeltzenleuchter507ba972015-09-30 16:16:57 -0600413 }
Karl Schultz6addd812016-02-02 17:17:23 -0700414 // Viewport and scissors must stay in synch or other errors will occur than
415 // the ones we want
Courtney Goeltzenleuchter507ba972015-09-30 16:16:57 -0600416 if (failMask & BsoFailViewport) {
417 pipelineobj.MakeDynamic(VK_DYNAMIC_STATE_VIEWPORT);
418 }
419 if (failMask & BsoFailScissor) {
420 pipelineobj.MakeDynamic(VK_DYNAMIC_STATE_SCISSOR);
421 }
422 if (failMask & BsoFailBlend) {
423 pipelineobj.MakeDynamic(VK_DYNAMIC_STATE_BLEND_CONSTANTS);
Tobin Ehlis7a1d2352016-03-28 11:18:19 -0600424 VkPipelineColorBlendAttachmentState att_state = {};
425 att_state.dstAlphaBlendFactor = VK_BLEND_FACTOR_CONSTANT_COLOR;
426 att_state.blendEnable = VK_TRUE;
427 pipelineobj.AddColorAttachment(0, &att_state);
Courtney Goeltzenleuchter507ba972015-09-30 16:16:57 -0600428 }
429 if (failMask & BsoFailDepthBounds) {
430 pipelineobj.MakeDynamic(VK_DYNAMIC_STATE_DEPTH_BOUNDS);
431 }
432 if (failMask & BsoFailStencilReadMask) {
433 pipelineobj.MakeDynamic(VK_DYNAMIC_STATE_STENCIL_COMPARE_MASK);
434 }
435 if (failMask & BsoFailStencilWriteMask) {
436 pipelineobj.MakeDynamic(VK_DYNAMIC_STATE_STENCIL_WRITE_MASK);
437 }
438 if (failMask & BsoFailStencilReference) {
439 pipelineobj.MakeDynamic(VK_DYNAMIC_STATE_STENCIL_REFERENCE);
440 }
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500441
442 VkDescriptorSetObj descriptorSet(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600443 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, constantBuffer);
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500444
445 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barbourfe3351b2015-07-28 10:17:20 -0600446 ASSERT_VK_SUCCESS(BeginCommandBuffer());
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500447
Tony Barbourfe3351b2015-07-28 10:17:20 -0600448 GenericDrawPreparation(pipelineobj, descriptorSet, failMask);
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500449
450 // render triangle
Tobin Ehlis379ba3b2016-07-19 11:22:29 -0600451 if (failMask & BsoFailIndexBuffer) {
452 // Use DrawIndexed w/o an index buffer bound
453 DrawIndexed(3, 1, 0, 0, 0);
454 } else {
455 Draw(3, 1, 0, 0);
456 }
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500457
Mark Muellerd4914412016-06-13 17:52:06 -0600458 if (failMask & BsoFailCmdClearAttachments) {
459 VkClearAttachment color_attachment = {};
460 color_attachment.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
461 color_attachment.colorAttachment = 1; // Someone who knew what they were doing would use 0 for the index;
462 VkClearRect clear_rect = {{{0, 0}, {static_cast<uint32_t>(m_width), static_cast<uint32_t>(m_height)}}, 0, 0};
463
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600464 vkCmdClearAttachments(m_commandBuffer->GetBufferHandle(), 1, &color_attachment, 1, &clear_rect);
Mark Muellerd4914412016-06-13 17:52:06 -0600465 }
466
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500467 // finalize recording of the command buffer
Tony Barbourfe3351b2015-07-28 10:17:20 -0600468 EndCommandBuffer();
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500469
Tony Barbourfe3351b2015-07-28 10:17:20 -0600470 QueueCommandBuffer();
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500471}
472
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600473void VkLayerTest::GenericDrawPreparation(VkCommandBufferObj *commandBuffer, VkPipelineObj &pipelineobj,
474 VkDescriptorSetObj &descriptorSet, BsoFailSelect failMask) {
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500475 if (m_depthStencil->Initialized()) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600476 commandBuffer->ClearAllBuffers(m_clear_color, m_depth_clear_color, m_stencil_clear_color, m_depthStencil);
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500477 } else {
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600478 commandBuffer->ClearAllBuffers(m_clear_color, m_depth_clear_color, m_stencil_clear_color, NULL);
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500479 }
480
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800481 commandBuffer->PrepareAttachments();
Karl Schultz6addd812016-02-02 17:17:23 -0700482 // Make sure depthWriteEnable is set so that Depth fail test will work
483 // correctly
484 // Make sure stencilTestEnable is set so that Stencil fail test will work
485 // correctly
Tony Barboureb254902015-07-15 12:50:33 -0600486 VkStencilOpState stencil = {};
Chia-I Wu1b99bb22015-10-27 19:25:11 +0800487 stencil.failOp = VK_STENCIL_OP_KEEP;
488 stencil.passOp = VK_STENCIL_OP_KEEP;
489 stencil.depthFailOp = VK_STENCIL_OP_KEEP;
490 stencil.compareOp = VK_COMPARE_OP_NEVER;
Tony Barboureb254902015-07-15 12:50:33 -0600491
492 VkPipelineDepthStencilStateCreateInfo ds_ci = {};
493 ds_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_DEPTH_STENCIL_STATE_CREATE_INFO;
Courtney Goeltzenleuchter507ba972015-09-30 16:16:57 -0600494 ds_ci.pNext = NULL;
495 ds_ci.depthTestEnable = VK_FALSE;
496 ds_ci.depthWriteEnable = VK_TRUE;
497 ds_ci.depthCompareOp = VK_COMPARE_OP_NEVER;
498 ds_ci.depthBoundsTestEnable = VK_FALSE;
Tobin Ehlis7a1d2352016-03-28 11:18:19 -0600499 if (failMask & BsoFailDepthBounds) {
500 ds_ci.depthBoundsTestEnable = VK_TRUE;
Tobin Ehlis21c88352016-05-26 06:15:45 -0600501 ds_ci.maxDepthBounds = 0.0f;
502 ds_ci.minDepthBounds = 0.0f;
Tobin Ehlis7a1d2352016-03-28 11:18:19 -0600503 }
Courtney Goeltzenleuchter507ba972015-09-30 16:16:57 -0600504 ds_ci.stencilTestEnable = VK_TRUE;
505 ds_ci.front = stencil;
506 ds_ci.back = stencil;
Tony Barboureb254902015-07-15 12:50:33 -0600507
Tobin Ehlis4bf96d12015-06-25 11:58:41 -0600508 pipelineobj.SetDepthStencil(&ds_ci);
Tobin Ehlisd332f282015-10-02 11:00:56 -0600509 pipelineobj.SetViewport(m_viewports);
510 pipelineobj.SetScissor(m_scissors);
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800511 descriptorSet.CreateVKDescriptorSet(commandBuffer);
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600512 VkResult err = pipelineobj.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Cody Northrop29a08f22015-08-27 10:20:35 -0600513 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800514 commandBuffer->BindPipeline(pipelineobj);
515 commandBuffer->BindDescriptorSet(descriptorSet);
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500516}
517
Ian Elliott2c1daf52016-05-12 09:41:46 -0600518class VkWsiEnabledLayerTest : public VkLayerTest {
519 public:
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600520 protected:
521 VkWsiEnabledLayerTest() { m_enableWSI = true; }
Ian Elliott2c1daf52016-05-12 09:41:46 -0600522};
523
Mark Muellerdfe37552016-07-07 14:47:42 -0600524class VkBufferTest {
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600525 public:
Mark Muellerdfe37552016-07-07 14:47:42 -0600526 enum eTestEnFlags {
527 eDoubleDelete,
528 eInvalidDeviceOffset,
529 eInvalidMemoryOffset,
530 eBindNullBuffer,
531 eFreeInvalidHandle,
Mark Mueller4042b652016-09-05 22:52:21 -0600532 eNone,
Mark Muellerdfe37552016-07-07 14:47:42 -0600533 };
534
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600535 enum eTestConditions { eOffsetAlignment = 1 };
Mark Muellerdfe37552016-07-07 14:47:42 -0600536
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600537 static bool GetTestConditionValid(VkDeviceObj *aVulkanDevice, eTestEnFlags aTestFlag, VkBufferUsageFlags aBufferUsage = 0) {
538 if (eInvalidDeviceOffset != aTestFlag && eInvalidMemoryOffset != aTestFlag) {
Mark Muellerdfe37552016-07-07 14:47:42 -0600539 return true;
540 }
541 VkDeviceSize offset_limit = 0;
542 if (eInvalidMemoryOffset == aTestFlag) {
543 VkBuffer vulkanBuffer;
544 VkBufferCreateInfo buffer_create_info = {};
545 buffer_create_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
546 buffer_create_info.size = 32;
547 buffer_create_info.usage = aBufferUsage;
548
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600549 vkCreateBuffer(aVulkanDevice->device(), &buffer_create_info, nullptr, &vulkanBuffer);
Mark Mueller4042b652016-09-05 22:52:21 -0600550 VkMemoryRequirements memory_reqs = {};
Mark Muellerdfe37552016-07-07 14:47:42 -0600551
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600552 vkGetBufferMemoryRequirements(aVulkanDevice->device(), vulkanBuffer, &memory_reqs);
Mark Muellerdfe37552016-07-07 14:47:42 -0600553 vkDestroyBuffer(aVulkanDevice->device(), vulkanBuffer, nullptr);
554 offset_limit = memory_reqs.alignment;
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600555 } else if ((VK_BUFFER_USAGE_UNIFORM_TEXEL_BUFFER_BIT | VK_BUFFER_USAGE_STORAGE_TEXEL_BUFFER_BIT) & aBufferUsage) {
556 offset_limit = aVulkanDevice->props.limits.minTexelBufferOffsetAlignment;
Mark Muellerdfe37552016-07-07 14:47:42 -0600557 } else if (VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT & aBufferUsage) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600558 offset_limit = aVulkanDevice->props.limits.minUniformBufferOffsetAlignment;
Mark Muellerdfe37552016-07-07 14:47:42 -0600559 } else if (VK_BUFFER_USAGE_STORAGE_BUFFER_BIT & aBufferUsage) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600560 offset_limit = aVulkanDevice->props.limits.minStorageBufferOffsetAlignment;
Mark Muellerdfe37552016-07-07 14:47:42 -0600561 }
562 if (eOffsetAlignment < offset_limit) {
563 return true;
564 }
565 return false;
566 }
567
568 // A constructor which performs validation tests within construction.
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600569 VkBufferTest(VkDeviceObj *aVulkanDevice, VkBufferUsageFlags aBufferUsage, eTestEnFlags aTestFlag = eNone)
570 : AllocateCurrent(false), BoundCurrent(false), CreateCurrent(false), VulkanDevice(aVulkanDevice->device()) {
Mark Muellerdfe37552016-07-07 14:47:42 -0600571
572 if (eBindNullBuffer == aTestFlag) {
573 VulkanMemory = 0;
574 vkBindBufferMemory(VulkanDevice, VulkanBuffer, VulkanMemory, 0);
575 } else {
576 VkBufferCreateInfo buffer_create_info = {};
577 buffer_create_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
578 buffer_create_info.size = 32;
579 buffer_create_info.usage = aBufferUsage;
580
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600581 vkCreateBuffer(VulkanDevice, &buffer_create_info, nullptr, &VulkanBuffer);
Mark Muellerdfe37552016-07-07 14:47:42 -0600582
583 CreateCurrent = true;
584
585 VkMemoryRequirements memory_requirements;
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600586 vkGetBufferMemoryRequirements(VulkanDevice, VulkanBuffer, &memory_requirements);
Mark Muellerdfe37552016-07-07 14:47:42 -0600587
588 VkMemoryAllocateInfo memory_allocate_info = {};
589 memory_allocate_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
590 memory_allocate_info.allocationSize = memory_requirements.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600591 bool pass = aVulkanDevice->phy().set_memory_type(memory_requirements.memoryTypeBits, &memory_allocate_info,
592 VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT);
Mark Muellerdfe37552016-07-07 14:47:42 -0600593 if (!pass) {
594 vkDestroyBuffer(VulkanDevice, VulkanBuffer, nullptr);
595 return;
596 }
597
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600598 vkAllocateMemory(VulkanDevice, &memory_allocate_info, NULL, &VulkanMemory);
Mark Muellerdfe37552016-07-07 14:47:42 -0600599 AllocateCurrent = true;
600 // NB: 1 is intentionally an invalid offset value
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600601 const bool offset_en = eInvalidDeviceOffset == aTestFlag || eInvalidMemoryOffset == aTestFlag;
602 vkBindBufferMemory(VulkanDevice, VulkanBuffer, VulkanMemory, offset_en ? eOffsetAlignment : 0);
Mark Muellerdfe37552016-07-07 14:47:42 -0600603 BoundCurrent = true;
604
605 InvalidDeleteEn = (eFreeInvalidHandle == aTestFlag);
606 }
607 }
608
609 ~VkBufferTest() {
610 if (CreateCurrent) {
611 vkDestroyBuffer(VulkanDevice, VulkanBuffer, nullptr);
612 }
613 if (AllocateCurrent) {
614 if (InvalidDeleteEn) {
615 union {
616 VkDeviceMemory device_memory;
617 unsigned long long index_access;
618 } bad_index;
619
620 bad_index.device_memory = VulkanMemory;
621 bad_index.index_access++;
622
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600623 vkFreeMemory(VulkanDevice, bad_index.device_memory, nullptr);
Mark Muellerdfe37552016-07-07 14:47:42 -0600624 }
625 vkFreeMemory(VulkanDevice, VulkanMemory, nullptr);
626 }
627 }
628
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600629 bool GetBufferCurrent() { return AllocateCurrent && BoundCurrent && CreateCurrent; }
Mark Muellerdfe37552016-07-07 14:47:42 -0600630
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600631 const VkBuffer &GetBuffer() { return VulkanBuffer; }
Mark Muellerdfe37552016-07-07 14:47:42 -0600632
633 void TestDoubleDestroy() {
634 // Destroy the buffer but leave the flag set, which will cause
635 // the buffer to be destroyed again in the destructor.
636 vkDestroyBuffer(VulkanDevice, VulkanBuffer, nullptr);
637 }
638
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600639 protected:
Mark Muellerdfe37552016-07-07 14:47:42 -0600640 bool AllocateCurrent;
641 bool BoundCurrent;
642 bool CreateCurrent;
643 bool InvalidDeleteEn;
644
645 VkBuffer VulkanBuffer;
646 VkDevice VulkanDevice;
647 VkDeviceMemory VulkanMemory;
Mark Muellerdfe37552016-07-07 14:47:42 -0600648};
649
650class VkVerticesObj {
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600651 public:
652 VkVerticesObj(VkDeviceObj *aVulkanDevice, unsigned aAttributeCount, unsigned aBindingCount, unsigned aByteStride,
Mark Muellerdfe37552016-07-07 14:47:42 -0600653 VkDeviceSize aVertexCount, const float *aVerticies)
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600654 : BoundCurrent(false), AttributeCount(aAttributeCount), BindingCount(aBindingCount), BindId(BindIdGenerator),
Mark Muellerdfe37552016-07-07 14:47:42 -0600655 PipelineVertexInputStateCreateInfo(),
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600656 VulkanMemoryBuffer(aVulkanDevice, 1, static_cast<int>(aByteStride * aVertexCount),
657 reinterpret_cast<const void *>(aVerticies), VK_BUFFER_USAGE_VERTEX_BUFFER_BIT) {
Mark Muellerdfe37552016-07-07 14:47:42 -0600658 BindIdGenerator++; // NB: This can wrap w/misuse
659
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600660 VertexInputAttributeDescription = new VkVertexInputAttributeDescription[AttributeCount];
661 VertexInputBindingDescription = new VkVertexInputBindingDescription[BindingCount];
Mark Muellerdfe37552016-07-07 14:47:42 -0600662
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600663 PipelineVertexInputStateCreateInfo.pVertexAttributeDescriptions = VertexInputAttributeDescription;
664 PipelineVertexInputStateCreateInfo.vertexAttributeDescriptionCount = AttributeCount;
665 PipelineVertexInputStateCreateInfo.pVertexBindingDescriptions = VertexInputBindingDescription;
666 PipelineVertexInputStateCreateInfo.vertexBindingDescriptionCount = BindingCount;
667 PipelineVertexInputStateCreateInfo.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
Mark Muellerdfe37552016-07-07 14:47:42 -0600668
669 unsigned i = 0;
670 do {
671 VertexInputAttributeDescription[i].binding = BindId;
672 VertexInputAttributeDescription[i].location = i;
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600673 VertexInputAttributeDescription[i].format = VK_FORMAT_R32G32B32_SFLOAT;
674 VertexInputAttributeDescription[i].offset = sizeof(float) * aByteStride;
Mark Muellerdfe37552016-07-07 14:47:42 -0600675 i++;
676 } while (AttributeCount < i);
677
678 i = 0;
679 do {
680 VertexInputBindingDescription[i].binding = BindId;
681 VertexInputBindingDescription[i].stride = aByteStride;
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600682 VertexInputBindingDescription[i].inputRate = VK_VERTEX_INPUT_RATE_VERTEX;
Mark Muellerdfe37552016-07-07 14:47:42 -0600683 i++;
684 } while (BindingCount < i);
685 }
686
687 ~VkVerticesObj() {
688 if (VertexInputAttributeDescription) {
689 delete[] VertexInputAttributeDescription;
690 }
691 if (VertexInputBindingDescription) {
692 delete[] VertexInputBindingDescription;
693 }
694 }
695
696 bool AddVertexInputToPipe(VkPipelineObj &aPipelineObj) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600697 aPipelineObj.AddVertexInputAttribs(VertexInputAttributeDescription, AttributeCount);
698 aPipelineObj.AddVertexInputBindings(VertexInputBindingDescription, BindingCount);
Mark Muellerdfe37552016-07-07 14:47:42 -0600699 return true;
700 }
701
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600702 void BindVertexBuffers(VkCommandBuffer aCommandBuffer, unsigned aOffsetCount = 0, VkDeviceSize *aOffsetList = nullptr) {
Mark Muellerdfe37552016-07-07 14:47:42 -0600703 VkDeviceSize *offsetList;
704 unsigned offsetCount;
705
706 if (aOffsetCount) {
707 offsetList = aOffsetList;
708 offsetCount = aOffsetCount;
709 } else {
710 offsetList = new VkDeviceSize[1]();
711 offsetCount = 1;
712 }
713
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600714 vkCmdBindVertexBuffers(aCommandBuffer, BindId, offsetCount, &VulkanMemoryBuffer.handle(), offsetList);
Mark Muellerdfe37552016-07-07 14:47:42 -0600715 BoundCurrent = true;
716
717 if (!aOffsetCount) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600718 delete[] offsetList;
Mark Muellerdfe37552016-07-07 14:47:42 -0600719 }
720 }
721
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600722 protected:
Mark Muellerdfe37552016-07-07 14:47:42 -0600723 static uint32_t BindIdGenerator;
724
725 bool BoundCurrent;
726 unsigned AttributeCount;
727 unsigned BindingCount;
728 uint32_t BindId;
729
730 VkPipelineVertexInputStateCreateInfo PipelineVertexInputStateCreateInfo;
731 VkVertexInputAttributeDescription *VertexInputAttributeDescription;
732 VkVertexInputBindingDescription *VertexInputBindingDescription;
733 VkConstantBufferObj VulkanMemoryBuffer;
734};
735
736uint32_t VkVerticesObj::BindIdGenerator;
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500737// ********************************************************************************************************************
738// ********************************************************************************************************************
739// ********************************************************************************************************************
740// ********************************************************************************************************************
Dustin Gravesffa90fa2016-05-06 11:20:38 -0600741#if PARAMETER_VALIDATION_TESTS
742TEST_F(VkLayerTest, RequiredParameter) {
743 TEST_DESCRIPTION("Specify VK_NULL_HANDLE, NULL, and 0 for required handle, "
744 "pointer, array, and array count parameters");
745
746 ASSERT_NO_FATAL_FAILURE(InitState());
747
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600748 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "required parameter pFeatures specified as NULL");
Dustin Gravesffa90fa2016-05-06 11:20:38 -0600749 // Specify NULL for a pointer to a handle
750 // Expected to trigger an error with
751 // parameter_validation::validate_required_pointer
752 vkGetPhysicalDeviceFeatures(gpu(), NULL);
753 m_errorMonitor->VerifyFound();
754
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600755 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
756 "required parameter pQueueFamilyPropertyCount specified as NULL");
Dustin Gravesffa90fa2016-05-06 11:20:38 -0600757 // Specify NULL for pointer to array count
758 // Expected to trigger an error with parameter_validation::validate_array
Dustin Gravesa4bb8c12016-05-16 17:22:51 -0600759 vkGetPhysicalDeviceQueueFamilyProperties(gpu(), NULL, NULL);
Dustin Gravesffa90fa2016-05-06 11:20:38 -0600760 m_errorMonitor->VerifyFound();
761
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600762 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "parameter viewportCount must be greater than 0");
Dustin Gravesffa90fa2016-05-06 11:20:38 -0600763 // Specify 0 for a required array count
764 // Expected to trigger an error with parameter_validation::validate_array
765 VkViewport view_port = {};
766 m_commandBuffer->SetViewport(0, 0, &view_port);
767 m_errorMonitor->VerifyFound();
768
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600769 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "required parameter pViewports specified as NULL");
Dustin Gravesffa90fa2016-05-06 11:20:38 -0600770 // Specify NULL for a required array
771 // Expected to trigger an error with parameter_validation::validate_array
772 m_commandBuffer->SetViewport(0, 1, NULL);
773 m_errorMonitor->VerifyFound();
774
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600775 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "required parameter memory specified as VK_NULL_HANDLE");
Dustin Gravesffa90fa2016-05-06 11:20:38 -0600776 // Specify VK_NULL_HANDLE for a required handle
777 // Expected to trigger an error with
778 // parameter_validation::validate_required_handle
779 vkUnmapMemory(device(), VK_NULL_HANDLE);
780 m_errorMonitor->VerifyFound();
781
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600782 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
783 "required parameter pFences[0] specified as VK_NULL_HANDLE");
Dustin Gravesffa90fa2016-05-06 11:20:38 -0600784 // Specify VK_NULL_HANDLE for a required handle array entry
785 // Expected to trigger an error with
786 // parameter_validation::validate_required_handle_array
787 VkFence fence = VK_NULL_HANDLE;
788 vkResetFences(device(), 1, &fence);
789 m_errorMonitor->VerifyFound();
790
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600791 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "required parameter pAllocateInfo specified as NULL");
Dustin Gravesffa90fa2016-05-06 11:20:38 -0600792 // Specify NULL for a required struct pointer
793 // Expected to trigger an error with
794 // parameter_validation::validate_struct_type
795 VkDeviceMemory memory = VK_NULL_HANDLE;
796 vkAllocateMemory(device(), NULL, NULL, &memory);
797 m_errorMonitor->VerifyFound();
798
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600799 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "value of faceMask must not be 0");
Dustin Gravesffa90fa2016-05-06 11:20:38 -0600800 // Specify 0 for a required VkFlags parameter
801 // Expected to trigger an error with parameter_validation::validate_flags
802 m_commandBuffer->SetStencilReference(0, 0);
803 m_errorMonitor->VerifyFound();
804
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600805 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "value of pSubmits[0].pWaitDstStageMask[0] must not be 0");
Dustin Gravesffa90fa2016-05-06 11:20:38 -0600806 // Specify 0 for a required VkFlags array entry
807 // Expected to trigger an error with
808 // parameter_validation::validate_flags_array
809 VkSemaphore semaphore = VK_NULL_HANDLE;
810 VkPipelineStageFlags stageFlags = 0;
811 VkSubmitInfo submitInfo = {};
812 submitInfo.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
813 submitInfo.waitSemaphoreCount = 1;
814 submitInfo.pWaitSemaphores = &semaphore;
815 submitInfo.pWaitDstStageMask = &stageFlags;
816 vkQueueSubmit(m_device->m_queue, 1, &submitInfo, VK_NULL_HANDLE);
817 m_errorMonitor->VerifyFound();
818}
Dustin Gravesc99cf5a2016-05-09 14:40:29 -0600819
Dustin Gravesfce74c02016-05-10 11:42:58 -0600820TEST_F(VkLayerTest, ReservedParameter) {
821 TEST_DESCRIPTION("Specify a non-zero value for a reserved parameter");
822
823 ASSERT_NO_FATAL_FAILURE(InitState());
824
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600825 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " must be 0");
Dustin Gravesfce74c02016-05-10 11:42:58 -0600826 // Specify 0 for a reserved VkFlags parameter
827 // Expected to trigger an error with
828 // parameter_validation::validate_reserved_flags
829 VkEvent event_handle = VK_NULL_HANDLE;
830 VkEventCreateInfo event_info = {};
831 event_info.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO;
832 event_info.flags = 1;
833 vkCreateEvent(device(), &event_info, NULL, &event_handle);
834 m_errorMonitor->VerifyFound();
835}
836
Dustin Gravesc99cf5a2016-05-09 14:40:29 -0600837TEST_F(VkLayerTest, InvalidStructSType) {
838 TEST_DESCRIPTION("Specify an invalid VkStructureType for a Vulkan "
839 "structure's sType field");
840
841 ASSERT_NO_FATAL_FAILURE(InitState());
842
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600843 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "parameter pAllocateInfo->sType must be");
Dustin Gravesc99cf5a2016-05-09 14:40:29 -0600844 // Zero struct memory, effectively setting sType to
845 // VK_STRUCTURE_TYPE_APPLICATION_INFO
846 // Expected to trigger an error with
847 // parameter_validation::validate_struct_type
848 VkMemoryAllocateInfo alloc_info = {};
849 VkDeviceMemory memory = VK_NULL_HANDLE;
850 vkAllocateMemory(device(), &alloc_info, NULL, &memory);
851 m_errorMonitor->VerifyFound();
852
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600853 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "parameter pSubmits[0].sType must be");
Dustin Gravesc99cf5a2016-05-09 14:40:29 -0600854 // Zero struct memory, effectively setting sType to
855 // VK_STRUCTURE_TYPE_APPLICATION_INFO
856 // Expected to trigger an error with
857 // parameter_validation::validate_struct_type_array
858 VkSubmitInfo submit_info = {};
859 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
860 m_errorMonitor->VerifyFound();
861}
862
863TEST_F(VkLayerTest, InvalidStructPNext) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600864 TEST_DESCRIPTION("Specify an invalid value for a Vulkan structure's pNext field");
Dustin Gravesc99cf5a2016-05-09 14:40:29 -0600865
866 ASSERT_NO_FATAL_FAILURE(InitState());
867
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600868 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT, "value of pCreateInfo->pNext must be NULL");
Dustin Gravesc99cf5a2016-05-09 14:40:29 -0600869 // Set VkMemoryAllocateInfo::pNext to a non-NULL value, when pNext must be
Karl Schultz38b50992016-07-11 16:09:09 -0600870 // NULL.
871 // Need to pick a function that has no allowed pNext structure types.
872 // Expected to trigger an error with
873 // parameter_validation::validate_struct_pnext
874 VkEvent event = VK_NULL_HANDLE;
Karl Schultz70db3902016-07-11 16:22:10 -0600875 VkEventCreateInfo event_alloc_info = {};
Karl Schultz38b50992016-07-11 16:09:09 -0600876 // Zero-initialization will provide the correct sType
877 VkApplicationInfo app_info = {};
878 event_alloc_info.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO;
879 event_alloc_info.pNext = &app_info;
880 vkCreateEvent(device(), &event_alloc_info, NULL, &event);
881 m_errorMonitor->VerifyFound();
882
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600883 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT,
884 " chain includes a structure with unexpected VkStructureType ");
Karl Schultz38b50992016-07-11 16:09:09 -0600885 // Set VkMemoryAllocateInfo::pNext to a non-NULL value, but use
886 // a function that has allowed pNext structure types and specify
887 // a structure type that is not allowed.
Dustin Gravesc99cf5a2016-05-09 14:40:29 -0600888 // Expected to trigger an error with
889 // parameter_validation::validate_struct_pnext
890 VkDeviceMemory memory = VK_NULL_HANDLE;
Dustin Graves47b6cba2016-05-10 17:34:38 -0600891 VkMemoryAllocateInfo memory_alloc_info = {};
892 memory_alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
893 memory_alloc_info.pNext = &app_info;
894 vkAllocateMemory(device(), &memory_alloc_info, NULL, &memory);
Dustin Gravesc99cf5a2016-05-09 14:40:29 -0600895 m_errorMonitor->VerifyFound();
896
Dustin Gravesfd1c8fe2016-07-15 11:40:20 -0600897 // Positive test to check parameter_validation and unique_objects support
898 // for NV_dedicated_allocation
899 uint32_t extension_count = 0;
900 bool supports_nv_dedicated_allocation = false;
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600901 VkResult err = vkEnumerateDeviceExtensionProperties(gpu(), nullptr, &extension_count, nullptr);
Dustin Gravesfd1c8fe2016-07-15 11:40:20 -0600902 ASSERT_VK_SUCCESS(err);
903
904 if (extension_count > 0) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600905 std::vector<VkExtensionProperties> available_extensions(extension_count);
Dustin Gravesfd1c8fe2016-07-15 11:40:20 -0600906
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600907 err = vkEnumerateDeviceExtensionProperties(gpu(), nullptr, &extension_count, &available_extensions[0]);
Dustin Gravesfd1c8fe2016-07-15 11:40:20 -0600908 ASSERT_VK_SUCCESS(err);
909
910 for (const auto &extension_props : available_extensions) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600911 if (strcmp(extension_props.extensionName, VK_NV_DEDICATED_ALLOCATION_EXTENSION_NAME) == 0) {
Dustin Gravesfd1c8fe2016-07-15 11:40:20 -0600912 supports_nv_dedicated_allocation = true;
913 }
914 }
915 }
916
917 if (supports_nv_dedicated_allocation) {
918 m_errorMonitor->ExpectSuccess();
919
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600920 VkDedicatedAllocationBufferCreateInfoNV dedicated_buffer_create_info = {};
921 dedicated_buffer_create_info.sType = VK_STRUCTURE_TYPE_DEDICATED_ALLOCATION_BUFFER_CREATE_INFO_NV;
Dustin Gravesfd1c8fe2016-07-15 11:40:20 -0600922 dedicated_buffer_create_info.pNext = nullptr;
923 dedicated_buffer_create_info.dedicatedAllocation = VK_TRUE;
924
925 uint32_t queue_family_index = 0;
926 VkBufferCreateInfo buffer_create_info = {};
927 buffer_create_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
928 buffer_create_info.pNext = &dedicated_buffer_create_info;
929 buffer_create_info.size = 1024;
930 buffer_create_info.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
931 buffer_create_info.queueFamilyIndexCount = 1;
932 buffer_create_info.pQueueFamilyIndices = &queue_family_index;
933
934 VkBuffer buffer;
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600935 VkResult err = vkCreateBuffer(m_device->device(), &buffer_create_info, NULL, &buffer);
Dustin Gravesfd1c8fe2016-07-15 11:40:20 -0600936 ASSERT_VK_SUCCESS(err);
937
938 VkMemoryRequirements memory_reqs;
939 vkGetBufferMemoryRequirements(m_device->device(), buffer, &memory_reqs);
940
941 VkDedicatedAllocationMemoryAllocateInfoNV dedicated_memory_info = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600942 dedicated_memory_info.sType = VK_STRUCTURE_TYPE_DEDICATED_ALLOCATION_MEMORY_ALLOCATE_INFO_NV;
Dustin Gravesfd1c8fe2016-07-15 11:40:20 -0600943 dedicated_memory_info.pNext = nullptr;
944 dedicated_memory_info.buffer = buffer;
945 dedicated_memory_info.image = VK_NULL_HANDLE;
946
947 VkMemoryAllocateInfo memory_info = {};
948 memory_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
949 memory_info.pNext = &dedicated_memory_info;
950 memory_info.allocationSize = memory_reqs.size;
951
952 bool pass;
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600953 pass = m_device->phy().set_memory_type(memory_reqs.memoryTypeBits, &memory_info, 0);
Dustin Gravesfd1c8fe2016-07-15 11:40:20 -0600954 ASSERT_TRUE(pass);
955
956 VkDeviceMemory buffer_memory;
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600957 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &buffer_memory);
Dustin Gravesfd1c8fe2016-07-15 11:40:20 -0600958 ASSERT_VK_SUCCESS(err);
959
960 err = vkBindBufferMemory(m_device->device(), buffer, buffer_memory, 0);
961 ASSERT_VK_SUCCESS(err);
962
963 vkDestroyBuffer(m_device->device(), buffer, NULL);
964 vkFreeMemory(m_device->device(), buffer_memory, NULL);
965
966 m_errorMonitor->VerifyNotFound();
967 }
Dustin Gravesc99cf5a2016-05-09 14:40:29 -0600968}
Dustin Graves5d33d532016-05-09 16:21:12 -0600969
970TEST_F(VkLayerTest, UnrecognizedValue) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600971 TEST_DESCRIPTION("Specify unrecognized Vulkan enumeration, flags, and VkBool32 values");
Dustin Graves5d33d532016-05-09 16:21:12 -0600972
973 ASSERT_NO_FATAL_FAILURE(InitState());
974
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600975 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "does not fall within the begin..end "
976 "range of the core VkFormat "
977 "enumeration tokens");
Dustin Graves5d33d532016-05-09 16:21:12 -0600978 // Specify an invalid VkFormat value
979 // Expected to trigger an error with
980 // parameter_validation::validate_ranged_enum
981 VkFormatProperties format_properties;
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600982 vkGetPhysicalDeviceFormatProperties(gpu(), static_cast<VkFormat>(8000), &format_properties);
Dustin Graves5d33d532016-05-09 16:21:12 -0600983 m_errorMonitor->VerifyFound();
984
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600985 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "contains flag bits that are not recognized members of");
Dustin Graves5d33d532016-05-09 16:21:12 -0600986 // Specify an invalid VkFlags bitmask value
987 // Expected to trigger an error with parameter_validation::validate_flags
988 VkImageFormatProperties image_format_properties;
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600989 vkGetPhysicalDeviceImageFormatProperties(gpu(), VK_FORMAT_R8G8B8A8_UNORM, VK_IMAGE_TYPE_2D, VK_IMAGE_TILING_OPTIMAL,
990 static_cast<VkImageUsageFlags>(1 << 25), 0, &image_format_properties);
Dustin Graves5d33d532016-05-09 16:21:12 -0600991 m_errorMonitor->VerifyFound();
992
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600993 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "contains flag bits that are not recognized members of");
Dustin Graves5d33d532016-05-09 16:21:12 -0600994 // Specify an invalid VkFlags array entry
995 // Expected to trigger an error with
996 // parameter_validation::validate_flags_array
997 VkSemaphore semaphore = VK_NULL_HANDLE;
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600998 VkPipelineStageFlags stage_flags = static_cast<VkPipelineStageFlags>(1 << 25);
Dustin Graves5d33d532016-05-09 16:21:12 -0600999 VkSubmitInfo submit_info = {};
1000 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
1001 submit_info.waitSemaphoreCount = 1;
1002 submit_info.pWaitSemaphores = &semaphore;
1003 submit_info.pWaitDstStageMask = &stage_flags;
1004 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
1005 m_errorMonitor->VerifyFound();
1006
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001007 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT, "is neither VK_TRUE nor VK_FALSE");
Dustin Graves5d33d532016-05-09 16:21:12 -06001008 // Specify an invalid VkBool32 value
1009 // Expected to trigger a warning with
1010 // parameter_validation::validate_bool32
1011 VkSampler sampler = VK_NULL_HANDLE;
1012 VkSamplerCreateInfo sampler_info = {};
1013 sampler_info.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
1014 sampler_info.pNext = NULL;
1015 sampler_info.magFilter = VK_FILTER_NEAREST;
1016 sampler_info.minFilter = VK_FILTER_NEAREST;
1017 sampler_info.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
1018 sampler_info.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
1019 sampler_info.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
1020 sampler_info.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
1021 sampler_info.mipLodBias = 1.0;
1022 sampler_info.maxAnisotropy = 1;
1023 sampler_info.compareEnable = VK_FALSE;
1024 sampler_info.compareOp = VK_COMPARE_OP_NEVER;
1025 sampler_info.minLod = 1.0;
1026 sampler_info.maxLod = 1.0;
1027 sampler_info.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
1028 sampler_info.unnormalizedCoordinates = VK_FALSE;
1029 // Not VK_TRUE or VK_FALSE
1030 sampler_info.anisotropyEnable = 3;
1031 vkCreateSampler(m_device->device(), &sampler_info, NULL, &sampler);
1032 m_errorMonitor->VerifyFound();
1033}
Dustin Gravesfce74c02016-05-10 11:42:58 -06001034
1035TEST_F(VkLayerTest, FailedReturnValue) {
1036 TEST_DESCRIPTION("Check for a message describing a VkResult failure code");
1037
1038 ASSERT_NO_FATAL_FAILURE(InitState());
1039
Dustin Graves13c1e2b2016-05-16 15:31:02 -06001040 // Find an unsupported image format
1041 VkFormat unsupported = VK_FORMAT_UNDEFINED;
1042 for (int f = VK_FORMAT_BEGIN_RANGE; f <= VK_FORMAT_END_RANGE; f++) {
1043 VkFormat format = static_cast<VkFormat>(f);
1044 VkFormatProperties fProps = m_device->format_properties(format);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001045 if (format != VK_FORMAT_UNDEFINED && fProps.linearTilingFeatures == 0 && fProps.optimalTilingFeatures == 0) {
Dustin Graves13c1e2b2016-05-16 15:31:02 -06001046 unsupported = format;
1047 break;
1048 }
1049 }
1050
1051 if (unsupported != VK_FORMAT_UNDEFINED) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001052 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT,
1053 "the requested format is not supported on this device");
Dustin Graves13c1e2b2016-05-16 15:31:02 -06001054 // Specify an unsupported VkFormat value to generate a
1055 // VK_ERROR_FORMAT_NOT_SUPPORTED return code
1056 // Expected to trigger a warning from
1057 // parameter_validation::validate_result
1058 VkImageFormatProperties image_format_properties;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001059 VkResult err = vkGetPhysicalDeviceImageFormatProperties(gpu(), unsupported, VK_IMAGE_TYPE_2D, VK_IMAGE_TILING_OPTIMAL,
1060 VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT, 0, &image_format_properties);
Dustin Graves13c1e2b2016-05-16 15:31:02 -06001061 ASSERT_TRUE(err == VK_ERROR_FORMAT_NOT_SUPPORTED);
1062 m_errorMonitor->VerifyFound();
1063 }
Dustin Gravesfce74c02016-05-10 11:42:58 -06001064}
Mark Lobodzinskie090fef2016-06-09 17:04:56 -06001065
1066TEST_F(VkLayerTest, UpdateBufferAlignment) {
1067 TEST_DESCRIPTION("Check alignment parameters for vkCmdUpdateBuffer");
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001068 uint32_t updateData[] = {1, 2, 3, 4, 5, 6, 7, 8};
Mark Lobodzinskie090fef2016-06-09 17:04:56 -06001069
1070 ASSERT_NO_FATAL_FAILURE(InitState());
1071
1072 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
1073 vk_testing::Buffer buffer;
1074 buffer.init_as_dst(*m_device, (VkDeviceSize)20, reqs);
1075
1076 BeginCommandBuffer();
1077 // Introduce failure by using dstOffset that is not multiple of 4
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001078 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " is not a multiple of 4");
Mark Lobodzinskie090fef2016-06-09 17:04:56 -06001079 m_commandBuffer->UpdateBuffer(buffer.handle(), 1, 4, updateData);
1080 m_errorMonitor->VerifyFound();
1081
1082 // Introduce failure by using dataSize that is not multiple of 4
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001083 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " is not a multiple of 4");
Mark Lobodzinskie090fef2016-06-09 17:04:56 -06001084 m_commandBuffer->UpdateBuffer(buffer.handle(), 0, 6, updateData);
1085 m_errorMonitor->VerifyFound();
1086
1087 // Introduce failure by using dataSize that is < 0
1088 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001089 "must be greater than zero and less than or equal to 65536");
Mark Lobodzinskie090fef2016-06-09 17:04:56 -06001090 m_commandBuffer->UpdateBuffer(buffer.handle(), 0, -44, updateData);
1091 m_errorMonitor->VerifyFound();
1092
1093 // Introduce failure by using dataSize that is > 65536
1094 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001095 "must be greater than zero and less than or equal to 65536");
Mark Lobodzinskie090fef2016-06-09 17:04:56 -06001096 m_commandBuffer->UpdateBuffer(buffer.handle(), 0, 80000, updateData);
1097 m_errorMonitor->VerifyFound();
1098
1099 EndCommandBuffer();
1100}
1101
1102TEST_F(VkLayerTest, FillBufferAlignment) {
1103 TEST_DESCRIPTION("Check alignment parameters for vkCmdFillBuffer");
1104
1105 ASSERT_NO_FATAL_FAILURE(InitState());
1106
1107 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
1108 vk_testing::Buffer buffer;
1109 buffer.init_as_dst(*m_device, (VkDeviceSize)20, reqs);
1110
1111 BeginCommandBuffer();
1112
1113 // Introduce failure by using dstOffset that is not multiple of 4
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001114 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " is not a multiple of 4");
Mark Lobodzinskie090fef2016-06-09 17:04:56 -06001115 m_commandBuffer->FillBuffer(buffer.handle(), 1, 4, 0x11111111);
1116 m_errorMonitor->VerifyFound();
1117
1118 // Introduce failure by using size that is not multiple of 4
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001119 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " is not a multiple of 4");
Mark Lobodzinskie090fef2016-06-09 17:04:56 -06001120 m_commandBuffer->FillBuffer(buffer.handle(), 0, 6, 0x11111111);
1121 m_errorMonitor->VerifyFound();
1122
1123 // Introduce failure by using size that is zero
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001124 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "must be greater than zero");
Mark Lobodzinskie090fef2016-06-09 17:04:56 -06001125 m_commandBuffer->FillBuffer(buffer.handle(), 0, 0, 0x11111111);
1126 m_errorMonitor->VerifyFound();
1127
1128 EndCommandBuffer();
1129}
Dustin Graves40f35822016-06-23 11:12:53 -06001130
1131// This is a positive test. No failures are expected.
1132TEST_F(VkLayerTest, IgnoreUnrelatedDescriptor) {
1133 TEST_DESCRIPTION("Ensure that the vkUpdateDescriptorSet validation code "
1134 "is ignoring VkWriteDescriptorSet members that are not "
1135 "related to the descriptor type specified by "
1136 "VkWriteDescriptorSet::descriptorType. Correct "
1137 "validation behavior will result in the test running to "
1138 "completion without validation errors.");
1139
Dustin Graves5e2d8fc2016-07-07 16:18:49 -06001140 const uintptr_t invalid_ptr = 0xcdcdcdcd;
1141
Dustin Graves40f35822016-06-23 11:12:53 -06001142 ASSERT_NO_FATAL_FAILURE(InitState());
1143
1144 // Image Case
1145 {
1146 m_errorMonitor->ExpectSuccess();
1147
1148 VkImage image;
1149 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
1150 const int32_t tex_width = 32;
1151 const int32_t tex_height = 32;
1152 VkImageCreateInfo image_create_info = {};
1153 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
1154 image_create_info.pNext = NULL;
1155 image_create_info.imageType = VK_IMAGE_TYPE_2D;
1156 image_create_info.format = tex_format;
1157 image_create_info.extent.width = tex_width;
1158 image_create_info.extent.height = tex_height;
1159 image_create_info.extent.depth = 1;
1160 image_create_info.mipLevels = 1;
1161 image_create_info.arrayLayers = 1;
1162 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
Tobin Ehlis51cde412016-07-11 16:08:30 -06001163 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
Dustin Graves40f35822016-06-23 11:12:53 -06001164 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
1165 image_create_info.flags = 0;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001166 VkResult err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
Dustin Graves40f35822016-06-23 11:12:53 -06001167 ASSERT_VK_SUCCESS(err);
1168
1169 VkMemoryRequirements memory_reqs;
1170 VkDeviceMemory image_memory;
1171 bool pass;
1172 VkMemoryAllocateInfo memory_info = {};
1173 memory_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
1174 memory_info.pNext = NULL;
1175 memory_info.allocationSize = 0;
1176 memory_info.memoryTypeIndex = 0;
1177 vkGetImageMemoryRequirements(m_device->device(), image, &memory_reqs);
1178 memory_info.allocationSize = memory_reqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001179 pass = m_device->phy().set_memory_type(memory_reqs.memoryTypeBits, &memory_info, 0);
Dustin Graves40f35822016-06-23 11:12:53 -06001180 ASSERT_TRUE(pass);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001181 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &image_memory);
Dustin Graves40f35822016-06-23 11:12:53 -06001182 ASSERT_VK_SUCCESS(err);
1183 err = vkBindImageMemory(m_device->device(), image, image_memory, 0);
1184 ASSERT_VK_SUCCESS(err);
1185
1186 VkImageViewCreateInfo image_view_create_info = {};
1187 image_view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
1188 image_view_create_info.image = image;
1189 image_view_create_info.viewType = VK_IMAGE_VIEW_TYPE_2D;
1190 image_view_create_info.format = tex_format;
1191 image_view_create_info.subresourceRange.layerCount = 1;
1192 image_view_create_info.subresourceRange.baseMipLevel = 0;
1193 image_view_create_info.subresourceRange.levelCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001194 image_view_create_info.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Dustin Graves40f35822016-06-23 11:12:53 -06001195
1196 VkImageView view;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001197 err = vkCreateImageView(m_device->device(), &image_view_create_info, NULL, &view);
Dustin Graves40f35822016-06-23 11:12:53 -06001198 ASSERT_VK_SUCCESS(err);
1199
1200 VkDescriptorPoolSize ds_type_count = {};
1201 ds_type_count.type = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE;
1202 ds_type_count.descriptorCount = 1;
1203
1204 VkDescriptorPoolCreateInfo ds_pool_ci = {};
1205 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
1206 ds_pool_ci.pNext = NULL;
1207 ds_pool_ci.maxSets = 1;
1208 ds_pool_ci.poolSizeCount = 1;
1209 ds_pool_ci.pPoolSizes = &ds_type_count;
1210
1211 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001212 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Dustin Graves40f35822016-06-23 11:12:53 -06001213 ASSERT_VK_SUCCESS(err);
1214
1215 VkDescriptorSetLayoutBinding dsl_binding = {};
1216 dsl_binding.binding = 0;
1217 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE;
1218 dsl_binding.descriptorCount = 1;
1219 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
1220 dsl_binding.pImmutableSamplers = NULL;
1221
1222 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001223 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
Dustin Graves40f35822016-06-23 11:12:53 -06001224 ds_layout_ci.pNext = NULL;
1225 ds_layout_ci.bindingCount = 1;
1226 ds_layout_ci.pBindings = &dsl_binding;
1227 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001228 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Dustin Graves40f35822016-06-23 11:12:53 -06001229 ASSERT_VK_SUCCESS(err);
1230
1231 VkDescriptorSet descriptor_set;
1232 VkDescriptorSetAllocateInfo alloc_info = {};
1233 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
1234 alloc_info.descriptorSetCount = 1;
1235 alloc_info.descriptorPool = ds_pool;
1236 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001237 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
Dustin Graves40f35822016-06-23 11:12:53 -06001238 ASSERT_VK_SUCCESS(err);
1239
1240 VkDescriptorImageInfo image_info = {};
1241 image_info.imageView = view;
1242 image_info.imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
1243
1244 VkWriteDescriptorSet descriptor_write;
1245 memset(&descriptor_write, 0, sizeof(descriptor_write));
1246 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
1247 descriptor_write.dstSet = descriptor_set;
1248 descriptor_write.dstBinding = 0;
1249 descriptor_write.descriptorCount = 1;
1250 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE;
1251 descriptor_write.pImageInfo = &image_info;
1252
1253 // Set pBufferInfo and pTexelBufferView to invalid values, which should
1254 // be
1255 // ignored for descriptorType == VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE.
1256 // This will most likely produce a crash if the parameter_validation
1257 // layer
1258 // does not correctly ignore pBufferInfo.
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001259 descriptor_write.pBufferInfo = reinterpret_cast<const VkDescriptorBufferInfo *>(invalid_ptr);
1260 descriptor_write.pTexelBufferView = reinterpret_cast<const VkBufferView *>(invalid_ptr);
Dustin Graves40f35822016-06-23 11:12:53 -06001261
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001262 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
Dustin Graves40f35822016-06-23 11:12:53 -06001263
1264 m_errorMonitor->VerifyNotFound();
1265
Dustin Graves40f35822016-06-23 11:12:53 -06001266 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
1267 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
1268 vkDestroyImageView(m_device->device(), view, NULL);
1269 vkDestroyImage(m_device->device(), image, NULL);
1270 vkFreeMemory(m_device->device(), image_memory, NULL);
1271 }
1272
1273 // Buffer Case
1274 {
1275 m_errorMonitor->ExpectSuccess();
1276
1277 VkBuffer buffer;
1278 uint32_t queue_family_index = 0;
1279 VkBufferCreateInfo buffer_create_info = {};
1280 buffer_create_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
1281 buffer_create_info.size = 1024;
1282 buffer_create_info.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
1283 buffer_create_info.queueFamilyIndexCount = 1;
1284 buffer_create_info.pQueueFamilyIndices = &queue_family_index;
1285
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001286 VkResult err = vkCreateBuffer(m_device->device(), &buffer_create_info, NULL, &buffer);
Dustin Graves40f35822016-06-23 11:12:53 -06001287 ASSERT_VK_SUCCESS(err);
1288
1289 VkMemoryRequirements memory_reqs;
1290 VkDeviceMemory buffer_memory;
1291 bool pass;
1292 VkMemoryAllocateInfo memory_info = {};
1293 memory_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
1294 memory_info.pNext = NULL;
1295 memory_info.allocationSize = 0;
1296 memory_info.memoryTypeIndex = 0;
1297
1298 vkGetBufferMemoryRequirements(m_device->device(), buffer, &memory_reqs);
1299 memory_info.allocationSize = memory_reqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001300 pass = m_device->phy().set_memory_type(memory_reqs.memoryTypeBits, &memory_info, 0);
Dustin Graves40f35822016-06-23 11:12:53 -06001301 ASSERT_TRUE(pass);
1302
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001303 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &buffer_memory);
Dustin Graves40f35822016-06-23 11:12:53 -06001304 ASSERT_VK_SUCCESS(err);
1305 err = vkBindBufferMemory(m_device->device(), buffer, buffer_memory, 0);
1306 ASSERT_VK_SUCCESS(err);
1307
1308 VkDescriptorPoolSize ds_type_count = {};
1309 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
1310 ds_type_count.descriptorCount = 1;
1311
1312 VkDescriptorPoolCreateInfo ds_pool_ci = {};
1313 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
1314 ds_pool_ci.pNext = NULL;
1315 ds_pool_ci.maxSets = 1;
1316 ds_pool_ci.poolSizeCount = 1;
1317 ds_pool_ci.pPoolSizes = &ds_type_count;
1318
1319 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001320 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Dustin Graves40f35822016-06-23 11:12:53 -06001321 ASSERT_VK_SUCCESS(err);
1322
1323 VkDescriptorSetLayoutBinding dsl_binding = {};
1324 dsl_binding.binding = 0;
1325 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
1326 dsl_binding.descriptorCount = 1;
1327 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
1328 dsl_binding.pImmutableSamplers = NULL;
1329
1330 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001331 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
Dustin Graves40f35822016-06-23 11:12:53 -06001332 ds_layout_ci.pNext = NULL;
1333 ds_layout_ci.bindingCount = 1;
1334 ds_layout_ci.pBindings = &dsl_binding;
1335 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001336 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Dustin Graves40f35822016-06-23 11:12:53 -06001337 ASSERT_VK_SUCCESS(err);
1338
1339 VkDescriptorSet descriptor_set;
1340 VkDescriptorSetAllocateInfo alloc_info = {};
1341 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
1342 alloc_info.descriptorSetCount = 1;
1343 alloc_info.descriptorPool = ds_pool;
1344 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001345 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
Dustin Graves40f35822016-06-23 11:12:53 -06001346 ASSERT_VK_SUCCESS(err);
1347
1348 VkDescriptorBufferInfo buffer_info = {};
1349 buffer_info.buffer = buffer;
1350 buffer_info.offset = 0;
1351 buffer_info.range = 1024;
1352
1353 VkWriteDescriptorSet descriptor_write;
1354 memset(&descriptor_write, 0, sizeof(descriptor_write));
1355 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
1356 descriptor_write.dstSet = descriptor_set;
1357 descriptor_write.dstBinding = 0;
1358 descriptor_write.descriptorCount = 1;
1359 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
1360 descriptor_write.pBufferInfo = &buffer_info;
1361
1362 // Set pImageInfo and pTexelBufferView to invalid values, which should
1363 // be
1364 // ignored for descriptorType == VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER.
1365 // This will most likely produce a crash if the parameter_validation
1366 // layer
1367 // does not correctly ignore pImageInfo.
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001368 descriptor_write.pImageInfo = reinterpret_cast<const VkDescriptorImageInfo *>(invalid_ptr);
1369 descriptor_write.pTexelBufferView = reinterpret_cast<const VkBufferView *>(invalid_ptr);
Dustin Graves40f35822016-06-23 11:12:53 -06001370
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001371 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
Dustin Graves40f35822016-06-23 11:12:53 -06001372
1373 m_errorMonitor->VerifyNotFound();
1374
1375 vkFreeDescriptorSets(m_device->device(), ds_pool, 1, &descriptor_set);
1376 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
1377 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
1378 vkDestroyBuffer(m_device->device(), buffer, NULL);
1379 vkFreeMemory(m_device->device(), buffer_memory, NULL);
1380 }
1381
1382 // Texel Buffer Case
1383 {
1384 m_errorMonitor->ExpectSuccess();
1385
1386 VkBuffer buffer;
1387 uint32_t queue_family_index = 0;
1388 VkBufferCreateInfo buffer_create_info = {};
1389 buffer_create_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
1390 buffer_create_info.size = 1024;
1391 buffer_create_info.usage = VK_BUFFER_USAGE_STORAGE_TEXEL_BUFFER_BIT;
1392 buffer_create_info.queueFamilyIndexCount = 1;
1393 buffer_create_info.pQueueFamilyIndices = &queue_family_index;
1394
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001395 VkResult err = vkCreateBuffer(m_device->device(), &buffer_create_info, NULL, &buffer);
Dustin Graves40f35822016-06-23 11:12:53 -06001396 ASSERT_VK_SUCCESS(err);
1397
1398 VkMemoryRequirements memory_reqs;
1399 VkDeviceMemory buffer_memory;
1400 bool pass;
1401 VkMemoryAllocateInfo memory_info = {};
1402 memory_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
1403 memory_info.pNext = NULL;
1404 memory_info.allocationSize = 0;
1405 memory_info.memoryTypeIndex = 0;
1406
1407 vkGetBufferMemoryRequirements(m_device->device(), buffer, &memory_reqs);
1408 memory_info.allocationSize = memory_reqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001409 pass = m_device->phy().set_memory_type(memory_reqs.memoryTypeBits, &memory_info, 0);
Dustin Graves40f35822016-06-23 11:12:53 -06001410 ASSERT_TRUE(pass);
1411
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001412 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &buffer_memory);
Dustin Graves40f35822016-06-23 11:12:53 -06001413 ASSERT_VK_SUCCESS(err);
1414 err = vkBindBufferMemory(m_device->device(), buffer, buffer_memory, 0);
1415 ASSERT_VK_SUCCESS(err);
1416
1417 VkBufferViewCreateInfo buff_view_ci = {};
1418 buff_view_ci.sType = VK_STRUCTURE_TYPE_BUFFER_VIEW_CREATE_INFO;
1419 buff_view_ci.buffer = buffer;
1420 buff_view_ci.format = VK_FORMAT_R8_UNORM;
1421 buff_view_ci.range = VK_WHOLE_SIZE;
1422 VkBufferView buffer_view;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001423 err = vkCreateBufferView(m_device->device(), &buff_view_ci, NULL, &buffer_view);
Dustin Graves40f35822016-06-23 11:12:53 -06001424
1425 VkDescriptorPoolSize ds_type_count = {};
1426 ds_type_count.type = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
1427 ds_type_count.descriptorCount = 1;
1428
1429 VkDescriptorPoolCreateInfo ds_pool_ci = {};
1430 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
1431 ds_pool_ci.pNext = NULL;
1432 ds_pool_ci.maxSets = 1;
1433 ds_pool_ci.poolSizeCount = 1;
1434 ds_pool_ci.pPoolSizes = &ds_type_count;
1435
1436 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001437 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Dustin Graves40f35822016-06-23 11:12:53 -06001438 ASSERT_VK_SUCCESS(err);
1439
1440 VkDescriptorSetLayoutBinding dsl_binding = {};
1441 dsl_binding.binding = 0;
1442 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
1443 dsl_binding.descriptorCount = 1;
1444 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
1445 dsl_binding.pImmutableSamplers = NULL;
1446
1447 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001448 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
Dustin Graves40f35822016-06-23 11:12:53 -06001449 ds_layout_ci.pNext = NULL;
1450 ds_layout_ci.bindingCount = 1;
1451 ds_layout_ci.pBindings = &dsl_binding;
1452 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001453 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Dustin Graves40f35822016-06-23 11:12:53 -06001454 ASSERT_VK_SUCCESS(err);
1455
1456 VkDescriptorSet descriptor_set;
1457 VkDescriptorSetAllocateInfo alloc_info = {};
1458 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
1459 alloc_info.descriptorSetCount = 1;
1460 alloc_info.descriptorPool = ds_pool;
1461 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001462 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
Dustin Graves40f35822016-06-23 11:12:53 -06001463 ASSERT_VK_SUCCESS(err);
1464
1465 VkWriteDescriptorSet descriptor_write;
1466 memset(&descriptor_write, 0, sizeof(descriptor_write));
1467 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
1468 descriptor_write.dstSet = descriptor_set;
1469 descriptor_write.dstBinding = 0;
1470 descriptor_write.descriptorCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001471 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
Dustin Graves40f35822016-06-23 11:12:53 -06001472 descriptor_write.pTexelBufferView = &buffer_view;
1473
1474 // Set pImageInfo and pBufferInfo to invalid values, which should be
1475 // ignored for descriptorType ==
1476 // VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER.
1477 // This will most likely produce a crash if the parameter_validation
1478 // layer
1479 // does not correctly ignore pImageInfo and pBufferInfo.
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001480 descriptor_write.pImageInfo = reinterpret_cast<const VkDescriptorImageInfo *>(invalid_ptr);
1481 descriptor_write.pBufferInfo = reinterpret_cast<const VkDescriptorBufferInfo *>(invalid_ptr);
Dustin Graves40f35822016-06-23 11:12:53 -06001482
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001483 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
Dustin Graves40f35822016-06-23 11:12:53 -06001484
1485 m_errorMonitor->VerifyNotFound();
1486
1487 vkFreeDescriptorSets(m_device->device(), ds_pool, 1, &descriptor_set);
1488 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
1489 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
1490 vkDestroyBufferView(m_device->device(), buffer_view, NULL);
1491 vkDestroyBuffer(m_device->device(), buffer, NULL);
1492 vkFreeMemory(m_device->device(), buffer_memory, NULL);
1493 }
1494}
Cortd889ff92016-07-27 09:51:27 -07001495
1496TEST_F(VkLayerTest, PSOPolygonModeInvalid) {
1497 VkResult err;
1498
1499 TEST_DESCRIPTION("Attempt to use a non-solid polygon fill mode in a "
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001500 "pipeline when this feature is not enabled.");
Cortd889ff92016-07-27 09:51:27 -07001501
1502 ASSERT_NO_FATAL_FAILURE(InitState());
1503 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
1504
1505 std::vector<const char *> device_extension_names;
1506 auto features = m_device->phy().features();
1507 // Artificially disable support for non-solid fill modes
1508 features.fillModeNonSolid = false;
1509 // The sacrificial device object
1510 VkDeviceObj test_device(0, gpu(), device_extension_names, &features);
1511
1512 VkRenderpassObj render_pass(&test_device);
1513
1514 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
1515 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
1516 pipeline_layout_ci.setLayoutCount = 0;
1517 pipeline_layout_ci.pSetLayouts = NULL;
1518
1519 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001520 err = vkCreatePipelineLayout(test_device.device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Cortd889ff92016-07-27 09:51:27 -07001521 ASSERT_VK_SUCCESS(err);
1522
1523 VkPipelineRasterizationStateCreateInfo rs_ci = {};
1524 rs_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
1525 rs_ci.pNext = nullptr;
1526 rs_ci.lineWidth = 1.0f;
1527 rs_ci.rasterizerDiscardEnable = true;
1528
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001529 VkShaderObj vs(&test_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
1530 VkShaderObj fs(&test_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Cortd889ff92016-07-27 09:51:27 -07001531
Mark Lobodzinski5e644732016-08-15 16:51:19 -06001532 // Set polygonMode to unsupported value POINT, should fail
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001533 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
1534 "polygonMode cannot be VK_POLYGON_MODE_POINT or VK_POLYGON_MODE_LINE");
Cortd889ff92016-07-27 09:51:27 -07001535 {
1536 VkPipelineObj pipe(&test_device);
1537 pipe.AddShader(&vs);
1538 pipe.AddShader(&fs);
1539 pipe.AddColorAttachment();
1540 // Introduce failure by setting unsupported polygon mode
1541 rs_ci.polygonMode = VK_POLYGON_MODE_POINT;
1542 pipe.SetRasterization(&rs_ci);
1543 pipe.CreateVKPipeline(pipeline_layout, render_pass.handle());
1544 }
1545 m_errorMonitor->VerifyFound();
1546
1547 // Try again with polygonMode=LINE, should fail
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001548 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
1549 "polygonMode cannot be VK_POLYGON_MODE_POINT or VK_POLYGON_MODE_LINE");
Cortd889ff92016-07-27 09:51:27 -07001550 {
1551 VkPipelineObj pipe(&test_device);
1552 pipe.AddShader(&vs);
1553 pipe.AddShader(&fs);
1554 pipe.AddColorAttachment();
1555 // Introduce failure by setting unsupported polygon mode
1556 rs_ci.polygonMode = VK_POLYGON_MODE_LINE;
1557 pipe.SetRasterization(&rs_ci);
1558 pipe.CreateVKPipeline(pipeline_layout, render_pass.handle());
1559 }
1560 m_errorMonitor->VerifyFound();
1561
1562 // Try again with polygonMode=FILL. No error is expected
1563 m_errorMonitor->ExpectSuccess();
1564 {
1565 VkPipelineObj pipe(&test_device);
1566 pipe.AddShader(&vs);
1567 pipe.AddShader(&fs);
1568 pipe.AddColorAttachment();
1569 // Set polygonMode to a good value
1570 rs_ci.polygonMode = VK_POLYGON_MODE_FILL;
1571 pipe.SetRasterization(&rs_ci);
1572 pipe.CreateVKPipeline(pipeline_layout, render_pass.handle());
1573 }
1574 m_errorMonitor->VerifyNotFound();
1575
1576 vkDestroyPipelineLayout(test_device.device(), pipeline_layout, NULL);
1577}
1578
Dustin Gravesffa90fa2016-05-06 11:20:38 -06001579#endif // PARAMETER_VALIDATION_TESTS
1580
Tobin Ehlis0788f522015-05-26 16:11:58 -06001581#if MEM_TRACKER_TESTS
Tobin Ehlis8fab6562015-12-01 09:57:09 -07001582#if 0
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001583TEST_F(VkLayerTest, CallResetCommandBufferBeforeCompletion)
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001584{
1585 vk_testing::Fence testFence;
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001586 VkFenceCreateInfo fenceInfo = {};
1587 fenceInfo.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
1588 fenceInfo.pNext = NULL;
1589 fenceInfo.flags = 0;
1590
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07001591 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Resetting CB");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06001592
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001593 ASSERT_NO_FATAL_FAILURE(InitState());
Tony Barbourc1eb1a52015-07-20 13:00:10 -06001594
1595 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
1596 vk_testing::Buffer buffer;
1597 buffer.init_as_dst(*m_device, (VkDeviceSize)20, reqs);
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001598
Tony Barbourfe3351b2015-07-28 10:17:20 -06001599 BeginCommandBuffer();
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001600 m_commandBuffer->FillBuffer(buffer.handle(), 0, 4, 0x11111111);
Tony Barbourfe3351b2015-07-28 10:17:20 -06001601 EndCommandBuffer();
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001602
1603 testFence.init(*m_device, fenceInfo);
1604
1605 // Bypass framework since it does the waits automatically
1606 VkResult err = VK_SUCCESS;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06001607 VkSubmitInfo submit_info;
Chia-I Wuf9be13c2015-10-26 20:37:06 +08001608 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
1609 submit_info.pNext = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08001610 submit_info.waitSemaphoreCount = 0;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06001611 submit_info.pWaitSemaphores = NULL;
Jon Ashburn7f9716c2015-12-30 16:42:50 -07001612 submit_info.pWaitDstStageMask = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08001613 submit_info.commandBufferCount = 1;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001614 submit_info.pCommandBuffers = &m_commandBuffer->handle();
Chia-I Wud50a7d72015-10-26 20:48:51 +08001615 submit_info.signalSemaphoreCount = 0;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06001616 submit_info.pSignalSemaphores = NULL;
Courtney Goeltzenleuchter646b9072015-10-20 18:04:07 -06001617
1618 err = vkQueueSubmit( m_device->m_queue, 1, &submit_info, testFence.handle());
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001619 ASSERT_VK_SUCCESS( err );
1620
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001621 // Introduce failure by calling begin again before checking fence
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001622 vkResetCommandBuffer(m_commandBuffer->handle(), 0);
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001623
Chris Forbes8f36a8a2016-04-07 13:21:07 +12001624 m_errorMonitor->VerifyFound();
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001625}
1626
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001627TEST_F(VkLayerTest, CallBeginCommandBufferBeforeCompletion)
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001628{
1629 vk_testing::Fence testFence;
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001630 VkFenceCreateInfo fenceInfo = {};
1631 fenceInfo.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
1632 fenceInfo.pNext = NULL;
1633 fenceInfo.flags = 0;
1634
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07001635 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Calling vkBeginCommandBuffer() on active CB");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06001636
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001637 ASSERT_NO_FATAL_FAILURE(InitState());
1638 ASSERT_NO_FATAL_FAILURE(InitViewport());
1639 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
1640
Tony Barbourfe3351b2015-07-28 10:17:20 -06001641 BeginCommandBuffer();
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001642 m_commandBuffer->ClearAllBuffers(m_clear_color, m_depth_clear_color, m_stencil_clear_color, NULL);
Tony Barbourfe3351b2015-07-28 10:17:20 -06001643 EndCommandBuffer();
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001644
1645 testFence.init(*m_device, fenceInfo);
1646
1647 // Bypass framework since it does the waits automatically
1648 VkResult err = VK_SUCCESS;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06001649 VkSubmitInfo submit_info;
Chia-I Wuf9be13c2015-10-26 20:37:06 +08001650 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
1651 submit_info.pNext = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08001652 submit_info.waitSemaphoreCount = 0;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06001653 submit_info.pWaitSemaphores = NULL;
Jon Ashburn7f9716c2015-12-30 16:42:50 -07001654 submit_info.pWaitDstStageMask = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08001655 submit_info.commandBufferCount = 1;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001656 submit_info.pCommandBuffers = &m_commandBuffer->handle();
Chia-I Wud50a7d72015-10-26 20:48:51 +08001657 submit_info.signalSemaphoreCount = 0;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06001658 submit_info.pSignalSemaphores = NULL;
Courtney Goeltzenleuchter646b9072015-10-20 18:04:07 -06001659
1660 err = vkQueueSubmit( m_device->m_queue, 1, &submit_info, testFence.handle());
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001661 ASSERT_VK_SUCCESS( err );
1662
Jon Ashburnf19916e2016-01-11 13:12:43 -07001663 VkCommandBufferInheritanceInfo hinfo = {};
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001664 VkCommandBufferBeginInfo info = {};
1665 info.flags = VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT;
1666 info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
Mark Lobodzinski5fcc4212015-09-14 17:43:42 -06001667 info.renderPass = VK_NULL_HANDLE;
1668 info.subpass = 0;
1669 info.framebuffer = VK_NULL_HANDLE;
Chia-I Wub8d47ae2015-11-11 10:18:12 +08001670 info.occlusionQueryEnable = VK_FALSE;
1671 info.queryFlags = 0;
1672 info.pipelineStatistics = 0;
Mark Lobodzinski5fcc4212015-09-14 17:43:42 -06001673
1674 // Introduce failure by calling BCB again before checking fence
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001675 vkBeginCommandBuffer(m_commandBuffer->handle(), &info);
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001676
Chris Forbes8f36a8a2016-04-07 13:21:07 +12001677 m_errorMonitor->VerifyFound();
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001678}
Tobin Ehlis8fab6562015-12-01 09:57:09 -07001679#endif
Chris Forbes8f36a8a2016-04-07 13:21:07 +12001680
Mark Lobodzinski152fe252016-05-03 16:49:15 -06001681// This is a positive test. No failures are expected.
1682TEST_F(VkLayerTest, TestAliasedMemoryTracking) {
1683 VkResult err;
1684 bool pass;
1685
1686 TEST_DESCRIPTION("Create a buffer, allocate memory, bind memory, destroy "
1687 "the buffer, create an image, and bind the same memory to "
1688 "it");
1689
1690 m_errorMonitor->ExpectSuccess();
1691
1692 ASSERT_NO_FATAL_FAILURE(InitState());
1693
1694 VkBuffer buffer;
1695 VkImage image;
1696 VkDeviceMemory mem;
1697 VkMemoryRequirements mem_reqs;
1698
1699 VkBufferCreateInfo buf_info = {};
1700 buf_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
1701 buf_info.pNext = NULL;
1702 buf_info.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
1703 buf_info.size = 256;
1704 buf_info.queueFamilyIndexCount = 0;
1705 buf_info.pQueueFamilyIndices = NULL;
1706 buf_info.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
1707 buf_info.flags = 0;
1708 err = vkCreateBuffer(m_device->device(), &buf_info, NULL, &buffer);
1709 ASSERT_VK_SUCCESS(err);
1710
1711 vkGetBufferMemoryRequirements(m_device->device(), buffer, &mem_reqs);
1712
1713 VkMemoryAllocateInfo alloc_info = {};
1714 alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
1715 alloc_info.pNext = NULL;
1716 alloc_info.memoryTypeIndex = 0;
1717
1718 // Ensure memory is big enough for both bindings
1719 alloc_info.allocationSize = 0x10000;
1720
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001721 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &alloc_info, VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT);
Mark Lobodzinski152fe252016-05-03 16:49:15 -06001722 if (!pass) {
1723 vkDestroyBuffer(m_device->device(), buffer, NULL);
1724 return;
1725 }
1726
1727 err = vkAllocateMemory(m_device->device(), &alloc_info, NULL, &mem);
1728 ASSERT_VK_SUCCESS(err);
1729
1730 uint8_t *pData;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001731 err = vkMapMemory(m_device->device(), mem, 0, mem_reqs.size, 0, (void **)&pData);
Mark Lobodzinski152fe252016-05-03 16:49:15 -06001732 ASSERT_VK_SUCCESS(err);
1733
Mark Lobodzinski2abefa92016-05-05 11:45:57 -06001734 memset(pData, 0xCADECADE, static_cast<size_t>(mem_reqs.size));
Mark Lobodzinski152fe252016-05-03 16:49:15 -06001735
1736 vkUnmapMemory(m_device->device(), mem);
1737
1738 err = vkBindBufferMemory(m_device->device(), buffer, mem, 0);
1739 ASSERT_VK_SUCCESS(err);
1740
1741 // NOW, destroy the buffer. Obviously, the resource no longer occupies this
1742 // memory. In fact, it was never used by the GPU.
1743 // Just be be sure, wait for idle.
1744 vkDestroyBuffer(m_device->device(), buffer, NULL);
1745 vkDeviceWaitIdle(m_device->device());
1746
1747 VkImageCreateInfo image_create_info = {};
1748 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
1749 image_create_info.pNext = NULL;
1750 image_create_info.imageType = VK_IMAGE_TYPE_2D;
1751 image_create_info.format = VK_FORMAT_R8G8B8A8_UNORM;
1752 image_create_info.extent.width = 64;
1753 image_create_info.extent.height = 64;
1754 image_create_info.extent.depth = 1;
1755 image_create_info.mipLevels = 1;
1756 image_create_info.arrayLayers = 1;
1757 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
1758 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
1759 image_create_info.initialLayout = VK_IMAGE_LAYOUT_PREINITIALIZED;
1760 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
1761 image_create_info.queueFamilyIndexCount = 0;
1762 image_create_info.pQueueFamilyIndices = NULL;
1763 image_create_info.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
1764 image_create_info.flags = 0;
1765
1766 VkMemoryAllocateInfo mem_alloc = {};
1767 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
1768 mem_alloc.pNext = NULL;
1769 mem_alloc.allocationSize = 0;
1770 mem_alloc.memoryTypeIndex = 0;
1771
1772 /* Create a mappable image. It will be the texture if linear images are ok
1773 * to be textures or it will be the staging image if they are not.
1774 */
1775 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
1776 ASSERT_VK_SUCCESS(err);
1777
1778 vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs);
1779
1780 mem_alloc.allocationSize = mem_reqs.size;
1781
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001782 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT);
Mark Lobodzinski152fe252016-05-03 16:49:15 -06001783 if (!pass) {
1784 vkDestroyImage(m_device->device(), image, NULL);
1785 return;
1786 }
1787
Tobin Ehlis077ded32016-05-12 17:39:13 -06001788 // VALIDATION FAILURE:
Mark Lobodzinski152fe252016-05-03 16:49:15 -06001789 err = vkBindImageMemory(m_device->device(), image, mem, 0);
1790 ASSERT_VK_SUCCESS(err);
1791
1792 m_errorMonitor->VerifyNotFound();
1793
Tony Barbourdf4c0042016-06-01 15:55:43 -06001794 vkFreeMemory(m_device->device(), mem, NULL);
Mark Lobodzinski152fe252016-05-03 16:49:15 -06001795 vkDestroyBuffer(m_device->device(), buffer, NULL);
1796 vkDestroyImage(m_device->device(), image, NULL);
1797}
1798
Tobin Ehlisf11be982016-05-11 13:52:53 -06001799TEST_F(VkLayerTest, InvalidMemoryAliasing) {
1800 TEST_DESCRIPTION("Create a buffer and image, allocate memory, and bind the "
1801 "buffer and image to memory such that they will alias.");
1802 VkResult err;
1803 bool pass;
1804 ASSERT_NO_FATAL_FAILURE(InitState());
1805
Tobin Ehlis077ded32016-05-12 17:39:13 -06001806 VkBuffer buffer, buffer2;
Tobin Ehlisf11be982016-05-11 13:52:53 -06001807 VkImage image;
1808 VkDeviceMemory mem; // buffer will be bound first
1809 VkDeviceMemory mem_img; // image bound first
Tobin Ehlis077ded32016-05-12 17:39:13 -06001810 VkMemoryRequirements buff_mem_reqs, img_mem_reqs;
Tobin Ehlisf11be982016-05-11 13:52:53 -06001811
1812 VkBufferCreateInfo buf_info = {};
1813 buf_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
1814 buf_info.pNext = NULL;
1815 buf_info.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
1816 buf_info.size = 256;
1817 buf_info.queueFamilyIndexCount = 0;
1818 buf_info.pQueueFamilyIndices = NULL;
1819 buf_info.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
1820 buf_info.flags = 0;
1821 err = vkCreateBuffer(m_device->device(), &buf_info, NULL, &buffer);
1822 ASSERT_VK_SUCCESS(err);
1823
Tobin Ehlis077ded32016-05-12 17:39:13 -06001824 vkGetBufferMemoryRequirements(m_device->device(), buffer, &buff_mem_reqs);
Tobin Ehlisf11be982016-05-11 13:52:53 -06001825
1826 VkImageCreateInfo image_create_info = {};
1827 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
1828 image_create_info.pNext = NULL;
1829 image_create_info.imageType = VK_IMAGE_TYPE_2D;
1830 image_create_info.format = VK_FORMAT_R8G8B8A8_UNORM;
1831 image_create_info.extent.width = 64;
1832 image_create_info.extent.height = 64;
1833 image_create_info.extent.depth = 1;
1834 image_create_info.mipLevels = 1;
1835 image_create_info.arrayLayers = 1;
1836 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
Tobin Ehlis12a4b5e2016-08-08 12:33:11 -06001837 // Image tiling must be optimal to trigger error when aliasing linear buffer
1838 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
Tobin Ehlisf11be982016-05-11 13:52:53 -06001839 image_create_info.initialLayout = VK_IMAGE_LAYOUT_PREINITIALIZED;
1840 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
1841 image_create_info.queueFamilyIndexCount = 0;
1842 image_create_info.pQueueFamilyIndices = NULL;
1843 image_create_info.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
1844 image_create_info.flags = 0;
1845
Tobin Ehlisf11be982016-05-11 13:52:53 -06001846 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
1847 ASSERT_VK_SUCCESS(err);
1848
Tobin Ehlis077ded32016-05-12 17:39:13 -06001849 vkGetImageMemoryRequirements(m_device->device(), image, &img_mem_reqs);
1850
1851 VkMemoryAllocateInfo alloc_info = {};
1852 alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
1853 alloc_info.pNext = NULL;
1854 alloc_info.memoryTypeIndex = 0;
1855 // Ensure memory is big enough for both bindings
1856 alloc_info.allocationSize = buff_mem_reqs.size + img_mem_reqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001857 pass = m_device->phy().set_memory_type(buff_mem_reqs.memoryTypeBits & img_mem_reqs.memoryTypeBits, &alloc_info,
1858 VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT);
Tobin Ehlisf11be982016-05-11 13:52:53 -06001859 if (!pass) {
Tobin Ehlis077ded32016-05-12 17:39:13 -06001860 vkDestroyBuffer(m_device->device(), buffer, NULL);
Tobin Ehlisf11be982016-05-11 13:52:53 -06001861 vkDestroyImage(m_device->device(), image, NULL);
1862 return;
1863 }
Tobin Ehlis077ded32016-05-12 17:39:13 -06001864 err = vkAllocateMemory(m_device->device(), &alloc_info, NULL, &mem);
1865 ASSERT_VK_SUCCESS(err);
1866 err = vkBindBufferMemory(m_device->device(), buffer, mem, 0);
1867 ASSERT_VK_SUCCESS(err);
1868
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001869 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " is aliased with linear buffer 0x");
Tobin Ehlis077ded32016-05-12 17:39:13 -06001870 // VALIDATION FAILURE due to image mapping overlapping buffer mapping
Tobin Ehlisf11be982016-05-11 13:52:53 -06001871 err = vkBindImageMemory(m_device->device(), image, mem, 0);
1872 m_errorMonitor->VerifyFound();
1873
1874 // Now correctly bind image to second mem allocation before incorrectly
Tobin Ehlis077ded32016-05-12 17:39:13 -06001875 // aliasing buffer2
1876 err = vkCreateBuffer(m_device->device(), &buf_info, NULL, &buffer2);
1877 ASSERT_VK_SUCCESS(err);
Tobin Ehlisf11be982016-05-11 13:52:53 -06001878 err = vkAllocateMemory(m_device->device(), &alloc_info, NULL, &mem_img);
1879 ASSERT_VK_SUCCESS(err);
1880 err = vkBindImageMemory(m_device->device(), image, mem_img, 0);
1881 ASSERT_VK_SUCCESS(err);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001882 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "is aliased with non-linear image 0x");
Tobin Ehlis077ded32016-05-12 17:39:13 -06001883 err = vkBindBufferMemory(m_device->device(), buffer2, mem_img, 0);
Tobin Ehlisf11be982016-05-11 13:52:53 -06001884 m_errorMonitor->VerifyFound();
1885
1886 vkDestroyBuffer(m_device->device(), buffer, NULL);
Tobin Ehlis077ded32016-05-12 17:39:13 -06001887 vkDestroyBuffer(m_device->device(), buffer2, NULL);
Tobin Ehlisf11be982016-05-11 13:52:53 -06001888 vkDestroyImage(m_device->device(), image, NULL);
1889 vkFreeMemory(m_device->device(), mem, NULL);
1890 vkFreeMemory(m_device->device(), mem_img, NULL);
1891}
1892
Tobin Ehlis35372522016-05-12 08:32:31 -06001893TEST_F(VkLayerTest, InvalidMemoryMapping) {
1894 TEST_DESCRIPTION("Attempt to map memory in a number of incorrect ways");
1895 VkResult err;
1896 bool pass;
1897 ASSERT_NO_FATAL_FAILURE(InitState());
1898
1899 VkBuffer buffer;
1900 VkDeviceMemory mem;
1901 VkMemoryRequirements mem_reqs;
1902
1903 VkBufferCreateInfo buf_info = {};
1904 buf_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
1905 buf_info.pNext = NULL;
1906 buf_info.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
1907 buf_info.size = 256;
1908 buf_info.queueFamilyIndexCount = 0;
1909 buf_info.pQueueFamilyIndices = NULL;
1910 buf_info.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
1911 buf_info.flags = 0;
1912 err = vkCreateBuffer(m_device->device(), &buf_info, NULL, &buffer);
1913 ASSERT_VK_SUCCESS(err);
1914
1915 vkGetBufferMemoryRequirements(m_device->device(), buffer, &mem_reqs);
1916 VkMemoryAllocateInfo alloc_info = {};
1917 alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
1918 alloc_info.pNext = NULL;
1919 alloc_info.memoryTypeIndex = 0;
1920
1921 // Ensure memory is big enough for both bindings
1922 static const VkDeviceSize allocation_size = 0x10000;
1923 alloc_info.allocationSize = allocation_size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001924 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &alloc_info, VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT);
Tobin Ehlis35372522016-05-12 08:32:31 -06001925 if (!pass) {
1926 vkDestroyBuffer(m_device->device(), buffer, NULL);
1927 return;
1928 }
1929 err = vkAllocateMemory(m_device->device(), &alloc_info, NULL, &mem);
1930 ASSERT_VK_SUCCESS(err);
1931
1932 uint8_t *pData;
1933 // Attempt to map memory size 0 is invalid
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001934 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "VkMapMemory: Attempting to map memory range of size zero");
Tobin Ehlis35372522016-05-12 08:32:31 -06001935 err = vkMapMemory(m_device->device(), mem, 0, 0, 0, (void **)&pData);
1936 m_errorMonitor->VerifyFound();
1937 // Map memory twice
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001938 err = vkMapMemory(m_device->device(), mem, 0, mem_reqs.size, 0, (void **)&pData);
Tobin Ehlis35372522016-05-12 08:32:31 -06001939 ASSERT_VK_SUCCESS(err);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001940 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
1941 "VkMapMemory: Attempting to map memory on an already-mapped object ");
1942 err = vkMapMemory(m_device->device(), mem, 0, mem_reqs.size, 0, (void **)&pData);
Tobin Ehlis35372522016-05-12 08:32:31 -06001943 m_errorMonitor->VerifyFound();
1944
1945 // Unmap the memory to avoid re-map error
1946 vkUnmapMemory(m_device->device(), mem);
1947 // overstep allocation with VK_WHOLE_SIZE
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001948 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
1949 " with size of VK_WHOLE_SIZE oversteps total array size 0x");
1950 err = vkMapMemory(m_device->device(), mem, allocation_size + 1, VK_WHOLE_SIZE, 0, (void **)&pData);
Tobin Ehlis35372522016-05-12 08:32:31 -06001951 m_errorMonitor->VerifyFound();
1952 // overstep allocation w/o VK_WHOLE_SIZE
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001953 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " oversteps total array size 0x");
1954 err = vkMapMemory(m_device->device(), mem, 1, allocation_size, 0, (void **)&pData);
Tobin Ehlis35372522016-05-12 08:32:31 -06001955 m_errorMonitor->VerifyFound();
1956 // Now error due to unmapping memory that's not mapped
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001957 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Unmapping Memory without memory being mapped: ");
Tobin Ehlis35372522016-05-12 08:32:31 -06001958 vkUnmapMemory(m_device->device(), mem);
1959 m_errorMonitor->VerifyFound();
1960 // Now map memory and cause errors due to flushing invalid ranges
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001961 err = vkMapMemory(m_device->device(), mem, 16, VK_WHOLE_SIZE, 0, (void **)&pData);
Tobin Ehlis35372522016-05-12 08:32:31 -06001962 ASSERT_VK_SUCCESS(err);
1963 VkMappedMemoryRange mmr = {};
Chris Forbes3aec0892016-06-13 10:29:26 +12001964 mmr.sType = VK_STRUCTURE_TYPE_MAPPED_MEMORY_RANGE;
Tobin Ehlis35372522016-05-12 08:32:31 -06001965 mmr.memory = mem;
1966 mmr.offset = 15; // Error b/c offset less than offset of mapped mem
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001967 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, ") is less than Memory Object's offset (");
Tobin Ehlis35372522016-05-12 08:32:31 -06001968 vkFlushMappedMemoryRanges(m_device->device(), 1, &mmr);
1969 m_errorMonitor->VerifyFound();
1970 // Now flush range that oversteps mapped range
1971 vkUnmapMemory(m_device->device(), mem);
1972 err = vkMapMemory(m_device->device(), mem, 0, 256, 0, (void **)&pData);
1973 ASSERT_VK_SUCCESS(err);
1974 mmr.offset = 16;
1975 mmr.size = 256; // flushing bounds (272) exceed mapped bounds (256)
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001976 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, ") exceeds the Memory Object's upper-bound (");
Tobin Ehlis35372522016-05-12 08:32:31 -06001977 vkFlushMappedMemoryRanges(m_device->device(), 1, &mmr);
1978 m_errorMonitor->VerifyFound();
1979
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001980 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &alloc_info, VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT,
1981 VK_MEMORY_PROPERTY_HOST_COHERENT_BIT);
Tobin Ehlis35372522016-05-12 08:32:31 -06001982 if (!pass) {
1983 vkFreeMemory(m_device->device(), mem, NULL);
1984 vkDestroyBuffer(m_device->device(), buffer, NULL);
1985 return;
1986 }
1987 // TODO : If we can get HOST_VISIBLE w/o HOST_COHERENT we can test cases of
1988 // MEMTRACK_INVALID_MAP in validateAndCopyNoncoherentMemoryToDriver()
1989
1990 vkDestroyBuffer(m_device->device(), buffer, NULL);
1991 vkFreeMemory(m_device->device(), mem, NULL);
1992}
1993
Mark Lobodzinski1f515922016-08-16 10:03:30 -06001994TEST_F(VkLayerTest, NonCoherentMemoryMapping) {
1995
1996 TEST_DESCRIPTION("Ensure that validations handling of non-coherent memory "
1997 "mapping while using VK_WHOLE_SIZE does not cause access "
1998 "violations");
1999 VkResult err;
2000 uint8_t *pData;
2001 ASSERT_NO_FATAL_FAILURE(InitState());
2002
2003 VkDeviceMemory mem;
2004 VkMemoryRequirements mem_reqs;
2005 mem_reqs.memoryTypeBits = 0xFFFFFFFF;
2006 VkMemoryAllocateInfo alloc_info = {};
2007 alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
2008 alloc_info.pNext = NULL;
2009 alloc_info.memoryTypeIndex = 0;
2010
2011 static const VkDeviceSize allocation_size = 0x1000;
2012 alloc_info.allocationSize = allocation_size;
2013
2014 // Find a memory configurations WITHOUT a COHERENT bit, otherwise exit
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002015 bool pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &alloc_info, VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT,
2016 VK_MEMORY_PROPERTY_HOST_COHERENT_BIT);
Mark Lobodzinski1f515922016-08-16 10:03:30 -06002017 if (!pass) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002018 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &alloc_info,
2019 VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT,
2020 VK_MEMORY_PROPERTY_HOST_COHERENT_BIT);
Mark Lobodzinski1f515922016-08-16 10:03:30 -06002021 if (!pass) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002022 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &alloc_info,
2023 VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT |
2024 VK_MEMORY_PROPERTY_HOST_CACHED_BIT,
2025 VK_MEMORY_PROPERTY_HOST_COHERENT_BIT);
Mark Lobodzinski1f515922016-08-16 10:03:30 -06002026 if (!pass) {
2027 return;
2028 }
2029 }
2030 }
2031
2032 err = vkAllocateMemory(m_device->device(), &alloc_info, NULL, &mem);
2033 ASSERT_VK_SUCCESS(err);
2034
2035 // Map/Flush/Invalidate using WHOLE_SIZE and zero offsets and entire
2036 // mapped range
2037 m_errorMonitor->ExpectSuccess();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002038 err = vkMapMemory(m_device->device(), mem, 0, VK_WHOLE_SIZE, 0, (void **)&pData);
Mark Lobodzinski1f515922016-08-16 10:03:30 -06002039 ASSERT_VK_SUCCESS(err);
2040 VkMappedMemoryRange mmr = {};
2041 mmr.sType = VK_STRUCTURE_TYPE_MAPPED_MEMORY_RANGE;
2042 mmr.memory = mem;
2043 mmr.offset = 0;
2044 mmr.size = VK_WHOLE_SIZE;
2045 err = vkFlushMappedMemoryRanges(m_device->device(), 1, &mmr);
2046 ASSERT_VK_SUCCESS(err);
2047 err = vkInvalidateMappedMemoryRanges(m_device->device(), 1, &mmr);
2048 ASSERT_VK_SUCCESS(err);
2049 m_errorMonitor->VerifyNotFound();
2050 vkUnmapMemory(m_device->device(), mem);
2051
2052 // Map/Flush/Invalidate using WHOLE_SIZE and a prime offset and entire
2053 // mapped range
2054 m_errorMonitor->ExpectSuccess();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002055 err = vkMapMemory(m_device->device(), mem, 13, VK_WHOLE_SIZE, 0, (void **)&pData);
Mark Lobodzinski1f515922016-08-16 10:03:30 -06002056 ASSERT_VK_SUCCESS(err);
2057 mmr.sType = VK_STRUCTURE_TYPE_MAPPED_MEMORY_RANGE;
2058 mmr.memory = mem;
2059 mmr.offset = 13;
2060 mmr.size = VK_WHOLE_SIZE;
2061 err = vkFlushMappedMemoryRanges(m_device->device(), 1, &mmr);
2062 ASSERT_VK_SUCCESS(err);
2063 err = vkInvalidateMappedMemoryRanges(m_device->device(), 1, &mmr);
2064 ASSERT_VK_SUCCESS(err);
2065 m_errorMonitor->VerifyNotFound();
2066 vkUnmapMemory(m_device->device(), mem);
2067
2068 // Map with prime offset and size
2069 // Flush/Invalidate subrange of mapped area with prime offset and size
2070 m_errorMonitor->ExpectSuccess();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002071 err = vkMapMemory(m_device->device(), mem, allocation_size - 137, 109, 0, (void **)&pData);
Mark Lobodzinski1f515922016-08-16 10:03:30 -06002072 ASSERT_VK_SUCCESS(err);
2073 mmr.sType = VK_STRUCTURE_TYPE_MAPPED_MEMORY_RANGE;
2074 mmr.memory = mem;
2075 mmr.offset = allocation_size - 107;
2076 mmr.size = 61;
2077 err = vkFlushMappedMemoryRanges(m_device->device(), 1, &mmr);
2078 ASSERT_VK_SUCCESS(err);
2079 err = vkInvalidateMappedMemoryRanges(m_device->device(), 1, &mmr);
2080 ASSERT_VK_SUCCESS(err);
2081 m_errorMonitor->VerifyNotFound();
2082 vkUnmapMemory(m_device->device(), mem);
2083
2084 vkFreeMemory(m_device->device(), mem, NULL);
2085}
2086
Ian Elliott1c32c772016-04-28 14:47:13 -06002087TEST_F(VkLayerTest, EnableWsiBeforeUse) {
2088 VkResult err;
2089 bool pass;
2090
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002091 // FIXME: After we turn on this code for non-Linux platforms, uncomment the
2092 // following declaration (which is temporarily being moved below):
2093 // VkSurfaceKHR surface = VK_NULL_HANDLE;
Ian Elliott1c32c772016-04-28 14:47:13 -06002094 VkSwapchainKHR swapchain = VK_NULL_HANDLE;
2095 VkSwapchainCreateInfoKHR swapchain_create_info = {};
2096 uint32_t swapchain_image_count = 0;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002097 // VkImage swapchain_images[1] = {VK_NULL_HANDLE};
Ian Elliott1c32c772016-04-28 14:47:13 -06002098 uint32_t image_index = 0;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002099 // VkPresentInfoKHR present_info = {};
Ian Elliott1c32c772016-04-28 14:47:13 -06002100
2101 ASSERT_NO_FATAL_FAILURE(InitState());
2102
Ian Elliott3f06ce52016-04-29 14:46:21 -06002103#ifdef NEED_TO_TEST_THIS_ON_PLATFORM
2104#if defined(VK_USE_PLATFORM_ANDROID_KHR)
2105 // Use the functions from the VK_KHR_android_surface extension without
2106 // enabling that extension:
2107
2108 // Create a surface:
2109 VkAndroidSurfaceCreateInfoKHR android_create_info = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002110 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
2111 err = vkCreateAndroidSurfaceKHR(instance(), &android_create_info, NULL, &surface);
Ian Elliott3f06ce52016-04-29 14:46:21 -06002112 pass = (err != VK_SUCCESS);
2113 ASSERT_TRUE(pass);
2114 m_errorMonitor->VerifyFound();
2115#endif // VK_USE_PLATFORM_ANDROID_KHR
2116
Ian Elliott3f06ce52016-04-29 14:46:21 -06002117#if defined(VK_USE_PLATFORM_MIR_KHR)
2118 // Use the functions from the VK_KHR_mir_surface extension without enabling
2119 // that extension:
2120
2121 // Create a surface:
2122 VkMirSurfaceCreateInfoKHR mir_create_info = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002123 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
Ian Elliott3f06ce52016-04-29 14:46:21 -06002124 err = vkCreateMirSurfaceKHR(instance(), &mir_create_info, NULL, &surface);
2125 pass = (err != VK_SUCCESS);
2126 ASSERT_TRUE(pass);
2127 m_errorMonitor->VerifyFound();
2128
2129 // Tell whether an mir_connection supports presentation:
2130 MirConnection *mir_connection = NULL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002131 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
2132 vkGetPhysicalDeviceMirPresentationSupportKHR(gpu(), 0, mir_connection, visual_id);
Ian Elliott3f06ce52016-04-29 14:46:21 -06002133 m_errorMonitor->VerifyFound();
2134#endif // VK_USE_PLATFORM_MIR_KHR
2135
Ian Elliott3f06ce52016-04-29 14:46:21 -06002136#if defined(VK_USE_PLATFORM_WAYLAND_KHR)
2137 // Use the functions from the VK_KHR_wayland_surface extension without
2138 // enabling that extension:
2139
2140 // Create a surface:
2141 VkWaylandSurfaceCreateInfoKHR wayland_create_info = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002142 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
2143 err = vkCreateWaylandSurfaceKHR(instance(), &wayland_create_info, NULL, &surface);
Ian Elliott3f06ce52016-04-29 14:46:21 -06002144 pass = (err != VK_SUCCESS);
2145 ASSERT_TRUE(pass);
2146 m_errorMonitor->VerifyFound();
2147
2148 // Tell whether an wayland_display supports presentation:
2149 struct wl_display wayland_display = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002150 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
2151 vkGetPhysicalDeviceWaylandPresentationSupportKHR(gpu(), 0, &wayland_display);
Ian Elliott3f06ce52016-04-29 14:46:21 -06002152 m_errorMonitor->VerifyFound();
2153#endif // VK_USE_PLATFORM_WAYLAND_KHR
Ian Elliott489eec02016-05-05 14:12:44 -06002154#endif // NEED_TO_TEST_THIS_ON_PLATFORM
Ian Elliott3f06ce52016-04-29 14:46:21 -06002155
Ian Elliott3f06ce52016-04-29 14:46:21 -06002156#if defined(VK_USE_PLATFORM_WIN32_KHR)
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002157 // FIXME: REMOVE THIS HERE, AND UNCOMMENT ABOVE, WHEN THIS TEST HAS BEEN PORTED
2158 // TO NON-LINUX PLATFORMS:
2159 VkSurfaceKHR surface = VK_NULL_HANDLE;
Ian Elliott3f06ce52016-04-29 14:46:21 -06002160 // Use the functions from the VK_KHR_win32_surface extension without
2161 // enabling that extension:
2162
2163 // Create a surface:
2164 VkWin32SurfaceCreateInfoKHR win32_create_info = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002165 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
2166 err = vkCreateWin32SurfaceKHR(instance(), &win32_create_info, NULL, &surface);
Ian Elliott3f06ce52016-04-29 14:46:21 -06002167 pass = (err != VK_SUCCESS);
2168 ASSERT_TRUE(pass);
2169 m_errorMonitor->VerifyFound();
2170
2171 // Tell whether win32 supports presentation:
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002172 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
Ian Elliott489eec02016-05-05 14:12:44 -06002173 vkGetPhysicalDeviceWin32PresentationSupportKHR(gpu(), 0);
Ian Elliott3f06ce52016-04-29 14:46:21 -06002174 m_errorMonitor->VerifyFound();
Ian Elliott489eec02016-05-05 14:12:44 -06002175// Set this (for now, until all platforms are supported and tested):
2176#define NEED_TO_TEST_THIS_ON_PLATFORM
2177#endif // VK_USE_PLATFORM_WIN32_KHR
Ian Elliott3f06ce52016-04-29 14:46:21 -06002178
Ian Elliott1c32c772016-04-28 14:47:13 -06002179#if defined(VK_USE_PLATFORM_XCB_KHR)
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002180 // FIXME: REMOVE THIS HERE, AND UNCOMMENT ABOVE, WHEN THIS TEST HAS BEEN PORTED
2181 // TO NON-LINUX PLATFORMS:
2182 VkSurfaceKHR surface = VK_NULL_HANDLE;
Ian Elliott1c32c772016-04-28 14:47:13 -06002183 // Use the functions from the VK_KHR_xcb_surface extension without enabling
2184 // that extension:
2185
2186 // Create a surface:
2187 VkXcbSurfaceCreateInfoKHR xcb_create_info = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002188 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
Ian Elliott1c32c772016-04-28 14:47:13 -06002189 err = vkCreateXcbSurfaceKHR(instance(), &xcb_create_info, NULL, &surface);
2190 pass = (err != VK_SUCCESS);
2191 ASSERT_TRUE(pass);
2192 m_errorMonitor->VerifyFound();
2193
2194 // Tell whether an xcb_visualid_t supports presentation:
Ian Elliott3f06ce52016-04-29 14:46:21 -06002195 xcb_connection_t *xcb_connection = NULL;
Ian Elliott1c32c772016-04-28 14:47:13 -06002196 xcb_visualid_t visual_id = 0;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002197 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
2198 vkGetPhysicalDeviceXcbPresentationSupportKHR(gpu(), 0, xcb_connection, visual_id);
Ian Elliott1c32c772016-04-28 14:47:13 -06002199 m_errorMonitor->VerifyFound();
Ian Elliott489eec02016-05-05 14:12:44 -06002200// Set this (for now, until all platforms are supported and tested):
2201#define NEED_TO_TEST_THIS_ON_PLATFORM
Ian Elliott1c32c772016-04-28 14:47:13 -06002202#endif // VK_USE_PLATFORM_XCB_KHR
2203
Ian Elliott12630812016-04-29 14:35:43 -06002204#if defined(VK_USE_PLATFORM_XLIB_KHR)
2205 // Use the functions from the VK_KHR_xlib_surface extension without enabling
2206 // that extension:
2207
2208 // Create a surface:
2209 VkXlibSurfaceCreateInfoKHR xlib_create_info = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002210 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
Ian Elliott12630812016-04-29 14:35:43 -06002211 err = vkCreateXlibSurfaceKHR(instance(), &xlib_create_info, NULL, &surface);
2212 pass = (err != VK_SUCCESS);
2213 ASSERT_TRUE(pass);
2214 m_errorMonitor->VerifyFound();
2215
2216 // Tell whether an Xlib VisualID supports presentation:
2217 Display *dpy = NULL;
2218 VisualID visual = 0;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002219 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
Ian Elliott12630812016-04-29 14:35:43 -06002220 vkGetPhysicalDeviceXlibPresentationSupportKHR(gpu(), 0, dpy, visual);
2221 m_errorMonitor->VerifyFound();
Ian Elliott489eec02016-05-05 14:12:44 -06002222// Set this (for now, until all platforms are supported and tested):
2223#define NEED_TO_TEST_THIS_ON_PLATFORM
Ian Elliott12630812016-04-29 14:35:43 -06002224#endif // VK_USE_PLATFORM_XLIB_KHR
2225
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002226// Use the functions from the VK_KHR_surface extension without enabling
2227// that extension:
Ian Elliott1c32c772016-04-28 14:47:13 -06002228
Ian Elliott489eec02016-05-05 14:12:44 -06002229#ifdef NEED_TO_TEST_THIS_ON_PLATFORM
Ian Elliott1c32c772016-04-28 14:47:13 -06002230 // Destroy a surface:
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002231 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
Ian Elliott1c32c772016-04-28 14:47:13 -06002232 vkDestroySurfaceKHR(instance(), surface, NULL);
2233 m_errorMonitor->VerifyFound();
2234
2235 // Check if surface supports presentation:
2236 VkBool32 supported = false;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002237 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
Ian Elliott1c32c772016-04-28 14:47:13 -06002238 err = vkGetPhysicalDeviceSurfaceSupportKHR(gpu(), 0, surface, &supported);
2239 pass = (err != VK_SUCCESS);
2240 ASSERT_TRUE(pass);
2241 m_errorMonitor->VerifyFound();
2242
2243 // Check surface capabilities:
2244 VkSurfaceCapabilitiesKHR capabilities = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002245 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
2246 err = vkGetPhysicalDeviceSurfaceCapabilitiesKHR(gpu(), surface, &capabilities);
Ian Elliott1c32c772016-04-28 14:47:13 -06002247 pass = (err != VK_SUCCESS);
2248 ASSERT_TRUE(pass);
2249 m_errorMonitor->VerifyFound();
2250
2251 // Check surface formats:
2252 uint32_t format_count = 0;
2253 VkSurfaceFormatKHR *formats = NULL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002254 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
2255 err = vkGetPhysicalDeviceSurfaceFormatsKHR(gpu(), surface, &format_count, formats);
Ian Elliott1c32c772016-04-28 14:47:13 -06002256 pass = (err != VK_SUCCESS);
2257 ASSERT_TRUE(pass);
2258 m_errorMonitor->VerifyFound();
2259
2260 // Check surface present modes:
2261 uint32_t present_mode_count = 0;
2262 VkSurfaceFormatKHR *present_modes = NULL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002263 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
2264 err = vkGetPhysicalDeviceSurfaceFormatsKHR(gpu(), surface, &present_mode_count, present_modes);
Ian Elliott1c32c772016-04-28 14:47:13 -06002265 pass = (err != VK_SUCCESS);
2266 ASSERT_TRUE(pass);
2267 m_errorMonitor->VerifyFound();
Ian Elliott489eec02016-05-05 14:12:44 -06002268#endif // NEED_TO_TEST_THIS_ON_PLATFORM
Ian Elliott1c32c772016-04-28 14:47:13 -06002269
Ian Elliott1c32c772016-04-28 14:47:13 -06002270 // Use the functions from the VK_KHR_swapchain extension without enabling
2271 // that extension:
2272
2273 // Create a swapchain:
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002274 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
Ian Elliott1c32c772016-04-28 14:47:13 -06002275 swapchain_create_info.sType = VK_STRUCTURE_TYPE_SWAPCHAIN_CREATE_INFO_KHR;
2276 swapchain_create_info.pNext = NULL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002277 err = vkCreateSwapchainKHR(m_device->device(), &swapchain_create_info, NULL, &swapchain);
Ian Elliott1c32c772016-04-28 14:47:13 -06002278 pass = (err != VK_SUCCESS);
2279 ASSERT_TRUE(pass);
2280 m_errorMonitor->VerifyFound();
2281
2282 // Get the images from the swapchain:
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002283 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
2284 err = vkGetSwapchainImagesKHR(m_device->device(), swapchain, &swapchain_image_count, NULL);
Ian Elliott1c32c772016-04-28 14:47:13 -06002285 pass = (err != VK_SUCCESS);
2286 ASSERT_TRUE(pass);
2287 m_errorMonitor->VerifyFound();
2288
Chris Forbeseb7d5502016-09-13 18:19:21 +12002289 // Add a fence to avoid (justifiable) error about not providing fence OR semaphore
2290 VkFenceCreateInfo fci = { VK_STRUCTURE_TYPE_FENCE_CREATE_INFO, nullptr, 0 };
2291 VkFence fence;
2292 err = vkCreateFence(m_device->device(), &fci, nullptr, &fence);
2293
Ian Elliott1c32c772016-04-28 14:47:13 -06002294 // Try to acquire an image:
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002295 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
Chris Forbeseb7d5502016-09-13 18:19:21 +12002296 err = vkAcquireNextImageKHR(m_device->device(), swapchain, 0, VK_NULL_HANDLE, fence, &image_index);
Ian Elliott1c32c772016-04-28 14:47:13 -06002297 pass = (err != VK_SUCCESS);
2298 ASSERT_TRUE(pass);
2299 m_errorMonitor->VerifyFound();
2300
Chris Forbeseb7d5502016-09-13 18:19:21 +12002301 vkDestroyFence(m_device->device(), fence, nullptr);
2302
Ian Elliott1c32c772016-04-28 14:47:13 -06002303 // Try to present an image:
Ian Elliott2c1daf52016-05-12 09:41:46 -06002304 //
2305 // NOTE: Currently can't test this because a real swapchain is needed (as
2306 // opposed to the fake one we created) in order for the layer to lookup the
2307 // VkDevice used to enable the extension:
Ian Elliott1c32c772016-04-28 14:47:13 -06002308
2309 // Destroy the swapchain:
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002310 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
Ian Elliott1c32c772016-04-28 14:47:13 -06002311 vkDestroySwapchainKHR(m_device->device(), swapchain, NULL);
2312 m_errorMonitor->VerifyFound();
2313}
2314
Ian Elliott2c1daf52016-05-12 09:41:46 -06002315TEST_F(VkWsiEnabledLayerTest, TestEnabledWsi) {
Ian Elliott2c1daf52016-05-12 09:41:46 -06002316
Dustin Graves6c6d8982016-05-17 10:09:21 -06002317#if defined(VK_USE_PLATFORM_XCB_KHR)
Ian Elliott2c1daf52016-05-12 09:41:46 -06002318 VkSurfaceKHR surface = VK_NULL_HANDLE;
Mark Lobodzinski085d27a2016-05-17 09:34:26 -06002319
Mark Lobodzinski085d27a2016-05-17 09:34:26 -06002320 VkResult err;
2321 bool pass;
Ian Elliott2c1daf52016-05-12 09:41:46 -06002322 VkSwapchainKHR swapchain = VK_NULL_HANDLE;
2323 VkSwapchainCreateInfoKHR swapchain_create_info = {};
Mark Lobodzinski085d27a2016-05-17 09:34:26 -06002324 // uint32_t swapchain_image_count = 0;
2325 // VkImage swapchain_images[1] = {VK_NULL_HANDLE};
2326 // uint32_t image_index = 0;
2327 // VkPresentInfoKHR present_info = {};
Ian Elliott2c1daf52016-05-12 09:41:46 -06002328
2329 ASSERT_NO_FATAL_FAILURE(InitState());
2330
2331 // Use the create function from one of the VK_KHR_*_surface extension in
2332 // order to create a surface, testing all known errors in the process,
2333 // before successfully creating a surface:
2334 // First, try to create a surface without a VkXcbSurfaceCreateInfoKHR:
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002335 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "required parameter pCreateInfo specified as NULL");
Ian Elliott2c1daf52016-05-12 09:41:46 -06002336 err = vkCreateXcbSurfaceKHR(instance(), NULL, NULL, &surface);
2337 pass = (err != VK_SUCCESS);
2338 ASSERT_TRUE(pass);
2339 m_errorMonitor->VerifyFound();
2340
2341 // Next, try to create a surface with the wrong
2342 // VkXcbSurfaceCreateInfoKHR::sType:
2343 VkXcbSurfaceCreateInfoKHR xcb_create_info = {};
2344 xcb_create_info.sType = VK_STRUCTURE_TYPE_APPLICATION_INFO;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002345 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "parameter pCreateInfo->sType must be");
Ian Elliott2c1daf52016-05-12 09:41:46 -06002346 err = vkCreateXcbSurfaceKHR(instance(), &xcb_create_info, NULL, &surface);
2347 pass = (err != VK_SUCCESS);
2348 ASSERT_TRUE(pass);
2349 m_errorMonitor->VerifyFound();
2350
Ian Elliott2c1daf52016-05-12 09:41:46 -06002351 // Create a native window, and then correctly create a surface:
2352 xcb_connection_t *connection;
2353 xcb_screen_t *screen;
2354 xcb_window_t xcb_window;
2355 xcb_intern_atom_reply_t *atom_wm_delete_window;
2356
2357 const xcb_setup_t *setup;
2358 xcb_screen_iterator_t iter;
2359 int scr;
2360 uint32_t value_mask, value_list[32];
2361 int width = 1;
2362 int height = 1;
2363
2364 connection = xcb_connect(NULL, &scr);
2365 ASSERT_TRUE(connection != NULL);
2366 setup = xcb_get_setup(connection);
2367 iter = xcb_setup_roots_iterator(setup);
2368 while (scr-- > 0)
2369 xcb_screen_next(&iter);
2370 screen = iter.data;
2371
2372 xcb_window = xcb_generate_id(connection);
2373
2374 value_mask = XCB_CW_BACK_PIXEL | XCB_CW_EVENT_MASK;
2375 value_list[0] = screen->black_pixel;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002376 value_list[1] = XCB_EVENT_MASK_KEY_RELEASE | XCB_EVENT_MASK_EXPOSURE | XCB_EVENT_MASK_STRUCTURE_NOTIFY;
Ian Elliott2c1daf52016-05-12 09:41:46 -06002377
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002378 xcb_create_window(connection, XCB_COPY_FROM_PARENT, xcb_window, screen->root, 0, 0, width, height, 0,
2379 XCB_WINDOW_CLASS_INPUT_OUTPUT, screen->root_visual, value_mask, value_list);
Ian Elliott2c1daf52016-05-12 09:41:46 -06002380
2381 /* Magic code that will send notification when window is destroyed */
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002382 xcb_intern_atom_cookie_t cookie = xcb_intern_atom(connection, 1, 12, "WM_PROTOCOLS");
2383 xcb_intern_atom_reply_t *reply = xcb_intern_atom_reply(connection, cookie, 0);
Ian Elliott2c1daf52016-05-12 09:41:46 -06002384
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002385 xcb_intern_atom_cookie_t cookie2 = xcb_intern_atom(connection, 0, 16, "WM_DELETE_WINDOW");
Mark Lobodzinski085d27a2016-05-17 09:34:26 -06002386 atom_wm_delete_window = xcb_intern_atom_reply(connection, cookie2, 0);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002387 xcb_change_property(connection, XCB_PROP_MODE_REPLACE, xcb_window, (*reply).atom, 4, 32, 1, &(*atom_wm_delete_window).atom);
Ian Elliott2c1daf52016-05-12 09:41:46 -06002388 free(reply);
2389
2390 xcb_map_window(connection, xcb_window);
2391
2392 // Force the x/y coordinates to 100,100 results are identical in consecutive
2393 // runs
2394 const uint32_t coords[] = {100, 100};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002395 xcb_configure_window(connection, xcb_window, XCB_CONFIG_WINDOW_X | XCB_CONFIG_WINDOW_Y, coords);
Ian Elliott2c1daf52016-05-12 09:41:46 -06002396
Ian Elliott2c1daf52016-05-12 09:41:46 -06002397 // Finally, try to correctly create a surface:
2398 xcb_create_info.sType = VK_STRUCTURE_TYPE_XCB_SURFACE_CREATE_INFO_KHR;
2399 xcb_create_info.pNext = NULL;
2400 xcb_create_info.flags = 0;
2401 xcb_create_info.connection = connection;
2402 xcb_create_info.window = xcb_window;
2403 err = vkCreateXcbSurfaceKHR(instance(), &xcb_create_info, NULL, &surface);
2404 pass = (err == VK_SUCCESS);
2405 ASSERT_TRUE(pass);
2406
Ian Elliott2c1daf52016-05-12 09:41:46 -06002407 // Check if surface supports presentation:
2408
2409 // 1st, do so without having queried the queue families:
2410 VkBool32 supported = false;
2411 // TODO: Get the following error to come out:
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002412 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
2413 "called before calling the vkGetPhysicalDeviceQueueFamilyProperties "
2414 "function");
Ian Elliott2c1daf52016-05-12 09:41:46 -06002415 err = vkGetPhysicalDeviceSurfaceSupportKHR(gpu(), 0, surface, &supported);
2416 pass = (err != VK_SUCCESS);
Mark Lobodzinski085d27a2016-05-17 09:34:26 -06002417 // ASSERT_TRUE(pass);
2418 // m_errorMonitor->VerifyFound();
Ian Elliott2c1daf52016-05-12 09:41:46 -06002419
2420 // Next, query a queue family index that's too large:
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002421 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "called with a queueFamilyIndex that is too large");
2422 err = vkGetPhysicalDeviceSurfaceSupportKHR(gpu(), 100000, surface, &supported);
Ian Elliott2c1daf52016-05-12 09:41:46 -06002423 pass = (err != VK_SUCCESS);
2424 ASSERT_TRUE(pass);
2425 m_errorMonitor->VerifyFound();
2426
2427 // Finally, do so correctly:
Mark Lobodzinski085d27a2016-05-17 09:34:26 -06002428 // FIXME: THIS ISN'T CORRECT--MUST QUERY UNTIL WE FIND A QUEUE FAMILY THAT'S
2429 // SUPPORTED
Ian Elliott2c1daf52016-05-12 09:41:46 -06002430 err = vkGetPhysicalDeviceSurfaceSupportKHR(gpu(), 0, surface, &supported);
2431 pass = (err == VK_SUCCESS);
2432 ASSERT_TRUE(pass);
2433
Ian Elliott2c1daf52016-05-12 09:41:46 -06002434 // Before proceeding, try to create a swapchain without having called
2435 // vkGetPhysicalDeviceSurfaceCapabilitiesKHR():
2436 swapchain_create_info.sType = VK_STRUCTURE_TYPE_SWAPCHAIN_CREATE_INFO_KHR;
2437 swapchain_create_info.pNext = NULL;
2438 swapchain_create_info.flags = 0;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002439 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
2440 "called before calling vkGetPhysicalDeviceSurfaceCapabilitiesKHR().");
2441 err = vkCreateSwapchainKHR(m_device->device(), &swapchain_create_info, NULL, &swapchain);
Ian Elliott2c1daf52016-05-12 09:41:46 -06002442 pass = (err != VK_SUCCESS);
2443 ASSERT_TRUE(pass);
2444 m_errorMonitor->VerifyFound();
2445
Ian Elliott2c1daf52016-05-12 09:41:46 -06002446 // Get the surface capabilities:
2447 VkSurfaceCapabilitiesKHR surface_capabilities;
2448
2449 // Do so correctly (only error logged by this entrypoint is if the
2450 // extension isn't enabled):
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002451 err = vkGetPhysicalDeviceSurfaceCapabilitiesKHR(gpu(), surface, &surface_capabilities);
Ian Elliott2c1daf52016-05-12 09:41:46 -06002452 pass = (err == VK_SUCCESS);
2453 ASSERT_TRUE(pass);
2454
Ian Elliott2c1daf52016-05-12 09:41:46 -06002455 // Get the surface formats:
2456 uint32_t surface_format_count;
2457
2458 // First, try without a pointer to surface_format_count:
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002459 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "required parameter pSurfaceFormatCount "
2460 "specified as NULL");
Ian Elliott2c1daf52016-05-12 09:41:46 -06002461 vkGetPhysicalDeviceSurfaceFormatsKHR(gpu(), surface, NULL, NULL);
2462 pass = (err == VK_SUCCESS);
2463 ASSERT_TRUE(pass);
2464 m_errorMonitor->VerifyFound();
2465
2466 // Next, call with a non-NULL pSurfaceFormats, even though we haven't
2467 // correctly done a 1st try (to get the count):
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002468 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT, "but no prior positive value has been seen for");
Ian Elliott2c1daf52016-05-12 09:41:46 -06002469 surface_format_count = 0;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002470 vkGetPhysicalDeviceSurfaceFormatsKHR(gpu(), surface, &surface_format_count, (VkSurfaceFormatKHR *)&surface_format_count);
Ian Elliott2c1daf52016-05-12 09:41:46 -06002471 pass = (err == VK_SUCCESS);
2472 ASSERT_TRUE(pass);
2473 m_errorMonitor->VerifyFound();
2474
2475 // Next, correctly do a 1st try (with a NULL pointer to surface_formats):
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002476 vkGetPhysicalDeviceSurfaceFormatsKHR(gpu(), surface, &surface_format_count, NULL);
Ian Elliott2c1daf52016-05-12 09:41:46 -06002477 pass = (err == VK_SUCCESS);
2478 ASSERT_TRUE(pass);
2479
2480 // Allocate memory for the correct number of VkSurfaceFormatKHR's:
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002481 VkSurfaceFormatKHR *surface_formats = (VkSurfaceFormatKHR *)malloc(surface_format_count * sizeof(VkSurfaceFormatKHR));
Ian Elliott2c1daf52016-05-12 09:41:46 -06002482
2483 // Next, do a 2nd try with surface_format_count being set too high:
2484 surface_format_count += 5;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002485 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "that is greater than the value");
2486 vkGetPhysicalDeviceSurfaceFormatsKHR(gpu(), surface, &surface_format_count, surface_formats);
Ian Elliott2c1daf52016-05-12 09:41:46 -06002487 pass = (err == VK_SUCCESS);
2488 ASSERT_TRUE(pass);
2489 m_errorMonitor->VerifyFound();
2490
2491 // Finally, do a correct 1st and 2nd try:
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002492 vkGetPhysicalDeviceSurfaceFormatsKHR(gpu(), surface, &surface_format_count, NULL);
Ian Elliott2c1daf52016-05-12 09:41:46 -06002493 pass = (err == VK_SUCCESS);
2494 ASSERT_TRUE(pass);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002495 vkGetPhysicalDeviceSurfaceFormatsKHR(gpu(), surface, &surface_format_count, surface_formats);
Ian Elliott2c1daf52016-05-12 09:41:46 -06002496 pass = (err == VK_SUCCESS);
2497 ASSERT_TRUE(pass);
2498
Ian Elliott2c1daf52016-05-12 09:41:46 -06002499 // Get the surface present modes:
2500 uint32_t surface_present_mode_count;
2501
2502 // First, try without a pointer to surface_format_count:
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002503 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "required parameter pPresentModeCount "
2504 "specified as NULL");
Mark Lobodzinskib02ea642016-08-17 13:03:57 -06002505
Ian Elliott2c1daf52016-05-12 09:41:46 -06002506 vkGetPhysicalDeviceSurfacePresentModesKHR(gpu(), surface, NULL, NULL);
2507 pass = (err == VK_SUCCESS);
2508 ASSERT_TRUE(pass);
2509 m_errorMonitor->VerifyFound();
2510
2511 // Next, call with a non-NULL VkPresentModeKHR, even though we haven't
2512 // correctly done a 1st try (to get the count):
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002513 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT, "but no prior positive value has been seen for");
Ian Elliott2c1daf52016-05-12 09:41:46 -06002514 surface_present_mode_count = 0;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002515 vkGetPhysicalDeviceSurfacePresentModesKHR(gpu(), surface, &surface_present_mode_count,
2516 (VkPresentModeKHR *)&surface_present_mode_count);
Ian Elliott2c1daf52016-05-12 09:41:46 -06002517 pass = (err == VK_SUCCESS);
2518 ASSERT_TRUE(pass);
2519 m_errorMonitor->VerifyFound();
2520
2521 // Next, correctly do a 1st try (with a NULL pointer to surface_formats):
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002522 vkGetPhysicalDeviceSurfacePresentModesKHR(gpu(), surface, &surface_present_mode_count, NULL);
Ian Elliott2c1daf52016-05-12 09:41:46 -06002523 pass = (err == VK_SUCCESS);
2524 ASSERT_TRUE(pass);
2525
2526 // Allocate memory for the correct number of VkSurfaceFormatKHR's:
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002527 VkPresentModeKHR *surface_present_modes = (VkPresentModeKHR *)malloc(surface_present_mode_count * sizeof(VkPresentModeKHR));
Ian Elliott2c1daf52016-05-12 09:41:46 -06002528
2529 // Next, do a 2nd try with surface_format_count being set too high:
2530 surface_present_mode_count += 5;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002531 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "that is greater than the value");
2532 vkGetPhysicalDeviceSurfacePresentModesKHR(gpu(), surface, &surface_present_mode_count, surface_present_modes);
Ian Elliott2c1daf52016-05-12 09:41:46 -06002533 pass = (err == VK_SUCCESS);
2534 ASSERT_TRUE(pass);
2535 m_errorMonitor->VerifyFound();
2536
2537 // Finally, do a correct 1st and 2nd try:
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002538 vkGetPhysicalDeviceSurfacePresentModesKHR(gpu(), surface, &surface_present_mode_count, NULL);
Ian Elliott2c1daf52016-05-12 09:41:46 -06002539 pass = (err == VK_SUCCESS);
2540 ASSERT_TRUE(pass);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002541 vkGetPhysicalDeviceSurfacePresentModesKHR(gpu(), surface, &surface_present_mode_count, surface_present_modes);
Ian Elliott2c1daf52016-05-12 09:41:46 -06002542 pass = (err == VK_SUCCESS);
2543 ASSERT_TRUE(pass);
2544
Ian Elliott2c1daf52016-05-12 09:41:46 -06002545 // Create a swapchain:
2546
2547 // First, try without a pointer to swapchain_create_info:
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002548 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "required parameter pCreateInfo "
2549 "specified as NULL");
Mark Lobodzinskib02ea642016-08-17 13:03:57 -06002550
Ian Elliott2c1daf52016-05-12 09:41:46 -06002551 err = vkCreateSwapchainKHR(m_device->device(), NULL, NULL, &swapchain);
2552 pass = (err != VK_SUCCESS);
2553 ASSERT_TRUE(pass);
2554 m_errorMonitor->VerifyFound();
2555
2556 // Next, call with a non-NULL swapchain_create_info, that has the wrong
2557 // sType:
2558 swapchain_create_info.sType = VK_STRUCTURE_TYPE_APPLICATION_INFO;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002559 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "parameter pCreateInfo->sType must be");
Mark Lobodzinskib02ea642016-08-17 13:03:57 -06002560
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002561 err = vkCreateSwapchainKHR(m_device->device(), &swapchain_create_info, NULL, &swapchain);
Ian Elliott2c1daf52016-05-12 09:41:46 -06002562 pass = (err != VK_SUCCESS);
2563 ASSERT_TRUE(pass);
2564 m_errorMonitor->VerifyFound();
2565
2566 // Next, call with a NULL swapchain pointer:
2567 swapchain_create_info.sType = VK_STRUCTURE_TYPE_SWAPCHAIN_CREATE_INFO_KHR;
2568 swapchain_create_info.pNext = NULL;
2569 swapchain_create_info.flags = 0;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002570 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "required parameter pSwapchain "
2571 "specified as NULL");
Mark Lobodzinskib02ea642016-08-17 13:03:57 -06002572
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002573 err = vkCreateSwapchainKHR(m_device->device(), &swapchain_create_info, NULL, NULL);
Ian Elliott2c1daf52016-05-12 09:41:46 -06002574 pass = (err != VK_SUCCESS);
2575 ASSERT_TRUE(pass);
2576 m_errorMonitor->VerifyFound();
2577
Mark Lobodzinski085d27a2016-05-17 09:34:26 -06002578 // TODO: Enhance swapchain layer so that
2579 // swapchain_create_info.queueFamilyIndexCount is checked against something?
Ian Elliott2c1daf52016-05-12 09:41:46 -06002580
2581 // Next, call with a queue family index that's too large:
2582 uint32_t queueFamilyIndex[2] = {100000, 0};
2583 swapchain_create_info.imageSharingMode = VK_SHARING_MODE_CONCURRENT;
2584 swapchain_create_info.queueFamilyIndexCount = 2;
2585 swapchain_create_info.pQueueFamilyIndices = queueFamilyIndex;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002586 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "called with a queueFamilyIndex that is too large");
2587 err = vkCreateSwapchainKHR(m_device->device(), &swapchain_create_info, NULL, &swapchain);
Ian Elliott2c1daf52016-05-12 09:41:46 -06002588 pass = (err != VK_SUCCESS);
2589 ASSERT_TRUE(pass);
2590 m_errorMonitor->VerifyFound();
2591
2592 // Next, call a queueFamilyIndexCount that's too small for CONCURRENT:
2593 swapchain_create_info.imageSharingMode = VK_SHARING_MODE_CONCURRENT;
2594 swapchain_create_info.queueFamilyIndexCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002595 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
2596 "but with a bad value(s) for pCreateInfo->queueFamilyIndexCount or "
2597 "pCreateInfo->pQueueFamilyIndices).");
2598 err = vkCreateSwapchainKHR(m_device->device(), &swapchain_create_info, NULL, &swapchain);
Ian Elliott2c1daf52016-05-12 09:41:46 -06002599 pass = (err != VK_SUCCESS);
2600 ASSERT_TRUE(pass);
2601 m_errorMonitor->VerifyFound();
2602
2603 // Next, call with an invalid imageSharingMode:
2604 swapchain_create_info.imageSharingMode = VK_SHARING_MODE_MAX_ENUM;
2605 swapchain_create_info.queueFamilyIndexCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002606 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
2607 "called with a non-supported pCreateInfo->imageSharingMode (i.e.");
2608 err = vkCreateSwapchainKHR(m_device->device(), &swapchain_create_info, NULL, &swapchain);
Ian Elliott2c1daf52016-05-12 09:41:46 -06002609 pass = (err != VK_SUCCESS);
2610 ASSERT_TRUE(pass);
2611 m_errorMonitor->VerifyFound();
2612 // Fix for the future:
Mark Lobodzinski085d27a2016-05-17 09:34:26 -06002613 // FIXME: THIS ISN'T CORRECT--MUST QUERY UNTIL WE FIND A QUEUE FAMILY THAT'S
2614 // SUPPORTED
Ian Elliott2c1daf52016-05-12 09:41:46 -06002615 swapchain_create_info.queueFamilyIndexCount = 0;
2616 queueFamilyIndex[0] = 0;
2617 swapchain_create_info.imageSharingMode = VK_SHARING_MODE_EXCLUSIVE;
2618
Mark Lobodzinski085d27a2016-05-17 09:34:26 -06002619 // TODO: CONTINUE TESTING VALIDATION OF vkCreateSwapchainKHR() ...
Ian Elliott2c1daf52016-05-12 09:41:46 -06002620 // Get the images from a swapchain:
Ian Elliott2c1daf52016-05-12 09:41:46 -06002621 // Acquire an image from a swapchain:
Ian Elliott2c1daf52016-05-12 09:41:46 -06002622 // Present an image to a swapchain:
Ian Elliott2c1daf52016-05-12 09:41:46 -06002623 // Destroy the swapchain:
2624
Mark Lobodzinski085d27a2016-05-17 09:34:26 -06002625 // TODOs:
2626 //
2627 // - Try destroying the device without first destroying the swapchain
2628 //
2629 // - Try destroying the device without first destroying the surface
2630 //
2631 // - Try destroying the surface without first destroying the swapchain
Ian Elliott2c1daf52016-05-12 09:41:46 -06002632
2633 // Destroy the surface:
2634 vkDestroySurfaceKHR(instance(), surface, NULL);
2635
Ian Elliott2c1daf52016-05-12 09:41:46 -06002636 // Tear down the window:
2637 xcb_destroy_window(connection, xcb_window);
2638 xcb_disconnect(connection);
2639
2640#else // VK_USE_PLATFORM_XCB_KHR
Mark Lobodzinski085d27a2016-05-17 09:34:26 -06002641 return;
Ian Elliott2c1daf52016-05-12 09:41:46 -06002642#endif // VK_USE_PLATFORM_XCB_KHR
2643}
2644
Karl Schultz6addd812016-02-02 17:17:23 -07002645TEST_F(VkLayerTest, MapMemWithoutHostVisibleBit) {
2646 VkResult err;
2647 bool pass;
Mark Lobodzinski3780e142015-05-14 15:08:13 -05002648
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002649 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
2650 "Mapping Memory without VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06002651
Mark Lobodzinski3780e142015-05-14 15:08:13 -05002652 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinski3780e142015-05-14 15:08:13 -05002653
2654 // Create an image, allocate memory, free it, and then try to bind it
Karl Schultz6addd812016-02-02 17:17:23 -07002655 VkImage image;
2656 VkDeviceMemory mem;
2657 VkMemoryRequirements mem_reqs;
Mark Lobodzinski3780e142015-05-14 15:08:13 -05002658
Karl Schultz6addd812016-02-02 17:17:23 -07002659 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
2660 const int32_t tex_width = 32;
2661 const int32_t tex_height = 32;
Mark Lobodzinski3780e142015-05-14 15:08:13 -05002662
Tony Barboureb254902015-07-15 12:50:33 -06002663 VkImageCreateInfo image_create_info = {};
2664 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
Karl Schultz6addd812016-02-02 17:17:23 -07002665 image_create_info.pNext = NULL;
2666 image_create_info.imageType = VK_IMAGE_TYPE_2D;
2667 image_create_info.format = tex_format;
2668 image_create_info.extent.width = tex_width;
2669 image_create_info.extent.height = tex_height;
2670 image_create_info.extent.depth = 1;
2671 image_create_info.mipLevels = 1;
2672 image_create_info.arrayLayers = 1;
2673 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
2674 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
2675 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
2676 image_create_info.flags = 0;
Chris Forbese65e4d02016-09-13 17:39:18 +12002677 image_create_info.initialLayout = VK_IMAGE_LAYOUT_PREINITIALIZED;
Mark Lobodzinski5fcc4212015-09-14 17:43:42 -06002678
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002679 VkMemoryAllocateInfo mem_alloc = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08002680 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
Karl Schultz6addd812016-02-02 17:17:23 -07002681 mem_alloc.pNext = NULL;
2682 mem_alloc.allocationSize = 0;
Mark Lobodzinski3780e142015-05-14 15:08:13 -05002683
Chia-I Wuf7458c52015-10-26 21:10:41 +08002684 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
Mark Lobodzinski3780e142015-05-14 15:08:13 -05002685 ASSERT_VK_SUCCESS(err);
2686
Karl Schultz6addd812016-02-02 17:17:23 -07002687 vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs);
Mark Lobodzinski3780e142015-05-14 15:08:13 -05002688
Mark Lobodzinski23065352015-05-29 09:32:35 -05002689 mem_alloc.allocationSize = mem_reqs.size;
Mark Lobodzinski3780e142015-05-14 15:08:13 -05002690
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002691 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0, VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT);
Karl Schultz6addd812016-02-02 17:17:23 -07002692 if (!pass) { // If we can't find any unmappable memory this test doesn't
2693 // make sense
Chia-I Wuf7458c52015-10-26 21:10:41 +08002694 vkDestroyImage(m_device->device(), image, NULL);
Tony Barbour02fdc7d2015-08-04 16:13:01 -06002695 return;
Mike Stroyand1c84a52015-08-18 14:40:24 -06002696 }
Mike Stroyan713b2d72015-08-04 10:49:29 -06002697
Mark Lobodzinski3780e142015-05-14 15:08:13 -05002698 // allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002699 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem);
Mark Lobodzinski3780e142015-05-14 15:08:13 -05002700 ASSERT_VK_SUCCESS(err);
2701
2702 // Try to bind free memory that has been freed
Tony Barbour67e99152015-07-10 14:10:27 -06002703 err = vkBindImageMemory(m_device->device(), image, mem, 0);
Mark Lobodzinski3780e142015-05-14 15:08:13 -05002704 ASSERT_VK_SUCCESS(err);
2705
2706 // Map memory as if to initialize the image
2707 void *mappedAddress = NULL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002708 err = vkMapMemory(m_device->device(), mem, 0, VK_WHOLE_SIZE, 0, &mappedAddress);
Mark Lobodzinski3780e142015-05-14 15:08:13 -05002709
Chris Forbes8f36a8a2016-04-07 13:21:07 +12002710 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06002711
Chia-I Wuf7458c52015-10-26 21:10:41 +08002712 vkDestroyImage(m_device->device(), image, NULL);
Tony Barbourdf4c0042016-06-01 15:55:43 -06002713 vkFreeMemory(m_device->device(), mem, NULL);
Mark Lobodzinski3780e142015-05-14 15:08:13 -05002714}
2715
Karl Schultz6addd812016-02-02 17:17:23 -07002716TEST_F(VkLayerTest, RebindMemory) {
2717 VkResult err;
2718 bool pass;
Mark Lobodzinski944aab12015-06-05 13:59:04 -05002719
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002720 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "which has already been bound to mem object");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06002721
Mark Lobodzinski944aab12015-06-05 13:59:04 -05002722 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinski944aab12015-06-05 13:59:04 -05002723
2724 // Create an image, allocate memory, free it, and then try to bind it
Karl Schultz6addd812016-02-02 17:17:23 -07002725 VkImage image;
2726 VkDeviceMemory mem1;
2727 VkDeviceMemory mem2;
2728 VkMemoryRequirements mem_reqs;
Mark Lobodzinski944aab12015-06-05 13:59:04 -05002729
Karl Schultz6addd812016-02-02 17:17:23 -07002730 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
2731 const int32_t tex_width = 32;
2732 const int32_t tex_height = 32;
Mark Lobodzinski944aab12015-06-05 13:59:04 -05002733
Tony Barboureb254902015-07-15 12:50:33 -06002734 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -07002735 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
2736 image_create_info.pNext = NULL;
2737 image_create_info.imageType = VK_IMAGE_TYPE_2D;
2738 image_create_info.format = tex_format;
2739 image_create_info.extent.width = tex_width;
2740 image_create_info.extent.height = tex_height;
2741 image_create_info.extent.depth = 1;
2742 image_create_info.mipLevels = 1;
2743 image_create_info.arrayLayers = 1;
2744 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
2745 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
2746 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
2747 image_create_info.flags = 0;
Mark Lobodzinski944aab12015-06-05 13:59:04 -05002748
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002749 VkMemoryAllocateInfo mem_alloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -07002750 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
2751 mem_alloc.pNext = NULL;
2752 mem_alloc.allocationSize = 0;
2753 mem_alloc.memoryTypeIndex = 0;
Tony Barboureb254902015-07-15 12:50:33 -06002754
Karl Schultz6addd812016-02-02 17:17:23 -07002755 // Introduce failure, do NOT set memProps to
2756 // VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT
Tony Barboureb254902015-07-15 12:50:33 -06002757 mem_alloc.memoryTypeIndex = 1;
Chia-I Wuf7458c52015-10-26 21:10:41 +08002758 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
Mark Lobodzinski944aab12015-06-05 13:59:04 -05002759 ASSERT_VK_SUCCESS(err);
2760
Karl Schultz6addd812016-02-02 17:17:23 -07002761 vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs);
Mark Lobodzinski944aab12015-06-05 13:59:04 -05002762
2763 mem_alloc.allocationSize = mem_reqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002764 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -06002765 ASSERT_TRUE(pass);
Mark Lobodzinski944aab12015-06-05 13:59:04 -05002766
2767 // allocate 2 memory objects
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002768 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem1);
Mark Lobodzinski944aab12015-06-05 13:59:04 -05002769 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002770 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem2);
Mark Lobodzinski944aab12015-06-05 13:59:04 -05002771 ASSERT_VK_SUCCESS(err);
2772
2773 // Bind first memory object to Image object
Tony Barbour67e99152015-07-10 14:10:27 -06002774 err = vkBindImageMemory(m_device->device(), image, mem1, 0);
Mark Lobodzinski944aab12015-06-05 13:59:04 -05002775 ASSERT_VK_SUCCESS(err);
2776
Karl Schultz6addd812016-02-02 17:17:23 -07002777 // Introduce validation failure, try to bind a different memory object to
2778 // the same image object
Tony Barbour67e99152015-07-10 14:10:27 -06002779 err = vkBindImageMemory(m_device->device(), image, mem2, 0);
Mark Lobodzinski944aab12015-06-05 13:59:04 -05002780
Chris Forbes8f36a8a2016-04-07 13:21:07 +12002781 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06002782
Chia-I Wuf7458c52015-10-26 21:10:41 +08002783 vkDestroyImage(m_device->device(), image, NULL);
2784 vkFreeMemory(m_device->device(), mem1, NULL);
2785 vkFreeMemory(m_device->device(), mem2, NULL);
Mark Lobodzinski944aab12015-06-05 13:59:04 -05002786}
Mark Lobodzinski3780e142015-05-14 15:08:13 -05002787
Karl Schultz6addd812016-02-02 17:17:23 -07002788TEST_F(VkLayerTest, SubmitSignaledFence) {
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06002789 vk_testing::Fence testFence;
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06002790
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002791 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "submitted in SIGNALED state. Fences "
2792 "must be reset before being submitted");
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06002793
2794 VkFenceCreateInfo fenceInfo = {};
Tony Barbour0b4d9562015-04-09 10:48:04 -06002795 fenceInfo.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
2796 fenceInfo.pNext = NULL;
2797 fenceInfo.flags = VK_FENCE_CREATE_SIGNALED_BIT;
Tony Barbour300a6082015-04-07 13:44:53 -06002798
Tony Barbour300a6082015-04-07 13:44:53 -06002799 ASSERT_NO_FATAL_FAILURE(InitState());
2800 ASSERT_NO_FATAL_FAILURE(InitViewport());
2801 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
2802
Tony Barbourfe3351b2015-07-28 10:17:20 -06002803 BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002804 m_commandBuffer->ClearAllBuffers(m_clear_color, m_depth_clear_color, m_stencil_clear_color, NULL);
Tony Barbourfe3351b2015-07-28 10:17:20 -06002805 EndCommandBuffer();
Tony Barbour300a6082015-04-07 13:44:53 -06002806
2807 testFence.init(*m_device, fenceInfo);
Mark Lobodzinski5fcc4212015-09-14 17:43:42 -06002808
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06002809 VkSubmitInfo submit_info;
Chia-I Wuf9be13c2015-10-26 20:37:06 +08002810 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
2811 submit_info.pNext = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08002812 submit_info.waitSemaphoreCount = 0;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06002813 submit_info.pWaitSemaphores = NULL;
Jon Ashburn7f9716c2015-12-30 16:42:50 -07002814 submit_info.pWaitDstStageMask = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08002815 submit_info.commandBufferCount = 1;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002816 submit_info.pCommandBuffers = &m_commandBuffer->handle();
Chia-I Wud50a7d72015-10-26 20:48:51 +08002817 submit_info.signalSemaphoreCount = 0;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06002818 submit_info.pSignalSemaphores = NULL;
Courtney Goeltzenleuchter646b9072015-10-20 18:04:07 -06002819
2820 vkQueueSubmit(m_device->m_queue, 1, &submit_info, testFence.handle());
Karl Schultz6addd812016-02-02 17:17:23 -07002821 vkQueueWaitIdle(m_device->m_queue);
Mark Lobodzinski5fcc4212015-09-14 17:43:42 -06002822
Chris Forbes8f36a8a2016-04-07 13:21:07 +12002823 m_errorMonitor->VerifyFound();
Tony Barbour0b4d9562015-04-09 10:48:04 -06002824}
Tobin Ehlisaff7ae92016-04-18 15:45:20 -06002825// This is a positive test. We used to expect error in this case but spec now
2826// allows it
Karl Schultz6addd812016-02-02 17:17:23 -07002827TEST_F(VkLayerTest, ResetUnsignaledFence) {
Tobin Ehlisaff7ae92016-04-18 15:45:20 -06002828 m_errorMonitor->ExpectSuccess();
Tony Barbour0b4d9562015-04-09 10:48:04 -06002829 vk_testing::Fence testFence;
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06002830 VkFenceCreateInfo fenceInfo = {};
Tony Barbour0b4d9562015-04-09 10:48:04 -06002831 fenceInfo.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
2832 fenceInfo.pNext = NULL;
2833
Tony Barbour0b4d9562015-04-09 10:48:04 -06002834 ASSERT_NO_FATAL_FAILURE(InitState());
2835 testFence.init(*m_device, fenceInfo);
Chia-I Wud9e8e822015-07-03 11:45:55 +08002836 VkFence fences[1] = {testFence.handle()};
Tobin Ehlisaff7ae92016-04-18 15:45:20 -06002837 VkResult result = vkResetFences(m_device->device(), 1, fences);
2838 ASSERT_VK_SUCCESS(result);
Tony Barbour300a6082015-04-07 13:44:53 -06002839
Tobin Ehlisaff7ae92016-04-18 15:45:20 -06002840 m_errorMonitor->VerifyNotFound();
Tony Barbour300a6082015-04-07 13:44:53 -06002841}
Tobin Ehlis56ab9022016-08-17 17:59:31 -06002842#if 0 // A few devices have issues with this test so disabling for now
Chris Forbese70b7d32016-06-15 15:49:12 +12002843TEST_F(VkLayerTest, LongFenceChain)
2844{
2845 m_errorMonitor->ExpectSuccess();
2846
2847 ASSERT_NO_FATAL_FAILURE(InitState());
2848 VkResult err;
2849
2850 std::vector<VkFence> fences;
2851
2852 const int chainLength = 32768;
2853
2854 for (int i = 0; i < chainLength; i++) {
2855 VkFenceCreateInfo fci = { VK_STRUCTURE_TYPE_FENCE_CREATE_INFO, nullptr, 0 };
2856 VkFence fence;
2857 err = vkCreateFence(m_device->device(), &fci, nullptr, &fence);
2858 ASSERT_VK_SUCCESS(err);
2859
2860 fences.push_back(fence);
2861
2862 VkSubmitInfo si = { VK_STRUCTURE_TYPE_SUBMIT_INFO, nullptr, 0, nullptr, nullptr,
2863 0, nullptr, 0, nullptr };
2864 err = vkQueueSubmit(m_device->m_queue, 1, &si, fence);
2865 ASSERT_VK_SUCCESS(err);
2866
2867 }
2868
2869 // BOOM, stack overflow.
2870 vkWaitForFences(m_device->device(), 1, &fences.back(), VK_TRUE, UINT64_MAX);
2871
2872 for (auto fence : fences)
2873 vkDestroyFence(m_device->device(), fence, nullptr);
2874
2875 m_errorMonitor->VerifyNotFound();
2876}
Tobin Ehlis56ab9022016-08-17 17:59:31 -06002877#endif
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002878TEST_F(VkLayerTest, CommandBufferSimultaneousUseSync) {
Chris Forbes18127d12016-06-08 16:52:28 +12002879 m_errorMonitor->ExpectSuccess();
2880
2881 ASSERT_NO_FATAL_FAILURE(InitState());
2882 VkResult err;
2883
2884 // Record (empty!) command buffer that can be submitted multiple times
2885 // simultaneously.
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002886 VkCommandBufferBeginInfo cbbi = {VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO, nullptr,
2887 VK_COMMAND_BUFFER_USAGE_SIMULTANEOUS_USE_BIT, nullptr};
Chris Forbes18127d12016-06-08 16:52:28 +12002888 m_commandBuffer->BeginCommandBuffer(&cbbi);
2889 m_commandBuffer->EndCommandBuffer();
2890
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002891 VkFenceCreateInfo fci = {VK_STRUCTURE_TYPE_FENCE_CREATE_INFO, nullptr, 0};
Chris Forbes18127d12016-06-08 16:52:28 +12002892 VkFence fence;
2893 err = vkCreateFence(m_device->device(), &fci, nullptr, &fence);
2894 ASSERT_VK_SUCCESS(err);
2895
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002896 VkSemaphoreCreateInfo sci = {VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO, nullptr, 0};
Chris Forbes18127d12016-06-08 16:52:28 +12002897 VkSemaphore s1, s2;
2898 err = vkCreateSemaphore(m_device->device(), &sci, nullptr, &s1);
2899 ASSERT_VK_SUCCESS(err);
2900 err = vkCreateSemaphore(m_device->device(), &sci, nullptr, &s2);
2901 ASSERT_VK_SUCCESS(err);
2902
2903 // Submit CB once signaling s1, with fence so we can roll forward to its retirement.
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002904 VkSubmitInfo si = {VK_STRUCTURE_TYPE_SUBMIT_INFO, nullptr, 0, nullptr, nullptr, 1, &m_commandBuffer->handle(), 1, &s1};
Chris Forbes18127d12016-06-08 16:52:28 +12002905 err = vkQueueSubmit(m_device->m_queue, 1, &si, fence);
2906 ASSERT_VK_SUCCESS(err);
2907
2908 // Submit CB again, signaling s2.
2909 si.pSignalSemaphores = &s2;
2910 err = vkQueueSubmit(m_device->m_queue, 1, &si, VK_NULL_HANDLE);
2911 ASSERT_VK_SUCCESS(err);
2912
2913 // Wait for fence.
2914 err = vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
2915 ASSERT_VK_SUCCESS(err);
2916
2917 // CB is still in flight from second submission, but semaphore s1 is no
2918 // longer in flight. delete it.
2919 vkDestroySemaphore(m_device->device(), s1, nullptr);
2920
2921 m_errorMonitor->VerifyNotFound();
2922
2923 // Force device idle and clean up remaining objects
2924 vkDeviceWaitIdle(m_device->device());
2925 vkDestroySemaphore(m_device->device(), s2, nullptr);
2926 vkDestroyFence(m_device->device(), fence, nullptr);
2927}
2928
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002929TEST_F(VkLayerTest, FenceCreateSignaledWaitHandling) {
Chris Forbes4e44c912016-06-16 10:20:00 +12002930 m_errorMonitor->ExpectSuccess();
2931
2932 ASSERT_NO_FATAL_FAILURE(InitState());
2933 VkResult err;
2934
2935 // A fence created signaled
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002936 VkFenceCreateInfo fci1 = {VK_STRUCTURE_TYPE_FENCE_CREATE_INFO, nullptr, VK_FENCE_CREATE_SIGNALED_BIT};
Chris Forbes4e44c912016-06-16 10:20:00 +12002937 VkFence f1;
2938 err = vkCreateFence(m_device->device(), &fci1, nullptr, &f1);
2939 ASSERT_VK_SUCCESS(err);
2940
2941 // A fence created not
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002942 VkFenceCreateInfo fci2 = {VK_STRUCTURE_TYPE_FENCE_CREATE_INFO, nullptr, 0};
Chris Forbes4e44c912016-06-16 10:20:00 +12002943 VkFence f2;
2944 err = vkCreateFence(m_device->device(), &fci2, nullptr, &f2);
2945 ASSERT_VK_SUCCESS(err);
2946
2947 // Submit the unsignaled fence
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002948 VkSubmitInfo si = {VK_STRUCTURE_TYPE_SUBMIT_INFO, nullptr, 0, nullptr, nullptr, 0, nullptr, 0, nullptr};
Chris Forbes4e44c912016-06-16 10:20:00 +12002949 err = vkQueueSubmit(m_device->m_queue, 1, &si, f2);
2950
2951 // Wait on both fences, with signaled first.
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002952 VkFence fences[] = {f1, f2};
Chris Forbes4e44c912016-06-16 10:20:00 +12002953 vkWaitForFences(m_device->device(), 2, fences, VK_TRUE, UINT64_MAX);
2954
2955 // Should have both retired!
2956 vkDestroyFence(m_device->device(), f1, nullptr);
2957 vkDestroyFence(m_device->device(), f2, nullptr);
2958
2959 m_errorMonitor->VerifyNotFound();
2960}
2961
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002962TEST_F(VkLayerTest, InvalidUsageBits) {
2963 TEST_DESCRIPTION("Specify wrong usage for image then create conflicting view of image "
2964 "Initialize buffer with wrong usage then perform copy expecting errors "
2965 "from both the image and the buffer (2 calls)");
2966 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Invalid usage flag for image ");
Tobin Ehlis41376e12015-07-03 08:45:14 -06002967
2968 ASSERT_NO_FATAL_FAILURE(InitState());
Tony Barbourf92621a2016-05-02 14:28:12 -06002969 VkImageObj image(m_device);
Tony Barbour75d79f02016-08-30 09:39:07 -06002970 // Initialize image with USAGE_TRANSIENT_ATTACHMENT
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002971 image.init(128, 128, VK_FORMAT_D24_UNORM_S8_UINT, VK_IMAGE_USAGE_TRANSIENT_ATTACHMENT_BIT, VK_IMAGE_TILING_OPTIMAL, 0);
Karl Schultzb5bc11e2016-05-04 08:36:08 -06002972 ASSERT_TRUE(image.initialized());
Tobin Ehlis41376e12015-07-03 08:45:14 -06002973
Tony Barbourf92621a2016-05-02 14:28:12 -06002974 VkImageView dsv;
2975 VkImageViewCreateInfo dsvci = {};
2976 dsvci.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
2977 dsvci.image = image.handle();
2978 dsvci.viewType = VK_IMAGE_VIEW_TYPE_2D;
2979 dsvci.format = VK_FORMAT_D32_SFLOAT_S8_UINT;
2980 dsvci.subresourceRange.layerCount = 1;
2981 dsvci.subresourceRange.baseMipLevel = 0;
2982 dsvci.subresourceRange.levelCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002983 dsvci.subresourceRange.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT;
Tobin Ehlis41376e12015-07-03 08:45:14 -06002984
Tony Barbourf92621a2016-05-02 14:28:12 -06002985 // Create a view with depth / stencil aspect for image with different usage
2986 vkCreateImageView(m_device->device(), &dsvci, NULL, &dsv);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06002987
Chris Forbes8f36a8a2016-04-07 13:21:07 +12002988 m_errorMonitor->VerifyFound();
Tony Barbourf92621a2016-05-02 14:28:12 -06002989
2990 // Initialize buffer with TRANSFER_DST usage
2991 vk_testing::Buffer buffer;
2992 VkMemoryPropertyFlags reqs = 0;
2993 buffer.init_as_dst(*m_device, 128 * 128, reqs);
2994 VkBufferImageCopy region = {};
2995 region.bufferRowLength = 128;
2996 region.bufferImageHeight = 128;
2997 region.imageSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
2998 region.imageSubresource.layerCount = 1;
2999 region.imageExtent.height = 16;
3000 region.imageExtent.width = 16;
3001 region.imageExtent.depth = 1;
3002
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003003 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Invalid usage flag for buffer ");
Tony Barbourf92621a2016-05-02 14:28:12 -06003004 // Buffer usage not set to TRANSFER_SRC and image usage not set to
3005 // TRANSFER_DST
3006 BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003007 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer.handle(), image.handle(),
3008 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, &region);
Tony Barbourf92621a2016-05-02 14:28:12 -06003009 m_errorMonitor->VerifyFound();
3010
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003011 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Invalid usage flag for image ");
3012 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer.handle(), image.handle(),
3013 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, &region);
Tony Barbourf92621a2016-05-02 14:28:12 -06003014 m_errorMonitor->VerifyFound();
Tobin Ehlis41376e12015-07-03 08:45:14 -06003015}
Tony Barbour75d79f02016-08-30 09:39:07 -06003016
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003017TEST_F(VkLayerTest, ValidUsage) {
3018 TEST_DESCRIPTION("Verify that creating an image view from an image with valid usage "
3019 "doesn't generate validation errors");
Tony Barbour75d79f02016-08-30 09:39:07 -06003020
3021 ASSERT_NO_FATAL_FAILURE(InitState());
3022
3023 m_errorMonitor->ExpectSuccess();
3024 // Verify that we can create a view with usage INPUT_ATTACHMENT
3025 VkImageObj image(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003026 image.init(128, 128, VK_FORMAT_R8G8B8A8_UNORM, VK_IMAGE_USAGE_INPUT_ATTACHMENT_BIT, VK_IMAGE_TILING_OPTIMAL, 0);
Tony Barbour75d79f02016-08-30 09:39:07 -06003027 ASSERT_TRUE(image.initialized());
3028 VkImageView imageView;
3029 VkImageViewCreateInfo ivci = {};
3030 ivci.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
3031 ivci.image = image.handle();
3032 ivci.viewType = VK_IMAGE_VIEW_TYPE_2D;
3033 ivci.format = VK_FORMAT_R8G8B8A8_UNORM;
3034 ivci.subresourceRange.layerCount = 1;
3035 ivci.subresourceRange.baseMipLevel = 0;
3036 ivci.subresourceRange.levelCount = 1;
3037 ivci.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
3038
3039 vkCreateImageView(m_device->device(), &ivci, NULL, &imageView);
3040 m_errorMonitor->VerifyNotFound();
3041 vkDestroyImageView(m_device->device(), imageView, NULL);
3042}
Mark Lobodzinski209b5292015-09-17 09:44:05 -06003043#endif // MEM_TRACKER_TESTS
3044
Tobin Ehlis4bf96d12015-06-25 11:58:41 -06003045#if OBJ_TRACKER_TESTS
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06003046
3047TEST_F(VkLayerTest, LeakAnObject) {
3048 VkResult err;
3049
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003050 TEST_DESCRIPTION("Create a fence and destroy its device without first destroying the fence.");
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06003051
3052 // Note that we have to create a new device since destroying the
3053 // framework's device causes Teardown() to fail and just calling Teardown
3054 // will destroy the errorMonitor.
3055
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003056 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "has not been destroyed.");
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06003057
3058 ASSERT_NO_FATAL_FAILURE(InitState());
3059
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003060 const std::vector<VkQueueFamilyProperties> queue_props = m_device->queue_props;
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06003061 std::vector<VkDeviceQueueCreateInfo> queue_info;
3062 queue_info.reserve(queue_props.size());
3063 std::vector<std::vector<float>> queue_priorities;
3064 for (uint32_t i = 0; i < (uint32_t)queue_props.size(); i++) {
3065 VkDeviceQueueCreateInfo qi = {};
3066 qi.sType = VK_STRUCTURE_TYPE_DEVICE_QUEUE_CREATE_INFO;
3067 qi.pNext = NULL;
3068 qi.queueFamilyIndex = i;
3069 qi.queueCount = queue_props[i].queueCount;
3070 queue_priorities.emplace_back(qi.queueCount, 0.0f);
3071 qi.pQueuePriorities = queue_priorities[i].data();
3072 queue_info.push_back(qi);
3073 }
3074
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06003075 std::vector<const char *> device_extension_names;
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06003076
3077 // The sacrificial device object
3078 VkDevice testDevice;
3079 VkDeviceCreateInfo device_create_info = {};
3080 auto features = m_device->phy().features();
3081 device_create_info.sType = VK_STRUCTURE_TYPE_DEVICE_CREATE_INFO;
3082 device_create_info.pNext = NULL;
3083 device_create_info.queueCreateInfoCount = queue_info.size();
3084 device_create_info.pQueueCreateInfos = queue_info.data();
Tony Barbour4c70d102016-08-08 16:06:56 -06003085 device_create_info.enabledLayerCount = 0;
3086 device_create_info.ppEnabledLayerNames = NULL;
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06003087 device_create_info.pEnabledFeatures = &features;
3088 err = vkCreateDevice(gpu(), &device_create_info, NULL, &testDevice);
3089 ASSERT_VK_SUCCESS(err);
3090
3091 VkFence fence;
3092 VkFenceCreateInfo fence_create_info = {};
3093 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
3094 fence_create_info.pNext = NULL;
3095 fence_create_info.flags = 0;
3096 err = vkCreateFence(testDevice, &fence_create_info, NULL, &fence);
3097 ASSERT_VK_SUCCESS(err);
3098
3099 // Induce failure by not calling vkDestroyFence
3100 vkDestroyDevice(testDevice, NULL);
3101 m_errorMonitor->VerifyFound();
3102}
3103
3104TEST_F(VkLayerTest, InvalidCommandPoolConsistency) {
3105
3106 TEST_DESCRIPTION("Allocate command buffers from one command pool and "
3107 "attempt to delete them from another.");
3108
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003109 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "FreeCommandBuffers is attempting to free Command Buffer");
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06003110
Cody Northropc31a84f2016-08-22 10:41:47 -06003111 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06003112 VkCommandPool command_pool_one;
3113 VkCommandPool command_pool_two;
3114
3115 VkCommandPoolCreateInfo pool_create_info{};
3116 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
3117 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
3118 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
3119
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003120 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool_one);
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06003121
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003122 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool_two);
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06003123
3124 VkCommandBuffer command_buffer[9];
3125 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003126 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06003127 command_buffer_allocate_info.commandPool = command_pool_one;
3128 command_buffer_allocate_info.commandBufferCount = 9;
3129 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003130 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, command_buffer);
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06003131
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003132 vkFreeCommandBuffers(m_device->device(), command_pool_two, 4, &command_buffer[3]);
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06003133
3134 m_errorMonitor->VerifyFound();
3135
3136 vkDestroyCommandPool(m_device->device(), command_pool_one, NULL);
3137 vkDestroyCommandPool(m_device->device(), command_pool_two, NULL);
3138}
3139
3140TEST_F(VkLayerTest, InvalidDescriptorPoolConsistency) {
3141 VkResult err;
3142
3143 TEST_DESCRIPTION("Allocate descriptor sets from one DS pool and "
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003144 "attempt to delete them from another.");
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06003145
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003146 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "FreeDescriptorSets is attempting to free descriptorSet");
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06003147
3148 ASSERT_NO_FATAL_FAILURE(InitState());
3149 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
3150
3151 VkDescriptorPoolSize ds_type_count = {};
3152 ds_type_count.type = VK_DESCRIPTOR_TYPE_SAMPLER;
3153 ds_type_count.descriptorCount = 1;
3154
3155 VkDescriptorPoolCreateInfo ds_pool_ci = {};
3156 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
3157 ds_pool_ci.pNext = NULL;
3158 ds_pool_ci.flags = 0;
3159 ds_pool_ci.maxSets = 1;
3160 ds_pool_ci.poolSizeCount = 1;
3161 ds_pool_ci.pPoolSizes = &ds_type_count;
3162
3163 VkDescriptorPool ds_pool_one;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003164 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool_one);
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06003165 ASSERT_VK_SUCCESS(err);
3166
3167 // Create a second descriptor pool
3168 VkDescriptorPool ds_pool_two;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003169 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool_two);
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06003170 ASSERT_VK_SUCCESS(err);
3171
3172 VkDescriptorSetLayoutBinding dsl_binding = {};
3173 dsl_binding.binding = 0;
3174 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
3175 dsl_binding.descriptorCount = 1;
3176 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
3177 dsl_binding.pImmutableSamplers = NULL;
3178
3179 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
3180 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
3181 ds_layout_ci.pNext = NULL;
3182 ds_layout_ci.bindingCount = 1;
3183 ds_layout_ci.pBindings = &dsl_binding;
3184
3185 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003186 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06003187 ASSERT_VK_SUCCESS(err);
3188
3189 VkDescriptorSet descriptorSet;
3190 VkDescriptorSetAllocateInfo alloc_info = {};
3191 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
3192 alloc_info.descriptorSetCount = 1;
3193 alloc_info.descriptorPool = ds_pool_one;
3194 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003195 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06003196 ASSERT_VK_SUCCESS(err);
3197
3198 err = vkFreeDescriptorSets(m_device->device(), ds_pool_two, 1, &descriptorSet);
3199
3200 m_errorMonitor->VerifyFound();
3201
3202 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
3203 vkDestroyDescriptorPool(m_device->device(), ds_pool_one, NULL);
3204 vkDestroyDescriptorPool(m_device->device(), ds_pool_two, NULL);
3205}
3206
3207TEST_F(VkLayerTest, CreateUnknownObject) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003208 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Invalid Image Object ");
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06003209
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003210 TEST_DESCRIPTION("Pass an invalid image object handle into a Vulkan API call.");
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06003211
3212 ASSERT_NO_FATAL_FAILURE(InitState());
3213
3214 // Pass bogus handle into GetImageMemoryRequirements
3215 VkMemoryRequirements mem_reqs;
3216 uint64_t fakeImageHandle = 0xCADECADE;
3217 VkImage fauxImage = reinterpret_cast<VkImage &>(fakeImageHandle);
3218
3219 vkGetImageMemoryRequirements(m_device->device(), fauxImage, &mem_reqs);
3220
3221 m_errorMonitor->VerifyFound();
3222}
3223
Karl Schultz6addd812016-02-02 17:17:23 -07003224TEST_F(VkLayerTest, PipelineNotBound) {
3225 VkResult err;
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06003226
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003227 TEST_DESCRIPTION("Pass in an invalid pipeline object handle into a Vulkan API call.");
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06003228
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003229 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Invalid Pipeline Object ");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06003230
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06003231 ASSERT_NO_FATAL_FAILURE(InitState());
3232 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06003233
Chia-I Wu1b99bb22015-10-27 19:25:11 +08003234 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07003235 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
3236 ds_type_count.descriptorCount = 1;
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06003237
3238 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07003239 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
3240 ds_pool_ci.pNext = NULL;
3241 ds_pool_ci.maxSets = 1;
3242 ds_pool_ci.poolSizeCount = 1;
3243 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06003244
3245 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003246 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06003247 ASSERT_VK_SUCCESS(err);
3248
3249 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07003250 dsl_binding.binding = 0;
3251 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
3252 dsl_binding.descriptorCount = 1;
3253 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
3254 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06003255
3256 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07003257 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
3258 ds_layout_ci.pNext = NULL;
3259 ds_layout_ci.bindingCount = 1;
3260 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06003261
3262 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003263 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06003264 ASSERT_VK_SUCCESS(err);
3265
3266 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08003267 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08003268 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07003269 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06003270 alloc_info.descriptorPool = ds_pool;
3271 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003272 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06003273 ASSERT_VK_SUCCESS(err);
3274
3275 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07003276 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
3277 pipeline_layout_ci.pNext = NULL;
3278 pipeline_layout_ci.setLayoutCount = 1;
3279 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06003280
3281 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003282 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06003283 ASSERT_VK_SUCCESS(err);
3284
Mark Youngad779052016-01-06 14:26:04 -07003285 VkPipeline badPipeline = (VkPipeline)((size_t)0xbaadb1be);
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06003286
3287 BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003288 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, badPipeline);
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06003289
Chris Forbes8f36a8a2016-04-07 13:21:07 +12003290 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06003291
Chia-I Wuf7458c52015-10-26 21:10:41 +08003292 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
3293 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
3294 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlisec598302015-09-15 15:02:17 -06003295}
Mike Stroyan80fc6c32016-06-20 15:42:29 -06003296
Mark Lobodzinskibc185762016-06-15 16:28:53 -06003297TEST_F(VkLayerTest, BindImageInvalidMemoryType) {
3298 VkResult err;
3299
3300 TEST_DESCRIPTION("Test validation check for an invalid memory type index "
3301 "during bind[Buffer|Image]Memory time");
3302
Mark Lobodzinskibc185762016-06-15 16:28:53 -06003303 ASSERT_NO_FATAL_FAILURE(InitState());
3304
3305 // Create an image, allocate memory, set a bad typeIndex and then try to
3306 // bind it
3307 VkImage image;
3308 VkDeviceMemory mem;
3309 VkMemoryRequirements mem_reqs;
3310 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
3311 const int32_t tex_width = 32;
3312 const int32_t tex_height = 32;
3313
3314 VkImageCreateInfo image_create_info = {};
3315 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
3316 image_create_info.pNext = NULL;
3317 image_create_info.imageType = VK_IMAGE_TYPE_2D;
3318 image_create_info.format = tex_format;
3319 image_create_info.extent.width = tex_width;
3320 image_create_info.extent.height = tex_height;
3321 image_create_info.extent.depth = 1;
3322 image_create_info.mipLevels = 1;
3323 image_create_info.arrayLayers = 1;
3324 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
3325 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
3326 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
3327 image_create_info.flags = 0;
3328
3329 VkMemoryAllocateInfo mem_alloc = {};
3330 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
3331 mem_alloc.pNext = NULL;
3332 mem_alloc.allocationSize = 0;
3333 mem_alloc.memoryTypeIndex = 0;
3334
3335 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
3336 ASSERT_VK_SUCCESS(err);
3337
3338 vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs);
3339 mem_alloc.allocationSize = mem_reqs.size;
Mike Stroyan80fc6c32016-06-20 15:42:29 -06003340
3341 // Introduce Failure, select invalid TypeIndex
3342 VkPhysicalDeviceMemoryProperties memory_info;
3343
3344 vkGetPhysicalDeviceMemoryProperties(gpu(), &memory_info);
3345 unsigned int i;
3346 for (i = 0; i < memory_info.memoryTypeCount; i++) {
3347 if ((mem_reqs.memoryTypeBits & (1 << i)) == 0) {
3348 mem_alloc.memoryTypeIndex = i;
3349 break;
3350 }
3351 }
3352 if (i >= memory_info.memoryTypeCount) {
3353 printf("No invalid memory type index could be found; skipped.\n");
3354 vkDestroyImage(m_device->device(), image, NULL);
3355 return;
3356 }
3357
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003358 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "for this object type are not compatible with the memory");
Mark Lobodzinskibc185762016-06-15 16:28:53 -06003359
3360 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem);
3361 ASSERT_VK_SUCCESS(err);
3362
3363 err = vkBindImageMemory(m_device->device(), image, mem, 0);
3364 (void)err;
3365
3366 m_errorMonitor->VerifyFound();
3367
3368 vkDestroyImage(m_device->device(), image, NULL);
3369 vkFreeMemory(m_device->device(), mem, NULL);
3370}
Mike Stroyan80fc6c32016-06-20 15:42:29 -06003371
Karl Schultz6addd812016-02-02 17:17:23 -07003372TEST_F(VkLayerTest, BindInvalidMemory) {
3373 VkResult err;
3374 bool pass;
Tobin Ehlisec598302015-09-15 15:02:17 -06003375
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003376 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Invalid Device Memory Object ");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06003377
Tobin Ehlisec598302015-09-15 15:02:17 -06003378 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisec598302015-09-15 15:02:17 -06003379
3380 // Create an image, allocate memory, free it, and then try to bind it
Karl Schultz6addd812016-02-02 17:17:23 -07003381 VkImage image;
3382 VkDeviceMemory mem;
3383 VkMemoryRequirements mem_reqs;
Tobin Ehlisec598302015-09-15 15:02:17 -06003384
Karl Schultz6addd812016-02-02 17:17:23 -07003385 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
3386 const int32_t tex_width = 32;
3387 const int32_t tex_height = 32;
Tobin Ehlisec598302015-09-15 15:02:17 -06003388
3389 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -07003390 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
3391 image_create_info.pNext = NULL;
3392 image_create_info.imageType = VK_IMAGE_TYPE_2D;
3393 image_create_info.format = tex_format;
3394 image_create_info.extent.width = tex_width;
3395 image_create_info.extent.height = tex_height;
3396 image_create_info.extent.depth = 1;
3397 image_create_info.mipLevels = 1;
3398 image_create_info.arrayLayers = 1;
3399 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
3400 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
3401 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
3402 image_create_info.flags = 0;
Tobin Ehlisec598302015-09-15 15:02:17 -06003403
Chia-I Wu3432a0c2015-10-27 18:04:07 +08003404 VkMemoryAllocateInfo mem_alloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -07003405 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
3406 mem_alloc.pNext = NULL;
3407 mem_alloc.allocationSize = 0;
3408 mem_alloc.memoryTypeIndex = 0;
Tobin Ehlisec598302015-09-15 15:02:17 -06003409
Chia-I Wuf7458c52015-10-26 21:10:41 +08003410 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
Tobin Ehlisec598302015-09-15 15:02:17 -06003411 ASSERT_VK_SUCCESS(err);
3412
Karl Schultz6addd812016-02-02 17:17:23 -07003413 vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs);
Tobin Ehlisec598302015-09-15 15:02:17 -06003414
3415 mem_alloc.allocationSize = mem_reqs.size;
3416
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003417 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -06003418 ASSERT_TRUE(pass);
Tobin Ehlisec598302015-09-15 15:02:17 -06003419
3420 // allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +08003421 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem);
Tobin Ehlisec598302015-09-15 15:02:17 -06003422 ASSERT_VK_SUCCESS(err);
3423
3424 // Introduce validation failure, free memory before binding
Chia-I Wuf7458c52015-10-26 21:10:41 +08003425 vkFreeMemory(m_device->device(), mem, NULL);
Tobin Ehlisec598302015-09-15 15:02:17 -06003426
3427 // Try to bind free memory that has been freed
3428 err = vkBindImageMemory(m_device->device(), image, mem, 0);
3429 // This may very well return an error.
3430 (void)err;
3431
Chris Forbes8f36a8a2016-04-07 13:21:07 +12003432 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06003433
Chia-I Wuf7458c52015-10-26 21:10:41 +08003434 vkDestroyImage(m_device->device(), image, NULL);
Tobin Ehlisec598302015-09-15 15:02:17 -06003435}
3436
Karl Schultz6addd812016-02-02 17:17:23 -07003437TEST_F(VkLayerTest, BindMemoryToDestroyedObject) {
3438 VkResult err;
3439 bool pass;
Tobin Ehlisec598302015-09-15 15:02:17 -06003440
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003441 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Invalid Image Object ");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06003442
Tobin Ehlisec598302015-09-15 15:02:17 -06003443 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisec598302015-09-15 15:02:17 -06003444
Karl Schultz6addd812016-02-02 17:17:23 -07003445 // Create an image object, allocate memory, destroy the object and then try
3446 // to bind it
3447 VkImage image;
3448 VkDeviceMemory mem;
3449 VkMemoryRequirements mem_reqs;
Tobin Ehlisec598302015-09-15 15:02:17 -06003450
Karl Schultz6addd812016-02-02 17:17:23 -07003451 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
3452 const int32_t tex_width = 32;
3453 const int32_t tex_height = 32;
Tobin Ehlisec598302015-09-15 15:02:17 -06003454
3455 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -07003456 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
3457 image_create_info.pNext = NULL;
3458 image_create_info.imageType = VK_IMAGE_TYPE_2D;
3459 image_create_info.format = tex_format;
3460 image_create_info.extent.width = tex_width;
3461 image_create_info.extent.height = tex_height;
3462 image_create_info.extent.depth = 1;
3463 image_create_info.mipLevels = 1;
3464 image_create_info.arrayLayers = 1;
3465 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
3466 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
3467 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
3468 image_create_info.flags = 0;
Tobin Ehlisec598302015-09-15 15:02:17 -06003469
Chia-I Wu3432a0c2015-10-27 18:04:07 +08003470 VkMemoryAllocateInfo mem_alloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -07003471 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
3472 mem_alloc.pNext = NULL;
3473 mem_alloc.allocationSize = 0;
3474 mem_alloc.memoryTypeIndex = 0;
Tobin Ehlisec598302015-09-15 15:02:17 -06003475
Chia-I Wuf7458c52015-10-26 21:10:41 +08003476 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
Tobin Ehlisec598302015-09-15 15:02:17 -06003477 ASSERT_VK_SUCCESS(err);
3478
Karl Schultz6addd812016-02-02 17:17:23 -07003479 vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs);
Tobin Ehlisec598302015-09-15 15:02:17 -06003480
3481 mem_alloc.allocationSize = mem_reqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003482 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -06003483 ASSERT_TRUE(pass);
Tobin Ehlisec598302015-09-15 15:02:17 -06003484
3485 // Allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +08003486 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem);
Tobin Ehlisec598302015-09-15 15:02:17 -06003487 ASSERT_VK_SUCCESS(err);
3488
3489 // Introduce validation failure, destroy Image object before binding
Chia-I Wuf7458c52015-10-26 21:10:41 +08003490 vkDestroyImage(m_device->device(), image, NULL);
Tobin Ehlisec598302015-09-15 15:02:17 -06003491 ASSERT_VK_SUCCESS(err);
3492
3493 // Now Try to bind memory to this destroyed object
3494 err = vkBindImageMemory(m_device->device(), image, mem, 0);
3495 // This may very well return an error.
Karl Schultz6addd812016-02-02 17:17:23 -07003496 (void)err;
Tobin Ehlisec598302015-09-15 15:02:17 -06003497
Chris Forbes8f36a8a2016-04-07 13:21:07 +12003498 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06003499
Chia-I Wuf7458c52015-10-26 21:10:41 +08003500 vkFreeMemory(m_device->device(), mem, NULL);
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06003501}
Tobin Ehlisa1c28562015-10-23 16:00:08 -06003502
Mark Lobodzinski209b5292015-09-17 09:44:05 -06003503#endif // OBJ_TRACKER_TESTS
3504
Tobin Ehlis0788f522015-05-26 16:11:58 -06003505#if DRAW_STATE_TESTS
Mark Lobodzinskic808d442016-04-14 10:57:23 -06003506
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06003507TEST_F(VkLayerTest, ImageSampleCounts) {
3508
3509 TEST_DESCRIPTION("Use bad sample counts in image transfer calls to trigger "
3510 "validation errors.");
3511 ASSERT_NO_FATAL_FAILURE(InitState());
3512
3513 VkMemoryPropertyFlags reqs = 0;
3514 VkImageCreateInfo image_create_info = {};
3515 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
3516 image_create_info.pNext = NULL;
3517 image_create_info.imageType = VK_IMAGE_TYPE_2D;
3518 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
3519 image_create_info.extent.width = 256;
3520 image_create_info.extent.height = 256;
3521 image_create_info.extent.depth = 1;
3522 image_create_info.mipLevels = 1;
3523 image_create_info.arrayLayers = 1;
3524 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
3525 image_create_info.flags = 0;
3526
3527 VkImageBlit blit_region = {};
3528 blit_region.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
3529 blit_region.srcSubresource.baseArrayLayer = 0;
3530 blit_region.srcSubresource.layerCount = 1;
3531 blit_region.srcSubresource.mipLevel = 0;
3532 blit_region.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
3533 blit_region.dstSubresource.baseArrayLayer = 0;
3534 blit_region.dstSubresource.layerCount = 1;
3535 blit_region.dstSubresource.mipLevel = 0;
3536
3537 // Create two images, the source with sampleCount = 2, and attempt to blit
3538 // between them
3539 {
3540 image_create_info.samples = VK_SAMPLE_COUNT_2_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003541 image_create_info.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06003542 vk_testing::Image src_image;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003543 src_image.init(*m_device, (const VkImageCreateInfo &)image_create_info, reqs);
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06003544 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003545 image_create_info.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT;
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06003546 vk_testing::Image dst_image;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003547 dst_image.init(*m_device, (const VkImageCreateInfo &)image_create_info, reqs);
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06003548 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003549 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "was created with a sample count "
3550 "of VK_SAMPLE_COUNT_2_BIT but "
3551 "must be VK_SAMPLE_COUNT_1_BIT");
3552 vkCmdBlitImage(m_commandBuffer->GetBufferHandle(), src_image.handle(), VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
3553 dst_image.handle(), VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL, 1, &blit_region, VK_FILTER_NEAREST);
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06003554 m_errorMonitor->VerifyFound();
3555 m_commandBuffer->EndCommandBuffer();
3556 }
3557
3558 // Create two images, the dest with sampleCount = 4, and attempt to blit
3559 // between them
3560 {
3561 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003562 image_create_info.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06003563 vk_testing::Image src_image;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003564 src_image.init(*m_device, (const VkImageCreateInfo &)image_create_info, reqs);
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06003565 image_create_info.samples = VK_SAMPLE_COUNT_4_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003566 image_create_info.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT;
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06003567 vk_testing::Image dst_image;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003568 dst_image.init(*m_device, (const VkImageCreateInfo &)image_create_info, reqs);
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06003569 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003570 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "was created with a sample count "
3571 "of VK_SAMPLE_COUNT_4_BIT but "
3572 "must be VK_SAMPLE_COUNT_1_BIT");
3573 vkCmdBlitImage(m_commandBuffer->GetBufferHandle(), src_image.handle(), VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
3574 dst_image.handle(), VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL, 1, &blit_region, VK_FILTER_NEAREST);
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06003575 m_errorMonitor->VerifyFound();
3576 m_commandBuffer->EndCommandBuffer();
3577 }
3578
3579 VkBufferImageCopy copy_region = {};
3580 copy_region.bufferRowLength = 128;
3581 copy_region.bufferImageHeight = 128;
3582 copy_region.imageSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
3583 copy_region.imageSubresource.layerCount = 1;
3584 copy_region.imageExtent.height = 64;
3585 copy_region.imageExtent.width = 64;
3586 copy_region.imageExtent.depth = 1;
3587
3588 // Create src buffer and dst image with sampleCount = 4 and attempt to copy
3589 // buffer to image
3590 {
3591 vk_testing::Buffer src_buffer;
3592 VkMemoryPropertyFlags reqs = 0;
3593 src_buffer.init_as_src(*m_device, 128 * 128 * 4, reqs);
3594 image_create_info.samples = VK_SAMPLE_COUNT_8_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003595 image_create_info.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT;
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06003596 vk_testing::Image dst_image;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003597 dst_image.init(*m_device, (const VkImageCreateInfo &)image_create_info, reqs);
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06003598 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003599 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "was created with a sample count "
3600 "of VK_SAMPLE_COUNT_8_BIT but "
3601 "must be VK_SAMPLE_COUNT_1_BIT");
3602 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), src_buffer.handle(), dst_image.handle(),
3603 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, &copy_region);
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06003604 m_errorMonitor->VerifyFound();
3605 m_commandBuffer->EndCommandBuffer();
3606 }
3607
3608 // Create dst buffer and src image with sampleCount = 2 and attempt to copy
3609 // image to buffer
3610 {
3611 vk_testing::Buffer dst_buffer;
3612 dst_buffer.init_as_dst(*m_device, 128 * 128 * 4, reqs);
3613 image_create_info.samples = VK_SAMPLE_COUNT_2_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003614 image_create_info.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06003615 vk_testing::Image src_image;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003616 src_image.init(*m_device, (const VkImageCreateInfo &)image_create_info, reqs);
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06003617 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003618 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "was created with a sample count "
3619 "of VK_SAMPLE_COUNT_2_BIT but "
3620 "must be VK_SAMPLE_COUNT_1_BIT");
3621 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), src_image.handle(), VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL,
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06003622 dst_buffer.handle(), 1, &copy_region);
3623 m_errorMonitor->VerifyFound();
3624 m_commandBuffer->EndCommandBuffer();
3625 }
3626}
3627
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06003628TEST_F(VkLayerTest, DSImageTransferGranularityTests) {
3629 VkResult err;
3630 bool pass;
3631
3632 TEST_DESCRIPTION("Tests for validaiton of Queue Family property minImageTransferGranularity.");
3633 ASSERT_NO_FATAL_FAILURE(InitState());
3634
3635 // If w/d/h granularity is 1, test is not meaningful
3636 // TODO: When virtual device limits are available, create a set of limits for this test that
3637 // will always have a granularity of > 1 for w, h, and d
3638 auto index = m_device->graphics_queue_node_index_;
3639 auto queue_family_properties = m_device->phy().queue_properties();
3640
3641 if ((queue_family_properties[index].minImageTransferGranularity.depth < 4) ||
3642 (queue_family_properties[index].minImageTransferGranularity.width < 4) ||
3643 (queue_family_properties[index].minImageTransferGranularity.height < 4)) {
3644 return;
3645 }
3646
3647 // Create two images of different types and try to copy between them
3648 VkImage srcImage;
3649 VkImage dstImage;
3650 VkDeviceMemory srcMem;
3651 VkDeviceMemory destMem;
3652 VkMemoryRequirements memReqs;
3653
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06003654 VkImageCreateInfo image_create_info = {};
3655 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
3656 image_create_info.pNext = NULL;
3657 image_create_info.imageType = VK_IMAGE_TYPE_2D;
3658 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
3659 image_create_info.extent.width = 32;
3660 image_create_info.extent.height = 32;
3661 image_create_info.extent.depth = 1;
3662 image_create_info.mipLevels = 1;
3663 image_create_info.arrayLayers = 4;
3664 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
3665 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
3666 image_create_info.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT;
3667 image_create_info.flags = 0;
3668
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003669 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06003670 ASSERT_VK_SUCCESS(err);
3671
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003672 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06003673 ASSERT_VK_SUCCESS(err);
3674
3675 // Allocate memory
3676 VkMemoryAllocateInfo memAlloc = {};
3677 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
3678 memAlloc.pNext = NULL;
3679 memAlloc.allocationSize = 0;
3680 memAlloc.memoryTypeIndex = 0;
3681
3682 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
3683 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003684 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06003685 ASSERT_TRUE(pass);
3686 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
3687 ASSERT_VK_SUCCESS(err);
3688
3689 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
3690 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003691 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06003692 ASSERT_VK_SUCCESS(err);
3693 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
3694 ASSERT_VK_SUCCESS(err);
3695
3696 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
3697 ASSERT_VK_SUCCESS(err);
3698 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
3699 ASSERT_VK_SUCCESS(err);
3700
3701 BeginCommandBuffer();
3702 VkImageCopy copyRegion;
3703 copyRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
3704 copyRegion.srcSubresource.mipLevel = 0;
3705 copyRegion.srcSubresource.baseArrayLayer = 0;
3706 copyRegion.srcSubresource.layerCount = 1;
3707 copyRegion.srcOffset.x = 0;
3708 copyRegion.srcOffset.y = 0;
3709 copyRegion.srcOffset.z = 0;
3710 copyRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
3711 copyRegion.dstSubresource.mipLevel = 0;
3712 copyRegion.dstSubresource.baseArrayLayer = 0;
3713 copyRegion.dstSubresource.layerCount = 1;
3714 copyRegion.dstOffset.x = 0;
3715 copyRegion.dstOffset.y = 0;
3716 copyRegion.dstOffset.z = 0;
3717 copyRegion.extent.width = 1;
3718 copyRegion.extent.height = 1;
3719 copyRegion.extent.depth = 1;
3720
3721 // Introduce failure by setting srcOffset to a bad granularity value
3722 copyRegion.srcOffset.y = 3;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003723 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "queue family image transfer granularity");
3724 m_commandBuffer->CopyImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, VK_IMAGE_LAYOUT_GENERAL, 1, &copyRegion);
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06003725 m_errorMonitor->VerifyFound();
3726
3727 // Introduce failure by setting extent to a bad granularity value
3728 copyRegion.srcOffset.y = 0;
3729 copyRegion.extent.width = 3;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003730 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "queue family image transfer granularity");
3731 m_commandBuffer->CopyImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, VK_IMAGE_LAYOUT_GENERAL, 1, &copyRegion);
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06003732 m_errorMonitor->VerifyFound();
3733
3734 // Now do some buffer/image copies
3735 vk_testing::Buffer buffer;
3736 VkMemoryPropertyFlags reqs = 0;
3737 buffer.init_as_dst(*m_device, 128 * 128, reqs);
3738 VkBufferImageCopy region = {};
3739 region.bufferOffset = 0;
3740 region.bufferRowLength = 3;
3741 region.bufferImageHeight = 128;
3742 region.imageSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
3743 region.imageSubresource.layerCount = 1;
3744 region.imageExtent.height = 16;
3745 region.imageExtent.width = 16;
3746 region.imageExtent.depth = 1;
3747 region.imageOffset.x = 0;
3748 region.imageOffset.y = 0;
3749 region.imageOffset.z = 0;
3750
3751 // Introduce failure by setting bufferRowLength to a bad granularity value
3752 region.bufferRowLength = 3;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003753 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "queue family image transfer granularity");
3754 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer.handle(), srcImage, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1,
3755 &region);
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06003756 m_errorMonitor->VerifyFound();
3757 region.bufferRowLength = 128;
3758
3759 // Introduce failure by setting bufferOffset to a bad granularity value
3760 region.bufferOffset = 3;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003761 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "queue family image transfer granularity");
3762 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), srcImage, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, buffer.handle(), 1,
3763 &region);
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06003764 m_errorMonitor->VerifyFound();
3765 region.bufferOffset = 0;
3766
3767 // Introduce failure by setting bufferImageHeight to a bad granularity value
3768 region.bufferImageHeight = 3;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003769 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "queue family image transfer granularity");
3770 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), srcImage, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, buffer.handle(), 1,
3771 &region);
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06003772 m_errorMonitor->VerifyFound();
3773 region.bufferImageHeight = 128;
3774
3775 // Introduce failure by setting imageExtent to a bad granularity value
3776 region.imageExtent.width = 3;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003777 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "queue family image transfer granularity");
3778 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), srcImage, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, buffer.handle(), 1,
3779 &region);
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06003780 m_errorMonitor->VerifyFound();
3781 region.imageExtent.width = 16;
3782
3783 // Introduce failure by setting imageOffset to a bad granularity value
3784 region.imageOffset.z = 3;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003785 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "queue family image transfer granularity");
3786 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer.handle(), srcImage, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1,
3787 &region);
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06003788 m_errorMonitor->VerifyFound();
3789
3790 EndCommandBuffer();
3791
3792 vkDestroyImage(m_device->device(), srcImage, NULL);
3793 vkDestroyImage(m_device->device(), dstImage, NULL);
3794 vkFreeMemory(m_device->device(), srcMem, NULL);
3795 vkFreeMemory(m_device->device(), destMem, NULL);
3796}
3797
Mark Lobodzinski570efc62016-08-09 16:43:19 -06003798TEST_F(VkLayerTest, MismatchedQueueFamiliesOnSubmit) {
Mark Lobodzinski570efc62016-08-09 16:43:19 -06003799 TEST_DESCRIPTION("Submit command buffer created using one queue family and "
3800 "attempt to submit them on a queue created in a different "
3801 "queue family.");
3802
Cody Northropc31a84f2016-08-22 10:41:47 -06003803 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinski570efc62016-08-09 16:43:19 -06003804 // This test is meaningless unless we have multiple queue families
3805 auto queue_family_properties = m_device->phy().queue_properties();
3806 if (queue_family_properties.size() < 2) {
3807 return;
3808 }
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003809 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " is being submitted on queue ");
Mark Lobodzinski570efc62016-08-09 16:43:19 -06003810 // Get safe index of another queue family
3811 uint32_t other_queue_family = (m_device->graphics_queue_node_index_ == 0) ? 1 : 0;
3812 ASSERT_NO_FATAL_FAILURE(InitState());
3813 // Create a second queue using a different queue family
3814 VkQueue other_queue;
3815 vkGetDeviceQueue(m_device->device(), other_queue_family, 0, &other_queue);
3816
3817 // Record an empty cmd buffer
3818 VkCommandBufferBeginInfo cmdBufBeginDesc = {};
3819 cmdBufBeginDesc.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
3820 vkBeginCommandBuffer(m_commandBuffer->handle(), &cmdBufBeginDesc);
3821 vkEndCommandBuffer(m_commandBuffer->handle());
3822
3823 // And submit on the wrong queue
3824 VkSubmitInfo submit_info = {};
3825 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
3826 submit_info.commandBufferCount = 1;
3827 submit_info.pCommandBuffers = &m_commandBuffer->handle();
Tobin Ehlisfd213ea2016-08-10 17:10:46 -06003828 vkQueueSubmit(other_queue, 1, &submit_info, VK_NULL_HANDLE);
Mark Lobodzinski570efc62016-08-09 16:43:19 -06003829
3830 m_errorMonitor->VerifyFound();
Mark Lobodzinski570efc62016-08-09 16:43:19 -06003831}
3832
Chris Forbes48a53902016-06-30 11:46:27 +12003833TEST_F(VkLayerTest, RenderPassInitialLayoutUndefined) {
3834 TEST_DESCRIPTION("Ensure that CmdBeginRenderPass with an attachment's "
3835 "initialLayout of VK_IMAGE_LAYOUT_UNDEFINED works when "
3836 "the command buffer has prior knowledge of that "
3837 "attachment's layout.");
3838
3839 m_errorMonitor->ExpectSuccess();
3840
3841 ASSERT_NO_FATAL_FAILURE(InitState());
3842
3843 // A renderpass with one color attachment.
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003844 VkAttachmentDescription attachment = {0,
3845 VK_FORMAT_R8G8B8A8_UNORM,
3846 VK_SAMPLE_COUNT_1_BIT,
3847 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
3848 VK_ATTACHMENT_STORE_OP_STORE,
3849 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
3850 VK_ATTACHMENT_STORE_OP_DONT_CARE,
3851 VK_IMAGE_LAYOUT_UNDEFINED,
3852 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL};
Chris Forbes48a53902016-06-30 11:46:27 +12003853
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003854 VkAttachmentReference att_ref = {0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL};
Chris Forbes48a53902016-06-30 11:46:27 +12003855
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003856 VkSubpassDescription subpass = {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 1, &att_ref, nullptr, nullptr, 0, nullptr};
Chris Forbes48a53902016-06-30 11:46:27 +12003857
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003858 VkRenderPassCreateInfo rpci = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 1, &attachment, 1, &subpass, 0, nullptr};
Chris Forbes48a53902016-06-30 11:46:27 +12003859
3860 VkRenderPass rp;
3861 VkResult err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
3862 ASSERT_VK_SUCCESS(err);
3863
3864 // A compatible framebuffer.
3865 VkImageObj image(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003866 image.init(32, 32, VK_FORMAT_R8G8B8A8_UNORM, VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT, VK_IMAGE_TILING_OPTIMAL, 0);
Chris Forbes48a53902016-06-30 11:46:27 +12003867 ASSERT_TRUE(image.initialized());
3868
3869 VkImageViewCreateInfo ivci = {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003870 VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO,
3871 nullptr,
3872 0,
3873 image.handle(),
3874 VK_IMAGE_VIEW_TYPE_2D,
3875 VK_FORMAT_R8G8B8A8_UNORM,
3876 {VK_COMPONENT_SWIZZLE_IDENTITY, VK_COMPONENT_SWIZZLE_IDENTITY, VK_COMPONENT_SWIZZLE_IDENTITY,
3877 VK_COMPONENT_SWIZZLE_IDENTITY},
3878 {VK_IMAGE_ASPECT_COLOR_BIT, 0, 1, 0, 1},
Chris Forbes48a53902016-06-30 11:46:27 +12003879 };
3880 VkImageView view;
3881 err = vkCreateImageView(m_device->device(), &ivci, nullptr, &view);
3882 ASSERT_VK_SUCCESS(err);
3883
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003884 VkFramebufferCreateInfo fci = {VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr, 0, rp, 1, &view, 32, 32, 1};
Chris Forbes48a53902016-06-30 11:46:27 +12003885 VkFramebuffer fb;
3886 err = vkCreateFramebuffer(m_device->device(), &fci, nullptr, &fb);
3887 ASSERT_VK_SUCCESS(err);
3888
3889 // Record a single command buffer which uses this renderpass twice. The
3890 // bug is triggered at the beginning of the second renderpass, when the
3891 // command buffer already has a layout recorded for the attachment.
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003892 VkRenderPassBeginInfo rpbi = {VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO, nullptr, rp, fb, {{0, 0}, {32, 32}}, 0, nullptr};
Chris Forbes48a53902016-06-30 11:46:27 +12003893 BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003894 vkCmdBeginRenderPass(m_commandBuffer->handle(), &rpbi, VK_SUBPASS_CONTENTS_INLINE);
Chris Forbes48a53902016-06-30 11:46:27 +12003895 vkCmdEndRenderPass(m_commandBuffer->handle());
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003896 vkCmdBeginRenderPass(m_commandBuffer->handle(), &rpbi, VK_SUBPASS_CONTENTS_INLINE);
Chris Forbes48a53902016-06-30 11:46:27 +12003897
3898 m_errorMonitor->VerifyNotFound();
3899
3900 vkCmdEndRenderPass(m_commandBuffer->handle());
3901 EndCommandBuffer();
3902
3903 vkDestroyFramebuffer(m_device->device(), fb, nullptr);
3904 vkDestroyRenderPass(m_device->device(), rp, nullptr);
3905 vkDestroyImageView(m_device->device(), view, nullptr);
3906}
3907
Tobin Ehlis75ac37b2016-07-29 10:55:41 -06003908TEST_F(VkLayerTest, FramebufferBindingDestroyCommandPool) {
3909 TEST_DESCRIPTION("This test should pass. Create a Framebuffer and "
3910 "command buffer, bind them together, then destroy "
3911 "command pool and framebuffer and verify there are no "
3912 "errors.");
3913
3914 m_errorMonitor->ExpectSuccess();
3915
3916 ASSERT_NO_FATAL_FAILURE(InitState());
3917
3918 // A renderpass with one color attachment.
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003919 VkAttachmentDescription attachment = {0,
3920 VK_FORMAT_R8G8B8A8_UNORM,
3921 VK_SAMPLE_COUNT_1_BIT,
3922 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
3923 VK_ATTACHMENT_STORE_OP_STORE,
3924 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
3925 VK_ATTACHMENT_STORE_OP_DONT_CARE,
3926 VK_IMAGE_LAYOUT_UNDEFINED,
3927 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL};
Tobin Ehlis75ac37b2016-07-29 10:55:41 -06003928
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003929 VkAttachmentReference att_ref = {0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL};
Tobin Ehlis75ac37b2016-07-29 10:55:41 -06003930
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003931 VkSubpassDescription subpass = {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 1, &att_ref, nullptr, nullptr, 0, nullptr};
Tobin Ehlis75ac37b2016-07-29 10:55:41 -06003932
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003933 VkRenderPassCreateInfo rpci = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 1, &attachment, 1, &subpass, 0, nullptr};
Tobin Ehlis75ac37b2016-07-29 10:55:41 -06003934
3935 VkRenderPass rp;
3936 VkResult err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
3937 ASSERT_VK_SUCCESS(err);
3938
3939 // A compatible framebuffer.
3940 VkImageObj image(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003941 image.init(32, 32, VK_FORMAT_R8G8B8A8_UNORM, VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT, VK_IMAGE_TILING_OPTIMAL, 0);
Tobin Ehlis75ac37b2016-07-29 10:55:41 -06003942 ASSERT_TRUE(image.initialized());
3943
3944 VkImageViewCreateInfo ivci = {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003945 VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO,
3946 nullptr,
3947 0,
3948 image.handle(),
3949 VK_IMAGE_VIEW_TYPE_2D,
3950 VK_FORMAT_R8G8B8A8_UNORM,
3951 {VK_COMPONENT_SWIZZLE_IDENTITY, VK_COMPONENT_SWIZZLE_IDENTITY, VK_COMPONENT_SWIZZLE_IDENTITY,
3952 VK_COMPONENT_SWIZZLE_IDENTITY},
3953 {VK_IMAGE_ASPECT_COLOR_BIT, 0, 1, 0, 1},
Tobin Ehlis75ac37b2016-07-29 10:55:41 -06003954 };
3955 VkImageView view;
3956 err = vkCreateImageView(m_device->device(), &ivci, nullptr, &view);
3957 ASSERT_VK_SUCCESS(err);
3958
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003959 VkFramebufferCreateInfo fci = {VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr, 0, rp, 1, &view, 32, 32, 1};
Tobin Ehlis75ac37b2016-07-29 10:55:41 -06003960 VkFramebuffer fb;
3961 err = vkCreateFramebuffer(m_device->device(), &fci, nullptr, &fb);
3962 ASSERT_VK_SUCCESS(err);
3963
3964 // Explicitly create a command buffer to bind the FB to so that we can then
3965 // destroy the command pool in order to implicitly free command buffer
3966 VkCommandPool command_pool;
3967 VkCommandPoolCreateInfo pool_create_info{};
3968 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
3969 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
3970 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003971 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
Tobin Ehlis75ac37b2016-07-29 10:55:41 -06003972
3973 VkCommandBuffer command_buffer;
3974 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003975 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
Tobin Ehlis75ac37b2016-07-29 10:55:41 -06003976 command_buffer_allocate_info.commandPool = command_pool;
3977 command_buffer_allocate_info.commandBufferCount = 1;
3978 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003979 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, &command_buffer);
Tobin Ehlis75ac37b2016-07-29 10:55:41 -06003980
3981 // Begin our cmd buffer with renderpass using our framebuffer
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003982 VkRenderPassBeginInfo rpbi = {VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO, nullptr, rp, fb, {{0, 0}, {32, 32}}, 0, nullptr};
Tobin Ehlis75ac37b2016-07-29 10:55:41 -06003983 VkCommandBufferBeginInfo begin_info{};
3984 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
3985 vkBeginCommandBuffer(command_buffer, &begin_info);
3986
3987 vkCmdBeginRenderPass(command_buffer, &rpbi, VK_SUBPASS_CONTENTS_INLINE);
3988 vkCmdEndRenderPass(command_buffer);
3989 vkEndCommandBuffer(command_buffer);
Mark Lobodzinski7d10a822016-08-03 14:08:40 -06003990 vkDestroyImageView(m_device->device(), view, nullptr);
Tobin Ehlis75ac37b2016-07-29 10:55:41 -06003991 // Destroy command pool to implicitly free command buffer
3992 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
3993 vkDestroyFramebuffer(m_device->device(), fb, nullptr);
3994 vkDestroyRenderPass(m_device->device(), rp, nullptr);
3995 m_errorMonitor->VerifyNotFound();
3996}
3997
Chris Forbes51bf7c92016-06-30 15:22:08 +12003998TEST_F(VkLayerTest, RenderPassSubpassZeroTransitionsApplied) {
3999 TEST_DESCRIPTION("Ensure that CmdBeginRenderPass applies the layout "
4000 "transitions for the first subpass");
4001
4002 m_errorMonitor->ExpectSuccess();
4003
4004 ASSERT_NO_FATAL_FAILURE(InitState());
4005
4006 // A renderpass with one color attachment.
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004007 VkAttachmentDescription attachment = {0,
4008 VK_FORMAT_R8G8B8A8_UNORM,
4009 VK_SAMPLE_COUNT_1_BIT,
4010 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
4011 VK_ATTACHMENT_STORE_OP_STORE,
4012 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
4013 VK_ATTACHMENT_STORE_OP_DONT_CARE,
4014 VK_IMAGE_LAYOUT_UNDEFINED,
4015 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL};
Chris Forbes51bf7c92016-06-30 15:22:08 +12004016
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004017 VkAttachmentReference att_ref = {0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL};
Chris Forbes51bf7c92016-06-30 15:22:08 +12004018
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004019 VkSubpassDescription subpass = {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 1, &att_ref, nullptr, nullptr, 0, nullptr};
Chris Forbes51bf7c92016-06-30 15:22:08 +12004020
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004021 VkSubpassDependency dep = {0,
4022 0,
4023 VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT,
4024 VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT,
4025 VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT,
4026 VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT,
4027 VK_DEPENDENCY_BY_REGION_BIT};
Chris Forbes51bf7c92016-06-30 15:22:08 +12004028
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004029 VkRenderPassCreateInfo rpci = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 1, &attachment, 1, &subpass, 1, &dep};
Chris Forbes51bf7c92016-06-30 15:22:08 +12004030
4031 VkResult err;
4032 VkRenderPass rp;
4033 err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
4034 ASSERT_VK_SUCCESS(err);
4035
4036 // A compatible framebuffer.
4037 VkImageObj image(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004038 image.init(32, 32, VK_FORMAT_R8G8B8A8_UNORM, VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT, VK_IMAGE_TILING_OPTIMAL, 0);
Chris Forbes51bf7c92016-06-30 15:22:08 +12004039 ASSERT_TRUE(image.initialized());
4040
4041 VkImageViewCreateInfo ivci = {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004042 VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO,
4043 nullptr,
4044 0,
4045 image.handle(),
4046 VK_IMAGE_VIEW_TYPE_2D,
4047 VK_FORMAT_R8G8B8A8_UNORM,
4048 {VK_COMPONENT_SWIZZLE_IDENTITY, VK_COMPONENT_SWIZZLE_IDENTITY, VK_COMPONENT_SWIZZLE_IDENTITY,
4049 VK_COMPONENT_SWIZZLE_IDENTITY},
4050 {VK_IMAGE_ASPECT_COLOR_BIT, 0, 1, 0, 1},
Chris Forbes51bf7c92016-06-30 15:22:08 +12004051 };
4052 VkImageView view;
4053 err = vkCreateImageView(m_device->device(), &ivci, nullptr, &view);
4054 ASSERT_VK_SUCCESS(err);
4055
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004056 VkFramebufferCreateInfo fci = {VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr, 0, rp, 1, &view, 32, 32, 1};
Chris Forbes51bf7c92016-06-30 15:22:08 +12004057 VkFramebuffer fb;
4058 err = vkCreateFramebuffer(m_device->device(), &fci, nullptr, &fb);
4059 ASSERT_VK_SUCCESS(err);
4060
4061 // Record a single command buffer which issues a pipeline barrier w/
4062 // image memory barrier for the attachment. This detects the previously
4063 // missing tracking of the subpass layout by throwing a validation error
4064 // if it doesn't occur.
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004065 VkRenderPassBeginInfo rpbi = {VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO, nullptr, rp, fb, {{0, 0}, {32, 32}}, 0, nullptr};
Chris Forbes51bf7c92016-06-30 15:22:08 +12004066 BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004067 vkCmdBeginRenderPass(m_commandBuffer->handle(), &rpbi, VK_SUBPASS_CONTENTS_INLINE);
Chris Forbes51bf7c92016-06-30 15:22:08 +12004068
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004069 VkImageMemoryBarrier imb = {VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER,
4070 nullptr,
4071 VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT,
4072 VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT,
4073 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
4074 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
4075 VK_QUEUE_FAMILY_IGNORED,
4076 VK_QUEUE_FAMILY_IGNORED,
4077 image.handle(),
4078 {VK_IMAGE_ASPECT_COLOR_BIT, 0, 1, 0, 1}};
4079 vkCmdPipelineBarrier(m_commandBuffer->handle(), VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT,
4080 VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT, VK_DEPENDENCY_BY_REGION_BIT, 0, nullptr, 0, nullptr, 1,
4081 &imb);
Chris Forbes51bf7c92016-06-30 15:22:08 +12004082
4083 vkCmdEndRenderPass(m_commandBuffer->handle());
4084 m_errorMonitor->VerifyNotFound();
4085 EndCommandBuffer();
4086
4087 vkDestroyFramebuffer(m_device->device(), fb, nullptr);
4088 vkDestroyRenderPass(m_device->device(), rp, nullptr);
4089 vkDestroyImageView(m_device->device(), view, nullptr);
4090}
4091
Mark Lobodzinski77a5d6f2016-08-05 09:38:18 -06004092TEST_F(VkLayerTest, DepthStencilLayoutTransitionForDepthOnlyImageview) {
4093 TEST_DESCRIPTION("Validate that when an imageView of a depth/stencil image "
4094 "is used as a depth/stencil framebuffer attachment, the "
4095 "aspectMask is ignored and both depth and stencil image "
4096 "subresources are used.");
4097
4098 VkFormatProperties format_properties;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004099 vkGetPhysicalDeviceFormatProperties(gpu(), VK_FORMAT_D32_SFLOAT_S8_UINT, &format_properties);
4100 if (!(format_properties.optimalTilingFeatures & VK_FORMAT_FEATURE_SAMPLED_IMAGE_BIT)) {
Mark Lobodzinski77a5d6f2016-08-05 09:38:18 -06004101 return;
4102 }
4103
4104 m_errorMonitor->ExpectSuccess();
4105
4106 ASSERT_NO_FATAL_FAILURE(InitState());
4107
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004108 VkAttachmentDescription attachment = {0,
4109 VK_FORMAT_D32_SFLOAT_S8_UINT,
4110 VK_SAMPLE_COUNT_1_BIT,
4111 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
4112 VK_ATTACHMENT_STORE_OP_STORE,
4113 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
4114 VK_ATTACHMENT_STORE_OP_DONT_CARE,
4115 VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL,
4116 VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL};
Mark Lobodzinski77a5d6f2016-08-05 09:38:18 -06004117
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004118 VkAttachmentReference att_ref = {0, VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL};
Mark Lobodzinski77a5d6f2016-08-05 09:38:18 -06004119
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004120 VkSubpassDescription subpass = {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 0, nullptr, nullptr, &att_ref, 0, nullptr};
Mark Lobodzinski77a5d6f2016-08-05 09:38:18 -06004121
4122 VkSubpassDependency dep = {0,
4123 0,
4124 VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT,
4125 VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT,
4126 VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT,
4127 VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT,
4128 VK_DEPENDENCY_BY_REGION_BIT};
4129
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004130 VkRenderPassCreateInfo rpci = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 1, &attachment, 1, &subpass, 1, &dep};
Mark Lobodzinski77a5d6f2016-08-05 09:38:18 -06004131
4132 VkResult err;
4133 VkRenderPass rp;
4134 err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
4135 ASSERT_VK_SUCCESS(err);
4136
4137 VkImageObj image(m_device);
4138 image.init_no_layout(32, 32, VK_FORMAT_D32_SFLOAT_S8_UINT,
4139 0x26, // usage
4140 VK_IMAGE_TILING_OPTIMAL, 0);
4141 ASSERT_TRUE(image.initialized());
4142 image.SetLayout(0x6, VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL);
4143
4144 VkImageViewCreateInfo ivci = {
4145 VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO,
4146 nullptr,
4147 0,
4148 image.handle(),
4149 VK_IMAGE_VIEW_TYPE_2D,
4150 VK_FORMAT_D32_SFLOAT_S8_UINT,
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004151 {VK_COMPONENT_SWIZZLE_R, VK_COMPONENT_SWIZZLE_G, VK_COMPONENT_SWIZZLE_B, VK_COMPONENT_SWIZZLE_A},
Mark Lobodzinski77a5d6f2016-08-05 09:38:18 -06004152 {0x2, 0, 1, 0, 1},
4153 };
4154 VkImageView view;
4155 err = vkCreateImageView(m_device->device(), &ivci, nullptr, &view);
4156 ASSERT_VK_SUCCESS(err);
4157
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004158 VkFramebufferCreateInfo fci = {VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr, 0, rp, 1, &view, 32, 32, 1};
Mark Lobodzinski77a5d6f2016-08-05 09:38:18 -06004159 VkFramebuffer fb;
4160 err = vkCreateFramebuffer(m_device->device(), &fci, nullptr, &fb);
4161 ASSERT_VK_SUCCESS(err);
4162
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004163 VkRenderPassBeginInfo rpbi = {VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO, nullptr, rp, fb, {{0, 0}, {32, 32}}, 0, nullptr};
Mark Lobodzinski77a5d6f2016-08-05 09:38:18 -06004164 BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004165 vkCmdBeginRenderPass(m_commandBuffer->handle(), &rpbi, VK_SUBPASS_CONTENTS_INLINE);
Mark Lobodzinski77a5d6f2016-08-05 09:38:18 -06004166
4167 VkImageMemoryBarrier imb = {};
4168 imb.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
4169 imb.pNext = nullptr;
4170 imb.srcAccessMask = VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_WRITE_BIT;
4171 imb.dstAccessMask = VK_ACCESS_SHADER_READ_BIT;
4172 imb.oldLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
4173 imb.newLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
4174 imb.srcQueueFamilyIndex = 0;
4175 imb.dstQueueFamilyIndex = 0;
4176 imb.image = image.handle();
4177 imb.subresourceRange.aspectMask = 0x6;
4178 imb.subresourceRange.baseMipLevel = 0;
4179 imb.subresourceRange.levelCount = 0x1;
4180 imb.subresourceRange.baseArrayLayer = 0;
4181 imb.subresourceRange.layerCount = 0x1;
4182
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004183 vkCmdPipelineBarrier(m_commandBuffer->handle(), VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT,
4184 VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT, VK_DEPENDENCY_BY_REGION_BIT, 0, nullptr, 0, nullptr, 1,
Mark Lobodzinski77a5d6f2016-08-05 09:38:18 -06004185 &imb);
4186
4187 vkCmdEndRenderPass(m_commandBuffer->handle());
4188 EndCommandBuffer();
4189 QueueCommandBuffer(false);
4190 m_errorMonitor->VerifyNotFound();
4191
4192 vkDestroyFramebuffer(m_device->device(), fb, nullptr);
4193 vkDestroyRenderPass(m_device->device(), rp, nullptr);
4194 vkDestroyImageView(m_device->device(), view, nullptr);
4195}
Tony Barbourd5f7b822016-08-02 15:39:33 -06004196
Tony Barbour4e919972016-08-09 13:27:40 -06004197TEST_F(VkLayerTest, RenderPassInvalidRenderArea) {
4198 TEST_DESCRIPTION("Generate INVALID_RENDER_AREA error by beginning renderpass"
4199 "with extent outside of framebuffer");
4200 ASSERT_NO_FATAL_FAILURE(InitState());
4201 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
4202
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004203 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Cannot execute a render pass with renderArea "
4204 "not within the bound of the framebuffer.");
Tony Barbour4e919972016-08-09 13:27:40 -06004205
4206 // Framebuffer for render target is 256x256, exceed that for INVALID_RENDER_AREA
4207 m_renderPassBeginInfo.renderArea.extent.width = 257;
4208 m_renderPassBeginInfo.renderArea.extent.height = 257;
4209 BeginCommandBuffer();
4210 m_errorMonitor->VerifyFound();
4211}
4212
4213TEST_F(VkLayerTest, DisabledIndependentBlend) {
4214 TEST_DESCRIPTION("Generate INDEPENDENT_BLEND by disabling independent "
4215 "blend and then specifying different blend states for two "
4216 "attachements");
Cody Northrop5703cc72016-08-19 09:57:10 -06004217 VkPhysicalDeviceFeatures features = {};
4218 features.independentBlend = VK_FALSE;
Cody Northropc31a84f2016-08-22 10:41:47 -06004219 ASSERT_NO_FATAL_FAILURE(InitState(&features));
Tony Barbour4e919972016-08-09 13:27:40 -06004220
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004221 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
4222 "Invalid Pipeline CreateInfo: If independent blend feature not "
4223 "enabled, all elements of pAttachments must be identical");
Tony Barbour4e919972016-08-09 13:27:40 -06004224
Cody Northropc31a84f2016-08-22 10:41:47 -06004225 VkDescriptorSetObj descriptorSet(m_device);
4226 descriptorSet.AppendDummy();
4227 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Tony Barbour4e919972016-08-09 13:27:40 -06004228
Cody Northropc31a84f2016-08-22 10:41:47 -06004229 VkPipelineObj pipeline(m_device);
4230 VkRenderpassObj renderpass(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004231 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
Cody Northropc31a84f2016-08-22 10:41:47 -06004232 pipeline.AddShader(&vs);
Cody Northrop5703cc72016-08-19 09:57:10 -06004233
Cody Northropc31a84f2016-08-22 10:41:47 -06004234 VkPipelineColorBlendAttachmentState att_state1 = {}, att_state2 = {};
4235 att_state1.dstAlphaBlendFactor = VK_BLEND_FACTOR_CONSTANT_COLOR;
4236 att_state1.blendEnable = VK_TRUE;
4237 att_state2.dstAlphaBlendFactor = VK_BLEND_FACTOR_CONSTANT_COLOR;
4238 att_state2.blendEnable = VK_FALSE;
4239 pipeline.AddColorAttachment(0, &att_state1);
4240 pipeline.AddColorAttachment(1, &att_state2);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004241 pipeline.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderpass.handle());
Cody Northropc31a84f2016-08-22 10:41:47 -06004242 m_errorMonitor->VerifyFound();
Tony Barbour4e919972016-08-09 13:27:40 -06004243}
4244
4245TEST_F(VkLayerTest, RenderPassDepthStencilAttachmentUnused) {
4246 TEST_DESCRIPTION("Specify no depth attachement in renderpass then specify "
4247 "depth attachments in subpass");
Cody Northropc31a84f2016-08-22 10:41:47 -06004248 ASSERT_NO_FATAL_FAILURE(InitState());
Tony Barbour4e919972016-08-09 13:27:40 -06004249
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004250 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
4251 "vkCreateRenderPass has no depth/stencil attachment, yet subpass");
Tony Barbour4e919972016-08-09 13:27:40 -06004252
4253 // Create a renderPass with a single color attachment
4254 VkAttachmentReference attach = {};
4255 attach.layout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
4256 VkSubpassDescription subpass = {};
4257 VkRenderPassCreateInfo rpci = {};
4258 rpci.subpassCount = 1;
4259 rpci.pSubpasses = &subpass;
4260 rpci.attachmentCount = 1;
4261 VkAttachmentDescription attach_desc = {};
4262 attach_desc.format = VK_FORMAT_B8G8R8A8_UNORM;
4263 attach_desc.samples = VK_SAMPLE_COUNT_1_BIT;
4264 rpci.pAttachments = &attach_desc;
4265 rpci.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
4266 VkRenderPass rp;
4267 subpass.pDepthStencilAttachment = &attach;
4268 subpass.pColorAttachments = NULL;
4269 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
4270 m_errorMonitor->VerifyFound();
4271}
4272
Chris Forbes6b3d3f42016-06-30 16:09:47 +12004273TEST_F(VkLayerTest, RenderPassTransitionsAttachmentUnused) {
4274 TEST_DESCRIPTION("Ensure that layout transitions work correctly without "
4275 "errors, when an attachment reference is "
4276 "VK_ATTACHMENT_UNUSED");
4277
4278 m_errorMonitor->ExpectSuccess();
4279
4280 ASSERT_NO_FATAL_FAILURE(InitState());
4281
4282 // A renderpass with no attachments
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004283 VkAttachmentReference att_ref = {VK_ATTACHMENT_UNUSED, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL};
Chris Forbes6b3d3f42016-06-30 16:09:47 +12004284
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004285 VkSubpassDescription subpass = {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 1, &att_ref, nullptr, nullptr, 0, nullptr};
Chris Forbes6b3d3f42016-06-30 16:09:47 +12004286
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004287 VkRenderPassCreateInfo rpci = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 0, nullptr, 1, &subpass, 0, nullptr};
Chris Forbes6b3d3f42016-06-30 16:09:47 +12004288
4289 VkRenderPass rp;
4290 VkResult err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
4291 ASSERT_VK_SUCCESS(err);
4292
4293 // A compatible framebuffer.
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004294 VkFramebufferCreateInfo fci = {VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr, 0, rp, 0, nullptr, 32, 32, 1};
Chris Forbes6b3d3f42016-06-30 16:09:47 +12004295 VkFramebuffer fb;
4296 err = vkCreateFramebuffer(m_device->device(), &fci, nullptr, &fb);
4297 ASSERT_VK_SUCCESS(err);
4298
4299 // Record a command buffer which just begins and ends the renderpass. The
4300 // bug manifests in BeginRenderPass.
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004301 VkRenderPassBeginInfo rpbi = {VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO, nullptr, rp, fb, {{0, 0}, {32, 32}}, 0, nullptr};
Chris Forbes6b3d3f42016-06-30 16:09:47 +12004302 BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004303 vkCmdBeginRenderPass(m_commandBuffer->handle(), &rpbi, VK_SUBPASS_CONTENTS_INLINE);
Chris Forbes6b3d3f42016-06-30 16:09:47 +12004304 vkCmdEndRenderPass(m_commandBuffer->handle());
4305 m_errorMonitor->VerifyNotFound();
4306 EndCommandBuffer();
4307
4308 vkDestroyFramebuffer(m_device->device(), fb, nullptr);
4309 vkDestroyRenderPass(m_device->device(), rp, nullptr);
4310}
4311
Mark Lobodzinskice7eee72016-06-14 16:33:29 -06004312// This is a positive test. No errors are expected.
4313TEST_F(VkLayerTest, StencilLoadOp) {
4314 TEST_DESCRIPTION("Create a stencil-only attachment with a LOAD_OP set to "
4315 "CLEAR. stencil[Load|Store]Op used to be ignored.");
4316 VkResult result = VK_SUCCESS;
4317 VkImageFormatProperties formatProps;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004318 vkGetPhysicalDeviceImageFormatProperties(gpu(), VK_FORMAT_D24_UNORM_S8_UINT, VK_IMAGE_TYPE_2D, VK_IMAGE_TILING_OPTIMAL,
4319 VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_SRC_BIT, 0,
4320 &formatProps);
Mark Lobodzinskice7eee72016-06-14 16:33:29 -06004321 if (formatProps.maxExtent.width < 100 || formatProps.maxExtent.height < 100) {
4322 return;
4323 }
4324
4325 ASSERT_NO_FATAL_FAILURE(InitState());
4326 VkFormat depth_stencil_fmt = VK_FORMAT_D24_UNORM_S8_UINT;
4327 m_depthStencil->Init(m_device, 100, 100, depth_stencil_fmt,
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004328 VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_SRC_BIT);
Mark Lobodzinskice7eee72016-06-14 16:33:29 -06004329 VkAttachmentDescription att = {};
4330 VkAttachmentReference ref = {};
4331 att.format = depth_stencil_fmt;
Chris Forbes787b4532016-09-16 16:45:16 +12004332 att.samples = VK_SAMPLE_COUNT_1_BIT;
Mark Lobodzinskice7eee72016-06-14 16:33:29 -06004333 att.loadOp = VK_ATTACHMENT_LOAD_OP_DONT_CARE;
4334 att.storeOp = VK_ATTACHMENT_STORE_OP_DONT_CARE;
4335 att.stencilLoadOp = VK_ATTACHMENT_LOAD_OP_CLEAR;
4336 att.stencilStoreOp = VK_ATTACHMENT_STORE_OP_STORE;
4337 att.initialLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
4338 att.finalLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
4339
4340 VkClearValue clear;
4341 clear.depthStencil.depth = 1.0;
4342 clear.depthStencil.stencil = 0;
4343 ref.attachment = 0;
4344 ref.layout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
4345
4346 VkSubpassDescription subpass = {};
4347 subpass.pipelineBindPoint = VK_PIPELINE_BIND_POINT_GRAPHICS;
4348 subpass.flags = 0;
4349 subpass.inputAttachmentCount = 0;
4350 subpass.pInputAttachments = NULL;
4351 subpass.colorAttachmentCount = 0;
4352 subpass.pColorAttachments = NULL;
4353 subpass.pResolveAttachments = NULL;
4354 subpass.pDepthStencilAttachment = &ref;
4355 subpass.preserveAttachmentCount = 0;
4356 subpass.pPreserveAttachments = NULL;
4357
4358 VkRenderPass rp;
4359 VkRenderPassCreateInfo rp_info = {};
4360 rp_info.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
4361 rp_info.attachmentCount = 1;
4362 rp_info.pAttachments = &att;
4363 rp_info.subpassCount = 1;
4364 rp_info.pSubpasses = &subpass;
4365 result = vkCreateRenderPass(device(), &rp_info, NULL, &rp);
4366 ASSERT_VK_SUCCESS(result);
4367
4368 VkImageView *depthView = m_depthStencil->BindInfo();
4369 VkFramebufferCreateInfo fb_info = {};
4370 fb_info.sType = VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO;
4371 fb_info.pNext = NULL;
4372 fb_info.renderPass = rp;
4373 fb_info.attachmentCount = 1;
4374 fb_info.pAttachments = depthView;
4375 fb_info.width = 100;
4376 fb_info.height = 100;
4377 fb_info.layers = 1;
4378 VkFramebuffer fb;
4379 result = vkCreateFramebuffer(device(), &fb_info, NULL, &fb);
4380 ASSERT_VK_SUCCESS(result);
4381
Mark Lobodzinskice7eee72016-06-14 16:33:29 -06004382 VkRenderPassBeginInfo rpbinfo = {};
4383 rpbinfo.clearValueCount = 1;
4384 rpbinfo.pClearValues = &clear;
4385 rpbinfo.pNext = NULL;
4386 rpbinfo.renderPass = rp;
4387 rpbinfo.sType = VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO;
4388 rpbinfo.renderArea.extent.width = 100;
4389 rpbinfo.renderArea.extent.height = 100;
4390 rpbinfo.renderArea.offset.x = 0;
4391 rpbinfo.renderArea.offset.y = 0;
4392 rpbinfo.framebuffer = fb;
4393
4394 VkFence fence = {};
4395 VkFenceCreateInfo fence_ci = {};
4396 fence_ci.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
4397 fence_ci.pNext = nullptr;
4398 fence_ci.flags = 0;
4399 result = vkCreateFence(m_device->device(), &fence_ci, nullptr, &fence);
4400 ASSERT_VK_SUCCESS(result);
4401
Mark Lobodzinskice7eee72016-06-14 16:33:29 -06004402 m_commandBuffer->BeginCommandBuffer();
4403 m_commandBuffer->BeginRenderPass(rpbinfo);
4404 m_commandBuffer->EndRenderPass();
4405 m_commandBuffer->EndCommandBuffer();
4406 m_commandBuffer->QueueCommandBuffer(fence);
4407
4408 VkImageObj destImage(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004409 destImage.init(100, 100, depth_stencil_fmt, VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT,
Mark Lobodzinskice7eee72016-06-14 16:33:29 -06004410 VK_IMAGE_TILING_OPTIMAL, 0);
4411 VkImageMemoryBarrier barrier = {};
4412 VkImageSubresourceRange range;
4413 barrier.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004414 barrier.srcAccessMask = VK_ACCESS_TRANSFER_WRITE_BIT | VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_WRITE_BIT;
4415 barrier.dstAccessMask = VK_ACCESS_TRANSFER_READ_BIT | VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_READ_BIT;
Mark Lobodzinskice7eee72016-06-14 16:33:29 -06004416 barrier.oldLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
4417 barrier.newLayout = VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL;
4418 barrier.image = m_depthStencil->handle();
4419 range.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT;
4420 range.baseMipLevel = 0;
4421 range.levelCount = 1;
4422 range.baseArrayLayer = 0;
4423 range.layerCount = 1;
4424 barrier.subresourceRange = range;
4425 vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
4426 VkCommandBufferObj cmdbuf(m_device, m_commandPool);
4427 cmdbuf.BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004428 cmdbuf.PipelineBarrier(VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0, nullptr, 0, nullptr, 1,
4429 &barrier);
Mark Lobodzinskice7eee72016-06-14 16:33:29 -06004430 barrier.srcAccessMask = 0;
4431 barrier.oldLayout = VK_IMAGE_LAYOUT_UNDEFINED;
4432 barrier.newLayout = VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL;
4433 barrier.image = destImage.handle();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004434 barrier.dstAccessMask = VK_ACCESS_TRANSFER_WRITE_BIT | VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_WRITE_BIT;
4435 cmdbuf.PipelineBarrier(VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0, nullptr, 0, nullptr, 1,
4436 &barrier);
Mark Lobodzinskice7eee72016-06-14 16:33:29 -06004437 VkImageCopy cregion;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004438 cregion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT;
Mark Lobodzinskice7eee72016-06-14 16:33:29 -06004439 cregion.srcSubresource.mipLevel = 0;
4440 cregion.srcSubresource.baseArrayLayer = 0;
4441 cregion.srcSubresource.layerCount = 1;
4442 cregion.srcOffset.x = 0;
4443 cregion.srcOffset.y = 0;
4444 cregion.srcOffset.z = 0;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004445 cregion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT;
Mark Lobodzinskice7eee72016-06-14 16:33:29 -06004446 cregion.dstSubresource.mipLevel = 0;
4447 cregion.dstSubresource.baseArrayLayer = 0;
4448 cregion.dstSubresource.layerCount = 1;
4449 cregion.dstOffset.x = 0;
4450 cregion.dstOffset.y = 0;
4451 cregion.dstOffset.z = 0;
4452 cregion.extent.width = 100;
4453 cregion.extent.height = 100;
4454 cregion.extent.depth = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004455 cmdbuf.CopyImage(m_depthStencil->handle(), VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL, destImage.handle(),
Mark Lobodzinskice7eee72016-06-14 16:33:29 -06004456 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, &cregion);
4457 cmdbuf.EndCommandBuffer();
4458
4459 VkSubmitInfo submit_info;
4460 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
4461 submit_info.pNext = NULL;
4462 submit_info.waitSemaphoreCount = 0;
4463 submit_info.pWaitSemaphores = NULL;
4464 submit_info.pWaitDstStageMask = NULL;
4465 submit_info.commandBufferCount = 1;
4466 submit_info.pCommandBuffers = &cmdbuf.handle();
4467 submit_info.signalSemaphoreCount = 0;
4468 submit_info.pSignalSemaphores = NULL;
4469
4470 m_errorMonitor->ExpectSuccess();
4471 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
4472 m_errorMonitor->VerifyNotFound();
4473
Mark Lobodzinskid0440da2016-06-17 15:10:03 -06004474 vkQueueWaitIdle(m_device->m_queue);
Mark Lobodzinskice7eee72016-06-14 16:33:29 -06004475 vkDestroyFence(m_device->device(), fence, nullptr);
4476 vkDestroyRenderPass(m_device->device(), rp, nullptr);
4477 vkDestroyFramebuffer(m_device->device(), fb, nullptr);
4478}
4479
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06004480TEST_F(VkLayerTest, UnusedPreserveAttachment) {
4481 TEST_DESCRIPTION("Create a framebuffer where a subpass has a preserve "
4482 "attachment reference of VK_ATTACHMENT_UNUSED");
4483
4484 ASSERT_NO_FATAL_FAILURE(InitState());
4485 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
4486
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004487 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "must not be VK_ATTACHMENT_UNUSED");
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06004488
4489 VkAttachmentReference color_attach = {};
4490 color_attach.layout = VK_IMAGE_LAYOUT_GENERAL;
4491 color_attach.attachment = 0;
4492 uint32_t preserve_attachment = VK_ATTACHMENT_UNUSED;
4493 VkSubpassDescription subpass = {};
4494 subpass.colorAttachmentCount = 1;
4495 subpass.pColorAttachments = &color_attach;
4496 subpass.preserveAttachmentCount = 1;
4497 subpass.pPreserveAttachments = &preserve_attachment;
4498
4499 VkRenderPassCreateInfo rpci = {};
4500 rpci.subpassCount = 1;
4501 rpci.pSubpasses = &subpass;
4502 rpci.attachmentCount = 1;
4503 VkAttachmentDescription attach_desc = {};
4504 attach_desc.format = VK_FORMAT_UNDEFINED;
4505 rpci.pAttachments = &attach_desc;
4506 rpci.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
4507 VkRenderPass rp;
Mark Lobodzinskia4feeeb2016-06-17 12:00:46 -06004508 VkResult result = vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06004509
4510 m_errorMonitor->VerifyFound();
4511
Mark Lobodzinskia4feeeb2016-06-17 12:00:46 -06004512 if (result == VK_SUCCESS) {
4513 vkDestroyRenderPass(m_device->device(), rp, NULL);
4514 }
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06004515}
4516
Chris Forbesc5389742016-06-29 11:49:23 +12004517TEST_F(VkLayerTest, CreateRenderPassResolveRequiresColorMsaa) {
Chris Forbes6655bb32016-07-01 18:27:30 +12004518 TEST_DESCRIPTION("Ensure that CreateRenderPass produces a validation error "
4519 "when the source of a subpass multisample resolve "
4520 "does not have multiple samples.");
4521
Chris Forbesc5389742016-06-29 11:49:23 +12004522 ASSERT_NO_FATAL_FAILURE(InitState());
4523
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004524 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
4525 "Subpass 0 requests multisample resolve from attachment 0 which has "
4526 "VK_SAMPLE_COUNT_1_BIT");
Chris Forbesc5389742016-06-29 11:49:23 +12004527
4528 VkAttachmentDescription attachments[] = {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004529 {0, VK_FORMAT_R8G8B8A8_UNORM, VK_SAMPLE_COUNT_1_BIT, VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE,
4530 VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
4531 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL},
4532 {0, VK_FORMAT_R8G8B8A8_UNORM, VK_SAMPLE_COUNT_1_BIT, VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE,
4533 VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
4534 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL},
Chris Forbesc5389742016-06-29 11:49:23 +12004535 };
4536
4537 VkAttachmentReference color = {
4538 0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
4539 };
4540
4541 VkAttachmentReference resolve = {
4542 0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
4543 };
4544
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004545 VkSubpassDescription subpass = {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 1, &color, &resolve, nullptr, 0, nullptr};
Chris Forbesc5389742016-06-29 11:49:23 +12004546
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004547 VkRenderPassCreateInfo rpci = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 2, attachments, 1, &subpass, 0, nullptr};
Chris Forbesc5389742016-06-29 11:49:23 +12004548
4549 VkRenderPass rp;
4550 VkResult err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
4551
4552 m_errorMonitor->VerifyFound();
4553
4554 if (err == VK_SUCCESS)
4555 vkDestroyRenderPass(m_device->device(), rp, nullptr);
4556}
4557
4558TEST_F(VkLayerTest, CreateRenderPassResolveRequiresSingleSampleDest) {
Chris Forbes6655bb32016-07-01 18:27:30 +12004559 TEST_DESCRIPTION("Ensure CreateRenderPass produces a validation error "
4560 "when a subpass multisample resolve operation is "
4561 "requested, and the destination of that resolve has "
4562 "multiple samples.");
4563
Chris Forbesc5389742016-06-29 11:49:23 +12004564 ASSERT_NO_FATAL_FAILURE(InitState());
4565
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004566 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
4567 "Subpass 0 requests multisample resolve into attachment 1, which "
4568 "must have VK_SAMPLE_COUNT_1_BIT but has VK_SAMPLE_COUNT_4_BIT");
Chris Forbesc5389742016-06-29 11:49:23 +12004569
4570 VkAttachmentDescription attachments[] = {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004571 {0, VK_FORMAT_R8G8B8A8_UNORM, VK_SAMPLE_COUNT_4_BIT, VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE,
4572 VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
4573 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL},
4574 {0, VK_FORMAT_R8G8B8A8_UNORM, VK_SAMPLE_COUNT_4_BIT, VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE,
4575 VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
4576 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL},
Chris Forbesc5389742016-06-29 11:49:23 +12004577 };
4578
4579 VkAttachmentReference color = {
4580 0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
4581 };
4582
4583 VkAttachmentReference resolve = {
4584 1, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
4585 };
4586
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004587 VkSubpassDescription subpass = {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 1, &color, &resolve, nullptr, 0, nullptr};
Chris Forbesc5389742016-06-29 11:49:23 +12004588
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004589 VkRenderPassCreateInfo rpci = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 2, attachments, 1, &subpass, 0, nullptr};
Chris Forbesc5389742016-06-29 11:49:23 +12004590
4591 VkRenderPass rp;
4592 VkResult err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
4593
4594 m_errorMonitor->VerifyFound();
4595
4596 if (err == VK_SUCCESS)
4597 vkDestroyRenderPass(m_device->device(), rp, nullptr);
4598}
4599
Chris Forbes3f128ef2016-06-29 14:58:53 +12004600TEST_F(VkLayerTest, CreateRenderPassSubpassSampleCountConsistency) {
Chris Forbes6655bb32016-07-01 18:27:30 +12004601 TEST_DESCRIPTION("Ensure CreateRenderPass produces a validation error "
4602 "when the color and depth attachments used by a subpass "
4603 "have inconsistent sample counts");
4604
Chris Forbes3f128ef2016-06-29 14:58:53 +12004605 ASSERT_NO_FATAL_FAILURE(InitState());
4606
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004607 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
4608 "Subpass 0 attempts to render to attachments with inconsistent sample counts");
Chris Forbes3f128ef2016-06-29 14:58:53 +12004609
4610 VkAttachmentDescription attachments[] = {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004611 {0, VK_FORMAT_R8G8B8A8_UNORM, VK_SAMPLE_COUNT_1_BIT, VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE,
4612 VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
4613 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL},
4614 {0, VK_FORMAT_R8G8B8A8_UNORM, VK_SAMPLE_COUNT_4_BIT, VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE,
4615 VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
4616 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL},
Chris Forbes3f128ef2016-06-29 14:58:53 +12004617 };
4618
4619 VkAttachmentReference color[] = {
4620 {
4621 0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
4622 },
4623 {
4624 1, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
4625 },
4626 };
4627
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004628 VkSubpassDescription subpass = {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 2, color, nullptr, nullptr, 0, nullptr};
Chris Forbes3f128ef2016-06-29 14:58:53 +12004629
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004630 VkRenderPassCreateInfo rpci = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 2, attachments, 1, &subpass, 0, nullptr};
Chris Forbes3f128ef2016-06-29 14:58:53 +12004631
4632 VkRenderPass rp;
4633 VkResult err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
4634
4635 m_errorMonitor->VerifyFound();
4636
4637 if (err == VK_SUCCESS)
4638 vkDestroyRenderPass(m_device->device(), rp, nullptr);
4639}
4640
Tobin Ehlis2545e6f2016-06-22 10:42:19 -06004641TEST_F(VkLayerTest, FramebufferCreateErrors) {
4642 TEST_DESCRIPTION("Hit errors when attempting to create a framebuffer :\n"
4643 " 1. Mismatch between fb & renderPass attachmentCount\n"
Tobin Ehlisd3bb23a2016-06-22 13:34:46 -06004644 " 2. Use a color image as depthStencil attachment\n"
Tobin Ehlis77d717c2016-06-22 14:19:19 -06004645 " 3. Mismatch fb & renderPass attachment formats\n"
Tobin Ehlis6cfda642016-06-22 16:12:58 -06004646 " 4. Mismatch fb & renderPass attachment #samples\n"
Tobin Ehlis27f2ae82016-06-23 07:36:57 -06004647 " 5. FB attachment w/ non-1 mip-levels\n"
Tobin Ehlisb1f303b2016-06-23 08:19:55 -06004648 " 6. FB attachment where dimensions don't match\n"
Tobin Ehlis08d4b5e2016-06-23 08:52:39 -06004649 " 7. FB attachment w/o identity swizzle\n"
4650 " 8. FB dimensions exceed physical device limits\n");
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06004651
4652 ASSERT_NO_FATAL_FAILURE(InitState());
4653 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
4654
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004655 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
4656 "vkCreateFramebuffer(): VkFramebufferCreateInfo attachmentCount of 2 "
4657 "does not match attachmentCount of 1 of ");
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06004658
Tobin Ehlis2545e6f2016-06-22 10:42:19 -06004659 // Create a renderPass with a single color attachment
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06004660 VkAttachmentReference attach = {};
4661 attach.layout = VK_IMAGE_LAYOUT_GENERAL;
4662 VkSubpassDescription subpass = {};
Tobin Ehlis2545e6f2016-06-22 10:42:19 -06004663 subpass.pColorAttachments = &attach;
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06004664 VkRenderPassCreateInfo rpci = {};
4665 rpci.subpassCount = 1;
4666 rpci.pSubpasses = &subpass;
4667 rpci.attachmentCount = 1;
4668 VkAttachmentDescription attach_desc = {};
Tobin Ehlisd3bb23a2016-06-22 13:34:46 -06004669 attach_desc.format = VK_FORMAT_B8G8R8A8_UNORM;
Tobin Ehlis77d717c2016-06-22 14:19:19 -06004670 attach_desc.samples = VK_SAMPLE_COUNT_1_BIT;
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06004671 rpci.pAttachments = &attach_desc;
4672 rpci.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
4673 VkRenderPass rp;
4674 VkResult err = vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
4675 ASSERT_VK_SUCCESS(err);
4676
Tobin Ehlis2545e6f2016-06-22 10:42:19 -06004677 VkImageView ivs[2];
4678 ivs[0] = m_renderTargets[0]->targetView(VK_FORMAT_B8G8R8A8_UNORM);
4679 ivs[1] = m_renderTargets[0]->targetView(VK_FORMAT_B8G8R8A8_UNORM);
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06004680 VkFramebufferCreateInfo fb_info = {};
4681 fb_info.sType = VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO;
4682 fb_info.pNext = NULL;
4683 fb_info.renderPass = rp;
Tobin Ehlis2545e6f2016-06-22 10:42:19 -06004684 // Set mis-matching attachmentCount
4685 fb_info.attachmentCount = 2;
4686 fb_info.pAttachments = ivs;
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06004687 fb_info.width = 100;
4688 fb_info.height = 100;
4689 fb_info.layers = 1;
4690
4691 VkFramebuffer fb;
4692 err = vkCreateFramebuffer(device(), &fb_info, NULL, &fb);
4693
4694 m_errorMonitor->VerifyFound();
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06004695 if (err == VK_SUCCESS) {
4696 vkDestroyFramebuffer(m_device->device(), fb, NULL);
4697 }
4698 vkDestroyRenderPass(m_device->device(), rp, NULL);
Tobin Ehlis2545e6f2016-06-22 10:42:19 -06004699
4700 // Create a renderPass with a depth-stencil attachment created with
4701 // IMAGE_USAGE_COLOR_ATTACHMENT
4702 // Add our color attachment to pDepthStencilAttachment
4703 subpass.pDepthStencilAttachment = &attach;
4704 subpass.pColorAttachments = NULL;
4705 VkRenderPass rp_ds;
4706 err = vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp_ds);
4707 ASSERT_VK_SUCCESS(err);
4708 // Set correct attachment count, but attachment has COLOR usage bit set
4709 fb_info.attachmentCount = 1;
4710 fb_info.renderPass = rp_ds;
4711
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004712 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " conflicts with the image's IMAGE_USAGE flags ");
Tobin Ehlis2545e6f2016-06-22 10:42:19 -06004713 err = vkCreateFramebuffer(device(), &fb_info, NULL, &fb);
4714
4715 m_errorMonitor->VerifyFound();
4716 if (err == VK_SUCCESS) {
4717 vkDestroyFramebuffer(m_device->device(), fb, NULL);
4718 }
4719 vkDestroyRenderPass(m_device->device(), rp_ds, NULL);
Tobin Ehlisd3bb23a2016-06-22 13:34:46 -06004720
4721 // Create new renderpass with alternate attachment format from fb
4722 attach_desc.format = VK_FORMAT_R8G8B8A8_UNORM;
4723 subpass.pDepthStencilAttachment = NULL;
4724 subpass.pColorAttachments = &attach;
4725 err = vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
4726 ASSERT_VK_SUCCESS(err);
4727
4728 // Cause error due to mis-matched formats between rp & fb
4729 // rp attachment 0 now has RGBA8 but corresponding fb attach is BGRA8
4730 fb_info.renderPass = rp;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004731 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
4732 " has format of VK_FORMAT_B8G8R8A8_UNORM that does not match ");
Tobin Ehlisd3bb23a2016-06-22 13:34:46 -06004733 err = vkCreateFramebuffer(device(), &fb_info, NULL, &fb);
4734
4735 m_errorMonitor->VerifyFound();
4736 if (err == VK_SUCCESS) {
4737 vkDestroyFramebuffer(m_device->device(), fb, NULL);
4738 }
Tobin Ehlis77d717c2016-06-22 14:19:19 -06004739 vkDestroyRenderPass(m_device->device(), rp, NULL);
4740
4741 // Create new renderpass with alternate sample count from fb
4742 attach_desc.format = VK_FORMAT_B8G8R8A8_UNORM;
4743 attach_desc.samples = VK_SAMPLE_COUNT_4_BIT;
4744 err = vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
4745 ASSERT_VK_SUCCESS(err);
4746
4747 // Cause error due to mis-matched sample count between rp & fb
4748 fb_info.renderPass = rp;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004749 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " has VK_SAMPLE_COUNT_1_BIT samples "
4750 "that do not match the "
4751 "VK_SAMPLE_COUNT_4_BIT ");
Tobin Ehlis77d717c2016-06-22 14:19:19 -06004752 err = vkCreateFramebuffer(device(), &fb_info, NULL, &fb);
4753
4754 m_errorMonitor->VerifyFound();
4755 if (err == VK_SUCCESS) {
4756 vkDestroyFramebuffer(m_device->device(), fb, NULL);
4757 }
Tobin Ehlisd3bb23a2016-06-22 13:34:46 -06004758
4759 vkDestroyRenderPass(m_device->device(), rp, NULL);
Tobin Ehlis6cfda642016-06-22 16:12:58 -06004760
4761 // Create a custom imageView with non-1 mip levels
4762 VkImageObj image(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004763 image.init(128, 128, VK_FORMAT_B8G8R8A8_UNORM, VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT, VK_IMAGE_TILING_OPTIMAL, 0);
Tobin Ehlis6cfda642016-06-22 16:12:58 -06004764 ASSERT_TRUE(image.initialized());
4765
4766 VkImageView view;
4767 VkImageViewCreateInfo ivci = {};
4768 ivci.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
4769 ivci.image = image.handle();
4770 ivci.viewType = VK_IMAGE_VIEW_TYPE_2D;
4771 ivci.format = VK_FORMAT_B8G8R8A8_UNORM;
4772 ivci.subresourceRange.layerCount = 1;
4773 ivci.subresourceRange.baseMipLevel = 0;
4774 // Set level count 2 (only 1 is allowed for FB attachment)
4775 ivci.subresourceRange.levelCount = 2;
4776 ivci.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
4777 err = vkCreateImageView(m_device->device(), &ivci, NULL, &view);
4778 ASSERT_VK_SUCCESS(err);
4779 // Re-create renderpass to have matching sample count
4780 attach_desc.samples = VK_SAMPLE_COUNT_1_BIT;
4781 err = vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
4782 ASSERT_VK_SUCCESS(err);
4783
4784 fb_info.renderPass = rp;
4785 fb_info.pAttachments = &view;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004786 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " has mip levelCount of 2 but only ");
Tobin Ehlis6cfda642016-06-22 16:12:58 -06004787 err = vkCreateFramebuffer(device(), &fb_info, NULL, &fb);
4788
4789 m_errorMonitor->VerifyFound();
4790 if (err == VK_SUCCESS) {
4791 vkDestroyFramebuffer(m_device->device(), fb, NULL);
4792 }
Tobin Ehlis6cfda642016-06-22 16:12:58 -06004793 vkDestroyImageView(m_device->device(), view, NULL);
Tobin Ehlis27f2ae82016-06-23 07:36:57 -06004794 // Update view to original color buffer and grow FB dimensions too big
4795 fb_info.pAttachments = ivs;
4796 fb_info.height = 1024;
4797 fb_info.width = 1024;
4798 fb_info.layers = 2;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004799 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " Attachment dimensions must be at "
4800 "least as large. ");
Tobin Ehlis27f2ae82016-06-23 07:36:57 -06004801 err = vkCreateFramebuffer(device(), &fb_info, NULL, &fb);
4802
4803 m_errorMonitor->VerifyFound();
4804 if (err == VK_SUCCESS) {
4805 vkDestroyFramebuffer(m_device->device(), fb, NULL);
4806 }
Tobin Ehlisb1f303b2016-06-23 08:19:55 -06004807 // Create view attachment with non-identity swizzle
4808 ivci.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
4809 ivci.image = image.handle();
4810 ivci.viewType = VK_IMAGE_VIEW_TYPE_2D;
4811 ivci.format = VK_FORMAT_B8G8R8A8_UNORM;
4812 ivci.subresourceRange.layerCount = 1;
4813 ivci.subresourceRange.baseMipLevel = 0;
4814 ivci.subresourceRange.levelCount = 1;
4815 ivci.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
4816 ivci.components.r = VK_COMPONENT_SWIZZLE_G;
4817 ivci.components.g = VK_COMPONENT_SWIZZLE_R;
4818 ivci.components.b = VK_COMPONENT_SWIZZLE_A;
4819 ivci.components.a = VK_COMPONENT_SWIZZLE_B;
4820 err = vkCreateImageView(m_device->device(), &ivci, NULL, &view);
4821 ASSERT_VK_SUCCESS(err);
4822
4823 fb_info.pAttachments = &view;
4824 fb_info.height = 100;
4825 fb_info.width = 100;
4826 fb_info.layers = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004827 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " has non-identy swizzle. All "
4828 "framebuffer attachments must have "
4829 "been created with the identity "
4830 "swizzle. ");
Tobin Ehlisb1f303b2016-06-23 08:19:55 -06004831 err = vkCreateFramebuffer(device(), &fb_info, NULL, &fb);
4832
4833 m_errorMonitor->VerifyFound();
4834 if (err == VK_SUCCESS) {
4835 vkDestroyFramebuffer(m_device->device(), fb, NULL);
4836 }
4837 vkDestroyImageView(m_device->device(), view, NULL);
Tobin Ehlis08d4b5e2016-06-23 08:52:39 -06004838 // Request fb that exceeds max dimensions
4839 // reset attachment to color attachment
4840 fb_info.pAttachments = ivs;
4841 fb_info.width = m_device->props.limits.maxFramebufferWidth + 1;
4842 fb_info.height = m_device->props.limits.maxFramebufferHeight + 1;
4843 fb_info.layers = m_device->props.limits.maxFramebufferLayers + 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004844 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " Requested VkFramebufferCreateInfo "
4845 "dimensions exceed physical device "
4846 "limits. ");
Tobin Ehlis08d4b5e2016-06-23 08:52:39 -06004847 err = vkCreateFramebuffer(device(), &fb_info, NULL, &fb);
4848
4849 m_errorMonitor->VerifyFound();
4850 if (err == VK_SUCCESS) {
4851 vkDestroyFramebuffer(m_device->device(), fb, NULL);
4852 }
Tobin Ehlis27f2ae82016-06-23 07:36:57 -06004853
Tobin Ehlis6cfda642016-06-22 16:12:58 -06004854 vkDestroyRenderPass(m_device->device(), rp, NULL);
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06004855}
4856
Mark Lobodzinskic808d442016-04-14 10:57:23 -06004857// This is a positive test. No errors should be generated.
Michael Lentine860b0fe2016-05-20 10:14:00 -05004858TEST_F(VkLayerTest, WaitEventThenSet) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004859 TEST_DESCRIPTION("Wait on a event then set it after the wait has been submitted.");
Michael Lentine860b0fe2016-05-20 10:14:00 -05004860
Michael Lentine860b0fe2016-05-20 10:14:00 -05004861 m_errorMonitor->ExpectSuccess();
Cody Northropc31a84f2016-08-22 10:41:47 -06004862 ASSERT_NO_FATAL_FAILURE(InitState());
Michael Lentine860b0fe2016-05-20 10:14:00 -05004863
4864 VkEvent event;
4865 VkEventCreateInfo event_create_info{};
4866 event_create_info.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO;
4867 vkCreateEvent(m_device->device(), &event_create_info, nullptr, &event);
4868
4869 VkCommandPool command_pool;
4870 VkCommandPoolCreateInfo pool_create_info{};
4871 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
4872 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
4873 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004874 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
Michael Lentine860b0fe2016-05-20 10:14:00 -05004875
4876 VkCommandBuffer command_buffer;
4877 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004878 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
Michael Lentine860b0fe2016-05-20 10:14:00 -05004879 command_buffer_allocate_info.commandPool = command_pool;
4880 command_buffer_allocate_info.commandBufferCount = 1;
4881 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004882 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, &command_buffer);
Michael Lentine860b0fe2016-05-20 10:14:00 -05004883
4884 VkQueue queue = VK_NULL_HANDLE;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004885 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 0, &queue);
Michael Lentine860b0fe2016-05-20 10:14:00 -05004886
4887 {
4888 VkCommandBufferBeginInfo begin_info{};
4889 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
4890 vkBeginCommandBuffer(command_buffer, &begin_info);
4891
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004892 vkCmdWaitEvents(command_buffer, 1, &event, VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, nullptr, 0,
Michael Lentine860b0fe2016-05-20 10:14:00 -05004893 nullptr, 0, nullptr);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004894 vkCmdResetEvent(command_buffer, event, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT);
Michael Lentine860b0fe2016-05-20 10:14:00 -05004895 vkEndCommandBuffer(command_buffer);
4896 }
4897 {
4898 VkSubmitInfo submit_info{};
4899 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
4900 submit_info.commandBufferCount = 1;
4901 submit_info.pCommandBuffers = &command_buffer;
4902 submit_info.signalSemaphoreCount = 0;
4903 submit_info.pSignalSemaphores = nullptr;
4904 vkQueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE);
4905 }
4906 { vkSetEvent(m_device->device(), event); }
4907
4908 vkQueueWaitIdle(queue);
4909
4910 vkDestroyEvent(m_device->device(), event, nullptr);
4911 vkFreeCommandBuffers(m_device->device(), command_pool, 1, &command_buffer);
4912 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
4913
4914 m_errorMonitor->VerifyNotFound();
4915}
Michael Lentine5627e692016-05-20 17:45:02 -05004916// This is a positive test. No errors should be generated.
Michael Lentinef01fb382016-07-21 17:24:56 -05004917TEST_F(VkLayerTest, QueryAndCopySecondaryCommandBuffers) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004918 TEST_DESCRIPTION("Issue a query on a secondary command buffery and copy it on a primary.");
Michael Lentinef01fb382016-07-21 17:24:56 -05004919
Cody Northropc31a84f2016-08-22 10:41:47 -06004920 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004921 if ((m_device->queue_props.empty()) || (m_device->queue_props[0].queueCount < 2))
Michael Lentinef01fb382016-07-21 17:24:56 -05004922 return;
4923
4924 m_errorMonitor->ExpectSuccess();
4925
4926 VkQueryPool query_pool;
4927 VkQueryPoolCreateInfo query_pool_create_info{};
4928 query_pool_create_info.sType = VK_STRUCTURE_TYPE_QUERY_POOL_CREATE_INFO;
4929 query_pool_create_info.queryType = VK_QUERY_TYPE_TIMESTAMP;
4930 query_pool_create_info.queryCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004931 vkCreateQueryPool(m_device->device(), &query_pool_create_info, nullptr, &query_pool);
Michael Lentinef01fb382016-07-21 17:24:56 -05004932
4933 VkCommandPool command_pool;
4934 VkCommandPoolCreateInfo pool_create_info{};
4935 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
4936 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
4937 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004938 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
Michael Lentinef01fb382016-07-21 17:24:56 -05004939
4940 VkCommandBuffer command_buffer;
4941 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004942 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
Michael Lentinef01fb382016-07-21 17:24:56 -05004943 command_buffer_allocate_info.commandPool = command_pool;
4944 command_buffer_allocate_info.commandBufferCount = 1;
4945 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004946 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, &command_buffer);
Michael Lentinef01fb382016-07-21 17:24:56 -05004947
4948 VkCommandBuffer secondary_command_buffer;
4949 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_SECONDARY;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004950 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, &secondary_command_buffer);
Michael Lentinef01fb382016-07-21 17:24:56 -05004951
4952 VkQueue queue = VK_NULL_HANDLE;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004953 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 1, &queue);
Michael Lentinef01fb382016-07-21 17:24:56 -05004954
4955 uint32_t qfi = 0;
4956 VkBufferCreateInfo buff_create_info = {};
4957 buff_create_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
4958 buff_create_info.size = 1024;
4959 buff_create_info.usage = VK_BUFFER_USAGE_TRANSFER_DST_BIT;
4960 buff_create_info.queueFamilyIndexCount = 1;
4961 buff_create_info.pQueueFamilyIndices = &qfi;
4962
4963 VkResult err;
4964 VkBuffer buffer;
4965 err = vkCreateBuffer(m_device->device(), &buff_create_info, NULL, &buffer);
4966 ASSERT_VK_SUCCESS(err);
4967 VkMemoryAllocateInfo mem_alloc = {};
4968 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
4969 mem_alloc.pNext = NULL;
4970 mem_alloc.allocationSize = 1024;
4971 mem_alloc.memoryTypeIndex = 0;
4972
4973 VkMemoryRequirements memReqs;
4974 vkGetBufferMemoryRequirements(m_device->device(), buffer, &memReqs);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004975 bool pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &mem_alloc, 0);
Michael Lentinef01fb382016-07-21 17:24:56 -05004976 if (!pass) {
4977 vkDestroyBuffer(m_device->device(), buffer, NULL);
4978 return;
4979 }
4980
4981 VkDeviceMemory mem;
4982 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem);
4983 ASSERT_VK_SUCCESS(err);
4984 err = vkBindBufferMemory(m_device->device(), buffer, mem, 0);
4985 ASSERT_VK_SUCCESS(err);
4986
4987 VkCommandBufferInheritanceInfo hinfo = {};
4988 hinfo.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_INHERITANCE_INFO;
4989 hinfo.renderPass = VK_NULL_HANDLE;
4990 hinfo.subpass = 0;
4991 hinfo.framebuffer = VK_NULL_HANDLE;
4992 hinfo.occlusionQueryEnable = VK_FALSE;
4993 hinfo.queryFlags = 0;
4994 hinfo.pipelineStatistics = 0;
4995
4996 {
4997 VkCommandBufferBeginInfo begin_info{};
4998 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
4999 begin_info.pInheritanceInfo = &hinfo;
5000 vkBeginCommandBuffer(secondary_command_buffer, &begin_info);
5001
5002 vkCmdResetQueryPool(secondary_command_buffer, query_pool, 0, 1);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005003 vkCmdWriteTimestamp(secondary_command_buffer, VK_PIPELINE_STAGE_ALL_GRAPHICS_BIT, query_pool, 0);
Michael Lentinef01fb382016-07-21 17:24:56 -05005004
5005 vkEndCommandBuffer(secondary_command_buffer);
5006
5007 begin_info.pInheritanceInfo = nullptr;
5008 vkBeginCommandBuffer(command_buffer, &begin_info);
5009
5010 vkCmdExecuteCommands(command_buffer, 1, &secondary_command_buffer);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005011 vkCmdCopyQueryPoolResults(command_buffer, query_pool, 0, 1, buffer, 0, 0, 0);
Michael Lentinef01fb382016-07-21 17:24:56 -05005012
5013 vkEndCommandBuffer(command_buffer);
5014 }
5015 {
5016 VkSubmitInfo submit_info{};
5017 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
5018 submit_info.commandBufferCount = 1;
5019 submit_info.pCommandBuffers = &command_buffer;
5020 submit_info.signalSemaphoreCount = 0;
5021 submit_info.pSignalSemaphores = nullptr;
5022 vkQueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE);
5023 }
5024
5025 vkQueueWaitIdle(queue);
5026
5027 vkDestroyQueryPool(m_device->device(), query_pool, nullptr);
5028 vkFreeCommandBuffers(m_device->device(), command_pool, 1, &command_buffer);
5029 vkFreeCommandBuffers(m_device->device(), command_pool, 1, &secondary_command_buffer);
5030 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
5031 vkDestroyBuffer(m_device->device(), buffer, NULL);
5032 vkFreeMemory(m_device->device(), mem, NULL);
5033
5034 m_errorMonitor->VerifyNotFound();
5035}
5036
5037// This is a positive test. No errors should be generated.
Michael Lentine5627e692016-05-20 17:45:02 -05005038TEST_F(VkLayerTest, QueryAndCopyMultipleCommandBuffers) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005039 TEST_DESCRIPTION("Issue a query and copy from it on a second command buffer.");
Michael Lentine5627e692016-05-20 17:45:02 -05005040
Cody Northropc31a84f2016-08-22 10:41:47 -06005041 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005042 if ((m_device->queue_props.empty()) || (m_device->queue_props[0].queueCount < 2))
Michael Lentine5627e692016-05-20 17:45:02 -05005043 return;
5044
5045 m_errorMonitor->ExpectSuccess();
5046
5047 VkQueryPool query_pool;
5048 VkQueryPoolCreateInfo query_pool_create_info{};
5049 query_pool_create_info.sType = VK_STRUCTURE_TYPE_QUERY_POOL_CREATE_INFO;
5050 query_pool_create_info.queryType = VK_QUERY_TYPE_TIMESTAMP;
5051 query_pool_create_info.queryCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005052 vkCreateQueryPool(m_device->device(), &query_pool_create_info, nullptr, &query_pool);
Michael Lentine5627e692016-05-20 17:45:02 -05005053
5054 VkCommandPool command_pool;
5055 VkCommandPoolCreateInfo pool_create_info{};
5056 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
5057 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
5058 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005059 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
Michael Lentine5627e692016-05-20 17:45:02 -05005060
5061 VkCommandBuffer command_buffer[2];
5062 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005063 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
Michael Lentine5627e692016-05-20 17:45:02 -05005064 command_buffer_allocate_info.commandPool = command_pool;
5065 command_buffer_allocate_info.commandBufferCount = 2;
5066 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005067 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, command_buffer);
Michael Lentine5627e692016-05-20 17:45:02 -05005068
5069 VkQueue queue = VK_NULL_HANDLE;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005070 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 1, &queue);
Michael Lentine5627e692016-05-20 17:45:02 -05005071
5072 uint32_t qfi = 0;
5073 VkBufferCreateInfo buff_create_info = {};
5074 buff_create_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
5075 buff_create_info.size = 1024;
5076 buff_create_info.usage = VK_BUFFER_USAGE_TRANSFER_DST_BIT;
5077 buff_create_info.queueFamilyIndexCount = 1;
5078 buff_create_info.pQueueFamilyIndices = &qfi;
5079
5080 VkResult err;
5081 VkBuffer buffer;
5082 err = vkCreateBuffer(m_device->device(), &buff_create_info, NULL, &buffer);
5083 ASSERT_VK_SUCCESS(err);
5084 VkMemoryAllocateInfo mem_alloc = {};
5085 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
5086 mem_alloc.pNext = NULL;
5087 mem_alloc.allocationSize = 1024;
5088 mem_alloc.memoryTypeIndex = 0;
5089
5090 VkMemoryRequirements memReqs;
5091 vkGetBufferMemoryRequirements(m_device->device(), buffer, &memReqs);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005092 bool pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &mem_alloc, 0);
Michael Lentine5627e692016-05-20 17:45:02 -05005093 if (!pass) {
5094 vkDestroyBuffer(m_device->device(), buffer, NULL);
5095 return;
5096 }
5097
5098 VkDeviceMemory mem;
5099 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem);
5100 ASSERT_VK_SUCCESS(err);
5101 err = vkBindBufferMemory(m_device->device(), buffer, mem, 0);
5102 ASSERT_VK_SUCCESS(err);
5103
5104 {
5105 VkCommandBufferBeginInfo begin_info{};
5106 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
5107 vkBeginCommandBuffer(command_buffer[0], &begin_info);
5108
5109 vkCmdResetQueryPool(command_buffer[0], query_pool, 0, 1);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005110 vkCmdWriteTimestamp(command_buffer[0], VK_PIPELINE_STAGE_ALL_GRAPHICS_BIT, query_pool, 0);
Michael Lentine5627e692016-05-20 17:45:02 -05005111
5112 vkEndCommandBuffer(command_buffer[0]);
5113
5114 vkBeginCommandBuffer(command_buffer[1], &begin_info);
5115
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005116 vkCmdCopyQueryPoolResults(command_buffer[1], query_pool, 0, 1, buffer, 0, 0, 0);
Michael Lentine5627e692016-05-20 17:45:02 -05005117
5118 vkEndCommandBuffer(command_buffer[1]);
5119 }
5120 {
5121 VkSubmitInfo submit_info{};
5122 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
5123 submit_info.commandBufferCount = 2;
5124 submit_info.pCommandBuffers = command_buffer;
5125 submit_info.signalSemaphoreCount = 0;
5126 submit_info.pSignalSemaphores = nullptr;
5127 vkQueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE);
5128 }
5129
5130 vkQueueWaitIdle(queue);
5131
5132 vkDestroyQueryPool(m_device->device(), query_pool, nullptr);
5133 vkFreeCommandBuffers(m_device->device(), command_pool, 2, command_buffer);
5134 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
Tony Barbourdf4c0042016-06-01 15:55:43 -06005135 vkDestroyBuffer(m_device->device(), buffer, NULL);
5136 vkFreeMemory(m_device->device(), mem, NULL);
Michael Lentine5627e692016-05-20 17:45:02 -05005137
5138 m_errorMonitor->VerifyNotFound();
5139}
Michael Lentine860b0fe2016-05-20 10:14:00 -05005140
5141TEST_F(VkLayerTest, ResetEventThenSet) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005142 TEST_DESCRIPTION("Reset an event then set it after the reset has been submitted.");
Michael Lentine860b0fe2016-05-20 10:14:00 -05005143
Michael Lentine860b0fe2016-05-20 10:14:00 -05005144 m_errorMonitor->ExpectSuccess();
5145
Cody Northropc31a84f2016-08-22 10:41:47 -06005146 ASSERT_NO_FATAL_FAILURE(InitState());
Michael Lentine860b0fe2016-05-20 10:14:00 -05005147 VkEvent event;
5148 VkEventCreateInfo event_create_info{};
5149 event_create_info.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO;
5150 vkCreateEvent(m_device->device(), &event_create_info, nullptr, &event);
5151
5152 VkCommandPool command_pool;
5153 VkCommandPoolCreateInfo pool_create_info{};
5154 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
5155 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
5156 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005157 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
Michael Lentine860b0fe2016-05-20 10:14:00 -05005158
5159 VkCommandBuffer command_buffer;
5160 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005161 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
Michael Lentine860b0fe2016-05-20 10:14:00 -05005162 command_buffer_allocate_info.commandPool = command_pool;
5163 command_buffer_allocate_info.commandBufferCount = 1;
5164 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005165 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, &command_buffer);
Michael Lentine860b0fe2016-05-20 10:14:00 -05005166
5167 VkQueue queue = VK_NULL_HANDLE;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005168 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 0, &queue);
Michael Lentine860b0fe2016-05-20 10:14:00 -05005169
5170 {
5171 VkCommandBufferBeginInfo begin_info{};
5172 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
5173 vkBeginCommandBuffer(command_buffer, &begin_info);
5174
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005175 vkCmdResetEvent(command_buffer, event, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT);
5176 vkCmdWaitEvents(command_buffer, 1, &event, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0,
5177 nullptr, 0, nullptr, 0, nullptr);
Michael Lentine860b0fe2016-05-20 10:14:00 -05005178 vkEndCommandBuffer(command_buffer);
5179 }
5180 {
5181 VkSubmitInfo submit_info{};
5182 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
5183 submit_info.commandBufferCount = 1;
5184 submit_info.pCommandBuffers = &command_buffer;
5185 submit_info.signalSemaphoreCount = 0;
5186 submit_info.pSignalSemaphores = nullptr;
5187 vkQueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE);
5188 }
5189 {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005190 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "that is already in use by a "
5191 "command buffer.");
Michael Lentine860b0fe2016-05-20 10:14:00 -05005192 vkSetEvent(m_device->device(), event);
5193 m_errorMonitor->VerifyFound();
5194 }
5195
5196 vkQueueWaitIdle(queue);
5197
5198 vkDestroyEvent(m_device->device(), event, nullptr);
5199 vkFreeCommandBuffers(m_device->device(), command_pool, 1, &command_buffer);
5200 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
5201}
5202
5203// This is a positive test. No errors should be generated.
Tobin Ehlis0bb263b2016-05-10 12:13:02 -06005204TEST_F(VkLayerTest, TwoFencesThreeFrames) {
5205 TEST_DESCRIPTION("Two command buffers with two separate fences are each "
5206 "run through a Submit & WaitForFences cycle 3 times. This "
5207 "previously revealed a bug so running this positive test "
5208 "to prevent a regression.");
5209 m_errorMonitor->ExpectSuccess();
5210
5211 ASSERT_NO_FATAL_FAILURE(InitState());
5212 VkQueue queue = VK_NULL_HANDLE;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005213 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 0, &queue);
Tobin Ehlis0bb263b2016-05-10 12:13:02 -06005214
5215 static const uint32_t NUM_OBJECTS = 2;
5216 static const uint32_t NUM_FRAMES = 3;
5217 VkCommandBuffer cmd_buffers[NUM_OBJECTS] = {};
5218 VkFence fences[NUM_OBJECTS] = {};
5219
5220 VkCommandPool cmd_pool;
5221 VkCommandPoolCreateInfo cmd_pool_ci = {};
5222 cmd_pool_ci.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
5223 cmd_pool_ci.queueFamilyIndex = m_device->graphics_queue_node_index_;
5224 cmd_pool_ci.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005225 VkResult err = vkCreateCommandPool(m_device->device(), &cmd_pool_ci, nullptr, &cmd_pool);
Tobin Ehlis0bb263b2016-05-10 12:13:02 -06005226 ASSERT_VK_SUCCESS(err);
5227
5228 VkCommandBufferAllocateInfo cmd_buf_info = {};
5229 cmd_buf_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
5230 cmd_buf_info.commandPool = cmd_pool;
5231 cmd_buf_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
5232 cmd_buf_info.commandBufferCount = 1;
5233
5234 VkFenceCreateInfo fence_ci = {};
5235 fence_ci.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
5236 fence_ci.pNext = nullptr;
5237 fence_ci.flags = 0;
5238
5239 for (uint32_t i = 0; i < NUM_OBJECTS; ++i) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005240 err = vkAllocateCommandBuffers(m_device->device(), &cmd_buf_info, &cmd_buffers[i]);
Tobin Ehlis0bb263b2016-05-10 12:13:02 -06005241 ASSERT_VK_SUCCESS(err);
5242 err = vkCreateFence(m_device->device(), &fence_ci, nullptr, &fences[i]);
5243 ASSERT_VK_SUCCESS(err);
5244 }
5245
5246 for (uint32_t frame = 0; frame < NUM_FRAMES; ++frame) {
Tobin Ehlisf9025162016-05-26 06:55:21 -06005247 for (uint32_t obj = 0; obj < NUM_OBJECTS; ++obj) {
5248 // Create empty cmd buffer
5249 VkCommandBufferBeginInfo cmdBufBeginDesc = {};
5250 cmdBufBeginDesc.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
Tobin Ehlis0bb263b2016-05-10 12:13:02 -06005251
Tobin Ehlisf9025162016-05-26 06:55:21 -06005252 err = vkBeginCommandBuffer(cmd_buffers[obj], &cmdBufBeginDesc);
5253 ASSERT_VK_SUCCESS(err);
5254 err = vkEndCommandBuffer(cmd_buffers[obj]);
5255 ASSERT_VK_SUCCESS(err);
Tobin Ehlis0bb263b2016-05-10 12:13:02 -06005256
Tobin Ehlisf9025162016-05-26 06:55:21 -06005257 VkSubmitInfo submit_info = {};
5258 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
5259 submit_info.commandBufferCount = 1;
5260 submit_info.pCommandBuffers = &cmd_buffers[obj];
5261 // Submit cmd buffer and wait for fence
5262 err = vkQueueSubmit(queue, 1, &submit_info, fences[obj]);
5263 ASSERT_VK_SUCCESS(err);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005264 err = vkWaitForFences(m_device->device(), 1, &fences[obj], VK_TRUE, UINT64_MAX);
Tobin Ehlisf9025162016-05-26 06:55:21 -06005265 ASSERT_VK_SUCCESS(err);
5266 err = vkResetFences(m_device->device(), 1, &fences[obj]);
5267 ASSERT_VK_SUCCESS(err);
5268 }
Tobin Ehlis0bb263b2016-05-10 12:13:02 -06005269 }
5270 m_errorMonitor->VerifyNotFound();
Tony Barbourdf4c0042016-06-01 15:55:43 -06005271 vkDestroyCommandPool(m_device->device(), cmd_pool, NULL);
5272 for (uint32_t i = 0; i < NUM_OBJECTS; ++i) {
5273 vkDestroyFence(m_device->device(), fences[i], nullptr);
5274 }
Tobin Ehlis0bb263b2016-05-10 12:13:02 -06005275}
5276// This is a positive test. No errors should be generated.
Mark Lobodzinskic808d442016-04-14 10:57:23 -06005277TEST_F(VkLayerTest, TwoQueueSubmitsSeparateQueuesWithSemaphoreAndOneFenceQWI) {
5278
5279 TEST_DESCRIPTION("Two command buffers, each in a separate QueueSubmit call "
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005280 "submitted on separate queues followed by a QueueWaitIdle.");
Mark Lobodzinskic808d442016-04-14 10:57:23 -06005281
Cody Northropc31a84f2016-08-22 10:41:47 -06005282 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005283 if ((m_device->queue_props.empty()) || (m_device->queue_props[0].queueCount < 2))
Tony Barbourdc18b262016-04-22 14:49:48 -06005284 return;
5285
Mark Lobodzinskic808d442016-04-14 10:57:23 -06005286 m_errorMonitor->ExpectSuccess();
5287
5288 VkSemaphore semaphore;
5289 VkSemaphoreCreateInfo semaphore_create_info{};
5290 semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005291 vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr, &semaphore);
Mark Lobodzinskic808d442016-04-14 10:57:23 -06005292
5293 VkCommandPool command_pool;
5294 VkCommandPoolCreateInfo pool_create_info{};
5295 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
5296 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
5297 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005298 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
Mark Lobodzinskic808d442016-04-14 10:57:23 -06005299
5300 VkCommandBuffer command_buffer[2];
5301 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005302 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
Mark Lobodzinskic808d442016-04-14 10:57:23 -06005303 command_buffer_allocate_info.commandPool = command_pool;
5304 command_buffer_allocate_info.commandBufferCount = 2;
5305 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005306 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, command_buffer);
Mark Lobodzinskic808d442016-04-14 10:57:23 -06005307
5308 VkQueue queue = VK_NULL_HANDLE;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005309 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 1, &queue);
Mark Lobodzinskic808d442016-04-14 10:57:23 -06005310
5311 {
5312 VkCommandBufferBeginInfo begin_info{};
5313 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
5314 vkBeginCommandBuffer(command_buffer[0], &begin_info);
5315
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005316 vkCmdPipelineBarrier(command_buffer[0], VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0,
5317 nullptr, 0, nullptr, 0, nullptr);
Mark Lobodzinskic808d442016-04-14 10:57:23 -06005318
5319 VkViewport viewport{};
5320 viewport.maxDepth = 1.0f;
5321 viewport.minDepth = 0.0f;
5322 viewport.width = 512;
5323 viewport.height = 512;
5324 viewport.x = 0;
5325 viewport.y = 0;
5326 vkCmdSetViewport(command_buffer[0], 0, 1, &viewport);
5327 vkEndCommandBuffer(command_buffer[0]);
5328 }
5329 {
5330 VkCommandBufferBeginInfo begin_info{};
5331 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
5332 vkBeginCommandBuffer(command_buffer[1], &begin_info);
5333
5334 VkViewport viewport{};
5335 viewport.maxDepth = 1.0f;
5336 viewport.minDepth = 0.0f;
5337 viewport.width = 512;
5338 viewport.height = 512;
5339 viewport.x = 0;
5340 viewport.y = 0;
5341 vkCmdSetViewport(command_buffer[1], 0, 1, &viewport);
5342 vkEndCommandBuffer(command_buffer[1]);
5343 }
5344 {
5345 VkSubmitInfo submit_info{};
5346 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
5347 submit_info.commandBufferCount = 1;
5348 submit_info.pCommandBuffers = &command_buffer[0];
5349 submit_info.signalSemaphoreCount = 1;
5350 submit_info.pSignalSemaphores = &semaphore;
5351 vkQueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE);
5352 }
5353 {
5354 VkPipelineStageFlags flags[]{VK_PIPELINE_STAGE_ALL_COMMANDS_BIT};
5355 VkSubmitInfo submit_info{};
5356 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
5357 submit_info.commandBufferCount = 1;
5358 submit_info.pCommandBuffers = &command_buffer[1];
5359 submit_info.waitSemaphoreCount = 1;
5360 submit_info.pWaitSemaphores = &semaphore;
5361 submit_info.pWaitDstStageMask = flags;
5362 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
5363 }
5364
5365 vkQueueWaitIdle(m_device->m_queue);
5366
5367 vkDestroySemaphore(m_device->device(), semaphore, nullptr);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005368 vkFreeCommandBuffers(m_device->device(), command_pool, 2, &command_buffer[0]);
Mark Lobodzinskic808d442016-04-14 10:57:23 -06005369 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
5370
5371 m_errorMonitor->VerifyNotFound();
5372}
5373
5374// This is a positive test. No errors should be generated.
5375TEST_F(VkLayerTest, TwoQueueSubmitsSeparateQueuesWithSemaphoreAndOneFenceQWIFence) {
5376
5377 TEST_DESCRIPTION("Two command buffers, each in a separate QueueSubmit call "
5378 "submitted on separate queues, the second having a fence"
5379 "followed by a QueueWaitIdle.");
5380
Cody Northropc31a84f2016-08-22 10:41:47 -06005381 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005382 if ((m_device->queue_props.empty()) || (m_device->queue_props[0].queueCount < 2))
Tony Barbourdc18b262016-04-22 14:49:48 -06005383 return;
5384
Mark Lobodzinskic808d442016-04-14 10:57:23 -06005385 m_errorMonitor->ExpectSuccess();
5386
5387 VkFence fence;
5388 VkFenceCreateInfo fence_create_info{};
5389 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
5390 vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence);
5391
5392 VkSemaphore semaphore;
5393 VkSemaphoreCreateInfo semaphore_create_info{};
5394 semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005395 vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr, &semaphore);
Mark Lobodzinskic808d442016-04-14 10:57:23 -06005396
5397 VkCommandPool command_pool;
5398 VkCommandPoolCreateInfo pool_create_info{};
5399 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
5400 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
5401 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005402 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
Mark Lobodzinskic808d442016-04-14 10:57:23 -06005403
5404 VkCommandBuffer command_buffer[2];
5405 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005406 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
Mark Lobodzinskic808d442016-04-14 10:57:23 -06005407 command_buffer_allocate_info.commandPool = command_pool;
5408 command_buffer_allocate_info.commandBufferCount = 2;
5409 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005410 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, command_buffer);
Mark Lobodzinskic808d442016-04-14 10:57:23 -06005411
5412 VkQueue queue = VK_NULL_HANDLE;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005413 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 1, &queue);
Mark Lobodzinskic808d442016-04-14 10:57:23 -06005414
5415 {
5416 VkCommandBufferBeginInfo begin_info{};
5417 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
5418 vkBeginCommandBuffer(command_buffer[0], &begin_info);
5419
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005420 vkCmdPipelineBarrier(command_buffer[0], VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0,
5421 nullptr, 0, nullptr, 0, nullptr);
Mark Lobodzinskic808d442016-04-14 10:57:23 -06005422
5423 VkViewport viewport{};
5424 viewport.maxDepth = 1.0f;
5425 viewport.minDepth = 0.0f;
5426 viewport.width = 512;
5427 viewport.height = 512;
5428 viewport.x = 0;
5429 viewport.y = 0;
5430 vkCmdSetViewport(command_buffer[0], 0, 1, &viewport);
5431 vkEndCommandBuffer(command_buffer[0]);
5432 }
5433 {
5434 VkCommandBufferBeginInfo begin_info{};
5435 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
5436 vkBeginCommandBuffer(command_buffer[1], &begin_info);
5437
5438 VkViewport viewport{};
5439 viewport.maxDepth = 1.0f;
5440 viewport.minDepth = 0.0f;
5441 viewport.width = 512;
5442 viewport.height = 512;
5443 viewport.x = 0;
5444 viewport.y = 0;
5445 vkCmdSetViewport(command_buffer[1], 0, 1, &viewport);
5446 vkEndCommandBuffer(command_buffer[1]);
5447 }
5448 {
5449 VkSubmitInfo submit_info{};
5450 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
5451 submit_info.commandBufferCount = 1;
5452 submit_info.pCommandBuffers = &command_buffer[0];
5453 submit_info.signalSemaphoreCount = 1;
5454 submit_info.pSignalSemaphores = &semaphore;
5455 vkQueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE);
5456 }
5457 {
5458 VkPipelineStageFlags flags[]{VK_PIPELINE_STAGE_ALL_COMMANDS_BIT};
5459 VkSubmitInfo submit_info{};
5460 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
5461 submit_info.commandBufferCount = 1;
5462 submit_info.pCommandBuffers = &command_buffer[1];
5463 submit_info.waitSemaphoreCount = 1;
5464 submit_info.pWaitSemaphores = &semaphore;
5465 submit_info.pWaitDstStageMask = flags;
5466 vkQueueSubmit(m_device->m_queue, 1, &submit_info, fence);
5467 }
5468
5469 vkQueueWaitIdle(m_device->m_queue);
5470
5471 vkDestroyFence(m_device->device(), fence, nullptr);
5472 vkDestroySemaphore(m_device->device(), semaphore, nullptr);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005473 vkFreeCommandBuffers(m_device->device(), command_pool, 2, &command_buffer[0]);
Mark Lobodzinskic808d442016-04-14 10:57:23 -06005474 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
5475
5476 m_errorMonitor->VerifyNotFound();
5477}
5478
5479// This is a positive test. No errors should be generated.
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005480TEST_F(VkLayerTest, TwoQueueSubmitsSeparateQueuesWithSemaphoreAndOneFenceTwoWFF) {
Mark Lobodzinskic808d442016-04-14 10:57:23 -06005481
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005482 TEST_DESCRIPTION("Two command buffers, each in a separate QueueSubmit call "
5483 "submitted on separate queues, the second having a fence"
5484 "followed by two consecutive WaitForFences calls on the same fence.");
Mark Lobodzinskic808d442016-04-14 10:57:23 -06005485
Cody Northropc31a84f2016-08-22 10:41:47 -06005486 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005487 if ((m_device->queue_props.empty()) || (m_device->queue_props[0].queueCount < 2))
Tony Barbourdc18b262016-04-22 14:49:48 -06005488 return;
5489
Mark Lobodzinskic808d442016-04-14 10:57:23 -06005490 m_errorMonitor->ExpectSuccess();
5491
5492 VkFence fence;
5493 VkFenceCreateInfo fence_create_info{};
5494 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
5495 vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence);
5496
5497 VkSemaphore semaphore;
5498 VkSemaphoreCreateInfo semaphore_create_info{};
5499 semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005500 vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr, &semaphore);
Mark Lobodzinskic808d442016-04-14 10:57:23 -06005501
5502 VkCommandPool command_pool;
5503 VkCommandPoolCreateInfo pool_create_info{};
5504 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
5505 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
5506 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005507 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
Mark Lobodzinskic808d442016-04-14 10:57:23 -06005508
5509 VkCommandBuffer command_buffer[2];
5510 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005511 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
Mark Lobodzinskic808d442016-04-14 10:57:23 -06005512 command_buffer_allocate_info.commandPool = command_pool;
5513 command_buffer_allocate_info.commandBufferCount = 2;
5514 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005515 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, command_buffer);
Mark Lobodzinskic808d442016-04-14 10:57:23 -06005516
5517 VkQueue queue = VK_NULL_HANDLE;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005518 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 1, &queue);
Mark Lobodzinskic808d442016-04-14 10:57:23 -06005519
5520 {
5521 VkCommandBufferBeginInfo begin_info{};
5522 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
5523 vkBeginCommandBuffer(command_buffer[0], &begin_info);
5524
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005525 vkCmdPipelineBarrier(command_buffer[0], VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0,
5526 nullptr, 0, nullptr, 0, nullptr);
Mark Lobodzinskic808d442016-04-14 10:57:23 -06005527
5528 VkViewport viewport{};
5529 viewport.maxDepth = 1.0f;
5530 viewport.minDepth = 0.0f;
5531 viewport.width = 512;
5532 viewport.height = 512;
5533 viewport.x = 0;
5534 viewport.y = 0;
5535 vkCmdSetViewport(command_buffer[0], 0, 1, &viewport);
5536 vkEndCommandBuffer(command_buffer[0]);
5537 }
5538 {
5539 VkCommandBufferBeginInfo begin_info{};
5540 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
5541 vkBeginCommandBuffer(command_buffer[1], &begin_info);
5542
5543 VkViewport viewport{};
5544 viewport.maxDepth = 1.0f;
5545 viewport.minDepth = 0.0f;
5546 viewport.width = 512;
5547 viewport.height = 512;
5548 viewport.x = 0;
5549 viewport.y = 0;
5550 vkCmdSetViewport(command_buffer[1], 0, 1, &viewport);
5551 vkEndCommandBuffer(command_buffer[1]);
5552 }
5553 {
5554 VkSubmitInfo submit_info{};
5555 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
5556 submit_info.commandBufferCount = 1;
5557 submit_info.pCommandBuffers = &command_buffer[0];
5558 submit_info.signalSemaphoreCount = 1;
5559 submit_info.pSignalSemaphores = &semaphore;
5560 vkQueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE);
5561 }
5562 {
5563 VkPipelineStageFlags flags[]{VK_PIPELINE_STAGE_ALL_COMMANDS_BIT};
5564 VkSubmitInfo submit_info{};
5565 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
5566 submit_info.commandBufferCount = 1;
5567 submit_info.pCommandBuffers = &command_buffer[1];
5568 submit_info.waitSemaphoreCount = 1;
5569 submit_info.pWaitSemaphores = &semaphore;
5570 submit_info.pWaitDstStageMask = flags;
5571 vkQueueSubmit(m_device->m_queue, 1, &submit_info, fence);
5572 }
5573
5574 vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
5575 vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
5576
5577 vkDestroyFence(m_device->device(), fence, nullptr);
5578 vkDestroySemaphore(m_device->device(), semaphore, nullptr);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005579 vkFreeCommandBuffers(m_device->device(), command_pool, 2, &command_buffer[0]);
Mark Lobodzinskic808d442016-04-14 10:57:23 -06005580 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
5581
5582 m_errorMonitor->VerifyNotFound();
5583}
5584
Chris Forbes0f8126b2016-06-20 17:48:22 +12005585TEST_F(VkLayerTest, TwoQueuesEnsureCorrectRetirementWithWorkStolen) {
Cody Northropc31a84f2016-08-22 10:41:47 -06005586
5587 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005588 if ((m_device->queue_props.empty()) || (m_device->queue_props[0].queueCount < 2)) {
Chris Forbes0f8126b2016-06-20 17:48:22 +12005589 printf("Test requires two queues, skipping\n");
5590 return;
5591 }
5592
5593 VkResult err;
5594
5595 m_errorMonitor->ExpectSuccess();
5596
5597 VkQueue q0 = m_device->m_queue;
5598 VkQueue q1 = nullptr;
5599 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 1, &q1);
5600 ASSERT_NE(q1, nullptr);
5601
5602 // An (empty) command buffer. We must have work in the first submission --
5603 // the layer treats unfenced work differently from fenced work.
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005604 VkCommandPoolCreateInfo cpci = {VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO, nullptr, 0, 0};
Chris Forbes0f8126b2016-06-20 17:48:22 +12005605 VkCommandPool pool;
5606 err = vkCreateCommandPool(m_device->device(), &cpci, nullptr, &pool);
5607 ASSERT_VK_SUCCESS(err);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005608 VkCommandBufferAllocateInfo cbai = {VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO, nullptr, pool,
5609 VK_COMMAND_BUFFER_LEVEL_PRIMARY, 1};
Chris Forbes0f8126b2016-06-20 17:48:22 +12005610 VkCommandBuffer cb;
5611 err = vkAllocateCommandBuffers(m_device->device(), &cbai, &cb);
5612 ASSERT_VK_SUCCESS(err);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005613 VkCommandBufferBeginInfo cbbi = {VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO, nullptr, 0, nullptr};
Chris Forbes0f8126b2016-06-20 17:48:22 +12005614 err = vkBeginCommandBuffer(cb, &cbbi);
5615 ASSERT_VK_SUCCESS(err);
5616 err = vkEndCommandBuffer(cb);
5617 ASSERT_VK_SUCCESS(err);
5618
5619 // A semaphore
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005620 VkSemaphoreCreateInfo sci = {VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO, nullptr, 0};
Chris Forbes0f8126b2016-06-20 17:48:22 +12005621 VkSemaphore s;
5622 err = vkCreateSemaphore(m_device->device(), &sci, nullptr, &s);
5623 ASSERT_VK_SUCCESS(err);
5624
5625 // First submission, to q0
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005626 VkSubmitInfo s0 = {VK_STRUCTURE_TYPE_SUBMIT_INFO, nullptr, 0, nullptr, nullptr, 1, &cb, 1, &s};
Chris Forbes0f8126b2016-06-20 17:48:22 +12005627
5628 err = vkQueueSubmit(q0, 1, &s0, VK_NULL_HANDLE);
5629 ASSERT_VK_SUCCESS(err);
5630
5631 // Second submission, to q1, waiting on s
5632 VkFlags waitmask = VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT; // doesn't really matter what this value is.
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005633 VkSubmitInfo s1 = {VK_STRUCTURE_TYPE_SUBMIT_INFO, nullptr, 1, &s, &waitmask, 0, nullptr, 0, nullptr};
Chris Forbes0f8126b2016-06-20 17:48:22 +12005634
5635 err = vkQueueSubmit(q1, 1, &s1, VK_NULL_HANDLE);
5636 ASSERT_VK_SUCCESS(err);
5637
5638 // Wait for q0 idle
5639 err = vkQueueWaitIdle(q0);
5640 ASSERT_VK_SUCCESS(err);
5641
5642 // Command buffer should have been completed (it was on q0); reset the pool.
5643 vkFreeCommandBuffers(m_device->device(), pool, 1, &cb);
5644
5645 m_errorMonitor->VerifyNotFound();
5646
5647 // Force device completely idle and clean up resources
5648 vkDeviceWaitIdle(m_device->device());
5649 vkDestroyCommandPool(m_device->device(), pool, nullptr);
5650 vkDestroySemaphore(m_device->device(), s, nullptr);
5651}
Chris Forbes0f8126b2016-06-20 17:48:22 +12005652
Mark Lobodzinskic808d442016-04-14 10:57:23 -06005653// This is a positive test. No errors should be generated.
5654TEST_F(VkLayerTest, TwoQueueSubmitsSeparateQueuesWithSemaphoreAndOneFence) {
5655
5656 TEST_DESCRIPTION("Two command buffers, each in a separate QueueSubmit call "
5657 "submitted on separate queues, the second having a fence, "
5658 "followed by a WaitForFences call.");
5659
Cody Northropc31a84f2016-08-22 10:41:47 -06005660 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005661 if ((m_device->queue_props.empty()) || (m_device->queue_props[0].queueCount < 2))
Tony Barbourdc18b262016-04-22 14:49:48 -06005662 return;
5663
Mark Lobodzinskic808d442016-04-14 10:57:23 -06005664 m_errorMonitor->ExpectSuccess();
5665
Cody Northropc31a84f2016-08-22 10:41:47 -06005666 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinskic808d442016-04-14 10:57:23 -06005667 VkFence fence;
5668 VkFenceCreateInfo fence_create_info{};
5669 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
5670 vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence);
5671
5672 VkSemaphore semaphore;
5673 VkSemaphoreCreateInfo semaphore_create_info{};
5674 semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005675 vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr, &semaphore);
Mark Lobodzinskic808d442016-04-14 10:57:23 -06005676
5677 VkCommandPool command_pool;
5678 VkCommandPoolCreateInfo pool_create_info{};
5679 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
5680 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
5681 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005682 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
Mark Lobodzinskic808d442016-04-14 10:57:23 -06005683
5684 VkCommandBuffer command_buffer[2];
5685 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005686 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
Mark Lobodzinskic808d442016-04-14 10:57:23 -06005687 command_buffer_allocate_info.commandPool = command_pool;
5688 command_buffer_allocate_info.commandBufferCount = 2;
5689 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005690 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, command_buffer);
Mark Lobodzinskic808d442016-04-14 10:57:23 -06005691
5692 VkQueue queue = VK_NULL_HANDLE;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005693 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 1, &queue);
Mark Lobodzinskic808d442016-04-14 10:57:23 -06005694
5695 {
5696 VkCommandBufferBeginInfo begin_info{};
5697 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
5698 vkBeginCommandBuffer(command_buffer[0], &begin_info);
5699
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005700 vkCmdPipelineBarrier(command_buffer[0], VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0,
5701 nullptr, 0, nullptr, 0, nullptr);
Mark Lobodzinskic808d442016-04-14 10:57:23 -06005702
5703 VkViewport viewport{};
5704 viewport.maxDepth = 1.0f;
5705 viewport.minDepth = 0.0f;
5706 viewport.width = 512;
5707 viewport.height = 512;
5708 viewport.x = 0;
5709 viewport.y = 0;
5710 vkCmdSetViewport(command_buffer[0], 0, 1, &viewport);
5711 vkEndCommandBuffer(command_buffer[0]);
5712 }
5713 {
5714 VkCommandBufferBeginInfo begin_info{};
5715 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
5716 vkBeginCommandBuffer(command_buffer[1], &begin_info);
5717
5718 VkViewport viewport{};
5719 viewport.maxDepth = 1.0f;
5720 viewport.minDepth = 0.0f;
5721 viewport.width = 512;
5722 viewport.height = 512;
5723 viewport.x = 0;
5724 viewport.y = 0;
5725 vkCmdSetViewport(command_buffer[1], 0, 1, &viewport);
5726 vkEndCommandBuffer(command_buffer[1]);
5727 }
5728 {
5729 VkSubmitInfo submit_info{};
5730 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
5731 submit_info.commandBufferCount = 1;
5732 submit_info.pCommandBuffers = &command_buffer[0];
5733 submit_info.signalSemaphoreCount = 1;
5734 submit_info.pSignalSemaphores = &semaphore;
5735 vkQueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE);
5736 }
5737 {
5738 VkPipelineStageFlags flags[]{VK_PIPELINE_STAGE_ALL_COMMANDS_BIT};
5739 VkSubmitInfo submit_info{};
5740 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
5741 submit_info.commandBufferCount = 1;
5742 submit_info.pCommandBuffers = &command_buffer[1];
5743 submit_info.waitSemaphoreCount = 1;
5744 submit_info.pWaitSemaphores = &semaphore;
5745 submit_info.pWaitDstStageMask = flags;
5746 vkQueueSubmit(m_device->m_queue, 1, &submit_info, fence);
5747 }
5748
5749 vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
5750
5751 vkDestroyFence(m_device->device(), fence, nullptr);
5752 vkDestroySemaphore(m_device->device(), semaphore, nullptr);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005753 vkFreeCommandBuffers(m_device->device(), command_pool, 2, &command_buffer[0]);
Mark Lobodzinskic808d442016-04-14 10:57:23 -06005754 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
5755
5756 m_errorMonitor->VerifyNotFound();
5757}
5758
5759// This is a positive test. No errors should be generated.
5760TEST_F(VkLayerTest, TwoQueueSubmitsOneQueueWithSemaphoreAndOneFence) {
5761
5762 TEST_DESCRIPTION("Two command buffers, each in a separate QueueSubmit call "
5763 "on the same queue, sharing a signal/wait semaphore, the "
5764 "second having a fence, "
5765 "followed by a WaitForFences call.");
5766
5767 m_errorMonitor->ExpectSuccess();
5768
Cody Northropc31a84f2016-08-22 10:41:47 -06005769 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinskic808d442016-04-14 10:57:23 -06005770 VkFence fence;
5771 VkFenceCreateInfo fence_create_info{};
5772 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
5773 vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence);
5774
5775 VkSemaphore semaphore;
5776 VkSemaphoreCreateInfo semaphore_create_info{};
5777 semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005778 vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr, &semaphore);
Mark Lobodzinskic808d442016-04-14 10:57:23 -06005779
5780 VkCommandPool command_pool;
5781 VkCommandPoolCreateInfo pool_create_info{};
5782 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
5783 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
5784 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005785 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
Mark Lobodzinskic808d442016-04-14 10:57:23 -06005786
5787 VkCommandBuffer command_buffer[2];
5788 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005789 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
Mark Lobodzinskic808d442016-04-14 10:57:23 -06005790 command_buffer_allocate_info.commandPool = command_pool;
5791 command_buffer_allocate_info.commandBufferCount = 2;
5792 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005793 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, command_buffer);
Mark Lobodzinskic808d442016-04-14 10:57:23 -06005794
5795 {
5796 VkCommandBufferBeginInfo begin_info{};
5797 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
5798 vkBeginCommandBuffer(command_buffer[0], &begin_info);
5799
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005800 vkCmdPipelineBarrier(command_buffer[0], VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0,
5801 nullptr, 0, nullptr, 0, nullptr);
Mark Lobodzinskic808d442016-04-14 10:57:23 -06005802
5803 VkViewport viewport{};
5804 viewport.maxDepth = 1.0f;
5805 viewport.minDepth = 0.0f;
5806 viewport.width = 512;
5807 viewport.height = 512;
5808 viewport.x = 0;
5809 viewport.y = 0;
5810 vkCmdSetViewport(command_buffer[0], 0, 1, &viewport);
5811 vkEndCommandBuffer(command_buffer[0]);
5812 }
5813 {
5814 VkCommandBufferBeginInfo begin_info{};
5815 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
5816 vkBeginCommandBuffer(command_buffer[1], &begin_info);
5817
5818 VkViewport viewport{};
5819 viewport.maxDepth = 1.0f;
5820 viewport.minDepth = 0.0f;
5821 viewport.width = 512;
5822 viewport.height = 512;
5823 viewport.x = 0;
5824 viewport.y = 0;
5825 vkCmdSetViewport(command_buffer[1], 0, 1, &viewport);
5826 vkEndCommandBuffer(command_buffer[1]);
5827 }
5828 {
5829 VkSubmitInfo submit_info{};
5830 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
5831 submit_info.commandBufferCount = 1;
5832 submit_info.pCommandBuffers = &command_buffer[0];
5833 submit_info.signalSemaphoreCount = 1;
5834 submit_info.pSignalSemaphores = &semaphore;
5835 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
5836 }
5837 {
5838 VkPipelineStageFlags flags[]{VK_PIPELINE_STAGE_ALL_COMMANDS_BIT};
5839 VkSubmitInfo submit_info{};
5840 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
5841 submit_info.commandBufferCount = 1;
5842 submit_info.pCommandBuffers = &command_buffer[1];
5843 submit_info.waitSemaphoreCount = 1;
5844 submit_info.pWaitSemaphores = &semaphore;
5845 submit_info.pWaitDstStageMask = flags;
5846 vkQueueSubmit(m_device->m_queue, 1, &submit_info, fence);
5847 }
5848
5849 vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
5850
5851 vkDestroyFence(m_device->device(), fence, nullptr);
5852 vkDestroySemaphore(m_device->device(), semaphore, nullptr);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005853 vkFreeCommandBuffers(m_device->device(), command_pool, 2, &command_buffer[0]);
Mark Lobodzinskic808d442016-04-14 10:57:23 -06005854 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
5855
5856 m_errorMonitor->VerifyNotFound();
5857}
5858
5859// This is a positive test. No errors should be generated.
5860TEST_F(VkLayerTest, TwoQueueSubmitsOneQueueNullQueueSubmitWithFence) {
5861
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005862 TEST_DESCRIPTION("Two command buffers, each in a separate QueueSubmit call "
5863 "on the same queue, no fences, followed by a third QueueSubmit with NO "
5864 "SubmitInfos but with a fence, followed by a WaitForFences call.");
Mark Lobodzinskic808d442016-04-14 10:57:23 -06005865
5866 m_errorMonitor->ExpectSuccess();
5867
Cody Northropc31a84f2016-08-22 10:41:47 -06005868 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinskic808d442016-04-14 10:57:23 -06005869 VkFence fence;
5870 VkFenceCreateInfo fence_create_info{};
5871 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
5872 vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence);
5873
5874 VkCommandPool command_pool;
5875 VkCommandPoolCreateInfo pool_create_info{};
5876 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
5877 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
5878 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005879 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
Mark Lobodzinskic808d442016-04-14 10:57:23 -06005880
5881 VkCommandBuffer command_buffer[2];
5882 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005883 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
Mark Lobodzinskic808d442016-04-14 10:57:23 -06005884 command_buffer_allocate_info.commandPool = command_pool;
5885 command_buffer_allocate_info.commandBufferCount = 2;
5886 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005887 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, command_buffer);
Mark Lobodzinskic808d442016-04-14 10:57:23 -06005888
5889 {
5890 VkCommandBufferBeginInfo begin_info{};
5891 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
5892 vkBeginCommandBuffer(command_buffer[0], &begin_info);
5893
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005894 vkCmdPipelineBarrier(command_buffer[0], VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0,
5895 nullptr, 0, nullptr, 0, nullptr);
Mark Lobodzinskic808d442016-04-14 10:57:23 -06005896
5897 VkViewport viewport{};
5898 viewport.maxDepth = 1.0f;
5899 viewport.minDepth = 0.0f;
5900 viewport.width = 512;
5901 viewport.height = 512;
5902 viewport.x = 0;
5903 viewport.y = 0;
5904 vkCmdSetViewport(command_buffer[0], 0, 1, &viewport);
5905 vkEndCommandBuffer(command_buffer[0]);
5906 }
5907 {
5908 VkCommandBufferBeginInfo begin_info{};
5909 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
5910 vkBeginCommandBuffer(command_buffer[1], &begin_info);
5911
5912 VkViewport viewport{};
5913 viewport.maxDepth = 1.0f;
5914 viewport.minDepth = 0.0f;
5915 viewport.width = 512;
5916 viewport.height = 512;
5917 viewport.x = 0;
5918 viewport.y = 0;
5919 vkCmdSetViewport(command_buffer[1], 0, 1, &viewport);
5920 vkEndCommandBuffer(command_buffer[1]);
5921 }
5922 {
5923 VkSubmitInfo submit_info{};
5924 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
5925 submit_info.commandBufferCount = 1;
5926 submit_info.pCommandBuffers = &command_buffer[0];
5927 submit_info.signalSemaphoreCount = 0;
5928 submit_info.pSignalSemaphores = VK_NULL_HANDLE;
5929 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
5930 }
5931 {
5932 VkPipelineStageFlags flags[]{VK_PIPELINE_STAGE_ALL_COMMANDS_BIT};
5933 VkSubmitInfo submit_info{};
5934 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
5935 submit_info.commandBufferCount = 1;
5936 submit_info.pCommandBuffers = &command_buffer[1];
5937 submit_info.waitSemaphoreCount = 0;
5938 submit_info.pWaitSemaphores = VK_NULL_HANDLE;
5939 submit_info.pWaitDstStageMask = flags;
5940 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
5941 }
5942
5943 vkQueueSubmit(m_device->m_queue, 0, NULL, fence);
5944
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005945 VkResult err = vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
Mike Stroyancd1c3e52016-06-21 09:20:01 -06005946 ASSERT_VK_SUCCESS(err);
Mark Lobodzinskic808d442016-04-14 10:57:23 -06005947
5948 vkDestroyFence(m_device->device(), fence, nullptr);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005949 vkFreeCommandBuffers(m_device->device(), command_pool, 2, &command_buffer[0]);
Mark Lobodzinskic808d442016-04-14 10:57:23 -06005950 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
5951
5952 m_errorMonitor->VerifyNotFound();
5953}
5954
5955// This is a positive test. No errors should be generated.
5956TEST_F(VkLayerTest, TwoQueueSubmitsOneQueueOneFence) {
5957
5958 TEST_DESCRIPTION("Two command buffers, each in a separate QueueSubmit call "
5959 "on the same queue, the second having a fence, followed "
5960 "by a WaitForFences call.");
5961
5962 m_errorMonitor->ExpectSuccess();
5963
Cody Northropc31a84f2016-08-22 10:41:47 -06005964 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinskic808d442016-04-14 10:57:23 -06005965 VkFence fence;
5966 VkFenceCreateInfo fence_create_info{};
5967 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
5968 vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence);
5969
5970 VkCommandPool command_pool;
5971 VkCommandPoolCreateInfo pool_create_info{};
5972 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
5973 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
5974 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005975 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
Mark Lobodzinskic808d442016-04-14 10:57:23 -06005976
5977 VkCommandBuffer command_buffer[2];
5978 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005979 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
Mark Lobodzinskic808d442016-04-14 10:57:23 -06005980 command_buffer_allocate_info.commandPool = command_pool;
5981 command_buffer_allocate_info.commandBufferCount = 2;
5982 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005983 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, command_buffer);
Mark Lobodzinskic808d442016-04-14 10:57:23 -06005984
5985 {
5986 VkCommandBufferBeginInfo begin_info{};
5987 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
5988 vkBeginCommandBuffer(command_buffer[0], &begin_info);
5989
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005990 vkCmdPipelineBarrier(command_buffer[0], VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0,
5991 nullptr, 0, nullptr, 0, nullptr);
Mark Lobodzinskic808d442016-04-14 10:57:23 -06005992
5993 VkViewport viewport{};
5994 viewport.maxDepth = 1.0f;
5995 viewport.minDepth = 0.0f;
5996 viewport.width = 512;
5997 viewport.height = 512;
5998 viewport.x = 0;
5999 viewport.y = 0;
6000 vkCmdSetViewport(command_buffer[0], 0, 1, &viewport);
6001 vkEndCommandBuffer(command_buffer[0]);
6002 }
6003 {
6004 VkCommandBufferBeginInfo begin_info{};
6005 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
6006 vkBeginCommandBuffer(command_buffer[1], &begin_info);
6007
6008 VkViewport viewport{};
6009 viewport.maxDepth = 1.0f;
6010 viewport.minDepth = 0.0f;
6011 viewport.width = 512;
6012 viewport.height = 512;
6013 viewport.x = 0;
6014 viewport.y = 0;
6015 vkCmdSetViewport(command_buffer[1], 0, 1, &viewport);
6016 vkEndCommandBuffer(command_buffer[1]);
6017 }
6018 {
6019 VkSubmitInfo submit_info{};
6020 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
6021 submit_info.commandBufferCount = 1;
6022 submit_info.pCommandBuffers = &command_buffer[0];
6023 submit_info.signalSemaphoreCount = 0;
6024 submit_info.pSignalSemaphores = VK_NULL_HANDLE;
6025 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
6026 }
6027 {
6028 VkPipelineStageFlags flags[]{VK_PIPELINE_STAGE_ALL_COMMANDS_BIT};
6029 VkSubmitInfo submit_info{};
6030 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
6031 submit_info.commandBufferCount = 1;
6032 submit_info.pCommandBuffers = &command_buffer[1];
6033 submit_info.waitSemaphoreCount = 0;
6034 submit_info.pWaitSemaphores = VK_NULL_HANDLE;
6035 submit_info.pWaitDstStageMask = flags;
6036 vkQueueSubmit(m_device->m_queue, 1, &submit_info, fence);
6037 }
6038
6039 vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
6040
6041 vkDestroyFence(m_device->device(), fence, nullptr);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006042 vkFreeCommandBuffers(m_device->device(), command_pool, 2, &command_buffer[0]);
Mark Lobodzinskic808d442016-04-14 10:57:23 -06006043 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
6044
6045 m_errorMonitor->VerifyNotFound();
6046}
6047
6048// This is a positive test. No errors should be generated.
6049TEST_F(VkLayerTest, TwoSubmitInfosWithSemaphoreOneQueueSubmitsOneFence) {
6050
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006051 TEST_DESCRIPTION("Two command buffers each in a separate SubmitInfo sent in a single "
6052 "QueueSubmit call followed by a WaitForFences call.");
Cody Northropc31a84f2016-08-22 10:41:47 -06006053 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinskic808d442016-04-14 10:57:23 -06006054
6055 m_errorMonitor->ExpectSuccess();
6056
6057 VkFence fence;
6058 VkFenceCreateInfo fence_create_info{};
6059 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
6060 vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence);
6061
6062 VkSemaphore semaphore;
6063 VkSemaphoreCreateInfo semaphore_create_info{};
6064 semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006065 vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr, &semaphore);
Mark Lobodzinskic808d442016-04-14 10:57:23 -06006066
6067 VkCommandPool command_pool;
6068 VkCommandPoolCreateInfo pool_create_info{};
6069 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
6070 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
6071 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006072 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
Mark Lobodzinskic808d442016-04-14 10:57:23 -06006073
6074 VkCommandBuffer command_buffer[2];
6075 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006076 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
Mark Lobodzinskic808d442016-04-14 10:57:23 -06006077 command_buffer_allocate_info.commandPool = command_pool;
6078 command_buffer_allocate_info.commandBufferCount = 2;
6079 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006080 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, command_buffer);
Mark Lobodzinskic808d442016-04-14 10:57:23 -06006081
6082 {
6083 VkCommandBufferBeginInfo begin_info{};
6084 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
6085 vkBeginCommandBuffer(command_buffer[0], &begin_info);
6086
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006087 vkCmdPipelineBarrier(command_buffer[0], VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0,
6088 nullptr, 0, nullptr, 0, nullptr);
Mark Lobodzinskic808d442016-04-14 10:57:23 -06006089
6090 VkViewport viewport{};
6091 viewport.maxDepth = 1.0f;
6092 viewport.minDepth = 0.0f;
6093 viewport.width = 512;
6094 viewport.height = 512;
6095 viewport.x = 0;
6096 viewport.y = 0;
6097 vkCmdSetViewport(command_buffer[0], 0, 1, &viewport);
6098 vkEndCommandBuffer(command_buffer[0]);
6099 }
6100 {
6101 VkCommandBufferBeginInfo begin_info{};
6102 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
6103 vkBeginCommandBuffer(command_buffer[1], &begin_info);
6104
6105 VkViewport viewport{};
6106 viewport.maxDepth = 1.0f;
6107 viewport.minDepth = 0.0f;
6108 viewport.width = 512;
6109 viewport.height = 512;
6110 viewport.x = 0;
6111 viewport.y = 0;
6112 vkCmdSetViewport(command_buffer[1], 0, 1, &viewport);
6113 vkEndCommandBuffer(command_buffer[1]);
6114 }
6115 {
6116 VkSubmitInfo submit_info[2];
6117 VkPipelineStageFlags flags[]{VK_PIPELINE_STAGE_ALL_COMMANDS_BIT};
6118
6119 submit_info[0].sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
6120 submit_info[0].pNext = NULL;
6121 submit_info[0].commandBufferCount = 1;
6122 submit_info[0].pCommandBuffers = &command_buffer[0];
6123 submit_info[0].signalSemaphoreCount = 1;
6124 submit_info[0].pSignalSemaphores = &semaphore;
6125 submit_info[0].waitSemaphoreCount = 0;
6126 submit_info[0].pWaitSemaphores = NULL;
6127 submit_info[0].pWaitDstStageMask = 0;
6128
6129 submit_info[1].sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
6130 submit_info[1].pNext = NULL;
6131 submit_info[1].commandBufferCount = 1;
6132 submit_info[1].pCommandBuffers = &command_buffer[1];
6133 submit_info[1].waitSemaphoreCount = 1;
6134 submit_info[1].pWaitSemaphores = &semaphore;
6135 submit_info[1].pWaitDstStageMask = flags;
6136 submit_info[1].signalSemaphoreCount = 0;
6137 submit_info[1].pSignalSemaphores = NULL;
6138 vkQueueSubmit(m_device->m_queue, 2, &submit_info[0], fence);
6139 }
6140
6141 vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
6142
6143 vkDestroyFence(m_device->device(), fence, nullptr);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006144 vkFreeCommandBuffers(m_device->device(), command_pool, 2, &command_buffer[0]);
Mark Lobodzinskic808d442016-04-14 10:57:23 -06006145 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
Tony Barbourdf4c0042016-06-01 15:55:43 -06006146 vkDestroySemaphore(m_device->device(), semaphore, nullptr);
Mark Lobodzinskic808d442016-04-14 10:57:23 -06006147
6148 m_errorMonitor->VerifyNotFound();
6149}
6150
Tobin Ehlisb1a87992016-05-25 16:42:47 -06006151TEST_F(VkLayerTest, DynamicDepthBiasNotBound) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006152 TEST_DESCRIPTION("Run a simple draw calls to validate failure when Depth Bias dynamic "
6153 "state is required but not correctly bound.");
Tobin Ehlisb1a87992016-05-25 16:42:47 -06006154
Cody Northropc31a84f2016-08-22 10:41:47 -06006155 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisb1a87992016-05-25 16:42:47 -06006156 // Dynamic depth bias
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006157 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Dynamic depth bias state not set for this command buffer");
6158 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailDepthBias);
Tobin Ehlisb1a87992016-05-25 16:42:47 -06006159 m_errorMonitor->VerifyFound();
6160}
6161
6162TEST_F(VkLayerTest, DynamicLineWidthNotBound) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006163 TEST_DESCRIPTION("Run a simple draw calls to validate failure when Line Width dynamic "
6164 "state is required but not correctly bound.");
Tobin Ehlisa5200ef2016-05-03 10:34:08 -06006165
Cody Northropc31a84f2016-08-22 10:41:47 -06006166 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisa5200ef2016-05-03 10:34:08 -06006167 // Dynamic line width
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006168 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Dynamic line width state not set for this command buffer");
6169 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailLineWidth);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006170 m_errorMonitor->VerifyFound();
Tobin Ehlisb1a87992016-05-25 16:42:47 -06006171}
6172
6173TEST_F(VkLayerTest, DynamicViewportNotBound) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006174 TEST_DESCRIPTION("Run a simple draw calls to validate failure when Viewport dynamic "
6175 "state is required but not correctly bound.");
Tobin Ehlisb1a87992016-05-25 16:42:47 -06006176
Cody Northropc31a84f2016-08-22 10:41:47 -06006177 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisa5200ef2016-05-03 10:34:08 -06006178 // Dynamic viewport state
Chris Forbesb2ba95b2016-09-16 17:11:50 +12006179 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Dynamic viewport(s) 0 are used by PSO, but were not provided");
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006180 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailViewport);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006181 m_errorMonitor->VerifyFound();
Tobin Ehlisb1a87992016-05-25 16:42:47 -06006182}
6183
6184TEST_F(VkLayerTest, DynamicScissorNotBound) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006185 TEST_DESCRIPTION("Run a simple draw calls to validate failure when Scissor dynamic "
6186 "state is required but not correctly bound.");
Tobin Ehlisb1a87992016-05-25 16:42:47 -06006187
Cody Northropc31a84f2016-08-22 10:41:47 -06006188 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisa5200ef2016-05-03 10:34:08 -06006189 // Dynamic scissor state
Chris Forbesb2ba95b2016-09-16 17:11:50 +12006190 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Dynamic scissor(s) 0 are used by PSO, but were not provided");
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006191 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailScissor);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006192 m_errorMonitor->VerifyFound();
Tobin Ehlisb1a87992016-05-25 16:42:47 -06006193}
6194
Cortd713fe82016-07-27 09:51:27 -07006195TEST_F(VkLayerTest, DynamicBlendConstantsNotBound) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006196 TEST_DESCRIPTION("Run a simple draw calls to validate failure when Blend Constants "
6197 "dynamic state is required but not correctly bound.");
Cody Northropc31a84f2016-08-22 10:41:47 -06006198
6199 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlis21c88352016-05-26 06:15:45 -06006200 // Dynamic blend constant state
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006201 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
6202 "Dynamic blend constants state not set for this command buffer");
6203 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailBlend);
Tobin Ehlis21c88352016-05-26 06:15:45 -06006204 m_errorMonitor->VerifyFound();
6205}
6206
6207TEST_F(VkLayerTest, DynamicDepthBoundsNotBound) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006208 TEST_DESCRIPTION("Run a simple draw calls to validate failure when Depth Bounds dynamic "
6209 "state is required but not correctly bound.");
Cody Northropc31a84f2016-08-22 10:41:47 -06006210
6211 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlis21c88352016-05-26 06:15:45 -06006212 if (!m_device->phy().features().depthBounds) {
6213 printf("Device does not support depthBounds test; skipped.\n");
6214 return;
6215 }
6216 // Dynamic depth bounds
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006217 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
6218 "Dynamic depth bounds state not set for this command buffer");
6219 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailDepthBounds);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006220 m_errorMonitor->VerifyFound();
Tobin Ehlisb1a87992016-05-25 16:42:47 -06006221}
6222
6223TEST_F(VkLayerTest, DynamicStencilReadNotBound) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006224 TEST_DESCRIPTION("Run a simple draw calls to validate failure when Stencil Read dynamic "
6225 "state is required but not correctly bound.");
Cody Northropc31a84f2016-08-22 10:41:47 -06006226
6227 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisa5200ef2016-05-03 10:34:08 -06006228 // Dynamic stencil read mask
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006229 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
6230 "Dynamic stencil read mask state not set for this command buffer");
6231 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailStencilReadMask);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006232 m_errorMonitor->VerifyFound();
Tobin Ehlisb1a87992016-05-25 16:42:47 -06006233}
6234
6235TEST_F(VkLayerTest, DynamicStencilWriteNotBound) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006236 TEST_DESCRIPTION("Run a simple draw calls to validate failure when Stencil Write dynamic"
6237 " state is required but not correctly bound.");
Cody Northropc31a84f2016-08-22 10:41:47 -06006238
6239 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisa5200ef2016-05-03 10:34:08 -06006240 // Dynamic stencil write mask
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006241 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
6242 "Dynamic stencil write mask state not set for this command buffer");
6243 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailStencilWriteMask);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006244 m_errorMonitor->VerifyFound();
Tobin Ehlisb1a87992016-05-25 16:42:47 -06006245}
6246
6247TEST_F(VkLayerTest, DynamicStencilRefNotBound) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006248 TEST_DESCRIPTION("Run a simple draw calls to validate failure when Stencil Ref dynamic "
6249 "state is required but not correctly bound.");
Cody Northropc31a84f2016-08-22 10:41:47 -06006250
6251 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisa5200ef2016-05-03 10:34:08 -06006252 // Dynamic stencil reference
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006253 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
6254 "Dynamic stencil reference state not set for this command buffer");
6255 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailStencilReference);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006256 m_errorMonitor->VerifyFound();
Tobin Ehlis963a4042015-09-29 08:18:34 -06006257}
6258
Tobin Ehlis379ba3b2016-07-19 11:22:29 -06006259TEST_F(VkLayerTest, IndexBufferNotBound) {
6260 TEST_DESCRIPTION("Run an indexed draw call without an index buffer bound.");
Cody Northropc31a84f2016-08-22 10:41:47 -06006261
6262 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006263 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
6264 "Index buffer object not bound to this command buffer when Indexed ");
6265 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailIndexBuffer);
Tobin Ehlis379ba3b2016-07-19 11:22:29 -06006266 m_errorMonitor->VerifyFound();
6267}
6268
Karl Schultz6addd812016-02-02 17:17:23 -07006269TEST_F(VkLayerTest, CommandBufferTwoSubmits) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006270 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
6271 "was begun w/ VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT set, but has "
6272 "been submitted");
Tobin Ehlis59278bf2015-08-18 07:10:58 -06006273
Tobin Ehlis59278bf2015-08-18 07:10:58 -06006274 ASSERT_NO_FATAL_FAILURE(InitState());
6275 ASSERT_NO_FATAL_FAILURE(InitViewport());
6276 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
6277
Karl Schultz6addd812016-02-02 17:17:23 -07006278 // We luck out b/c by default the framework creates CB w/ the
6279 // VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT set
Tobin Ehlis59278bf2015-08-18 07:10:58 -06006280 BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006281 m_commandBuffer->ClearAllBuffers(m_clear_color, m_depth_clear_color, m_stencil_clear_color, NULL);
Tobin Ehlis59278bf2015-08-18 07:10:58 -06006282 EndCommandBuffer();
6283
Tobin Ehlis59278bf2015-08-18 07:10:58 -06006284 // Bypass framework since it does the waits automatically
6285 VkResult err = VK_SUCCESS;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06006286 VkSubmitInfo submit_info;
Chia-I Wuf9be13c2015-10-26 20:37:06 +08006287 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
6288 submit_info.pNext = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08006289 submit_info.waitSemaphoreCount = 0;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06006290 submit_info.pWaitSemaphores = NULL;
Jon Ashburn7f9716c2015-12-30 16:42:50 -07006291 submit_info.pWaitDstStageMask = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08006292 submit_info.commandBufferCount = 1;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08006293 submit_info.pCommandBuffers = &m_commandBuffer->handle();
Chia-I Wud50a7d72015-10-26 20:48:51 +08006294 submit_info.signalSemaphoreCount = 0;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06006295 submit_info.pSignalSemaphores = NULL;
6296
Chris Forbes40028e22016-06-13 09:59:34 +12006297 err = vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
Karl Schultz6addd812016-02-02 17:17:23 -07006298 ASSERT_VK_SUCCESS(err);
Tobin Ehlis59278bf2015-08-18 07:10:58 -06006299
Karl Schultz6addd812016-02-02 17:17:23 -07006300 // Cause validation error by re-submitting cmd buffer that should only be
6301 // submitted once
Chris Forbes40028e22016-06-13 09:59:34 +12006302 err = vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
Tobin Ehlis59278bf2015-08-18 07:10:58 -06006303
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006304 m_errorMonitor->VerifyFound();
Tobin Ehlis59278bf2015-08-18 07:10:58 -06006305}
6306
Karl Schultz6addd812016-02-02 17:17:23 -07006307TEST_F(VkLayerTest, AllocDescriptorFromEmptyPool) {
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06006308 // Initiate Draw w/o a PSO bound
Karl Schultz6addd812016-02-02 17:17:23 -07006309 VkResult err;
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06006310
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006311 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Unable to allocate 1 descriptors of "
6312 "type "
6313 "VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER ");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06006314
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06006315 ASSERT_NO_FATAL_FAILURE(InitState());
6316 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06006317
Karl Schultz6addd812016-02-02 17:17:23 -07006318 // Create Pool w/ 1 Sampler descriptor, but try to alloc Uniform Buffer
6319 // descriptor from it
Chia-I Wu1b99bb22015-10-27 19:25:11 +08006320 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006321 ds_type_count.type = VK_DESCRIPTOR_TYPE_SAMPLER;
6322 ds_type_count.descriptorCount = 1;
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06006323
6324 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006325 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
6326 ds_pool_ci.pNext = NULL;
6327 ds_pool_ci.flags = 0;
6328 ds_pool_ci.maxSets = 1;
6329 ds_pool_ci.poolSizeCount = 1;
6330 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06006331
6332 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006333 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06006334 ASSERT_VK_SUCCESS(err);
6335
6336 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006337 dsl_binding.binding = 0;
6338 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
6339 dsl_binding.descriptorCount = 1;
6340 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
6341 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06006342
6343 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006344 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
6345 ds_layout_ci.pNext = NULL;
6346 ds_layout_ci.bindingCount = 1;
6347 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06006348
6349 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006350 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06006351 ASSERT_VK_SUCCESS(err);
6352
6353 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08006354 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08006355 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07006356 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06006357 alloc_info.descriptorPool = ds_pool;
6358 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006359 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06006360
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006361 m_errorMonitor->VerifyFound();
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06006362
Chia-I Wuf7458c52015-10-26 21:10:41 +08006363 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
6364 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06006365}
6366
Karl Schultz6addd812016-02-02 17:17:23 -07006367TEST_F(VkLayerTest, FreeDescriptorFromOneShotPool) {
6368 VkResult err;
Tobin Ehlise735c692015-10-08 13:13:50 -06006369
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006370 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
6371 "It is invalid to call vkFreeDescriptorSets() with a pool created "
6372 "without setting VK_DESCRIPTOR_POOL_CREATE_FREE_DESCRIPTOR_SET_BIT.");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06006373
Tobin Ehlise735c692015-10-08 13:13:50 -06006374 ASSERT_NO_FATAL_FAILURE(InitState());
6375 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlise735c692015-10-08 13:13:50 -06006376
Chia-I Wu1b99bb22015-10-27 19:25:11 +08006377 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006378 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
6379 ds_type_count.descriptorCount = 1;
Tobin Ehlise735c692015-10-08 13:13:50 -06006380
6381 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006382 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
6383 ds_pool_ci.pNext = NULL;
6384 ds_pool_ci.maxSets = 1;
6385 ds_pool_ci.poolSizeCount = 1;
6386 ds_pool_ci.flags = 0;
6387 // Not specifying VK_DESCRIPTOR_POOL_CREATE_FREE_DESCRIPTOR_SET_BIT means
6388 // app can only call vkResetDescriptorPool on this pool.;
6389 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlise735c692015-10-08 13:13:50 -06006390
6391 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006392 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlise735c692015-10-08 13:13:50 -06006393 ASSERT_VK_SUCCESS(err);
6394
6395 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006396 dsl_binding.binding = 0;
6397 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
6398 dsl_binding.descriptorCount = 1;
6399 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
6400 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlise735c692015-10-08 13:13:50 -06006401
6402 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006403 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
6404 ds_layout_ci.pNext = NULL;
6405 ds_layout_ci.bindingCount = 1;
6406 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlise735c692015-10-08 13:13:50 -06006407
6408 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006409 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlise735c692015-10-08 13:13:50 -06006410 ASSERT_VK_SUCCESS(err);
6411
6412 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08006413 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08006414 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07006415 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06006416 alloc_info.descriptorPool = ds_pool;
6417 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006418 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlise735c692015-10-08 13:13:50 -06006419 ASSERT_VK_SUCCESS(err);
6420
6421 err = vkFreeDescriptorSets(m_device->device(), ds_pool, 1, &descriptorSet);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006422 m_errorMonitor->VerifyFound();
Tobin Ehlise735c692015-10-08 13:13:50 -06006423
Chia-I Wuf7458c52015-10-26 21:10:41 +08006424 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
6425 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlise735c692015-10-08 13:13:50 -06006426}
6427
Karl Schultz6addd812016-02-02 17:17:23 -07006428TEST_F(VkLayerTest, InvalidDescriptorPool) {
Karl Schultzbdb75952016-04-19 11:36:49 -06006429 // Attempt to clear Descriptor Pool with bad object.
6430 // ObjectTracker should catch this.
Cody Northropc31a84f2016-08-22 10:41:47 -06006431
6432 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006433 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Invalid Descriptor Pool Object 0xbaad6001");
Mark Lobodzinski02bf89d2016-05-10 14:45:13 -06006434 uint64_t fake_pool_handle = 0xbaad6001;
6435 VkDescriptorPool bad_pool = reinterpret_cast<VkDescriptorPool &>(fake_pool_handle);
6436 vkResetDescriptorPool(device(), bad_pool, 0);
Karl Schultzbdb75952016-04-19 11:36:49 -06006437 m_errorMonitor->VerifyFound();
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06006438}
6439
Karl Schultz6addd812016-02-02 17:17:23 -07006440TEST_F(VkLayerTest, InvalidDescriptorSet) {
Karl Schultzbdb75952016-04-19 11:36:49 -06006441 // Attempt to bind an invalid Descriptor Set to a valid Command Buffer
6442 // ObjectTracker should catch this.
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06006443 // Create a valid cmd buffer
Karl Schultzbdb75952016-04-19 11:36:49 -06006444 // call vkCmdBindDescriptorSets w/ false Descriptor Set
Mark Lobodzinski02bf89d2016-05-10 14:45:13 -06006445
6446 uint64_t fake_set_handle = 0xbaad6001;
6447 VkDescriptorSet bad_set = reinterpret_cast<VkDescriptorSet &>(fake_set_handle);
Karl Schultzbdb75952016-04-19 11:36:49 -06006448 VkResult err;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006449 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Invalid Descriptor Set Object 0xbaad6001");
Karl Schultzbdb75952016-04-19 11:36:49 -06006450
6451 ASSERT_NO_FATAL_FAILURE(InitState());
6452
6453 VkDescriptorSetLayoutBinding layout_bindings[1] = {};
6454 layout_bindings[0].binding = 0;
6455 layout_bindings[0].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
6456 layout_bindings[0].descriptorCount = 1;
6457 layout_bindings[0].stageFlags = VK_SHADER_STAGE_VERTEX_BIT;
6458 layout_bindings[0].pImmutableSamplers = NULL;
6459
6460 VkDescriptorSetLayout descriptor_set_layout;
6461 VkDescriptorSetLayoutCreateInfo dslci = {};
6462 dslci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
6463 dslci.pNext = NULL;
6464 dslci.bindingCount = 1;
6465 dslci.pBindings = layout_bindings;
6466 err = vkCreateDescriptorSetLayout(device(), &dslci, NULL, &descriptor_set_layout);
Karl Schultz5cb21112016-04-21 17:17:40 -06006467 ASSERT_VK_SUCCESS(err);
Karl Schultzbdb75952016-04-19 11:36:49 -06006468
6469 VkPipelineLayout pipeline_layout;
6470 VkPipelineLayoutCreateInfo plci = {};
6471 plci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
6472 plci.pNext = NULL;
6473 plci.setLayoutCount = 1;
6474 plci.pSetLayouts = &descriptor_set_layout;
6475 err = vkCreatePipelineLayout(device(), &plci, NULL, &pipeline_layout);
Karl Schultz5cb21112016-04-21 17:17:40 -06006476 ASSERT_VK_SUCCESS(err);
Karl Schultzbdb75952016-04-19 11:36:49 -06006477
6478 BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006479 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1, &bad_set, 0,
6480 NULL);
Karl Schultzbdb75952016-04-19 11:36:49 -06006481 m_errorMonitor->VerifyFound();
6482 EndCommandBuffer();
6483 vkDestroyPipelineLayout(device(), pipeline_layout, NULL);
6484 vkDestroyDescriptorSetLayout(device(), descriptor_set_layout, NULL);
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06006485}
6486
Karl Schultz6addd812016-02-02 17:17:23 -07006487TEST_F(VkLayerTest, InvalidDescriptorSetLayout) {
Karl Schultzbdb75952016-04-19 11:36:49 -06006488 // Attempt to create a Pipeline Layout with an invalid Descriptor Set Layout.
6489 // ObjectTracker should catch this.
Mark Lobodzinski02bf89d2016-05-10 14:45:13 -06006490 uint64_t fake_layout_handle = 0xbaad6001;
6491 VkDescriptorSetLayout bad_layout = reinterpret_cast<VkDescriptorSetLayout &>(fake_layout_handle);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006492 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Invalid Descriptor Set Layout Object 0xbaad6001");
Cody Northropc31a84f2016-08-22 10:41:47 -06006493 ASSERT_NO_FATAL_FAILURE(InitState());
Karl Schultzbdb75952016-04-19 11:36:49 -06006494 VkPipelineLayout pipeline_layout;
6495 VkPipelineLayoutCreateInfo plci = {};
6496 plci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
6497 plci.pNext = NULL;
6498 plci.setLayoutCount = 1;
6499 plci.pSetLayouts = &bad_layout;
6500 vkCreatePipelineLayout(device(), &plci, NULL, &pipeline_layout);
6501
6502 m_errorMonitor->VerifyFound();
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06006503}
6504
Mark Muellerd4914412016-06-13 17:52:06 -06006505TEST_F(VkLayerTest, WriteDescriptorSetIntegrityCheck) {
6506 TEST_DESCRIPTION("This test verifies some requirements of chapter 13.2.3 of the Vulkan Spec "
6507 "1) A uniform buffer update must have a valid buffer index."
6508 "2) When using an array of descriptors in a single WriteDescriptor,"
6509 " the descriptor types and stageflags must all be the same."
6510 "3) Immutable Sampler state must match across descriptors");
6511
6512 const char *invalid_BufferInfo_ErrorMessage =
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006513 "vkUpdateDescriptorSets: if pDescriptorWrites[0].descriptorType is VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, "
6514 "VK_DESCRIPTOR_TYPE_STORAGE_BUFFER, VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC or "
6515 "VK_DESCRIPTOR_TYPE_STORAGE_BUFFER_DYNAMIC, pDescriptorWrites[0].pBufferInfo must not be NULL";
6516 const char *stateFlag_ErrorMessage = "Attempting write update to descriptor set ";
6517 const char *immutable_ErrorMessage = "Attempting write update to descriptor set ";
Mark Muellerd4914412016-06-13 17:52:06 -06006518
Mark Muellerd4914412016-06-13 17:52:06 -06006519 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, invalid_BufferInfo_ErrorMessage);
6520
6521 ASSERT_NO_FATAL_FAILURE(InitState());
6522 VkDescriptorPoolSize ds_type_count[4] = {};
6523 ds_type_count[0].type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
6524 ds_type_count[0].descriptorCount = 1;
6525 ds_type_count[1].type = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
6526 ds_type_count[1].descriptorCount = 1;
6527 ds_type_count[2].type = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
6528 ds_type_count[2].descriptorCount = 1;
6529 ds_type_count[3].type = VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT;
6530 ds_type_count[3].descriptorCount = 1;
6531
6532 VkDescriptorPoolCreateInfo ds_pool_ci = {};
6533 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
6534 ds_pool_ci.maxSets = 1;
6535 ds_pool_ci.poolSizeCount = sizeof(ds_type_count) / sizeof(VkDescriptorPoolSize);
6536 ds_pool_ci.pPoolSizes = ds_type_count;
6537
6538 VkDescriptorPool ds_pool;
6539 VkResult err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
6540 ASSERT_VK_SUCCESS(err);
6541
Mark Muellerb9896722016-06-16 09:54:29 -06006542 VkDescriptorSetLayoutBinding layout_binding[3] = {};
Mark Muellerd4914412016-06-13 17:52:06 -06006543 layout_binding[0].binding = 0;
6544 layout_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
6545 layout_binding[0].descriptorCount = 1;
6546 layout_binding[0].stageFlags = VK_SHADER_STAGE_ALL;
6547 layout_binding[0].pImmutableSamplers = NULL;
6548
6549 layout_binding[1].binding = 1;
6550 layout_binding[1].descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
6551 layout_binding[1].descriptorCount = 1;
6552 layout_binding[1].stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
6553 layout_binding[1].pImmutableSamplers = NULL;
6554
6555 VkSamplerCreateInfo sampler_ci = {};
6556 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
6557 sampler_ci.pNext = NULL;
6558 sampler_ci.magFilter = VK_FILTER_NEAREST;
6559 sampler_ci.minFilter = VK_FILTER_NEAREST;
6560 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
6561 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
6562 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
6563 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
6564 sampler_ci.mipLodBias = 1.0;
6565 sampler_ci.anisotropyEnable = VK_FALSE;
6566 sampler_ci.maxAnisotropy = 1;
6567 sampler_ci.compareEnable = VK_FALSE;
6568 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
6569 sampler_ci.minLod = 1.0;
6570 sampler_ci.maxLod = 1.0;
6571 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
6572 sampler_ci.unnormalizedCoordinates = VK_FALSE;
6573 VkSampler sampler;
6574
6575 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
6576 ASSERT_VK_SUCCESS(err);
6577
6578 layout_binding[2].binding = 2;
6579 layout_binding[2].descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
6580 layout_binding[2].descriptorCount = 1;
6581 layout_binding[2].stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
6582 layout_binding[2].pImmutableSamplers = static_cast<VkSampler *>(&sampler);
6583
Mark Muellerd4914412016-06-13 17:52:06 -06006584 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
6585 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
6586 ds_layout_ci.bindingCount = sizeof(layout_binding) / sizeof(VkDescriptorSetLayoutBinding);
6587 ds_layout_ci.pBindings = layout_binding;
6588 VkDescriptorSetLayout ds_layout;
6589 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
6590 ASSERT_VK_SUCCESS(err);
6591
6592 VkDescriptorSetAllocateInfo alloc_info = {};
6593 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
6594 alloc_info.descriptorSetCount = 1;
6595 alloc_info.descriptorPool = ds_pool;
6596 alloc_info.pSetLayouts = &ds_layout;
6597 VkDescriptorSet descriptorSet;
6598 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
6599 ASSERT_VK_SUCCESS(err);
6600
6601 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
6602 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
6603 pipeline_layout_ci.pNext = NULL;
6604 pipeline_layout_ci.setLayoutCount = 1;
6605 pipeline_layout_ci.pSetLayouts = &ds_layout;
6606
6607 VkPipelineLayout pipeline_layout;
6608 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
6609 ASSERT_VK_SUCCESS(err);
6610
Mark Mueller5c838ce2016-06-16 09:54:29 -06006611 VkWriteDescriptorSet descriptor_write = {};
Mark Muellerd4914412016-06-13 17:52:06 -06006612 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
6613 descriptor_write.dstSet = descriptorSet;
6614 descriptor_write.dstBinding = 0;
6615 descriptor_write.descriptorCount = 1;
6616 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
6617
Mark Mueller5c838ce2016-06-16 09:54:29 -06006618 // 1) The uniform buffer is intentionally invalid here
Mark Muellerd4914412016-06-13 17:52:06 -06006619 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
6620 m_errorMonitor->VerifyFound();
6621
6622 // Create a buffer to update the descriptor with
6623 uint32_t qfi = 0;
6624 VkBufferCreateInfo buffCI = {};
6625 buffCI.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
6626 buffCI.size = 1024;
6627 buffCI.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
6628 buffCI.queueFamilyIndexCount = 1;
6629 buffCI.pQueueFamilyIndices = &qfi;
6630
6631 VkBuffer dyub;
6632 err = vkCreateBuffer(m_device->device(), &buffCI, NULL, &dyub);
6633 ASSERT_VK_SUCCESS(err);
6634 VkDescriptorBufferInfo buffInfo = {};
6635 buffInfo.buffer = dyub;
6636 buffInfo.offset = 0;
6637 buffInfo.range = 1024;
6638
6639 descriptor_write.pBufferInfo = &buffInfo;
6640 descriptor_write.descriptorCount = 2;
6641
Mark Mueller5c838ce2016-06-16 09:54:29 -06006642 // 2) The stateFlags don't match between the first and second descriptor
Mark Muellerd4914412016-06-13 17:52:06 -06006643 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, stateFlag_ErrorMessage);
6644 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
6645 m_errorMonitor->VerifyFound();
6646
Mark Mueller5c838ce2016-06-16 09:54:29 -06006647 // 3) The second descriptor has a null_ptr pImmutableSamplers and
6648 // the third descriptor contains an immutable sampler
Mark Muellerd4914412016-06-13 17:52:06 -06006649 descriptor_write.dstBinding = 1;
6650 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
Mark Mueller5c838ce2016-06-16 09:54:29 -06006651
Mark Mueller5c838ce2016-06-16 09:54:29 -06006652 // Make pImageInfo index non-null to avoid complaints of it missing
6653 VkDescriptorImageInfo imageInfo = {};
6654 imageInfo.imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
6655 descriptor_write.pImageInfo = &imageInfo;
Mark Muellerd4914412016-06-13 17:52:06 -06006656 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, immutable_ErrorMessage);
6657 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
6658 m_errorMonitor->VerifyFound();
6659
Mark Muellerd4914412016-06-13 17:52:06 -06006660 vkDestroyBuffer(m_device->device(), dyub, NULL);
6661 vkDestroySampler(m_device->device(), sampler, NULL);
6662 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
6663 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
6664 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
6665}
6666
Tobin Ehlis0283c4d2016-06-28 17:57:07 -06006667TEST_F(VkLayerTest, InvalidCmdBufferBufferDestroyed) {
6668 TEST_DESCRIPTION("Attempt to draw with a command buffer that is invalid "
6669 "due to a buffer dependency being destroyed.");
6670 ASSERT_NO_FATAL_FAILURE(InitState());
6671
Tobin Ehlis0283c4d2016-06-28 17:57:07 -06006672 VkBuffer buffer;
6673 VkDeviceMemory mem;
6674 VkMemoryRequirements mem_reqs;
6675
6676 VkBufferCreateInfo buf_info = {};
6677 buf_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
Chris Forbes3d5882f2016-09-16 17:37:17 +12006678 buf_info.usage = VK_BUFFER_USAGE_TRANSFER_DST_BIT;
Tobin Ehlis0283c4d2016-06-28 17:57:07 -06006679 buf_info.size = 256;
6680 buf_info.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
6681 VkResult err = vkCreateBuffer(m_device->device(), &buf_info, NULL, &buffer);
6682 ASSERT_VK_SUCCESS(err);
6683
6684 vkGetBufferMemoryRequirements(m_device->device(), buffer, &mem_reqs);
6685
6686 VkMemoryAllocateInfo alloc_info = {};
6687 alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
6688 alloc_info.allocationSize = 256;
6689 bool pass = false;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006690 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &alloc_info, VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT);
Tobin Ehlis0283c4d2016-06-28 17:57:07 -06006691 if (!pass) {
6692 vkDestroyBuffer(m_device->device(), buffer, NULL);
6693 return;
6694 }
6695 err = vkAllocateMemory(m_device->device(), &alloc_info, NULL, &mem);
6696 ASSERT_VK_SUCCESS(err);
6697
6698 err = vkBindBufferMemory(m_device->device(), buffer, mem, 0);
6699 ASSERT_VK_SUCCESS(err);
6700
Tobin Ehlis0283c4d2016-06-28 17:57:07 -06006701 m_commandBuffer->BeginCommandBuffer();
Chris Forbes3d5882f2016-09-16 17:37:17 +12006702 vkCmdFillBuffer(m_commandBuffer->GetBufferHandle(), buffer, 0, VK_WHOLE_SIZE, 0);
Tobin Ehlis0283c4d2016-06-28 17:57:07 -06006703 m_commandBuffer->EndCommandBuffer();
6704
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006705 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " that is invalid because bound buffer ");
Tobin Ehlis0283c4d2016-06-28 17:57:07 -06006706 // Destroy buffer dependency prior to submit to cause ERROR
6707 vkDestroyBuffer(m_device->device(), buffer, NULL);
6708
6709 VkSubmitInfo submit_info = {};
6710 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
6711 submit_info.commandBufferCount = 1;
6712 submit_info.pCommandBuffers = &m_commandBuffer->handle();
6713 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
6714
6715 m_errorMonitor->VerifyFound();
6716 vkFreeMemory(m_device->handle(), mem, NULL);
6717}
6718
Tobin Ehlis11c8cea2016-06-28 17:44:21 -06006719TEST_F(VkLayerTest, InvalidCmdBufferImageDestroyed) {
6720 TEST_DESCRIPTION("Attempt to draw with a command buffer that is invalid "
6721 "due to an image dependency being destroyed.");
6722 ASSERT_NO_FATAL_FAILURE(InitState());
6723
6724 VkImage image;
6725 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
6726 VkImageCreateInfo image_create_info = {};
6727 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
6728 image_create_info.pNext = NULL;
6729 image_create_info.imageType = VK_IMAGE_TYPE_2D;
6730 image_create_info.format = tex_format;
6731 image_create_info.extent.width = 32;
6732 image_create_info.extent.height = 32;
6733 image_create_info.extent.depth = 1;
6734 image_create_info.mipLevels = 1;
6735 image_create_info.arrayLayers = 1;
6736 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
6737 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006738 image_create_info.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT;
Tobin Ehlis11c8cea2016-06-28 17:44:21 -06006739 image_create_info.flags = 0;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006740 VkResult err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
Tobin Ehlis11c8cea2016-06-28 17:44:21 -06006741 ASSERT_VK_SUCCESS(err);
Tobin Ehlis3d09fd52016-07-06 08:12:56 -06006742 // Have to bind memory to image before recording cmd in cmd buffer using it
6743 VkMemoryRequirements mem_reqs;
6744 VkDeviceMemory image_mem;
6745 bool pass;
6746 VkMemoryAllocateInfo mem_alloc = {};
6747 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
6748 mem_alloc.pNext = NULL;
6749 mem_alloc.memoryTypeIndex = 0;
6750 vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs);
6751 mem_alloc.allocationSize = mem_reqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006752 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0);
Tobin Ehlis3d09fd52016-07-06 08:12:56 -06006753 ASSERT_TRUE(pass);
6754 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &image_mem);
6755 ASSERT_VK_SUCCESS(err);
6756 err = vkBindImageMemory(m_device->device(), image, image_mem, 0);
6757 ASSERT_VK_SUCCESS(err);
Tobin Ehlis11c8cea2016-06-28 17:44:21 -06006758
Tobin Ehlis11c8cea2016-06-28 17:44:21 -06006759 m_commandBuffer->BeginCommandBuffer();
Tobin Ehlis764d7072016-07-01 12:54:29 -06006760 VkClearColorValue ccv;
6761 ccv.float32[0] = 1.0f;
6762 ccv.float32[1] = 1.0f;
6763 ccv.float32[2] = 1.0f;
6764 ccv.float32[3] = 1.0f;
6765 VkImageSubresourceRange isr = {};
6766 isr.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Tobin Ehlis3d09fd52016-07-06 08:12:56 -06006767 isr.baseArrayLayer = 0;
6768 isr.baseMipLevel = 0;
Tobin Ehlis764d7072016-07-01 12:54:29 -06006769 isr.layerCount = 1;
6770 isr.levelCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006771 vkCmdClearColorImage(m_commandBuffer->GetBufferHandle(), image, VK_IMAGE_LAYOUT_GENERAL, &ccv, 1, &isr);
Tobin Ehlis11c8cea2016-06-28 17:44:21 -06006772 m_commandBuffer->EndCommandBuffer();
6773
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006774 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " that is invalid because bound image ");
Tobin Ehlis11c8cea2016-06-28 17:44:21 -06006775 // Destroy image dependency prior to submit to cause ERROR
6776 vkDestroyImage(m_device->device(), image, NULL);
6777
6778 VkSubmitInfo submit_info = {};
6779 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
6780 submit_info.commandBufferCount = 1;
6781 submit_info.pCommandBuffers = &m_commandBuffer->handle();
6782 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
6783
6784 m_errorMonitor->VerifyFound();
Tobin Ehlis3d09fd52016-07-06 08:12:56 -06006785 vkFreeMemory(m_device->device(), image_mem, nullptr);
Tobin Ehlis11c8cea2016-06-28 17:44:21 -06006786}
6787
Tobin Ehlis59f68ab2016-09-06 21:59:07 -06006788TEST_F(VkLayerTest, InvalidCmdBufferFramebufferImageDestroyed) {
6789 TEST_DESCRIPTION("Attempt to draw with a command buffer that is invalid "
6790 "due to a framebuffer image dependency being destroyed.");
6791 VkFormatProperties format_properties;
6792 VkResult err = VK_SUCCESS;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006793 vkGetPhysicalDeviceFormatProperties(gpu(), VK_FORMAT_B8G8R8A8_UNORM, &format_properties);
6794 if (!(format_properties.optimalTilingFeatures & VK_FORMAT_FEATURE_SAMPLED_IMAGE_BIT)) {
Tobin Ehlis59f68ab2016-09-06 21:59:07 -06006795 return;
6796 }
6797
6798 ASSERT_NO_FATAL_FAILURE(InitState());
6799 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
6800
6801 VkImageCreateInfo image_ci = {};
6802 image_ci.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
6803 image_ci.pNext = NULL;
6804 image_ci.imageType = VK_IMAGE_TYPE_2D;
6805 image_ci.format = VK_FORMAT_B8G8R8A8_UNORM;
6806 image_ci.extent.width = 32;
6807 image_ci.extent.height = 32;
6808 image_ci.extent.depth = 1;
6809 image_ci.mipLevels = 1;
6810 image_ci.arrayLayers = 1;
6811 image_ci.samples = VK_SAMPLE_COUNT_1_BIT;
6812 image_ci.tiling = VK_IMAGE_TILING_OPTIMAL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006813 image_ci.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_SAMPLED_BIT;
Tobin Ehlis59f68ab2016-09-06 21:59:07 -06006814 image_ci.initialLayout = VK_IMAGE_LAYOUT_UNDEFINED;
6815 image_ci.flags = 0;
6816 VkImage image;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006817 ASSERT_VK_SUCCESS(vkCreateImage(m_device->handle(), &image_ci, NULL, &image));
Tobin Ehlis59f68ab2016-09-06 21:59:07 -06006818
6819 VkMemoryRequirements memory_reqs;
6820 VkDeviceMemory image_memory;
6821 bool pass;
6822 VkMemoryAllocateInfo memory_info = {};
6823 memory_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
6824 memory_info.pNext = NULL;
6825 memory_info.allocationSize = 0;
6826 memory_info.memoryTypeIndex = 0;
6827 vkGetImageMemoryRequirements(m_device->device(), image, &memory_reqs);
6828 memory_info.allocationSize = memory_reqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006829 pass = m_device->phy().set_memory_type(memory_reqs.memoryTypeBits, &memory_info, 0);
Tobin Ehlis59f68ab2016-09-06 21:59:07 -06006830 ASSERT_TRUE(pass);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006831 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &image_memory);
Tobin Ehlis59f68ab2016-09-06 21:59:07 -06006832 ASSERT_VK_SUCCESS(err);
6833 err = vkBindImageMemory(m_device->device(), image, image_memory, 0);
6834 ASSERT_VK_SUCCESS(err);
6835
6836 VkImageViewCreateInfo ivci = {
6837 VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO,
6838 nullptr,
6839 0,
6840 image,
6841 VK_IMAGE_VIEW_TYPE_2D,
6842 VK_FORMAT_B8G8R8A8_UNORM,
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006843 {VK_COMPONENT_SWIZZLE_R, VK_COMPONENT_SWIZZLE_G, VK_COMPONENT_SWIZZLE_B, VK_COMPONENT_SWIZZLE_A},
Tobin Ehlis59f68ab2016-09-06 21:59:07 -06006844 {VK_IMAGE_ASPECT_COLOR_BIT, 0, 1, 0, 1},
6845 };
6846 VkImageView view;
6847 err = vkCreateImageView(m_device->device(), &ivci, nullptr, &view);
6848 ASSERT_VK_SUCCESS(err);
6849
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006850 VkFramebufferCreateInfo fci = {VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr, 0, m_renderPass, 1, &view, 32, 32, 1};
Tobin Ehlis59f68ab2016-09-06 21:59:07 -06006851 VkFramebuffer fb;
6852 err = vkCreateFramebuffer(m_device->device(), &fci, nullptr, &fb);
6853 ASSERT_VK_SUCCESS(err);
6854
6855 // Just use default renderpass with our framebuffer
6856 m_renderPassBeginInfo.framebuffer = fb;
6857 // Create Null cmd buffer for submit
6858 BeginCommandBuffer();
6859 EndCommandBuffer();
6860 // Destroy image attached to framebuffer to invalidate cmd buffer
6861 vkDestroyImage(m_device->device(), image, NULL);
6862 // Now attempt to submit cmd buffer and verify error
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006863 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " that is invalid because bound image ");
Tobin Ehlis59f68ab2016-09-06 21:59:07 -06006864 QueueCommandBuffer(false);
6865 m_errorMonitor->VerifyFound();
6866
6867 vkDestroyFramebuffer(m_device->device(), fb, nullptr);
6868 vkDestroyImageView(m_device->device(), view, nullptr);
6869 vkFreeMemory(m_device->device(), image_memory, nullptr);
6870}
6871
Mark Lobodzinskia4df3632016-07-14 09:57:41 -06006872TEST_F(VkLayerTest, ImageMemoryNotBound) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006873 TEST_DESCRIPTION("Attempt to draw with an image which has not had memory bound to it.");
Mark Lobodzinskia4df3632016-07-14 09:57:41 -06006874 ASSERT_NO_FATAL_FAILURE(InitState());
6875
6876 VkImage image;
6877 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
6878 VkImageCreateInfo image_create_info = {};
6879 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
6880 image_create_info.pNext = NULL;
6881 image_create_info.imageType = VK_IMAGE_TYPE_2D;
6882 image_create_info.format = tex_format;
6883 image_create_info.extent.width = 32;
6884 image_create_info.extent.height = 32;
6885 image_create_info.extent.depth = 1;
6886 image_create_info.mipLevels = 1;
6887 image_create_info.arrayLayers = 1;
6888 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
6889 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006890 image_create_info.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT;
Mark Lobodzinskia4df3632016-07-14 09:57:41 -06006891 image_create_info.flags = 0;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006892 VkResult err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
Mark Lobodzinskia4df3632016-07-14 09:57:41 -06006893 ASSERT_VK_SUCCESS(err);
6894 // Have to bind memory to image before recording cmd in cmd buffer using it
6895 VkMemoryRequirements mem_reqs;
6896 VkDeviceMemory image_mem;
6897 bool pass;
6898 VkMemoryAllocateInfo mem_alloc = {};
6899 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
6900 mem_alloc.pNext = NULL;
6901 mem_alloc.memoryTypeIndex = 0;
6902 vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs);
6903 mem_alloc.allocationSize = mem_reqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006904 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0);
Mark Lobodzinskia4df3632016-07-14 09:57:41 -06006905 ASSERT_TRUE(pass);
6906 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &image_mem);
6907 ASSERT_VK_SUCCESS(err);
6908
6909 // Introduce error, do not call vkBindImageMemory(m_device->device(), image,
6910 // image_mem, 0);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006911 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "used without first calling vkBindImageMemory");
Mark Lobodzinskia4df3632016-07-14 09:57:41 -06006912
6913 m_commandBuffer->BeginCommandBuffer();
6914 VkClearColorValue ccv;
6915 ccv.float32[0] = 1.0f;
6916 ccv.float32[1] = 1.0f;
6917 ccv.float32[2] = 1.0f;
6918 ccv.float32[3] = 1.0f;
6919 VkImageSubresourceRange isr = {};
6920 isr.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
6921 isr.baseArrayLayer = 0;
6922 isr.baseMipLevel = 0;
6923 isr.layerCount = 1;
6924 isr.levelCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006925 vkCmdClearColorImage(m_commandBuffer->GetBufferHandle(), image, VK_IMAGE_LAYOUT_GENERAL, &ccv, 1, &isr);
Mark Lobodzinskia4df3632016-07-14 09:57:41 -06006926 m_commandBuffer->EndCommandBuffer();
6927
6928 m_errorMonitor->VerifyFound();
6929 vkDestroyImage(m_device->device(), image, NULL);
6930 vkFreeMemory(m_device->device(), image_mem, nullptr);
6931}
6932
6933TEST_F(VkLayerTest, BufferMemoryNotBound) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006934 TEST_DESCRIPTION("Attempt to copy from a buffer which has not had memory bound to it.");
Mark Lobodzinskia4df3632016-07-14 09:57:41 -06006935 ASSERT_NO_FATAL_FAILURE(InitState());
6936
6937 VkImageObj image(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006938 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 -06006939 VK_IMAGE_TILING_OPTIMAL, 0);
6940 ASSERT_TRUE(image.initialized());
6941
6942 VkBuffer buffer;
6943 VkDeviceMemory mem;
6944 VkMemoryRequirements mem_reqs;
6945
6946 VkBufferCreateInfo buf_info = {};
6947 buf_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
Chris Forbes8d260dd2016-09-16 17:42:42 +12006948 buf_info.usage = VK_BUFFER_USAGE_TRANSFER_SRC_BIT;
Mark Lobodzinskia4df3632016-07-14 09:57:41 -06006949 buf_info.size = 256;
6950 buf_info.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
6951 VkResult err = vkCreateBuffer(m_device->device(), &buf_info, NULL, &buffer);
6952 ASSERT_VK_SUCCESS(err);
6953
6954 vkGetBufferMemoryRequirements(m_device->device(), buffer, &mem_reqs);
6955
6956 VkMemoryAllocateInfo alloc_info = {};
6957 alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
6958 alloc_info.allocationSize = 256;
6959 bool pass = false;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006960 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 -06006961 if (!pass) {
6962 vkDestroyBuffer(m_device->device(), buffer, NULL);
6963 return;
6964 }
6965 err = vkAllocateMemory(m_device->device(), &alloc_info, NULL, &mem);
6966 ASSERT_VK_SUCCESS(err);
6967
6968 // Introduce failure by not calling vkBindBufferMemory(m_device->device(),
6969 // buffer, mem, 0);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006970 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "used without first calling vkBindBufferMemory");
Mark Lobodzinskia4df3632016-07-14 09:57:41 -06006971 VkBufferImageCopy region = {};
6972 region.bufferRowLength = 128;
6973 region.bufferImageHeight = 128;
6974 region.imageSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
6975
6976 region.imageSubresource.layerCount = 1;
6977 region.imageExtent.height = 4;
6978 region.imageExtent.width = 4;
6979 region.imageExtent.depth = 1;
6980 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006981 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer, image.handle(), VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1,
6982 &region);
Mark Lobodzinskia4df3632016-07-14 09:57:41 -06006983 m_commandBuffer->EndCommandBuffer();
6984
6985 m_errorMonitor->VerifyFound();
6986
6987 vkDestroyBuffer(m_device->device(), buffer, NULL);
6988 vkFreeMemory(m_device->handle(), mem, NULL);
6989}
6990
Tobin Ehlis85940f52016-07-07 16:57:21 -06006991TEST_F(VkLayerTest, InvalidCmdBufferEventDestroyed) {
6992 TEST_DESCRIPTION("Attempt to draw with a command buffer that is invalid "
6993 "due to an event dependency being destroyed.");
6994 ASSERT_NO_FATAL_FAILURE(InitState());
6995
6996 VkEvent event;
6997 VkEventCreateInfo evci = {};
6998 evci.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO;
6999 VkResult result = vkCreateEvent(m_device->device(), &evci, NULL, &event);
7000 ASSERT_VK_SUCCESS(result);
7001
7002 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007003 vkCmdSetEvent(m_commandBuffer->GetBufferHandle(), event, VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT);
Tobin Ehlis85940f52016-07-07 16:57:21 -06007004 m_commandBuffer->EndCommandBuffer();
7005
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007006 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " that is invalid because bound event ");
Tobin Ehlis85940f52016-07-07 16:57:21 -06007007 // Destroy event dependency prior to submit to cause ERROR
7008 vkDestroyEvent(m_device->device(), event, NULL);
7009
7010 VkSubmitInfo submit_info = {};
7011 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
7012 submit_info.commandBufferCount = 1;
7013 submit_info.pCommandBuffers = &m_commandBuffer->handle();
7014 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
7015
7016 m_errorMonitor->VerifyFound();
7017}
7018
Tobin Ehlisdbea7552016-07-08 14:33:31 -06007019TEST_F(VkLayerTest, InvalidCmdBufferQueryPoolDestroyed) {
7020 TEST_DESCRIPTION("Attempt to draw with a command buffer that is invalid "
7021 "due to a query pool dependency being destroyed.");
7022 ASSERT_NO_FATAL_FAILURE(InitState());
7023
7024 VkQueryPool query_pool;
7025 VkQueryPoolCreateInfo qpci{};
7026 qpci.sType = VK_STRUCTURE_TYPE_QUERY_POOL_CREATE_INFO;
7027 qpci.queryType = VK_QUERY_TYPE_TIMESTAMP;
7028 qpci.queryCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007029 VkResult result = vkCreateQueryPool(m_device->device(), &qpci, nullptr, &query_pool);
Tobin Ehlisdbea7552016-07-08 14:33:31 -06007030 ASSERT_VK_SUCCESS(result);
7031
7032 m_commandBuffer->BeginCommandBuffer();
7033 vkCmdResetQueryPool(m_commandBuffer->GetBufferHandle(), query_pool, 0, 1);
7034 m_commandBuffer->EndCommandBuffer();
7035
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007036 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " that is invalid because bound query pool ");
Tobin Ehlisdbea7552016-07-08 14:33:31 -06007037 // Destroy query pool dependency prior to submit to cause ERROR
7038 vkDestroyQueryPool(m_device->device(), query_pool, NULL);
7039
7040 VkSubmitInfo submit_info = {};
7041 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
7042 submit_info.commandBufferCount = 1;
7043 submit_info.pCommandBuffers = &m_commandBuffer->handle();
7044 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
7045
7046 m_errorMonitor->VerifyFound();
7047}
7048
Tobin Ehlis24130d92016-07-08 15:50:53 -06007049TEST_F(VkLayerTest, InvalidCmdBufferPipelineDestroyed) {
7050 TEST_DESCRIPTION("Attempt to draw with a command buffer that is invalid "
7051 "due to a pipeline dependency being destroyed.");
7052 ASSERT_NO_FATAL_FAILURE(InitState());
7053 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
7054
7055 VkResult err;
7056
7057 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
7058 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
7059
7060 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007061 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis24130d92016-07-08 15:50:53 -06007062 ASSERT_VK_SUCCESS(err);
7063
7064 VkPipelineViewportStateCreateInfo vp_state_ci = {};
7065 vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
7066 vp_state_ci.viewportCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007067 VkViewport vp = {}; // Just need dummy vp to point to
Tobin Ehlis52b504f2016-07-19 13:25:12 -06007068 vp_state_ci.pViewports = &vp;
Tobin Ehlis24130d92016-07-08 15:50:53 -06007069 vp_state_ci.scissorCount = 1;
7070 VkRect2D scissors = {}; // Dummy scissors to point to
7071 vp_state_ci.pScissors = &scissors;
Tobin Ehlis24130d92016-07-08 15:50:53 -06007072
7073 VkPipelineShaderStageCreateInfo shaderStages[2];
7074 memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo));
7075
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007076 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
7077 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this); // We shouldn't need a fragment shader
7078 // but add it to be able to run on more devices
Tobin Ehlis24130d92016-07-08 15:50:53 -06007079 shaderStages[0] = vs.GetStageCreateInfo();
7080 shaderStages[1] = fs.GetStageCreateInfo();
7081
7082 VkPipelineVertexInputStateCreateInfo vi_ci = {};
7083 vi_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
7084
7085 VkPipelineInputAssemblyStateCreateInfo ia_ci = {};
7086 ia_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
7087 ia_ci.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP;
7088
7089 VkPipelineRasterizationStateCreateInfo rs_ci = {};
7090 rs_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
Chris Forbese06ba252016-09-16 17:48:53 +12007091 rs_ci.rasterizerDiscardEnable = true;
7092 rs_ci.lineWidth = 1.0f;
Tobin Ehlis24130d92016-07-08 15:50:53 -06007093
7094 VkPipelineColorBlendAttachmentState att = {};
7095 att.blendEnable = VK_FALSE;
7096 att.colorWriteMask = 0xf;
7097
7098 VkPipelineColorBlendStateCreateInfo cb_ci = {};
7099 cb_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO;
7100 cb_ci.attachmentCount = 1;
7101 cb_ci.pAttachments = &att;
7102
7103 VkGraphicsPipelineCreateInfo gp_ci = {};
7104 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
7105 gp_ci.stageCount = 2;
7106 gp_ci.pStages = shaderStages;
7107 gp_ci.pVertexInputState = &vi_ci;
7108 gp_ci.pInputAssemblyState = &ia_ci;
7109 gp_ci.pViewportState = &vp_state_ci;
7110 gp_ci.pRasterizationState = &rs_ci;
7111 gp_ci.pColorBlendState = &cb_ci;
Tobin Ehlis24130d92016-07-08 15:50:53 -06007112 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
7113 gp_ci.layout = pipeline_layout;
7114 gp_ci.renderPass = renderPass();
7115
7116 VkPipelineCacheCreateInfo pc_ci = {};
7117 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
7118
7119 VkPipeline pipeline;
7120 VkPipelineCache pipelineCache;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007121 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Tobin Ehlis24130d92016-07-08 15:50:53 -06007122 ASSERT_VK_SUCCESS(err);
7123
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007124 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Tobin Ehlis24130d92016-07-08 15:50:53 -06007125 ASSERT_VK_SUCCESS(err);
7126
7127 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007128 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline);
Tobin Ehlis24130d92016-07-08 15:50:53 -06007129 m_commandBuffer->EndCommandBuffer();
7130 // Now destroy pipeline in order to cause error when submitting
7131 vkDestroyPipeline(m_device->device(), pipeline, nullptr);
7132
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007133 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " that is invalid because bound pipeline ");
Tobin Ehlis24130d92016-07-08 15:50:53 -06007134
7135 VkSubmitInfo submit_info = {};
7136 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
7137 submit_info.commandBufferCount = 1;
7138 submit_info.pCommandBuffers = &m_commandBuffer->handle();
7139 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
7140
7141 m_errorMonitor->VerifyFound();
7142 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
7143 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
7144}
7145
Tobin Ehlis31289162016-08-17 14:57:58 -06007146TEST_F(VkLayerTest, InvalidCmdBufferDescriptorSetBufferDestroyed) {
7147 TEST_DESCRIPTION("Attempt to draw with a command buffer that is invalid "
7148 "due to a bound descriptor set with a buffer dependency "
7149 "being destroyed.");
7150 ASSERT_NO_FATAL_FAILURE(InitState());
7151 ASSERT_NO_FATAL_FAILURE(InitViewport());
7152 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
7153
7154 VkDescriptorPoolSize ds_type_count = {};
7155 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
7156 ds_type_count.descriptorCount = 1;
7157
7158 VkDescriptorPoolCreateInfo ds_pool_ci = {};
7159 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
7160 ds_pool_ci.pNext = NULL;
7161 ds_pool_ci.maxSets = 1;
7162 ds_pool_ci.poolSizeCount = 1;
7163 ds_pool_ci.pPoolSizes = &ds_type_count;
7164
7165 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007166 VkResult err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis31289162016-08-17 14:57:58 -06007167 ASSERT_VK_SUCCESS(err);
7168
7169 VkDescriptorSetLayoutBinding dsl_binding = {};
7170 dsl_binding.binding = 0;
7171 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
7172 dsl_binding.descriptorCount = 1;
7173 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
7174 dsl_binding.pImmutableSamplers = NULL;
7175
7176 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
7177 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
7178 ds_layout_ci.pNext = NULL;
7179 ds_layout_ci.bindingCount = 1;
7180 ds_layout_ci.pBindings = &dsl_binding;
7181 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007182 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis31289162016-08-17 14:57:58 -06007183 ASSERT_VK_SUCCESS(err);
7184
7185 VkDescriptorSet descriptorSet;
7186 VkDescriptorSetAllocateInfo alloc_info = {};
7187 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
7188 alloc_info.descriptorSetCount = 1;
7189 alloc_info.descriptorPool = ds_pool;
7190 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007191 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis31289162016-08-17 14:57:58 -06007192 ASSERT_VK_SUCCESS(err);
7193
7194 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
7195 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
7196 pipeline_layout_ci.pNext = NULL;
7197 pipeline_layout_ci.setLayoutCount = 1;
7198 pipeline_layout_ci.pSetLayouts = &ds_layout;
7199
7200 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007201 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis31289162016-08-17 14:57:58 -06007202 ASSERT_VK_SUCCESS(err);
7203
7204 // Create a buffer to update the descriptor with
7205 uint32_t qfi = 0;
7206 VkBufferCreateInfo buffCI = {};
7207 buffCI.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
7208 buffCI.size = 1024;
7209 buffCI.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
7210 buffCI.queueFamilyIndexCount = 1;
7211 buffCI.pQueueFamilyIndices = &qfi;
7212
7213 VkBuffer buffer;
7214 err = vkCreateBuffer(m_device->device(), &buffCI, NULL, &buffer);
7215 ASSERT_VK_SUCCESS(err);
7216 // Allocate memory and bind to buffer so we can make it to the appropriate
7217 // error
7218 VkMemoryAllocateInfo mem_alloc = {};
7219 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
7220 mem_alloc.pNext = NULL;
7221 mem_alloc.allocationSize = 1024;
7222 mem_alloc.memoryTypeIndex = 0;
7223
7224 VkMemoryRequirements memReqs;
7225 vkGetBufferMemoryRequirements(m_device->device(), buffer, &memReqs);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007226 bool pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &mem_alloc, 0);
Tobin Ehlis31289162016-08-17 14:57:58 -06007227 if (!pass) {
7228 vkDestroyBuffer(m_device->device(), buffer, NULL);
7229 return;
7230 }
7231
7232 VkDeviceMemory mem;
7233 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem);
7234 ASSERT_VK_SUCCESS(err);
7235 err = vkBindBufferMemory(m_device->device(), buffer, mem, 0);
7236 ASSERT_VK_SUCCESS(err);
7237 // Correctly update descriptor to avoid "NOT_UPDATED" error
7238 VkDescriptorBufferInfo buffInfo = {};
7239 buffInfo.buffer = buffer;
7240 buffInfo.offset = 0;
7241 buffInfo.range = 1024;
7242
7243 VkWriteDescriptorSet descriptor_write;
7244 memset(&descriptor_write, 0, sizeof(descriptor_write));
7245 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
7246 descriptor_write.dstSet = descriptorSet;
7247 descriptor_write.dstBinding = 0;
7248 descriptor_write.descriptorCount = 1;
7249 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
7250 descriptor_write.pBufferInfo = &buffInfo;
7251
7252 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
7253
7254 // Create PSO to be used for draw-time errors below
7255 char const *vsSource = "#version 450\n"
7256 "\n"
7257 "out gl_PerVertex { \n"
7258 " vec4 gl_Position;\n"
7259 "};\n"
7260 "void main(){\n"
7261 " gl_Position = vec4(1);\n"
7262 "}\n";
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007263 char const *fsSource = "#version 450\n"
7264 "\n"
7265 "layout(location=0) out vec4 x;\n"
7266 "layout(set=0) layout(binding=0) uniform foo { int x; int y; } bar;\n"
7267 "void main(){\n"
7268 " x = vec4(bar.y);\n"
7269 "}\n";
Tobin Ehlis31289162016-08-17 14:57:58 -06007270 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
7271 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
7272 VkPipelineObj pipe(m_device);
7273 pipe.AddShader(&vs);
7274 pipe.AddShader(&fs);
7275 pipe.AddColorAttachment();
7276 pipe.CreateVKPipeline(pipeline_layout, renderPass());
7277
7278 BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007279 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
7280 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
7281 &descriptorSet, 0, NULL);
Tobin Ehlis31289162016-08-17 14:57:58 -06007282 Draw(1, 0, 0, 0);
7283 EndCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007284 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " that is invalid because bound buffer ");
Tobin Ehlis31289162016-08-17 14:57:58 -06007285 // Destroy buffer should invalidate the cmd buffer, causing error on submit
7286 vkDestroyBuffer(m_device->device(), buffer, NULL);
7287 // Attempt to submit cmd buffer
7288 VkSubmitInfo submit_info = {};
7289 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
7290 submit_info.commandBufferCount = 1;
7291 submit_info.pCommandBuffers = &m_commandBuffer->handle();
7292 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
7293 m_errorMonitor->VerifyFound();
7294 // Cleanup
7295 vkFreeMemory(m_device->device(), mem, NULL);
7296
7297 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
7298 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
7299 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
7300}
7301
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06007302TEST_F(VkLayerTest, InvalidCmdBufferDescriptorSetImageSamplerDestroyed) {
7303 TEST_DESCRIPTION("Attempt to draw with a command buffer that is invalid "
7304 "due to a bound descriptor sets with a combined image "
7305 "sampler having their image, sampler, and descriptor set "
7306 "each respectively destroyed and then attempting to "
Mark Mueller917f6bc2016-08-30 10:57:19 -06007307 "submit associated cmd buffers. Attempt to destroy a "
7308 "DescriptorSet that is in use.");
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06007309 ASSERT_NO_FATAL_FAILURE(InitState());
7310 ASSERT_NO_FATAL_FAILURE(InitViewport());
7311 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
7312
7313 VkDescriptorPoolSize ds_type_count = {};
7314 ds_type_count.type = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
7315 ds_type_count.descriptorCount = 1;
7316
7317 VkDescriptorPoolCreateInfo ds_pool_ci = {};
7318 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
7319 ds_pool_ci.pNext = NULL;
7320 ds_pool_ci.maxSets = 1;
7321 ds_pool_ci.poolSizeCount = 1;
7322 ds_pool_ci.pPoolSizes = &ds_type_count;
7323
7324 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007325 VkResult err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06007326 ASSERT_VK_SUCCESS(err);
7327
7328 VkDescriptorSetLayoutBinding dsl_binding = {};
7329 dsl_binding.binding = 0;
7330 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
7331 dsl_binding.descriptorCount = 1;
7332 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
7333 dsl_binding.pImmutableSamplers = NULL;
7334
7335 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
7336 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
7337 ds_layout_ci.pNext = NULL;
7338 ds_layout_ci.bindingCount = 1;
7339 ds_layout_ci.pBindings = &dsl_binding;
7340 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007341 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06007342 ASSERT_VK_SUCCESS(err);
7343
7344 VkDescriptorSet descriptorSet;
7345 VkDescriptorSetAllocateInfo alloc_info = {};
7346 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
7347 alloc_info.descriptorSetCount = 1;
7348 alloc_info.descriptorPool = ds_pool;
7349 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007350 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06007351 ASSERT_VK_SUCCESS(err);
7352
7353 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
7354 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
7355 pipeline_layout_ci.pNext = NULL;
7356 pipeline_layout_ci.setLayoutCount = 1;
7357 pipeline_layout_ci.pSetLayouts = &ds_layout;
7358
7359 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007360 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06007361 ASSERT_VK_SUCCESS(err);
7362
7363 // Create images to update the descriptor with
7364 VkImage image;
7365 VkImage image2;
7366 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
7367 const int32_t tex_width = 32;
7368 const int32_t tex_height = 32;
7369 VkImageCreateInfo image_create_info = {};
7370 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
7371 image_create_info.pNext = NULL;
7372 image_create_info.imageType = VK_IMAGE_TYPE_2D;
7373 image_create_info.format = tex_format;
7374 image_create_info.extent.width = tex_width;
7375 image_create_info.extent.height = tex_height;
7376 image_create_info.extent.depth = 1;
7377 image_create_info.mipLevels = 1;
7378 image_create_info.arrayLayers = 1;
7379 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
7380 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
7381 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
7382 image_create_info.flags = 0;
7383 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
7384 ASSERT_VK_SUCCESS(err);
7385 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image2);
7386 ASSERT_VK_SUCCESS(err);
7387
7388 VkMemoryRequirements memory_reqs;
7389 VkDeviceMemory image_memory;
7390 bool pass;
7391 VkMemoryAllocateInfo memory_info = {};
7392 memory_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
7393 memory_info.pNext = NULL;
7394 memory_info.allocationSize = 0;
7395 memory_info.memoryTypeIndex = 0;
7396 vkGetImageMemoryRequirements(m_device->device(), image, &memory_reqs);
7397 // Allocate enough memory for both images
7398 memory_info.allocationSize = memory_reqs.size * 2;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007399 pass = m_device->phy().set_memory_type(memory_reqs.memoryTypeBits, &memory_info, 0);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06007400 ASSERT_TRUE(pass);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007401 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &image_memory);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06007402 ASSERT_VK_SUCCESS(err);
7403 err = vkBindImageMemory(m_device->device(), image, image_memory, 0);
7404 ASSERT_VK_SUCCESS(err);
7405 // Bind second image to memory right after first image
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007406 err = vkBindImageMemory(m_device->device(), image2, image_memory, memory_reqs.size);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06007407 ASSERT_VK_SUCCESS(err);
7408
7409 VkImageViewCreateInfo image_view_create_info = {};
7410 image_view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
7411 image_view_create_info.image = image;
7412 image_view_create_info.viewType = VK_IMAGE_VIEW_TYPE_2D;
7413 image_view_create_info.format = tex_format;
7414 image_view_create_info.subresourceRange.layerCount = 1;
7415 image_view_create_info.subresourceRange.baseMipLevel = 0;
7416 image_view_create_info.subresourceRange.levelCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007417 image_view_create_info.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06007418
7419 VkImageView view;
7420 VkImageView view2;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007421 err = vkCreateImageView(m_device->device(), &image_view_create_info, NULL, &view);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06007422 ASSERT_VK_SUCCESS(err);
7423 image_view_create_info.image = image2;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007424 err = vkCreateImageView(m_device->device(), &image_view_create_info, NULL, &view2);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06007425 ASSERT_VK_SUCCESS(err);
7426 // Create Samplers
7427 VkSamplerCreateInfo sampler_ci = {};
7428 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
7429 sampler_ci.pNext = NULL;
7430 sampler_ci.magFilter = VK_FILTER_NEAREST;
7431 sampler_ci.minFilter = VK_FILTER_NEAREST;
7432 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
7433 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
7434 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
7435 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
7436 sampler_ci.mipLodBias = 1.0;
7437 sampler_ci.anisotropyEnable = VK_FALSE;
7438 sampler_ci.maxAnisotropy = 1;
7439 sampler_ci.compareEnable = VK_FALSE;
7440 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
7441 sampler_ci.minLod = 1.0;
7442 sampler_ci.maxLod = 1.0;
7443 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
7444 sampler_ci.unnormalizedCoordinates = VK_FALSE;
7445 VkSampler sampler;
7446 VkSampler sampler2;
7447 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
7448 ASSERT_VK_SUCCESS(err);
7449 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler2);
7450 ASSERT_VK_SUCCESS(err);
7451 // Update descriptor with image and sampler
7452 VkDescriptorImageInfo img_info = {};
7453 img_info.sampler = sampler;
7454 img_info.imageView = view;
7455 img_info.imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
7456
7457 VkWriteDescriptorSet descriptor_write;
7458 memset(&descriptor_write, 0, sizeof(descriptor_write));
7459 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
7460 descriptor_write.dstSet = descriptorSet;
7461 descriptor_write.dstBinding = 0;
7462 descriptor_write.descriptorCount = 1;
7463 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
7464 descriptor_write.pImageInfo = &img_info;
7465
7466 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
7467
7468 // Create PSO to be used for draw-time errors below
7469 char const *vsSource = "#version 450\n"
7470 "\n"
7471 "out gl_PerVertex { \n"
7472 " vec4 gl_Position;\n"
7473 "};\n"
7474 "void main(){\n"
7475 " gl_Position = vec4(1);\n"
7476 "}\n";
7477 char const *fsSource = "#version 450\n"
7478 "\n"
7479 "layout(set=0, binding=0) uniform sampler2D s;\n"
7480 "layout(location=0) out vec4 x;\n"
7481 "void main(){\n"
7482 " x = texture(s, vec2(1));\n"
7483 "}\n";
7484 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
7485 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
7486 VkPipelineObj pipe(m_device);
7487 pipe.AddShader(&vs);
7488 pipe.AddShader(&fs);
7489 pipe.AddColorAttachment();
7490 pipe.CreateVKPipeline(pipeline_layout, renderPass());
7491
7492 // First error case is destroying sampler prior to cmd buffer submission
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007493 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Cannot submit cmd buffer using deleted sampler ");
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06007494 BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007495 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
7496 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
7497 &descriptorSet, 0, NULL);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06007498 Draw(1, 0, 0, 0);
7499 EndCommandBuffer();
7500 // Destroy sampler invalidates the cmd buffer, causing error on submit
7501 vkDestroySampler(m_device->device(), sampler, NULL);
7502 // Attempt to submit cmd buffer
7503 VkSubmitInfo submit_info = {};
7504 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
7505 submit_info.commandBufferCount = 1;
7506 submit_info.pCommandBuffers = &m_commandBuffer->handle();
7507 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
7508 m_errorMonitor->VerifyFound();
7509 // Now re-update descriptor with valid sampler and delete image
7510 img_info.sampler = sampler2;
7511 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007512 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " that is invalid because bound image ");
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06007513 BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007514 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
7515 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
7516 &descriptorSet, 0, NULL);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06007517 Draw(1, 0, 0, 0);
7518 EndCommandBuffer();
7519 // Destroy image invalidates the cmd buffer, causing error on submit
7520 vkDestroyImage(m_device->device(), image, NULL);
7521 // Attempt to submit cmd buffer
7522 submit_info = {};
7523 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
7524 submit_info.commandBufferCount = 1;
7525 submit_info.pCommandBuffers = &m_commandBuffer->handle();
7526 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
7527 m_errorMonitor->VerifyFound();
7528 // Now update descriptor to be valid, but then free descriptor
7529 img_info.imageView = view2;
7530 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007531 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " that is invalid because bound descriptor set ");
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06007532 BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007533 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
7534 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
7535 &descriptorSet, 0, NULL);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06007536 Draw(1, 0, 0, 0);
7537 EndCommandBuffer();
7538 // Destroy descriptor set invalidates the cb, causing error on submit
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007539 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Cannot call vkFreeDescriptorSets() on descriptor set 0x");
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06007540 vkFreeDescriptorSets(m_device->device(), ds_pool, 1, &descriptorSet);
Mark Mueller917f6bc2016-08-30 10:57:19 -06007541 m_errorMonitor->VerifyFound();
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06007542 // 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 // Cleanup
7550 vkFreeMemory(m_device->device(), image_memory, NULL);
7551 vkDestroySampler(m_device->device(), sampler2, NULL);
7552 vkDestroyImage(m_device->device(), image2, NULL);
7553 vkDestroyImageView(m_device->device(), view, NULL);
7554 vkDestroyImageView(m_device->device(), view2, NULL);
7555 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
7556 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
7557 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
7558}
7559
Karl Schultz6addd812016-02-02 17:17:23 -07007560TEST_F(VkLayerTest, InvalidPipeline) {
Karl Schultzbdb75952016-04-19 11:36:49 -06007561 // Attempt to bind an invalid Pipeline to a valid Command Buffer
7562 // ObjectTracker should catch this.
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06007563 // Create a valid cmd buffer
7564 // call vkCmdBindPipeline w/ false Pipeline
Mark Lobodzinski02bf89d2016-05-10 14:45:13 -06007565 uint64_t fake_pipeline_handle = 0xbaad6001;
7566 VkPipeline bad_pipeline = reinterpret_cast<VkPipeline &>(fake_pipeline_handle);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007567 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Invalid Pipeline Object 0xbaad6001");
Karl Schultzbdb75952016-04-19 11:36:49 -06007568 ASSERT_NO_FATAL_FAILURE(InitState());
7569 BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007570 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, bad_pipeline);
Karl Schultzbdb75952016-04-19 11:36:49 -06007571 m_errorMonitor->VerifyFound();
Tobin Ehlisb8b6b272016-05-02 13:26:06 -06007572 // Now issue a draw call with no pipeline bound
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007573 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 -06007574
Tobin Ehlisb8b6b272016-05-02 13:26:06 -06007575 BeginCommandBuffer();
7576 Draw(1, 0, 0, 0);
7577 m_errorMonitor->VerifyFound();
7578 // Finally same check once more but with Dispatch/Compute
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007579 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 -06007580 BeginCommandBuffer();
7581 vkCmdDispatch(m_commandBuffer->GetBufferHandle(), 0, 0, 0);
7582 m_errorMonitor->VerifyFound();
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06007583}
7584
Karl Schultz6addd812016-02-02 17:17:23 -07007585TEST_F(VkLayerTest, DescriptorSetNotUpdated) {
Tobin Ehlis5a5f5ef2016-08-17 13:56:55 -06007586 TEST_DESCRIPTION("Bind a descriptor set that hasn't been updated.");
Karl Schultz6addd812016-02-02 17:17:23 -07007587 VkResult err;
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06007588
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007589 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT, " bound but it was never updated. ");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06007590
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06007591 ASSERT_NO_FATAL_FAILURE(InitState());
Mike Stroyan713b2d72015-08-04 10:49:29 -06007592 ASSERT_NO_FATAL_FAILURE(InitViewport());
7593 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chia-I Wu1b99bb22015-10-27 19:25:11 +08007594 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007595 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
7596 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -06007597
7598 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007599 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
7600 ds_pool_ci.pNext = NULL;
7601 ds_pool_ci.maxSets = 1;
7602 ds_pool_ci.poolSizeCount = 1;
7603 ds_pool_ci.pPoolSizes = &ds_type_count;
Mike Stroyan713b2d72015-08-04 10:49:29 -06007604
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06007605 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007606 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06007607 ASSERT_VK_SUCCESS(err);
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06007608
Tony Barboureb254902015-07-15 12:50:33 -06007609 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007610 dsl_binding.binding = 0;
7611 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
7612 dsl_binding.descriptorCount = 1;
7613 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
7614 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06007615
Tony Barboureb254902015-07-15 12:50:33 -06007616 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007617 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
7618 ds_layout_ci.pNext = NULL;
7619 ds_layout_ci.bindingCount = 1;
7620 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06007621 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007622 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06007623 ASSERT_VK_SUCCESS(err);
7624
7625 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08007626 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08007627 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07007628 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06007629 alloc_info.descriptorPool = ds_pool;
7630 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007631 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06007632 ASSERT_VK_SUCCESS(err);
7633
Tony Barboureb254902015-07-15 12:50:33 -06007634 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007635 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
7636 pipeline_layout_ci.pNext = NULL;
7637 pipeline_layout_ci.setLayoutCount = 1;
7638 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06007639
7640 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007641 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06007642 ASSERT_VK_SUCCESS(err);
7643
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007644 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
Karl Schultzbdb75952016-04-19 11:36:49 -06007645 // We shouldn't need a fragment shader but add it to be able to run
Karl Schultz6addd812016-02-02 17:17:23 -07007646 // on more devices
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007647 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06007648
Tony Barbourc95e4ac2015-08-04 17:05:26 -06007649 VkPipelineObj pipe(m_device);
7650 pipe.AddShader(&vs);
Tony Barbour1c94d372015-08-06 11:21:08 -06007651 pipe.AddShader(&fs);
Mark Youngc89c6312016-03-31 16:03:20 -06007652 pipe.AddColorAttachment();
Tony Barbourc95e4ac2015-08-04 17:05:26 -06007653 pipe.CreateVKPipeline(pipeline_layout, renderPass());
Tony Barbourfe3351b2015-07-28 10:17:20 -06007654
7655 BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007656 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
7657 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
7658 &descriptorSet, 0, NULL);
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06007659
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007660 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06007661
Chia-I Wuf7458c52015-10-26 21:10:41 +08007662 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
7663 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
7664 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06007665}
7666
Karl Schultz6addd812016-02-02 17:17:23 -07007667TEST_F(VkLayerTest, InvalidBufferViewObject) {
Tobin Ehlisba31cab2015-11-02 15:24:32 -07007668 // Create a single TEXEL_BUFFER descriptor and send it an invalid bufferView
Karl Schultz6addd812016-02-02 17:17:23 -07007669 VkResult err;
Tobin Ehlisba31cab2015-11-02 15:24:32 -07007670
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007671 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Attempted write update to texel buffer "
7672 "descriptor with invalid buffer view");
Tobin Ehlisba31cab2015-11-02 15:24:32 -07007673
7674 ASSERT_NO_FATAL_FAILURE(InitState());
7675 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007676 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER;
7677 ds_type_count.descriptorCount = 1;
Tobin Ehlisba31cab2015-11-02 15:24:32 -07007678
7679 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007680 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
7681 ds_pool_ci.pNext = NULL;
7682 ds_pool_ci.maxSets = 1;
7683 ds_pool_ci.poolSizeCount = 1;
7684 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlisba31cab2015-11-02 15:24:32 -07007685
7686 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007687 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlisba31cab2015-11-02 15:24:32 -07007688 ASSERT_VK_SUCCESS(err);
7689
7690 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007691 dsl_binding.binding = 0;
7692 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER;
7693 dsl_binding.descriptorCount = 1;
7694 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
7695 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlisba31cab2015-11-02 15:24:32 -07007696
7697 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007698 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
7699 ds_layout_ci.pNext = NULL;
7700 ds_layout_ci.bindingCount = 1;
7701 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlisba31cab2015-11-02 15:24:32 -07007702 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007703 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlisba31cab2015-11-02 15:24:32 -07007704 ASSERT_VK_SUCCESS(err);
7705
7706 VkDescriptorSet descriptorSet;
7707 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08007708 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07007709 alloc_info.descriptorSetCount = 1;
Tobin Ehlisba31cab2015-11-02 15:24:32 -07007710 alloc_info.descriptorPool = ds_pool;
7711 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007712 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlisba31cab2015-11-02 15:24:32 -07007713 ASSERT_VK_SUCCESS(err);
7714
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007715 VkBufferView view = (VkBufferView)((size_t)0xbaadbeef); // invalid bufferView object
Tobin Ehlisba31cab2015-11-02 15:24:32 -07007716 VkWriteDescriptorSet descriptor_write;
7717 memset(&descriptor_write, 0, sizeof(descriptor_write));
7718 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
7719 descriptor_write.dstSet = descriptorSet;
7720 descriptor_write.dstBinding = 0;
7721 descriptor_write.descriptorCount = 1;
7722 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER;
7723 descriptor_write.pTexelBufferView = &view;
7724
7725 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
7726
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007727 m_errorMonitor->VerifyFound();
Tobin Ehlisba31cab2015-11-02 15:24:32 -07007728
7729 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
7730 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
7731}
7732
Mark Youngd339ba32016-05-30 13:28:35 -06007733TEST_F(VkLayerTest, CreateBufferViewNoMemoryBoundToBuffer) {
7734 TEST_DESCRIPTION("Attempt to create a buffer view with a buffer that has"
7735 " no memory bound to it.");
7736
7737 VkResult err;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007738 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "used without first calling vkBindBufferMemory");
Mark Youngd339ba32016-05-30 13:28:35 -06007739
7740 ASSERT_NO_FATAL_FAILURE(InitState());
7741
7742 // Create a buffer with no bound memory and then attempt to create
7743 // a buffer view.
7744 VkBufferCreateInfo buff_ci = {};
7745 buff_ci.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
Chris Forbes4538d242016-09-13 18:13:58 +12007746 buff_ci.usage = VK_BUFFER_USAGE_UNIFORM_TEXEL_BUFFER_BIT;
Mark Youngd339ba32016-05-30 13:28:35 -06007747 buff_ci.size = 256;
7748 buff_ci.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
7749 VkBuffer buffer;
7750 err = vkCreateBuffer(m_device->device(), &buff_ci, NULL, &buffer);
7751 ASSERT_VK_SUCCESS(err);
7752
7753 VkBufferViewCreateInfo buff_view_ci = {};
7754 buff_view_ci.sType = VK_STRUCTURE_TYPE_BUFFER_VIEW_CREATE_INFO;
7755 buff_view_ci.buffer = buffer;
7756 buff_view_ci.format = VK_FORMAT_R8_UNORM;
7757 buff_view_ci.range = VK_WHOLE_SIZE;
7758 VkBufferView buff_view;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007759 err = vkCreateBufferView(m_device->device(), &buff_view_ci, NULL, &buff_view);
Mark Youngd339ba32016-05-30 13:28:35 -06007760
7761 m_errorMonitor->VerifyFound();
7762 vkDestroyBuffer(m_device->device(), buffer, NULL);
7763 // If last error is success, it still created the view, so delete it.
7764 if (err == VK_SUCCESS) {
7765 vkDestroyBufferView(m_device->device(), buff_view, NULL);
7766 }
7767}
7768
Karl Schultz6addd812016-02-02 17:17:23 -07007769TEST_F(VkLayerTest, InvalidDynamicOffsetCases) {
7770 // Create a descriptorSet w/ dynamic descriptor and then hit 3 offset error
7771 // cases:
Tobin Ehlisf6585052015-12-17 11:48:42 -07007772 // 1. No dynamicOffset supplied
7773 // 2. Too many dynamicOffsets supplied
7774 // 3. Dynamic offset oversteps buffer being updated
Karl Schultz6addd812016-02-02 17:17:23 -07007775 VkResult err;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007776 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " requires 1 dynamicOffsets, but only "
7777 "0 dynamicOffsets are left in "
7778 "pDynamicOffsets ");
Tobin Ehlis49f903e2015-11-04 13:30:34 -07007779
7780 ASSERT_NO_FATAL_FAILURE(InitState());
7781 ASSERT_NO_FATAL_FAILURE(InitViewport());
7782 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
7783
7784 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007785 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
7786 ds_type_count.descriptorCount = 1;
Tobin Ehlis49f903e2015-11-04 13:30:34 -07007787
7788 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007789 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
7790 ds_pool_ci.pNext = NULL;
7791 ds_pool_ci.maxSets = 1;
7792 ds_pool_ci.poolSizeCount = 1;
7793 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlis49f903e2015-11-04 13:30:34 -07007794
7795 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007796 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis49f903e2015-11-04 13:30:34 -07007797 ASSERT_VK_SUCCESS(err);
7798
7799 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007800 dsl_binding.binding = 0;
7801 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
7802 dsl_binding.descriptorCount = 1;
7803 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
7804 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis49f903e2015-11-04 13:30:34 -07007805
7806 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007807 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
7808 ds_layout_ci.pNext = NULL;
7809 ds_layout_ci.bindingCount = 1;
7810 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlis49f903e2015-11-04 13:30:34 -07007811 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007812 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis49f903e2015-11-04 13:30:34 -07007813 ASSERT_VK_SUCCESS(err);
7814
7815 VkDescriptorSet descriptorSet;
7816 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08007817 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07007818 alloc_info.descriptorSetCount = 1;
Tobin Ehlis49f903e2015-11-04 13:30:34 -07007819 alloc_info.descriptorPool = ds_pool;
7820 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007821 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis49f903e2015-11-04 13:30:34 -07007822 ASSERT_VK_SUCCESS(err);
7823
7824 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007825 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
7826 pipeline_layout_ci.pNext = NULL;
7827 pipeline_layout_ci.setLayoutCount = 1;
7828 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlis49f903e2015-11-04 13:30:34 -07007829
7830 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007831 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis49f903e2015-11-04 13:30:34 -07007832 ASSERT_VK_SUCCESS(err);
7833
7834 // Create a buffer to update the descriptor with
7835 uint32_t qfi = 0;
7836 VkBufferCreateInfo buffCI = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007837 buffCI.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
7838 buffCI.size = 1024;
7839 buffCI.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
7840 buffCI.queueFamilyIndexCount = 1;
7841 buffCI.pQueueFamilyIndices = &qfi;
Tobin Ehlis49f903e2015-11-04 13:30:34 -07007842
7843 VkBuffer dyub;
7844 err = vkCreateBuffer(m_device->device(), &buffCI, NULL, &dyub);
7845 ASSERT_VK_SUCCESS(err);
Tobin Ehlis0a43bde2016-05-03 08:31:08 -06007846 // Allocate memory and bind to buffer so we can make it to the appropriate
7847 // error
7848 VkMemoryAllocateInfo mem_alloc = {};
7849 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
7850 mem_alloc.pNext = NULL;
7851 mem_alloc.allocationSize = 1024;
Chris Forbesb6116cc2016-05-08 11:39:59 +12007852 mem_alloc.memoryTypeIndex = 0;
7853
7854 VkMemoryRequirements memReqs;
7855 vkGetBufferMemoryRequirements(m_device->device(), dyub, &memReqs);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007856 bool pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &mem_alloc, 0);
Chris Forbesb6116cc2016-05-08 11:39:59 +12007857 if (!pass) {
7858 vkDestroyBuffer(m_device->device(), dyub, NULL);
7859 return;
7860 }
7861
Tobin Ehlis0a43bde2016-05-03 08:31:08 -06007862 VkDeviceMemory mem;
7863 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem);
7864 ASSERT_VK_SUCCESS(err);
7865 err = vkBindBufferMemory(m_device->device(), dyub, mem, 0);
7866 ASSERT_VK_SUCCESS(err);
Tobin Ehlis49f903e2015-11-04 13:30:34 -07007867 // Correctly update descriptor to avoid "NOT_UPDATED" error
7868 VkDescriptorBufferInfo buffInfo = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007869 buffInfo.buffer = dyub;
7870 buffInfo.offset = 0;
7871 buffInfo.range = 1024;
Tobin Ehlis49f903e2015-11-04 13:30:34 -07007872
7873 VkWriteDescriptorSet descriptor_write;
7874 memset(&descriptor_write, 0, sizeof(descriptor_write));
7875 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
7876 descriptor_write.dstSet = descriptorSet;
7877 descriptor_write.dstBinding = 0;
7878 descriptor_write.descriptorCount = 1;
7879 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
7880 descriptor_write.pBufferInfo = &buffInfo;
7881
7882 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
7883
7884 BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007885 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
7886 &descriptorSet, 0, NULL);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007887 m_errorMonitor->VerifyFound();
Tobin Ehlisf6585052015-12-17 11:48:42 -07007888 uint32_t pDynOff[2] = {512, 756};
7889 // Now cause error b/c too many dynOffsets in array for # of dyn descriptors
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007890 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
7891 "Attempting to bind 1 descriptorSets with 1 dynamic descriptors, but ");
7892 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
7893 &descriptorSet, 2, pDynOff);
Chris Forbes7b342802016-04-07 13:20:10 +12007894 m_errorMonitor->VerifyFound();
Tobin Ehlisf6585052015-12-17 11:48:42 -07007895 // Finally cause error due to dynamicOffset being too big
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007896 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " dynamic offset 512 combined with "
7897 "offset 0 and range 1024 that "
7898 "oversteps the buffer size of 1024");
Tobin Ehlisf6585052015-12-17 11:48:42 -07007899 // Create PSO to be used for draw-time errors below
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007900 char const *vsSource = "#version 450\n"
7901 "\n"
7902 "out gl_PerVertex { \n"
7903 " vec4 gl_Position;\n"
7904 "};\n"
7905 "void main(){\n"
7906 " gl_Position = vec4(1);\n"
7907 "}\n";
7908 char const *fsSource = "#version 450\n"
7909 "\n"
7910 "layout(location=0) out vec4 x;\n"
7911 "layout(set=0) layout(binding=0) uniform foo { int x; int y; } bar;\n"
7912 "void main(){\n"
7913 " x = vec4(bar.y);\n"
7914 "}\n";
Tobin Ehlisf6585052015-12-17 11:48:42 -07007915 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
7916 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
7917 VkPipelineObj pipe(m_device);
7918 pipe.AddShader(&vs);
7919 pipe.AddShader(&fs);
7920 pipe.AddColorAttachment();
7921 pipe.CreateVKPipeline(pipeline_layout, renderPass());
7922
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007923 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Karl Schultz6addd812016-02-02 17:17:23 -07007924 // This update should succeed, but offset size of 512 will overstep buffer
7925 // /w range 1024 & size 1024
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007926 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
7927 &descriptorSet, 1, pDynOff);
Tobin Ehlisf6585052015-12-17 11:48:42 -07007928 Draw(1, 0, 0, 0);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007929 m_errorMonitor->VerifyFound();
Tobin Ehlis49f903e2015-11-04 13:30:34 -07007930
Tobin Ehlis0a43bde2016-05-03 08:31:08 -06007931 vkDestroyBuffer(m_device->device(), dyub, NULL);
Tobin Ehlis512098e2016-05-05 09:06:12 -06007932 vkFreeMemory(m_device->device(), mem, NULL);
Tobin Ehlis0a43bde2016-05-03 08:31:08 -06007933
Tobin Ehlis49f903e2015-11-04 13:30:34 -07007934 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
Tony Barbourdf4c0042016-06-01 15:55:43 -06007935 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
Tobin Ehlis49f903e2015-11-04 13:30:34 -07007936 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
7937}
7938
Tobin Ehlis8ef479c2016-07-20 16:14:49 -06007939TEST_F(VkLayerTest, DescriptorBufferUpdateNoMemoryBound) {
7940 TEST_DESCRIPTION("Attempt to update a descriptor with a non-sparse buffer "
7941 "that doesn't have memory bound");
7942 VkResult err;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007943 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " used without first calling vkBindBufferMemory.");
Tobin Ehlis8ef479c2016-07-20 16:14:49 -06007944
7945 ASSERT_NO_FATAL_FAILURE(InitState());
7946 ASSERT_NO_FATAL_FAILURE(InitViewport());
7947 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
7948
7949 VkDescriptorPoolSize ds_type_count = {};
7950 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
7951 ds_type_count.descriptorCount = 1;
7952
7953 VkDescriptorPoolCreateInfo ds_pool_ci = {};
7954 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
7955 ds_pool_ci.pNext = NULL;
7956 ds_pool_ci.maxSets = 1;
7957 ds_pool_ci.poolSizeCount = 1;
7958 ds_pool_ci.pPoolSizes = &ds_type_count;
7959
7960 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007961 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis8ef479c2016-07-20 16:14:49 -06007962 ASSERT_VK_SUCCESS(err);
7963
7964 VkDescriptorSetLayoutBinding dsl_binding = {};
7965 dsl_binding.binding = 0;
7966 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
7967 dsl_binding.descriptorCount = 1;
7968 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
7969 dsl_binding.pImmutableSamplers = NULL;
7970
7971 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
7972 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
7973 ds_layout_ci.pNext = NULL;
7974 ds_layout_ci.bindingCount = 1;
7975 ds_layout_ci.pBindings = &dsl_binding;
7976 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007977 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis8ef479c2016-07-20 16:14:49 -06007978 ASSERT_VK_SUCCESS(err);
7979
7980 VkDescriptorSet descriptorSet;
7981 VkDescriptorSetAllocateInfo alloc_info = {};
7982 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
7983 alloc_info.descriptorSetCount = 1;
7984 alloc_info.descriptorPool = ds_pool;
7985 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007986 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis8ef479c2016-07-20 16:14:49 -06007987 ASSERT_VK_SUCCESS(err);
7988
7989 // Create a buffer to update the descriptor with
7990 uint32_t qfi = 0;
7991 VkBufferCreateInfo buffCI = {};
7992 buffCI.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
7993 buffCI.size = 1024;
7994 buffCI.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
7995 buffCI.queueFamilyIndexCount = 1;
7996 buffCI.pQueueFamilyIndices = &qfi;
7997
7998 VkBuffer dyub;
7999 err = vkCreateBuffer(m_device->device(), &buffCI, NULL, &dyub);
8000 ASSERT_VK_SUCCESS(err);
8001
8002 // Attempt to update descriptor without binding memory to it
8003 VkDescriptorBufferInfo buffInfo = {};
8004 buffInfo.buffer = dyub;
8005 buffInfo.offset = 0;
8006 buffInfo.range = 1024;
8007
8008 VkWriteDescriptorSet descriptor_write;
8009 memset(&descriptor_write, 0, sizeof(descriptor_write));
8010 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
8011 descriptor_write.dstSet = descriptorSet;
8012 descriptor_write.dstBinding = 0;
8013 descriptor_write.descriptorCount = 1;
8014 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
8015 descriptor_write.pBufferInfo = &buffInfo;
8016
8017 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
8018 m_errorMonitor->VerifyFound();
8019
8020 vkDestroyBuffer(m_device->device(), dyub, NULL);
8021 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
8022 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
8023}
8024
Tobin Ehlis3a23b6a2016-02-17 10:35:18 -07008025TEST_F(VkLayerTest, InvalidPushConstants) {
Tobin Ehlis3a23b6a2016-02-17 10:35:18 -07008026 VkResult err;
Tobin Ehlis3a23b6a2016-02-17 10:35:18 -07008027 ASSERT_NO_FATAL_FAILURE(InitState());
8028 ASSERT_NO_FATAL_FAILURE(InitViewport());
8029 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
8030
Karl Schultzfc8eaf12016-05-06 13:56:42 -06008031 VkPipelineLayout pipeline_layout;
Tobin Ehlis3a23b6a2016-02-17 10:35:18 -07008032 VkPushConstantRange pc_range = {};
Tobin Ehlis3a23b6a2016-02-17 10:35:18 -07008033 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
8034 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
8035 pipeline_layout_ci.pushConstantRangeCount = 1;
8036 pipeline_layout_ci.pPushConstantRanges = &pc_range;
8037
Karl Schultzfc8eaf12016-05-06 13:56:42 -06008038 //
8039 // Check for invalid push constant ranges in pipeline layouts.
8040 //
8041 struct PipelineLayoutTestCase {
Karl Schultzc81037d2016-05-12 08:11:23 -06008042 VkPushConstantRange const range;
Karl Schultzfc8eaf12016-05-06 13:56:42 -06008043 char const *msg;
8044 };
Tobin Ehlis3a23b6a2016-02-17 10:35:18 -07008045
Karl Schultzc81037d2016-05-12 08:11:23 -06008046 const uint32_t too_big = m_device->props.limits.maxPushConstantsSize + 0x4;
8047 const std::array<PipelineLayoutTestCase, 10> range_tests = {{
8048 {{VK_SHADER_STAGE_VERTEX_BIT, 0, 0},
8049 "vkCreatePipelineLayout() call has push constants index 0 with "
8050 "size 0."},
8051 {{VK_SHADER_STAGE_VERTEX_BIT, 0, 1},
8052 "vkCreatePipelineLayout() call has push constants index 0 with "
8053 "size 1."},
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06008054 {{VK_SHADER_STAGE_VERTEX_BIT, 4, 1},
Karl Schultzc81037d2016-05-12 08:11:23 -06008055 "vkCreatePipelineLayout() call has push constants index 0 with "
8056 "size 1."},
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06008057 {{VK_SHADER_STAGE_VERTEX_BIT, 4, 0},
Karl Schultzc81037d2016-05-12 08:11:23 -06008058 "vkCreatePipelineLayout() call has push constants index 0 with "
8059 "size 0."},
8060 {{VK_SHADER_STAGE_VERTEX_BIT, 1, 4},
8061 "vkCreatePipelineLayout() call has push constants index 0 with "
8062 "offset 1. Offset must"},
8063 {{VK_SHADER_STAGE_VERTEX_BIT, 0, too_big},
8064 "vkCreatePipelineLayout() call has push constants index 0 "
8065 "with offset "},
8066 {{VK_SHADER_STAGE_VERTEX_BIT, too_big, too_big},
8067 "vkCreatePipelineLayout() call has push constants "
8068 "index 0 with offset "},
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06008069 {{VK_SHADER_STAGE_VERTEX_BIT, too_big, 4},
Karl Schultzc81037d2016-05-12 08:11:23 -06008070 "vkCreatePipelineLayout() call has push constants index 0 "
8071 "with offset "},
8072 {{VK_SHADER_STAGE_VERTEX_BIT, 0xFFFFFFF0, 0x00000020},
8073 "vkCreatePipelineLayout() call has push "
8074 "constants index 0 with offset "},
8075 {{VK_SHADER_STAGE_VERTEX_BIT, 0x00000020, 0xFFFFFFF0},
8076 "vkCreatePipelineLayout() call has push "
8077 "constants index 0 with offset "},
Karl Schultzfc8eaf12016-05-06 13:56:42 -06008078 }};
8079
8080 // Check for invalid offset and size
Karl Schultzc81037d2016-05-12 08:11:23 -06008081 for (const auto &iter : range_tests) {
8082 pc_range = iter.range;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008083 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, iter.msg);
8084 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Karl Schultzfc8eaf12016-05-06 13:56:42 -06008085 m_errorMonitor->VerifyFound();
8086 if (VK_SUCCESS == err) {
8087 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
8088 }
8089 }
8090
8091 // Check for invalid stage flag
8092 pc_range.offset = 0;
8093 pc_range.size = 16;
8094 pc_range.stageFlags = 0;
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06008095 m_errorMonitor->SetDesiredFailureMsg(
8096 VK_DEBUG_REPORT_ERROR_BIT_EXT,
8097 "vkCreatePipelineLayout: value of pCreateInfo->pPushConstantRanges[0].stageFlags must not be 0");
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008098 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008099 m_errorMonitor->VerifyFound();
Karl Schultzfc8eaf12016-05-06 13:56:42 -06008100 if (VK_SUCCESS == err) {
8101 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
8102 }
8103
8104 // Check for overlapping ranges
Karl Schultzc81037d2016-05-12 08:11:23 -06008105 const uint32_t ranges_per_test = 5;
Karl Schultzfc8eaf12016-05-06 13:56:42 -06008106 struct OverlappingRangeTestCase {
Karl Schultzc81037d2016-05-12 08:11:23 -06008107 VkPushConstantRange const ranges[ranges_per_test];
Karl Schultzfc8eaf12016-05-06 13:56:42 -06008108 char const *msg;
8109 };
8110
Karl Schultzc81037d2016-05-12 08:11:23 -06008111 const std::array<OverlappingRangeTestCase, 5> overlapping_range_tests = {
Karl Schultzfc8eaf12016-05-06 13:56:42 -06008112 {{{{VK_SHADER_STAGE_VERTEX_BIT, 0, 4},
8113 {VK_SHADER_STAGE_VERTEX_BIT, 0, 4},
8114 {VK_SHADER_STAGE_VERTEX_BIT, 0, 4},
8115 {VK_SHADER_STAGE_VERTEX_BIT, 0, 4},
8116 {VK_SHADER_STAGE_VERTEX_BIT, 0, 4}},
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06008117 "vkCreatePipelineLayout() call has push constants with overlapping ranges:"},
Karl Schultzfc8eaf12016-05-06 13:56:42 -06008118 {
8119 {{VK_SHADER_STAGE_VERTEX_BIT, 0, 4},
8120 {VK_SHADER_STAGE_VERTEX_BIT, 4, 4},
8121 {VK_SHADER_STAGE_VERTEX_BIT, 8, 4},
8122 {VK_SHADER_STAGE_VERTEX_BIT, 12, 8},
8123 {VK_SHADER_STAGE_VERTEX_BIT, 16, 4}},
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06008124 "vkCreatePipelineLayout() call has push constants with overlapping ranges: 3:[12, 20), 4:[16, 20)",
Karl Schultzfc8eaf12016-05-06 13:56:42 -06008125 },
8126 {
8127 {{VK_SHADER_STAGE_VERTEX_BIT, 16, 4},
8128 {VK_SHADER_STAGE_VERTEX_BIT, 12, 8},
8129 {VK_SHADER_STAGE_VERTEX_BIT, 8, 4},
8130 {VK_SHADER_STAGE_VERTEX_BIT, 4, 4},
8131 {VK_SHADER_STAGE_VERTEX_BIT, 0, 4}},
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06008132 "vkCreatePipelineLayout() call has push constants with overlapping ranges: 0:[16, 20), 1:[12, 20)",
Karl Schultzfc8eaf12016-05-06 13:56:42 -06008133 },
8134 {
8135 {{VK_SHADER_STAGE_VERTEX_BIT, 16, 4},
8136 {VK_SHADER_STAGE_VERTEX_BIT, 8, 4},
8137 {VK_SHADER_STAGE_VERTEX_BIT, 4, 4},
8138 {VK_SHADER_STAGE_VERTEX_BIT, 12, 8},
8139 {VK_SHADER_STAGE_VERTEX_BIT, 0, 4}},
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06008140 "vkCreatePipelineLayout() call has push constants with overlapping ranges: 0:[16, 20), 3:[12, 20)",
Karl Schultzfc8eaf12016-05-06 13:56:42 -06008141 },
8142 {
8143 {{VK_SHADER_STAGE_VERTEX_BIT, 16, 4},
8144 {VK_SHADER_STAGE_VERTEX_BIT, 32, 4},
8145 {VK_SHADER_STAGE_VERTEX_BIT, 4, 96},
8146 {VK_SHADER_STAGE_VERTEX_BIT, 40, 8},
8147 {VK_SHADER_STAGE_VERTEX_BIT, 52, 4}},
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06008148 "vkCreatePipelineLayout() call has push constants with overlapping ranges:",
Karl Schultzfc8eaf12016-05-06 13:56:42 -06008149 }}};
Karl Schultzfc8eaf12016-05-06 13:56:42 -06008150
Karl Schultzc81037d2016-05-12 08:11:23 -06008151 for (const auto &iter : overlapping_range_tests) {
Karl Schultzfc8eaf12016-05-06 13:56:42 -06008152 pipeline_layout_ci.pPushConstantRanges = iter.ranges;
Karl Schultzc81037d2016-05-12 08:11:23 -06008153 pipeline_layout_ci.pushConstantRangeCount = ranges_per_test;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008154 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT, iter.msg);
8155 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Karl Schultzfc8eaf12016-05-06 13:56:42 -06008156 m_errorMonitor->VerifyFound();
8157 if (VK_SUCCESS == err) {
8158 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
8159 }
8160 }
8161
8162 // Run some positive tests to make sure overlap checking in the layer is OK
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008163 const std::array<OverlappingRangeTestCase, 2> overlapping_range_tests_pos = {{{{{VK_SHADER_STAGE_VERTEX_BIT, 0, 4},
8164 {VK_SHADER_STAGE_VERTEX_BIT, 4, 4},
8165 {VK_SHADER_STAGE_VERTEX_BIT, 8, 4},
8166 {VK_SHADER_STAGE_VERTEX_BIT, 12, 4},
8167 {VK_SHADER_STAGE_VERTEX_BIT, 16, 4}},
8168 ""},
8169 {{{VK_SHADER_STAGE_VERTEX_BIT, 92, 24},
8170 {VK_SHADER_STAGE_VERTEX_BIT, 80, 4},
8171 {VK_SHADER_STAGE_VERTEX_BIT, 64, 8},
8172 {VK_SHADER_STAGE_VERTEX_BIT, 4, 16},
8173 {VK_SHADER_STAGE_VERTEX_BIT, 0, 4}},
8174 ""}}};
Karl Schultzc81037d2016-05-12 08:11:23 -06008175 for (const auto &iter : overlapping_range_tests_pos) {
Karl Schultzfc8eaf12016-05-06 13:56:42 -06008176 pipeline_layout_ci.pPushConstantRanges = iter.ranges;
8177 m_errorMonitor->ExpectSuccess();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008178 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Karl Schultzfc8eaf12016-05-06 13:56:42 -06008179 m_errorMonitor->VerifyNotFound();
8180 if (VK_SUCCESS == err) {
8181 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
8182 }
8183 }
8184
8185 //
8186 // CmdPushConstants tests
8187 //
Karl Schultzc81037d2016-05-12 08:11:23 -06008188 const uint8_t dummy_values[100] = {};
Karl Schultzfc8eaf12016-05-06 13:56:42 -06008189
8190 // Check for invalid offset and size and if range is within layout range(s)
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06008191 const std::array<PipelineLayoutTestCase, 11> cmd_range_tests = {{
8192 {{VK_SHADER_STAGE_VERTEX_BIT, 0, 0}, "vkCmdPushConstants: parameter size must be greater than 0"},
Karl Schultzc81037d2016-05-12 08:11:23 -06008193 {{VK_SHADER_STAGE_VERTEX_BIT, 0, 1},
8194 "vkCmdPushConstants() call has push constants with size 1. Size "
8195 "must be greater than zero and a multiple of 4."},
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06008196 {{VK_SHADER_STAGE_VERTEX_BIT, 4, 1},
Karl Schultzc81037d2016-05-12 08:11:23 -06008197 "vkCmdPushConstants() call has push constants with size 1. Size "
8198 "must be greater than zero and a multiple of 4."},
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06008199 {{VK_SHADER_STAGE_VERTEX_BIT, 1, 4},
Karl Schultzc81037d2016-05-12 08:11:23 -06008200 "vkCmdPushConstants() call has push constants with offset 1. "
8201 "Offset must be a multiple of 4."},
8202 {{VK_SHADER_STAGE_VERTEX_BIT, 1, 4},
8203 "vkCmdPushConstants() call has push constants with offset 1. "
8204 "Offset must be a multiple of 4."},
8205 {{VK_SHADER_STAGE_VERTEX_BIT, 0, 20},
8206 "vkCmdPushConstants() Push constant range [0, 20) with stageFlags = "
8207 "0x1 not within flag-matching ranges in pipeline layout"},
8208 {{VK_SHADER_STAGE_VERTEX_BIT, 60, 8},
8209 "vkCmdPushConstants() Push constant range [60, 68) with stageFlags = "
8210 "0x1 not within flag-matching ranges in pipeline layout"},
8211 {{VK_SHADER_STAGE_VERTEX_BIT, 76, 8},
8212 "vkCmdPushConstants() Push constant range [76, 84) with stageFlags = "
8213 "0x1 not within flag-matching ranges in pipeline layout"},
8214 {{VK_SHADER_STAGE_VERTEX_BIT, 0, 80},
8215 "vkCmdPushConstants() Push constant range [0, 80) with stageFlags = "
8216 "0x1 not within flag-matching ranges in pipeline layout"},
8217 {{VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT, 0, 4},
8218 "vkCmdPushConstants() stageFlags = 0x2 do not match the stageFlags in "
8219 "any of the ranges in pipeline layout"},
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008220 {{VK_SHADER_STAGE_VERTEX_BIT | VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT, 0, 16},
Karl Schultzc81037d2016-05-12 08:11:23 -06008221 "vkCmdPushConstants() stageFlags = 0x3 do not match the stageFlags in "
8222 "any of the ranges in pipeline layout"},
Karl Schultzfc8eaf12016-05-06 13:56:42 -06008223 }};
8224
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06008225 BeginCommandBuffer();
8226
8227 // Setup ranges: [0,16) [64,80)
Karl Schultzc81037d2016-05-12 08:11:23 -06008228 const VkPushConstantRange pc_range2[] = {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008229 {VK_SHADER_STAGE_VERTEX_BIT, 64, 16}, {VK_SHADER_STAGE_VERTEX_BIT, 0, 16},
Karl Schultzfc8eaf12016-05-06 13:56:42 -06008230 };
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008231 pipeline_layout_ci.pushConstantRangeCount = sizeof(pc_range2) / sizeof(VkPushConstantRange);
Karl Schultzfc8eaf12016-05-06 13:56:42 -06008232 pipeline_layout_ci.pPushConstantRanges = pc_range2;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008233 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis3a23b6a2016-02-17 10:35:18 -07008234 ASSERT_VK_SUCCESS(err);
Karl Schultzc81037d2016-05-12 08:11:23 -06008235 for (const auto &iter : cmd_range_tests) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008236 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, iter.msg);
8237 vkCmdPushConstants(m_commandBuffer->GetBufferHandle(), pipeline_layout, iter.range.stageFlags, iter.range.offset,
Karl Schultzc81037d2016-05-12 08:11:23 -06008238 iter.range.size, dummy_values);
Karl Schultzfc8eaf12016-05-06 13:56:42 -06008239 m_errorMonitor->VerifyFound();
8240 }
8241
8242 // Check for invalid stage flag
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06008243 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "vkCmdPushConstants: value of stageFlags must not be 0");
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008244 vkCmdPushConstants(m_commandBuffer->GetBufferHandle(), pipeline_layout, 0, 0, 16, dummy_values);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008245 m_errorMonitor->VerifyFound();
Karl Schultzc81037d2016-05-12 08:11:23 -06008246 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
Karl Schultzfc8eaf12016-05-06 13:56:42 -06008247
Karl Schultzc81037d2016-05-12 08:11:23 -06008248 // overlapping range tests with cmd
8249 const std::array<PipelineLayoutTestCase, 3> cmd_overlap_tests = {{
8250 {{VK_SHADER_STAGE_VERTEX_BIT, 0, 20},
8251 "vkCmdPushConstants() Push constant range [0, 20) with stageFlags = "
8252 "0x1 not within flag-matching ranges in pipeline layout"},
8253 {{VK_SHADER_STAGE_VERTEX_BIT, 16, 4},
8254 "vkCmdPushConstants() Push constant range [16, 20) with stageFlags = "
8255 "0x1 not within flag-matching ranges in pipeline layout"},
8256 {{VK_SHADER_STAGE_VERTEX_BIT, 40, 16},
8257 "vkCmdPushConstants() Push constant range [40, 56) with stageFlags = "
8258 "0x1 not within flag-matching ranges in pipeline layout"},
8259 }};
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06008260 // Setup ranges: [0,16), [20,36), [36,44), [44,52), [80,92)
Karl Schultzc81037d2016-05-12 08:11:23 -06008261 const VkPushConstantRange pc_range3[] = {
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06008262 {VK_SHADER_STAGE_VERTEX_BIT, 20, 16}, {VK_SHADER_STAGE_VERTEX_BIT, 0, 16}, {VK_SHADER_STAGE_VERTEX_BIT, 44, 8},
8263 {VK_SHADER_STAGE_VERTEX_BIT, 80, 12}, {VK_SHADER_STAGE_VERTEX_BIT, 36, 8},
Karl Schultzc81037d2016-05-12 08:11:23 -06008264 };
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008265 pipeline_layout_ci.pushConstantRangeCount = sizeof(pc_range3) / sizeof(VkPushConstantRange);
Karl Schultzc81037d2016-05-12 08:11:23 -06008266 pipeline_layout_ci.pPushConstantRanges = pc_range3;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008267 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Karl Schultzc81037d2016-05-12 08:11:23 -06008268 ASSERT_VK_SUCCESS(err);
Karl Schultzc81037d2016-05-12 08:11:23 -06008269 for (const auto &iter : cmd_overlap_tests) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008270 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, iter.msg);
8271 vkCmdPushConstants(m_commandBuffer->GetBufferHandle(), pipeline_layout, iter.range.stageFlags, iter.range.offset,
Karl Schultzc81037d2016-05-12 08:11:23 -06008272 iter.range.size, dummy_values);
8273 m_errorMonitor->VerifyFound();
8274 }
Karl Schultzc81037d2016-05-12 08:11:23 -06008275 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
8276
8277 // positive overlapping range tests with cmd
8278 const std::array<PipelineLayoutTestCase, 4> cmd_overlap_tests_pos = {{
8279 {{VK_SHADER_STAGE_VERTEX_BIT, 0, 16}, ""},
8280 {{VK_SHADER_STAGE_VERTEX_BIT, 0, 4}, ""},
8281 {{VK_SHADER_STAGE_VERTEX_BIT, 20, 12}, ""},
8282 {{VK_SHADER_STAGE_VERTEX_BIT, 56, 36}, ""},
8283 }};
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06008284 // Setup ranges: [0,16) [20,36) [36,44) [44,52) [56,80) [80,92)
Karl Schultzc81037d2016-05-12 08:11:23 -06008285 const VkPushConstantRange pc_range4[] = {
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06008286 {VK_SHADER_STAGE_VERTEX_BIT, 20, 16}, {VK_SHADER_STAGE_VERTEX_BIT, 0, 16}, {VK_SHADER_STAGE_VERTEX_BIT, 44, 8},
8287 {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 -06008288 };
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008289 pipeline_layout_ci.pushConstantRangeCount = sizeof(pc_range4) / sizeof(VkPushConstantRange);
Karl Schultzc81037d2016-05-12 08:11:23 -06008290 pipeline_layout_ci.pPushConstantRanges = pc_range4;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008291 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Karl Schultzc81037d2016-05-12 08:11:23 -06008292 ASSERT_VK_SUCCESS(err);
Karl Schultzc81037d2016-05-12 08:11:23 -06008293 for (const auto &iter : cmd_overlap_tests_pos) {
8294 m_errorMonitor->ExpectSuccess();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008295 vkCmdPushConstants(m_commandBuffer->GetBufferHandle(), pipeline_layout, iter.range.stageFlags, iter.range.offset,
Karl Schultzc81037d2016-05-12 08:11:23 -06008296 iter.range.size, dummy_values);
8297 m_errorMonitor->VerifyNotFound();
8298 }
Tobin Ehlis3a23b6a2016-02-17 10:35:18 -07008299 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06008300
8301 EndCommandBuffer();
Tobin Ehlis3a23b6a2016-02-17 10:35:18 -07008302}
8303
Karl Schultz6addd812016-02-02 17:17:23 -07008304TEST_F(VkLayerTest, DescriptorSetCompatibility) {
Tobin Ehlis559c6382015-11-05 09:52:49 -07008305 // Test various desriptorSet errors with bad binding combinations
Karl Schultz6addd812016-02-02 17:17:23 -07008306 VkResult err;
Tobin Ehlis559c6382015-11-05 09:52:49 -07008307
8308 ASSERT_NO_FATAL_FAILURE(InitState());
8309 ASSERT_NO_FATAL_FAILURE(InitViewport());
8310 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
8311
Mike Stroyanb8a61002016-06-20 16:00:28 -06008312 const VkFormat tex_format = VK_FORMAT_R8G8B8A8_UNORM;
8313 VkImageTiling tiling;
8314 VkFormatProperties format_properties;
8315 vkGetPhysicalDeviceFormatProperties(gpu(), tex_format, &format_properties);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008316 if (format_properties.linearTilingFeatures & VK_FORMAT_FEATURE_STORAGE_IMAGE_BIT) {
Mike Stroyanb8a61002016-06-20 16:00:28 -06008317 tiling = VK_IMAGE_TILING_LINEAR;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008318 } else if (format_properties.optimalTilingFeatures & VK_FORMAT_FEATURE_STORAGE_IMAGE_BIT) {
Mike Stroyanb8a61002016-06-20 16:00:28 -06008319 tiling = VK_IMAGE_TILING_OPTIMAL;
8320 } else {
8321 printf("Device does not support VK_FORMAT_FEATURE_STORAGE_IMAGE_BIT; "
8322 "skipped.\n");
8323 return;
8324 }
8325
Tobin Ehlis559c6382015-11-05 09:52:49 -07008326 static const uint32_t NUM_DESCRIPTOR_TYPES = 5;
8327 VkDescriptorPoolSize ds_type_count[NUM_DESCRIPTOR_TYPES] = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008328 ds_type_count[0].type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
8329 ds_type_count[0].descriptorCount = 10;
8330 ds_type_count[1].type = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE;
8331 ds_type_count[1].descriptorCount = 2;
8332 ds_type_count[2].type = VK_DESCRIPTOR_TYPE_STORAGE_IMAGE;
8333 ds_type_count[2].descriptorCount = 2;
8334 ds_type_count[3].type = VK_DESCRIPTOR_TYPE_SAMPLER;
8335 ds_type_count[3].descriptorCount = 5;
8336 // TODO : LunarG ILO driver currently asserts in desc.c w/ INPUT_ATTACHMENT
8337 // type
8338 // ds_type_count[4].type = VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT;
8339 ds_type_count[4].type = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
8340 ds_type_count[4].descriptorCount = 2;
Tobin Ehlis559c6382015-11-05 09:52:49 -07008341
8342 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008343 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
8344 ds_pool_ci.pNext = NULL;
8345 ds_pool_ci.maxSets = 5;
8346 ds_pool_ci.poolSizeCount = NUM_DESCRIPTOR_TYPES;
8347 ds_pool_ci.pPoolSizes = ds_type_count;
Tobin Ehlis559c6382015-11-05 09:52:49 -07008348
8349 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008350 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis559c6382015-11-05 09:52:49 -07008351 ASSERT_VK_SUCCESS(err);
8352
8353 static const uint32_t MAX_DS_TYPES_IN_LAYOUT = 2;
8354 VkDescriptorSetLayoutBinding dsl_binding[MAX_DS_TYPES_IN_LAYOUT] = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008355 dsl_binding[0].binding = 0;
8356 dsl_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
8357 dsl_binding[0].descriptorCount = 5;
8358 dsl_binding[0].stageFlags = VK_SHADER_STAGE_ALL;
8359 dsl_binding[0].pImmutableSamplers = NULL;
Tobin Ehlis559c6382015-11-05 09:52:49 -07008360
Tobin Ehlis8fab6562015-12-01 09:57:09 -07008361 // Create layout identical to set0 layout but w/ different stageFlags
8362 VkDescriptorSetLayoutBinding dsl_fs_stage_only = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008363 dsl_fs_stage_only.binding = 0;
8364 dsl_fs_stage_only.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
8365 dsl_fs_stage_only.descriptorCount = 5;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008366 dsl_fs_stage_only.stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT; // Different stageFlags to cause error at
8367 // bind time
Karl Schultz6addd812016-02-02 17:17:23 -07008368 dsl_fs_stage_only.pImmutableSamplers = NULL;
Tobin Ehlis559c6382015-11-05 09:52:49 -07008369 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008370 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
8371 ds_layout_ci.pNext = NULL;
8372 ds_layout_ci.bindingCount = 1;
8373 ds_layout_ci.pBindings = dsl_binding;
Tobin Ehlis559c6382015-11-05 09:52:49 -07008374 static const uint32_t NUM_LAYOUTS = 4;
8375 VkDescriptorSetLayout ds_layout[NUM_LAYOUTS] = {};
Tobin Ehlis8fab6562015-12-01 09:57:09 -07008376 VkDescriptorSetLayout ds_layout_fs_only = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008377 // Create 4 unique layouts for full pipelineLayout, and 1 special fs-only
8378 // layout for error case
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008379 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout[0]);
Tobin Ehlis559c6382015-11-05 09:52:49 -07008380 ASSERT_VK_SUCCESS(err);
Jon Ashburn6e23c1f2015-12-30 18:01:16 -07008381 ds_layout_ci.pBindings = &dsl_fs_stage_only;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008382 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout_fs_only);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07008383 ASSERT_VK_SUCCESS(err);
Tobin Ehlis559c6382015-11-05 09:52:49 -07008384 dsl_binding[0].binding = 0;
8385 dsl_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE;
Tobin Ehlis8fab6562015-12-01 09:57:09 -07008386 dsl_binding[0].descriptorCount = 2;
Mike Stroyan9c70cdb2016-01-06 14:14:17 -07008387 dsl_binding[1].binding = 1;
8388 dsl_binding[1].descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_IMAGE;
8389 dsl_binding[1].descriptorCount = 2;
8390 dsl_binding[1].stageFlags = VK_SHADER_STAGE_ALL;
8391 dsl_binding[1].pImmutableSamplers = NULL;
Jon Ashburn6e23c1f2015-12-30 18:01:16 -07008392 ds_layout_ci.pBindings = dsl_binding;
Tobin Ehlis559c6382015-11-05 09:52:49 -07008393 ds_layout_ci.bindingCount = 2;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008394 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout[1]);
Tobin Ehlis559c6382015-11-05 09:52:49 -07008395 ASSERT_VK_SUCCESS(err);
8396 dsl_binding[0].binding = 0;
8397 dsl_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
Tobin Ehlis8fab6562015-12-01 09:57:09 -07008398 dsl_binding[0].descriptorCount = 5;
Tobin Ehlis559c6382015-11-05 09:52:49 -07008399 ds_layout_ci.bindingCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008400 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout[2]);
Tobin Ehlis559c6382015-11-05 09:52:49 -07008401 ASSERT_VK_SUCCESS(err);
8402 dsl_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
Tobin Ehlis8fab6562015-12-01 09:57:09 -07008403 dsl_binding[0].descriptorCount = 2;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008404 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout[3]);
Tobin Ehlis559c6382015-11-05 09:52:49 -07008405 ASSERT_VK_SUCCESS(err);
8406
8407 static const uint32_t NUM_SETS = 4;
8408 VkDescriptorSet descriptorSet[NUM_SETS] = {};
8409 VkDescriptorSetAllocateInfo alloc_info = {};
Tobin Ehlis8fab6562015-12-01 09:57:09 -07008410 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07008411 alloc_info.descriptorSetCount = NUM_LAYOUTS;
Tobin Ehlis559c6382015-11-05 09:52:49 -07008412 alloc_info.descriptorPool = ds_pool;
8413 alloc_info.pSetLayouts = ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008414 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, descriptorSet);
Tobin Ehlis559c6382015-11-05 09:52:49 -07008415 ASSERT_VK_SUCCESS(err);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07008416 VkDescriptorSet ds0_fs_only = {};
Jon Ashburnf19916e2016-01-11 13:12:43 -07008417 alloc_info.descriptorSetCount = 1;
Tobin Ehlis8fab6562015-12-01 09:57:09 -07008418 alloc_info.pSetLayouts = &ds_layout_fs_only;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008419 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &ds0_fs_only);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07008420 ASSERT_VK_SUCCESS(err);
Tobin Ehlis559c6382015-11-05 09:52:49 -07008421
8422 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008423 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
8424 pipeline_layout_ci.pNext = NULL;
8425 pipeline_layout_ci.setLayoutCount = NUM_LAYOUTS;
8426 pipeline_layout_ci.pSetLayouts = ds_layout;
Tobin Ehlis559c6382015-11-05 09:52:49 -07008427
8428 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008429 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis559c6382015-11-05 09:52:49 -07008430 ASSERT_VK_SUCCESS(err);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07008431 // Create pipelineLayout with only one setLayout
8432 pipeline_layout_ci.setLayoutCount = 1;
8433 VkPipelineLayout single_pipe_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008434 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &single_pipe_layout);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07008435 ASSERT_VK_SUCCESS(err);
8436 // Create pipelineLayout with 2 descriptor setLayout at index 0
8437 pipeline_layout_ci.pSetLayouts = &ds_layout[3];
8438 VkPipelineLayout pipe_layout_one_desc;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008439 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipe_layout_one_desc);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07008440 ASSERT_VK_SUCCESS(err);
8441 // Create pipelineLayout with 5 SAMPLER descriptor setLayout at index 0
8442 pipeline_layout_ci.pSetLayouts = &ds_layout[2];
8443 VkPipelineLayout pipe_layout_five_samp;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008444 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipe_layout_five_samp);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07008445 ASSERT_VK_SUCCESS(err);
8446 // Create pipelineLayout with UB type, but stageFlags for FS only
8447 pipeline_layout_ci.pSetLayouts = &ds_layout_fs_only;
8448 VkPipelineLayout pipe_layout_fs_only;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008449 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipe_layout_fs_only);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07008450 ASSERT_VK_SUCCESS(err);
8451 // Create pipelineLayout w/ incompatible set0 layout, but set1 is fine
8452 VkDescriptorSetLayout pl_bad_s0[2] = {};
8453 pl_bad_s0[0] = ds_layout_fs_only;
8454 pl_bad_s0[1] = ds_layout[1];
8455 pipeline_layout_ci.setLayoutCount = 2;
8456 pipeline_layout_ci.pSetLayouts = pl_bad_s0;
8457 VkPipelineLayout pipe_layout_bad_set0;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008458 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipe_layout_bad_set0);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07008459 ASSERT_VK_SUCCESS(err);
Tobin Ehlis559c6382015-11-05 09:52:49 -07008460
8461 // Create a buffer to update the descriptor with
8462 uint32_t qfi = 0;
8463 VkBufferCreateInfo buffCI = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008464 buffCI.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
8465 buffCI.size = 1024;
8466 buffCI.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
8467 buffCI.queueFamilyIndexCount = 1;
8468 buffCI.pQueueFamilyIndices = &qfi;
Tobin Ehlis559c6382015-11-05 09:52:49 -07008469
8470 VkBuffer dyub;
8471 err = vkCreateBuffer(m_device->device(), &buffCI, NULL, &dyub);
8472 ASSERT_VK_SUCCESS(err);
8473 // Correctly update descriptor to avoid "NOT_UPDATED" error
8474 static const uint32_t NUM_BUFFS = 5;
8475 VkDescriptorBufferInfo buffInfo[NUM_BUFFS] = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008476 for (uint32_t i = 0; i < NUM_BUFFS; ++i) {
Tobin Ehlis559c6382015-11-05 09:52:49 -07008477 buffInfo[i].buffer = dyub;
8478 buffInfo[i].offset = 0;
8479 buffInfo[i].range = 1024;
8480 }
Karl Schultz6addd812016-02-02 17:17:23 -07008481 VkImage image;
Karl Schultz6addd812016-02-02 17:17:23 -07008482 const int32_t tex_width = 32;
8483 const int32_t tex_height = 32;
Tobin Ehlis8fab6562015-12-01 09:57:09 -07008484 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008485 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
8486 image_create_info.pNext = NULL;
8487 image_create_info.imageType = VK_IMAGE_TYPE_2D;
8488 image_create_info.format = tex_format;
8489 image_create_info.extent.width = tex_width;
8490 image_create_info.extent.height = tex_height;
8491 image_create_info.extent.depth = 1;
8492 image_create_info.mipLevels = 1;
8493 image_create_info.arrayLayers = 1;
8494 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
Mike Stroyanb8a61002016-06-20 16:00:28 -06008495 image_create_info.tiling = tiling;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008496 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT | VK_IMAGE_USAGE_STORAGE_BIT;
Karl Schultz6addd812016-02-02 17:17:23 -07008497 image_create_info.flags = 0;
Tobin Ehlis8fab6562015-12-01 09:57:09 -07008498 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
8499 ASSERT_VK_SUCCESS(err);
Tobin Ehlis559c6382015-11-05 09:52:49 -07008500
Karl Schultz6addd812016-02-02 17:17:23 -07008501 VkMemoryRequirements memReqs;
8502 VkDeviceMemory imageMem;
8503 bool pass;
Mike Stroyan9c70cdb2016-01-06 14:14:17 -07008504 VkMemoryAllocateInfo memAlloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008505 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
8506 memAlloc.pNext = NULL;
8507 memAlloc.allocationSize = 0;
8508 memAlloc.memoryTypeIndex = 0;
Mike Stroyan9c70cdb2016-01-06 14:14:17 -07008509 vkGetImageMemoryRequirements(m_device->device(), image, &memReqs);
8510 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008511 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Mike Stroyan9c70cdb2016-01-06 14:14:17 -07008512 ASSERT_TRUE(pass);
8513 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &imageMem);
8514 ASSERT_VK_SUCCESS(err);
8515 err = vkBindImageMemory(m_device->device(), image, imageMem, 0);
8516 ASSERT_VK_SUCCESS(err);
8517
Tobin Ehlis8fab6562015-12-01 09:57:09 -07008518 VkImageViewCreateInfo image_view_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008519 image_view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
8520 image_view_create_info.image = image;
8521 image_view_create_info.viewType = VK_IMAGE_VIEW_TYPE_2D;
8522 image_view_create_info.format = tex_format;
8523 image_view_create_info.subresourceRange.layerCount = 1;
8524 image_view_create_info.subresourceRange.baseMipLevel = 0;
8525 image_view_create_info.subresourceRange.levelCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008526 image_view_create_info.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Tobin Ehlis559c6382015-11-05 09:52:49 -07008527
Tobin Ehlis8fab6562015-12-01 09:57:09 -07008528 VkImageView view;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008529 err = vkCreateImageView(m_device->device(), &image_view_create_info, NULL, &view);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07008530 ASSERT_VK_SUCCESS(err);
Tobin Ehlis991d45a2016-01-06 08:48:41 -07008531 VkDescriptorImageInfo imageInfo[4] = {};
Tobin Ehlis8fab6562015-12-01 09:57:09 -07008532 imageInfo[0].imageView = view;
8533 imageInfo[0].imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
8534 imageInfo[1].imageView = view;
8535 imageInfo[1].imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
Tobin Ehlis991d45a2016-01-06 08:48:41 -07008536 imageInfo[2].imageView = view;
8537 imageInfo[2].imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
8538 imageInfo[3].imageView = view;
8539 imageInfo[3].imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
Tobin Ehlis8fab6562015-12-01 09:57:09 -07008540
8541 static const uint32_t NUM_SET_UPDATES = 3;
8542 VkWriteDescriptorSet descriptor_write[NUM_SET_UPDATES] = {};
8543 descriptor_write[0].sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
8544 descriptor_write[0].dstSet = descriptorSet[0];
8545 descriptor_write[0].dstBinding = 0;
8546 descriptor_write[0].descriptorCount = 5;
8547 descriptor_write[0].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
8548 descriptor_write[0].pBufferInfo = buffInfo;
8549 descriptor_write[1].sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
8550 descriptor_write[1].dstSet = descriptorSet[1];
8551 descriptor_write[1].dstBinding = 0;
8552 descriptor_write[1].descriptorCount = 2;
8553 descriptor_write[1].descriptorType = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE;
8554 descriptor_write[1].pImageInfo = imageInfo;
8555 descriptor_write[2].sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
8556 descriptor_write[2].dstSet = descriptorSet[1];
8557 descriptor_write[2].dstBinding = 1;
8558 descriptor_write[2].descriptorCount = 2;
8559 descriptor_write[2].descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_IMAGE;
Tobin Ehlis991d45a2016-01-06 08:48:41 -07008560 descriptor_write[2].pImageInfo = &imageInfo[2];
Tobin Ehlis8fab6562015-12-01 09:57:09 -07008561
8562 vkUpdateDescriptorSets(m_device->device(), 3, descriptor_write, 0, NULL);
Tobin Ehlis559c6382015-11-05 09:52:49 -07008563
Tobin Ehlis88452832015-12-03 09:40:56 -07008564 // Create PSO to be used for draw-time errors below
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008565 char const *vsSource = "#version 450\n"
8566 "\n"
8567 "out gl_PerVertex {\n"
8568 " vec4 gl_Position;\n"
8569 "};\n"
8570 "void main(){\n"
8571 " gl_Position = vec4(1);\n"
8572 "}\n";
8573 char const *fsSource = "#version 450\n"
8574 "\n"
8575 "layout(location=0) out vec4 x;\n"
8576 "layout(set=0) layout(binding=0) uniform foo { int x; int y; } bar;\n"
8577 "void main(){\n"
8578 " x = vec4(bar.y);\n"
8579 "}\n";
Tobin Ehlis88452832015-12-03 09:40:56 -07008580 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
8581 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Tobin Ehlis559c6382015-11-05 09:52:49 -07008582 VkPipelineObj pipe(m_device);
8583 pipe.AddShader(&vs);
8584 pipe.AddShader(&fs);
Tobin Ehlis88452832015-12-03 09:40:56 -07008585 pipe.AddColorAttachment();
8586 pipe.CreateVKPipeline(pipe_layout_fs_only, renderPass());
Tobin Ehlis559c6382015-11-05 09:52:49 -07008587
8588 BeginCommandBuffer();
Tobin Ehlis88452832015-12-03 09:40:56 -07008589
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008590 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Karl Schultz6addd812016-02-02 17:17:23 -07008591 // NOTE : I believe LunarG ilo driver has bug (LX#189) that requires binding
8592 // of PSO
8593 // here before binding DSs. Otherwise we assert in cmd_copy_dset_data() of
8594 // cmd_pipeline.c
8595 // due to the fact that cmd_alloc_dset_data() has not been called in
8596 // cmd_bind_graphics_pipeline()
8597 // TODO : Want to cause various binding incompatibility issues here to test
8598 // DrawState
Tobin Ehlis559c6382015-11-05 09:52:49 -07008599 // First cause various verify_layout_compatibility() fails
8600 // Second disturb early and late sets and verify INFO msgs
Tobin Ehlis8fab6562015-12-01 09:57:09 -07008601 // verify_set_layout_compatibility fail cases:
8602 // 1. invalid VkPipelineLayout (layout) passed into vkCmdBindDescriptorSets
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008603 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Invalid Pipeline Layout Object ");
8604 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS,
8605 (VkPipelineLayout)((size_t)0xbaadb1be), 0, 1, &descriptorSet[0], 0, NULL);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008606 m_errorMonitor->VerifyFound();
8607
Tobin Ehlis8fab6562015-12-01 09:57:09 -07008608 // 2. layoutIndex exceeds # of layouts in layout
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008609 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " attempting to bind set to index 1");
8610 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, single_pipe_layout, 0, 2,
8611 &descriptorSet[0], 0, NULL);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008612 m_errorMonitor->VerifyFound();
8613
Tobin Ehlis8fab6562015-12-01 09:57:09 -07008614 vkDestroyPipelineLayout(m_device->device(), single_pipe_layout, NULL);
Karl Schultz6addd812016-02-02 17:17:23 -07008615 // 3. Pipeline setLayout[0] has 2 descriptors, but set being bound has 5
8616 // descriptors
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008617 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " has 2 descriptors, but DescriptorSetLayout ");
8618 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe_layout_one_desc, 0, 1,
8619 &descriptorSet[0], 0, NULL);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008620 m_errorMonitor->VerifyFound();
8621
Tobin Ehlis8fab6562015-12-01 09:57:09 -07008622 vkDestroyPipelineLayout(m_device->device(), pipe_layout_one_desc, NULL);
8623 // 4. same # of descriptors but mismatch in type
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008624 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " is type 'VK_DESCRIPTOR_TYPE_SAMPLER' but binding ");
8625 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe_layout_five_samp, 0, 1,
8626 &descriptorSet[0], 0, NULL);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008627 m_errorMonitor->VerifyFound();
8628
Tobin Ehlis8fab6562015-12-01 09:57:09 -07008629 vkDestroyPipelineLayout(m_device->device(), pipe_layout_five_samp, NULL);
8630 // 5. same # of descriptors but mismatch in stageFlags
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008631 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
8632 " has stageFlags 16 but binding 0 for DescriptorSetLayout ");
8633 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe_layout_fs_only, 0, 1,
8634 &descriptorSet[0], 0, NULL);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008635 m_errorMonitor->VerifyFound();
8636
Tobin Ehlis8fab6562015-12-01 09:57:09 -07008637 // Cause INFO messages due to disturbing previously bound Sets
8638 // First bind sets 0 & 1
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008639 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 2,
8640 &descriptorSet[0], 0, NULL);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07008641 // 1. Disturb bound set0 by re-binding set1 w/ updated pipelineLayout
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008642 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT, " previously bound as set #0 was disturbed ");
8643 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe_layout_bad_set0, 1, 1,
8644 &descriptorSet[1], 0, NULL);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008645 m_errorMonitor->VerifyFound();
8646
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008647 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 2,
8648 &descriptorSet[0], 0, NULL);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07008649 // 2. Disturb set after last bound set
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008650 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT, " newly bound as set #0 so set #1 and "
8651 "any subsequent sets were disturbed ");
8652 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe_layout_fs_only, 0, 1,
8653 &ds0_fs_only, 0, NULL);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008654 m_errorMonitor->VerifyFound();
8655
Tobin Ehlis10fad692016-07-07 12:00:36 -06008656 // Now that we're done actively using the pipelineLayout that gfx pipeline
8657 // was created with, we should be able to delete it. Do that now to verify
8658 // that validation obeys pipelineLayout lifetime
8659 vkDestroyPipelineLayout(m_device->device(), pipe_layout_fs_only, NULL);
8660
Tobin Ehlis88452832015-12-03 09:40:56 -07008661 // Cause draw-time errors due to PSO incompatibilities
Karl Schultz6addd812016-02-02 17:17:23 -07008662 // 1. Error due to not binding required set (we actually use same code as
8663 // above to disturb set0)
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008664 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 2,
8665 &descriptorSet[0], 0, NULL);
8666 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe_layout_bad_set0, 1, 1,
8667 &descriptorSet[1], 0, NULL);
8668 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 -07008669 Draw(1, 0, 0, 0);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008670 m_errorMonitor->VerifyFound();
8671
Tobin Ehlis991d45a2016-01-06 08:48:41 -07008672 vkDestroyPipelineLayout(m_device->device(), pipe_layout_bad_set0, NULL);
Karl Schultz6addd812016-02-02 17:17:23 -07008673 // 2. Error due to bound set not being compatible with PSO's
8674 // VkPipelineLayout (diff stageFlags in this case)
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008675 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 2,
8676 &descriptorSet[0], 0, NULL);
8677 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " bound as set #0 is not compatible with ");
Tobin Ehlis88452832015-12-03 09:40:56 -07008678 Draw(1, 0, 0, 0);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008679 m_errorMonitor->VerifyFound();
8680
Tobin Ehlis8fab6562015-12-01 09:57:09 -07008681 // Remaining clean-up
Karl Schultz6addd812016-02-02 17:17:23 -07008682 for (uint32_t i = 0; i < NUM_LAYOUTS; ++i) {
Tobin Ehlis8fab6562015-12-01 09:57:09 -07008683 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout[i], NULL);
8684 }
8685 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout_fs_only, NULL);
Tobin Ehlis9bfd4492016-05-05 15:09:11 -06008686 vkFreeDescriptorSets(m_device->device(), ds_pool, 1, &ds0_fs_only);
8687 vkFreeDescriptorSets(m_device->device(), ds_pool, NUM_SETS, descriptorSet);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07008688 vkDestroyBuffer(m_device->device(), dyub, NULL);
Tobin Ehlis559c6382015-11-05 09:52:49 -07008689 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
8690 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tony Barbourdf4c0042016-06-01 15:55:43 -06008691 vkFreeMemory(m_device->device(), imageMem, NULL);
8692 vkDestroyImage(m_device->device(), image, NULL);
8693 vkDestroyImageView(m_device->device(), view, NULL);
Tobin Ehlis559c6382015-11-05 09:52:49 -07008694}
Tobin Ehlis559c6382015-11-05 09:52:49 -07008695
Karl Schultz6addd812016-02-02 17:17:23 -07008696TEST_F(VkLayerTest, NoBeginCommandBuffer) {
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06008697
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008698 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
8699 "You must call vkBeginCommandBuffer() before this call to ");
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06008700
8701 ASSERT_NO_FATAL_FAILURE(InitState());
Chia-I Wu3432a0c2015-10-27 18:04:07 +08008702 VkCommandBufferObj commandBuffer(m_device, m_commandPool);
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06008703 // Call EndCommandBuffer() w/o calling BeginCommandBuffer()
Chia-I Wu3432a0c2015-10-27 18:04:07 +08008704 vkEndCommandBuffer(commandBuffer.GetBufferHandle());
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06008705
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008706 m_errorMonitor->VerifyFound();
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06008707}
8708
Karl Schultz6addd812016-02-02 17:17:23 -07008709TEST_F(VkLayerTest, SecondaryCommandBufferNullRenderpass) {
8710 VkResult err;
8711 VkCommandBuffer draw_cmd;
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06008712
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008713 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " must specify a valid renderpass parameter.");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06008714
Mark Lobodzinskid9139a62015-08-04 16:24:20 -06008715 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinskid9139a62015-08-04 16:24:20 -06008716
Chia-I Wu3432a0c2015-10-27 18:04:07 +08008717 VkCommandBufferAllocateInfo cmd = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08008718 cmd.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
Cody Northropb4569702015-08-04 17:35:57 -06008719 cmd.pNext = NULL;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08008720 cmd.commandPool = m_commandPool;
8721 cmd.level = VK_COMMAND_BUFFER_LEVEL_SECONDARY;
Jon Ashburnf19916e2016-01-11 13:12:43 -07008722 cmd.commandBufferCount = 1;
Cody Northropb4569702015-08-04 17:35:57 -06008723
Chia-I Wu3432a0c2015-10-27 18:04:07 +08008724 err = vkAllocateCommandBuffers(m_device->device(), &cmd, &draw_cmd);
Mike Stroyand1c84a52015-08-18 14:40:24 -06008725 ASSERT_VK_SUCCESS(err);
Mark Lobodzinskid9139a62015-08-04 16:24:20 -06008726
8727 // Force the failure by not setting the Renderpass and Framebuffer fields
Chia-I Wu3432a0c2015-10-27 18:04:07 +08008728 VkCommandBufferBeginInfo cmd_buf_info = {};
Jon Ashburnf19916e2016-01-11 13:12:43 -07008729 VkCommandBufferInheritanceInfo cmd_buf_hinfo = {};
Chia-I Wu3432a0c2015-10-27 18:04:07 +08008730 cmd_buf_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
Cody Northropb4569702015-08-04 17:35:57 -06008731 cmd_buf_info.pNext = NULL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008732 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 -07008733 cmd_buf_info.pInheritanceInfo = &cmd_buf_hinfo;
Mark Lobodzinskid9139a62015-08-04 16:24:20 -06008734
8735 // The error should be caught by validation of the BeginCommandBuffer call
8736 vkBeginCommandBuffer(draw_cmd, &cmd_buf_info);
8737
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008738 m_errorMonitor->VerifyFound();
Chia-I Wu3432a0c2015-10-27 18:04:07 +08008739 vkFreeCommandBuffers(m_device->device(), m_commandPool, 1, &draw_cmd);
Mark Lobodzinskid9139a62015-08-04 16:24:20 -06008740}
8741
Karl Schultz6addd812016-02-02 17:17:23 -07008742TEST_F(VkLayerTest, CommandBufferResetErrors) {
Tobin Ehlisac0ef842015-12-14 13:46:38 -07008743 // Cause error due to Begin while recording CB
8744 // Then cause 2 errors for attempting to reset CB w/o having
8745 // VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT set for the pool from
8746 // which CBs were allocated. Note that this bit is off by default.
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008747 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Cannot call Begin on CB");
Tobin Ehlisac0ef842015-12-14 13:46:38 -07008748
8749 ASSERT_NO_FATAL_FAILURE(InitState());
8750
8751 // Calls AllocateCommandBuffers
8752 VkCommandBufferObj commandBuffer(m_device, m_commandPool);
8753
Karl Schultz6addd812016-02-02 17:17:23 -07008754 // Force the failure by setting the Renderpass and Framebuffer fields with
8755 // (fake) data
Tobin Ehlisac0ef842015-12-14 13:46:38 -07008756 VkCommandBufferBeginInfo cmd_buf_info = {};
Jon Ashburnf19916e2016-01-11 13:12:43 -07008757 VkCommandBufferInheritanceInfo cmd_buf_hinfo = {};
Tobin Ehlisac0ef842015-12-14 13:46:38 -07008758 cmd_buf_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
8759 cmd_buf_info.pNext = NULL;
8760 cmd_buf_info.flags = VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT;
Jon Ashburnf19916e2016-01-11 13:12:43 -07008761 cmd_buf_info.pInheritanceInfo = &cmd_buf_hinfo;
Tobin Ehlisac0ef842015-12-14 13:46:38 -07008762
8763 // Begin CB to transition to recording state
8764 vkBeginCommandBuffer(commandBuffer.GetBufferHandle(), &cmd_buf_info);
8765 // Can't re-begin. This should trigger error
8766 vkBeginCommandBuffer(commandBuffer.GetBufferHandle(), &cmd_buf_info);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008767 m_errorMonitor->VerifyFound();
8768
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008769 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Attempt to reset command buffer ");
Tobin Ehlisac0ef842015-12-14 13:46:38 -07008770 VkCommandBufferResetFlags flags = 0; // Don't care about flags for this test
8771 // Reset attempt will trigger error due to incorrect CommandPool state
8772 vkResetCommandBuffer(commandBuffer.GetBufferHandle(), flags);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008773 m_errorMonitor->VerifyFound();
8774
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008775 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " attempts to implicitly reset cmdBuffer created from ");
Tobin Ehlisac0ef842015-12-14 13:46:38 -07008776 // Transition CB to RECORDED state
8777 vkEndCommandBuffer(commandBuffer.GetBufferHandle());
8778 // Now attempting to Begin will implicitly reset, which triggers error
8779 vkBeginCommandBuffer(commandBuffer.GetBufferHandle(), &cmd_buf_info);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008780 m_errorMonitor->VerifyFound();
Tobin Ehlisac0ef842015-12-14 13:46:38 -07008781}
8782
Karl Schultz6addd812016-02-02 17:17:23 -07008783TEST_F(VkLayerTest, InvalidPipelineCreateState) {
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06008784 // Attempt to Create Gfx Pipeline w/o a VS
Karl Schultz6addd812016-02-02 17:17:23 -07008785 VkResult err;
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06008786
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008787 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Invalid Pipeline CreateInfo State: Vtx Shader required");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06008788
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06008789 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06008790 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Mark Lobodzinski209b5292015-09-17 09:44:05 -06008791
Chia-I Wu1b99bb22015-10-27 19:25:11 +08008792 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008793 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
8794 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -06008795
8796 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008797 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
8798 ds_pool_ci.pNext = NULL;
8799 ds_pool_ci.maxSets = 1;
8800 ds_pool_ci.poolSizeCount = 1;
8801 ds_pool_ci.pPoolSizes = &ds_type_count;
Mark Lobodzinski209b5292015-09-17 09:44:05 -06008802
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06008803 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008804 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06008805 ASSERT_VK_SUCCESS(err);
8806
Tony Barboureb254902015-07-15 12:50:33 -06008807 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008808 dsl_binding.binding = 0;
8809 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
8810 dsl_binding.descriptorCount = 1;
8811 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
8812 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06008813
Tony Barboureb254902015-07-15 12:50:33 -06008814 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008815 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
8816 ds_layout_ci.pNext = NULL;
8817 ds_layout_ci.bindingCount = 1;
8818 ds_layout_ci.pBindings = &dsl_binding;
Tony Barboureb254902015-07-15 12:50:33 -06008819
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06008820 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008821 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06008822 ASSERT_VK_SUCCESS(err);
8823
8824 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08008825 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08008826 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07008827 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06008828 alloc_info.descriptorPool = ds_pool;
8829 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008830 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06008831 ASSERT_VK_SUCCESS(err);
8832
Tony Barboureb254902015-07-15 12:50:33 -06008833 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008834 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
8835 pipeline_layout_ci.setLayoutCount = 1;
8836 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06008837
8838 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008839 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06008840 ASSERT_VK_SUCCESS(err);
8841
Tobin Ehlise68360f2015-10-01 11:15:13 -06008842 VkViewport vp = {}; // Just need dummy vp to point to
Karl Schultz6addd812016-02-02 17:17:23 -07008843 VkRect2D sc = {}; // dummy scissor to point to
Tobin Ehlise68360f2015-10-01 11:15:13 -06008844
8845 VkPipelineViewportStateCreateInfo vp_state_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008846 vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
8847 vp_state_ci.scissorCount = 1;
8848 vp_state_ci.pScissors = &sc;
8849 vp_state_ci.viewportCount = 1;
8850 vp_state_ci.pViewports = &vp;
Tobin Ehlise68360f2015-10-01 11:15:13 -06008851
Karl Schultzdfdb8d42016-03-08 10:30:21 -07008852 VkPipelineRasterizationStateCreateInfo rs_state_ci = {};
8853 rs_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
8854 rs_state_ci.polygonMode = VK_POLYGON_MODE_FILL;
8855 rs_state_ci.cullMode = VK_CULL_MODE_BACK_BIT;
8856 rs_state_ci.frontFace = VK_FRONT_FACE_COUNTER_CLOCKWISE;
8857 rs_state_ci.depthClampEnable = VK_FALSE;
8858 rs_state_ci.rasterizerDiscardEnable = VK_FALSE;
8859 rs_state_ci.depthBiasEnable = VK_FALSE;
8860
Tony Barboureb254902015-07-15 12:50:33 -06008861 VkGraphicsPipelineCreateInfo gp_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008862 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
8863 gp_ci.pViewportState = &vp_state_ci;
Karl Schultzdfdb8d42016-03-08 10:30:21 -07008864 gp_ci.pRasterizationState = &rs_state_ci;
Karl Schultz6addd812016-02-02 17:17:23 -07008865 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
8866 gp_ci.layout = pipeline_layout;
8867 gp_ci.renderPass = renderPass();
Tony Barboureb254902015-07-15 12:50:33 -06008868
8869 VkPipelineCacheCreateInfo pc_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008870 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
8871 pc_ci.initialDataSize = 0;
8872 pc_ci.pInitialData = 0;
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06008873
8874 VkPipeline pipeline;
Jon Ashburnc669cc62015-07-09 15:02:25 -06008875 VkPipelineCache pipelineCache;
8876
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008877 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Jon Ashburnc669cc62015-07-09 15:02:25 -06008878 ASSERT_VK_SUCCESS(err);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008879 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06008880
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008881 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06008882
Chia-I Wuf7458c52015-10-26 21:10:41 +08008883 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
8884 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
8885 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
8886 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06008887}
Tobin Ehlis912df022015-09-17 08:46:18 -06008888/*// TODO : This test should be good, but needs Tess support in compiler to run
8889TEST_F(VkLayerTest, InvalidPatchControlPoints)
8890{
8891 // Attempt to Create Gfx Pipeline w/o a VS
Tobin Ehlis912df022015-09-17 08:46:18 -06008892 VkResult err;
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06008893
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07008894 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Karl Schultz6addd812016-02-02 17:17:23 -07008895 "Invalid Pipeline CreateInfo State: VK_PRIMITIVE_TOPOLOGY_PATCH
8896primitive ");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06008897
Tobin Ehlis912df022015-09-17 08:46:18 -06008898 ASSERT_NO_FATAL_FAILURE(InitState());
8899 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlis912df022015-09-17 08:46:18 -06008900
Chia-I Wu1b99bb22015-10-27 19:25:11 +08008901 VkDescriptorPoolSize ds_type_count = {};
Tobin Ehlis912df022015-09-17 08:46:18 -06008902 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Chia-I Wud50a7d72015-10-26 20:48:51 +08008903 ds_type_count.descriptorCount = 1;
Tobin Ehlis912df022015-09-17 08:46:18 -06008904
8905 VkDescriptorPoolCreateInfo ds_pool_ci = {};
8906 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
8907 ds_pool_ci.pNext = NULL;
Chia-I Wu1b99bb22015-10-27 19:25:11 +08008908 ds_pool_ci.poolSizeCount = 1;
8909 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlis912df022015-09-17 08:46:18 -06008910
8911 VkDescriptorPool ds_pool;
Karl Schultz6addd812016-02-02 17:17:23 -07008912 err = vkCreateDescriptorPool(m_device->device(),
8913VK_DESCRIPTOR_POOL_USAGE_NON_FREE, 1, &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis912df022015-09-17 08:46:18 -06008914 ASSERT_VK_SUCCESS(err);
8915
8916 VkDescriptorSetLayoutBinding dsl_binding = {};
Chia-I Wud46e6ae2015-10-31 00:31:16 +08008917 dsl_binding.binding = 0;
Tobin Ehlis912df022015-09-17 08:46:18 -06008918 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Chia-I Wu02124482015-11-06 06:42:02 +08008919 dsl_binding.descriptorCount = 1;
Tobin Ehlis912df022015-09-17 08:46:18 -06008920 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
8921 dsl_binding.pImmutableSamplers = NULL;
8922
8923 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008924 ds_layout_ci.sType =
8925VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
Tobin Ehlis912df022015-09-17 08:46:18 -06008926 ds_layout_ci.pNext = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08008927 ds_layout_ci.bindingCount = 1;
Jon Ashburn6e23c1f2015-12-30 18:01:16 -07008928 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlis912df022015-09-17 08:46:18 -06008929
8930 VkDescriptorSetLayout ds_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07008931 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL,
8932&ds_layout);
Tobin Ehlis912df022015-09-17 08:46:18 -06008933 ASSERT_VK_SUCCESS(err);
8934
8935 VkDescriptorSet descriptorSet;
Karl Schultz6addd812016-02-02 17:17:23 -07008936 err = vkAllocateDescriptorSets(m_device->device(), ds_pool,
8937VK_DESCRIPTOR_SET_USAGE_NON_FREE, 1, &ds_layout, &descriptorSet);
Tobin Ehlis912df022015-09-17 08:46:18 -06008938 ASSERT_VK_SUCCESS(err);
8939
8940 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008941 pipeline_layout_ci.sType =
8942VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
Tobin Ehlis912df022015-09-17 08:46:18 -06008943 pipeline_layout_ci.pNext = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08008944 pipeline_layout_ci.setLayoutCount = 1;
Tobin Ehlis912df022015-09-17 08:46:18 -06008945 pipeline_layout_ci.pSetLayouts = &ds_layout;
8946
8947 VkPipelineLayout pipeline_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07008948 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL,
8949&pipeline_layout);
Tobin Ehlis912df022015-09-17 08:46:18 -06008950 ASSERT_VK_SUCCESS(err);
8951
8952 VkPipelineShaderStageCreateInfo shaderStages[3];
8953 memset(&shaderStages, 0, 3 * sizeof(VkPipelineShaderStageCreateInfo));
8954
Karl Schultz6addd812016-02-02 17:17:23 -07008955 VkShaderObj vs(m_device,bindStateVertShaderText,VK_SHADER_STAGE_VERTEX_BIT,
8956this);
Tobin Ehlis912df022015-09-17 08:46:18 -06008957 // Just using VS txt for Tess shaders as we don't care about functionality
Karl Schultz6addd812016-02-02 17:17:23 -07008958 VkShaderObj
8959tc(m_device,bindStateVertShaderText,VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT,
8960this);
8961 VkShaderObj
8962te(m_device,bindStateVertShaderText,VK_SHADER_STAGE_TESSELLATION_EVALUATION_BIT,
8963this);
Tobin Ehlis912df022015-09-17 08:46:18 -06008964
Karl Schultz6addd812016-02-02 17:17:23 -07008965 shaderStages[0].sType =
8966VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO;
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -06008967 shaderStages[0].stage = VK_SHADER_STAGE_VERTEX_BIT;
Tobin Ehlis912df022015-09-17 08:46:18 -06008968 shaderStages[0].shader = vs.handle();
Karl Schultz6addd812016-02-02 17:17:23 -07008969 shaderStages[1].sType =
8970VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO;
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -06008971 shaderStages[1].stage = VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT;
Tobin Ehlis912df022015-09-17 08:46:18 -06008972 shaderStages[1].shader = tc.handle();
Karl Schultz6addd812016-02-02 17:17:23 -07008973 shaderStages[2].sType =
8974VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO;
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -06008975 shaderStages[2].stage = VK_SHADER_STAGE_TESSELLATION_EVALUATION_BIT;
Tobin Ehlis912df022015-09-17 08:46:18 -06008976 shaderStages[2].shader = te.handle();
8977
8978 VkPipelineInputAssemblyStateCreateInfo iaCI = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008979 iaCI.sType =
8980VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
Chia-I Wu515eb8f2015-10-31 00:31:16 +08008981 iaCI.topology = VK_PRIMITIVE_TOPOLOGY_PATCH_LIST;
Tobin Ehlis912df022015-09-17 08:46:18 -06008982
8983 VkPipelineTessellationStateCreateInfo tsCI = {};
8984 tsCI.sType = VK_STRUCTURE_TYPE_PIPELINE_TESSELLATION_STATE_CREATE_INFO;
8985 tsCI.patchControlPoints = 0; // This will cause an error
8986
8987 VkGraphicsPipelineCreateInfo gp_ci = {};
8988 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
8989 gp_ci.pNext = NULL;
8990 gp_ci.stageCount = 3;
8991 gp_ci.pStages = shaderStages;
8992 gp_ci.pVertexInputState = NULL;
8993 gp_ci.pInputAssemblyState = &iaCI;
8994 gp_ci.pTessellationState = &tsCI;
8995 gp_ci.pViewportState = NULL;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08008996 gp_ci.pRasterizationState = NULL;
Tobin Ehlis912df022015-09-17 08:46:18 -06008997 gp_ci.pMultisampleState = NULL;
8998 gp_ci.pDepthStencilState = NULL;
8999 gp_ci.pColorBlendState = NULL;
9000 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
9001 gp_ci.layout = pipeline_layout;
9002 gp_ci.renderPass = renderPass();
9003
9004 VkPipelineCacheCreateInfo pc_ci = {};
9005 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
9006 pc_ci.pNext = NULL;
9007 pc_ci.initialSize = 0;
9008 pc_ci.initialData = 0;
9009 pc_ci.maxSize = 0;
9010
9011 VkPipeline pipeline;
9012 VkPipelineCache pipelineCache;
9013
Karl Schultz6addd812016-02-02 17:17:23 -07009014 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL,
9015&pipelineCache);
Tobin Ehlis912df022015-09-17 08:46:18 -06009016 ASSERT_VK_SUCCESS(err);
Karl Schultz6addd812016-02-02 17:17:23 -07009017 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1,
9018&gp_ci, NULL, &pipeline);
Tobin Ehlis912df022015-09-17 08:46:18 -06009019
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009020 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06009021
Chia-I Wuf7458c52015-10-26 21:10:41 +08009022 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
9023 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
9024 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
9025 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis912df022015-09-17 08:46:18 -06009026}
9027*/
Tobin Ehlise68360f2015-10-01 11:15:13 -06009028// Set scissor and viewport counts to different numbers
Karl Schultz6addd812016-02-02 17:17:23 -07009029TEST_F(VkLayerTest, PSOViewportScissorCountMismatch) {
Karl Schultz6addd812016-02-02 17:17:23 -07009030 VkResult err;
Tobin Ehlise68360f2015-10-01 11:15:13 -06009031
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009032 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
9033 "Gfx Pipeline viewport count (1) must match scissor count (0).");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06009034
Tobin Ehlise68360f2015-10-01 11:15:13 -06009035 ASSERT_NO_FATAL_FAILURE(InitState());
9036 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlise68360f2015-10-01 11:15:13 -06009037
Chia-I Wu1b99bb22015-10-27 19:25:11 +08009038 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009039 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
9040 ds_type_count.descriptorCount = 1;
Tobin Ehlise68360f2015-10-01 11:15:13 -06009041
9042 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009043 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
9044 ds_pool_ci.maxSets = 1;
9045 ds_pool_ci.poolSizeCount = 1;
9046 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlise68360f2015-10-01 11:15:13 -06009047
9048 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009049 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlise68360f2015-10-01 11:15:13 -06009050 ASSERT_VK_SUCCESS(err);
9051
9052 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009053 dsl_binding.binding = 0;
9054 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
9055 dsl_binding.descriptorCount = 1;
9056 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
Tobin Ehlise68360f2015-10-01 11:15:13 -06009057
9058 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009059 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
9060 ds_layout_ci.bindingCount = 1;
9061 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlise68360f2015-10-01 11:15:13 -06009062
9063 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009064 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlise68360f2015-10-01 11:15:13 -06009065 ASSERT_VK_SUCCESS(err);
9066
9067 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009068 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08009069 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07009070 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06009071 alloc_info.descriptorPool = ds_pool;
9072 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009073 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlise68360f2015-10-01 11:15:13 -06009074 ASSERT_VK_SUCCESS(err);
9075
9076 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009077 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
9078 pipeline_layout_ci.setLayoutCount = 1;
9079 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlise68360f2015-10-01 11:15:13 -06009080
9081 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009082 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlise68360f2015-10-01 11:15:13 -06009083 ASSERT_VK_SUCCESS(err);
9084
9085 VkViewport vp = {}; // Just need dummy vp to point to
9086
9087 VkPipelineViewportStateCreateInfo vp_state_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009088 vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
9089 vp_state_ci.scissorCount = 0;
9090 vp_state_ci.viewportCount = 1; // Count mismatch should cause error
9091 vp_state_ci.pViewports = &vp;
Tobin Ehlise68360f2015-10-01 11:15:13 -06009092
Karl Schultzdfdb8d42016-03-08 10:30:21 -07009093 VkPipelineRasterizationStateCreateInfo rs_state_ci = {};
9094 rs_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
9095 rs_state_ci.polygonMode = VK_POLYGON_MODE_FILL;
9096 rs_state_ci.cullMode = VK_CULL_MODE_BACK_BIT;
9097 rs_state_ci.frontFace = VK_FRONT_FACE_COUNTER_CLOCKWISE;
9098 rs_state_ci.depthClampEnable = VK_FALSE;
9099 rs_state_ci.rasterizerDiscardEnable = VK_FALSE;
9100 rs_state_ci.depthBiasEnable = VK_FALSE;
9101
Cody Northropeb3a6c12015-10-05 14:44:45 -06009102 VkPipelineShaderStageCreateInfo shaderStages[2];
Karl Schultz6addd812016-02-02 17:17:23 -07009103 memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo));
Tobin Ehlise68360f2015-10-01 11:15:13 -06009104
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009105 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
9106 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this); // We shouldn't need a fragment shader
9107 // but add it to be able to run on more devices
Chia-I Wu28e06912015-10-31 00:31:16 +08009108 shaderStages[0] = vs.GetStageCreateInfo();
9109 shaderStages[1] = fs.GetStageCreateInfo();
Tobin Ehlise68360f2015-10-01 11:15:13 -06009110
9111 VkGraphicsPipelineCreateInfo gp_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009112 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
9113 gp_ci.stageCount = 2;
9114 gp_ci.pStages = shaderStages;
9115 gp_ci.pViewportState = &vp_state_ci;
Karl Schultzdfdb8d42016-03-08 10:30:21 -07009116 gp_ci.pRasterizationState = &rs_state_ci;
Karl Schultz6addd812016-02-02 17:17:23 -07009117 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
9118 gp_ci.layout = pipeline_layout;
9119 gp_ci.renderPass = renderPass();
Tobin Ehlise68360f2015-10-01 11:15:13 -06009120
9121 VkPipelineCacheCreateInfo pc_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009122 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
Tobin Ehlise68360f2015-10-01 11:15:13 -06009123
9124 VkPipeline pipeline;
9125 VkPipelineCache pipelineCache;
9126
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009127 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Tobin Ehlise68360f2015-10-01 11:15:13 -06009128 ASSERT_VK_SUCCESS(err);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009129 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Tobin Ehlise68360f2015-10-01 11:15:13 -06009130
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009131 m_errorMonitor->VerifyFound();
Tobin Ehlise68360f2015-10-01 11:15:13 -06009132
Chia-I Wuf7458c52015-10-26 21:10:41 +08009133 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
9134 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
9135 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
9136 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlise68360f2015-10-01 11:15:13 -06009137}
Karl Schultz6addd812016-02-02 17:17:23 -07009138// Don't set viewport state in PSO. This is an error b/c we always need this
9139// state
Tobin Ehlisd332f282015-10-02 11:00:56 -06009140// for the counts even if the data is going to be set dynamically.
Karl Schultz6addd812016-02-02 17:17:23 -07009141TEST_F(VkLayerTest, PSOViewportStateNotSet) {
Tobin Ehlise68360f2015-10-01 11:15:13 -06009142 // Attempt to Create Gfx Pipeline w/o a VS
Karl Schultz6addd812016-02-02 17:17:23 -07009143 VkResult err;
Tobin Ehlise68360f2015-10-01 11:15:13 -06009144
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009145 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Gfx Pipeline pViewportState is null. Even if ");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06009146
Tobin Ehlise68360f2015-10-01 11:15:13 -06009147 ASSERT_NO_FATAL_FAILURE(InitState());
9148 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlise68360f2015-10-01 11:15:13 -06009149
Chia-I Wu1b99bb22015-10-27 19:25:11 +08009150 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009151 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
9152 ds_type_count.descriptorCount = 1;
Tobin Ehlise68360f2015-10-01 11:15:13 -06009153
9154 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009155 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
9156 ds_pool_ci.maxSets = 1;
9157 ds_pool_ci.poolSizeCount = 1;
9158 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlise68360f2015-10-01 11:15:13 -06009159
9160 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009161 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlise68360f2015-10-01 11:15:13 -06009162 ASSERT_VK_SUCCESS(err);
9163
9164 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009165 dsl_binding.binding = 0;
9166 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
9167 dsl_binding.descriptorCount = 1;
9168 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
Tobin Ehlise68360f2015-10-01 11:15:13 -06009169
9170 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009171 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
9172 ds_layout_ci.bindingCount = 1;
9173 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlise68360f2015-10-01 11:15:13 -06009174
9175 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009176 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlise68360f2015-10-01 11:15:13 -06009177 ASSERT_VK_SUCCESS(err);
9178
9179 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009180 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08009181 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07009182 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06009183 alloc_info.descriptorPool = ds_pool;
9184 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009185 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlise68360f2015-10-01 11:15:13 -06009186 ASSERT_VK_SUCCESS(err);
9187
9188 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009189 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
9190 pipeline_layout_ci.setLayoutCount = 1;
9191 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlise68360f2015-10-01 11:15:13 -06009192
9193 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009194 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlise68360f2015-10-01 11:15:13 -06009195 ASSERT_VK_SUCCESS(err);
9196
9197 VkDynamicState sc_state = VK_DYNAMIC_STATE_SCISSOR;
9198 // Set scissor as dynamic to avoid second error
9199 VkPipelineDynamicStateCreateInfo dyn_state_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009200 dyn_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_DYNAMIC_STATE_CREATE_INFO;
9201 dyn_state_ci.dynamicStateCount = 1;
9202 dyn_state_ci.pDynamicStates = &sc_state;
Tobin Ehlise68360f2015-10-01 11:15:13 -06009203
Cody Northropeb3a6c12015-10-05 14:44:45 -06009204 VkPipelineShaderStageCreateInfo shaderStages[2];
Karl Schultz6addd812016-02-02 17:17:23 -07009205 memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo));
Tobin Ehlise68360f2015-10-01 11:15:13 -06009206
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009207 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
9208 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this); // We shouldn't need a fragment shader
9209 // but add it to be able to run on more devices
Chia-I Wu28e06912015-10-31 00:31:16 +08009210 shaderStages[0] = vs.GetStageCreateInfo();
9211 shaderStages[1] = fs.GetStageCreateInfo();
Tobin Ehlise68360f2015-10-01 11:15:13 -06009212
Karl Schultzdfdb8d42016-03-08 10:30:21 -07009213 VkPipelineRasterizationStateCreateInfo rs_state_ci = {};
9214 rs_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
9215 rs_state_ci.polygonMode = VK_POLYGON_MODE_FILL;
9216 rs_state_ci.cullMode = VK_CULL_MODE_BACK_BIT;
9217 rs_state_ci.frontFace = VK_FRONT_FACE_COUNTER_CLOCKWISE;
9218 rs_state_ci.depthClampEnable = VK_FALSE;
9219 rs_state_ci.rasterizerDiscardEnable = VK_FALSE;
9220 rs_state_ci.depthBiasEnable = VK_FALSE;
9221
Tobin Ehlise68360f2015-10-01 11:15:13 -06009222 VkGraphicsPipelineCreateInfo gp_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009223 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
9224 gp_ci.stageCount = 2;
9225 gp_ci.pStages = shaderStages;
Karl Schultzdfdb8d42016-03-08 10:30:21 -07009226 gp_ci.pRasterizationState = &rs_state_ci;
Karl Schultz6addd812016-02-02 17:17:23 -07009227 gp_ci.pViewportState = NULL; // Not setting VP state w/o dynamic vp state
9228 // should cause validation error
9229 gp_ci.pDynamicState = &dyn_state_ci;
9230 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
9231 gp_ci.layout = pipeline_layout;
9232 gp_ci.renderPass = renderPass();
Tobin Ehlise68360f2015-10-01 11:15:13 -06009233
9234 VkPipelineCacheCreateInfo pc_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009235 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
Tobin Ehlise68360f2015-10-01 11:15:13 -06009236
9237 VkPipeline pipeline;
9238 VkPipelineCache pipelineCache;
9239
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009240 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Tobin Ehlise68360f2015-10-01 11:15:13 -06009241 ASSERT_VK_SUCCESS(err);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009242 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Tobin Ehlise68360f2015-10-01 11:15:13 -06009243
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009244 m_errorMonitor->VerifyFound();
Tobin Ehlise68360f2015-10-01 11:15:13 -06009245
Chia-I Wuf7458c52015-10-26 21:10:41 +08009246 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
9247 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
9248 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
9249 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlise68360f2015-10-01 11:15:13 -06009250}
9251// Create PSO w/o non-zero viewportCount but no viewport data
Karl Schultz6addd812016-02-02 17:17:23 -07009252// Then run second test where dynamic scissor count doesn't match PSO scissor
9253// count
9254TEST_F(VkLayerTest, PSOViewportCountWithoutDataAndDynScissorMismatch) {
9255 VkResult err;
Tobin Ehlise68360f2015-10-01 11:15:13 -06009256
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009257 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
9258 "Gfx Pipeline viewportCount is 1, but pViewports is NULL. ");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06009259
Tobin Ehlise68360f2015-10-01 11:15:13 -06009260 ASSERT_NO_FATAL_FAILURE(InitState());
Chris Forbesc08a6ca2016-07-28 14:14:07 +12009261
9262 if (!m_device->phy().features().multiViewport) {
9263 printf("Device does not support multiple viewports/scissors; skipped.\n");
9264 return;
9265 }
9266
Tobin Ehlise68360f2015-10-01 11:15:13 -06009267 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlise68360f2015-10-01 11:15:13 -06009268
Chia-I Wu1b99bb22015-10-27 19:25:11 +08009269 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009270 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
9271 ds_type_count.descriptorCount = 1;
Tobin Ehlise68360f2015-10-01 11:15:13 -06009272
9273 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009274 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
9275 ds_pool_ci.maxSets = 1;
9276 ds_pool_ci.poolSizeCount = 1;
9277 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlise68360f2015-10-01 11:15:13 -06009278
9279 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009280 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlise68360f2015-10-01 11:15:13 -06009281 ASSERT_VK_SUCCESS(err);
9282
9283 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009284 dsl_binding.binding = 0;
9285 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
9286 dsl_binding.descriptorCount = 1;
9287 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
Tobin Ehlise68360f2015-10-01 11:15:13 -06009288
9289 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009290 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
9291 ds_layout_ci.bindingCount = 1;
9292 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlise68360f2015-10-01 11:15:13 -06009293
9294 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009295 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlise68360f2015-10-01 11:15:13 -06009296 ASSERT_VK_SUCCESS(err);
9297
9298 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009299 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08009300 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07009301 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06009302 alloc_info.descriptorPool = ds_pool;
9303 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009304 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlise68360f2015-10-01 11:15:13 -06009305 ASSERT_VK_SUCCESS(err);
9306
9307 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009308 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
9309 pipeline_layout_ci.setLayoutCount = 1;
9310 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlise68360f2015-10-01 11:15:13 -06009311
9312 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009313 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlise68360f2015-10-01 11:15:13 -06009314 ASSERT_VK_SUCCESS(err);
9315
9316 VkPipelineViewportStateCreateInfo vp_state_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009317 vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
9318 vp_state_ci.viewportCount = 1;
9319 vp_state_ci.pViewports = NULL; // Null vp w/ count of 1 should cause error
9320 vp_state_ci.scissorCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009321 vp_state_ci.pScissors = NULL; // Scissor is dynamic (below) so this won't cause error
Tobin Ehlise68360f2015-10-01 11:15:13 -06009322
9323 VkDynamicState sc_state = VK_DYNAMIC_STATE_SCISSOR;
9324 // Set scissor as dynamic to avoid that error
9325 VkPipelineDynamicStateCreateInfo dyn_state_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009326 dyn_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_DYNAMIC_STATE_CREATE_INFO;
9327 dyn_state_ci.dynamicStateCount = 1;
9328 dyn_state_ci.pDynamicStates = &sc_state;
Tobin Ehlise68360f2015-10-01 11:15:13 -06009329
Cody Northropeb3a6c12015-10-05 14:44:45 -06009330 VkPipelineShaderStageCreateInfo shaderStages[2];
Karl Schultz6addd812016-02-02 17:17:23 -07009331 memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo));
Tobin Ehlise68360f2015-10-01 11:15:13 -06009332
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009333 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
9334 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this); // We shouldn't need a fragment shader
9335 // but add it to be able to run on more devices
Chia-I Wu28e06912015-10-31 00:31:16 +08009336 shaderStages[0] = vs.GetStageCreateInfo();
9337 shaderStages[1] = fs.GetStageCreateInfo();
Tobin Ehlise68360f2015-10-01 11:15:13 -06009338
Cody Northropf6622dc2015-10-06 10:33:21 -06009339 VkPipelineVertexInputStateCreateInfo vi_ci = {};
9340 vi_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
9341 vi_ci.pNext = nullptr;
Chia-I Wud50a7d72015-10-26 20:48:51 +08009342 vi_ci.vertexBindingDescriptionCount = 0;
Cody Northropf6622dc2015-10-06 10:33:21 -06009343 vi_ci.pVertexBindingDescriptions = nullptr;
Chia-I Wud50a7d72015-10-26 20:48:51 +08009344 vi_ci.vertexAttributeDescriptionCount = 0;
Cody Northropf6622dc2015-10-06 10:33:21 -06009345 vi_ci.pVertexAttributeDescriptions = nullptr;
9346
9347 VkPipelineInputAssemblyStateCreateInfo ia_ci = {};
9348 ia_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
9349 ia_ci.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP;
9350
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009351 VkPipelineRasterizationStateCreateInfo rs_ci = {};
Chia-I Wu1b99bb22015-10-27 19:25:11 +08009352 rs_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
Cody Northropf6622dc2015-10-06 10:33:21 -06009353 rs_ci.pNext = nullptr;
9354
Mark Youngc89c6312016-03-31 16:03:20 -06009355 VkPipelineColorBlendAttachmentState att = {};
9356 att.blendEnable = VK_FALSE;
9357 att.colorWriteMask = 0xf;
9358
Cody Northropf6622dc2015-10-06 10:33:21 -06009359 VkPipelineColorBlendStateCreateInfo cb_ci = {};
9360 cb_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO;
9361 cb_ci.pNext = nullptr;
Mark Youngc89c6312016-03-31 16:03:20 -06009362 cb_ci.attachmentCount = 1;
9363 cb_ci.pAttachments = &att;
Cody Northropf6622dc2015-10-06 10:33:21 -06009364
Tobin Ehlise68360f2015-10-01 11:15:13 -06009365 VkGraphicsPipelineCreateInfo gp_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009366 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
9367 gp_ci.stageCount = 2;
9368 gp_ci.pStages = shaderStages;
9369 gp_ci.pVertexInputState = &vi_ci;
9370 gp_ci.pInputAssemblyState = &ia_ci;
9371 gp_ci.pViewportState = &vp_state_ci;
9372 gp_ci.pRasterizationState = &rs_ci;
9373 gp_ci.pColorBlendState = &cb_ci;
9374 gp_ci.pDynamicState = &dyn_state_ci;
9375 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
9376 gp_ci.layout = pipeline_layout;
9377 gp_ci.renderPass = renderPass();
Tobin Ehlise68360f2015-10-01 11:15:13 -06009378
9379 VkPipelineCacheCreateInfo pc_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009380 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
Tobin Ehlise68360f2015-10-01 11:15:13 -06009381
9382 VkPipeline pipeline;
9383 VkPipelineCache pipelineCache;
9384
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009385 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Tobin Ehlise68360f2015-10-01 11:15:13 -06009386 ASSERT_VK_SUCCESS(err);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009387 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Tobin Ehlise68360f2015-10-01 11:15:13 -06009388
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009389 m_errorMonitor->VerifyFound();
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06009390
Tobin Ehlisd332f282015-10-02 11:00:56 -06009391 // Now hit second fail case where we set scissor w/ different count than PSO
Karl Schultz6addd812016-02-02 17:17:23 -07009392 // First need to successfully create the PSO from above by setting
9393 // pViewports
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009394 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Dynamic scissor(s) 0 are used by PSO, ");
Karl Schultz6addd812016-02-02 17:17:23 -07009395
9396 VkViewport vp = {}; // Just need dummy vp to point to
9397 vp_state_ci.pViewports = &vp;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009398 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Karl Schultz6addd812016-02-02 17:17:23 -07009399 ASSERT_VK_SUCCESS(err);
9400 BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009401 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline);
Chris Forbesc08a6ca2016-07-28 14:14:07 +12009402 VkRect2D scissors[1] = {}; // don't care about data
Karl Schultz6addd812016-02-02 17:17:23 -07009403 // Count of 2 doesn't match PSO count of 1
Chris Forbesc08a6ca2016-07-28 14:14:07 +12009404 vkCmdSetScissor(m_commandBuffer->GetBufferHandle(), 1, 1, scissors);
Karl Schultz6addd812016-02-02 17:17:23 -07009405 Draw(1, 0, 0, 0);
9406
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009407 m_errorMonitor->VerifyFound();
Karl Schultz6addd812016-02-02 17:17:23 -07009408
9409 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
9410 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
9411 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
9412 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tony Barbourdf4c0042016-06-01 15:55:43 -06009413 vkDestroyPipeline(m_device->device(), pipeline, NULL);
Karl Schultz6addd812016-02-02 17:17:23 -07009414}
9415// Create PSO w/o non-zero scissorCount but no scissor data
9416// Then run second test where dynamic viewportCount doesn't match PSO
9417// viewportCount
9418TEST_F(VkLayerTest, PSOScissorCountWithoutDataAndDynViewportMismatch) {
9419 VkResult err;
9420
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009421 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 -07009422
9423 ASSERT_NO_FATAL_FAILURE(InitState());
Chris Forbesc08a6ca2016-07-28 14:14:07 +12009424
9425 if (!m_device->phy().features().multiViewport) {
9426 printf("Device does not support multiple viewports/scissors; skipped.\n");
9427 return;
9428 }
9429
Karl Schultz6addd812016-02-02 17:17:23 -07009430 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
9431
9432 VkDescriptorPoolSize ds_type_count = {};
9433 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
9434 ds_type_count.descriptorCount = 1;
9435
9436 VkDescriptorPoolCreateInfo ds_pool_ci = {};
9437 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
9438 ds_pool_ci.maxSets = 1;
9439 ds_pool_ci.poolSizeCount = 1;
9440 ds_pool_ci.pPoolSizes = &ds_type_count;
9441
9442 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009443 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Karl Schultz6addd812016-02-02 17:17:23 -07009444 ASSERT_VK_SUCCESS(err);
9445
9446 VkDescriptorSetLayoutBinding dsl_binding = {};
9447 dsl_binding.binding = 0;
9448 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
9449 dsl_binding.descriptorCount = 1;
9450 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
9451
9452 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
9453 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
9454 ds_layout_ci.bindingCount = 1;
9455 ds_layout_ci.pBindings = &dsl_binding;
9456
9457 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009458 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Karl Schultz6addd812016-02-02 17:17:23 -07009459 ASSERT_VK_SUCCESS(err);
9460
9461 VkDescriptorSet descriptorSet;
9462 VkDescriptorSetAllocateInfo alloc_info = {};
9463 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
9464 alloc_info.descriptorSetCount = 1;
9465 alloc_info.descriptorPool = ds_pool;
9466 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009467 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Karl Schultz6addd812016-02-02 17:17:23 -07009468 ASSERT_VK_SUCCESS(err);
9469
9470 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
9471 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
9472 pipeline_layout_ci.setLayoutCount = 1;
9473 pipeline_layout_ci.pSetLayouts = &ds_layout;
9474
9475 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009476 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Karl Schultz6addd812016-02-02 17:17:23 -07009477 ASSERT_VK_SUCCESS(err);
9478
9479 VkPipelineViewportStateCreateInfo vp_state_ci = {};
9480 vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
9481 vp_state_ci.scissorCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009482 vp_state_ci.pScissors = NULL; // Null scissor w/ count of 1 should cause error
Karl Schultz6addd812016-02-02 17:17:23 -07009483 vp_state_ci.viewportCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009484 vp_state_ci.pViewports = NULL; // vp is dynamic (below) so this won't cause error
Karl Schultz6addd812016-02-02 17:17:23 -07009485
9486 VkDynamicState vp_state = VK_DYNAMIC_STATE_VIEWPORT;
9487 // Set scissor as dynamic to avoid that error
9488 VkPipelineDynamicStateCreateInfo dyn_state_ci = {};
9489 dyn_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_DYNAMIC_STATE_CREATE_INFO;
9490 dyn_state_ci.dynamicStateCount = 1;
9491 dyn_state_ci.pDynamicStates = &vp_state;
9492
9493 VkPipelineShaderStageCreateInfo shaderStages[2];
9494 memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo));
9495
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009496 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
9497 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this); // We shouldn't need a fragment shader
9498 // but add it to be able to run on more devices
Karl Schultz6addd812016-02-02 17:17:23 -07009499 shaderStages[0] = vs.GetStageCreateInfo();
9500 shaderStages[1] = fs.GetStageCreateInfo();
9501
9502 VkPipelineVertexInputStateCreateInfo vi_ci = {};
9503 vi_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
9504 vi_ci.pNext = nullptr;
9505 vi_ci.vertexBindingDescriptionCount = 0;
9506 vi_ci.pVertexBindingDescriptions = nullptr;
9507 vi_ci.vertexAttributeDescriptionCount = 0;
9508 vi_ci.pVertexAttributeDescriptions = nullptr;
9509
9510 VkPipelineInputAssemblyStateCreateInfo ia_ci = {};
9511 ia_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
9512 ia_ci.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP;
9513
9514 VkPipelineRasterizationStateCreateInfo rs_ci = {};
9515 rs_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
9516 rs_ci.pNext = nullptr;
9517
Mark Youngc89c6312016-03-31 16:03:20 -06009518 VkPipelineColorBlendAttachmentState att = {};
9519 att.blendEnable = VK_FALSE;
9520 att.colorWriteMask = 0xf;
9521
Karl Schultz6addd812016-02-02 17:17:23 -07009522 VkPipelineColorBlendStateCreateInfo cb_ci = {};
9523 cb_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO;
9524 cb_ci.pNext = nullptr;
Mark Youngc89c6312016-03-31 16:03:20 -06009525 cb_ci.attachmentCount = 1;
9526 cb_ci.pAttachments = &att;
Karl Schultz6addd812016-02-02 17:17:23 -07009527
9528 VkGraphicsPipelineCreateInfo gp_ci = {};
9529 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
9530 gp_ci.stageCount = 2;
9531 gp_ci.pStages = shaderStages;
9532 gp_ci.pVertexInputState = &vi_ci;
9533 gp_ci.pInputAssemblyState = &ia_ci;
9534 gp_ci.pViewportState = &vp_state_ci;
9535 gp_ci.pRasterizationState = &rs_ci;
9536 gp_ci.pColorBlendState = &cb_ci;
9537 gp_ci.pDynamicState = &dyn_state_ci;
9538 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
9539 gp_ci.layout = pipeline_layout;
9540 gp_ci.renderPass = renderPass();
9541
9542 VkPipelineCacheCreateInfo pc_ci = {};
9543 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
9544
9545 VkPipeline pipeline;
9546 VkPipelineCache pipelineCache;
9547
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009548 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Karl Schultz6addd812016-02-02 17:17:23 -07009549 ASSERT_VK_SUCCESS(err);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009550 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Karl Schultz6addd812016-02-02 17:17:23 -07009551
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009552 m_errorMonitor->VerifyFound();
Karl Schultz6addd812016-02-02 17:17:23 -07009553
9554 // Now hit second fail case where we set scissor w/ different count than PSO
9555 // First need to successfully create the PSO from above by setting
9556 // pViewports
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009557 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Dynamic viewport(s) 0 are used by PSO, ");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06009558
Tobin Ehlisd332f282015-10-02 11:00:56 -06009559 VkRect2D sc = {}; // Just need dummy vp to point to
9560 vp_state_ci.pScissors = &sc;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009561 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Tobin Ehlisd332f282015-10-02 11:00:56 -06009562 ASSERT_VK_SUCCESS(err);
9563 BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009564 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline);
Chris Forbesc08a6ca2016-07-28 14:14:07 +12009565 VkViewport viewports[1] = {}; // don't care about data
Tobin Ehlisd332f282015-10-02 11:00:56 -06009566 // Count of 2 doesn't match PSO count of 1
Chris Forbesc08a6ca2016-07-28 14:14:07 +12009567 vkCmdSetViewport(m_commandBuffer->GetBufferHandle(), 1, 1, viewports);
Tobin Ehlisd332f282015-10-02 11:00:56 -06009568 Draw(1, 0, 0, 0);
9569
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009570 m_errorMonitor->VerifyFound();
Tobin Ehlise68360f2015-10-01 11:15:13 -06009571
Chia-I Wuf7458c52015-10-26 21:10:41 +08009572 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
9573 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
9574 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
9575 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tony Barbourdf4c0042016-06-01 15:55:43 -06009576 vkDestroyPipeline(m_device->device(), pipeline, NULL);
Tobin Ehlise68360f2015-10-01 11:15:13 -06009577}
9578
Mark Young7394fdd2016-03-31 14:56:43 -06009579TEST_F(VkLayerTest, PSOLineWidthInvalid) {
9580 VkResult err;
9581
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009582 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Attempt to set lineWidth to -1");
Mark Young7394fdd2016-03-31 14:56:43 -06009583
9584 ASSERT_NO_FATAL_FAILURE(InitState());
9585 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
9586
9587 VkDescriptorPoolSize ds_type_count = {};
9588 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
9589 ds_type_count.descriptorCount = 1;
9590
9591 VkDescriptorPoolCreateInfo ds_pool_ci = {};
9592 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
9593 ds_pool_ci.maxSets = 1;
9594 ds_pool_ci.poolSizeCount = 1;
9595 ds_pool_ci.pPoolSizes = &ds_type_count;
9596
9597 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009598 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Mark Young7394fdd2016-03-31 14:56:43 -06009599 ASSERT_VK_SUCCESS(err);
9600
9601 VkDescriptorSetLayoutBinding dsl_binding = {};
9602 dsl_binding.binding = 0;
9603 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
9604 dsl_binding.descriptorCount = 1;
9605 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
9606
9607 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
9608 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
9609 ds_layout_ci.bindingCount = 1;
9610 ds_layout_ci.pBindings = &dsl_binding;
9611
9612 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009613 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Mark Young7394fdd2016-03-31 14:56:43 -06009614 ASSERT_VK_SUCCESS(err);
9615
9616 VkDescriptorSet descriptorSet;
9617 VkDescriptorSetAllocateInfo alloc_info = {};
9618 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
9619 alloc_info.descriptorSetCount = 1;
9620 alloc_info.descriptorPool = ds_pool;
9621 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009622 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Mark Young7394fdd2016-03-31 14:56:43 -06009623 ASSERT_VK_SUCCESS(err);
9624
9625 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
9626 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
9627 pipeline_layout_ci.setLayoutCount = 1;
9628 pipeline_layout_ci.pSetLayouts = &ds_layout;
9629
9630 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009631 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Mark Young7394fdd2016-03-31 14:56:43 -06009632 ASSERT_VK_SUCCESS(err);
9633
9634 VkPipelineViewportStateCreateInfo vp_state_ci = {};
9635 vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
9636 vp_state_ci.scissorCount = 1;
9637 vp_state_ci.pScissors = NULL;
9638 vp_state_ci.viewportCount = 1;
9639 vp_state_ci.pViewports = NULL;
9640
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009641 VkDynamicState dynamic_states[3] = {VK_DYNAMIC_STATE_VIEWPORT, VK_DYNAMIC_STATE_SCISSOR, VK_DYNAMIC_STATE_LINE_WIDTH};
Mark Young7394fdd2016-03-31 14:56:43 -06009642 // Set scissor as dynamic to avoid that error
9643 VkPipelineDynamicStateCreateInfo dyn_state_ci = {};
9644 dyn_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_DYNAMIC_STATE_CREATE_INFO;
9645 dyn_state_ci.dynamicStateCount = 2;
9646 dyn_state_ci.pDynamicStates = dynamic_states;
9647
9648 VkPipelineShaderStageCreateInfo shaderStages[2];
9649 memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo));
9650
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009651 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
9652 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT,
Mark Young7394fdd2016-03-31 14:56:43 -06009653 this); // TODO - We shouldn't need a fragment shader
9654 // but add it to be able to run on more devices
9655 shaderStages[0] = vs.GetStageCreateInfo();
9656 shaderStages[1] = fs.GetStageCreateInfo();
9657
9658 VkPipelineVertexInputStateCreateInfo vi_ci = {};
9659 vi_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
9660 vi_ci.pNext = nullptr;
9661 vi_ci.vertexBindingDescriptionCount = 0;
9662 vi_ci.pVertexBindingDescriptions = nullptr;
9663 vi_ci.vertexAttributeDescriptionCount = 0;
9664 vi_ci.pVertexAttributeDescriptions = nullptr;
9665
9666 VkPipelineInputAssemblyStateCreateInfo ia_ci = {};
9667 ia_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
9668 ia_ci.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP;
9669
9670 VkPipelineRasterizationStateCreateInfo rs_ci = {};
9671 rs_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
9672 rs_ci.pNext = nullptr;
9673
Mark Young47107952016-05-02 15:59:55 -06009674 // Check too low (line width of -1.0f).
9675 rs_ci.lineWidth = -1.0f;
Mark Young7394fdd2016-03-31 14:56:43 -06009676
9677 VkPipelineColorBlendAttachmentState att = {};
9678 att.blendEnable = VK_FALSE;
9679 att.colorWriteMask = 0xf;
9680
9681 VkPipelineColorBlendStateCreateInfo cb_ci = {};
9682 cb_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO;
9683 cb_ci.pNext = nullptr;
9684 cb_ci.attachmentCount = 1;
9685 cb_ci.pAttachments = &att;
9686
9687 VkGraphicsPipelineCreateInfo gp_ci = {};
9688 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
9689 gp_ci.stageCount = 2;
9690 gp_ci.pStages = shaderStages;
9691 gp_ci.pVertexInputState = &vi_ci;
9692 gp_ci.pInputAssemblyState = &ia_ci;
9693 gp_ci.pViewportState = &vp_state_ci;
9694 gp_ci.pRasterizationState = &rs_ci;
9695 gp_ci.pColorBlendState = &cb_ci;
9696 gp_ci.pDynamicState = &dyn_state_ci;
9697 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
9698 gp_ci.layout = pipeline_layout;
9699 gp_ci.renderPass = renderPass();
9700
9701 VkPipelineCacheCreateInfo pc_ci = {};
9702 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
9703
9704 VkPipeline pipeline;
9705 VkPipelineCache pipelineCache;
9706
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009707 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Mark Young7394fdd2016-03-31 14:56:43 -06009708 ASSERT_VK_SUCCESS(err);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009709 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Mark Young7394fdd2016-03-31 14:56:43 -06009710
9711 m_errorMonitor->VerifyFound();
Tony Barbourdf4c0042016-06-01 15:55:43 -06009712 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
Mark Young7394fdd2016-03-31 14:56:43 -06009713
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009714 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Attempt to set lineWidth to 65536");
Mark Young7394fdd2016-03-31 14:56:43 -06009715
9716 // Check too high (line width of 65536.0f).
9717 rs_ci.lineWidth = 65536.0f;
9718
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009719 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Mark Young7394fdd2016-03-31 14:56:43 -06009720 ASSERT_VK_SUCCESS(err);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009721 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Mark Young7394fdd2016-03-31 14:56:43 -06009722
9723 m_errorMonitor->VerifyFound();
Tony Barbourdf4c0042016-06-01 15:55:43 -06009724 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
Mark Young7394fdd2016-03-31 14:56:43 -06009725
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009726 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Attempt to set lineWidth to -1");
Mark Young7394fdd2016-03-31 14:56:43 -06009727
9728 dyn_state_ci.dynamicStateCount = 3;
9729
9730 rs_ci.lineWidth = 1.0f;
9731
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009732 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Mark Young7394fdd2016-03-31 14:56:43 -06009733 ASSERT_VK_SUCCESS(err);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009734 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Mark Young7394fdd2016-03-31 14:56:43 -06009735 BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009736 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline);
Mark Young7394fdd2016-03-31 14:56:43 -06009737
9738 // Check too low with dynamic setting.
Mark Young47107952016-05-02 15:59:55 -06009739 vkCmdSetLineWidth(m_commandBuffer->GetBufferHandle(), -1.0f);
Mark Young7394fdd2016-03-31 14:56:43 -06009740 m_errorMonitor->VerifyFound();
9741
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009742 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Attempt to set lineWidth to 65536");
Mark Young7394fdd2016-03-31 14:56:43 -06009743
9744 // Check too high with dynamic setting.
9745 vkCmdSetLineWidth(m_commandBuffer->GetBufferHandle(), 65536.0f);
9746 m_errorMonitor->VerifyFound();
9747 EndCommandBuffer();
9748
9749 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
9750 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
9751 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
9752 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tony Barbourdf4c0042016-06-01 15:55:43 -06009753 vkDestroyPipeline(m_device->device(), pipeline, NULL);
Mark Young7394fdd2016-03-31 14:56:43 -06009754}
9755
Karl Schultz6addd812016-02-02 17:17:23 -07009756TEST_F(VkLayerTest, NullRenderPass) {
Tobin Ehlis98aa0ed2015-06-25 16:27:19 -06009757 // Bind a NULL RenderPass
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009758 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
9759 "You cannot use a NULL RenderPass object in vkCmdBeginRenderPass()");
Tobin Ehlis98aa0ed2015-06-25 16:27:19 -06009760
9761 ASSERT_NO_FATAL_FAILURE(InitState());
9762 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlis98aa0ed2015-06-25 16:27:19 -06009763
Tony Barbourfe3351b2015-07-28 10:17:20 -06009764 BeginCommandBuffer();
Karl Schultz6addd812016-02-02 17:17:23 -07009765 // Don't care about RenderPass handle b/c error should be flagged before
9766 // that
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009767 vkCmdBeginRenderPass(m_commandBuffer->GetBufferHandle(), NULL, VK_SUBPASS_CONTENTS_INLINE);
Tobin Ehlis98aa0ed2015-06-25 16:27:19 -06009768
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009769 m_errorMonitor->VerifyFound();
Tobin Ehlis98aa0ed2015-06-25 16:27:19 -06009770}
9771
Karl Schultz6addd812016-02-02 17:17:23 -07009772TEST_F(VkLayerTest, RenderPassWithinRenderPass) {
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06009773 // Bind a BeginRenderPass within an active RenderPass
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009774 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
9775 "It is invalid to issue this call inside an active render pass");
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06009776
9777 ASSERT_NO_FATAL_FAILURE(InitState());
9778 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06009779
Tony Barbourfe3351b2015-07-28 10:17:20 -06009780 BeginCommandBuffer();
Karl Schultz6addd812016-02-02 17:17:23 -07009781 // Just create a dummy Renderpass that's non-NULL so we can get to the
9782 // proper error
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009783 vkCmdBeginRenderPass(m_commandBuffer->GetBufferHandle(), &m_renderPassBeginInfo, VK_SUBPASS_CONTENTS_INLINE);
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06009784
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009785 m_errorMonitor->VerifyFound();
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06009786}
9787
Chris Forbes2eeabe32016-06-21 20:52:34 +12009788TEST_F(VkLayerTest, RenderPassSecondaryCommandBuffersMultipleTimes) {
9789 m_errorMonitor->ExpectSuccess();
9790
9791 ASSERT_NO_FATAL_FAILURE(InitState());
9792 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
9793
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009794 BeginCommandBuffer(); // framework implicitly begins the renderpass.
Chris Forbes2eeabe32016-06-21 20:52:34 +12009795 vkCmdEndRenderPass(m_commandBuffer->GetBufferHandle()); // end implicit.
9796
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009797 vkCmdBeginRenderPass(m_commandBuffer->GetBufferHandle(), &m_renderPassBeginInfo, VK_SUBPASS_CONTENTS_SECONDARY_COMMAND_BUFFERS);
Chris Forbes2eeabe32016-06-21 20:52:34 +12009798 vkCmdEndRenderPass(m_commandBuffer->GetBufferHandle());
9799 m_errorMonitor->VerifyNotFound();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009800 vkCmdBeginRenderPass(m_commandBuffer->GetBufferHandle(), &m_renderPassBeginInfo, VK_SUBPASS_CONTENTS_INLINE);
Chris Forbes2eeabe32016-06-21 20:52:34 +12009801 m_errorMonitor->VerifyNotFound();
9802 vkCmdEndRenderPass(m_commandBuffer->GetBufferHandle());
9803 m_errorMonitor->VerifyNotFound();
9804
9805 m_commandBuffer->EndCommandBuffer();
9806 m_errorMonitor->VerifyNotFound();
9807}
9808
Tobin Ehlis5a1c0332016-05-31 13:59:26 -06009809TEST_F(VkLayerTest, RenderPassClearOpMismatch) {
9810 TEST_DESCRIPTION("Begin a renderPass where clearValueCount is less than"
9811 "the number of renderPass attachments that use loadOp"
9812 "VK_ATTACHMENT_LOAD_OP_CLEAR.");
9813
9814 ASSERT_NO_FATAL_FAILURE(InitState());
9815 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
9816
9817 // Create a renderPass with a single attachment that uses loadOp CLEAR
9818 VkAttachmentReference attach = {};
9819 attach.layout = VK_IMAGE_LAYOUT_GENERAL;
9820 VkSubpassDescription subpass = {};
9821 subpass.inputAttachmentCount = 1;
9822 subpass.pInputAttachments = &attach;
9823 VkRenderPassCreateInfo rpci = {};
9824 rpci.subpassCount = 1;
9825 rpci.pSubpasses = &subpass;
9826 rpci.attachmentCount = 1;
9827 VkAttachmentDescription attach_desc = {};
9828 attach_desc.format = VK_FORMAT_UNDEFINED;
9829 // Set loadOp to CLEAR
9830 attach_desc.loadOp = VK_ATTACHMENT_LOAD_OP_CLEAR;
9831 rpci.pAttachments = &attach_desc;
9832 rpci.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
9833 VkRenderPass rp;
9834 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
9835
9836 VkCommandBufferInheritanceInfo hinfo = {};
9837 hinfo.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_INHERITANCE_INFO;
9838 hinfo.renderPass = VK_NULL_HANDLE;
9839 hinfo.subpass = 0;
9840 hinfo.framebuffer = VK_NULL_HANDLE;
9841 hinfo.occlusionQueryEnable = VK_FALSE;
9842 hinfo.queryFlags = 0;
9843 hinfo.pipelineStatistics = 0;
9844 VkCommandBufferBeginInfo info = {};
9845 info.flags = VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT;
9846 info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
9847 info.pInheritanceInfo = &hinfo;
9848
9849 vkBeginCommandBuffer(m_commandBuffer->handle(), &info);
9850 VkRenderPassBeginInfo rp_begin = {};
9851 rp_begin.sType = VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO;
9852 rp_begin.pNext = NULL;
9853 rp_begin.renderPass = renderPass();
9854 rp_begin.framebuffer = framebuffer();
9855 rp_begin.clearValueCount = 0; // Should be 1
9856
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009857 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " has a clearValueCount of 0 but "
9858 "there must be at least 1 entries in "
9859 "pClearValues array to account for ");
Tobin Ehlis5a1c0332016-05-31 13:59:26 -06009860
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009861 vkCmdBeginRenderPass(m_commandBuffer->GetBufferHandle(), &rp_begin, VK_SUBPASS_CONTENTS_INLINE);
Tobin Ehlis5a1c0332016-05-31 13:59:26 -06009862
9863 m_errorMonitor->VerifyFound();
Mark Lobodzinski5c70ebd2016-06-09 13:45:00 -06009864
9865 vkDestroyRenderPass(m_device->device(), rp, NULL);
Tobin Ehlis5a1c0332016-05-31 13:59:26 -06009866}
9867
Cody Northrop3bb4d962016-05-09 16:15:57 -06009868TEST_F(VkLayerTest, EndCommandBufferWithinRenderPass) {
9869
9870 TEST_DESCRIPTION("End a command buffer with an active render pass");
9871
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009872 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
9873 "It is invalid to issue this call inside an active render pass");
Cody Northrop3bb4d962016-05-09 16:15:57 -06009874
9875 ASSERT_NO_FATAL_FAILURE(InitState());
9876 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
9877
9878 // The framework's BeginCommandBuffer calls CreateRenderPass
9879 BeginCommandBuffer();
9880
9881 // Call directly into vkEndCommandBuffer instead of the
9882 // the framework's EndCommandBuffer, which inserts a
9883 // vkEndRenderPass
9884 vkEndCommandBuffer(m_commandBuffer->GetBufferHandle());
9885
9886 m_errorMonitor->VerifyFound();
9887
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009888 // TODO: Add test for VK_COMMAND_BUFFER_LEVEL_SECONDARY
9889 // TODO: Add test for VK_COMMAND_BUFFER_USAGE_RENDER_PASS_CONTINUE_BIT
Cody Northrop3bb4d962016-05-09 16:15:57 -06009890}
9891
Karl Schultz6addd812016-02-02 17:17:23 -07009892TEST_F(VkLayerTest, FillBufferWithinRenderPass) {
Mark Lobodzinskid5639502015-09-24 09:51:47 -06009893 // Call CmdFillBuffer within an active renderpass
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009894 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
9895 "It is invalid to issue this call inside an active render pass");
Mark Lobodzinskid5639502015-09-24 09:51:47 -06009896
9897 ASSERT_NO_FATAL_FAILURE(InitState());
9898 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Mark Lobodzinskid5639502015-09-24 09:51:47 -06009899
9900 // Renderpass is started here
9901 BeginCommandBuffer();
9902
9903 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009904 vk_testing::Buffer dstBuffer;
9905 dstBuffer.init_as_dst(*m_device, (VkDeviceSize)1024, reqs);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06009906
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009907 m_commandBuffer->FillBuffer(dstBuffer.handle(), 0, 4, 0x11111111);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06009908
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009909 m_errorMonitor->VerifyFound();
Mark Lobodzinskid5639502015-09-24 09:51:47 -06009910}
9911
Karl Schultz6addd812016-02-02 17:17:23 -07009912TEST_F(VkLayerTest, UpdateBufferWithinRenderPass) {
Mark Lobodzinskid5639502015-09-24 09:51:47 -06009913 // Call CmdUpdateBuffer within an active renderpass
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009914 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
9915 "It is invalid to issue this call inside an active render pass");
Mark Lobodzinskid5639502015-09-24 09:51:47 -06009916
9917 ASSERT_NO_FATAL_FAILURE(InitState());
9918 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Mark Lobodzinskid5639502015-09-24 09:51:47 -06009919
9920 // Renderpass is started here
9921 BeginCommandBuffer();
9922
9923 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009924 vk_testing::Buffer dstBuffer;
9925 dstBuffer.init_as_dst(*m_device, (VkDeviceSize)1024, reqs);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06009926
Karl Schultz6addd812016-02-02 17:17:23 -07009927 VkDeviceSize dstOffset = 0;
9928 VkDeviceSize dataSize = 1024;
Karl Schultzee344492016-07-11 15:09:57 -06009929 const void *pData = NULL;
Mark Lobodzinskid5639502015-09-24 09:51:47 -06009930
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009931 vkCmdUpdateBuffer(m_commandBuffer->GetBufferHandle(), dstBuffer.handle(), dstOffset, dataSize, pData);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06009932
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009933 m_errorMonitor->VerifyFound();
Mark Lobodzinskid5639502015-09-24 09:51:47 -06009934}
9935
Karl Schultz6addd812016-02-02 17:17:23 -07009936TEST_F(VkLayerTest, ClearColorImageWithinRenderPass) {
Mark Lobodzinskid5639502015-09-24 09:51:47 -06009937 // Call CmdClearColorImage within an active RenderPass
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009938 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
9939 "It is invalid to issue this call inside an active render pass");
Mark Lobodzinskid5639502015-09-24 09:51:47 -06009940
9941 ASSERT_NO_FATAL_FAILURE(InitState());
9942 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Mark Lobodzinskid5639502015-09-24 09:51:47 -06009943
9944 // Renderpass is started here
9945 BeginCommandBuffer();
9946
Michael Lentine0a369f62016-02-03 16:51:46 -06009947 VkClearColorValue clear_color;
9948 memset(clear_color.uint32, 0, sizeof(uint32_t) * 4);
Karl Schultz6addd812016-02-02 17:17:23 -07009949 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
9950 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
9951 const int32_t tex_width = 32;
9952 const int32_t tex_height = 32;
9953 VkImageCreateInfo image_create_info = {};
9954 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
9955 image_create_info.pNext = NULL;
9956 image_create_info.imageType = VK_IMAGE_TYPE_2D;
9957 image_create_info.format = tex_format;
9958 image_create_info.extent.width = tex_width;
9959 image_create_info.extent.height = tex_height;
9960 image_create_info.extent.depth = 1;
9961 image_create_info.mipLevels = 1;
9962 image_create_info.arrayLayers = 1;
9963 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
9964 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
9965 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
Mark Lobodzinskid5639502015-09-24 09:51:47 -06009966
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009967 vk_testing::Image dstImage;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009968 dstImage.init(*m_device, (const VkImageCreateInfo &)image_create_info, reqs);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06009969
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009970 const VkImageSubresourceRange range = vk_testing::Image::subresource_range(image_create_info, VK_IMAGE_ASPECT_COLOR_BIT);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06009971
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009972 vkCmdClearColorImage(m_commandBuffer->GetBufferHandle(), dstImage.handle(), VK_IMAGE_LAYOUT_GENERAL, &clear_color, 1, &range);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06009973
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009974 m_errorMonitor->VerifyFound();
Mark Lobodzinskid5639502015-09-24 09:51:47 -06009975}
9976
Karl Schultz6addd812016-02-02 17:17:23 -07009977TEST_F(VkLayerTest, ClearDepthStencilImageWithinRenderPass) {
Mark Lobodzinskid5639502015-09-24 09:51:47 -06009978 // Call CmdClearDepthStencilImage within an active RenderPass
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009979 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
9980 "It is invalid to issue this call inside an active render pass");
Mark Lobodzinskid5639502015-09-24 09:51:47 -06009981
9982 ASSERT_NO_FATAL_FAILURE(InitState());
9983 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Mark Lobodzinskid5639502015-09-24 09:51:47 -06009984
9985 // Renderpass is started here
9986 BeginCommandBuffer();
9987
9988 VkClearDepthStencilValue clear_value = {0};
Dustin Gravesa2e5c942016-02-11 18:28:06 -07009989 VkMemoryPropertyFlags reqs = 0;
Karl Schultz6addd812016-02-02 17:17:23 -07009990 VkImageCreateInfo image_create_info = vk_testing::Image::create_info();
9991 image_create_info.imageType = VK_IMAGE_TYPE_2D;
9992 image_create_info.format = VK_FORMAT_D24_UNORM_S8_UINT;
9993 image_create_info.extent.width = 64;
9994 image_create_info.extent.height = 64;
9995 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
9996 image_create_info.usage = VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT;
Mark Lobodzinskid5639502015-09-24 09:51:47 -06009997
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009998 vk_testing::Image dstImage;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009999 dstImage.init(*m_device, (const VkImageCreateInfo &)image_create_info, reqs);
Mark Lobodzinskid5639502015-09-24 09:51:47 -060010000
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010001 const VkImageSubresourceRange range = vk_testing::Image::subresource_range(image_create_info, VK_IMAGE_ASPECT_DEPTH_BIT);
Mark Lobodzinskid5639502015-09-24 09:51:47 -060010002
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010003 vkCmdClearDepthStencilImage(m_commandBuffer->GetBufferHandle(), dstImage.handle(),
10004 VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL, &clear_value, 1, &range);
Mark Lobodzinskid5639502015-09-24 09:51:47 -060010005
Chris Forbes8f36a8a2016-04-07 13:21:07 +120010006 m_errorMonitor->VerifyFound();
Mark Lobodzinskid5639502015-09-24 09:51:47 -060010007}
10008
Karl Schultz6addd812016-02-02 17:17:23 -070010009TEST_F(VkLayerTest, ClearColorAttachmentsOutsideRenderPass) {
Courtney Goeltzenleuchterc9323e02015-10-15 16:51:05 -060010010 // Call CmdClearAttachmentss outside of an active RenderPass
Karl Schultz6addd812016-02-02 17:17:23 -070010011 VkResult err;
Mark Lobodzinskid5639502015-09-24 09:51:47 -060010012
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010013 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "vkCmdClearAttachments(): This call "
10014 "must be issued inside an active "
10015 "render pass");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060010016
Mark Lobodzinskid5639502015-09-24 09:51:47 -060010017 ASSERT_NO_FATAL_FAILURE(InitState());
10018 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Mark Lobodzinskid5639502015-09-24 09:51:47 -060010019
10020 // Start no RenderPass
Chia-I Wu3432a0c2015-10-27 18:04:07 +080010021 err = m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskid5639502015-09-24 09:51:47 -060010022 ASSERT_VK_SUCCESS(err);
10023
Courtney Goeltzenleuchterc9323e02015-10-15 16:51:05 -060010024 VkClearAttachment color_attachment;
10025 color_attachment.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
10026 color_attachment.clearValue.color.float32[0] = 0;
10027 color_attachment.clearValue.color.float32[1] = 0;
10028 color_attachment.clearValue.color.float32[2] = 0;
10029 color_attachment.clearValue.color.float32[3] = 0;
10030 color_attachment.colorAttachment = 0;
Karl Schultz6addd812016-02-02 17:17:23 -070010031 VkClearRect clear_rect = {{{0, 0}, {32, 32}}};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010032 vkCmdClearAttachments(m_commandBuffer->GetBufferHandle(), 1, &color_attachment, 1, &clear_rect);
Mark Lobodzinskid5639502015-09-24 09:51:47 -060010033
Chris Forbes8f36a8a2016-04-07 13:21:07 +120010034 m_errorMonitor->VerifyFound();
Mark Lobodzinskid5639502015-09-24 09:51:47 -060010035}
10036
Chris Forbes3b97e932016-09-07 11:29:24 +120010037TEST_F(VkLayerTest, RenderPassExcessiveNextSubpass) {
10038 TEST_DESCRIPTION("Test that an error is produced when CmdNextSubpass is "
10039 "called too many times in a renderpass instance");
10040
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010041 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "vkCmdNextSubpass(): Attempted to advance "
10042 "beyond final subpass");
Chris Forbes3b97e932016-09-07 11:29:24 +120010043
10044 ASSERT_NO_FATAL_FAILURE(InitState());
10045 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
10046
10047 BeginCommandBuffer();
10048
10049 // error here.
10050 vkCmdNextSubpass(m_commandBuffer->GetBufferHandle(), VK_SUBPASS_CONTENTS_INLINE);
10051 m_errorMonitor->VerifyFound();
10052
10053 EndCommandBuffer();
10054}
10055
Chris Forbes6d624702016-09-07 13:57:05 +120010056TEST_F(VkLayerTest, RenderPassEndedBeforeFinalSubpass) {
10057 TEST_DESCRIPTION("Test that an error is produced when CmdEndRenderPass is "
10058 "called before the final subpass has been reached");
10059
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010060 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "vkCmdEndRenderPass(): Called before reaching "
10061 "final subpass");
Chris Forbes6d624702016-09-07 13:57:05 +120010062
10063 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010064 VkSubpassDescription sd[2] = {{0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 0, nullptr, nullptr, nullptr, 0, nullptr},
10065 {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 0, nullptr, nullptr, nullptr, 0, nullptr}};
Chris Forbes6d624702016-09-07 13:57:05 +120010066
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010067 VkRenderPassCreateInfo rcpi = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 0, nullptr, 2, sd, 0, nullptr};
Chris Forbes6d624702016-09-07 13:57:05 +120010068
10069 VkRenderPass rp;
10070 VkResult err = vkCreateRenderPass(m_device->device(), &rcpi, nullptr, &rp);
10071 ASSERT_VK_SUCCESS(err);
10072
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010073 VkFramebufferCreateInfo fbci = {VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr, 0, rp, 0, nullptr, 16, 16, 1};
Chris Forbes6d624702016-09-07 13:57:05 +120010074
10075 VkFramebuffer fb;
10076 err = vkCreateFramebuffer(m_device->device(), &fbci, nullptr, &fb);
10077 ASSERT_VK_SUCCESS(err);
10078
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010079 m_commandBuffer->BeginCommandBuffer(); // no implicit RP begin
Chris Forbes6d624702016-09-07 13:57:05 +120010080
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010081 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 +120010082
10083 vkCmdBeginRenderPass(m_commandBuffer->GetBufferHandle(), &rpbi, VK_SUBPASS_CONTENTS_INLINE);
10084
10085 // Error here.
10086 vkCmdEndRenderPass(m_commandBuffer->GetBufferHandle());
10087 m_errorMonitor->VerifyFound();
10088
10089 // Clean up.
10090 vkDestroyFramebuffer(m_device->device(), fb, nullptr);
10091 vkDestroyRenderPass(m_device->device(), rp, nullptr);
10092}
10093
Karl Schultz9e66a292016-04-21 15:57:51 -060010094TEST_F(VkLayerTest, BufferMemoryBarrierNoBuffer) {
10095 // Try to add a buffer memory barrier with no buffer.
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010096 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
10097 "required parameter pBufferMemoryBarriers[0].buffer specified as VK_NULL_HANDLE");
Karl Schultz9e66a292016-04-21 15:57:51 -060010098
10099 ASSERT_NO_FATAL_FAILURE(InitState());
10100 BeginCommandBuffer();
10101
10102 VkBufferMemoryBarrier buf_barrier = {};
10103 buf_barrier.sType = VK_STRUCTURE_TYPE_BUFFER_MEMORY_BARRIER;
10104 buf_barrier.srcAccessMask = VK_ACCESS_HOST_WRITE_BIT;
10105 buf_barrier.dstAccessMask = VK_ACCESS_SHADER_READ_BIT;
10106 buf_barrier.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
10107 buf_barrier.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
10108 buf_barrier.buffer = VK_NULL_HANDLE;
10109 buf_barrier.offset = 0;
10110 buf_barrier.size = VK_WHOLE_SIZE;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010111 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
10112 nullptr, 1, &buf_barrier, 0, nullptr);
Karl Schultz9e66a292016-04-21 15:57:51 -060010113
10114 m_errorMonitor->VerifyFound();
10115}
10116
Tony Barbour7fd5c0f2016-05-03 16:11:53 -060010117TEST_F(VkLayerTest, InvalidBarriers) {
10118 TEST_DESCRIPTION("A variety of ways to get VK_INVALID_BARRIER ");
10119
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010120 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Barriers cannot be set during subpass");
Tony Barbour7fd5c0f2016-05-03 16:11:53 -060010121
10122 ASSERT_NO_FATAL_FAILURE(InitState());
10123 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
10124
10125 VkMemoryBarrier mem_barrier = {};
10126 mem_barrier.sType = VK_STRUCTURE_TYPE_MEMORY_BARRIER;
10127 mem_barrier.pNext = NULL;
10128 mem_barrier.srcAccessMask = VK_ACCESS_HOST_WRITE_BIT;
10129 mem_barrier.dstAccessMask = VK_ACCESS_SHADER_READ_BIT;
10130 BeginCommandBuffer();
10131 // BeginCommandBuffer() starts a render pass
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010132 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 1,
Tony Barbour7fd5c0f2016-05-03 16:11:53 -060010133 &mem_barrier, 0, nullptr, 0, nullptr);
10134 m_errorMonitor->VerifyFound();
10135
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010136 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Image Layout cannot be transitioned to UNDEFINED");
Tony Barbour7fd5c0f2016-05-03 16:11:53 -060010137 VkImageObj image(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010138 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 -060010139 ASSERT_TRUE(image.initialized());
10140 VkImageMemoryBarrier img_barrier = {};
10141 img_barrier.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
10142 img_barrier.pNext = NULL;
10143 img_barrier.srcAccessMask = VK_ACCESS_HOST_WRITE_BIT;
10144 img_barrier.dstAccessMask = VK_ACCESS_SHADER_READ_BIT;
10145 img_barrier.oldLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
10146 // New layout can't be UNDEFINED
10147 img_barrier.newLayout = VK_IMAGE_LAYOUT_UNDEFINED;
10148 img_barrier.image = image.handle();
10149 img_barrier.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
10150 img_barrier.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
10151 img_barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
10152 img_barrier.subresourceRange.baseArrayLayer = 0;
10153 img_barrier.subresourceRange.baseMipLevel = 0;
10154 img_barrier.subresourceRange.layerCount = 1;
10155 img_barrier.subresourceRange.levelCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010156 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
10157 nullptr, 0, nullptr, 1, &img_barrier);
Tony Barbour7fd5c0f2016-05-03 16:11:53 -060010158 m_errorMonitor->VerifyFound();
10159 img_barrier.newLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
10160
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010161 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Subresource must have the sum of the "
10162 "baseArrayLayer");
Tony Barbour7fd5c0f2016-05-03 16:11:53 -060010163 // baseArrayLayer + layerCount must be <= image's arrayLayers
10164 img_barrier.subresourceRange.baseArrayLayer = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010165 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
10166 nullptr, 0, nullptr, 1, &img_barrier);
Tony Barbour7fd5c0f2016-05-03 16:11:53 -060010167 m_errorMonitor->VerifyFound();
10168 img_barrier.subresourceRange.baseArrayLayer = 0;
10169
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010170 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Subresource must have the sum of the baseMipLevel");
Tony Barbour7fd5c0f2016-05-03 16:11:53 -060010171 // baseMipLevel + levelCount must be <= image's mipLevels
10172 img_barrier.subresourceRange.baseMipLevel = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010173 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
10174 nullptr, 0, nullptr, 1, &img_barrier);
Tony Barbour7fd5c0f2016-05-03 16:11:53 -060010175 m_errorMonitor->VerifyFound();
10176 img_barrier.subresourceRange.baseMipLevel = 0;
10177
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010178 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 -060010179 vk_testing::Buffer buffer;
10180 buffer.init(*m_device, 256);
10181 VkBufferMemoryBarrier buf_barrier = {};
10182 buf_barrier.sType = VK_STRUCTURE_TYPE_BUFFER_MEMORY_BARRIER;
10183 buf_barrier.pNext = NULL;
10184 buf_barrier.srcAccessMask = VK_ACCESS_HOST_WRITE_BIT;
10185 buf_barrier.dstAccessMask = VK_ACCESS_SHADER_READ_BIT;
10186 buf_barrier.buffer = buffer.handle();
10187 buf_barrier.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
10188 buf_barrier.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
10189 buf_barrier.offset = 0;
10190 buf_barrier.size = VK_WHOLE_SIZE;
10191 // Can't send buffer barrier during a render pass
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010192 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
10193 nullptr, 1, &buf_barrier, 0, nullptr);
Tony Barbour7fd5c0f2016-05-03 16:11:53 -060010194 m_errorMonitor->VerifyFound();
10195 vkCmdEndRenderPass(m_commandBuffer->GetBufferHandle());
10196
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010197 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "which is not less than total size");
Tony Barbour7fd5c0f2016-05-03 16:11:53 -060010198 buf_barrier.offset = 257;
10199 // Offset greater than total size
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010200 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
10201 nullptr, 1, &buf_barrier, 0, nullptr);
Tony Barbour7fd5c0f2016-05-03 16:11:53 -060010202 m_errorMonitor->VerifyFound();
10203 buf_barrier.offset = 0;
10204
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010205 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "whose sum is greater than total size");
Tony Barbour7fd5c0f2016-05-03 16:11:53 -060010206 buf_barrier.size = 257;
10207 // Size greater than total size
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010208 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
10209 nullptr, 1, &buf_barrier, 0, nullptr);
Tony Barbour7fd5c0f2016-05-03 16:11:53 -060010210 m_errorMonitor->VerifyFound();
Tony Barbour7fd5c0f2016-05-03 16:11:53 -060010211
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -060010212 // Now exercise barrier aspect bit errors, first DS
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010213 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Image is a depth and stencil format and thus must "
10214 "have either one or both of VK_IMAGE_ASPECT_DEPTH_BIT and "
10215 "VK_IMAGE_ASPECT_STENCIL_BIT set.");
Tony Barbour7fd5c0f2016-05-03 16:11:53 -060010216 VkDepthStencilObj ds_image(m_device);
10217 ds_image.Init(m_device, 128, 128, VK_FORMAT_D24_UNORM_S8_UINT);
10218 ASSERT_TRUE(ds_image.initialized());
Tobin Ehlis15684a02016-07-21 14:55:26 -060010219 img_barrier.oldLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
10220 img_barrier.newLayout = VK_IMAGE_LAYOUT_GENERAL;
Tony Barbour7fd5c0f2016-05-03 16:11:53 -060010221 img_barrier.image = ds_image.handle();
Tobin Ehlis15684a02016-07-21 14:55:26 -060010222 // Use of COLOR aspect on DS image is error
10223 img_barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010224 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
10225 nullptr, 0, nullptr, 1, &img_barrier);
Tony Barbour7fd5c0f2016-05-03 16:11:53 -060010226 m_errorMonitor->VerifyFound();
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -060010227 // Now test depth-only
10228 VkFormatProperties format_props;
10229
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010230 vkGetPhysicalDeviceFormatProperties(m_device->phy().handle(), VK_FORMAT_D16_UNORM, &format_props);
10231 if (format_props.optimalTilingFeatures & VK_FORMAT_FEATURE_DEPTH_STENCIL_ATTACHMENT_BIT) {
10232 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Image is a depth-only format and thus must "
10233 "have VK_IMAGE_ASPECT_DEPTH_BIT set.");
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -060010234 VkDepthStencilObj d_image(m_device);
10235 d_image.Init(m_device, 128, 128, VK_FORMAT_D16_UNORM);
10236 ASSERT_TRUE(d_image.initialized());
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010237 img_barrier.oldLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
Tobin Ehlis15684a02016-07-21 14:55:26 -060010238 img_barrier.newLayout = VK_IMAGE_LAYOUT_GENERAL;
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -060010239 img_barrier.image = d_image.handle();
Tobin Ehlis15684a02016-07-21 14:55:26 -060010240 // Use of COLOR aspect on depth image is error
10241 img_barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010242 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0,
10243 0, nullptr, 0, nullptr, 1, &img_barrier);
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -060010244 m_errorMonitor->VerifyFound();
10245 }
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010246 vkGetPhysicalDeviceFormatProperties(m_device->phy().handle(), VK_FORMAT_S8_UINT, &format_props);
10247 if (format_props.optimalTilingFeatures & VK_FORMAT_FEATURE_DEPTH_STENCIL_ATTACHMENT_BIT) {
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -060010248 // Now test stencil-only
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010249 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Image is a stencil-only format and thus must "
10250 "have VK_IMAGE_ASPECT_STENCIL_BIT set.");
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -060010251 VkDepthStencilObj s_image(m_device);
10252 s_image.Init(m_device, 128, 128, VK_FORMAT_S8_UINT);
10253 ASSERT_TRUE(s_image.initialized());
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010254 img_barrier.oldLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
Tobin Ehlis15684a02016-07-21 14:55:26 -060010255 img_barrier.newLayout = VK_IMAGE_LAYOUT_GENERAL;
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -060010256 img_barrier.image = s_image.handle();
Tobin Ehlis15684a02016-07-21 14:55:26 -060010257 // Use of COLOR aspect on depth image is error
10258 img_barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010259 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0,
10260 0, nullptr, 0, nullptr, 1, &img_barrier);
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -060010261 m_errorMonitor->VerifyFound();
10262 }
10263 // Finally test color
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010264 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Image is a color format and thus must "
10265 "have VK_IMAGE_ASPECT_COLOR_BIT set.");
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -060010266 VkImageObj c_image(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010267 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 -060010268 ASSERT_TRUE(c_image.initialized());
10269 img_barrier.oldLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
10270 img_barrier.newLayout = VK_IMAGE_LAYOUT_GENERAL;
10271 img_barrier.image = c_image.handle();
10272 // Set aspect to depth (non-color)
10273 img_barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010274 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
10275 nullptr, 0, nullptr, 1, &img_barrier);
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -060010276 m_errorMonitor->VerifyFound();
Tony Barbour7fd5c0f2016-05-03 16:11:53 -060010277}
10278
Karl Schultz6addd812016-02-02 17:17:23 -070010279TEST_F(VkLayerTest, IdxBufferAlignmentError) {
Tobin Ehlisc4c23182015-09-17 12:24:13 -060010280 // Bind a BeginRenderPass within an active RenderPass
Karl Schultz6addd812016-02-02 17:17:23 -070010281 VkResult err;
Tobin Ehlisc4c23182015-09-17 12:24:13 -060010282
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010283 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "vkCmdBindIndexBuffer() offset (0x7) does not fall on ");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060010284
Tobin Ehlisc4c23182015-09-17 12:24:13 -060010285 ASSERT_NO_FATAL_FAILURE(InitState());
10286 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlisc4c23182015-09-17 12:24:13 -060010287 uint32_t qfi = 0;
10288 VkBufferCreateInfo buffCI = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010289 buffCI.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
10290 buffCI.size = 1024;
10291 buffCI.usage = VK_BUFFER_USAGE_INDEX_BUFFER_BIT;
10292 buffCI.queueFamilyIndexCount = 1;
10293 buffCI.pQueueFamilyIndices = &qfi;
Tobin Ehlisc4c23182015-09-17 12:24:13 -060010294
10295 VkBuffer ib;
Chia-I Wuf7458c52015-10-26 21:10:41 +080010296 err = vkCreateBuffer(m_device->device(), &buffCI, NULL, &ib);
Tobin Ehlisc4c23182015-09-17 12:24:13 -060010297 ASSERT_VK_SUCCESS(err);
10298
10299 BeginCommandBuffer();
10300 ASSERT_VK_SUCCESS(err);
Karl Schultz6addd812016-02-02 17:17:23 -070010301 // vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(),
10302 // VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Tobin Ehlisc4c23182015-09-17 12:24:13 -060010303 // Should error before calling to driver so don't care about actual data
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010304 vkCmdBindIndexBuffer(m_commandBuffer->GetBufferHandle(), ib, 7, VK_INDEX_TYPE_UINT16);
Tobin Ehlisc4c23182015-09-17 12:24:13 -060010305
Chris Forbes8f36a8a2016-04-07 13:21:07 +120010306 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -060010307
Chia-I Wuf7458c52015-10-26 21:10:41 +080010308 vkDestroyBuffer(m_device->device(), ib, NULL);
Tobin Ehlisc4c23182015-09-17 12:24:13 -060010309}
10310
Mark Lobodzinski52a6e7d2016-02-25 15:09:52 -070010311TEST_F(VkLayerTest, InvalidQueueFamilyIndex) {
10312 // Create an out-of-range queueFamilyIndex
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010313 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
10314 "vkCreateBuffer: pCreateInfo->pQueueFamilyIndices[0] (777) must be one "
10315 "of the indices specified when the device was created, via the "
10316 "VkDeviceQueueCreateInfo structure.");
Mark Lobodzinski52a6e7d2016-02-25 15:09:52 -070010317
10318 ASSERT_NO_FATAL_FAILURE(InitState());
10319 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
10320 VkBufferCreateInfo buffCI = {};
10321 buffCI.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
10322 buffCI.size = 1024;
10323 buffCI.usage = VK_BUFFER_USAGE_INDEX_BUFFER_BIT;
10324 buffCI.queueFamilyIndexCount = 1;
10325 // Introduce failure by specifying invalid queue_family_index
10326 uint32_t qfi = 777;
10327 buffCI.pQueueFamilyIndices = &qfi;
Tobin Ehlis24aab042016-03-24 10:54:18 -060010328 buffCI.sharingMode = VK_SHARING_MODE_CONCURRENT; // qfi only matters in CONCURRENT mode
Mark Lobodzinski52a6e7d2016-02-25 15:09:52 -070010329
10330 VkBuffer ib;
10331 vkCreateBuffer(m_device->device(), &buffCI, NULL, &ib);
10332
Chris Forbes8f36a8a2016-04-07 13:21:07 +120010333 m_errorMonitor->VerifyFound();
Tony Barbourdf4c0042016-06-01 15:55:43 -060010334 vkDestroyBuffer(m_device->device(), ib, NULL);
Mark Lobodzinski52a6e7d2016-02-25 15:09:52 -070010335}
10336
Karl Schultz6addd812016-02-02 17:17:23 -070010337TEST_F(VkLayerTest, ExecuteCommandsPrimaryCB) {
Tobin Ehlis0c94db02016-07-19 10:49:32 -060010338 TEST_DESCRIPTION("Attempt vkCmdExecuteCommands w/ a primary cmd buffer"
10339 " (should only be secondary)");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060010340
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010341 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "vkCmdExecuteCommands() called w/ Primary Cmd Buffer ");
Tobin Ehlis4b34ddc2015-09-17 14:18:16 -060010342
10343 ASSERT_NO_FATAL_FAILURE(InitState());
10344 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlis4b34ddc2015-09-17 14:18:16 -060010345
10346 BeginCommandBuffer();
Tobin Ehlis0c94db02016-07-19 10:49:32 -060010347
Chia-I Wu3432a0c2015-10-27 18:04:07 +080010348 VkCommandBuffer primCB = m_commandBuffer->GetBufferHandle();
10349 vkCmdExecuteCommands(m_commandBuffer->GetBufferHandle(), 1, &primCB);
Tobin Ehlis4b34ddc2015-09-17 14:18:16 -060010350
Chris Forbes8f36a8a2016-04-07 13:21:07 +120010351 m_errorMonitor->VerifyFound();
Tobin Ehlis4b34ddc2015-09-17 14:18:16 -060010352}
10353
Tobin Ehlis17826bd2016-05-25 11:12:50 -060010354TEST_F(VkLayerTest, DSUsageBitsErrors) {
10355 TEST_DESCRIPTION("Attempt to update descriptor sets for images and buffers "
10356 "that do not have correct usage bits sets.");
10357 VkResult err;
10358
10359 ASSERT_NO_FATAL_FAILURE(InitState());
10360 VkDescriptorPoolSize ds_type_count[VK_DESCRIPTOR_TYPE_RANGE_SIZE] = {};
10361 for (uint32_t i = 0; i < VK_DESCRIPTOR_TYPE_RANGE_SIZE; ++i) {
10362 ds_type_count[i].type = VkDescriptorType(i);
10363 ds_type_count[i].descriptorCount = 1;
10364 }
10365 VkDescriptorPoolCreateInfo ds_pool_ci = {};
10366 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
10367 ds_pool_ci.pNext = NULL;
10368 ds_pool_ci.maxSets = VK_DESCRIPTOR_TYPE_RANGE_SIZE;
10369 ds_pool_ci.poolSizeCount = VK_DESCRIPTOR_TYPE_RANGE_SIZE;
10370 ds_pool_ci.pPoolSizes = ds_type_count;
10371
10372 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010373 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis17826bd2016-05-25 11:12:50 -060010374 ASSERT_VK_SUCCESS(err);
10375
10376 // Create 10 layouts where each has a single descriptor of different type
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010377 VkDescriptorSetLayoutBinding dsl_binding[VK_DESCRIPTOR_TYPE_RANGE_SIZE] = {};
Tobin Ehlis17826bd2016-05-25 11:12:50 -060010378 for (uint32_t i = 0; i < VK_DESCRIPTOR_TYPE_RANGE_SIZE; ++i) {
10379 dsl_binding[i].binding = 0;
10380 dsl_binding[i].descriptorType = VkDescriptorType(i);
10381 dsl_binding[i].descriptorCount = 1;
10382 dsl_binding[i].stageFlags = VK_SHADER_STAGE_ALL;
10383 dsl_binding[i].pImmutableSamplers = NULL;
10384 }
10385
10386 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
10387 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
10388 ds_layout_ci.pNext = NULL;
10389 ds_layout_ci.bindingCount = 1;
10390 VkDescriptorSetLayout ds_layouts[VK_DESCRIPTOR_TYPE_RANGE_SIZE];
10391 for (uint32_t i = 0; i < VK_DESCRIPTOR_TYPE_RANGE_SIZE; ++i) {
10392 ds_layout_ci.pBindings = dsl_binding + i;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010393 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, ds_layouts + i);
Tobin Ehlis17826bd2016-05-25 11:12:50 -060010394 ASSERT_VK_SUCCESS(err);
10395 }
10396 VkDescriptorSet descriptor_sets[VK_DESCRIPTOR_TYPE_RANGE_SIZE] = {};
10397 VkDescriptorSetAllocateInfo alloc_info = {};
10398 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
10399 alloc_info.descriptorSetCount = VK_DESCRIPTOR_TYPE_RANGE_SIZE;
10400 alloc_info.descriptorPool = ds_pool;
10401 alloc_info.pSetLayouts = ds_layouts;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010402 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, descriptor_sets);
Tobin Ehlis17826bd2016-05-25 11:12:50 -060010403 ASSERT_VK_SUCCESS(err);
10404
10405 // Create a buffer & bufferView to be used for invalid updates
10406 VkBufferCreateInfo buff_ci = {};
10407 buff_ci.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
10408 // This usage is not valid for any descriptor type
10409 buff_ci.usage = VK_BUFFER_USAGE_TRANSFER_SRC_BIT;
10410 buff_ci.size = 256;
10411 buff_ci.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
10412 VkBuffer buffer;
10413 err = vkCreateBuffer(m_device->device(), &buff_ci, NULL, &buffer);
10414 ASSERT_VK_SUCCESS(err);
10415
10416 VkBufferViewCreateInfo buff_view_ci = {};
10417 buff_view_ci.sType = VK_STRUCTURE_TYPE_BUFFER_VIEW_CREATE_INFO;
10418 buff_view_ci.buffer = buffer;
10419 buff_view_ci.format = VK_FORMAT_R8_UNORM;
10420 buff_view_ci.range = VK_WHOLE_SIZE;
10421 VkBufferView buff_view;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010422 err = vkCreateBufferView(m_device->device(), &buff_view_ci, NULL, &buff_view);
Tobin Ehlis17826bd2016-05-25 11:12:50 -060010423 ASSERT_VK_SUCCESS(err);
10424
10425 // Create an image to be used for invalid updates
10426 VkImageCreateInfo image_ci = {};
10427 image_ci.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
10428 image_ci.imageType = VK_IMAGE_TYPE_2D;
10429 image_ci.format = VK_FORMAT_R8G8B8A8_UNORM;
10430 image_ci.extent.width = 64;
10431 image_ci.extent.height = 64;
10432 image_ci.extent.depth = 1;
10433 image_ci.mipLevels = 1;
10434 image_ci.arrayLayers = 1;
10435 image_ci.samples = VK_SAMPLE_COUNT_1_BIT;
10436 image_ci.tiling = VK_IMAGE_TILING_LINEAR;
10437 image_ci.initialLayout = VK_IMAGE_LAYOUT_PREINITIALIZED;
10438 // This usage is not valid for any descriptor type
10439 image_ci.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
10440 image_ci.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
10441 VkImage image;
10442 err = vkCreateImage(m_device->device(), &image_ci, NULL, &image);
10443 ASSERT_VK_SUCCESS(err);
10444 // Bind memory to image
10445 VkMemoryRequirements mem_reqs;
10446 VkDeviceMemory image_mem;
10447 bool pass;
10448 VkMemoryAllocateInfo mem_alloc = {};
10449 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
10450 mem_alloc.pNext = NULL;
10451 mem_alloc.allocationSize = 0;
10452 mem_alloc.memoryTypeIndex = 0;
10453 vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs);
10454 mem_alloc.allocationSize = mem_reqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010455 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0);
Tobin Ehlis17826bd2016-05-25 11:12:50 -060010456 ASSERT_TRUE(pass);
10457 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &image_mem);
10458 ASSERT_VK_SUCCESS(err);
10459 err = vkBindImageMemory(m_device->device(), image, image_mem, 0);
10460 ASSERT_VK_SUCCESS(err);
10461 // Now create view for image
10462 VkImageViewCreateInfo image_view_ci = {};
10463 image_view_ci.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
10464 image_view_ci.image = image;
10465 image_view_ci.format = VK_FORMAT_R8G8B8A8_UNORM;
10466 image_view_ci.viewType = VK_IMAGE_VIEW_TYPE_2D;
10467 image_view_ci.subresourceRange.layerCount = 1;
10468 image_view_ci.subresourceRange.baseArrayLayer = 0;
10469 image_view_ci.subresourceRange.levelCount = 1;
10470 image_view_ci.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
10471 VkImageView image_view;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010472 err = vkCreateImageView(m_device->device(), &image_view_ci, NULL, &image_view);
Tobin Ehlis17826bd2016-05-25 11:12:50 -060010473 ASSERT_VK_SUCCESS(err);
10474
10475 VkDescriptorBufferInfo buff_info = {};
10476 buff_info.buffer = buffer;
10477 VkDescriptorImageInfo img_info = {};
10478 img_info.imageView = image_view;
10479 VkWriteDescriptorSet descriptor_write = {};
10480 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
10481 descriptor_write.dstBinding = 0;
10482 descriptor_write.descriptorCount = 1;
10483 descriptor_write.pTexelBufferView = &buff_view;
10484 descriptor_write.pBufferInfo = &buff_info;
10485 descriptor_write.pImageInfo = &img_info;
10486
10487 // These error messages align with VkDescriptorType struct
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010488 const char *error_msgs[] = {"", // placeholder, no error for SAMPLER descriptor
10489 " does not have VK_IMAGE_USAGE_SAMPLED_BIT set.",
10490 " does not have VK_IMAGE_USAGE_SAMPLED_BIT set.",
10491 " does not have VK_IMAGE_USAGE_STORAGE_BIT set.",
10492 " does not have VK_BUFFER_USAGE_UNIFORM_TEXEL_BUFFER_BIT set.",
10493 " does not have VK_BUFFER_USAGE_STORAGE_TEXEL_BUFFER_BIT set.",
10494 " does not have VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT set.",
10495 " does not have VK_BUFFER_USAGE_STORAGE_BUFFER_BIT set.",
10496 " does not have VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT set.",
10497 " does not have VK_BUFFER_USAGE_STORAGE_BUFFER_BIT set.",
10498 " does not have VK_IMAGE_USAGE_INPUT_ATTACHMENT_BIT set."};
Tobin Ehlis17826bd2016-05-25 11:12:50 -060010499 // Start loop at 1 as SAMPLER desc type has no usage bit error
10500 for (uint32_t i = 1; i < VK_DESCRIPTOR_TYPE_RANGE_SIZE; ++i) {
10501 descriptor_write.descriptorType = VkDescriptorType(i);
10502 descriptor_write.dstSet = descriptor_sets[i];
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010503 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, error_msgs[i]);
Tobin Ehlis17826bd2016-05-25 11:12:50 -060010504
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010505 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
Tobin Ehlis17826bd2016-05-25 11:12:50 -060010506
10507 m_errorMonitor->VerifyFound();
10508 vkDestroyDescriptorSetLayout(m_device->device(), ds_layouts[i], NULL);
10509 }
10510 vkDestroyDescriptorSetLayout(m_device->device(), ds_layouts[0], NULL);
10511 vkDestroyImage(m_device->device(), image, NULL);
Tony Barbourdf4c0042016-06-01 15:55:43 -060010512 vkFreeMemory(m_device->device(), image_mem, NULL);
Tobin Ehlis17826bd2016-05-25 11:12:50 -060010513 vkDestroyImageView(m_device->device(), image_view, NULL);
10514 vkDestroyBuffer(m_device->device(), buffer, NULL);
10515 vkDestroyBufferView(m_device->device(), buff_view, NULL);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010516 vkFreeDescriptorSets(m_device->device(), ds_pool, VK_DESCRIPTOR_TYPE_RANGE_SIZE, descriptor_sets);
Tobin Ehlis17826bd2016-05-25 11:12:50 -060010517 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
10518}
10519
Tobin Ehlis585f66d2016-07-01 18:23:58 -060010520TEST_F(VkLayerTest, DSBufferInfoErrors) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010521 TEST_DESCRIPTION("Attempt to update buffer descriptor set that has incorrect "
10522 "parameters in VkDescriptorBufferInfo struct. This includes:\n"
10523 "1. offset value greater than buffer size\n"
10524 "2. range value of 0\n"
10525 "3. range value greater than buffer (size - offset)");
Tobin Ehlis585f66d2016-07-01 18:23:58 -060010526 VkResult err;
10527
10528 ASSERT_NO_FATAL_FAILURE(InitState());
10529 VkDescriptorPoolSize ds_type_count = {};
10530 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
10531 ds_type_count.descriptorCount = 1;
10532
10533 VkDescriptorPoolCreateInfo ds_pool_ci = {};
10534 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
10535 ds_pool_ci.pNext = NULL;
10536 ds_pool_ci.maxSets = 1;
10537 ds_pool_ci.poolSizeCount = 1;
10538 ds_pool_ci.pPoolSizes = &ds_type_count;
10539
10540 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010541 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis585f66d2016-07-01 18:23:58 -060010542 ASSERT_VK_SUCCESS(err);
10543
10544 // Create layout with single uniform buffer descriptor
10545 VkDescriptorSetLayoutBinding dsl_binding = {};
10546 dsl_binding.binding = 0;
10547 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
10548 dsl_binding.descriptorCount = 1;
10549 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
10550 dsl_binding.pImmutableSamplers = NULL;
10551
10552 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
10553 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
10554 ds_layout_ci.pNext = NULL;
10555 ds_layout_ci.bindingCount = 1;
10556 ds_layout_ci.pBindings = &dsl_binding;
10557 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010558 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis585f66d2016-07-01 18:23:58 -060010559 ASSERT_VK_SUCCESS(err);
10560
10561 VkDescriptorSet descriptor_set = {};
10562 VkDescriptorSetAllocateInfo alloc_info = {};
10563 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
10564 alloc_info.descriptorSetCount = 1;
10565 alloc_info.descriptorPool = ds_pool;
10566 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010567 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
Tobin Ehlis585f66d2016-07-01 18:23:58 -060010568 ASSERT_VK_SUCCESS(err);
10569
10570 // Create a buffer to be used for invalid updates
10571 VkBufferCreateInfo buff_ci = {};
10572 buff_ci.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
10573 buff_ci.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
10574 buff_ci.size = 256;
10575 buff_ci.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
10576 VkBuffer buffer;
10577 err = vkCreateBuffer(m_device->device(), &buff_ci, NULL, &buffer);
10578 ASSERT_VK_SUCCESS(err);
10579 // Have to bind memory to buffer before descriptor update
10580 VkMemoryAllocateInfo mem_alloc = {};
10581 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
10582 mem_alloc.pNext = NULL;
10583 mem_alloc.allocationSize = 256;
10584 mem_alloc.memoryTypeIndex = 0;
10585
10586 VkMemoryRequirements mem_reqs;
10587 vkGetBufferMemoryRequirements(m_device->device(), buffer, &mem_reqs);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010588 bool pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0);
Tobin Ehlis585f66d2016-07-01 18:23:58 -060010589 if (!pass) {
10590 vkDestroyBuffer(m_device->device(), buffer, NULL);
10591 return;
10592 }
10593
10594 VkDeviceMemory mem;
10595 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem);
10596 ASSERT_VK_SUCCESS(err);
10597 err = vkBindBufferMemory(m_device->device(), buffer, mem, 0);
10598 ASSERT_VK_SUCCESS(err);
10599
10600 VkDescriptorBufferInfo buff_info = {};
10601 buff_info.buffer = buffer;
10602 // First make offset 1 larger than buffer size
10603 buff_info.offset = 257;
10604 buff_info.range = VK_WHOLE_SIZE;
10605 VkWriteDescriptorSet descriptor_write = {};
10606 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
10607 descriptor_write.dstBinding = 0;
10608 descriptor_write.descriptorCount = 1;
10609 descriptor_write.pTexelBufferView = nullptr;
10610 descriptor_write.pBufferInfo = &buff_info;
10611 descriptor_write.pImageInfo = nullptr;
10612
10613 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
10614 descriptor_write.dstSet = descriptor_set;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010615 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " offset of 257 is greater than buffer ");
Tobin Ehlis585f66d2016-07-01 18:23:58 -060010616
10617 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
10618
10619 m_errorMonitor->VerifyFound();
10620 // Now cause error due to range of 0
10621 buff_info.offset = 0;
10622 buff_info.range = 0;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010623 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
10624 " range is not VK_WHOLE_SIZE and is zero, which is not allowed.");
Tobin Ehlis585f66d2016-07-01 18:23:58 -060010625
10626 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
10627
10628 m_errorMonitor->VerifyFound();
10629 // Now cause error due to range exceeding buffer size - offset
10630 buff_info.offset = 128;
10631 buff_info.range = 200;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010632 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 -060010633
10634 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
10635
10636 m_errorMonitor->VerifyFound();
Mark Lobodzinski4bb54092016-07-06 14:27:19 -060010637 vkFreeMemory(m_device->device(), mem, NULL);
Tobin Ehlis585f66d2016-07-01 18:23:58 -060010638 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
10639 vkDestroyBuffer(m_device->device(), buffer, NULL);
10640 vkFreeDescriptorSets(m_device->device(), ds_pool, 1, &descriptor_set);
10641 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
10642}
10643
Tobin Ehlis2fc296b2016-06-15 14:05:27 -060010644TEST_F(VkLayerTest, DSAspectBitsErrors) {
10645 // TODO : Initially only catching case where DEPTH & STENCIL aspect bits
10646 // are set, but could expand this test to hit more cases.
10647 TEST_DESCRIPTION("Attempt to update descriptor sets for images "
10648 "that do not have correct aspect bits sets.");
10649 VkResult err;
10650
10651 ASSERT_NO_FATAL_FAILURE(InitState());
10652 VkDescriptorPoolSize ds_type_count = {};
10653 ds_type_count.type = VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT;
10654 ds_type_count.descriptorCount = 1;
10655
10656 VkDescriptorPoolCreateInfo ds_pool_ci = {};
10657 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
10658 ds_pool_ci.pNext = NULL;
10659 ds_pool_ci.maxSets = 5;
10660 ds_pool_ci.poolSizeCount = 1;
10661 ds_pool_ci.pPoolSizes = &ds_type_count;
10662
10663 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010664 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis2fc296b2016-06-15 14:05:27 -060010665 ASSERT_VK_SUCCESS(err);
10666
10667 VkDescriptorSetLayoutBinding dsl_binding = {};
10668 dsl_binding.binding = 0;
10669 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT;
10670 dsl_binding.descriptorCount = 1;
10671 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
10672 dsl_binding.pImmutableSamplers = NULL;
10673
10674 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
10675 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
10676 ds_layout_ci.pNext = NULL;
10677 ds_layout_ci.bindingCount = 1;
10678 ds_layout_ci.pBindings = &dsl_binding;
10679 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010680 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis2fc296b2016-06-15 14:05:27 -060010681 ASSERT_VK_SUCCESS(err);
10682
10683 VkDescriptorSet descriptor_set = {};
10684 VkDescriptorSetAllocateInfo alloc_info = {};
10685 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
10686 alloc_info.descriptorSetCount = 1;
10687 alloc_info.descriptorPool = ds_pool;
10688 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010689 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
Tobin Ehlis2fc296b2016-06-15 14:05:27 -060010690 ASSERT_VK_SUCCESS(err);
10691
10692 // Create an image to be used for invalid updates
10693 VkImageCreateInfo image_ci = {};
10694 image_ci.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
10695 image_ci.imageType = VK_IMAGE_TYPE_2D;
10696 image_ci.format = VK_FORMAT_D24_UNORM_S8_UINT;
10697 image_ci.extent.width = 64;
10698 image_ci.extent.height = 64;
10699 image_ci.extent.depth = 1;
10700 image_ci.mipLevels = 1;
10701 image_ci.arrayLayers = 1;
10702 image_ci.samples = VK_SAMPLE_COUNT_1_BIT;
10703 image_ci.tiling = VK_IMAGE_TILING_LINEAR;
10704 image_ci.initialLayout = VK_IMAGE_LAYOUT_PREINITIALIZED;
10705 image_ci.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
10706 image_ci.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
10707 VkImage image;
10708 err = vkCreateImage(m_device->device(), &image_ci, NULL, &image);
10709 ASSERT_VK_SUCCESS(err);
10710 // Bind memory to image
10711 VkMemoryRequirements mem_reqs;
10712 VkDeviceMemory image_mem;
10713 bool pass;
10714 VkMemoryAllocateInfo mem_alloc = {};
10715 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
10716 mem_alloc.pNext = NULL;
10717 mem_alloc.allocationSize = 0;
10718 mem_alloc.memoryTypeIndex = 0;
10719 vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs);
10720 mem_alloc.allocationSize = mem_reqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010721 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0);
Tobin Ehlis2fc296b2016-06-15 14:05:27 -060010722 ASSERT_TRUE(pass);
10723 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &image_mem);
10724 ASSERT_VK_SUCCESS(err);
10725 err = vkBindImageMemory(m_device->device(), image, image_mem, 0);
10726 ASSERT_VK_SUCCESS(err);
10727 // Now create view for image
10728 VkImageViewCreateInfo image_view_ci = {};
10729 image_view_ci.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
10730 image_view_ci.image = image;
10731 image_view_ci.format = VK_FORMAT_D24_UNORM_S8_UINT;
10732 image_view_ci.viewType = VK_IMAGE_VIEW_TYPE_2D;
10733 image_view_ci.subresourceRange.layerCount = 1;
10734 image_view_ci.subresourceRange.baseArrayLayer = 0;
10735 image_view_ci.subresourceRange.levelCount = 1;
10736 // Setting both depth & stencil aspect bits is illegal for descriptor
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010737 image_view_ci.subresourceRange.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT;
Tobin Ehlis2fc296b2016-06-15 14:05:27 -060010738
10739 VkImageView image_view;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010740 err = vkCreateImageView(m_device->device(), &image_view_ci, NULL, &image_view);
Tobin Ehlis2fc296b2016-06-15 14:05:27 -060010741 ASSERT_VK_SUCCESS(err);
10742
10743 VkDescriptorImageInfo img_info = {};
10744 img_info.imageView = image_view;
10745 VkWriteDescriptorSet descriptor_write = {};
10746 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
10747 descriptor_write.dstBinding = 0;
10748 descriptor_write.descriptorCount = 1;
10749 descriptor_write.pTexelBufferView = NULL;
10750 descriptor_write.pBufferInfo = NULL;
10751 descriptor_write.pImageInfo = &img_info;
10752 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT;
10753 descriptor_write.dstSet = descriptor_set;
10754 const char *error_msg = " please only set either VK_IMAGE_ASPECT_DEPTH_BIT "
10755 "or VK_IMAGE_ASPECT_STENCIL_BIT ";
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010756 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, error_msg);
Tobin Ehlis2fc296b2016-06-15 14:05:27 -060010757
10758 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
10759
10760 m_errorMonitor->VerifyFound();
10761 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
10762 vkDestroyImage(m_device->device(), image, NULL);
10763 vkFreeMemory(m_device->device(), image_mem, NULL);
10764 vkDestroyImageView(m_device->device(), image_view, NULL);
10765 vkFreeDescriptorSets(m_device->device(), ds_pool, 1, &descriptor_set);
10766 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
10767}
10768
Karl Schultz6addd812016-02-02 17:17:23 -070010769TEST_F(VkLayerTest, DSTypeMismatch) {
Tobin Ehlis49eb23d2015-05-22 12:38:55 -060010770 // Create DS w/ layout of one type and attempt Update w/ mis-matched type
Karl Schultz6addd812016-02-02 17:17:23 -070010771 VkResult err;
Tobin Ehlis3b780662015-05-28 12:11:26 -060010772
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010773 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
10774 " binding #0 with type VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER but update "
10775 "type is VK_DESCRIPTOR_TYPE_SAMPLER");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060010776
Tobin Ehlis3b780662015-05-28 12:11:26 -060010777 ASSERT_NO_FATAL_FAILURE(InitState());
Karl Schultz6addd812016-02-02 17:17:23 -070010778 // VkDescriptorSetObj descriptorSet(m_device);
Chia-I Wu1b99bb22015-10-27 19:25:11 +080010779 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010780 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
10781 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -060010782
10783 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010784 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
10785 ds_pool_ci.pNext = NULL;
10786 ds_pool_ci.maxSets = 1;
10787 ds_pool_ci.poolSizeCount = 1;
10788 ds_pool_ci.pPoolSizes = &ds_type_count;
Tony Barboureb254902015-07-15 12:50:33 -060010789
Tobin Ehlis3b780662015-05-28 12:11:26 -060010790 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010791 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis3b780662015-05-28 12:11:26 -060010792 ASSERT_VK_SUCCESS(err);
Tony Barboureb254902015-07-15 12:50:33 -060010793 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010794 dsl_binding.binding = 0;
10795 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
10796 dsl_binding.descriptorCount = 1;
10797 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
10798 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis3b780662015-05-28 12:11:26 -060010799
Tony Barboureb254902015-07-15 12:50:33 -060010800 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010801 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
10802 ds_layout_ci.pNext = NULL;
10803 ds_layout_ci.bindingCount = 1;
10804 ds_layout_ci.pBindings = &dsl_binding;
Tony Barboureb254902015-07-15 12:50:33 -060010805
Tobin Ehlis3b780662015-05-28 12:11:26 -060010806 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010807 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis3b780662015-05-28 12:11:26 -060010808 ASSERT_VK_SUCCESS(err);
10809
10810 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080010811 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +080010812 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -070010813 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -060010814 alloc_info.descriptorPool = ds_pool;
10815 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010816 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis3b780662015-05-28 12:11:26 -060010817 ASSERT_VK_SUCCESS(err);
Tobin Ehlis3b780662015-05-28 12:11:26 -060010818
Tobin Ehlis30db8f82016-05-05 08:19:48 -060010819 VkSamplerCreateInfo sampler_ci = {};
10820 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
10821 sampler_ci.pNext = NULL;
10822 sampler_ci.magFilter = VK_FILTER_NEAREST;
10823 sampler_ci.minFilter = VK_FILTER_NEAREST;
10824 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
10825 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
10826 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
10827 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
10828 sampler_ci.mipLodBias = 1.0;
10829 sampler_ci.anisotropyEnable = VK_FALSE;
10830 sampler_ci.maxAnisotropy = 1;
10831 sampler_ci.compareEnable = VK_FALSE;
10832 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
10833 sampler_ci.minLod = 1.0;
10834 sampler_ci.maxLod = 1.0;
10835 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
10836 sampler_ci.unnormalizedCoordinates = VK_FALSE;
10837 VkSampler sampler;
10838 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
10839 ASSERT_VK_SUCCESS(err);
10840
10841 VkDescriptorImageInfo info = {};
10842 info.sampler = sampler;
Chia-I Wu9d00ed72015-05-25 16:27:55 +080010843
10844 VkWriteDescriptorSet descriptor_write;
10845 memset(&descriptor_write, 0, sizeof(descriptor_write));
10846 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080010847 descriptor_write.dstSet = descriptorSet;
Chia-I Wud50a7d72015-10-26 20:48:51 +080010848 descriptor_write.descriptorCount = 1;
Tobin Ehlis3b780662015-05-28 12:11:26 -060010849 // This is a mismatched type for the layout which expects BUFFER
Chia-I Wu9d00ed72015-05-25 16:27:55 +080010850 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
Courtney Goeltzenleuchter4cb6d922015-10-23 13:38:14 -060010851 descriptor_write.pImageInfo = &info;
Chia-I Wu9d00ed72015-05-25 16:27:55 +080010852
10853 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
10854
Chris Forbes8f36a8a2016-04-07 13:21:07 +120010855 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -060010856
Chia-I Wuf7458c52015-10-26 21:10:41 +080010857 vkDestroySampler(m_device->device(), sampler, NULL);
10858 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
10859 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis49eb23d2015-05-22 12:38:55 -060010860}
10861
Karl Schultz6addd812016-02-02 17:17:23 -070010862TEST_F(VkLayerTest, DSUpdateOutOfBounds) {
Tobin Ehlis49eb23d2015-05-22 12:38:55 -060010863 // For overlapping Update, have arrayIndex exceed that of layout
Karl Schultz6addd812016-02-02 17:17:23 -070010864 VkResult err;
Tobin Ehlis3b780662015-05-28 12:11:26 -060010865
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010866 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
10867 " binding #0 with 1 total descriptors but update of 1 descriptors "
10868 "starting at binding offset of 0 combined with update array element "
10869 "offset of 1 oversteps the size of this descriptor set.");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060010870
Tobin Ehlis3b780662015-05-28 12:11:26 -060010871 ASSERT_NO_FATAL_FAILURE(InitState());
Karl Schultz6addd812016-02-02 17:17:23 -070010872 // VkDescriptorSetObj descriptorSet(m_device);
Chia-I Wu1b99bb22015-10-27 19:25:11 +080010873 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010874 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
10875 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -060010876
10877 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010878 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
10879 ds_pool_ci.pNext = NULL;
10880 ds_pool_ci.maxSets = 1;
10881 ds_pool_ci.poolSizeCount = 1;
10882 ds_pool_ci.pPoolSizes = &ds_type_count;
Tony Barboureb254902015-07-15 12:50:33 -060010883
Tobin Ehlis3b780662015-05-28 12:11:26 -060010884 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010885 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis3b780662015-05-28 12:11:26 -060010886 ASSERT_VK_SUCCESS(err);
Tobin Ehlis3b780662015-05-28 12:11:26 -060010887
Tony Barboureb254902015-07-15 12:50:33 -060010888 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010889 dsl_binding.binding = 0;
10890 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
10891 dsl_binding.descriptorCount = 1;
10892 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
10893 dsl_binding.pImmutableSamplers = NULL;
Tony Barboureb254902015-07-15 12:50:33 -060010894
10895 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010896 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
10897 ds_layout_ci.pNext = NULL;
10898 ds_layout_ci.bindingCount = 1;
10899 ds_layout_ci.pBindings = &dsl_binding;
Tony Barboureb254902015-07-15 12:50:33 -060010900
Tobin Ehlis3b780662015-05-28 12:11:26 -060010901 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010902 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis3b780662015-05-28 12:11:26 -060010903 ASSERT_VK_SUCCESS(err);
10904
10905 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080010906 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +080010907 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -070010908 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -060010909 alloc_info.descriptorPool = ds_pool;
10910 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010911 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis3b780662015-05-28 12:11:26 -060010912 ASSERT_VK_SUCCESS(err);
Tobin Ehlis3b780662015-05-28 12:11:26 -060010913
Tobin Ehlis30db8f82016-05-05 08:19:48 -060010914 // Correctly update descriptor to avoid "NOT_UPDATED" error
10915 VkDescriptorBufferInfo buff_info = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010916 buff_info.buffer = VkBuffer(0); // Don't care about buffer handle for this test
Tobin Ehlis30db8f82016-05-05 08:19:48 -060010917 buff_info.offset = 0;
10918 buff_info.range = 1024;
Chia-I Wu9d00ed72015-05-25 16:27:55 +080010919
10920 VkWriteDescriptorSet descriptor_write;
10921 memset(&descriptor_write, 0, sizeof(descriptor_write));
10922 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080010923 descriptor_write.dstSet = descriptorSet;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010924 descriptor_write.dstArrayElement = 1; /* This index out of bounds for the update */
Chia-I Wud50a7d72015-10-26 20:48:51 +080010925 descriptor_write.descriptorCount = 1;
Tobin Ehlis0a43bde2016-05-03 08:31:08 -060010926 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
10927 descriptor_write.pBufferInfo = &buff_info;
Chia-I Wu9d00ed72015-05-25 16:27:55 +080010928
10929 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
10930
Chris Forbes8f36a8a2016-04-07 13:21:07 +120010931 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -060010932
Chia-I Wuf7458c52015-10-26 21:10:41 +080010933 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
10934 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis49eb23d2015-05-22 12:38:55 -060010935}
10936
Karl Schultz6addd812016-02-02 17:17:23 -070010937TEST_F(VkLayerTest, InvalidDSUpdateIndex) {
10938 // Create layout w/ count of 1 and attempt update to that layout w/ binding
10939 // index 2
10940 VkResult err;
Tobin Ehlis3b780662015-05-28 12:11:26 -060010941
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010942 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " does not have binding 2.");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060010943
Tobin Ehlis3b780662015-05-28 12:11:26 -060010944 ASSERT_NO_FATAL_FAILURE(InitState());
Karl Schultz6addd812016-02-02 17:17:23 -070010945 // VkDescriptorSetObj descriptorSet(m_device);
Chia-I Wu1b99bb22015-10-27 19:25:11 +080010946 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010947 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
10948 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -060010949
10950 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010951 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
10952 ds_pool_ci.pNext = NULL;
10953 ds_pool_ci.maxSets = 1;
10954 ds_pool_ci.poolSizeCount = 1;
10955 ds_pool_ci.pPoolSizes = &ds_type_count;
Courtney Goeltzenleuchterfe908d32015-09-16 16:12:45 -060010956
Tobin Ehlis3b780662015-05-28 12:11:26 -060010957 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010958 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis3b780662015-05-28 12:11:26 -060010959 ASSERT_VK_SUCCESS(err);
Tobin Ehlis3b780662015-05-28 12:11:26 -060010960
Tony Barboureb254902015-07-15 12:50:33 -060010961 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010962 dsl_binding.binding = 0;
10963 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
10964 dsl_binding.descriptorCount = 1;
10965 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
10966 dsl_binding.pImmutableSamplers = NULL;
Tony Barboureb254902015-07-15 12:50:33 -060010967
10968 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010969 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
10970 ds_layout_ci.pNext = NULL;
10971 ds_layout_ci.bindingCount = 1;
10972 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlis3b780662015-05-28 12:11:26 -060010973 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010974 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis3b780662015-05-28 12:11:26 -060010975 ASSERT_VK_SUCCESS(err);
10976
10977 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080010978 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +080010979 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -070010980 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -060010981 alloc_info.descriptorPool = ds_pool;
10982 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010983 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis3b780662015-05-28 12:11:26 -060010984 ASSERT_VK_SUCCESS(err);
Tobin Ehlis3b780662015-05-28 12:11:26 -060010985
Tony Barboureb254902015-07-15 12:50:33 -060010986 VkSamplerCreateInfo sampler_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010987 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
10988 sampler_ci.pNext = NULL;
10989 sampler_ci.magFilter = VK_FILTER_NEAREST;
10990 sampler_ci.minFilter = VK_FILTER_NEAREST;
10991 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
10992 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
10993 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
10994 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
10995 sampler_ci.mipLodBias = 1.0;
10996 sampler_ci.anisotropyEnable = VK_FALSE;
10997 sampler_ci.maxAnisotropy = 1;
10998 sampler_ci.compareEnable = VK_FALSE;
10999 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
11000 sampler_ci.minLod = 1.0;
11001 sampler_ci.maxLod = 1.0;
11002 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
11003 sampler_ci.unnormalizedCoordinates = VK_FALSE;
Tony Barboureb254902015-07-15 12:50:33 -060011004
Tobin Ehlis3b780662015-05-28 12:11:26 -060011005 VkSampler sampler;
Chia-I Wuf7458c52015-10-26 21:10:41 +080011006 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
Tobin Ehlis3b780662015-05-28 12:11:26 -060011007 ASSERT_VK_SUCCESS(err);
Chia-I Wu9d00ed72015-05-25 16:27:55 +080011008
Courtney Goeltzenleuchter4cb6d922015-10-23 13:38:14 -060011009 VkDescriptorImageInfo info = {};
11010 info.sampler = sampler;
Chia-I Wu9d00ed72015-05-25 16:27:55 +080011011
11012 VkWriteDescriptorSet descriptor_write;
11013 memset(&descriptor_write, 0, sizeof(descriptor_write));
11014 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080011015 descriptor_write.dstSet = descriptorSet;
11016 descriptor_write.dstBinding = 2;
Chia-I Wud50a7d72015-10-26 20:48:51 +080011017 descriptor_write.descriptorCount = 1;
Tobin Ehlis3b780662015-05-28 12:11:26 -060011018 // This is the wrong type, but out of bounds will be flagged first
Chia-I Wu9d00ed72015-05-25 16:27:55 +080011019 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
Courtney Goeltzenleuchter4cb6d922015-10-23 13:38:14 -060011020 descriptor_write.pImageInfo = &info;
Chia-I Wu9d00ed72015-05-25 16:27:55 +080011021
11022 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
11023
Chris Forbes8f36a8a2016-04-07 13:21:07 +120011024 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -060011025
Chia-I Wuf7458c52015-10-26 21:10:41 +080011026 vkDestroySampler(m_device->device(), sampler, NULL);
11027 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
11028 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis49eb23d2015-05-22 12:38:55 -060011029}
11030
Karl Schultz6addd812016-02-02 17:17:23 -070011031TEST_F(VkLayerTest, InvalidDSUpdateStruct) {
11032 // Call UpdateDS w/ struct type other than valid VK_STRUCTUR_TYPE_UPDATE_*
11033 // types
11034 VkResult err;
Tobin Ehlis3b780662015-05-28 12:11:26 -060011035
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011036 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 -060011037
Tobin Ehlis3b780662015-05-28 12:11:26 -060011038 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinski209b5292015-09-17 09:44:05 -060011039
Chia-I Wu1b99bb22015-10-27 19:25:11 +080011040 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011041 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
11042 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -060011043
11044 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011045 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
11046 ds_pool_ci.pNext = NULL;
11047 ds_pool_ci.maxSets = 1;
11048 ds_pool_ci.poolSizeCount = 1;
11049 ds_pool_ci.pPoolSizes = &ds_type_count;
Courtney Goeltzenleuchterfe908d32015-09-16 16:12:45 -060011050
Tobin Ehlis3b780662015-05-28 12:11:26 -060011051 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011052 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis3b780662015-05-28 12:11:26 -060011053 ASSERT_VK_SUCCESS(err);
Tony Barboureb254902015-07-15 12:50:33 -060011054 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011055 dsl_binding.binding = 0;
11056 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
11057 dsl_binding.descriptorCount = 1;
11058 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
11059 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis3b780662015-05-28 12:11:26 -060011060
Tony Barboureb254902015-07-15 12:50:33 -060011061 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011062 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
11063 ds_layout_ci.pNext = NULL;
11064 ds_layout_ci.bindingCount = 1;
11065 ds_layout_ci.pBindings = &dsl_binding;
Tony Barboureb254902015-07-15 12:50:33 -060011066
Tobin Ehlis3b780662015-05-28 12:11:26 -060011067 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011068 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis3b780662015-05-28 12:11:26 -060011069 ASSERT_VK_SUCCESS(err);
11070
11071 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080011072 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +080011073 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -070011074 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -060011075 alloc_info.descriptorPool = ds_pool;
11076 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011077 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis3b780662015-05-28 12:11:26 -060011078 ASSERT_VK_SUCCESS(err);
Tobin Ehlis3b780662015-05-28 12:11:26 -060011079
Tony Barboureb254902015-07-15 12:50:33 -060011080 VkSamplerCreateInfo sampler_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011081 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
11082 sampler_ci.pNext = NULL;
11083 sampler_ci.magFilter = VK_FILTER_NEAREST;
11084 sampler_ci.minFilter = VK_FILTER_NEAREST;
11085 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
11086 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
11087 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
11088 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
11089 sampler_ci.mipLodBias = 1.0;
11090 sampler_ci.anisotropyEnable = VK_FALSE;
11091 sampler_ci.maxAnisotropy = 1;
11092 sampler_ci.compareEnable = VK_FALSE;
11093 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
11094 sampler_ci.minLod = 1.0;
11095 sampler_ci.maxLod = 1.0;
11096 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
11097 sampler_ci.unnormalizedCoordinates = VK_FALSE;
Tobin Ehlis3b780662015-05-28 12:11:26 -060011098 VkSampler sampler;
Chia-I Wuf7458c52015-10-26 21:10:41 +080011099 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
Tobin Ehlis3b780662015-05-28 12:11:26 -060011100 ASSERT_VK_SUCCESS(err);
Chia-I Wu9d00ed72015-05-25 16:27:55 +080011101
Courtney Goeltzenleuchter4cb6d922015-10-23 13:38:14 -060011102 VkDescriptorImageInfo info = {};
11103 info.sampler = sampler;
Chia-I Wu9d00ed72015-05-25 16:27:55 +080011104
11105 VkWriteDescriptorSet descriptor_write;
11106 memset(&descriptor_write, 0, sizeof(descriptor_write));
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011107 descriptor_write.sType = (VkStructureType)0x99999999; /* Intentionally broken struct type */
Chia-I Wu3432a0c2015-10-27 18:04:07 +080011108 descriptor_write.dstSet = descriptorSet;
Chia-I Wud50a7d72015-10-26 20:48:51 +080011109 descriptor_write.descriptorCount = 1;
Tobin Ehlis3b780662015-05-28 12:11:26 -060011110 // This is the wrong type, but out of bounds will be flagged first
Chia-I Wu9d00ed72015-05-25 16:27:55 +080011111 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
Courtney Goeltzenleuchter4cb6d922015-10-23 13:38:14 -060011112 descriptor_write.pImageInfo = &info;
Chia-I Wu9d00ed72015-05-25 16:27:55 +080011113
11114 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
11115
Chris Forbes8f36a8a2016-04-07 13:21:07 +120011116 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -060011117
Chia-I Wuf7458c52015-10-26 21:10:41 +080011118 vkDestroySampler(m_device->device(), sampler, NULL);
11119 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
11120 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis49eb23d2015-05-22 12:38:55 -060011121}
11122
Karl Schultz6addd812016-02-02 17:17:23 -070011123TEST_F(VkLayerTest, SampleDescriptorUpdateError) {
Tobin Ehlisa1c28562015-10-23 16:00:08 -060011124 // Create a single Sampler descriptor and send it an invalid Sampler
Karl Schultz6addd812016-02-02 17:17:23 -070011125 VkResult err;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060011126
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011127 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
11128 "Attempted write update to sampler descriptor with invalid sampler");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060011129
Tobin Ehlisa1c28562015-10-23 16:00:08 -060011130 ASSERT_NO_FATAL_FAILURE(InitState());
Karl Schultz6addd812016-02-02 17:17:23 -070011131 // TODO : Farm Descriptor setup code to helper function(s) to reduce copied
11132 // code
Chia-I Wu1b99bb22015-10-27 19:25:11 +080011133 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011134 ds_type_count.type = VK_DESCRIPTOR_TYPE_SAMPLER;
11135 ds_type_count.descriptorCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060011136
11137 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011138 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
11139 ds_pool_ci.pNext = NULL;
11140 ds_pool_ci.maxSets = 1;
11141 ds_pool_ci.poolSizeCount = 1;
11142 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060011143
11144 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011145 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060011146 ASSERT_VK_SUCCESS(err);
11147
11148 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011149 dsl_binding.binding = 0;
11150 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
11151 dsl_binding.descriptorCount = 1;
11152 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
11153 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060011154
11155 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011156 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
11157 ds_layout_ci.pNext = NULL;
11158 ds_layout_ci.bindingCount = 1;
11159 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060011160 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011161 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060011162 ASSERT_VK_SUCCESS(err);
11163
11164 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080011165 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +080011166 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -070011167 alloc_info.descriptorSetCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060011168 alloc_info.descriptorPool = ds_pool;
11169 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011170 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060011171 ASSERT_VK_SUCCESS(err);
11172
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011173 VkSampler sampler = (VkSampler)((size_t)0xbaadbeef); // Sampler with invalid handle
Tobin Ehlisa1c28562015-10-23 16:00:08 -060011174
11175 VkDescriptorImageInfo descriptor_info;
11176 memset(&descriptor_info, 0, sizeof(VkDescriptorImageInfo));
11177 descriptor_info.sampler = sampler;
11178
11179 VkWriteDescriptorSet descriptor_write;
11180 memset(&descriptor_write, 0, sizeof(descriptor_write));
11181 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080011182 descriptor_write.dstSet = descriptorSet;
11183 descriptor_write.dstBinding = 0;
Chia-I Wud50a7d72015-10-26 20:48:51 +080011184 descriptor_write.descriptorCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060011185 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
11186 descriptor_write.pImageInfo = &descriptor_info;
11187
11188 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
11189
Chris Forbes8f36a8a2016-04-07 13:21:07 +120011190 m_errorMonitor->VerifyFound();
Tobin Ehlisa1c28562015-10-23 16:00:08 -060011191
Chia-I Wuf7458c52015-10-26 21:10:41 +080011192 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
11193 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060011194}
11195
Karl Schultz6addd812016-02-02 17:17:23 -070011196TEST_F(VkLayerTest, ImageViewDescriptorUpdateError) {
11197 // Create a single combined Image/Sampler descriptor and send it an invalid
11198 // imageView
11199 VkResult err;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060011200
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011201 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Attempted write update to combined "
11202 "image sampler descriptor failed due "
11203 "to: Invalid VkImageView:");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060011204
Tobin Ehlisa1c28562015-10-23 16:00:08 -060011205 ASSERT_NO_FATAL_FAILURE(InitState());
Chia-I Wu1b99bb22015-10-27 19:25:11 +080011206 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011207 ds_type_count.type = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
11208 ds_type_count.descriptorCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060011209
11210 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011211 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
11212 ds_pool_ci.pNext = NULL;
11213 ds_pool_ci.maxSets = 1;
11214 ds_pool_ci.poolSizeCount = 1;
11215 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060011216
11217 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011218 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060011219 ASSERT_VK_SUCCESS(err);
11220
11221 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011222 dsl_binding.binding = 0;
11223 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
11224 dsl_binding.descriptorCount = 1;
11225 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
11226 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060011227
11228 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011229 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
11230 ds_layout_ci.pNext = NULL;
11231 ds_layout_ci.bindingCount = 1;
11232 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060011233 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011234 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060011235 ASSERT_VK_SUCCESS(err);
11236
11237 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080011238 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +080011239 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -070011240 alloc_info.descriptorSetCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060011241 alloc_info.descriptorPool = ds_pool;
11242 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011243 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060011244 ASSERT_VK_SUCCESS(err);
11245
11246 VkSamplerCreateInfo sampler_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011247 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
11248 sampler_ci.pNext = NULL;
11249 sampler_ci.magFilter = VK_FILTER_NEAREST;
11250 sampler_ci.minFilter = VK_FILTER_NEAREST;
11251 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
11252 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
11253 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
11254 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
11255 sampler_ci.mipLodBias = 1.0;
11256 sampler_ci.anisotropyEnable = VK_FALSE;
11257 sampler_ci.maxAnisotropy = 1;
11258 sampler_ci.compareEnable = VK_FALSE;
11259 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
11260 sampler_ci.minLod = 1.0;
11261 sampler_ci.maxLod = 1.0;
11262 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
11263 sampler_ci.unnormalizedCoordinates = VK_FALSE;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060011264
11265 VkSampler sampler;
Chia-I Wuf7458c52015-10-26 21:10:41 +080011266 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060011267 ASSERT_VK_SUCCESS(err);
11268
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011269 VkImageView view = (VkImageView)((size_t)0xbaadbeef); // invalid imageView object
Tobin Ehlisa1c28562015-10-23 16:00:08 -060011270
11271 VkDescriptorImageInfo descriptor_info;
11272 memset(&descriptor_info, 0, sizeof(VkDescriptorImageInfo));
11273 descriptor_info.sampler = sampler;
11274 descriptor_info.imageView = view;
11275
11276 VkWriteDescriptorSet descriptor_write;
11277 memset(&descriptor_write, 0, sizeof(descriptor_write));
11278 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080011279 descriptor_write.dstSet = descriptorSet;
11280 descriptor_write.dstBinding = 0;
Chia-I Wud50a7d72015-10-26 20:48:51 +080011281 descriptor_write.descriptorCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060011282 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
11283 descriptor_write.pImageInfo = &descriptor_info;
11284
11285 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
11286
Chris Forbes8f36a8a2016-04-07 13:21:07 +120011287 m_errorMonitor->VerifyFound();
Tobin Ehlisa1c28562015-10-23 16:00:08 -060011288
Chia-I Wuf7458c52015-10-26 21:10:41 +080011289 vkDestroySampler(m_device->device(), sampler, NULL);
11290 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
11291 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060011292}
11293
Karl Schultz6addd812016-02-02 17:17:23 -070011294TEST_F(VkLayerTest, CopyDescriptorUpdateErrors) {
11295 // Create DS w/ layout of 2 types, write update 1 and attempt to copy-update
11296 // into the other
11297 VkResult err;
Tobin Ehlis04356f92015-10-27 16:35:27 -060011298
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011299 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " binding #1 with type "
11300 "VK_DESCRIPTOR_TYPE_SAMPLER. Types do "
11301 "not match.");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060011302
Tobin Ehlis04356f92015-10-27 16:35:27 -060011303 ASSERT_NO_FATAL_FAILURE(InitState());
Karl Schultz6addd812016-02-02 17:17:23 -070011304 // VkDescriptorSetObj descriptorSet(m_device);
Chia-I Wu1b99bb22015-10-27 19:25:11 +080011305 VkDescriptorPoolSize ds_type_count[2] = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011306 ds_type_count[0].type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
11307 ds_type_count[0].descriptorCount = 1;
11308 ds_type_count[1].type = VK_DESCRIPTOR_TYPE_SAMPLER;
11309 ds_type_count[1].descriptorCount = 1;
Tobin Ehlis04356f92015-10-27 16:35:27 -060011310
11311 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011312 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
11313 ds_pool_ci.pNext = NULL;
11314 ds_pool_ci.maxSets = 1;
11315 ds_pool_ci.poolSizeCount = 2;
11316 ds_pool_ci.pPoolSizes = ds_type_count;
Tobin Ehlis04356f92015-10-27 16:35:27 -060011317
11318 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011319 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis04356f92015-10-27 16:35:27 -060011320 ASSERT_VK_SUCCESS(err);
11321 VkDescriptorSetLayoutBinding dsl_binding[2] = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011322 dsl_binding[0].binding = 0;
11323 dsl_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
11324 dsl_binding[0].descriptorCount = 1;
11325 dsl_binding[0].stageFlags = VK_SHADER_STAGE_ALL;
11326 dsl_binding[0].pImmutableSamplers = NULL;
11327 dsl_binding[1].binding = 1;
11328 dsl_binding[1].descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
11329 dsl_binding[1].descriptorCount = 1;
11330 dsl_binding[1].stageFlags = VK_SHADER_STAGE_ALL;
11331 dsl_binding[1].pImmutableSamplers = NULL;
Tobin Ehlis04356f92015-10-27 16:35:27 -060011332
11333 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011334 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
11335 ds_layout_ci.pNext = NULL;
11336 ds_layout_ci.bindingCount = 2;
11337 ds_layout_ci.pBindings = dsl_binding;
Tobin Ehlis04356f92015-10-27 16:35:27 -060011338
11339 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011340 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis04356f92015-10-27 16:35:27 -060011341 ASSERT_VK_SUCCESS(err);
11342
11343 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080011344 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +080011345 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -070011346 alloc_info.descriptorSetCount = 1;
Tobin Ehlis04356f92015-10-27 16:35:27 -060011347 alloc_info.descriptorPool = ds_pool;
11348 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011349 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis04356f92015-10-27 16:35:27 -060011350 ASSERT_VK_SUCCESS(err);
11351
11352 VkSamplerCreateInfo sampler_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011353 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
11354 sampler_ci.pNext = NULL;
11355 sampler_ci.magFilter = VK_FILTER_NEAREST;
11356 sampler_ci.minFilter = VK_FILTER_NEAREST;
11357 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
11358 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
11359 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
11360 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
11361 sampler_ci.mipLodBias = 1.0;
11362 sampler_ci.anisotropyEnable = VK_FALSE;
11363 sampler_ci.maxAnisotropy = 1;
11364 sampler_ci.compareEnable = VK_FALSE;
11365 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
11366 sampler_ci.minLod = 1.0;
11367 sampler_ci.maxLod = 1.0;
11368 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
11369 sampler_ci.unnormalizedCoordinates = VK_FALSE;
Tobin Ehlis04356f92015-10-27 16:35:27 -060011370
11371 VkSampler sampler;
Chia-I Wuf7458c52015-10-26 21:10:41 +080011372 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
Tobin Ehlis04356f92015-10-27 16:35:27 -060011373 ASSERT_VK_SUCCESS(err);
11374
11375 VkDescriptorImageInfo info = {};
11376 info.sampler = sampler;
11377
11378 VkWriteDescriptorSet descriptor_write;
11379 memset(&descriptor_write, 0, sizeof(VkWriteDescriptorSet));
11380 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080011381 descriptor_write.dstSet = descriptorSet;
11382 descriptor_write.dstBinding = 1; // SAMPLER binding from layout above
Chia-I Wud50a7d72015-10-26 20:48:51 +080011383 descriptor_write.descriptorCount = 1;
Tobin Ehlis04356f92015-10-27 16:35:27 -060011384 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
11385 descriptor_write.pImageInfo = &info;
11386 // This write update should succeed
11387 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
11388 // Now perform a copy update that fails due to type mismatch
11389 VkCopyDescriptorSet copy_ds_update;
11390 memset(&copy_ds_update, 0, sizeof(VkCopyDescriptorSet));
11391 copy_ds_update.sType = VK_STRUCTURE_TYPE_COPY_DESCRIPTOR_SET;
11392 copy_ds_update.srcSet = descriptorSet;
Mark Young29927482016-05-04 14:38:51 -060011393 copy_ds_update.srcBinding = 1; // Copy from SAMPLER binding
Chia-I Wu3432a0c2015-10-27 18:04:07 +080011394 copy_ds_update.dstSet = descriptorSet;
Karl Schultz6addd812016-02-02 17:17:23 -070011395 copy_ds_update.dstBinding = 0; // ERROR : copy to UNIFORM binding
Chia-I Wud50a7d72015-10-26 20:48:51 +080011396 copy_ds_update.descriptorCount = 1; // copy 1 descriptor
Tobin Ehlis04356f92015-10-27 16:35:27 -060011397 vkUpdateDescriptorSets(m_device->device(), 0, NULL, 1, &copy_ds_update);
11398
Chris Forbes8f36a8a2016-04-07 13:21:07 +120011399 m_errorMonitor->VerifyFound();
Tobin Ehlis04356f92015-10-27 16:35:27 -060011400 // Now perform a copy update that fails due to binding out of bounds
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011401 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 -060011402 memset(&copy_ds_update, 0, sizeof(VkCopyDescriptorSet));
11403 copy_ds_update.sType = VK_STRUCTURE_TYPE_COPY_DESCRIPTOR_SET;
11404 copy_ds_update.srcSet = descriptorSet;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011405 copy_ds_update.srcBinding = 3; // ERROR : Invalid binding for matching layout
Chia-I Wu3432a0c2015-10-27 18:04:07 +080011406 copy_ds_update.dstSet = descriptorSet;
11407 copy_ds_update.dstBinding = 0;
Mark Young29927482016-05-04 14:38:51 -060011408 copy_ds_update.descriptorCount = 1; // Copy 1 descriptor
Tobin Ehlis04356f92015-10-27 16:35:27 -060011409 vkUpdateDescriptorSets(m_device->device(), 0, NULL, 1, &copy_ds_update);
11410
Chris Forbes8f36a8a2016-04-07 13:21:07 +120011411 m_errorMonitor->VerifyFound();
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060011412
Tobin Ehlis04356f92015-10-27 16:35:27 -060011413 // Now perform a copy update that fails due to binding out of bounds
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011414 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " binding#1 with offset index of 1 plus "
11415 "update array offset of 0 and update of "
11416 "5 descriptors oversteps total number "
11417 "of descriptors in set: 2.");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060011418
Tobin Ehlis04356f92015-10-27 16:35:27 -060011419 memset(&copy_ds_update, 0, sizeof(VkCopyDescriptorSet));
11420 copy_ds_update.sType = VK_STRUCTURE_TYPE_COPY_DESCRIPTOR_SET;
11421 copy_ds_update.srcSet = descriptorSet;
11422 copy_ds_update.srcBinding = 1;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080011423 copy_ds_update.dstSet = descriptorSet;
11424 copy_ds_update.dstBinding = 0;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011425 copy_ds_update.descriptorCount = 5; // ERROR copy 5 descriptors (out of bounds for layout)
Tobin Ehlis04356f92015-10-27 16:35:27 -060011426 vkUpdateDescriptorSets(m_device->device(), 0, NULL, 1, &copy_ds_update);
11427
Chris Forbes8f36a8a2016-04-07 13:21:07 +120011428 m_errorMonitor->VerifyFound();
Tobin Ehlis04356f92015-10-27 16:35:27 -060011429
Chia-I Wuf7458c52015-10-26 21:10:41 +080011430 vkDestroySampler(m_device->device(), sampler, NULL);
11431 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
11432 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis04356f92015-10-27 16:35:27 -060011433}
11434
Karl Schultz6addd812016-02-02 17:17:23 -070011435TEST_F(VkLayerTest, NumSamplesMismatch) {
11436 // Create CommandBuffer where MSAA samples doesn't match RenderPass
11437 // sampleCount
11438 VkResult err;
Tobin Ehlis3b780662015-05-28 12:11:26 -060011439
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011440 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Num samples mismatch! ");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060011441
Tobin Ehlis3b780662015-05-28 12:11:26 -060011442 ASSERT_NO_FATAL_FAILURE(InitState());
11443 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chia-I Wu1b99bb22015-10-27 19:25:11 +080011444 VkDescriptorPoolSize ds_type_count = {};
Tony Barboureb254902015-07-15 12:50:33 -060011445 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Chia-I Wud50a7d72015-10-26 20:48:51 +080011446 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -060011447
11448 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011449 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
11450 ds_pool_ci.pNext = NULL;
11451 ds_pool_ci.maxSets = 1;
11452 ds_pool_ci.poolSizeCount = 1;
11453 ds_pool_ci.pPoolSizes = &ds_type_count;
Courtney Goeltzenleuchterfe908d32015-09-16 16:12:45 -060011454
Tobin Ehlis3b780662015-05-28 12:11:26 -060011455 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011456 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis3b780662015-05-28 12:11:26 -060011457 ASSERT_VK_SUCCESS(err);
Tobin Ehlis3b780662015-05-28 12:11:26 -060011458
Tony Barboureb254902015-07-15 12:50:33 -060011459 VkDescriptorSetLayoutBinding dsl_binding = {};
Chia-I Wud46e6ae2015-10-31 00:31:16 +080011460 dsl_binding.binding = 0;
Tony Barboureb254902015-07-15 12:50:33 -060011461 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Chia-I Wu02124482015-11-06 06:42:02 +080011462 dsl_binding.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -060011463 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
11464 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis3b780662015-05-28 12:11:26 -060011465
Tony Barboureb254902015-07-15 12:50:33 -060011466 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
11467 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
11468 ds_layout_ci.pNext = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +080011469 ds_layout_ci.bindingCount = 1;
Jon Ashburn6e23c1f2015-12-30 18:01:16 -070011470 ds_layout_ci.pBindings = &dsl_binding;
Tony Barboureb254902015-07-15 12:50:33 -060011471
Tobin Ehlis3b780662015-05-28 12:11:26 -060011472 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011473 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis3b780662015-05-28 12:11:26 -060011474 ASSERT_VK_SUCCESS(err);
11475
11476 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080011477 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +080011478 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -070011479 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -060011480 alloc_info.descriptorPool = ds_pool;
11481 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011482 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis3b780662015-05-28 12:11:26 -060011483 ASSERT_VK_SUCCESS(err);
11484
Tony Barboureb254902015-07-15 12:50:33 -060011485 VkPipelineMultisampleStateCreateInfo pipe_ms_state_ci = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011486 pipe_ms_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
Karl Schultz6addd812016-02-02 17:17:23 -070011487 pipe_ms_state_ci.pNext = NULL;
11488 pipe_ms_state_ci.rasterizationSamples = VK_SAMPLE_COUNT_4_BIT;
11489 pipe_ms_state_ci.sampleShadingEnable = 0;
11490 pipe_ms_state_ci.minSampleShading = 1.0;
11491 pipe_ms_state_ci.pSampleMask = NULL;
Tobin Ehlis3b780662015-05-28 12:11:26 -060011492
Tony Barboureb254902015-07-15 12:50:33 -060011493 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011494 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
11495 pipeline_layout_ci.pNext = NULL;
11496 pipeline_layout_ci.setLayoutCount = 1;
11497 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlis3b780662015-05-28 12:11:26 -060011498
11499 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011500 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis3b780662015-05-28 12:11:26 -060011501 ASSERT_VK_SUCCESS(err);
11502
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011503 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
11504 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this); // We shouldn't need a fragment shader
11505 // but add it to be able to run on more devices
Tony Barbour62e1a5b2015-08-06 10:16:07 -060011506 VkPipelineObj pipe(m_device);
11507 pipe.AddShader(&vs);
Tony Barbour1c94d372015-08-06 11:21:08 -060011508 pipe.AddShader(&fs);
Mark Youngc89c6312016-03-31 16:03:20 -060011509 pipe.AddColorAttachment();
Tony Barbour62e1a5b2015-08-06 10:16:07 -060011510 pipe.SetMSAA(&pipe_ms_state_ci);
11511 pipe.CreateVKPipeline(pipeline_layout, renderPass());
Tobin Ehlis3b780662015-05-28 12:11:26 -060011512
Tony Barbourfe3351b2015-07-28 10:17:20 -060011513 BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011514 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Tobin Ehlis3b780662015-05-28 12:11:26 -060011515
Mark Young29927482016-05-04 14:38:51 -060011516 // Render triangle (the error should trigger on the attempt to draw).
11517 Draw(3, 1, 0, 0);
11518
11519 // Finalize recording of the command buffer
11520 EndCommandBuffer();
11521
Chris Forbes8f36a8a2016-04-07 13:21:07 +120011522 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -060011523
Chia-I Wuf7458c52015-10-26 21:10:41 +080011524 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
11525 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
11526 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis49eb23d2015-05-22 12:38:55 -060011527}
Mark Young29927482016-05-04 14:38:51 -060011528
Tobin Ehlis85aa15a2016-06-15 10:52:37 -060011529TEST_F(VkLayerTest, RenderPassIncompatible) {
11530 TEST_DESCRIPTION("Hit RenderPass incompatible cases. "
11531 "Initial case is drawing with an active renderpass that's "
11532 "not compatible with the bound PSO's creation renderpass");
11533 VkResult err;
11534
11535 ASSERT_NO_FATAL_FAILURE(InitState());
11536 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
11537
11538 VkDescriptorSetLayoutBinding dsl_binding = {};
11539 dsl_binding.binding = 0;
11540 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
11541 dsl_binding.descriptorCount = 1;
11542 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
11543 dsl_binding.pImmutableSamplers = NULL;
11544
11545 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
11546 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
11547 ds_layout_ci.pNext = NULL;
11548 ds_layout_ci.bindingCount = 1;
11549 ds_layout_ci.pBindings = &dsl_binding;
11550
11551 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011552 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis85aa15a2016-06-15 10:52:37 -060011553 ASSERT_VK_SUCCESS(err);
11554
11555 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
11556 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
11557 pipeline_layout_ci.pNext = NULL;
11558 pipeline_layout_ci.setLayoutCount = 1;
11559 pipeline_layout_ci.pSetLayouts = &ds_layout;
11560
11561 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011562 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis85aa15a2016-06-15 10:52:37 -060011563 ASSERT_VK_SUCCESS(err);
11564
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011565 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
11566 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this); // We shouldn't need a fragment shader
11567 // but add it to be able to run on more devices
Tobin Ehlis85aa15a2016-06-15 10:52:37 -060011568 // Create a renderpass that will be incompatible with default renderpass
11569 VkAttachmentReference attach = {};
11570 attach.layout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
11571 VkAttachmentReference color_att = {};
11572 color_att.layout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
11573 VkSubpassDescription subpass = {};
11574 subpass.inputAttachmentCount = 1;
11575 subpass.pInputAttachments = &attach;
11576 subpass.colorAttachmentCount = 1;
11577 subpass.pColorAttachments = &color_att;
11578 VkRenderPassCreateInfo rpci = {};
11579 rpci.subpassCount = 1;
11580 rpci.pSubpasses = &subpass;
11581 rpci.attachmentCount = 1;
11582 VkAttachmentDescription attach_desc = {};
11583 attach_desc.samples = VK_SAMPLE_COUNT_1_BIT;
Cody Northropbd16af12016-06-21 09:25:48 -060011584 // Format incompatible with PSO RP color attach format B8G8R8A8_UNORM
11585 attach_desc.format = VK_FORMAT_R8G8B8A8_UNORM;
Tobin Ehlis85aa15a2016-06-15 10:52:37 -060011586 rpci.pAttachments = &attach_desc;
11587 rpci.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
11588 VkRenderPass rp;
11589 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
11590 VkPipelineObj pipe(m_device);
11591 pipe.AddShader(&vs);
11592 pipe.AddShader(&fs);
11593 pipe.AddColorAttachment();
11594 VkViewport view_port = {};
11595 m_viewports.push_back(view_port);
11596 pipe.SetViewport(m_viewports);
11597 VkRect2D rect = {};
11598 m_scissors.push_back(rect);
11599 pipe.SetScissor(m_scissors);
11600 pipe.CreateVKPipeline(pipeline_layout, renderPass());
11601
11602 VkCommandBufferInheritanceInfo cbii = {};
11603 cbii.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_INHERITANCE_INFO;
11604 cbii.renderPass = rp;
11605 cbii.subpass = 0;
11606 VkCommandBufferBeginInfo cbbi = {};
11607 cbbi.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
11608 cbbi.pInheritanceInfo = &cbii;
11609 vkBeginCommandBuffer(m_commandBuffer->handle(), &cbbi);
11610 VkRenderPassBeginInfo rpbi = {};
11611 rpbi.sType = VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO;
11612 rpbi.framebuffer = m_framebuffer;
11613 rpbi.renderPass = rp;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011614 vkCmdBeginRenderPass(m_commandBuffer->GetBufferHandle(), &rpbi, VK_SUBPASS_CONTENTS_INLINE);
11615 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Tobin Ehlis85aa15a2016-06-15 10:52:37 -060011616
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011617 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " is incompatible w/ gfx pipeline ");
Tobin Ehlis85aa15a2016-06-15 10:52:37 -060011618 // Render triangle (the error should trigger on the attempt to draw).
11619 Draw(3, 1, 0, 0);
11620
11621 // Finalize recording of the command buffer
11622 EndCommandBuffer();
11623
11624 m_errorMonitor->VerifyFound();
11625
11626 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
11627 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
11628 vkDestroyRenderPass(m_device->device(), rp, NULL);
11629}
11630
Mark Youngc89c6312016-03-31 16:03:20 -060011631TEST_F(VkLayerTest, NumBlendAttachMismatch) {
11632 // Create Pipeline where the number of blend attachments doesn't match the
11633 // number of color attachments. In this case, we don't add any color
11634 // blend attachments even though we have a color attachment.
11635 VkResult err;
11636
11637 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011638 "Render pass subpass 0 mismatch with blending state defined and blend state attachment");
Mark Youngc89c6312016-03-31 16:03:20 -060011639
11640 ASSERT_NO_FATAL_FAILURE(InitState());
11641 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
11642 VkDescriptorPoolSize ds_type_count = {};
11643 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
11644 ds_type_count.descriptorCount = 1;
11645
11646 VkDescriptorPoolCreateInfo ds_pool_ci = {};
11647 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
11648 ds_pool_ci.pNext = NULL;
11649 ds_pool_ci.maxSets = 1;
11650 ds_pool_ci.poolSizeCount = 1;
11651 ds_pool_ci.pPoolSizes = &ds_type_count;
11652
11653 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011654 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Mark Youngc89c6312016-03-31 16:03:20 -060011655 ASSERT_VK_SUCCESS(err);
11656
11657 VkDescriptorSetLayoutBinding dsl_binding = {};
11658 dsl_binding.binding = 0;
11659 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
11660 dsl_binding.descriptorCount = 1;
11661 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
11662 dsl_binding.pImmutableSamplers = NULL;
11663
11664 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
11665 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
11666 ds_layout_ci.pNext = NULL;
11667 ds_layout_ci.bindingCount = 1;
11668 ds_layout_ci.pBindings = &dsl_binding;
11669
11670 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011671 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Mark Youngc89c6312016-03-31 16:03:20 -060011672 ASSERT_VK_SUCCESS(err);
11673
11674 VkDescriptorSet descriptorSet;
11675 VkDescriptorSetAllocateInfo alloc_info = {};
11676 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
11677 alloc_info.descriptorSetCount = 1;
11678 alloc_info.descriptorPool = ds_pool;
11679 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011680 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Mark Youngc89c6312016-03-31 16:03:20 -060011681 ASSERT_VK_SUCCESS(err);
11682
11683 VkPipelineMultisampleStateCreateInfo pipe_ms_state_ci = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011684 pipe_ms_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
Mark Youngc89c6312016-03-31 16:03:20 -060011685 pipe_ms_state_ci.pNext = NULL;
11686 pipe_ms_state_ci.rasterizationSamples = VK_SAMPLE_COUNT_1_BIT;
11687 pipe_ms_state_ci.sampleShadingEnable = 0;
11688 pipe_ms_state_ci.minSampleShading = 1.0;
11689 pipe_ms_state_ci.pSampleMask = NULL;
11690
11691 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
11692 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
11693 pipeline_layout_ci.pNext = NULL;
11694 pipeline_layout_ci.setLayoutCount = 1;
11695 pipeline_layout_ci.pSetLayouts = &ds_layout;
11696
11697 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011698 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Mark Youngc89c6312016-03-31 16:03:20 -060011699 ASSERT_VK_SUCCESS(err);
11700
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011701 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
11702 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this); // We shouldn't need a fragment shader
11703 // but add it to be able to run on more devices
Mark Youngc89c6312016-03-31 16:03:20 -060011704 VkPipelineObj pipe(m_device);
11705 pipe.AddShader(&vs);
11706 pipe.AddShader(&fs);
11707 pipe.SetMSAA(&pipe_ms_state_ci);
11708 pipe.CreateVKPipeline(pipeline_layout, renderPass());
11709
11710 BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011711 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Mark Youngc89c6312016-03-31 16:03:20 -060011712
Mark Young29927482016-05-04 14:38:51 -060011713 // Render triangle (the error should trigger on the attempt to draw).
11714 Draw(3, 1, 0, 0);
11715
11716 // Finalize recording of the command buffer
11717 EndCommandBuffer();
11718
Chris Forbes8f36a8a2016-04-07 13:21:07 +120011719 m_errorMonitor->VerifyFound();
Mark Youngc89c6312016-03-31 16:03:20 -060011720
11721 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
11722 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
11723 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
11724}
Mark Young29927482016-05-04 14:38:51 -060011725
Mark Muellerd4914412016-06-13 17:52:06 -060011726TEST_F(VkLayerTest, MissingClearAttachment) {
11727 TEST_DESCRIPTION("Points to a wrong colorAttachment index in a VkClearAttachment "
11728 "structure passed to vkCmdClearAttachments");
Cody Northropc31a84f2016-08-22 10:41:47 -060011729 ASSERT_NO_FATAL_FAILURE(InitState());
Chris Forbesda6ae6f2016-09-09 14:36:33 +120011730 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Chris Forbesef5e2842016-09-08 15:25:24 +120011731 "vkCmdClearAttachments() color attachment index 1 out of range for active subpass 0; ignored");
Mark Muellerd4914412016-06-13 17:52:06 -060011732
11733 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailCmdClearAttachments);
11734 m_errorMonitor->VerifyFound();
11735}
11736
Karl Schultz6addd812016-02-02 17:17:23 -070011737TEST_F(VkLayerTest, ClearCmdNoDraw) {
11738 // Create CommandBuffer where we add ClearCmd for FB Color attachment prior
11739 // to issuing a Draw
11740 VkResult err;
Tobin Ehlis53eddda2015-07-01 16:46:13 -060011741
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011742 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
11743 "vkCmdClearAttachments() issued on CB object ");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060011744
Tobin Ehlis53eddda2015-07-01 16:46:13 -060011745 ASSERT_NO_FATAL_FAILURE(InitState());
11746 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barboureb254902015-07-15 12:50:33 -060011747
Chia-I Wu1b99bb22015-10-27 19:25:11 +080011748 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011749 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
11750 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -060011751
11752 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011753 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
11754 ds_pool_ci.pNext = NULL;
11755 ds_pool_ci.maxSets = 1;
11756 ds_pool_ci.poolSizeCount = 1;
11757 ds_pool_ci.pPoolSizes = &ds_type_count;
Tony Barboureb254902015-07-15 12:50:33 -060011758
Tobin Ehlis53eddda2015-07-01 16:46:13 -060011759 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011760 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis53eddda2015-07-01 16:46:13 -060011761 ASSERT_VK_SUCCESS(err);
11762
Tony Barboureb254902015-07-15 12:50:33 -060011763 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011764 dsl_binding.binding = 0;
11765 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
11766 dsl_binding.descriptorCount = 1;
11767 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
11768 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis53eddda2015-07-01 16:46:13 -060011769
Tony Barboureb254902015-07-15 12:50:33 -060011770 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011771 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
11772 ds_layout_ci.pNext = NULL;
11773 ds_layout_ci.bindingCount = 1;
11774 ds_layout_ci.pBindings = &dsl_binding;
Mark Lobodzinski209b5292015-09-17 09:44:05 -060011775
Tobin Ehlis53eddda2015-07-01 16:46:13 -060011776 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011777 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis53eddda2015-07-01 16:46:13 -060011778 ASSERT_VK_SUCCESS(err);
11779
11780 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080011781 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +080011782 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -070011783 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -060011784 alloc_info.descriptorPool = ds_pool;
11785 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011786 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis53eddda2015-07-01 16:46:13 -060011787 ASSERT_VK_SUCCESS(err);
11788
Tony Barboureb254902015-07-15 12:50:33 -060011789 VkPipelineMultisampleStateCreateInfo pipe_ms_state_ci = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011790 pipe_ms_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
Karl Schultz6addd812016-02-02 17:17:23 -070011791 pipe_ms_state_ci.pNext = NULL;
11792 pipe_ms_state_ci.rasterizationSamples = VK_SAMPLE_COUNT_4_BIT;
11793 pipe_ms_state_ci.sampleShadingEnable = 0;
11794 pipe_ms_state_ci.minSampleShading = 1.0;
11795 pipe_ms_state_ci.pSampleMask = NULL;
Tobin Ehlis53eddda2015-07-01 16:46:13 -060011796
Tony Barboureb254902015-07-15 12:50:33 -060011797 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011798 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
11799 pipeline_layout_ci.pNext = NULL;
11800 pipeline_layout_ci.setLayoutCount = 1;
11801 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlis53eddda2015-07-01 16:46:13 -060011802
11803 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011804 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis53eddda2015-07-01 16:46:13 -060011805 ASSERT_VK_SUCCESS(err);
Mark Lobodzinski209b5292015-09-17 09:44:05 -060011806
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011807 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
Karl Schultzbdb75952016-04-19 11:36:49 -060011808 // We shouldn't need a fragment shader but add it to be able to run
Karl Schultz6addd812016-02-02 17:17:23 -070011809 // on more devices
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011810 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060011811
Tony Barbour62e1a5b2015-08-06 10:16:07 -060011812 VkPipelineObj pipe(m_device);
11813 pipe.AddShader(&vs);
Tony Barbour1c94d372015-08-06 11:21:08 -060011814 pipe.AddShader(&fs);
Tony Barbour62e1a5b2015-08-06 10:16:07 -060011815 pipe.SetMSAA(&pipe_ms_state_ci);
11816 pipe.CreateVKPipeline(pipeline_layout, renderPass());
Tony Barbourfe3351b2015-07-28 10:17:20 -060011817
11818 BeginCommandBuffer();
Tobin Ehlis53eddda2015-07-01 16:46:13 -060011819
Karl Schultz6addd812016-02-02 17:17:23 -070011820 // Main thing we care about for this test is that the VkImage obj we're
11821 // clearing matches Color Attachment of FB
Tobin Ehlis53eddda2015-07-01 16:46:13 -060011822 // Also pass down other dummy params to keep driver and paramchecker happy
Courtney Goeltzenleuchterc9323e02015-10-15 16:51:05 -060011823 VkClearAttachment color_attachment;
11824 color_attachment.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
11825 color_attachment.clearValue.color.float32[0] = 1.0;
11826 color_attachment.clearValue.color.float32[1] = 1.0;
11827 color_attachment.clearValue.color.float32[2] = 1.0;
11828 color_attachment.clearValue.color.float32[3] = 1.0;
11829 color_attachment.colorAttachment = 0;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011830 VkClearRect clear_rect = {{{0, 0}, {(uint32_t)m_width, (uint32_t)m_height}}};
Tobin Ehlis53eddda2015-07-01 16:46:13 -060011831
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011832 vkCmdClearAttachments(m_commandBuffer->GetBufferHandle(), 1, &color_attachment, 1, &clear_rect);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060011833
Chris Forbes8f36a8a2016-04-07 13:21:07 +120011834 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -060011835
Chia-I Wuf7458c52015-10-26 21:10:41 +080011836 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
11837 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
11838 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis53eddda2015-07-01 16:46:13 -060011839}
11840
Karl Schultz6addd812016-02-02 17:17:23 -070011841TEST_F(VkLayerTest, VtxBufferBadIndex) {
11842 VkResult err;
Tobin Ehlis502480b2015-06-24 15:53:07 -060011843
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011844 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
11845 "but no vertex buffers are attached to this Pipeline State Object");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060011846
Tobin Ehlis502480b2015-06-24 15:53:07 -060011847 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisd332f282015-10-02 11:00:56 -060011848 ASSERT_NO_FATAL_FAILURE(InitViewport());
Tobin Ehlis502480b2015-06-24 15:53:07 -060011849 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barboureb254902015-07-15 12:50:33 -060011850
Chia-I Wu1b99bb22015-10-27 19:25:11 +080011851 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011852 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
11853 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -060011854
11855 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011856 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
11857 ds_pool_ci.pNext = NULL;
11858 ds_pool_ci.maxSets = 1;
11859 ds_pool_ci.poolSizeCount = 1;
11860 ds_pool_ci.pPoolSizes = &ds_type_count;
Tony Barboureb254902015-07-15 12:50:33 -060011861
Courtney Goeltzenleuchterfe908d32015-09-16 16:12:45 -060011862 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011863 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis502480b2015-06-24 15:53:07 -060011864 ASSERT_VK_SUCCESS(err);
11865
Tony Barboureb254902015-07-15 12:50:33 -060011866 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011867 dsl_binding.binding = 0;
11868 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
11869 dsl_binding.descriptorCount = 1;
11870 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
11871 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis502480b2015-06-24 15:53:07 -060011872
Tony Barboureb254902015-07-15 12:50:33 -060011873 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011874 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
11875 ds_layout_ci.pNext = NULL;
11876 ds_layout_ci.bindingCount = 1;
11877 ds_layout_ci.pBindings = &dsl_binding;
Tony Barboureb254902015-07-15 12:50:33 -060011878
Tobin Ehlis502480b2015-06-24 15:53:07 -060011879 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011880 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis502480b2015-06-24 15:53:07 -060011881 ASSERT_VK_SUCCESS(err);
11882
11883 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080011884 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +080011885 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -070011886 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -060011887 alloc_info.descriptorPool = ds_pool;
11888 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011889 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis502480b2015-06-24 15:53:07 -060011890 ASSERT_VK_SUCCESS(err);
11891
Tony Barboureb254902015-07-15 12:50:33 -060011892 VkPipelineMultisampleStateCreateInfo pipe_ms_state_ci = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011893 pipe_ms_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
Karl Schultz6addd812016-02-02 17:17:23 -070011894 pipe_ms_state_ci.pNext = NULL;
11895 pipe_ms_state_ci.rasterizationSamples = VK_SAMPLE_COUNT_1_BIT;
11896 pipe_ms_state_ci.sampleShadingEnable = 0;
11897 pipe_ms_state_ci.minSampleShading = 1.0;
11898 pipe_ms_state_ci.pSampleMask = NULL;
Tobin Ehlis502480b2015-06-24 15:53:07 -060011899
Tony Barboureb254902015-07-15 12:50:33 -060011900 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011901 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
11902 pipeline_layout_ci.pNext = NULL;
11903 pipeline_layout_ci.setLayoutCount = 1;
11904 pipeline_layout_ci.pSetLayouts = &ds_layout;
11905 VkPipelineLayout pipeline_layout;
Tobin Ehlis502480b2015-06-24 15:53:07 -060011906
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011907 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis502480b2015-06-24 15:53:07 -060011908 ASSERT_VK_SUCCESS(err);
11909
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011910 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
11911 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this); // We shouldn't need a fragment shader
11912 // but add it to be able to run on more devices
Tony Barbour62e1a5b2015-08-06 10:16:07 -060011913 VkPipelineObj pipe(m_device);
11914 pipe.AddShader(&vs);
Tony Barbour1c94d372015-08-06 11:21:08 -060011915 pipe.AddShader(&fs);
Mark Youngc89c6312016-03-31 16:03:20 -060011916 pipe.AddColorAttachment();
Tony Barbour62e1a5b2015-08-06 10:16:07 -060011917 pipe.SetMSAA(&pipe_ms_state_ci);
Tobin Ehlisd332f282015-10-02 11:00:56 -060011918 pipe.SetViewport(m_viewports);
11919 pipe.SetScissor(m_scissors);
Tony Barbour62e1a5b2015-08-06 10:16:07 -060011920 pipe.CreateVKPipeline(pipeline_layout, renderPass());
Tony Barbourfe3351b2015-07-28 10:17:20 -060011921
11922 BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011923 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Tobin Ehlisf7bf4502015-09-09 15:12:35 -060011924 // Don't care about actual data, just need to get to draw to flag error
11925 static const float vbo_data[3] = {1.f, 0.f, 1.f};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011926 VkConstantBufferObj vbo(m_device, sizeof(vbo_data), sizeof(float), (const void *)&vbo_data);
Tobin Ehlisf7bf4502015-09-09 15:12:35 -060011927 BindVertexBuffer(&vbo, (VkDeviceSize)0, 1); // VBO idx 1, but no VBO in PSO
Courtney Goeltzenleuchter08c26372015-09-23 12:31:50 -060011928 Draw(1, 0, 0, 0);
Tobin Ehlis502480b2015-06-24 15:53:07 -060011929
Chris Forbes8f36a8a2016-04-07 13:21:07 +120011930 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -060011931
Chia-I Wuf7458c52015-10-26 21:10:41 +080011932 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
11933 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
11934 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis502480b2015-06-24 15:53:07 -060011935}
Mark Muellerdfe37552016-07-07 14:47:42 -060011936
Mark Mueller2ee294f2016-08-04 12:59:48 -060011937TEST_F(VkLayerTest, MismatchCountQueueCreateRequestedFeature) {
11938 TEST_DESCRIPTION("Use an invalid count in a vkEnumeratePhysicalDevices call."
11939 "Use invalid Queue Family Index in vkCreateDevice");
Cody Northropc31a84f2016-08-22 10:41:47 -060011940 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Mueller2ee294f2016-08-04 12:59:48 -060011941
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011942 const char *mismatch_count_message = "Call to vkEnumeratePhysicalDevices() "
11943 "w/ pPhysicalDeviceCount value ";
Mark Mueller2ee294f2016-08-04 12:59:48 -060011944
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011945 const char *invalid_queueFamilyIndex_message = "Invalid queue create request in vkCreateDevice(). Invalid "
11946 "queueFamilyIndex ";
Mark Mueller2ee294f2016-08-04 12:59:48 -060011947
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011948 const char *unavailable_feature_message = "While calling vkCreateDevice(), requesting feature #";
Mark Mueller2ee294f2016-08-04 12:59:48 -060011949
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011950 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT, mismatch_count_message);
Mark Mueller880fce52016-08-17 15:23:23 -060011951 // The following test fails with recent NVidia drivers.
11952 // By the time core_validation is reached, the NVidia
11953 // driver has sanitized the invalid condition and core_validation
11954 // is not introduced to the failure condition. This is not the case
11955 // with AMD and Mesa drivers. Futher investigation is required
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011956 // uint32_t count = static_cast<uint32_t>(~0);
11957 // VkPhysicalDevice physical_device;
11958 // vkEnumeratePhysicalDevices(instance(), &count, &physical_device);
11959 // m_errorMonitor->VerifyFound();
Mark Mueller2ee294f2016-08-04 12:59:48 -060011960
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011961 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, invalid_queueFamilyIndex_message);
Mark Mueller2ee294f2016-08-04 12:59:48 -060011962 float queue_priority = 0.0;
11963
11964 VkDeviceQueueCreateInfo queue_create_info = {};
11965 queue_create_info.sType = VK_STRUCTURE_TYPE_DEVICE_QUEUE_CREATE_INFO;
11966 queue_create_info.queueCount = 1;
11967 queue_create_info.pQueuePriorities = &queue_priority;
11968 queue_create_info.queueFamilyIndex = static_cast<uint32_t>(~0);
11969
11970 VkPhysicalDeviceFeatures features = m_device->phy().features();
11971 VkDevice testDevice;
11972 VkDeviceCreateInfo device_create_info = {};
11973 device_create_info.sType = VK_STRUCTURE_TYPE_DEVICE_CREATE_INFO;
11974 device_create_info.queueCreateInfoCount = 1;
11975 device_create_info.pQueueCreateInfos = &queue_create_info;
11976 device_create_info.pEnabledFeatures = &features;
11977 vkCreateDevice(gpu(), &device_create_info, nullptr, &testDevice);
11978 m_errorMonitor->VerifyFound();
11979
11980 queue_create_info.queueFamilyIndex = 1;
11981
11982 unsigned feature_count = sizeof(VkPhysicalDeviceFeatures) / sizeof(VkBool32);
11983 VkBool32 *feature_array = reinterpret_cast<VkBool32 *>(&features);
11984 for (unsigned i = 0; i < feature_count; i++) {
11985 if (VK_FALSE == feature_array[i]) {
11986 feature_array[i] = VK_TRUE;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011987 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, unavailable_feature_message);
Mark Mueller2ee294f2016-08-04 12:59:48 -060011988 device_create_info.pEnabledFeatures = &features;
11989 vkCreateDevice(gpu(), &device_create_info, nullptr, &testDevice);
11990 m_errorMonitor->VerifyFound();
11991 break;
11992 }
11993 }
11994}
11995
11996TEST_F(VkLayerTest, InvalidQueueIndexInvalidQuery) {
11997 TEST_DESCRIPTION("Use an invalid queue index in a vkCmdWaitEvents call."
11998 "End a command buffer with a query still in progress.");
11999
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012000 const char *invalid_queue_index = "was created with sharingMode of VK_SHARING_MODE_EXCLUSIVE. If one "
12001 "of src- or dstQueueFamilyIndex is VK_QUEUE_FAMILY_IGNORED, both "
12002 "must be.";
Mark Mueller2ee294f2016-08-04 12:59:48 -060012003
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012004 const char *invalid_query = "Ending command buffer with in progress query: queryPool 0x";
Mark Mueller2ee294f2016-08-04 12:59:48 -060012005
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012006 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, invalid_queue_index);
Mark Mueller2ee294f2016-08-04 12:59:48 -060012007
12008 ASSERT_NO_FATAL_FAILURE(InitState());
12009
12010 VkEvent event;
12011 VkEventCreateInfo event_create_info{};
12012 event_create_info.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO;
12013 vkCreateEvent(m_device->device(), &event_create_info, nullptr, &event);
12014
Mark Mueller2ee294f2016-08-04 12:59:48 -060012015 VkQueue queue = VK_NULL_HANDLE;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012016 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 0, &queue);
Mark Mueller2ee294f2016-08-04 12:59:48 -060012017
12018 BeginCommandBuffer();
12019
12020 VkImageObj image(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012021 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 -060012022 ASSERT_TRUE(image.initialized());
12023 VkImageMemoryBarrier img_barrier = {};
12024 img_barrier.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
12025 img_barrier.pNext = NULL;
12026 img_barrier.srcAccessMask = VK_ACCESS_HOST_WRITE_BIT;
12027 img_barrier.dstAccessMask = VK_ACCESS_SHADER_READ_BIT;
12028 img_barrier.oldLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
12029 img_barrier.newLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
12030 img_barrier.image = image.handle();
12031 img_barrier.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
Mark Lobodzinski2a74c5c2016-08-17 13:26:28 -060012032
12033 // QueueFamilyIndex must be VK_QUEUE_FAMILY_IGNORED, this verifies
12034 // that layer validation catches the case when it is not.
12035 img_barrier.dstQueueFamilyIndex = 0;
Mark Mueller2ee294f2016-08-04 12:59:48 -060012036 img_barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
12037 img_barrier.subresourceRange.baseArrayLayer = 0;
12038 img_barrier.subresourceRange.baseMipLevel = 0;
12039 img_barrier.subresourceRange.layerCount = 1;
12040 img_barrier.subresourceRange.levelCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012041 vkCmdWaitEvents(m_commandBuffer->handle(), 1, &event, VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0,
12042 nullptr, 0, nullptr, 1, &img_barrier);
Mark Mueller2ee294f2016-08-04 12:59:48 -060012043 m_errorMonitor->VerifyFound();
12044
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012045 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, invalid_query);
Mark Mueller2ee294f2016-08-04 12:59:48 -060012046
12047 VkQueryPool query_pool;
12048 VkQueryPoolCreateInfo query_pool_create_info = {};
12049 query_pool_create_info.sType = VK_STRUCTURE_TYPE_QUERY_POOL_CREATE_INFO;
12050 query_pool_create_info.queryType = VK_QUERY_TYPE_OCCLUSION;
12051 query_pool_create_info.queryCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012052 vkCreateQueryPool(m_device->device(), &query_pool_create_info, nullptr, &query_pool);
Mark Mueller2ee294f2016-08-04 12:59:48 -060012053
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012054 vkCmdResetQueryPool(m_commandBuffer->handle(), query_pool, 0 /*startQuery*/, 1 /*queryCount*/);
Mark Mueller2ee294f2016-08-04 12:59:48 -060012055 vkCmdBeginQuery(m_commandBuffer->handle(), query_pool, 0, 0);
12056
12057 vkEndCommandBuffer(m_commandBuffer->handle());
12058 m_errorMonitor->VerifyFound();
12059
12060 vkDestroyQueryPool(m_device->device(), query_pool, nullptr);
12061 vkDestroyEvent(m_device->device(), event, nullptr);
12062}
12063
Mark Muellerdfe37552016-07-07 14:47:42 -060012064TEST_F(VkLayerTest, VertexBufferInvalid) {
12065 TEST_DESCRIPTION("Submit a command buffer using deleted vertex buffer, "
12066 "delete a buffer twice, use an invalid offset for each "
12067 "buffer type, and attempt to bind a null buffer");
12068
12069 const char *deleted_buffer_in_command_buffer = "Cannot submit cmd buffer "
12070 "using deleted buffer ";
12071 const char *double_destroy_message = "Cannot free buffer 0x";
12072 const char *invalid_offset_message = "vkBindBufferMemory(): "
12073 "memoryOffset is 0x";
12074 const char *invalid_storage_buffer_offset_message = "vkBindBufferMemory(): "
12075 "storage memoryOffset "
12076 "is 0x";
12077 const char *invalid_texel_buffer_offset_message = "vkBindBufferMemory(): "
12078 "texel memoryOffset "
12079 "is 0x";
12080 const char *invalid_uniform_buffer_offset_message = "vkBindBufferMemory(): "
12081 "uniform memoryOffset "
12082 "is 0x";
12083 const char *bind_null_buffer_message = "In vkBindBufferMemory, attempting"
12084 " to Bind Obj(0x";
12085 const char *free_invalid_buffer_message = "Request to delete memory "
12086 "object 0x";
12087
12088 ASSERT_NO_FATAL_FAILURE(InitState());
12089 ASSERT_NO_FATAL_FAILURE(InitViewport());
12090 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12091
12092 VkPipelineMultisampleStateCreateInfo pipe_ms_state_ci = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012093 pipe_ms_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
Mark Muellerdfe37552016-07-07 14:47:42 -060012094 pipe_ms_state_ci.pNext = NULL;
12095 pipe_ms_state_ci.rasterizationSamples = VK_SAMPLE_COUNT_1_BIT;
12096 pipe_ms_state_ci.sampleShadingEnable = 0;
12097 pipe_ms_state_ci.minSampleShading = 1.0;
12098 pipe_ms_state_ci.pSampleMask = nullptr;
12099
12100 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
12101 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
12102 VkPipelineLayout pipeline_layout;
12103
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012104 VkResult err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, nullptr, &pipeline_layout);
Mark Muellerdfe37552016-07-07 14:47:42 -060012105 ASSERT_VK_SUCCESS(err);
12106
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012107 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
12108 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Mark Muellerdfe37552016-07-07 14:47:42 -060012109 VkPipelineObj pipe(m_device);
12110 pipe.AddShader(&vs);
12111 pipe.AddShader(&fs);
12112 pipe.AddColorAttachment();
12113 pipe.SetMSAA(&pipe_ms_state_ci);
12114 pipe.SetViewport(m_viewports);
12115 pipe.SetScissor(m_scissors);
12116 pipe.CreateVKPipeline(pipeline_layout, renderPass());
12117
12118 BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012119 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Mark Muellerdfe37552016-07-07 14:47:42 -060012120
12121 {
12122 // Create and bind a vertex buffer in a reduced scope, which will cause
12123 // it to be deleted upon leaving this scope
12124 const float vbo_data[3] = {1.f, 0.f, 1.f};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012125 VkVerticesObj draw_verticies(m_device, 1, 1, sizeof(vbo_data), 3, vbo_data);
Mark Muellerdfe37552016-07-07 14:47:42 -060012126 draw_verticies.BindVertexBuffers(m_commandBuffer->handle());
12127 draw_verticies.AddVertexInputToPipe(pipe);
12128 }
12129
12130 Draw(1, 0, 0, 0);
12131
12132 EndCommandBuffer();
12133
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012134 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, deleted_buffer_in_command_buffer);
Mark Muellerdfe37552016-07-07 14:47:42 -060012135 QueueCommandBuffer(false);
12136 m_errorMonitor->VerifyFound();
12137
12138 {
12139 // Create and bind a vertex buffer in a reduced scope, and delete it
12140 // twice, the second through the destructor
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012141 VkBufferTest buffer_test(m_device, VK_BUFFER_USAGE_STORAGE_BUFFER_BIT, VkBufferTest::eDoubleDelete);
12142 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, double_destroy_message);
Mark Muellerdfe37552016-07-07 14:47:42 -060012143 buffer_test.TestDoubleDestroy();
12144 }
12145 m_errorMonitor->VerifyFound();
12146
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012147 if (VkBufferTest::GetTestConditionValid(m_device, VkBufferTest::eInvalidMemoryOffset)) {
Mark Muellerdfe37552016-07-07 14:47:42 -060012148 // Create and bind a memory buffer with an invalid offset.
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012149 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, invalid_offset_message);
12150 VkBufferTest buffer_test(m_device, VK_BUFFER_USAGE_UNIFORM_TEXEL_BUFFER_BIT, VkBufferTest::eInvalidMemoryOffset);
12151 (void)buffer_test;
Mark Muellerdfe37552016-07-07 14:47:42 -060012152 m_errorMonitor->VerifyFound();
12153 }
12154
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012155 if (VkBufferTest::GetTestConditionValid(m_device, VkBufferTest::eInvalidDeviceOffset,
12156 VK_BUFFER_USAGE_UNIFORM_TEXEL_BUFFER_BIT)) {
Mark Muellerdfe37552016-07-07 14:47:42 -060012157 // Create and bind a memory buffer with an invalid offset again,
12158 // but look for a texel buffer message.
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012159 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, invalid_texel_buffer_offset_message);
12160 VkBufferTest buffer_test(m_device, VK_BUFFER_USAGE_UNIFORM_TEXEL_BUFFER_BIT, VkBufferTest::eInvalidDeviceOffset);
12161 (void)buffer_test;
Mark Muellerdfe37552016-07-07 14:47:42 -060012162 m_errorMonitor->VerifyFound();
12163 }
12164
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012165 if (VkBufferTest::GetTestConditionValid(m_device, VkBufferTest::eInvalidDeviceOffset, VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT)) {
Mark Muellerdfe37552016-07-07 14:47:42 -060012166 // Create and bind a memory buffer with an invalid offset again, but
12167 // look for a uniform buffer message.
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012168 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, invalid_uniform_buffer_offset_message);
12169 VkBufferTest buffer_test(m_device, VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT, VkBufferTest::eInvalidDeviceOffset);
12170 (void)buffer_test;
Mark Muellerdfe37552016-07-07 14:47:42 -060012171 m_errorMonitor->VerifyFound();
12172 }
12173
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012174 if (VkBufferTest::GetTestConditionValid(m_device, VkBufferTest::eInvalidDeviceOffset, VK_BUFFER_USAGE_STORAGE_BUFFER_BIT)) {
Mark Muellerdfe37552016-07-07 14:47:42 -060012175 // Create and bind a memory buffer with an invalid offset again, but
12176 // look for a storage buffer message.
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012177 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, invalid_storage_buffer_offset_message);
12178 VkBufferTest buffer_test(m_device, VK_BUFFER_USAGE_STORAGE_BUFFER_BIT, VkBufferTest::eInvalidDeviceOffset);
12179 (void)buffer_test;
Mark Muellerdfe37552016-07-07 14:47:42 -060012180 m_errorMonitor->VerifyFound();
12181 }
12182
12183 {
12184 // Attempt to bind a null buffer.
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012185 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, bind_null_buffer_message);
12186 VkBufferTest buffer_test(m_device, VK_BUFFER_USAGE_STORAGE_BUFFER_BIT, VkBufferTest::eBindNullBuffer);
12187 (void)buffer_test;
Mark Muellerdfe37552016-07-07 14:47:42 -060012188 m_errorMonitor->VerifyFound();
12189 }
12190
12191 {
12192 // Attempt to use an invalid handle to delete a buffer.
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012193 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, free_invalid_buffer_message);
12194 VkBufferTest buffer_test(m_device, VK_BUFFER_USAGE_STORAGE_BUFFER_BIT, VkBufferTest::eFreeInvalidHandle);
12195 (void)buffer_test;
Mark Muellerdfe37552016-07-07 14:47:42 -060012196 }
12197 m_errorMonitor->VerifyFound();
12198
12199 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
12200}
12201
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060012202// INVALID_IMAGE_LAYOUT tests (one other case is hit by MapMemWithoutHostVisibleBit and not here)
12203TEST_F(VkLayerTest, InvalidImageLayout) {
12204 TEST_DESCRIPTION("Hit all possible validation checks associated with the "
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012205 "DRAWSTATE_INVALID_IMAGE_LAYOUT enum. Generally these involve having"
12206 "images in the wrong layout when they're copied or transitioned.");
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060012207 // 3 in ValidateCmdBufImageLayouts
12208 // * -1 Attempt to submit cmd buf w/ deleted image
12209 // * -2 Cmd buf submit of image w/ layout not matching first use w/ subresource
12210 // * -3 Cmd buf submit of image w/ layout not matching first use w/o subresource
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012211 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
12212 "Layout for input image should be TRANSFER_SRC_OPTIMAL instead of GENERAL.");
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060012213
12214 ASSERT_NO_FATAL_FAILURE(InitState());
12215 // Create src & dst images to use for copy operations
12216 VkImage src_image;
12217 VkImage dst_image;
12218
12219 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
12220 const int32_t tex_width = 32;
12221 const int32_t tex_height = 32;
12222
12223 VkImageCreateInfo image_create_info = {};
12224 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
12225 image_create_info.pNext = NULL;
12226 image_create_info.imageType = VK_IMAGE_TYPE_2D;
12227 image_create_info.format = tex_format;
12228 image_create_info.extent.width = tex_width;
12229 image_create_info.extent.height = tex_height;
12230 image_create_info.extent.depth = 1;
12231 image_create_info.mipLevels = 1;
12232 image_create_info.arrayLayers = 4;
12233 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
12234 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
12235 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
12236 image_create_info.flags = 0;
12237
12238 VkResult err = vkCreateImage(m_device->device(), &image_create_info, NULL, &src_image);
12239 ASSERT_VK_SUCCESS(err);
12240 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &dst_image);
12241 ASSERT_VK_SUCCESS(err);
12242
12243 BeginCommandBuffer();
12244 VkImageCopy copyRegion;
12245 copyRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
12246 copyRegion.srcSubresource.mipLevel = 0;
12247 copyRegion.srcSubresource.baseArrayLayer = 0;
12248 copyRegion.srcSubresource.layerCount = 1;
12249 copyRegion.srcOffset.x = 0;
12250 copyRegion.srcOffset.y = 0;
12251 copyRegion.srcOffset.z = 0;
12252 copyRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
12253 copyRegion.dstSubresource.mipLevel = 0;
12254 copyRegion.dstSubresource.baseArrayLayer = 0;
12255 copyRegion.dstSubresource.layerCount = 1;
12256 copyRegion.dstOffset.x = 0;
12257 copyRegion.dstOffset.y = 0;
12258 copyRegion.dstOffset.z = 0;
12259 copyRegion.extent.width = 1;
12260 copyRegion.extent.height = 1;
12261 copyRegion.extent.depth = 1;
12262 m_commandBuffer->CopyImage(src_image, VK_IMAGE_LAYOUT_GENERAL, dst_image, VK_IMAGE_LAYOUT_GENERAL, 1, &copyRegion);
12263 m_errorMonitor->VerifyFound();
12264 // Now cause error due to src image layout changing
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012265 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Cannot copy from an image whose source layout is "
12266 "VK_IMAGE_LAYOUT_UNDEFINED and doesn't match the current "
12267 "layout VK_IMAGE_LAYOUT_GENERAL.");
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060012268 m_commandBuffer->CopyImage(src_image, VK_IMAGE_LAYOUT_UNDEFINED, dst_image, VK_IMAGE_LAYOUT_GENERAL, 1, &copyRegion);
12269 m_errorMonitor->VerifyFound();
12270 // Final src error is due to bad layout type
12271 m_errorMonitor->SetDesiredFailureMsg(
12272 VK_DEBUG_REPORT_ERROR_BIT_EXT,
12273 "Layout for input image is VK_IMAGE_LAYOUT_UNDEFINED but can only be TRANSFER_SRC_OPTIMAL or GENERAL.");
12274 m_commandBuffer->CopyImage(src_image, VK_IMAGE_LAYOUT_UNDEFINED, dst_image, VK_IMAGE_LAYOUT_GENERAL, 1, &copyRegion);
12275 m_errorMonitor->VerifyFound();
12276 // Now verify same checks for dst
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012277 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
12278 "Layout for output image should be TRANSFER_DST_OPTIMAL instead of GENERAL.");
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060012279 m_commandBuffer->CopyImage(src_image, VK_IMAGE_LAYOUT_GENERAL, dst_image, VK_IMAGE_LAYOUT_GENERAL, 1, &copyRegion);
12280 m_errorMonitor->VerifyFound();
12281 // Now cause error due to src image layout changing
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012282 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Cannot copy from an image whose dest layout is "
12283 "VK_IMAGE_LAYOUT_UNDEFINED and doesn't match the current "
12284 "layout VK_IMAGE_LAYOUT_GENERAL.");
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060012285 m_commandBuffer->CopyImage(src_image, VK_IMAGE_LAYOUT_GENERAL, dst_image, VK_IMAGE_LAYOUT_UNDEFINED, 1, &copyRegion);
12286 m_errorMonitor->VerifyFound();
12287 m_errorMonitor->SetDesiredFailureMsg(
12288 VK_DEBUG_REPORT_ERROR_BIT_EXT,
12289 "Layout for output image is VK_IMAGE_LAYOUT_UNDEFINED but can only be TRANSFER_DST_OPTIMAL or GENERAL.");
12290 m_commandBuffer->CopyImage(src_image, VK_IMAGE_LAYOUT_GENERAL, dst_image, VK_IMAGE_LAYOUT_UNDEFINED, 1, &copyRegion);
12291 m_errorMonitor->VerifyFound();
12292 // Now cause error due to bad image layout transition in PipelineBarrier
12293 VkImageMemoryBarrier image_barrier[1] = {};
12294 image_barrier[0].oldLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL;
12295 image_barrier[0].image = src_image;
12296 image_barrier[0].subresourceRange.layerCount = 2;
12297 image_barrier[0].subresourceRange.levelCount = 2;
12298 image_barrier[0].subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012299 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "You cannot transition the layout from "
12300 "VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL when "
12301 "current layout is VK_IMAGE_LAYOUT_GENERAL.");
12302 vkCmdPipelineBarrier(m_commandBuffer->handle(), VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0,
12303 NULL, 0, NULL, 1, image_barrier);
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060012304 m_errorMonitor->VerifyFound();
12305
12306 // Finally some layout errors at RenderPass create time
12307 // Just hacking in specific state to get to the errors we want so don't copy this unless you know what you're doing.
12308 VkAttachmentReference attach = {};
12309 // perf warning for GENERAL layout w/ non-DS input attachment
12310 attach.layout = VK_IMAGE_LAYOUT_GENERAL;
12311 VkSubpassDescription subpass = {};
12312 subpass.inputAttachmentCount = 1;
12313 subpass.pInputAttachments = &attach;
12314 VkRenderPassCreateInfo rpci = {};
12315 rpci.subpassCount = 1;
12316 rpci.pSubpasses = &subpass;
12317 rpci.attachmentCount = 1;
12318 VkAttachmentDescription attach_desc = {};
12319 attach_desc.format = VK_FORMAT_UNDEFINED;
12320 rpci.pAttachments = &attach_desc;
Tobin Ehlis1efce022016-05-11 10:40:34 -060012321 rpci.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060012322 VkRenderPass rp;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012323 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
12324 "Layout for input attachment is GENERAL but should be READ_ONLY_OPTIMAL.");
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060012325 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
12326 m_errorMonitor->VerifyFound();
12327 // error w/ non-general layout
12328 attach.layout = VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL;
12329
12330 m_errorMonitor->SetDesiredFailureMsg(
12331 VK_DEBUG_REPORT_ERROR_BIT_EXT,
12332 "Layout for input attachment is VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL but can only be READ_ONLY_OPTIMAL or GENERAL.");
12333 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
12334 m_errorMonitor->VerifyFound();
12335 subpass.inputAttachmentCount = 0;
12336 subpass.colorAttachmentCount = 1;
12337 subpass.pColorAttachments = &attach;
12338 attach.layout = VK_IMAGE_LAYOUT_GENERAL;
12339 // perf warning for GENERAL layout on color attachment
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012340 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
12341 "Layout for color attachment is GENERAL but should be COLOR_ATTACHMENT_OPTIMAL.");
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060012342 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
12343 m_errorMonitor->VerifyFound();
12344 // error w/ non-color opt or GENERAL layout for color attachment
12345 attach.layout = VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL;
12346 m_errorMonitor->SetDesiredFailureMsg(
12347 VK_DEBUG_REPORT_ERROR_BIT_EXT,
12348 "Layout for color attachment is VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL but can only be COLOR_ATTACHMENT_OPTIMAL or GENERAL.");
12349 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
12350 m_errorMonitor->VerifyFound();
12351 subpass.colorAttachmentCount = 0;
12352 subpass.pDepthStencilAttachment = &attach;
12353 attach.layout = VK_IMAGE_LAYOUT_GENERAL;
12354 // perf warning for GENERAL layout on DS attachment
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012355 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
12356 "GENERAL layout for depth attachment may not give optimal performance.");
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060012357 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
12358 m_errorMonitor->VerifyFound();
12359 // error w/ non-ds opt or GENERAL layout for color attachment
12360 attach.layout = VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012361 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
12362 "Layout for depth attachment is VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL but can only be "
12363 "DEPTH_STENCIL_ATTACHMENT_OPTIMAL, DEPTH_STENCIL_READ_ONLY_OPTIMAL or GENERAL.");
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060012364 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
12365 m_errorMonitor->VerifyFound();
Tobin Ehlis1efce022016-05-11 10:40:34 -060012366 // For this error we need a valid renderpass so create default one
12367 attach.layout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL;
12368 attach.attachment = 0;
12369 attach_desc.format = VK_FORMAT_D24_UNORM_S8_UINT;
12370 attach_desc.samples = VK_SAMPLE_COUNT_1_BIT;
12371 attach_desc.storeOp = VK_ATTACHMENT_STORE_OP_STORE;
12372 attach_desc.stencilLoadOp = VK_ATTACHMENT_LOAD_OP_DONT_CARE;
12373 attach_desc.stencilStoreOp = VK_ATTACHMENT_STORE_OP_DONT_CARE;
12374 // Can't do a CLEAR load on READ_ONLY initialLayout
12375 attach_desc.loadOp = VK_ATTACHMENT_LOAD_OP_CLEAR;
12376 attach_desc.initialLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL;
12377 attach_desc.finalLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012378 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " with invalid first layout "
12379 "VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_"
12380 "ONLY_OPTIMAL");
Tobin Ehlis1efce022016-05-11 10:40:34 -060012381 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
12382 m_errorMonitor->VerifyFound();
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060012383
12384 vkDestroyImage(m_device->device(), src_image, NULL);
12385 vkDestroyImage(m_device->device(), dst_image, NULL);
12386}
Tobin Ehlisd8d89182016-07-18 20:13:11 -060012387
12388TEST_F(VkLayerTest, ValidRenderPassAttachmentLayoutWithLoadOp) {
12389 TEST_DESCRIPTION("Positive test where we create a renderpass with an "
12390 "attachment that uses LOAD_OP_CLEAR, the first subpass "
12391 "has a valid layout, and a second subpass then uses a "
12392 "valid *READ_ONLY* layout.");
12393 m_errorMonitor->ExpectSuccess();
12394 ASSERT_NO_FATAL_FAILURE(InitState());
12395
12396 VkAttachmentReference attach[2] = {};
12397 attach[0].attachment = 0;
12398 attach[0].layout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
12399 attach[1].attachment = 0;
12400 attach[1].layout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL;
12401 VkSubpassDescription subpasses[2] = {};
12402 // First subpass clears DS attach on load
12403 subpasses[0].pDepthStencilAttachment = &attach[0];
12404 // 2nd subpass reads in DS as input attachment
12405 subpasses[1].inputAttachmentCount = 1;
12406 subpasses[1].pInputAttachments = &attach[1];
12407 VkAttachmentDescription attach_desc = {};
12408 attach_desc.format = VK_FORMAT_D24_UNORM_S8_UINT;
12409 attach_desc.samples = VK_SAMPLE_COUNT_1_BIT;
12410 attach_desc.storeOp = VK_ATTACHMENT_STORE_OP_STORE;
12411 attach_desc.stencilStoreOp = VK_ATTACHMENT_STORE_OP_DONT_CARE;
12412 attach_desc.loadOp = VK_ATTACHMENT_LOAD_OP_CLEAR;
12413 attach_desc.stencilLoadOp = VK_ATTACHMENT_LOAD_OP_CLEAR;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012414 attach_desc.initialLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
Tobin Ehlisd8d89182016-07-18 20:13:11 -060012415 attach_desc.finalLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL;
12416 VkRenderPassCreateInfo rpci = {};
12417 rpci.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
12418 rpci.attachmentCount = 1;
12419 rpci.pAttachments = &attach_desc;
12420 rpci.subpassCount = 2;
12421 rpci.pSubpasses = subpasses;
12422
12423 // Now create RenderPass and verify no errors
12424 VkRenderPass rp;
12425 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
12426 m_errorMonitor->VerifyNotFound();
12427
12428 vkDestroyRenderPass(m_device->device(), rp, NULL);
12429}
Tobin Ehlis4af23302016-07-19 10:50:30 -060012430
Mark Mueller93b938f2016-08-18 10:27:40 -060012431TEST_F(VkLayerTest, SimultaneousUse) {
12432 TEST_DESCRIPTION("Use vkCmdExecuteCommands with invalid state "
12433 "in primary and secondary command buffers.");
12434
12435 ASSERT_NO_FATAL_FAILURE(InitState());
12436 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12437
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012438 const char *simultaneous_use_message1 = "w/o VK_COMMAND_BUFFER_USAGE_SIMULTANEOUS_USE_BIT set!";
12439 const char *simultaneous_use_message2 = "does not have VK_COMMAND_BUFFER_USAGE_SIMULTANEOUS_USE_BIT set and "
12440 "will cause primary command buffer";
Mark Mueller93b938f2016-08-18 10:27:40 -060012441
12442 VkCommandBufferAllocateInfo command_buffer_allocate_info = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012443 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
Mark Mueller93b938f2016-08-18 10:27:40 -060012444 command_buffer_allocate_info.commandPool = m_commandPool;
12445 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_SECONDARY;
12446 command_buffer_allocate_info.commandBufferCount = 1;
12447
12448 VkCommandBuffer secondary_command_buffer;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012449 ASSERT_VK_SUCCESS(vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, &secondary_command_buffer));
Mark Mueller93b938f2016-08-18 10:27:40 -060012450 VkCommandBufferBeginInfo command_buffer_begin_info = {};
12451 VkCommandBufferInheritanceInfo command_buffer_inheritance_info = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012452 command_buffer_inheritance_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_INHERITANCE_INFO;
Mark Mueller93b938f2016-08-18 10:27:40 -060012453 command_buffer_inheritance_info.renderPass = m_renderPass;
12454 command_buffer_inheritance_info.framebuffer = m_framebuffer;
12455 command_buffer_begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012456 command_buffer_begin_info.flags =
12457 VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT | VK_COMMAND_BUFFER_USAGE_RENDER_PASS_CONTINUE_BIT;
Mark Mueller93b938f2016-08-18 10:27:40 -060012458 command_buffer_begin_info.pInheritanceInfo = &command_buffer_inheritance_info;
12459
12460 vkBeginCommandBuffer(secondary_command_buffer, &command_buffer_begin_info);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012461 vkCmdBeginRenderPass(m_commandBuffer->handle(), &renderPassBeginInfo(), VK_SUBPASS_CONTENTS_SECONDARY_COMMAND_BUFFERS);
12462 vkCmdExecuteCommands(m_commandBuffer->handle(), 1, &secondary_command_buffer);
Mark Mueller4042b652016-09-05 22:52:21 -060012463 vkCmdEndRenderPass(m_commandBuffer->GetBufferHandle());
Mark Mueller93b938f2016-08-18 10:27:40 -060012464 vkEndCommandBuffer(secondary_command_buffer);
12465
Mark Mueller93b938f2016-08-18 10:27:40 -060012466 VkSubmitInfo submit_info = {};
12467 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
12468 submit_info.commandBufferCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012469 submit_info.pCommandBuffers = &m_commandBuffer->handle();
Mark Mueller4042b652016-09-05 22:52:21 -060012470 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
Mark Mueller93b938f2016-08-18 10:27:40 -060012471
Mark Mueller4042b652016-09-05 22:52:21 -060012472 vkBeginCommandBuffer(m_commandBuffer->handle(), &command_buffer_begin_info);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012473 vkCmdBeginRenderPass(m_commandBuffer->handle(), &renderPassBeginInfo(), VK_SUBPASS_CONTENTS_SECONDARY_COMMAND_BUFFERS);
12474 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, simultaneous_use_message1);
12475 vkCmdExecuteCommands(m_commandBuffer->handle(), 1, &secondary_command_buffer);
Mark Mueller93b938f2016-08-18 10:27:40 -060012476 m_errorMonitor->VerifyFound();
Mark Mueller4042b652016-09-05 22:52:21 -060012477 vkCmdEndRenderPass(m_commandBuffer->GetBufferHandle());
12478 vkEndCommandBuffer(m_commandBuffer->handle());
Mark Mueller93b938f2016-08-18 10:27:40 -060012479
12480 m_errorMonitor->SetDesiredFailureMsg(0, "");
Mark Mueller93b938f2016-08-18 10:27:40 -060012481 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
12482
Mark Mueller4042b652016-09-05 22:52:21 -060012483 command_buffer_begin_info.flags = VK_COMMAND_BUFFER_USAGE_SIMULTANEOUS_USE_BIT;
Mark Mueller93b938f2016-08-18 10:27:40 -060012484 vkBeginCommandBuffer(m_commandBuffer->handle(), &command_buffer_begin_info);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012485 vkCmdBeginRenderPass(m_commandBuffer->handle(), &renderPassBeginInfo(), VK_SUBPASS_CONTENTS_SECONDARY_COMMAND_BUFFERS);
Mark Mueller4042b652016-09-05 22:52:21 -060012486
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012487 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT, simultaneous_use_message2);
12488 vkCmdExecuteCommands(m_commandBuffer->handle(), 1, &secondary_command_buffer);
Mark Mueller93b938f2016-08-18 10:27:40 -060012489 m_errorMonitor->VerifyFound();
Mark Mueller4042b652016-09-05 22:52:21 -060012490 vkCmdEndRenderPass(m_commandBuffer->GetBufferHandle());
12491 vkEndCommandBuffer(m_commandBuffer->handle());
Mark Mueller93b938f2016-08-18 10:27:40 -060012492}
12493
Mark Mueller917f6bc2016-08-30 10:57:19 -060012494TEST_F(VkLayerTest, InUseDestroyedSignaled) {
12495 TEST_DESCRIPTION("Use vkCmdExecuteCommands with invalid state "
12496 "in primary and secondary command buffers. "
Mark Muellerc8d441e2016-08-23 17:36:00 -060012497 "Delete objects that are inuse. Call VkQueueSubmit "
12498 "with an event that has been deleted.");
Mark Mueller917f6bc2016-08-30 10:57:19 -060012499
12500 ASSERT_NO_FATAL_FAILURE(InitState());
12501 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12502
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012503 const char *submit_with_deleted_event_message = "Cannot submit cmd buffer using deleted event 0x";
12504 const char *cannot_delete_event_message = "Cannot delete event 0x";
12505 const char *cannot_delete_semaphore_message = "Cannot delete semaphore 0x";
12506 const char *cannot_destroy_fence_message = "Fence 0x";
Mark Mueller917f6bc2016-08-30 10:57:19 -060012507
12508 BeginCommandBuffer();
12509
12510 VkEvent event;
12511 VkEventCreateInfo event_create_info = {};
12512 event_create_info.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO;
12513 vkCreateEvent(m_device->device(), &event_create_info, nullptr, &event);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012514 vkCmdSetEvent(m_commandBuffer->handle(), event, VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT);
Mark Mueller917f6bc2016-08-30 10:57:19 -060012515
Mark Muellerc8d441e2016-08-23 17:36:00 -060012516 EndCommandBuffer();
12517 vkDestroyEvent(m_device->device(), event, nullptr);
12518
12519 VkSubmitInfo submit_info = {};
12520 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
12521 submit_info.commandBufferCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012522 submit_info.pCommandBuffers = &m_commandBuffer->handle();
12523 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, submit_with_deleted_event_message);
Mark Muellerc8d441e2016-08-23 17:36:00 -060012524 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
12525 m_errorMonitor->VerifyFound();
12526
12527 m_errorMonitor->SetDesiredFailureMsg(0, "");
12528 vkResetCommandBuffer(m_commandBuffer->handle(), 0);
12529
12530 vkCreateEvent(m_device->device(), &event_create_info, nullptr, &event);
12531
Mark Mueller917f6bc2016-08-30 10:57:19 -060012532 VkSemaphoreCreateInfo semaphore_create_info = {};
12533 semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
12534 VkSemaphore semaphore;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012535 ASSERT_VK_SUCCESS(vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr, &semaphore));
Mark Mueller917f6bc2016-08-30 10:57:19 -060012536 VkFenceCreateInfo fence_create_info = {};
12537 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
12538 VkFence fence;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012539 ASSERT_VK_SUCCESS(vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence));
Mark Mueller917f6bc2016-08-30 10:57:19 -060012540
12541 VkDescriptorPoolSize descriptor_pool_type_count = {};
Mark Mueller4042b652016-09-05 22:52:21 -060012542 descriptor_pool_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Mark Mueller917f6bc2016-08-30 10:57:19 -060012543 descriptor_pool_type_count.descriptorCount = 1;
12544
12545 VkDescriptorPoolCreateInfo descriptor_pool_create_info = {};
12546 descriptor_pool_create_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
12547 descriptor_pool_create_info.maxSets = 1;
12548 descriptor_pool_create_info.poolSizeCount = 1;
12549 descriptor_pool_create_info.pPoolSizes = &descriptor_pool_type_count;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012550 descriptor_pool_create_info.flags = VK_DESCRIPTOR_POOL_CREATE_FREE_DESCRIPTOR_SET_BIT;
Mark Mueller917f6bc2016-08-30 10:57:19 -060012551
12552 VkDescriptorPool descriptorset_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012553 ASSERT_VK_SUCCESS(vkCreateDescriptorPool(m_device->device(), &descriptor_pool_create_info, nullptr, &descriptorset_pool));
Mark Mueller917f6bc2016-08-30 10:57:19 -060012554
12555 VkDescriptorSetLayoutBinding descriptorset_layout_binding = {};
Mark Mueller4042b652016-09-05 22:52:21 -060012556 descriptorset_layout_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Mark Mueller917f6bc2016-08-30 10:57:19 -060012557 descriptorset_layout_binding.descriptorCount = 1;
12558 descriptorset_layout_binding.stageFlags = VK_SHADER_STAGE_ALL;
12559
12560 VkDescriptorSetLayoutCreateInfo descriptorset_layout_create_info = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012561 descriptorset_layout_create_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
Mark Mueller917f6bc2016-08-30 10:57:19 -060012562 descriptorset_layout_create_info.bindingCount = 1;
12563 descriptorset_layout_create_info.pBindings = &descriptorset_layout_binding;
12564
12565 VkDescriptorSetLayout descriptorset_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012566 ASSERT_VK_SUCCESS(
12567 vkCreateDescriptorSetLayout(m_device->device(), &descriptorset_layout_create_info, nullptr, &descriptorset_layout));
Mark Mueller917f6bc2016-08-30 10:57:19 -060012568
12569 VkDescriptorSet descriptorset;
12570 VkDescriptorSetAllocateInfo descriptorset_allocate_info = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012571 descriptorset_allocate_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Mark Mueller917f6bc2016-08-30 10:57:19 -060012572 descriptorset_allocate_info.descriptorSetCount = 1;
12573 descriptorset_allocate_info.descriptorPool = descriptorset_pool;
12574 descriptorset_allocate_info.pSetLayouts = &descriptorset_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012575 ASSERT_VK_SUCCESS(vkAllocateDescriptorSets(m_device->device(), &descriptorset_allocate_info, &descriptorset));
Mark Mueller917f6bc2016-08-30 10:57:19 -060012576
Mark Mueller4042b652016-09-05 22:52:21 -060012577 VkBufferTest buffer_test(m_device, VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT);
12578
12579 VkDescriptorBufferInfo buffer_info = {};
12580 buffer_info.buffer = buffer_test.GetBuffer();
12581 buffer_info.offset = 0;
12582 buffer_info.range = 1024;
12583
12584 VkWriteDescriptorSet write_descriptor_set = {};
12585 write_descriptor_set.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
12586 write_descriptor_set.dstSet = descriptorset;
12587 write_descriptor_set.descriptorCount = 1;
12588 write_descriptor_set.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
12589 write_descriptor_set.pBufferInfo = &buffer_info;
12590
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012591 vkUpdateDescriptorSets(m_device->device(), 1, &write_descriptor_set, 0, nullptr);
Mark Mueller4042b652016-09-05 22:52:21 -060012592
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012593 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
12594 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Mark Mueller917f6bc2016-08-30 10:57:19 -060012595
12596 VkPipelineObj pipe(m_device);
12597 pipe.AddColorAttachment();
12598 pipe.AddShader(&vs);
12599 pipe.AddShader(&fs);
12600
12601 VkPipelineLayoutCreateInfo pipeline_layout_create_info = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012602 pipeline_layout_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
Mark Mueller917f6bc2016-08-30 10:57:19 -060012603 pipeline_layout_create_info.setLayoutCount = 1;
12604 pipeline_layout_create_info.pSetLayouts = &descriptorset_layout;
12605
12606 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012607 ASSERT_VK_SUCCESS(vkCreatePipelineLayout(m_device->device(), &pipeline_layout_create_info, nullptr, &pipeline_layout));
Mark Mueller917f6bc2016-08-30 10:57:19 -060012608
12609 pipe.CreateVKPipeline(pipeline_layout, m_renderPass);
12610
Mark Muellerc8d441e2016-08-23 17:36:00 -060012611 BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012612 vkCmdSetEvent(m_commandBuffer->handle(), event, VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT);
Mark Muellerc8d441e2016-08-23 17:36:00 -060012613
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012614 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
12615 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
12616 &descriptorset, 0, NULL);
Mark Mueller917f6bc2016-08-30 10:57:19 -060012617
Mark Muellerc8d441e2016-08-23 17:36:00 -060012618 EndCommandBuffer();
Mark Mueller917f6bc2016-08-30 10:57:19 -060012619
Mark Mueller917f6bc2016-08-30 10:57:19 -060012620 submit_info.signalSemaphoreCount = 1;
12621 submit_info.pSignalSemaphores = &semaphore;
12622 vkQueueSubmit(m_device->m_queue, 1, &submit_info, fence);
Mark Muellerc8d441e2016-08-23 17:36:00 -060012623
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012624 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, cannot_delete_event_message);
Mark Mueller917f6bc2016-08-30 10:57:19 -060012625 vkDestroyEvent(m_device->device(), event, nullptr);
12626 m_errorMonitor->VerifyFound();
12627
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012628 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, cannot_delete_semaphore_message);
Mark Mueller917f6bc2016-08-30 10:57:19 -060012629 vkDestroySemaphore(m_device->device(), semaphore, nullptr);
12630 m_errorMonitor->VerifyFound();
12631
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012632 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, cannot_destroy_fence_message);
Mark Mueller917f6bc2016-08-30 10:57:19 -060012633 vkDestroyFence(m_device->device(), fence, nullptr);
12634 m_errorMonitor->VerifyFound();
12635
Tobin Ehlis122207b2016-09-01 08:50:06 -070012636 vkQueueWaitIdle(m_device->m_queue);
Mark Mueller917f6bc2016-08-30 10:57:19 -060012637 vkDestroySemaphore(m_device->device(), semaphore, nullptr);
12638 vkDestroyFence(m_device->device(), fence, nullptr);
12639 vkDestroyEvent(m_device->device(), event, nullptr);
12640 vkDestroyDescriptorPool(m_device->device(), descriptorset_pool, nullptr);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012641 vkDestroyDescriptorSetLayout(m_device->device(), descriptorset_layout, nullptr);
Mark Mueller917f6bc2016-08-30 10:57:19 -060012642 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, nullptr);
12643}
12644
Tobin Ehlis2adda372016-09-01 08:51:06 -070012645TEST_F(VkLayerTest, QueryPoolInUseDestroyedSignaled) {
12646 TEST_DESCRIPTION("Delete in-use query pool.");
12647
12648 ASSERT_NO_FATAL_FAILURE(InitState());
12649 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12650
12651 VkQueryPool query_pool;
12652 VkQueryPoolCreateInfo query_pool_ci{};
12653 query_pool_ci.sType = VK_STRUCTURE_TYPE_QUERY_POOL_CREATE_INFO;
12654 query_pool_ci.queryType = VK_QUERY_TYPE_TIMESTAMP;
12655 query_pool_ci.queryCount = 1;
12656 vkCreateQueryPool(m_device->device(), &query_pool_ci, nullptr, &query_pool);
12657 BeginCommandBuffer();
12658 // Reset query pool to create binding with cmd buffer
12659 vkCmdResetQueryPool(m_commandBuffer->handle(), query_pool, 0, 1);
12660
12661 EndCommandBuffer();
12662
12663 VkSubmitInfo submit_info = {};
12664 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
12665 submit_info.commandBufferCount = 1;
12666 submit_info.pCommandBuffers = &m_commandBuffer->handle();
12667 // Submit cmd buffer and then destroy query pool while in-flight
12668 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
12669
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012670 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Cannot delete query pool 0x");
Tobin Ehlis2adda372016-09-01 08:51:06 -070012671 vkDestroyQueryPool(m_device->handle(), query_pool, NULL);
12672 m_errorMonitor->VerifyFound();
12673
12674 vkQueueWaitIdle(m_device->m_queue);
12675 // Now that cmd buffer done we can safely destroy query_pool
12676 vkDestroyQueryPool(m_device->handle(), query_pool, NULL);
12677}
12678
Tobin Ehlisfafab2d2016-09-07 13:51:24 -060012679TEST_F(VkLayerTest, PipelineInUseDestroyedSignaled) {
12680 TEST_DESCRIPTION("Delete in-use pipeline.");
12681
12682 ASSERT_NO_FATAL_FAILURE(InitState());
12683 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12684
12685 // Empty pipeline layout used for binding PSO
12686 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
12687 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
12688 pipeline_layout_ci.setLayoutCount = 0;
12689 pipeline_layout_ci.pSetLayouts = NULL;
12690
12691 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012692 VkResult err = vkCreatePipelineLayout(m_device->handle(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlisfafab2d2016-09-07 13:51:24 -060012693 ASSERT_VK_SUCCESS(err);
12694
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012695 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Cannot delete pipeline 0x");
Tobin Ehlisfafab2d2016-09-07 13:51:24 -060012696 // Create PSO to be used for draw-time errors below
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012697 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
12698 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Tobin Ehlisfafab2d2016-09-07 13:51:24 -060012699 // Store pipeline handle so we can actually delete it before test finishes
12700 VkPipeline delete_this_pipeline;
12701 { // Scope pipeline so it will be auto-deleted
12702 VkPipelineObj pipe(m_device);
12703 pipe.AddShader(&vs);
12704 pipe.AddShader(&fs);
12705 pipe.AddColorAttachment();
12706 pipe.CreateVKPipeline(pipeline_layout, renderPass());
12707 delete_this_pipeline = pipe.handle();
12708
12709 BeginCommandBuffer();
12710 // Bind pipeline to cmd buffer
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012711 vkCmdBindPipeline(m_commandBuffer->handle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Tobin Ehlisfafab2d2016-09-07 13:51:24 -060012712
12713 EndCommandBuffer();
12714
12715 VkSubmitInfo submit_info = {};
12716 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
12717 submit_info.commandBufferCount = 1;
12718 submit_info.pCommandBuffers = &m_commandBuffer->handle();
12719 // Submit cmd buffer and then pipeline destroyed while in-flight
12720 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
12721 } // Pipeline deletion triggered here
12722 m_errorMonitor->VerifyFound();
12723 // Make sure queue finished and then actually delete pipeline
12724 vkQueueWaitIdle(m_device->m_queue);
12725 vkDestroyPipeline(m_device->handle(), delete_this_pipeline, nullptr);
12726 vkDestroyPipelineLayout(m_device->handle(), pipeline_layout, nullptr);
12727}
12728
Tobin Ehlis209532e2016-09-07 13:52:18 -060012729TEST_F(VkLayerTest, SamplerInUseDestroyedSignaled) {
12730 TEST_DESCRIPTION("Delete in-use sampler.");
12731
12732 ASSERT_NO_FATAL_FAILURE(InitState());
12733 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12734
12735 VkDescriptorPoolSize ds_type_count;
12736 ds_type_count.type = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
12737 ds_type_count.descriptorCount = 1;
12738
12739 VkDescriptorPoolCreateInfo ds_pool_ci = {};
12740 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
12741 ds_pool_ci.maxSets = 1;
12742 ds_pool_ci.poolSizeCount = 1;
12743 ds_pool_ci.pPoolSizes = &ds_type_count;
12744
12745 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012746 VkResult err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis209532e2016-09-07 13:52:18 -060012747 ASSERT_VK_SUCCESS(err);
12748
12749 VkSamplerCreateInfo sampler_ci = {};
12750 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
12751 sampler_ci.pNext = NULL;
12752 sampler_ci.magFilter = VK_FILTER_NEAREST;
12753 sampler_ci.minFilter = VK_FILTER_NEAREST;
12754 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
12755 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
12756 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
12757 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
12758 sampler_ci.mipLodBias = 1.0;
12759 sampler_ci.anisotropyEnable = VK_FALSE;
12760 sampler_ci.maxAnisotropy = 1;
12761 sampler_ci.compareEnable = VK_FALSE;
12762 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
12763 sampler_ci.minLod = 1.0;
12764 sampler_ci.maxLod = 1.0;
12765 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
12766 sampler_ci.unnormalizedCoordinates = VK_FALSE;
12767 VkSampler sampler;
12768
12769 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
12770 ASSERT_VK_SUCCESS(err);
12771
12772 VkDescriptorSetLayoutBinding layout_binding;
12773 layout_binding.binding = 0;
12774 layout_binding.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
12775 layout_binding.descriptorCount = 1;
12776 layout_binding.stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
12777 layout_binding.pImmutableSamplers = NULL;
12778
12779 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
12780 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
12781 ds_layout_ci.bindingCount = 1;
12782 ds_layout_ci.pBindings = &layout_binding;
12783 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012784 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis209532e2016-09-07 13:52:18 -060012785 ASSERT_VK_SUCCESS(err);
12786
12787 VkDescriptorSetAllocateInfo alloc_info = {};
12788 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
12789 alloc_info.descriptorSetCount = 1;
12790 alloc_info.descriptorPool = ds_pool;
12791 alloc_info.pSetLayouts = &ds_layout;
12792 VkDescriptorSet descriptor_set;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012793 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
Tobin Ehlis209532e2016-09-07 13:52:18 -060012794 ASSERT_VK_SUCCESS(err);
12795
12796 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
12797 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
12798 pipeline_layout_ci.pNext = NULL;
12799 pipeline_layout_ci.setLayoutCount = 1;
12800 pipeline_layout_ci.pSetLayouts = &ds_layout;
12801
12802 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012803 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis209532e2016-09-07 13:52:18 -060012804 ASSERT_VK_SUCCESS(err);
12805
12806 VkImageObj image(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012807 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 -060012808 ASSERT_TRUE(image.initialized());
12809
12810 VkImageView view;
12811 VkImageViewCreateInfo ivci = {};
12812 ivci.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
12813 ivci.image = image.handle();
12814 ivci.viewType = VK_IMAGE_VIEW_TYPE_2D;
12815 ivci.format = VK_FORMAT_R8G8B8A8_UNORM;
12816 ivci.subresourceRange.layerCount = 1;
12817 ivci.subresourceRange.baseMipLevel = 0;
12818 ivci.subresourceRange.levelCount = 1;
12819 ivci.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
12820
12821 err = vkCreateImageView(m_device->device(), &ivci, NULL, &view);
12822 ASSERT_VK_SUCCESS(err);
12823
12824 VkDescriptorImageInfo image_info{};
12825 image_info.imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
12826 image_info.imageView = view;
12827 image_info.sampler = sampler;
12828
12829 VkWriteDescriptorSet descriptor_write = {};
12830 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
12831 descriptor_write.dstSet = descriptor_set;
12832 descriptor_write.dstBinding = 0;
12833 descriptor_write.descriptorCount = 1;
12834 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
12835 descriptor_write.pImageInfo = &image_info;
12836
12837 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
12838
12839 // Create PSO to use the sampler
12840 char const *vsSource = "#version 450\n"
12841 "\n"
12842 "out gl_PerVertex { \n"
12843 " vec4 gl_Position;\n"
12844 "};\n"
12845 "void main(){\n"
12846 " gl_Position = vec4(1);\n"
12847 "}\n";
12848 char const *fsSource = "#version 450\n"
12849 "\n"
12850 "layout(set=0, binding=0) uniform sampler2D s;\n"
12851 "layout(location=0) out vec4 x;\n"
12852 "void main(){\n"
12853 " x = texture(s, vec2(1));\n"
12854 "}\n";
12855 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
12856 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
12857 VkPipelineObj pipe(m_device);
12858 pipe.AddShader(&vs);
12859 pipe.AddShader(&fs);
12860 pipe.AddColorAttachment();
12861 pipe.CreateVKPipeline(pipeline_layout, renderPass());
12862
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012863 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Cannot delete sampler 0x");
Tobin Ehlis209532e2016-09-07 13:52:18 -060012864
12865 BeginCommandBuffer();
12866 // Bind pipeline to cmd buffer
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012867 vkCmdBindPipeline(m_commandBuffer->handle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
12868 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
12869 &descriptor_set, 0, nullptr);
Tobin Ehlis209532e2016-09-07 13:52:18 -060012870 Draw(1, 0, 0, 0);
12871 EndCommandBuffer();
12872 // Submit cmd buffer then destroy sampler
12873 VkSubmitInfo submit_info = {};
12874 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
12875 submit_info.commandBufferCount = 1;
12876 submit_info.pCommandBuffers = &m_commandBuffer->handle();
12877 // Submit cmd buffer and then destroy sampler while in-flight
12878 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
12879
12880 vkDestroySampler(m_device->device(), sampler, nullptr);
12881 m_errorMonitor->VerifyFound();
12882 vkQueueWaitIdle(m_device->m_queue);
12883 // Now we can actually destroy sampler
12884 vkDestroySampler(m_device->device(), sampler, nullptr);
12885 vkDestroyImageView(m_device->device(), view, NULL);
12886 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
12887 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
12888 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
12889}
12890
Mark Mueller1cd9f412016-08-25 13:23:52 -060012891TEST_F(VkLayerTest, QueueForwardProgressFenceWait) {
Mark Mueller96a56d52016-08-24 10:28:05 -060012892 TEST_DESCRIPTION("Call VkQueueSubmit with a semaphore that is already "
Mark Mueller1cd9f412016-08-25 13:23:52 -060012893 "signaled but not waited on by the queue. Wait on a "
12894 "fence that has not yet been submitted to a queue.");
Mark Mueller96a56d52016-08-24 10:28:05 -060012895
12896 ASSERT_NO_FATAL_FAILURE(InitState());
12897 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12898
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012899 const char *queue_forward_progress_message = " that has already been signaled but not waited on by queue 0x";
12900 const char *invalid_fence_wait_message = " which has not been submitted on a Queue or during "
12901 "acquire next image.";
Mark Mueller96a56d52016-08-24 10:28:05 -060012902
12903 BeginCommandBuffer();
12904 EndCommandBuffer();
12905
12906 VkSemaphoreCreateInfo semaphore_create_info = {};
12907 semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
12908 VkSemaphore semaphore;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012909 ASSERT_VK_SUCCESS(vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr, &semaphore));
Mark Mueller96a56d52016-08-24 10:28:05 -060012910 VkSubmitInfo submit_info = {};
12911 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
12912 submit_info.commandBufferCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012913 submit_info.pCommandBuffers = &m_commandBuffer->handle();
Mark Mueller96a56d52016-08-24 10:28:05 -060012914 submit_info.signalSemaphoreCount = 1;
12915 submit_info.pSignalSemaphores = &semaphore;
12916 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
12917 m_errorMonitor->SetDesiredFailureMsg(0, "");
12918 vkResetCommandBuffer(m_commandBuffer->handle(), 0);
12919 BeginCommandBuffer();
12920 EndCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012921 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, queue_forward_progress_message);
Mark Mueller96a56d52016-08-24 10:28:05 -060012922 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
12923 m_errorMonitor->VerifyFound();
12924
Mark Mueller1cd9f412016-08-25 13:23:52 -060012925 VkFenceCreateInfo fence_create_info = {};
12926 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
12927 VkFence fence;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012928 ASSERT_VK_SUCCESS(vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence));
Mark Mueller1cd9f412016-08-25 13:23:52 -060012929
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012930 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT, invalid_fence_wait_message);
Mark Mueller1cd9f412016-08-25 13:23:52 -060012931 vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
12932 m_errorMonitor->VerifyFound();
12933
Mark Mueller4042b652016-09-05 22:52:21 -060012934 vkDeviceWaitIdle(m_device->device());
Mark Mueller1cd9f412016-08-25 13:23:52 -060012935 vkDestroyFence(m_device->device(), fence, nullptr);
Mark Mueller96a56d52016-08-24 10:28:05 -060012936 vkDestroySemaphore(m_device->device(), semaphore, nullptr);
12937}
12938
Tobin Ehlis4af23302016-07-19 10:50:30 -060012939TEST_F(VkLayerTest, FramebufferIncompatible) {
12940 TEST_DESCRIPTION("Bind a secondary command buffer with with a framebuffer "
12941 "that does not match the framebuffer for the active "
12942 "renderpass.");
12943 ASSERT_NO_FATAL_FAILURE(InitState());
12944 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12945
12946 // A renderpass with one color attachment.
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012947 VkAttachmentDescription attachment = {0,
12948 VK_FORMAT_B8G8R8A8_UNORM,
12949 VK_SAMPLE_COUNT_1_BIT,
12950 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
12951 VK_ATTACHMENT_STORE_OP_STORE,
12952 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
12953 VK_ATTACHMENT_STORE_OP_DONT_CARE,
12954 VK_IMAGE_LAYOUT_UNDEFINED,
12955 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL};
Tobin Ehlis4af23302016-07-19 10:50:30 -060012956
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012957 VkAttachmentReference att_ref = {0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL};
Tobin Ehlis4af23302016-07-19 10:50:30 -060012958
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012959 VkSubpassDescription subpass = {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 1, &att_ref, nullptr, nullptr, 0, nullptr};
Tobin Ehlis4af23302016-07-19 10:50:30 -060012960
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012961 VkRenderPassCreateInfo rpci = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 1, &attachment, 1, &subpass, 0, nullptr};
Tobin Ehlis4af23302016-07-19 10:50:30 -060012962
12963 VkRenderPass rp;
12964 VkResult err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
12965 ASSERT_VK_SUCCESS(err);
12966
12967 // A compatible framebuffer.
12968 VkImageObj image(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012969 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 -060012970 ASSERT_TRUE(image.initialized());
12971
12972 VkImageViewCreateInfo ivci = {
12973 VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO,
12974 nullptr,
12975 0,
12976 image.handle(),
12977 VK_IMAGE_VIEW_TYPE_2D,
12978 VK_FORMAT_B8G8R8A8_UNORM,
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012979 {VK_COMPONENT_SWIZZLE_IDENTITY, VK_COMPONENT_SWIZZLE_IDENTITY, VK_COMPONENT_SWIZZLE_IDENTITY,
12980 VK_COMPONENT_SWIZZLE_IDENTITY},
Tobin Ehlis4af23302016-07-19 10:50:30 -060012981 {VK_IMAGE_ASPECT_COLOR_BIT, 0, 1, 0, 1},
12982 };
12983 VkImageView view;
12984 err = vkCreateImageView(m_device->device(), &ivci, nullptr, &view);
12985 ASSERT_VK_SUCCESS(err);
12986
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012987 VkFramebufferCreateInfo fci = {VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr, 0, rp, 1, &view, 32, 32, 1};
Tobin Ehlis4af23302016-07-19 10:50:30 -060012988 VkFramebuffer fb;
12989 err = vkCreateFramebuffer(m_device->device(), &fci, nullptr, &fb);
12990 ASSERT_VK_SUCCESS(err);
12991
12992 VkCommandBufferAllocateInfo cbai = {};
12993 cbai.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
12994 cbai.commandPool = m_commandPool;
12995 cbai.level = VK_COMMAND_BUFFER_LEVEL_SECONDARY;
12996 cbai.commandBufferCount = 1;
12997
12998 VkCommandBuffer sec_cb;
12999 err = vkAllocateCommandBuffers(m_device->device(), &cbai, &sec_cb);
13000 ASSERT_VK_SUCCESS(err);
13001 VkCommandBufferBeginInfo cbbi = {};
13002 VkCommandBufferInheritanceInfo cbii = {};
13003 cbii.renderPass = renderPass();
13004 cbii.framebuffer = fb;
13005 cbbi.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
13006 cbbi.pNext = NULL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013007 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 -060013008 cbbi.pInheritanceInfo = &cbii;
13009 vkBeginCommandBuffer(sec_cb, &cbbi);
13010 vkEndCommandBuffer(sec_cb);
13011
Chris Forbes3400bc52016-09-13 18:10:34 +120013012 VkCommandBufferBeginInfo cbbi2 = {
13013 VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO, nullptr,
13014 0, nullptr
13015 };
13016 vkBeginCommandBuffer(m_commandBuffer->GetBufferHandle(), &cbbi2);
13017 vkCmdBeginRenderPass(m_commandBuffer->GetBufferHandle(), &m_renderPassBeginInfo, VK_SUBPASS_CONTENTS_SECONDARY_COMMAND_BUFFERS);
Tobin Ehlis4af23302016-07-19 10:50:30 -060013018
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013019 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
13020 " that is not the same as the primaryCB's current active framebuffer ");
Tobin Ehlis4af23302016-07-19 10:50:30 -060013021 vkCmdExecuteCommands(m_commandBuffer->GetBufferHandle(), 1, &sec_cb);
13022 m_errorMonitor->VerifyFound();
13023 // Cleanup
13024 vkDestroyImageView(m_device->device(), view, NULL);
13025 vkDestroyRenderPass(m_device->device(), rp, NULL);
13026 vkDestroyFramebuffer(m_device->device(), fb, NULL);
13027}
Tobin Ehlis52b504f2016-07-19 13:25:12 -060013028
13029TEST_F(VkLayerTest, ColorBlendLogicOpTests) {
13030 TEST_DESCRIPTION("If logicOp is available on the device, set it to an "
13031 "invalid value. If logicOp is not available, attempt to "
13032 "use it and verify that we see the correct error.");
13033 ASSERT_NO_FATAL_FAILURE(InitState());
13034 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13035
13036 auto features = m_device->phy().features();
13037 // Set the expected error depending on whether or not logicOp available
13038 if (VK_FALSE == features.logicOp) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013039 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "If logic operations feature not "
13040 "enabled, logicOpEnable must be "
13041 "VK_FALSE");
Tobin Ehlis52b504f2016-07-19 13:25:12 -060013042 } else {
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013043 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, ", logicOp must be a valid VkLogicOp value");
Tobin Ehlis52b504f2016-07-19 13:25:12 -060013044 }
13045 // Create a pipeline using logicOp
13046 VkResult err;
13047
13048 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
13049 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
13050
13051 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013052 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis52b504f2016-07-19 13:25:12 -060013053 ASSERT_VK_SUCCESS(err);
13054
13055 VkPipelineViewportStateCreateInfo vp_state_ci = {};
13056 vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
13057 vp_state_ci.viewportCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013058 VkViewport vp = {}; // Just need dummy vp to point to
Tobin Ehlis52b504f2016-07-19 13:25:12 -060013059 vp_state_ci.pViewports = &vp;
13060 vp_state_ci.scissorCount = 1;
13061 VkRect2D scissors = {}; // Dummy scissors to point to
13062 vp_state_ci.pScissors = &scissors;
13063 // No dynamic state
13064 VkPipelineDynamicStateCreateInfo dyn_state_ci = {};
13065 dyn_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_DYNAMIC_STATE_CREATE_INFO;
13066
13067 VkPipelineShaderStageCreateInfo shaderStages[2];
13068 memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo));
13069
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013070 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
13071 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Tobin Ehlis52b504f2016-07-19 13:25:12 -060013072 shaderStages[0] = vs.GetStageCreateInfo();
13073 shaderStages[1] = fs.GetStageCreateInfo();
13074
13075 VkPipelineVertexInputStateCreateInfo vi_ci = {};
13076 vi_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
13077
13078 VkPipelineInputAssemblyStateCreateInfo ia_ci = {};
13079 ia_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
13080 ia_ci.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP;
13081
13082 VkPipelineRasterizationStateCreateInfo rs_ci = {};
13083 rs_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
13084
13085 VkPipelineColorBlendAttachmentState att = {};
13086 att.blendEnable = VK_FALSE;
13087 att.colorWriteMask = 0xf;
13088
13089 VkPipelineColorBlendStateCreateInfo cb_ci = {};
13090 cb_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO;
13091 // Enable logicOp & set logicOp to value 1 beyond allowed entries
13092 cb_ci.logicOpEnable = VK_TRUE;
13093 cb_ci.logicOp = VK_LOGIC_OP_RANGE_SIZE; // This should cause an error
13094 cb_ci.attachmentCount = 1;
13095 cb_ci.pAttachments = &att;
13096
13097 VkGraphicsPipelineCreateInfo gp_ci = {};
13098 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
13099 gp_ci.stageCount = 2;
13100 gp_ci.pStages = shaderStages;
13101 gp_ci.pVertexInputState = &vi_ci;
13102 gp_ci.pInputAssemblyState = &ia_ci;
13103 gp_ci.pViewportState = &vp_state_ci;
13104 gp_ci.pRasterizationState = &rs_ci;
13105 gp_ci.pColorBlendState = &cb_ci;
13106 gp_ci.pDynamicState = &dyn_state_ci;
13107 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
13108 gp_ci.layout = pipeline_layout;
13109 gp_ci.renderPass = renderPass();
13110
13111 VkPipelineCacheCreateInfo pc_ci = {};
13112 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
13113
13114 VkPipeline pipeline;
13115 VkPipelineCache pipelineCache;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013116 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Tobin Ehlis52b504f2016-07-19 13:25:12 -060013117 ASSERT_VK_SUCCESS(err);
13118
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013119 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Tobin Ehlis52b504f2016-07-19 13:25:12 -060013120 m_errorMonitor->VerifyFound();
13121 if (VK_SUCCESS == err) {
13122 vkDestroyPipeline(m_device->device(), pipeline, NULL);
13123 }
13124 m_errorMonitor->VerifyFound();
13125 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
13126 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
13127}
Mark Lobodzinski209b5292015-09-17 09:44:05 -060013128#endif // DRAW_STATE_TESTS
13129
Tobin Ehlis0788f522015-05-26 16:11:58 -060013130#if THREADING_TESTS
Mike Stroyanaccf7692015-05-12 16:00:45 -060013131#if GTEST_IS_THREADSAFE
13132struct thread_data_struct {
Chia-I Wu3432a0c2015-10-27 18:04:07 +080013133 VkCommandBuffer commandBuffer;
Mike Stroyanaccf7692015-05-12 16:00:45 -060013134 VkEvent event;
13135 bool bailout;
13136};
13137
Karl Schultz6addd812016-02-02 17:17:23 -070013138extern "C" void *AddToCommandBuffer(void *arg) {
13139 struct thread_data_struct *data = (struct thread_data_struct *)arg;
Mike Stroyanaccf7692015-05-12 16:00:45 -060013140
Mike Stroyana6d14942016-07-13 15:10:05 -060013141 for (int i = 0; i < 80000; i++) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013142 vkCmdSetEvent(data->commandBuffer, data->event, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT);
Mike Stroyanaccf7692015-05-12 16:00:45 -060013143 if (data->bailout) {
13144 break;
13145 }
13146 }
13147 return NULL;
13148}
13149
Karl Schultz6addd812016-02-02 17:17:23 -070013150TEST_F(VkLayerTest, ThreadCommandBufferCollision) {
Mike Stroyan4268d1f2015-07-13 14:45:35 -060013151 test_platform_thread thread;
Mike Stroyanaccf7692015-05-12 16:00:45 -060013152
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013153 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "THREADING ERROR");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060013154
Mike Stroyanaccf7692015-05-12 16:00:45 -060013155 ASSERT_NO_FATAL_FAILURE(InitState());
13156 ASSERT_NO_FATAL_FAILURE(InitViewport());
13157 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13158
Chia-I Wu3432a0c2015-10-27 18:04:07 +080013159 // Calls AllocateCommandBuffers
13160 VkCommandBufferObj commandBuffer(m_device, m_commandPool);
Mark Lobodzinski5495d132015-09-30 16:19:16 -060013161
13162 // Avoid creating RenderPass
Chia-I Wu3432a0c2015-10-27 18:04:07 +080013163 commandBuffer.BeginCommandBuffer();
Mike Stroyanaccf7692015-05-12 16:00:45 -060013164
13165 VkEventCreateInfo event_info;
13166 VkEvent event;
Mike Stroyanaccf7692015-05-12 16:00:45 -060013167 VkResult err;
13168
13169 memset(&event_info, 0, sizeof(event_info));
13170 event_info.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO;
13171
Chia-I Wuf7458c52015-10-26 21:10:41 +080013172 err = vkCreateEvent(device(), &event_info, NULL, &event);
Mike Stroyanaccf7692015-05-12 16:00:45 -060013173 ASSERT_VK_SUCCESS(err);
13174
Mike Stroyanaccf7692015-05-12 16:00:45 -060013175 err = vkResetEvent(device(), event);
13176 ASSERT_VK_SUCCESS(err);
13177
13178 struct thread_data_struct data;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080013179 data.commandBuffer = commandBuffer.GetBufferHandle();
Mike Stroyanaccf7692015-05-12 16:00:45 -060013180 data.event = event;
13181 data.bailout = false;
13182 m_errorMonitor->SetBailout(&data.bailout);
Mike Stroyana6d14942016-07-13 15:10:05 -060013183
13184 // First do some correct operations using multiple threads.
13185 // Add many entries to command buffer from another thread.
13186 test_platform_thread_create(&thread, AddToCommandBuffer, (void *)&data);
13187 // Make non-conflicting calls from this thread at the same time.
13188 for (int i = 0; i < 80000; i++) {
Mike Stroyand6343902016-07-14 08:56:16 -060013189 uint32_t count;
13190 vkEnumeratePhysicalDevices(instance(), &count, NULL);
Mike Stroyana6d14942016-07-13 15:10:05 -060013191 }
13192 test_platform_thread_join(thread, NULL);
13193
13194 // Then do some incorrect operations using multiple threads.
Mike Stroyanaccf7692015-05-12 16:00:45 -060013195 // Add many entries to command buffer from another thread.
Mike Stroyan4268d1f2015-07-13 14:45:35 -060013196 test_platform_thread_create(&thread, AddToCommandBuffer, (void *)&data);
Mike Stroyanaccf7692015-05-12 16:00:45 -060013197 // Add many entries to command buffer from this thread at the same time.
13198 AddToCommandBuffer(&data);
Mark Lobodzinski5495d132015-09-30 16:19:16 -060013199
Mike Stroyan4268d1f2015-07-13 14:45:35 -060013200 test_platform_thread_join(thread, NULL);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080013201 commandBuffer.EndCommandBuffer();
Mike Stroyanaccf7692015-05-12 16:00:45 -060013202
Mike Stroyan10b8cb72016-01-22 15:22:03 -070013203 m_errorMonitor->SetBailout(NULL);
13204
Chris Forbes8f36a8a2016-04-07 13:21:07 +120013205 m_errorMonitor->VerifyFound();
Mike Stroyanaccf7692015-05-12 16:00:45 -060013206
Chia-I Wuf7458c52015-10-26 21:10:41 +080013207 vkDestroyEvent(device(), event, NULL);
Mike Stroyanaccf7692015-05-12 16:00:45 -060013208}
Mark Lobodzinski209b5292015-09-17 09:44:05 -060013209#endif // GTEST_IS_THREADSAFE
13210#endif // THREADING_TESTS
13211
Chris Forbes9f7ff632015-05-25 11:13:08 +120013212#if SHADER_CHECKER_TESTS
Karl Schultz6addd812016-02-02 17:17:23 -070013213TEST_F(VkLayerTest, InvalidSPIRVCodeSize) {
Chris Forbes1cc79542016-07-20 11:13:44 +120013214 TEST_DESCRIPTION("Test that an error is produced for a spirv module "
13215 "with an impossible code size");
13216
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013217 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Invalid SPIR-V header");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060013218
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060013219 ASSERT_NO_FATAL_FAILURE(InitState());
13220 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13221
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060013222 VkShaderModule module;
13223 VkShaderModuleCreateInfo moduleCreateInfo;
13224 struct icd_spv_header spv;
13225
13226 spv.magic = ICD_SPV_MAGIC;
13227 spv.version = ICD_SPV_VERSION;
13228 spv.gen_magic = 0;
13229
13230 moduleCreateInfo.sType = VK_STRUCTURE_TYPE_SHADER_MODULE_CREATE_INFO;
13231 moduleCreateInfo.pNext = NULL;
Karl Schultz6addd812016-02-02 17:17:23 -070013232 moduleCreateInfo.pCode = (const uint32_t *)&spv;
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060013233 moduleCreateInfo.codeSize = 4;
13234 moduleCreateInfo.flags = 0;
Chia-I Wuf7458c52015-10-26 21:10:41 +080013235 vkCreateShaderModule(m_device->device(), &moduleCreateInfo, NULL, &module);
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060013236
Chris Forbes8f36a8a2016-04-07 13:21:07 +120013237 m_errorMonitor->VerifyFound();
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060013238}
13239
Karl Schultz6addd812016-02-02 17:17:23 -070013240TEST_F(VkLayerTest, InvalidSPIRVMagic) {
Chris Forbes1cc79542016-07-20 11:13:44 +120013241 TEST_DESCRIPTION("Test that an error is produced for a spirv module "
13242 "with a bad magic number");
13243
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013244 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Invalid SPIR-V magic number");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060013245
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060013246 ASSERT_NO_FATAL_FAILURE(InitState());
13247 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13248
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060013249 VkShaderModule module;
13250 VkShaderModuleCreateInfo moduleCreateInfo;
13251 struct icd_spv_header spv;
13252
13253 spv.magic = ~ICD_SPV_MAGIC;
13254 spv.version = ICD_SPV_VERSION;
13255 spv.gen_magic = 0;
13256
13257 moduleCreateInfo.sType = VK_STRUCTURE_TYPE_SHADER_MODULE_CREATE_INFO;
13258 moduleCreateInfo.pNext = NULL;
Karl Schultz6addd812016-02-02 17:17:23 -070013259 moduleCreateInfo.pCode = (const uint32_t *)&spv;
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060013260 moduleCreateInfo.codeSize = sizeof(spv) + 10;
13261 moduleCreateInfo.flags = 0;
Chia-I Wuf7458c52015-10-26 21:10:41 +080013262 vkCreateShaderModule(m_device->device(), &moduleCreateInfo, NULL, &module);
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060013263
Chris Forbes8f36a8a2016-04-07 13:21:07 +120013264 m_errorMonitor->VerifyFound();
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060013265}
13266
Chris Forbesb4afd0f2016-04-04 10:48:35 +120013267#if 0
13268// Not currently covered by SPIRV-Tools validator
Karl Schultz6addd812016-02-02 17:17:23 -070013269TEST_F(VkLayerTest, InvalidSPIRVVersion) {
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -070013270 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Chris Forbesb4afd0f2016-04-04 10:48:35 +120013271 "Invalid SPIR-V header");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060013272
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060013273 ASSERT_NO_FATAL_FAILURE(InitState());
13274 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13275
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060013276 VkShaderModule module;
13277 VkShaderModuleCreateInfo moduleCreateInfo;
13278 struct icd_spv_header spv;
13279
13280 spv.magic = ICD_SPV_MAGIC;
13281 spv.version = ~ICD_SPV_VERSION;
13282 spv.gen_magic = 0;
13283
13284 moduleCreateInfo.sType = VK_STRUCTURE_TYPE_SHADER_MODULE_CREATE_INFO;
13285 moduleCreateInfo.pNext = NULL;
13286
Karl Schultz6addd812016-02-02 17:17:23 -070013287 moduleCreateInfo.pCode = (const uint32_t *)&spv;
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060013288 moduleCreateInfo.codeSize = sizeof(spv) + 10;
13289 moduleCreateInfo.flags = 0;
Chia-I Wuf7458c52015-10-26 21:10:41 +080013290 vkCreateShaderModule(m_device->device(), &moduleCreateInfo, NULL, &module);
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060013291
Chris Forbes8f36a8a2016-04-07 13:21:07 +120013292 m_errorMonitor->VerifyFound();
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060013293}
Chris Forbesb4afd0f2016-04-04 10:48:35 +120013294#endif
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060013295
Karl Schultz6addd812016-02-02 17:17:23 -070013296TEST_F(VkLayerTest, CreatePipelineVertexOutputNotConsumed) {
Chris Forbes1cc79542016-07-20 11:13:44 +120013297 TEST_DESCRIPTION("Test that a warning is produced for a vertex output that "
13298 "is not consumed by the fragment stage");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013299 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT, "not consumed by fragment shader");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060013300
Chris Forbes9f7ff632015-05-25 11:13:08 +120013301 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -060013302 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbes9f7ff632015-05-25 11:13:08 +120013303
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013304 char const *vsSource = "#version 450\n"
13305 "\n"
13306 "layout(location=0) out float x;\n"
13307 "out gl_PerVertex {\n"
13308 " vec4 gl_Position;\n"
13309 "};\n"
13310 "void main(){\n"
13311 " gl_Position = vec4(1);\n"
13312 " x = 0;\n"
13313 "}\n";
13314 char const *fsSource = "#version 450\n"
13315 "\n"
13316 "layout(location=0) out vec4 color;\n"
13317 "void main(){\n"
13318 " color = vec4(1);\n"
13319 "}\n";
Chris Forbes9f7ff632015-05-25 11:13:08 +120013320
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060013321 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13322 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbes9f7ff632015-05-25 11:13:08 +120013323
13324 VkPipelineObj pipe(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +080013325 pipe.AddColorAttachment();
Chris Forbes9f7ff632015-05-25 11:13:08 +120013326 pipe.AddShader(&vs);
13327 pipe.AddShader(&fs);
13328
Chris Forbes9f7ff632015-05-25 11:13:08 +120013329 VkDescriptorSetObj descriptorSet(m_device);
13330 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080013331 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbes9f7ff632015-05-25 11:13:08 +120013332
Tony Barbour5781e8f2015-08-04 16:23:11 -060013333 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbes9f7ff632015-05-25 11:13:08 +120013334
Chris Forbes8f36a8a2016-04-07 13:21:07 +120013335 m_errorMonitor->VerifyFound();
Chris Forbes9f7ff632015-05-25 11:13:08 +120013336}
Chris Forbes9f7ff632015-05-25 11:13:08 +120013337
Karl Schultz6addd812016-02-02 17:17:23 -070013338TEST_F(VkLayerTest, CreatePipelineFragmentInputNotProvided) {
Chris Forbes1cc79542016-07-20 11:13:44 +120013339 TEST_DESCRIPTION("Test that an error is produced for a fragment shader input "
13340 "which is not present in the outputs of the previous stage");
13341
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013342 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "not written by vertex shader");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060013343
Chris Forbes59cb88d2015-05-25 11:13:13 +120013344 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -060013345 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbes59cb88d2015-05-25 11:13:13 +120013346
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013347 char const *vsSource = "#version 450\n"
13348 "\n"
13349 "out gl_PerVertex {\n"
13350 " vec4 gl_Position;\n"
13351 "};\n"
13352 "void main(){\n"
13353 " gl_Position = vec4(1);\n"
13354 "}\n";
13355 char const *fsSource = "#version 450\n"
13356 "\n"
13357 "layout(location=0) in float x;\n"
13358 "layout(location=0) out vec4 color;\n"
13359 "void main(){\n"
13360 " color = vec4(x);\n"
13361 "}\n";
Chris Forbes59cb88d2015-05-25 11:13:13 +120013362
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060013363 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13364 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbes59cb88d2015-05-25 11:13:13 +120013365
13366 VkPipelineObj pipe(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +080013367 pipe.AddColorAttachment();
Chris Forbes59cb88d2015-05-25 11:13:13 +120013368 pipe.AddShader(&vs);
13369 pipe.AddShader(&fs);
13370
Chris Forbes59cb88d2015-05-25 11:13:13 +120013371 VkDescriptorSetObj descriptorSet(m_device);
13372 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080013373 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbes59cb88d2015-05-25 11:13:13 +120013374
Tony Barbour5781e8f2015-08-04 16:23:11 -060013375 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbes59cb88d2015-05-25 11:13:13 +120013376
Chris Forbes8f36a8a2016-04-07 13:21:07 +120013377 m_errorMonitor->VerifyFound();
Chris Forbes59cb88d2015-05-25 11:13:13 +120013378}
13379
Karl Schultz6addd812016-02-02 17:17:23 -070013380TEST_F(VkLayerTest, CreatePipelineFragmentInputNotProvidedInBlock) {
Chris Forbes1cc79542016-07-20 11:13:44 +120013381 TEST_DESCRIPTION("Test that an error is produced for a fragment shader input "
13382 "within an interace block, which is not present in the outputs "
13383 "of the previous stage.");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013384 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "not written by vertex shader");
Chris Forbesa3e85f62016-01-15 14:53:11 +130013385
13386 ASSERT_NO_FATAL_FAILURE(InitState());
13387 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13388
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013389 char const *vsSource = "#version 450\n"
13390 "\n"
13391 "out gl_PerVertex {\n"
13392 " vec4 gl_Position;\n"
13393 "};\n"
13394 "void main(){\n"
13395 " gl_Position = vec4(1);\n"
13396 "}\n";
13397 char const *fsSource = "#version 450\n"
13398 "\n"
13399 "in block { layout(location=0) float x; } ins;\n"
13400 "layout(location=0) out vec4 color;\n"
13401 "void main(){\n"
13402 " color = vec4(ins.x);\n"
13403 "}\n";
Chris Forbesa3e85f62016-01-15 14:53:11 +130013404
13405 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13406 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
13407
13408 VkPipelineObj pipe(m_device);
13409 pipe.AddColorAttachment();
13410 pipe.AddShader(&vs);
13411 pipe.AddShader(&fs);
13412
13413 VkDescriptorSetObj descriptorSet(m_device);
13414 descriptorSet.AppendDummy();
13415 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
13416
13417 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
13418
Chris Forbes8f36a8a2016-04-07 13:21:07 +120013419 m_errorMonitor->VerifyFound();
Chris Forbesa3e85f62016-01-15 14:53:11 +130013420}
13421
Karl Schultz6addd812016-02-02 17:17:23 -070013422TEST_F(VkLayerTest, CreatePipelineVsFsTypeMismatchArraySize) {
Chris Forbes1cc79542016-07-20 11:13:44 +120013423 TEST_DESCRIPTION("Test that an error is produced for mismatched array sizes "
13424 "across the VS->FS interface");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013425 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Type mismatch on location 0.0: 'ptr to "
13426 "output arr[2] of float32' vs 'ptr to "
13427 "input arr[3] of float32'");
Chris Forbes0036fd12016-01-26 14:19:49 +130013428
13429 ASSERT_NO_FATAL_FAILURE(InitState());
13430 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13431
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013432 char const *vsSource = "#version 450\n"
13433 "\n"
13434 "layout(location=0) out float x[2];\n"
13435 "out gl_PerVertex {\n"
13436 " vec4 gl_Position;\n"
13437 "};\n"
13438 "void main(){\n"
13439 " x[0] = 0; x[1] = 0;\n"
13440 " gl_Position = vec4(1);\n"
13441 "}\n";
13442 char const *fsSource = "#version 450\n"
13443 "\n"
13444 "layout(location=0) in float x[3];\n"
13445 "layout(location=0) out vec4 color;\n"
13446 "void main(){\n"
13447 " color = vec4(x[0] + x[1] + x[2]);\n"
13448 "}\n";
Chris Forbes0036fd12016-01-26 14:19:49 +130013449
13450 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13451 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
13452
13453 VkPipelineObj pipe(m_device);
13454 pipe.AddColorAttachment();
13455 pipe.AddShader(&vs);
13456 pipe.AddShader(&fs);
13457
13458 VkDescriptorSetObj descriptorSet(m_device);
13459 descriptorSet.AppendDummy();
13460 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
13461
13462 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
13463
Chris Forbes8f36a8a2016-04-07 13:21:07 +120013464 m_errorMonitor->VerifyFound();
Chris Forbes0036fd12016-01-26 14:19:49 +130013465}
13466
Karl Schultz6addd812016-02-02 17:17:23 -070013467TEST_F(VkLayerTest, CreatePipelineVsFsTypeMismatch) {
Chris Forbes1cc79542016-07-20 11:13:44 +120013468 TEST_DESCRIPTION("Test that an error is produced for mismatched types across "
13469 "the VS->FS interface");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013470 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Type mismatch on location 0");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060013471
Chris Forbesb56af562015-05-25 11:13:17 +120013472 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -060013473 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbesb56af562015-05-25 11:13:17 +120013474
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013475 char const *vsSource = "#version 450\n"
13476 "\n"
13477 "layout(location=0) out int x;\n"
13478 "out gl_PerVertex {\n"
13479 " vec4 gl_Position;\n"
13480 "};\n"
13481 "void main(){\n"
13482 " x = 0;\n"
13483 " gl_Position = vec4(1);\n"
13484 "}\n";
13485 char const *fsSource = "#version 450\n"
13486 "\n"
13487 "layout(location=0) in float x;\n" /* VS writes int */
13488 "layout(location=0) out vec4 color;\n"
13489 "void main(){\n"
13490 " color = vec4(x);\n"
13491 "}\n";
Chris Forbesb56af562015-05-25 11:13:17 +120013492
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060013493 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13494 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbesb56af562015-05-25 11:13:17 +120013495
13496 VkPipelineObj pipe(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +080013497 pipe.AddColorAttachment();
Chris Forbesb56af562015-05-25 11:13:17 +120013498 pipe.AddShader(&vs);
13499 pipe.AddShader(&fs);
13500
Chris Forbesb56af562015-05-25 11:13:17 +120013501 VkDescriptorSetObj descriptorSet(m_device);
13502 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080013503 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbesb56af562015-05-25 11:13:17 +120013504
Tony Barbour5781e8f2015-08-04 16:23:11 -060013505 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbesb56af562015-05-25 11:13:17 +120013506
Chris Forbes8f36a8a2016-04-07 13:21:07 +120013507 m_errorMonitor->VerifyFound();
Chris Forbesb56af562015-05-25 11:13:17 +120013508}
13509
Karl Schultz6addd812016-02-02 17:17:23 -070013510TEST_F(VkLayerTest, CreatePipelineVsFsTypeMismatchInBlock) {
Chris Forbes1cc79542016-07-20 11:13:44 +120013511 TEST_DESCRIPTION("Test that an error is produced for mismatched types across "
13512 "the VS->FS interface, when the variable is contained within "
13513 "an interface block");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013514 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Type mismatch on location 0");
Chris Forbesa3e85f62016-01-15 14:53:11 +130013515
13516 ASSERT_NO_FATAL_FAILURE(InitState());
13517 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13518
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013519 char const *vsSource = "#version 450\n"
13520 "\n"
13521 "out block { layout(location=0) int x; } outs;\n"
13522 "out gl_PerVertex {\n"
13523 " vec4 gl_Position;\n"
13524 "};\n"
13525 "void main(){\n"
13526 " outs.x = 0;\n"
13527 " gl_Position = vec4(1);\n"
13528 "}\n";
13529 char const *fsSource = "#version 450\n"
13530 "\n"
13531 "in block { layout(location=0) float x; } ins;\n" /* VS writes int */
13532 "layout(location=0) out vec4 color;\n"
13533 "void main(){\n"
13534 " color = vec4(ins.x);\n"
13535 "}\n";
Chris Forbesa3e85f62016-01-15 14:53:11 +130013536
13537 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13538 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
13539
13540 VkPipelineObj pipe(m_device);
13541 pipe.AddColorAttachment();
13542 pipe.AddShader(&vs);
13543 pipe.AddShader(&fs);
13544
13545 VkDescriptorSetObj descriptorSet(m_device);
13546 descriptorSet.AppendDummy();
13547 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
13548
13549 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
13550
Chris Forbes8f36a8a2016-04-07 13:21:07 +120013551 m_errorMonitor->VerifyFound();
Chris Forbese9928822016-02-17 14:44:52 +130013552}
13553
13554TEST_F(VkLayerTest, CreatePipelineVsFsMismatchByLocation) {
Chris Forbes1cc79542016-07-20 11:13:44 +120013555 TEST_DESCRIPTION("Test that an error is produced for location mismatches across "
13556 "the VS->FS interface; This should manifest as a not-written/not-consumed "
13557 "pair, but flushes out broken walking of the interfaces");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013558 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 +130013559
13560 ASSERT_NO_FATAL_FAILURE(InitState());
13561 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13562
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013563 char const *vsSource = "#version 450\n"
13564 "\n"
13565 "out block { layout(location=1) float x; } outs;\n"
13566 "out gl_PerVertex {\n"
13567 " vec4 gl_Position;\n"
13568 "};\n"
13569 "void main(){\n"
13570 " outs.x = 0;\n"
13571 " gl_Position = vec4(1);\n"
13572 "}\n";
13573 char const *fsSource = "#version 450\n"
13574 "\n"
13575 "in block { layout(location=0) float x; } ins;\n"
13576 "layout(location=0) out vec4 color;\n"
13577 "void main(){\n"
13578 " color = vec4(ins.x);\n"
13579 "}\n";
Chris Forbese9928822016-02-17 14:44:52 +130013580
13581 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13582 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
13583
13584 VkPipelineObj pipe(m_device);
13585 pipe.AddColorAttachment();
13586 pipe.AddShader(&vs);
13587 pipe.AddShader(&fs);
13588
13589 VkDescriptorSetObj descriptorSet(m_device);
13590 descriptorSet.AppendDummy();
13591 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
13592
13593 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
13594
Chris Forbes8f36a8a2016-04-07 13:21:07 +120013595 m_errorMonitor->VerifyFound();
Chris Forbese9928822016-02-17 14:44:52 +130013596}
13597
13598TEST_F(VkLayerTest, CreatePipelineVsFsMismatchByComponent) {
Chris Forbes1cc79542016-07-20 11:13:44 +120013599 TEST_DESCRIPTION("Test that an error is produced for component mismatches across the "
13600 "VS->FS interface. It's not enough to have the same set of locations in "
13601 "use; matching is defined in terms of spirv variables.");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013602 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 +130013603
13604 ASSERT_NO_FATAL_FAILURE(InitState());
13605 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13606
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013607 char const *vsSource = "#version 450\n"
13608 "\n"
13609 "out block { layout(location=0, component=0) float x; } outs;\n"
13610 "out gl_PerVertex {\n"
13611 " vec4 gl_Position;\n"
13612 "};\n"
13613 "void main(){\n"
13614 " outs.x = 0;\n"
13615 " gl_Position = vec4(1);\n"
13616 "}\n";
13617 char const *fsSource = "#version 450\n"
13618 "\n"
13619 "in block { layout(location=0, component=1) float x; } ins;\n"
13620 "layout(location=0) out vec4 color;\n"
13621 "void main(){\n"
13622 " color = vec4(ins.x);\n"
13623 "}\n";
Chris Forbese9928822016-02-17 14:44:52 +130013624
13625 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13626 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
13627
13628 VkPipelineObj pipe(m_device);
13629 pipe.AddColorAttachment();
13630 pipe.AddShader(&vs);
13631 pipe.AddShader(&fs);
13632
13633 VkDescriptorSetObj descriptorSet(m_device);
13634 descriptorSet.AppendDummy();
13635 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
13636
13637 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
13638
Chris Forbes8f36a8a2016-04-07 13:21:07 +120013639 m_errorMonitor->VerifyFound();
Chris Forbesa3e85f62016-01-15 14:53:11 +130013640}
13641
Karl Schultz6addd812016-02-02 17:17:23 -070013642TEST_F(VkLayerTest, CreatePipelineAttribNotConsumed) {
Chris Forbes1cc79542016-07-20 11:13:44 +120013643 TEST_DESCRIPTION("Test that a warning is produced for a vertex attribute which is "
13644 "not consumed by the vertex shader");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013645 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT, "location 0 not consumed by VS");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060013646
Chris Forbesde136e02015-05-25 11:13:28 +120013647 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -060013648 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbesde136e02015-05-25 11:13:28 +120013649
13650 VkVertexInputBindingDescription input_binding;
13651 memset(&input_binding, 0, sizeof(input_binding));
13652
13653 VkVertexInputAttributeDescription input_attrib;
13654 memset(&input_attrib, 0, sizeof(input_attrib));
13655 input_attrib.format = VK_FORMAT_R32_SFLOAT;
13656
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013657 char const *vsSource = "#version 450\n"
13658 "\n"
13659 "out gl_PerVertex {\n"
13660 " vec4 gl_Position;\n"
13661 "};\n"
13662 "void main(){\n"
13663 " gl_Position = vec4(1);\n"
13664 "}\n";
13665 char const *fsSource = "#version 450\n"
13666 "\n"
13667 "layout(location=0) out vec4 color;\n"
13668 "void main(){\n"
13669 " color = vec4(1);\n"
13670 "}\n";
Chris Forbesde136e02015-05-25 11:13:28 +120013671
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060013672 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13673 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbesde136e02015-05-25 11:13:28 +120013674
13675 VkPipelineObj pipe(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +080013676 pipe.AddColorAttachment();
Chris Forbesde136e02015-05-25 11:13:28 +120013677 pipe.AddShader(&vs);
13678 pipe.AddShader(&fs);
13679
13680 pipe.AddVertexInputBindings(&input_binding, 1);
13681 pipe.AddVertexInputAttribs(&input_attrib, 1);
13682
Chris Forbesde136e02015-05-25 11:13:28 +120013683 VkDescriptorSetObj descriptorSet(m_device);
13684 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080013685 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbesde136e02015-05-25 11:13:28 +120013686
Tony Barbour5781e8f2015-08-04 16:23:11 -060013687 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbesde136e02015-05-25 11:13:28 +120013688
Chris Forbes8f36a8a2016-04-07 13:21:07 +120013689 m_errorMonitor->VerifyFound();
Chris Forbesde136e02015-05-25 11:13:28 +120013690}
13691
Karl Schultz6addd812016-02-02 17:17:23 -070013692TEST_F(VkLayerTest, CreatePipelineAttribLocationMismatch) {
Chris Forbes1cc79542016-07-20 11:13:44 +120013693 TEST_DESCRIPTION("Test that a warning is produced for a location mismatch on "
13694 "vertex attributes. This flushes out bad behavior in the interface walker");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013695 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT, "location 0 not consumed by VS");
Chris Forbes7d83cd52016-01-15 11:32:03 +130013696
13697 ASSERT_NO_FATAL_FAILURE(InitState());
13698 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13699
13700 VkVertexInputBindingDescription input_binding;
13701 memset(&input_binding, 0, sizeof(input_binding));
13702
13703 VkVertexInputAttributeDescription input_attrib;
13704 memset(&input_attrib, 0, sizeof(input_attrib));
13705 input_attrib.format = VK_FORMAT_R32_SFLOAT;
13706
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013707 char const *vsSource = "#version 450\n"
13708 "\n"
13709 "layout(location=1) in float x;\n"
13710 "out gl_PerVertex {\n"
13711 " vec4 gl_Position;\n"
13712 "};\n"
13713 "void main(){\n"
13714 " gl_Position = vec4(x);\n"
13715 "}\n";
13716 char const *fsSource = "#version 450\n"
13717 "\n"
13718 "layout(location=0) out vec4 color;\n"
13719 "void main(){\n"
13720 " color = vec4(1);\n"
13721 "}\n";
Chris Forbes7d83cd52016-01-15 11:32:03 +130013722
13723 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13724 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
13725
13726 VkPipelineObj pipe(m_device);
13727 pipe.AddColorAttachment();
13728 pipe.AddShader(&vs);
13729 pipe.AddShader(&fs);
13730
13731 pipe.AddVertexInputBindings(&input_binding, 1);
13732 pipe.AddVertexInputAttribs(&input_attrib, 1);
13733
13734 VkDescriptorSetObj descriptorSet(m_device);
13735 descriptorSet.AppendDummy();
13736 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
13737
13738 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
13739
Chris Forbes8f36a8a2016-04-07 13:21:07 +120013740 m_errorMonitor->VerifyFound();
Chris Forbes7d83cd52016-01-15 11:32:03 +130013741}
13742
Karl Schultz6addd812016-02-02 17:17:23 -070013743TEST_F(VkLayerTest, CreatePipelineAttribNotProvided) {
Chris Forbes1cc79542016-07-20 11:13:44 +120013744 TEST_DESCRIPTION("Test that an error is produced for a VS input which is not "
13745 "provided by a vertex attribute");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013746 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 -060013747
Chris Forbes62e8e502015-05-25 11:13:29 +120013748 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -060013749 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbes62e8e502015-05-25 11:13:29 +120013750
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013751 char const *vsSource = "#version 450\n"
13752 "\n"
13753 "layout(location=0) in vec4 x;\n" /* not provided */
13754 "out gl_PerVertex {\n"
13755 " vec4 gl_Position;\n"
13756 "};\n"
13757 "void main(){\n"
13758 " gl_Position = x;\n"
13759 "}\n";
13760 char const *fsSource = "#version 450\n"
13761 "\n"
13762 "layout(location=0) out vec4 color;\n"
13763 "void main(){\n"
13764 " color = vec4(1);\n"
13765 "}\n";
Chris Forbes62e8e502015-05-25 11:13:29 +120013766
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060013767 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13768 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbes62e8e502015-05-25 11:13:29 +120013769
13770 VkPipelineObj pipe(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +080013771 pipe.AddColorAttachment();
Chris Forbes62e8e502015-05-25 11:13:29 +120013772 pipe.AddShader(&vs);
13773 pipe.AddShader(&fs);
13774
Chris Forbes62e8e502015-05-25 11:13:29 +120013775 VkDescriptorSetObj descriptorSet(m_device);
13776 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080013777 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbes62e8e502015-05-25 11:13:29 +120013778
Tony Barbour5781e8f2015-08-04 16:23:11 -060013779 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbes62e8e502015-05-25 11:13:29 +120013780
Chris Forbes8f36a8a2016-04-07 13:21:07 +120013781 m_errorMonitor->VerifyFound();
Chris Forbes62e8e502015-05-25 11:13:29 +120013782}
13783
Karl Schultz6addd812016-02-02 17:17:23 -070013784TEST_F(VkLayerTest, CreatePipelineAttribTypeMismatch) {
Chris Forbes1cc79542016-07-20 11:13:44 +120013785 TEST_DESCRIPTION("Test that an error is produced for a mismatch between the "
13786 "fundamental type (float/int/uint) of an attribute and the "
13787 "VS input that consumes it");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013788 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "location 0 does not match VS input type");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060013789
Chris Forbesc97d98e2015-05-25 11:13:31 +120013790 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -060013791 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbesc97d98e2015-05-25 11:13:31 +120013792
13793 VkVertexInputBindingDescription input_binding;
13794 memset(&input_binding, 0, sizeof(input_binding));
13795
13796 VkVertexInputAttributeDescription input_attrib;
13797 memset(&input_attrib, 0, sizeof(input_attrib));
13798 input_attrib.format = VK_FORMAT_R32_SFLOAT;
13799
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013800 char const *vsSource = "#version 450\n"
13801 "\n"
13802 "layout(location=0) in int x;\n" /* attrib provided float */
13803 "out gl_PerVertex {\n"
13804 " vec4 gl_Position;\n"
13805 "};\n"
13806 "void main(){\n"
13807 " gl_Position = vec4(x);\n"
13808 "}\n";
13809 char const *fsSource = "#version 450\n"
13810 "\n"
13811 "layout(location=0) out vec4 color;\n"
13812 "void main(){\n"
13813 " color = vec4(1);\n"
13814 "}\n";
Chris Forbesc97d98e2015-05-25 11:13:31 +120013815
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060013816 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13817 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbesc97d98e2015-05-25 11:13:31 +120013818
13819 VkPipelineObj pipe(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +080013820 pipe.AddColorAttachment();
Chris Forbesc97d98e2015-05-25 11:13:31 +120013821 pipe.AddShader(&vs);
13822 pipe.AddShader(&fs);
13823
13824 pipe.AddVertexInputBindings(&input_binding, 1);
13825 pipe.AddVertexInputAttribs(&input_attrib, 1);
13826
Chris Forbesc97d98e2015-05-25 11:13:31 +120013827 VkDescriptorSetObj descriptorSet(m_device);
13828 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080013829 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbesc97d98e2015-05-25 11:13:31 +120013830
Tony Barbour5781e8f2015-08-04 16:23:11 -060013831 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbesc97d98e2015-05-25 11:13:31 +120013832
Chris Forbes8f36a8a2016-04-07 13:21:07 +120013833 m_errorMonitor->VerifyFound();
Chris Forbesc97d98e2015-05-25 11:13:31 +120013834}
13835
Chris Forbesc68b43c2016-04-06 11:18:47 +120013836TEST_F(VkLayerTest, CreatePipelineDuplicateStage) {
Chris Forbes1cc79542016-07-20 11:13:44 +120013837 TEST_DESCRIPTION("Test that an error is produced for a pipeline containing multiple "
13838 "shaders for the same stage");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013839 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
13840 "Multiple shaders provided for stage VK_SHADER_STAGE_VERTEX_BIT");
Chris Forbesc68b43c2016-04-06 11:18:47 +120013841
13842 ASSERT_NO_FATAL_FAILURE(InitState());
13843 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13844
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013845 char const *vsSource = "#version 450\n"
13846 "\n"
13847 "out gl_PerVertex {\n"
13848 " vec4 gl_Position;\n"
13849 "};\n"
13850 "void main(){\n"
13851 " gl_Position = vec4(1);\n"
13852 "}\n";
13853 char const *fsSource = "#version 450\n"
13854 "\n"
13855 "layout(location=0) out vec4 color;\n"
13856 "void main(){\n"
13857 " color = vec4(1);\n"
13858 "}\n";
Chris Forbesc68b43c2016-04-06 11:18:47 +120013859
13860 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13861 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
13862
13863 VkPipelineObj pipe(m_device);
13864 pipe.AddColorAttachment();
13865 pipe.AddShader(&vs);
13866 pipe.AddShader(&vs);
13867 pipe.AddShader(&fs);
13868
13869 VkDescriptorSetObj descriptorSet(m_device);
13870 descriptorSet.AppendDummy();
13871 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
13872
13873 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
13874
Chris Forbes8f36a8a2016-04-07 13:21:07 +120013875 m_errorMonitor->VerifyFound();
Chris Forbesc68b43c2016-04-06 11:18:47 +120013876}
13877
Karl Schultz6addd812016-02-02 17:17:23 -070013878TEST_F(VkLayerTest, CreatePipelineAttribMatrixType) {
Chris Forbes1cc79542016-07-20 11:13:44 +120013879 TEST_DESCRIPTION("Test that pipeline validation accepts matrices passed "
13880 "as vertex attributes");
Chris Forbes8f36a8a2016-04-07 13:21:07 +120013881 m_errorMonitor->ExpectSuccess();
Chris Forbes2682b242015-11-24 11:13:14 +130013882
13883 ASSERT_NO_FATAL_FAILURE(InitState());
13884 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13885
13886 VkVertexInputBindingDescription input_binding;
13887 memset(&input_binding, 0, sizeof(input_binding));
13888
13889 VkVertexInputAttributeDescription input_attribs[2];
13890 memset(input_attribs, 0, sizeof(input_attribs));
13891
13892 for (int i = 0; i < 2; i++) {
13893 input_attribs[i].format = VK_FORMAT_R32G32B32A32_SFLOAT;
13894 input_attribs[i].location = i;
13895 }
13896
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013897 char const *vsSource = "#version 450\n"
13898 "\n"
13899 "layout(location=0) in mat2x4 x;\n"
13900 "out gl_PerVertex {\n"
13901 " vec4 gl_Position;\n"
13902 "};\n"
13903 "void main(){\n"
13904 " gl_Position = x[0] + x[1];\n"
13905 "}\n";
13906 char const *fsSource = "#version 450\n"
13907 "\n"
13908 "layout(location=0) out vec4 color;\n"
13909 "void main(){\n"
13910 " color = vec4(1);\n"
13911 "}\n";
Chris Forbes2682b242015-11-24 11:13:14 +130013912
13913 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13914 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
13915
13916 VkPipelineObj pipe(m_device);
13917 pipe.AddColorAttachment();
13918 pipe.AddShader(&vs);
13919 pipe.AddShader(&fs);
13920
13921 pipe.AddVertexInputBindings(&input_binding, 1);
13922 pipe.AddVertexInputAttribs(input_attribs, 2);
13923
13924 VkDescriptorSetObj descriptorSet(m_device);
13925 descriptorSet.AppendDummy();
13926 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
13927
13928 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
13929
13930 /* expect success */
Chris Forbes8f36a8a2016-04-07 13:21:07 +120013931 m_errorMonitor->VerifyNotFound();
Chris Forbes2682b242015-11-24 11:13:14 +130013932}
13933
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013934TEST_F(VkLayerTest, CreatePipelineAttribArrayType) {
Chris Forbes8f36a8a2016-04-07 13:21:07 +120013935 m_errorMonitor->ExpectSuccess();
Chris Forbes2682b242015-11-24 11:13:14 +130013936
13937 ASSERT_NO_FATAL_FAILURE(InitState());
13938 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13939
13940 VkVertexInputBindingDescription input_binding;
13941 memset(&input_binding, 0, sizeof(input_binding));
13942
13943 VkVertexInputAttributeDescription input_attribs[2];
13944 memset(input_attribs, 0, sizeof(input_attribs));
13945
13946 for (int i = 0; i < 2; i++) {
13947 input_attribs[i].format = VK_FORMAT_R32G32B32A32_SFLOAT;
13948 input_attribs[i].location = i;
13949 }
13950
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013951 char const *vsSource = "#version 450\n"
13952 "\n"
13953 "layout(location=0) in vec4 x[2];\n"
13954 "out gl_PerVertex {\n"
13955 " vec4 gl_Position;\n"
13956 "};\n"
13957 "void main(){\n"
13958 " gl_Position = x[0] + x[1];\n"
13959 "}\n";
13960 char const *fsSource = "#version 450\n"
13961 "\n"
13962 "layout(location=0) out vec4 color;\n"
13963 "void main(){\n"
13964 " color = vec4(1);\n"
13965 "}\n";
Chris Forbes2682b242015-11-24 11:13:14 +130013966
13967 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13968 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
13969
13970 VkPipelineObj pipe(m_device);
13971 pipe.AddColorAttachment();
13972 pipe.AddShader(&vs);
13973 pipe.AddShader(&fs);
13974
13975 pipe.AddVertexInputBindings(&input_binding, 1);
13976 pipe.AddVertexInputAttribs(input_attribs, 2);
13977
13978 VkDescriptorSetObj descriptorSet(m_device);
13979 descriptorSet.AppendDummy();
13980 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
13981
13982 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
13983
Chris Forbes8f36a8a2016-04-07 13:21:07 +120013984 m_errorMonitor->VerifyNotFound();
Chris Forbes2682b242015-11-24 11:13:14 +130013985}
Chris Forbes2682b242015-11-24 11:13:14 +130013986
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013987TEST_F(VkLayerTest, CreatePipelineAttribComponents) {
Chris Forbes1cc79542016-07-20 11:13:44 +120013988 TEST_DESCRIPTION("Test that pipeline validation accepts consuming a vertex attribute "
13989 "through multiple VS inputs, each consuming a different subset of the "
13990 "components.");
Chris Forbesbc290ce2016-07-06 12:01:49 +120013991 m_errorMonitor->ExpectSuccess();
13992
13993 ASSERT_NO_FATAL_FAILURE(InitState());
13994 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13995
13996 VkVertexInputBindingDescription input_binding;
13997 memset(&input_binding, 0, sizeof(input_binding));
13998
13999 VkVertexInputAttributeDescription input_attribs[3];
14000 memset(input_attribs, 0, sizeof(input_attribs));
14001
14002 for (int i = 0; i < 3; i++) {
14003 input_attribs[i].format = VK_FORMAT_R32G32B32A32_SFLOAT;
14004 input_attribs[i].location = i;
14005 }
14006
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014007 char const *vsSource = "#version 450\n"
14008 "\n"
14009 "layout(location=0) in vec4 x;\n"
14010 "layout(location=1) in vec3 y1;\n"
14011 "layout(location=1, component=3) in float y2;\n"
14012 "layout(location=2) in vec4 z;\n"
14013 "out gl_PerVertex {\n"
14014 " vec4 gl_Position;\n"
14015 "};\n"
14016 "void main(){\n"
14017 " gl_Position = x + vec4(y1, y2) + z;\n"
14018 "}\n";
14019 char const *fsSource = "#version 450\n"
14020 "\n"
14021 "layout(location=0) out vec4 color;\n"
14022 "void main(){\n"
14023 " color = vec4(1);\n"
14024 "}\n";
Chris Forbesbc290ce2016-07-06 12:01:49 +120014025
14026 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
14027 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
14028
14029 VkPipelineObj pipe(m_device);
14030 pipe.AddColorAttachment();
14031 pipe.AddShader(&vs);
14032 pipe.AddShader(&fs);
14033
14034 pipe.AddVertexInputBindings(&input_binding, 1);
14035 pipe.AddVertexInputAttribs(input_attribs, 3);
14036
14037 VkDescriptorSetObj descriptorSet(m_device);
14038 descriptorSet.AppendDummy();
14039 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
14040
14041 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
14042
14043 m_errorMonitor->VerifyNotFound();
14044}
14045
Chris Forbes82ff92a2016-09-09 10:50:24 +120014046TEST_F(VkLayerTest, CreatePipelineMissingEntrypoint) {
14047 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
14048 "No entrypoint found named `foo`");
14049
14050 ASSERT_NO_FATAL_FAILURE(InitState());
14051 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
14052
14053 char const *vsSource = "#version 450\n"
14054 "out gl_PerVertex {\n"
14055 " vec4 gl_Position;\n"
14056 "};\n"
14057 "void main(){\n"
14058 " gl_Position = vec4(0);\n"
14059 "}\n";
14060 char const *fsSource = "#version 450\n"
14061 "\n"
14062 "layout(location=0) out vec4 color;\n"
14063 "void main(){\n"
14064 " color = vec4(1);\n"
14065 "}\n";
14066
14067 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
14068 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this, "foo");
14069
14070 VkPipelineObj pipe(m_device);
14071 pipe.AddColorAttachment();
14072 pipe.AddShader(&vs);
14073 pipe.AddShader(&fs);
14074
14075 VkDescriptorSetObj descriptorSet(m_device);
14076 descriptorSet.AppendDummy();
14077 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
14078
14079 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
14080
14081 m_errorMonitor->VerifyFound();
14082}
14083
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014084TEST_F(VkLayerTest, CreatePipelineSimplePositive) {
Chris Forbes8f36a8a2016-04-07 13:21:07 +120014085 m_errorMonitor->ExpectSuccess();
Chris Forbes4ea14fc2016-04-04 18:52:54 +120014086
14087 ASSERT_NO_FATAL_FAILURE(InitState());
14088 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
14089
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014090 char const *vsSource = "#version 450\n"
14091 "out gl_PerVertex {\n"
14092 " vec4 gl_Position;\n"
14093 "};\n"
14094 "void main(){\n"
14095 " gl_Position = vec4(0);\n"
14096 "}\n";
14097 char const *fsSource = "#version 450\n"
14098 "\n"
14099 "layout(location=0) out vec4 color;\n"
14100 "void main(){\n"
14101 " color = vec4(1);\n"
14102 "}\n";
Chris Forbes4ea14fc2016-04-04 18:52:54 +120014103
14104 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
14105 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
14106
14107 VkPipelineObj pipe(m_device);
14108 pipe.AddColorAttachment();
14109 pipe.AddShader(&vs);
14110 pipe.AddShader(&fs);
14111
14112 VkDescriptorSetObj descriptorSet(m_device);
14113 descriptorSet.AppendDummy();
14114 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
14115
14116 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
14117
Chris Forbes8f36a8a2016-04-07 13:21:07 +120014118 m_errorMonitor->VerifyNotFound();
Chris Forbes4ea14fc2016-04-04 18:52:54 +120014119}
14120
Chris Forbesae9d8cd2016-09-13 16:32:57 +120014121TEST_F(VkLayerTest, CreatePipelineDepthStencilRequired) {
14122 m_errorMonitor->SetDesiredFailureMsg(
14123 VK_DEBUG_REPORT_ERROR_BIT_EXT,
14124 "pDepthStencilState is NULL when rasterization is enabled and subpass "
14125 "uses a depth/stencil attachment");
14126
14127 ASSERT_NO_FATAL_FAILURE(InitState());
14128 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
14129
14130 char const *vsSource = "#version 450\n"
14131 "void main(){ gl_Position = vec4(0); }\n";
14132 char const *fsSource = "#version 450\n"
14133 "\n"
14134 "layout(location=0) out vec4 color;\n"
14135 "void main(){\n"
14136 " color = vec4(1);\n"
14137 "}\n";
14138
14139 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
14140 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
14141
14142 VkPipelineObj pipe(m_device);
14143 pipe.AddColorAttachment();
14144 pipe.AddShader(&vs);
14145 pipe.AddShader(&fs);
14146
14147 VkDescriptorSetObj descriptorSet(m_device);
14148 descriptorSet.AppendDummy();
14149 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
14150
14151 VkAttachmentDescription attachments[] = {
14152 { 0, VK_FORMAT_B8G8R8A8_UNORM, VK_SAMPLE_COUNT_1_BIT,
14153 VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE,
14154 VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE,
14155 VK_IMAGE_LAYOUT_UNDEFINED, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
14156 },
14157 { 0, VK_FORMAT_D16_UNORM, VK_SAMPLE_COUNT_1_BIT,
14158 VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE,
14159 VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE,
14160 VK_IMAGE_LAYOUT_UNDEFINED, VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL,
14161 },
14162 };
14163 VkAttachmentReference refs[] = {
14164 { 0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL },
14165 { 1, VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL },
14166 };
14167 VkSubpassDescription subpass = {
14168 0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr,
14169 1, &refs[0], nullptr, &refs[1],
14170 0, nullptr
14171 };
14172 VkRenderPassCreateInfo rpci = {
14173 VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr,
14174 0, 2, attachments, 1, &subpass, 0, nullptr
14175 };
14176 VkRenderPass rp;
14177 VkResult err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
14178 ASSERT_VK_SUCCESS(err);
14179
14180 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), rp);
14181
14182 m_errorMonitor->VerifyFound();
14183
14184 vkDestroyRenderPass(m_device->device(), rp, nullptr);
14185}
14186
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014187TEST_F(VkLayerTest, CreatePipelineRelaxedTypeMatch) {
Chris Forbes1cc79542016-07-20 11:13:44 +120014188 TEST_DESCRIPTION("Test that pipeline validation accepts the relaxed type matching rules "
14189 "set out in 14.1.3: fundamental type must match, and producer side must "
14190 "have at least as many components");
Chris Forbes8f36a8a2016-04-07 13:21:07 +120014191 m_errorMonitor->ExpectSuccess();
Chris Forbes912c9192016-04-05 17:50:35 +120014192
14193 // VK 1.0.8 Specification, 14.1.3 "Additionally,..." block
14194
14195 ASSERT_NO_FATAL_FAILURE(InitState());
14196 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
14197
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014198 char const *vsSource = "#version 450\n"
14199 "out gl_PerVertex {\n"
14200 " vec4 gl_Position;\n"
14201 "};\n"
14202 "layout(location=0) out vec3 x;\n"
14203 "layout(location=1) out ivec3 y;\n"
14204 "layout(location=2) out vec3 z;\n"
14205 "void main(){\n"
14206 " gl_Position = vec4(0);\n"
14207 " x = vec3(0); y = ivec3(0); z = vec3(0);\n"
14208 "}\n";
14209 char const *fsSource = "#version 450\n"
14210 "\n"
14211 "layout(location=0) out vec4 color;\n"
14212 "layout(location=0) in float x;\n"
14213 "layout(location=1) flat in int y;\n"
14214 "layout(location=2) in vec2 z;\n"
14215 "void main(){\n"
14216 " color = vec4(1 + x + y + z.x);\n"
14217 "}\n";
Chris Forbes912c9192016-04-05 17:50:35 +120014218
14219 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
14220 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
14221
14222 VkPipelineObj pipe(m_device);
14223 pipe.AddColorAttachment();
14224 pipe.AddShader(&vs);
14225 pipe.AddShader(&fs);
14226
14227 VkDescriptorSetObj descriptorSet(m_device);
14228 descriptorSet.AppendDummy();
14229 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
14230
Mike Stroyan255e9582016-06-24 09:49:32 -060014231 VkResult err = VK_SUCCESS;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014232 err = pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Mike Stroyan255e9582016-06-24 09:49:32 -060014233 ASSERT_VK_SUCCESS(err);
14234
Chris Forbes8f36a8a2016-04-07 13:21:07 +120014235 m_errorMonitor->VerifyNotFound();
Chris Forbes912c9192016-04-05 17:50:35 +120014236}
14237
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014238TEST_F(VkLayerTest, CreatePipelineTessPerVertex) {
Chris Forbes1cc79542016-07-20 11:13:44 +120014239 TEST_DESCRIPTION("Test that pipeline validation accepts per-vertex variables "
14240 "passed between the TCS and TES stages");
Chris Forbes8f36a8a2016-04-07 13:21:07 +120014241 m_errorMonitor->ExpectSuccess();
Chris Forbes4ea14fc2016-04-04 18:52:54 +120014242
14243 ASSERT_NO_FATAL_FAILURE(InitState());
14244 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
14245
Chris Forbesc1e852d2016-04-04 19:26:42 +120014246 if (!m_device->phy().features().tessellationShader) {
14247 printf("Device does not support tessellation shaders; skipped.\n");
14248 return;
14249 }
14250
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014251 char const *vsSource = "#version 450\n"
14252 "void main(){}\n";
14253 char const *tcsSource = "#version 450\n"
14254 "layout(location=0) out int x[];\n"
14255 "layout(vertices=3) out;\n"
14256 "void main(){\n"
14257 " gl_TessLevelOuter[0] = gl_TessLevelOuter[1] = gl_TessLevelOuter[2] = 1;\n"
14258 " gl_TessLevelInner[0] = 1;\n"
14259 " x[gl_InvocationID] = gl_InvocationID;\n"
14260 "}\n";
14261 char const *tesSource = "#version 450\n"
14262 "layout(triangles, equal_spacing, cw) in;\n"
14263 "layout(location=0) in int x[];\n"
14264 "out gl_PerVertex { vec4 gl_Position; };\n"
14265 "void main(){\n"
14266 " gl_Position.xyz = gl_TessCoord;\n"
14267 " gl_Position.w = x[0] + x[1] + x[2];\n"
14268 "}\n";
14269 char const *fsSource = "#version 450\n"
14270 "layout(location=0) out vec4 color;\n"
14271 "void main(){\n"
14272 " color = vec4(1);\n"
14273 "}\n";
Chris Forbes4ea14fc2016-04-04 18:52:54 +120014274
14275 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
14276 VkShaderObj tcs(m_device, tcsSource, VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT, this);
14277 VkShaderObj tes(m_device, tesSource, VK_SHADER_STAGE_TESSELLATION_EVALUATION_BIT, this);
14278 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
14279
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014280 VkPipelineInputAssemblyStateCreateInfo iasci{VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO, nullptr, 0,
14281 VK_PRIMITIVE_TOPOLOGY_PATCH_LIST, VK_FALSE};
Chris Forbes4ea14fc2016-04-04 18:52:54 +120014282
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014283 VkPipelineTessellationStateCreateInfo tsci{VK_STRUCTURE_TYPE_PIPELINE_TESSELLATION_STATE_CREATE_INFO, nullptr, 0, 3};
Chris Forbesb4cacb62016-04-04 19:15:00 +120014284
Chris Forbes4ea14fc2016-04-04 18:52:54 +120014285 VkPipelineObj pipe(m_device);
14286 pipe.SetInputAssembly(&iasci);
Chris Forbesb4cacb62016-04-04 19:15:00 +120014287 pipe.SetTessellation(&tsci);
Chris Forbes4ea14fc2016-04-04 18:52:54 +120014288 pipe.AddColorAttachment();
14289 pipe.AddShader(&vs);
14290 pipe.AddShader(&tcs);
14291 pipe.AddShader(&tes);
14292 pipe.AddShader(&fs);
14293
14294 VkDescriptorSetObj descriptorSet(m_device);
14295 descriptorSet.AppendDummy();
14296 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
14297
14298 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
14299
Chris Forbes8f36a8a2016-04-07 13:21:07 +120014300 m_errorMonitor->VerifyNotFound();
Chris Forbes4ea14fc2016-04-04 18:52:54 +120014301}
14302
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014303TEST_F(VkLayerTest, CreatePipelineGeometryInputBlockPositive) {
Chris Forbes1cc79542016-07-20 11:13:44 +120014304 TEST_DESCRIPTION("Test that pipeline validation accepts a user-defined "
14305 "interface block passed into the geometry shader. This "
14306 "is interesting because the 'extra' array level is not "
14307 "present on the member type, but on the block instance.");
Chris Forbesa0ab8152016-04-20 13:34:27 +120014308 m_errorMonitor->ExpectSuccess();
14309
14310 ASSERT_NO_FATAL_FAILURE(InitState());
14311 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
14312
14313 if (!m_device->phy().features().geometryShader) {
14314 printf("Device does not support geometry shaders; skipped.\n");
14315 return;
14316 }
14317
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014318 char const *vsSource = "#version 450\n"
14319 "layout(location=0) out VertexData { vec4 x; } vs_out;\n"
14320 "void main(){\n"
14321 " vs_out.x = vec4(1);\n"
14322 "}\n";
14323 char const *gsSource = "#version 450\n"
14324 "layout(triangles) in;\n"
14325 "layout(triangle_strip, max_vertices=3) out;\n"
14326 "layout(location=0) in VertexData { vec4 x; } gs_in[];\n"
14327 "out gl_PerVertex { vec4 gl_Position; };\n"
14328 "void main() {\n"
14329 " gl_Position = gs_in[0].x;\n"
14330 " EmitVertex();\n"
14331 "}\n";
14332 char const *fsSource = "#version 450\n"
14333 "layout(location=0) out vec4 color;\n"
14334 "void main(){\n"
14335 " color = vec4(1);\n"
14336 "}\n";
Chris Forbesa0ab8152016-04-20 13:34:27 +120014337
14338 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
14339 VkShaderObj gs(m_device, gsSource, VK_SHADER_STAGE_GEOMETRY_BIT, this);
14340 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
14341
14342 VkPipelineObj pipe(m_device);
14343 pipe.AddColorAttachment();
14344 pipe.AddShader(&vs);
14345 pipe.AddShader(&gs);
14346 pipe.AddShader(&fs);
14347
14348 VkDescriptorSetObj descriptorSet(m_device);
14349 descriptorSet.AppendDummy();
14350 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
14351
14352 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
14353
14354 m_errorMonitor->VerifyNotFound();
14355}
14356
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014357TEST_F(VkLayerTest, CreatePipelineTessPatchDecorationMismatch) {
Chris Forbes1cc79542016-07-20 11:13:44 +120014358 TEST_DESCRIPTION("Test that an error is produced for a variable output from "
14359 "the TCS without the patch decoration, but consumed in the TES "
14360 "with the decoration.");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014361 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "is per-vertex in tessellation control shader stage "
14362 "but per-patch in tessellation evaluation shader stage");
Chris Forbesa0193bc2016-04-04 19:19:47 +120014363
14364 ASSERT_NO_FATAL_FAILURE(InitState());
14365 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
14366
Chris Forbesc1e852d2016-04-04 19:26:42 +120014367 if (!m_device->phy().features().tessellationShader) {
14368 printf("Device does not support tessellation shaders; skipped.\n");
14369 return;
14370 }
14371
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014372 char const *vsSource = "#version 450\n"
14373 "void main(){}\n";
14374 char const *tcsSource = "#version 450\n"
14375 "layout(location=0) out int x[];\n"
14376 "layout(vertices=3) out;\n"
14377 "void main(){\n"
14378 " gl_TessLevelOuter[0] = gl_TessLevelOuter[1] = gl_TessLevelOuter[2] = 1;\n"
14379 " gl_TessLevelInner[0] = 1;\n"
14380 " x[gl_InvocationID] = gl_InvocationID;\n"
14381 "}\n";
14382 char const *tesSource = "#version 450\n"
14383 "layout(triangles, equal_spacing, cw) in;\n"
14384 "layout(location=0) patch in int x;\n"
14385 "out gl_PerVertex { vec4 gl_Position; };\n"
14386 "void main(){\n"
14387 " gl_Position.xyz = gl_TessCoord;\n"
14388 " gl_Position.w = x;\n"
14389 "}\n";
14390 char const *fsSource = "#version 450\n"
14391 "layout(location=0) out vec4 color;\n"
14392 "void main(){\n"
14393 " color = vec4(1);\n"
14394 "}\n";
Chris Forbesa0193bc2016-04-04 19:19:47 +120014395
14396 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
14397 VkShaderObj tcs(m_device, tcsSource, VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT, this);
14398 VkShaderObj tes(m_device, tesSource, VK_SHADER_STAGE_TESSELLATION_EVALUATION_BIT, this);
14399 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
14400
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014401 VkPipelineInputAssemblyStateCreateInfo iasci{VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO, nullptr, 0,
14402 VK_PRIMITIVE_TOPOLOGY_PATCH_LIST, VK_FALSE};
Chris Forbesa0193bc2016-04-04 19:19:47 +120014403
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014404 VkPipelineTessellationStateCreateInfo tsci{VK_STRUCTURE_TYPE_PIPELINE_TESSELLATION_STATE_CREATE_INFO, nullptr, 0, 3};
Chris Forbesa0193bc2016-04-04 19:19:47 +120014405
14406 VkPipelineObj pipe(m_device);
14407 pipe.SetInputAssembly(&iasci);
14408 pipe.SetTessellation(&tsci);
14409 pipe.AddColorAttachment();
14410 pipe.AddShader(&vs);
14411 pipe.AddShader(&tcs);
14412 pipe.AddShader(&tes);
14413 pipe.AddShader(&fs);
14414
14415 VkDescriptorSetObj descriptorSet(m_device);
14416 descriptorSet.AppendDummy();
14417 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
14418
14419 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
14420
Chris Forbes8f36a8a2016-04-07 13:21:07 +120014421 m_errorMonitor->VerifyFound();
Chris Forbesa0193bc2016-04-04 19:19:47 +120014422}
14423
Karl Schultz6addd812016-02-02 17:17:23 -070014424TEST_F(VkLayerTest, CreatePipelineAttribBindingConflict) {
Chris Forbes1cc79542016-07-20 11:13:44 +120014425 TEST_DESCRIPTION("Test that an error is produced for a vertex attribute setup where multiple "
14426 "bindings provide the same location");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014427 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
14428 "Duplicate vertex input binding descriptions for binding 0");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060014429
Chris Forbes280ba2c2015-06-12 11:16:41 +120014430 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -060014431 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbes280ba2c2015-06-12 11:16:41 +120014432
14433 /* Two binding descriptions for binding 0 */
14434 VkVertexInputBindingDescription input_bindings[2];
14435 memset(input_bindings, 0, sizeof(input_bindings));
14436
14437 VkVertexInputAttributeDescription input_attrib;
14438 memset(&input_attrib, 0, sizeof(input_attrib));
14439 input_attrib.format = VK_FORMAT_R32_SFLOAT;
14440
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014441 char const *vsSource = "#version 450\n"
14442 "\n"
14443 "layout(location=0) in float x;\n" /* attrib provided float */
14444 "out gl_PerVertex {\n"
14445 " vec4 gl_Position;\n"
14446 "};\n"
14447 "void main(){\n"
14448 " gl_Position = vec4(x);\n"
14449 "}\n";
14450 char const *fsSource = "#version 450\n"
14451 "\n"
14452 "layout(location=0) out vec4 color;\n"
14453 "void main(){\n"
14454 " color = vec4(1);\n"
14455 "}\n";
Chris Forbes280ba2c2015-06-12 11:16:41 +120014456
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060014457 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
14458 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbes280ba2c2015-06-12 11:16:41 +120014459
14460 VkPipelineObj pipe(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +080014461 pipe.AddColorAttachment();
Chris Forbes280ba2c2015-06-12 11:16:41 +120014462 pipe.AddShader(&vs);
14463 pipe.AddShader(&fs);
14464
14465 pipe.AddVertexInputBindings(input_bindings, 2);
14466 pipe.AddVertexInputAttribs(&input_attrib, 1);
14467
Chris Forbes280ba2c2015-06-12 11:16:41 +120014468 VkDescriptorSetObj descriptorSet(m_device);
14469 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014470 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbes280ba2c2015-06-12 11:16:41 +120014471
Tony Barbour5781e8f2015-08-04 16:23:11 -060014472 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbes280ba2c2015-06-12 11:16:41 +120014473
Chris Forbes8f36a8a2016-04-07 13:21:07 +120014474 m_errorMonitor->VerifyFound();
Chris Forbes280ba2c2015-06-12 11:16:41 +120014475}
Chris Forbes8f68b562015-05-25 11:13:32 +120014476
Chris Forbes35efec72016-04-21 14:32:08 +120014477TEST_F(VkLayerTest, CreatePipeline64BitAttributesPositive) {
Chris Forbes1cc79542016-07-20 11:13:44 +120014478 TEST_DESCRIPTION("Test that pipeline validation accepts basic use of 64bit vertex "
14479 "attributes. This is interesting because they consume multiple "
14480 "locations.");
Chris Forbes35efec72016-04-21 14:32:08 +120014481 m_errorMonitor->ExpectSuccess();
14482
14483 ASSERT_NO_FATAL_FAILURE(InitState());
14484 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
14485
Chris Forbes91cf3a82016-06-28 17:51:35 +120014486 if (!m_device->phy().features().shaderFloat64) {
Chris Forbes35efec72016-04-21 14:32:08 +120014487 printf("Device does not support 64bit vertex attributes; skipped.\n");
14488 return;
14489 }
14490
14491 VkVertexInputBindingDescription input_bindings[1];
14492 memset(input_bindings, 0, sizeof(input_bindings));
14493
14494 VkVertexInputAttributeDescription input_attribs[4];
14495 memset(input_attribs, 0, sizeof(input_attribs));
14496 input_attribs[0].location = 0;
14497 input_attribs[0].offset = 0;
14498 input_attribs[0].format = VK_FORMAT_R64G64B64A64_SFLOAT;
14499 input_attribs[1].location = 2;
14500 input_attribs[1].offset = 32;
14501 input_attribs[1].format = VK_FORMAT_R64G64B64A64_SFLOAT;
14502 input_attribs[2].location = 4;
14503 input_attribs[2].offset = 64;
14504 input_attribs[2].format = VK_FORMAT_R64G64B64A64_SFLOAT;
14505 input_attribs[3].location = 6;
14506 input_attribs[3].offset = 96;
14507 input_attribs[3].format = VK_FORMAT_R64G64B64A64_SFLOAT;
14508
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014509 char const *vsSource = "#version 450\n"
14510 "\n"
14511 "layout(location=0) in dmat4 x;\n"
14512 "out gl_PerVertex {\n"
14513 " vec4 gl_Position;\n"
14514 "};\n"
14515 "void main(){\n"
14516 " gl_Position = vec4(x[0][0]);\n"
14517 "}\n";
14518 char const *fsSource = "#version 450\n"
14519 "\n"
14520 "layout(location=0) out vec4 color;\n"
14521 "void main(){\n"
14522 " color = vec4(1);\n"
14523 "}\n";
Chris Forbes35efec72016-04-21 14:32:08 +120014524
14525 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
14526 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
14527
14528 VkPipelineObj pipe(m_device);
14529 pipe.AddColorAttachment();
14530 pipe.AddShader(&vs);
14531 pipe.AddShader(&fs);
14532
14533 pipe.AddVertexInputBindings(input_bindings, 1);
14534 pipe.AddVertexInputAttribs(input_attribs, 4);
14535
14536 VkDescriptorSetObj descriptorSet(m_device);
14537 descriptorSet.AppendDummy();
14538 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
14539
14540 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
14541
14542 m_errorMonitor->VerifyNotFound();
14543}
14544
Karl Schultz6addd812016-02-02 17:17:23 -070014545TEST_F(VkLayerTest, CreatePipelineFragmentOutputNotWritten) {
Chris Forbes1cc79542016-07-20 11:13:44 +120014546 TEST_DESCRIPTION("Test that an error is produced for a FS which does not "
14547 "provide an output for one of the pipeline's color attachments");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014548 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Attachment 0 not written by FS");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060014549
Chris Forbes4d6d1e52015-05-25 11:13:40 +120014550 ASSERT_NO_FATAL_FAILURE(InitState());
Chris Forbes4d6d1e52015-05-25 11:13:40 +120014551
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014552 char const *vsSource = "#version 450\n"
14553 "\n"
14554 "out gl_PerVertex {\n"
14555 " vec4 gl_Position;\n"
14556 "};\n"
14557 "void main(){\n"
14558 " gl_Position = vec4(1);\n"
14559 "}\n";
14560 char const *fsSource = "#version 450\n"
14561 "\n"
14562 "void main(){\n"
14563 "}\n";
Chris Forbes4d6d1e52015-05-25 11:13:40 +120014564
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060014565 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
14566 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbes4d6d1e52015-05-25 11:13:40 +120014567
14568 VkPipelineObj pipe(m_device);
14569 pipe.AddShader(&vs);
14570 pipe.AddShader(&fs);
14571
Chia-I Wu08accc62015-07-07 11:50:03 +080014572 /* set up CB 0, not written */
14573 pipe.AddColorAttachment();
14574 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbes4d6d1e52015-05-25 11:13:40 +120014575
Chris Forbes4d6d1e52015-05-25 11:13:40 +120014576 VkDescriptorSetObj descriptorSet(m_device);
14577 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014578 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbes4d6d1e52015-05-25 11:13:40 +120014579
Tony Barbour5781e8f2015-08-04 16:23:11 -060014580 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbes4d6d1e52015-05-25 11:13:40 +120014581
Chris Forbes8f36a8a2016-04-07 13:21:07 +120014582 m_errorMonitor->VerifyFound();
Chris Forbes4d6d1e52015-05-25 11:13:40 +120014583}
14584
Karl Schultz6addd812016-02-02 17:17:23 -070014585TEST_F(VkLayerTest, CreatePipelineFragmentOutputNotConsumed) {
Chris Forbes1cc79542016-07-20 11:13:44 +120014586 TEST_DESCRIPTION("Test that a warning is produced for a FS which provides a spurious "
14587 "output with no matching attachment");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014588 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT,
14589 "FS writes to output location 1 with no matching attachment");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060014590
Chris Forbesf3fffaa2015-05-25 11:13:43 +120014591 ASSERT_NO_FATAL_FAILURE(InitState());
Chris Forbesf3fffaa2015-05-25 11:13:43 +120014592
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014593 char const *vsSource = "#version 450\n"
14594 "\n"
14595 "out gl_PerVertex {\n"
14596 " vec4 gl_Position;\n"
14597 "};\n"
14598 "void main(){\n"
14599 " gl_Position = vec4(1);\n"
14600 "}\n";
14601 char const *fsSource = "#version 450\n"
14602 "\n"
14603 "layout(location=0) out vec4 x;\n"
14604 "layout(location=1) out vec4 y;\n" /* no matching attachment for this */
14605 "void main(){\n"
14606 " x = vec4(1);\n"
14607 " y = vec4(1);\n"
14608 "}\n";
Chris Forbesf3fffaa2015-05-25 11:13:43 +120014609
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060014610 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
14611 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbesf3fffaa2015-05-25 11:13:43 +120014612
14613 VkPipelineObj pipe(m_device);
14614 pipe.AddShader(&vs);
14615 pipe.AddShader(&fs);
14616
Chia-I Wu08accc62015-07-07 11:50:03 +080014617 /* set up CB 0, not written */
14618 pipe.AddColorAttachment();
14619 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbesf3fffaa2015-05-25 11:13:43 +120014620 /* FS writes CB 1, but we don't configure it */
14621
Chris Forbesf3fffaa2015-05-25 11:13:43 +120014622 VkDescriptorSetObj descriptorSet(m_device);
14623 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014624 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbesf3fffaa2015-05-25 11:13:43 +120014625
Tony Barbour5781e8f2015-08-04 16:23:11 -060014626 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbesf3fffaa2015-05-25 11:13:43 +120014627
Chris Forbes8f36a8a2016-04-07 13:21:07 +120014628 m_errorMonitor->VerifyFound();
Chris Forbesf3fffaa2015-05-25 11:13:43 +120014629}
14630
Karl Schultz6addd812016-02-02 17:17:23 -070014631TEST_F(VkLayerTest, CreatePipelineFragmentOutputTypeMismatch) {
Chris Forbes1cc79542016-07-20 11:13:44 +120014632 TEST_DESCRIPTION("Test that an error is produced for a mismatch between the fundamental "
14633 "type of an FS output variable, and the format of the corresponding attachment");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014634 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "does not match FS output type");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060014635
Chris Forbesa36d69e2015-05-25 11:13:44 +120014636 ASSERT_NO_FATAL_FAILURE(InitState());
Chris Forbesa36d69e2015-05-25 11:13:44 +120014637
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014638 char const *vsSource = "#version 450\n"
14639 "\n"
14640 "out gl_PerVertex {\n"
14641 " vec4 gl_Position;\n"
14642 "};\n"
14643 "void main(){\n"
14644 " gl_Position = vec4(1);\n"
14645 "}\n";
14646 char const *fsSource = "#version 450\n"
14647 "\n"
14648 "layout(location=0) out ivec4 x;\n" /* not UNORM */
14649 "void main(){\n"
14650 " x = ivec4(1);\n"
14651 "}\n";
Chris Forbesa36d69e2015-05-25 11:13:44 +120014652
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060014653 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
14654 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbesa36d69e2015-05-25 11:13:44 +120014655
14656 VkPipelineObj pipe(m_device);
14657 pipe.AddShader(&vs);
14658 pipe.AddShader(&fs);
14659
Chia-I Wu08accc62015-07-07 11:50:03 +080014660 /* set up CB 0; type is UNORM by default */
14661 pipe.AddColorAttachment();
14662 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbesa36d69e2015-05-25 11:13:44 +120014663
Chris Forbesa36d69e2015-05-25 11:13:44 +120014664 VkDescriptorSetObj descriptorSet(m_device);
14665 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014666 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbesa36d69e2015-05-25 11:13:44 +120014667
Tony Barbour5781e8f2015-08-04 16:23:11 -060014668 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbesa36d69e2015-05-25 11:13:44 +120014669
Chris Forbes8f36a8a2016-04-07 13:21:07 +120014670 m_errorMonitor->VerifyFound();
Chris Forbesa36d69e2015-05-25 11:13:44 +120014671}
Chris Forbes7b1b8932015-06-05 14:43:36 +120014672
Karl Schultz6addd812016-02-02 17:17:23 -070014673TEST_F(VkLayerTest, CreatePipelineUniformBlockNotProvided) {
Chris Forbes1cc79542016-07-20 11:13:44 +120014674 TEST_DESCRIPTION("Test that an error is produced for a shader consuming a uniform "
14675 "block which has no corresponding binding in the pipeline layout");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014676 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "not declared in pipeline layout");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060014677
Chris Forbes556c76c2015-08-14 12:04:59 +120014678 ASSERT_NO_FATAL_FAILURE(InitState());
Chris Forbes556c76c2015-08-14 12:04:59 +120014679
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014680 char const *vsSource = "#version 450\n"
14681 "\n"
14682 "out gl_PerVertex {\n"
14683 " vec4 gl_Position;\n"
14684 "};\n"
14685 "void main(){\n"
14686 " gl_Position = vec4(1);\n"
14687 "}\n";
14688 char const *fsSource = "#version 450\n"
14689 "\n"
14690 "layout(location=0) out vec4 x;\n"
14691 "layout(set=0) layout(binding=0) uniform foo { int x; int y; } bar;\n"
14692 "void main(){\n"
14693 " x = vec4(bar.y);\n"
14694 "}\n";
Chris Forbes556c76c2015-08-14 12:04:59 +120014695
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060014696 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
14697 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbes556c76c2015-08-14 12:04:59 +120014698
Chris Forbes556c76c2015-08-14 12:04:59 +120014699 VkPipelineObj pipe(m_device);
14700 pipe.AddShader(&vs);
14701 pipe.AddShader(&fs);
14702
14703 /* set up CB 0; type is UNORM by default */
14704 pipe.AddColorAttachment();
14705 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
14706
14707 VkDescriptorSetObj descriptorSet(m_device);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014708 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbes556c76c2015-08-14 12:04:59 +120014709
14710 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
14711
Chris Forbes8f36a8a2016-04-07 13:21:07 +120014712 m_errorMonitor->VerifyFound();
Chris Forbes556c76c2015-08-14 12:04:59 +120014713}
14714
Chris Forbes5c59e902016-02-26 16:56:09 +130014715TEST_F(VkLayerTest, CreatePipelinePushConstantsNotInLayout) {
Chris Forbes1cc79542016-07-20 11:13:44 +120014716 TEST_DESCRIPTION("Test that an error is produced for a shader consuming push constants "
14717 "which are not provided in the pipeline layout");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014718 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "not declared in layout");
Chris Forbes5c59e902016-02-26 16:56:09 +130014719
14720 ASSERT_NO_FATAL_FAILURE(InitState());
14721
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014722 char const *vsSource = "#version 450\n"
14723 "\n"
14724 "layout(push_constant, std430) uniform foo { float x; } consts;\n"
14725 "out gl_PerVertex {\n"
14726 " vec4 gl_Position;\n"
14727 "};\n"
14728 "void main(){\n"
14729 " gl_Position = vec4(consts.x);\n"
14730 "}\n";
14731 char const *fsSource = "#version 450\n"
14732 "\n"
14733 "layout(location=0) out vec4 x;\n"
14734 "void main(){\n"
14735 " x = vec4(1);\n"
14736 "}\n";
Chris Forbes5c59e902016-02-26 16:56:09 +130014737
14738 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
14739 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
14740
14741 VkPipelineObj pipe(m_device);
14742 pipe.AddShader(&vs);
14743 pipe.AddShader(&fs);
14744
14745 /* set up CB 0; type is UNORM by default */
14746 pipe.AddColorAttachment();
14747 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
14748
14749 VkDescriptorSetObj descriptorSet(m_device);
14750 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
14751
14752 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
14753
14754 /* should have generated an error -- no push constant ranges provided! */
Chris Forbes8f36a8a2016-04-07 13:21:07 +120014755 m_errorMonitor->VerifyFound();
Chris Forbes5c59e902016-02-26 16:56:09 +130014756}
14757
Chris Forbes3fb17902016-08-22 14:57:55 +120014758TEST_F(VkLayerTest, CreatePipelineInputAttachmentMissing) {
14759 TEST_DESCRIPTION("Test that an error is produced for a shader consuming an input attachment "
14760 "which is not included in the subpass description");
14761 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
14762 "consumes input attachment index 0 but not provided in subpass");
14763
14764 ASSERT_NO_FATAL_FAILURE(InitState());
14765
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014766 char const *vsSource = "#version 450\n"
14767 "\n"
14768 "out gl_PerVertex {\n"
14769 " vec4 gl_Position;\n"
14770 "};\n"
14771 "void main(){\n"
14772 " gl_Position = vec4(1);\n"
14773 "}\n";
14774 char const *fsSource = "#version 450\n"
14775 "\n"
14776 "layout(input_attachment_index=0, set=0, binding=0) uniform subpassInput x;\n"
14777 "layout(location=0) out vec4 color;\n"
14778 "void main() {\n"
14779 " color = subpassLoad(x);\n"
14780 "}\n";
Chris Forbes3fb17902016-08-22 14:57:55 +120014781
14782 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
14783 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
14784
14785 VkPipelineObj pipe(m_device);
14786 pipe.AddShader(&vs);
14787 pipe.AddShader(&fs);
14788 pipe.AddColorAttachment();
14789 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
14790
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014791 VkDescriptorSetLayoutBinding dslb = {0, VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT, 1, VK_SHADER_STAGE_FRAGMENT_BIT, nullptr};
14792 VkDescriptorSetLayoutCreateInfo dslci = {VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dslb};
Chris Forbes3fb17902016-08-22 14:57:55 +120014793 VkDescriptorSetLayout dsl;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014794 VkResult err = vkCreateDescriptorSetLayout(m_device->device(), &dslci, nullptr, &dsl);
Chris Forbes3fb17902016-08-22 14:57:55 +120014795 ASSERT_VK_SUCCESS(err);
14796
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014797 VkPipelineLayoutCreateInfo plci = {VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dsl, 0, nullptr};
Chris Forbes3fb17902016-08-22 14:57:55 +120014798 VkPipelineLayout pl;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014799 err = vkCreatePipelineLayout(m_device->device(), &plci, nullptr, &pl);
Chris Forbes3fb17902016-08-22 14:57:55 +120014800 ASSERT_VK_SUCCESS(err);
14801
14802 // error here.
14803 pipe.CreateVKPipeline(pl, renderPass());
14804
14805 m_errorMonitor->VerifyFound();
14806
14807 vkDestroyPipelineLayout(m_device->device(), pl, nullptr);
14808 vkDestroyDescriptorSetLayout(m_device->device(), dsl, nullptr);
14809}
14810
Chris Forbes663b5a82016-08-22 16:14:06 +120014811TEST_F(VkLayerTest, CreatePipelineInputAttachmentPositive) {
14812 TEST_DESCRIPTION("Positive test for a correctly matched input attachment");
14813 m_errorMonitor->ExpectSuccess();
14814
14815 ASSERT_NO_FATAL_FAILURE(InitState());
14816
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014817 char const *vsSource = "#version 450\n"
14818 "\n"
14819 "out gl_PerVertex {\n"
14820 " vec4 gl_Position;\n"
14821 "};\n"
14822 "void main(){\n"
14823 " gl_Position = vec4(1);\n"
14824 "}\n";
14825 char const *fsSource = "#version 450\n"
14826 "\n"
14827 "layout(input_attachment_index=0, set=0, binding=0) uniform subpassInput x;\n"
14828 "layout(location=0) out vec4 color;\n"
14829 "void main() {\n"
14830 " color = subpassLoad(x);\n"
14831 "}\n";
Chris Forbes663b5a82016-08-22 16:14:06 +120014832
14833 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
14834 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
14835
14836 VkPipelineObj pipe(m_device);
14837 pipe.AddShader(&vs);
14838 pipe.AddShader(&fs);
14839 pipe.AddColorAttachment();
14840 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
14841
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014842 VkDescriptorSetLayoutBinding dslb = {0, VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT, 1, VK_SHADER_STAGE_FRAGMENT_BIT, nullptr};
14843 VkDescriptorSetLayoutCreateInfo dslci = {VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dslb};
Chris Forbes663b5a82016-08-22 16:14:06 +120014844 VkDescriptorSetLayout dsl;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014845 VkResult err = vkCreateDescriptorSetLayout(m_device->device(), &dslci, nullptr, &dsl);
Chris Forbes663b5a82016-08-22 16:14:06 +120014846 ASSERT_VK_SUCCESS(err);
14847
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014848 VkPipelineLayoutCreateInfo plci = {VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dsl, 0, nullptr};
Chris Forbes663b5a82016-08-22 16:14:06 +120014849 VkPipelineLayout pl;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014850 err = vkCreatePipelineLayout(m_device->device(), &plci, nullptr, &pl);
Chris Forbes663b5a82016-08-22 16:14:06 +120014851 ASSERT_VK_SUCCESS(err);
14852
14853 VkAttachmentDescription descs[2] = {
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014854 {0, VK_FORMAT_R8G8B8A8_UNORM, VK_SAMPLE_COUNT_1_BIT, VK_ATTACHMENT_LOAD_OP_LOAD, VK_ATTACHMENT_STORE_OP_STORE,
14855 VK_ATTACHMENT_LOAD_OP_LOAD, VK_ATTACHMENT_STORE_OP_STORE, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
14856 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL},
14857 {0, VK_FORMAT_R8G8B8A8_UNORM, VK_SAMPLE_COUNT_1_BIT, VK_ATTACHMENT_LOAD_OP_LOAD, VK_ATTACHMENT_STORE_OP_STORE,
14858 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 +120014859 };
14860 VkAttachmentReference color = {
14861 0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
14862 };
14863 VkAttachmentReference input = {
14864 1, VK_IMAGE_LAYOUT_GENERAL,
14865 };
14866
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014867 VkSubpassDescription sd = {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 1, &input, 1, &color, nullptr, nullptr, 0, nullptr};
Chris Forbes663b5a82016-08-22 16:14:06 +120014868
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014869 VkRenderPassCreateInfo rpci = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 2, descs, 1, &sd, 0, nullptr};
Chris Forbes663b5a82016-08-22 16:14:06 +120014870 VkRenderPass rp;
14871 err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
14872 ASSERT_VK_SUCCESS(err);
14873
14874 // should be OK. would go wrong here if it's going to...
14875 pipe.CreateVKPipeline(pl, rp);
14876
14877 m_errorMonitor->VerifyNotFound();
14878
14879 vkDestroyRenderPass(m_device->device(), rp, nullptr);
14880 vkDestroyPipelineLayout(m_device->device(), pl, nullptr);
14881 vkDestroyDescriptorSetLayout(m_device->device(), dsl, nullptr);
14882}
14883
Chris Forbes5a9a0472016-08-22 16:02:09 +120014884TEST_F(VkLayerTest, CreatePipelineInputAttachmentTypeMismatch) {
14885 TEST_DESCRIPTION("Test that an error is produced for a shader consuming an input attachment "
14886 "with a format having a different fundamental type");
14887 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
14888 "input attachment 0 format of VK_FORMAT_R8G8B8A8_UINT does not match");
14889
14890 ASSERT_NO_FATAL_FAILURE(InitState());
14891
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014892 char const *vsSource = "#version 450\n"
14893 "\n"
14894 "out gl_PerVertex {\n"
14895 " vec4 gl_Position;\n"
14896 "};\n"
14897 "void main(){\n"
14898 " gl_Position = vec4(1);\n"
14899 "}\n";
14900 char const *fsSource = "#version 450\n"
14901 "\n"
14902 "layout(input_attachment_index=0, set=0, binding=0) uniform subpassInput x;\n"
14903 "layout(location=0) out vec4 color;\n"
14904 "void main() {\n"
14905 " color = subpassLoad(x);\n"
14906 "}\n";
Chris Forbes5a9a0472016-08-22 16:02:09 +120014907
14908 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
14909 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
14910
14911 VkPipelineObj pipe(m_device);
14912 pipe.AddShader(&vs);
14913 pipe.AddShader(&fs);
14914 pipe.AddColorAttachment();
14915 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
14916
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014917 VkDescriptorSetLayoutBinding dslb = {0, VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT, 1, VK_SHADER_STAGE_FRAGMENT_BIT, nullptr};
14918 VkDescriptorSetLayoutCreateInfo dslci = {VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dslb};
Chris Forbes5a9a0472016-08-22 16:02:09 +120014919 VkDescriptorSetLayout dsl;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014920 VkResult err = vkCreateDescriptorSetLayout(m_device->device(), &dslci, nullptr, &dsl);
Chris Forbes5a9a0472016-08-22 16:02:09 +120014921 ASSERT_VK_SUCCESS(err);
14922
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014923 VkPipelineLayoutCreateInfo plci = {VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dsl, 0, nullptr};
Chris Forbes5a9a0472016-08-22 16:02:09 +120014924 VkPipelineLayout pl;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014925 err = vkCreatePipelineLayout(m_device->device(), &plci, nullptr, &pl);
Chris Forbes5a9a0472016-08-22 16:02:09 +120014926 ASSERT_VK_SUCCESS(err);
14927
14928 VkAttachmentDescription descs[2] = {
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014929 {0, VK_FORMAT_R8G8B8A8_UNORM, VK_SAMPLE_COUNT_1_BIT, VK_ATTACHMENT_LOAD_OP_LOAD, VK_ATTACHMENT_STORE_OP_STORE,
14930 VK_ATTACHMENT_LOAD_OP_LOAD, VK_ATTACHMENT_STORE_OP_STORE, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
14931 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL},
14932 {0, VK_FORMAT_R8G8B8A8_UINT, VK_SAMPLE_COUNT_1_BIT, VK_ATTACHMENT_LOAD_OP_LOAD, VK_ATTACHMENT_STORE_OP_STORE,
14933 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 +120014934 };
14935 VkAttachmentReference color = {
14936 0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
14937 };
14938 VkAttachmentReference input = {
14939 1, VK_IMAGE_LAYOUT_GENERAL,
14940 };
14941
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014942 VkSubpassDescription sd = {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 1, &input, 1, &color, nullptr, nullptr, 0, nullptr};
Chris Forbes5a9a0472016-08-22 16:02:09 +120014943
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014944 VkRenderPassCreateInfo rpci = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 2, descs, 1, &sd, 0, nullptr};
Chris Forbes5a9a0472016-08-22 16:02:09 +120014945 VkRenderPass rp;
14946 err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
14947 ASSERT_VK_SUCCESS(err);
14948
14949 // error here.
14950 pipe.CreateVKPipeline(pl, rp);
14951
14952 m_errorMonitor->VerifyFound();
14953
14954 vkDestroyRenderPass(m_device->device(), rp, nullptr);
14955 vkDestroyPipelineLayout(m_device->device(), pl, nullptr);
14956 vkDestroyDescriptorSetLayout(m_device->device(), dsl, nullptr);
14957}
14958
Chris Forbes541f7b02016-08-22 15:30:27 +120014959TEST_F(VkLayerTest, CreatePipelineInputAttachmentMissingArray) {
14960 TEST_DESCRIPTION("Test that an error is produced for a shader consuming an input attachment "
14961 "which is not included in the subpass description -- array case");
14962 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
14963 "consumes input attachment index 1 but not provided in subpass");
14964
14965 ASSERT_NO_FATAL_FAILURE(InitState());
14966
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014967 char const *vsSource = "#version 450\n"
14968 "\n"
14969 "out gl_PerVertex {\n"
14970 " vec4 gl_Position;\n"
14971 "};\n"
14972 "void main(){\n"
14973 " gl_Position = vec4(1);\n"
14974 "}\n";
14975 char const *fsSource = "#version 450\n"
14976 "\n"
14977 "layout(input_attachment_index=0, set=0, binding=0) uniform subpassInput xs[2];\n"
14978 "layout(location=0) out vec4 color;\n"
14979 "void main() {\n"
14980 " color = subpassLoad(xs[1]);\n"
14981 "}\n";
Chris Forbes541f7b02016-08-22 15:30:27 +120014982
14983 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
14984 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
14985
14986 VkPipelineObj pipe(m_device);
14987 pipe.AddShader(&vs);
14988 pipe.AddShader(&fs);
14989 pipe.AddColorAttachment();
14990 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
14991
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014992 VkDescriptorSetLayoutBinding dslb = {0, VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT, 2, VK_SHADER_STAGE_FRAGMENT_BIT, nullptr};
14993 VkDescriptorSetLayoutCreateInfo dslci = {VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dslb};
Chris Forbes541f7b02016-08-22 15:30:27 +120014994 VkDescriptorSetLayout dsl;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014995 VkResult err = vkCreateDescriptorSetLayout(m_device->device(), &dslci, nullptr, &dsl);
Chris Forbes541f7b02016-08-22 15:30:27 +120014996 ASSERT_VK_SUCCESS(err);
14997
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014998 VkPipelineLayoutCreateInfo plci = {VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dsl, 0, nullptr};
Chris Forbes541f7b02016-08-22 15:30:27 +120014999 VkPipelineLayout pl;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015000 err = vkCreatePipelineLayout(m_device->device(), &plci, nullptr, &pl);
Chris Forbes541f7b02016-08-22 15:30:27 +120015001 ASSERT_VK_SUCCESS(err);
15002
15003 // error here.
15004 pipe.CreateVKPipeline(pl, renderPass());
15005
15006 m_errorMonitor->VerifyFound();
15007
15008 vkDestroyPipelineLayout(m_device->device(), pl, nullptr);
15009 vkDestroyDescriptorSetLayout(m_device->device(), dsl, nullptr);
15010}
15011
Chris Forbes10eb9ae2016-05-31 16:09:42 +120015012TEST_F(VkLayerTest, CreateComputePipelineMissingDescriptor) {
Chris Forbes1cc79542016-07-20 11:13:44 +120015013 TEST_DESCRIPTION("Test that an error is produced for a compute pipeline consuming a "
15014 "descriptor which is not provided in the pipeline layout");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015015 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Shader uses descriptor slot 0.0");
Chris Forbes10eb9ae2016-05-31 16:09:42 +120015016
15017 ASSERT_NO_FATAL_FAILURE(InitState());
15018
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015019 char const *csSource = "#version 450\n"
15020 "\n"
15021 "layout(local_size_x=1) in;\n"
15022 "layout(set=0, binding=0) buffer block { vec4 x; };\n"
15023 "void main(){\n"
15024 " x = vec4(1);\n"
15025 "}\n";
Chris Forbes10eb9ae2016-05-31 16:09:42 +120015026
15027 VkShaderObj cs(m_device, csSource, VK_SHADER_STAGE_COMPUTE_BIT, this);
15028
15029 VkDescriptorSetObj descriptorSet(m_device);
15030 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
15031
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015032 VkComputePipelineCreateInfo cpci = {VK_STRUCTURE_TYPE_COMPUTE_PIPELINE_CREATE_INFO,
15033 nullptr,
15034 0,
15035 {VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO, nullptr, 0,
15036 VK_SHADER_STAGE_COMPUTE_BIT, cs.handle(), "main", nullptr},
15037 descriptorSet.GetPipelineLayout(),
15038 VK_NULL_HANDLE,
15039 -1};
Chris Forbes10eb9ae2016-05-31 16:09:42 +120015040
15041 VkPipeline pipe;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015042 VkResult err = vkCreateComputePipelines(m_device->device(), VK_NULL_HANDLE, 1, &cpci, nullptr, &pipe);
Chris Forbes10eb9ae2016-05-31 16:09:42 +120015043
15044 m_errorMonitor->VerifyFound();
15045
15046 if (err == VK_SUCCESS) {
15047 vkDestroyPipeline(m_device->device(), pipe, nullptr);
15048 }
15049}
15050
15051TEST_F(VkLayerTest, CreateComputePipelineMissingDescriptorUnusedPositive) {
Chris Forbes1cc79542016-07-20 11:13:44 +120015052 TEST_DESCRIPTION("Test that pipeline validation accepts a compute pipeline which declares a "
15053 "descriptor-backed resource which is not provided, but the shader does not "
15054 "statically use it. This is interesting because it requires compute pipelines "
15055 "to have a proper descriptor use walk, which they didn't for some time.");
Chris Forbes10eb9ae2016-05-31 16:09:42 +120015056 m_errorMonitor->ExpectSuccess();
15057
15058 ASSERT_NO_FATAL_FAILURE(InitState());
15059
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015060 char const *csSource = "#version 450\n"
15061 "\n"
15062 "layout(local_size_x=1) in;\n"
15063 "layout(set=0, binding=0) buffer block { vec4 x; };\n"
15064 "void main(){\n"
15065 " // x is not used.\n"
15066 "}\n";
Chris Forbes10eb9ae2016-05-31 16:09:42 +120015067
15068 VkShaderObj cs(m_device, csSource, VK_SHADER_STAGE_COMPUTE_BIT, this);
15069
15070 VkDescriptorSetObj descriptorSet(m_device);
15071 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
15072
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015073 VkComputePipelineCreateInfo cpci = {VK_STRUCTURE_TYPE_COMPUTE_PIPELINE_CREATE_INFO,
15074 nullptr,
15075 0,
15076 {VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO, nullptr, 0,
15077 VK_SHADER_STAGE_COMPUTE_BIT, cs.handle(), "main", nullptr},
15078 descriptorSet.GetPipelineLayout(),
15079 VK_NULL_HANDLE,
15080 -1};
Chris Forbes10eb9ae2016-05-31 16:09:42 +120015081
15082 VkPipeline pipe;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015083 VkResult err = vkCreateComputePipelines(m_device->device(), VK_NULL_HANDLE, 1, &cpci, nullptr, &pipe);
Chris Forbes10eb9ae2016-05-31 16:09:42 +120015084
15085 m_errorMonitor->VerifyNotFound();
15086
15087 if (err == VK_SUCCESS) {
15088 vkDestroyPipeline(m_device->device(), pipe, nullptr);
15089 }
15090}
15091
Chris Forbes22a9b092016-07-19 14:34:05 +120015092TEST_F(VkLayerTest, CreateComputePipelineDescriptorTypeMismatch) {
Chris Forbes1cc79542016-07-20 11:13:44 +120015093 TEST_DESCRIPTION("Test that an error is produced for a pipeline consuming a "
15094 "descriptor-backed resource of a mismatched type");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015095 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
15096 "but descriptor of type VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER");
Chris Forbes22a9b092016-07-19 14:34:05 +120015097
15098 ASSERT_NO_FATAL_FAILURE(InitState());
15099
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015100 VkDescriptorSetLayoutBinding binding = {0, VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, 1, VK_SHADER_STAGE_COMPUTE_BIT, nullptr};
15101 VkDescriptorSetLayoutCreateInfo dslci = {VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO, nullptr, 0, 1, &binding};
Chris Forbes22a9b092016-07-19 14:34:05 +120015102 VkDescriptorSetLayout dsl;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015103 VkResult err = vkCreateDescriptorSetLayout(m_device->device(), &dslci, nullptr, &dsl);
Chris Forbes22a9b092016-07-19 14:34:05 +120015104 ASSERT_VK_SUCCESS(err);
15105
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015106 VkPipelineLayoutCreateInfo plci = {VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dsl, 0, nullptr};
Chris Forbes22a9b092016-07-19 14:34:05 +120015107 VkPipelineLayout pl;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015108 err = vkCreatePipelineLayout(m_device->device(), &plci, nullptr, &pl);
Chris Forbes22a9b092016-07-19 14:34:05 +120015109 ASSERT_VK_SUCCESS(err);
15110
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015111 char const *csSource = "#version 450\n"
15112 "\n"
15113 "layout(local_size_x=1) in;\n"
15114 "layout(set=0, binding=0) buffer block { vec4 x; };\n"
15115 "void main() {\n"
15116 " x.x = 1.0f;\n"
15117 "}\n";
Chris Forbes22a9b092016-07-19 14:34:05 +120015118 VkShaderObj cs(m_device, csSource, VK_SHADER_STAGE_COMPUTE_BIT, this);
15119
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015120 VkComputePipelineCreateInfo cpci = {VK_STRUCTURE_TYPE_COMPUTE_PIPELINE_CREATE_INFO,
15121 nullptr,
15122 0,
15123 {VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO, nullptr, 0,
15124 VK_SHADER_STAGE_COMPUTE_BIT, cs.handle(), "main", nullptr},
15125 pl,
15126 VK_NULL_HANDLE,
15127 -1};
Chris Forbes22a9b092016-07-19 14:34:05 +120015128
15129 VkPipeline pipe;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015130 err = vkCreateComputePipelines(m_device->device(), VK_NULL_HANDLE, 1, &cpci, nullptr, &pipe);
Chris Forbes22a9b092016-07-19 14:34:05 +120015131
15132 m_errorMonitor->VerifyFound();
15133
15134 if (err == VK_SUCCESS) {
15135 vkDestroyPipeline(m_device->device(), pipe, nullptr);
15136 }
15137
15138 vkDestroyPipelineLayout(m_device->device(), pl, nullptr);
15139 vkDestroyDescriptorSetLayout(m_device->device(), dsl, nullptr);
15140}
15141
Chris Forbese10a51f2016-07-19 14:42:51 +120015142TEST_F(VkLayerTest, CreateComputePipelineCombinedImageSamplerConsumedAsSampler) {
Chris Forbes1cc79542016-07-20 11:13:44 +120015143 TEST_DESCRIPTION("Test that pipeline validation accepts a shader consuming only the "
15144 "sampler portion of a combined image + sampler");
Chris Forbese10a51f2016-07-19 14:42:51 +120015145 m_errorMonitor->ExpectSuccess();
15146
15147 ASSERT_NO_FATAL_FAILURE(InitState());
15148
15149 VkDescriptorSetLayoutBinding bindings[] = {
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015150 {0, VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, 1, VK_SHADER_STAGE_COMPUTE_BIT, nullptr},
15151 {1, VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE, 1, VK_SHADER_STAGE_COMPUTE_BIT, nullptr},
15152 {2, VK_DESCRIPTOR_TYPE_STORAGE_BUFFER, 1, VK_SHADER_STAGE_COMPUTE_BIT, nullptr},
Chris Forbese10a51f2016-07-19 14:42:51 +120015153 };
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015154 VkDescriptorSetLayoutCreateInfo dslci = {VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO, nullptr, 0, 3, bindings};
Chris Forbese10a51f2016-07-19 14:42:51 +120015155 VkDescriptorSetLayout dsl;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015156 VkResult err = vkCreateDescriptorSetLayout(m_device->device(), &dslci, nullptr, &dsl);
Chris Forbese10a51f2016-07-19 14:42:51 +120015157 ASSERT_VK_SUCCESS(err);
15158
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015159 VkPipelineLayoutCreateInfo plci = {VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dsl, 0, nullptr};
Chris Forbese10a51f2016-07-19 14:42:51 +120015160 VkPipelineLayout pl;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015161 err = vkCreatePipelineLayout(m_device->device(), &plci, nullptr, &pl);
Chris Forbese10a51f2016-07-19 14:42:51 +120015162 ASSERT_VK_SUCCESS(err);
15163
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015164 char const *csSource = "#version 450\n"
15165 "\n"
15166 "layout(local_size_x=1) in;\n"
15167 "layout(set=0, binding=0) uniform sampler s;\n"
15168 "layout(set=0, binding=1) uniform texture2D t;\n"
15169 "layout(set=0, binding=2) buffer block { vec4 x; };\n"
15170 "void main() {\n"
15171 " x = texture(sampler2D(t, s), vec2(0));\n"
15172 "}\n";
Chris Forbese10a51f2016-07-19 14:42:51 +120015173 VkShaderObj cs(m_device, csSource, VK_SHADER_STAGE_COMPUTE_BIT, this);
15174
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015175 VkComputePipelineCreateInfo cpci = {VK_STRUCTURE_TYPE_COMPUTE_PIPELINE_CREATE_INFO,
15176 nullptr,
15177 0,
15178 {VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO, nullptr, 0,
15179 VK_SHADER_STAGE_COMPUTE_BIT, cs.handle(), "main", nullptr},
15180 pl,
15181 VK_NULL_HANDLE,
15182 -1};
Chris Forbese10a51f2016-07-19 14:42:51 +120015183
15184 VkPipeline pipe;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015185 err = vkCreateComputePipelines(m_device->device(), VK_NULL_HANDLE, 1, &cpci, nullptr, &pipe);
Chris Forbese10a51f2016-07-19 14:42:51 +120015186
15187 m_errorMonitor->VerifyNotFound();
15188
15189 if (err == VK_SUCCESS) {
15190 vkDestroyPipeline(m_device->device(), pipe, nullptr);
15191 }
15192
15193 vkDestroyPipelineLayout(m_device->device(), pl, nullptr);
15194 vkDestroyDescriptorSetLayout(m_device->device(), dsl, nullptr);
15195}
15196
Chris Forbes91c3b2a2016-07-19 14:46:38 +120015197TEST_F(VkLayerTest, CreateComputePipelineCombinedImageSamplerConsumedAsImage) {
Chris Forbes1cc79542016-07-20 11:13:44 +120015198 TEST_DESCRIPTION("Test that pipeline validation accepts a shader consuming only the "
15199 "image portion of a combined image + sampler");
Chris Forbes91c3b2a2016-07-19 14:46:38 +120015200 m_errorMonitor->ExpectSuccess();
15201
15202 ASSERT_NO_FATAL_FAILURE(InitState());
15203
15204 VkDescriptorSetLayoutBinding bindings[] = {
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015205 {0, VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, 1, VK_SHADER_STAGE_COMPUTE_BIT, nullptr},
15206 {1, VK_DESCRIPTOR_TYPE_SAMPLER, 1, VK_SHADER_STAGE_COMPUTE_BIT, nullptr},
15207 {2, VK_DESCRIPTOR_TYPE_STORAGE_BUFFER, 1, VK_SHADER_STAGE_COMPUTE_BIT, nullptr},
Chris Forbes91c3b2a2016-07-19 14:46:38 +120015208 };
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015209 VkDescriptorSetLayoutCreateInfo dslci = {VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO, nullptr, 0, 3, bindings};
Chris Forbes91c3b2a2016-07-19 14:46:38 +120015210 VkDescriptorSetLayout dsl;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015211 VkResult err = vkCreateDescriptorSetLayout(m_device->device(), &dslci, nullptr, &dsl);
Chris Forbes91c3b2a2016-07-19 14:46:38 +120015212 ASSERT_VK_SUCCESS(err);
15213
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015214 VkPipelineLayoutCreateInfo plci = {VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dsl, 0, nullptr};
Chris Forbes91c3b2a2016-07-19 14:46:38 +120015215 VkPipelineLayout pl;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015216 err = vkCreatePipelineLayout(m_device->device(), &plci, nullptr, &pl);
Chris Forbes91c3b2a2016-07-19 14:46:38 +120015217 ASSERT_VK_SUCCESS(err);
15218
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015219 char const *csSource = "#version 450\n"
15220 "\n"
15221 "layout(local_size_x=1) in;\n"
15222 "layout(set=0, binding=0) uniform texture2D t;\n"
15223 "layout(set=0, binding=1) uniform sampler s;\n"
15224 "layout(set=0, binding=2) buffer block { vec4 x; };\n"
15225 "void main() {\n"
15226 " x = texture(sampler2D(t, s), vec2(0));\n"
15227 "}\n";
Chris Forbes91c3b2a2016-07-19 14:46:38 +120015228 VkShaderObj cs(m_device, csSource, VK_SHADER_STAGE_COMPUTE_BIT, this);
15229
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015230 VkComputePipelineCreateInfo cpci = {VK_STRUCTURE_TYPE_COMPUTE_PIPELINE_CREATE_INFO,
15231 nullptr,
15232 0,
15233 {VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO, nullptr, 0,
15234 VK_SHADER_STAGE_COMPUTE_BIT, cs.handle(), "main", nullptr},
15235 pl,
15236 VK_NULL_HANDLE,
15237 -1};
Chris Forbes91c3b2a2016-07-19 14:46:38 +120015238
15239 VkPipeline pipe;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015240 err = vkCreateComputePipelines(m_device->device(), VK_NULL_HANDLE, 1, &cpci, nullptr, &pipe);
Chris Forbes91c3b2a2016-07-19 14:46:38 +120015241
15242 m_errorMonitor->VerifyNotFound();
15243
15244 if (err == VK_SUCCESS) {
15245 vkDestroyPipeline(m_device->device(), pipe, nullptr);
15246 }
15247
15248 vkDestroyPipelineLayout(m_device->device(), pl, nullptr);
15249 vkDestroyDescriptorSetLayout(m_device->device(), dsl, nullptr);
15250}
15251
Chris Forbes6a4991a2016-07-19 15:07:32 +120015252TEST_F(VkLayerTest, CreateComputePipelineCombinedImageSamplerConsumedAsBoth) {
Chris Forbes1cc79542016-07-20 11:13:44 +120015253 TEST_DESCRIPTION("Test that pipeline validation accepts a shader consuming "
15254 "both the sampler and the image of a combined image+sampler "
15255 "but via separate variables");
Chris Forbes6a4991a2016-07-19 15:07:32 +120015256 m_errorMonitor->ExpectSuccess();
15257
15258 ASSERT_NO_FATAL_FAILURE(InitState());
15259
15260 VkDescriptorSetLayoutBinding bindings[] = {
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015261 {0, VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, 1, VK_SHADER_STAGE_COMPUTE_BIT, nullptr},
15262 {1, VK_DESCRIPTOR_TYPE_STORAGE_BUFFER, 1, VK_SHADER_STAGE_COMPUTE_BIT, nullptr},
Chris Forbes6a4991a2016-07-19 15:07:32 +120015263 };
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015264 VkDescriptorSetLayoutCreateInfo dslci = {VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO, nullptr, 0, 2, bindings};
Chris Forbes6a4991a2016-07-19 15:07:32 +120015265 VkDescriptorSetLayout dsl;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015266 VkResult err = vkCreateDescriptorSetLayout(m_device->device(), &dslci, nullptr, &dsl);
Chris Forbes6a4991a2016-07-19 15:07:32 +120015267 ASSERT_VK_SUCCESS(err);
15268
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015269 VkPipelineLayoutCreateInfo plci = {VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dsl, 0, nullptr};
Chris Forbes6a4991a2016-07-19 15:07:32 +120015270 VkPipelineLayout pl;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015271 err = vkCreatePipelineLayout(m_device->device(), &plci, nullptr, &pl);
Chris Forbes6a4991a2016-07-19 15:07:32 +120015272 ASSERT_VK_SUCCESS(err);
15273
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015274 char const *csSource = "#version 450\n"
15275 "\n"
15276 "layout(local_size_x=1) in;\n"
15277 "layout(set=0, binding=0) uniform texture2D t;\n"
15278 "layout(set=0, binding=0) uniform sampler s; // both binding 0!\n"
15279 "layout(set=0, binding=1) buffer block { vec4 x; };\n"
15280 "void main() {\n"
15281 " x = texture(sampler2D(t, s), vec2(0));\n"
15282 "}\n";
Chris Forbes6a4991a2016-07-19 15:07:32 +120015283 VkShaderObj cs(m_device, csSource, VK_SHADER_STAGE_COMPUTE_BIT, this);
15284
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015285 VkComputePipelineCreateInfo cpci = {VK_STRUCTURE_TYPE_COMPUTE_PIPELINE_CREATE_INFO,
15286 nullptr,
15287 0,
15288 {VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO, nullptr, 0,
15289 VK_SHADER_STAGE_COMPUTE_BIT, cs.handle(), "main", nullptr},
15290 pl,
15291 VK_NULL_HANDLE,
15292 -1};
Chris Forbes6a4991a2016-07-19 15:07:32 +120015293
15294 VkPipeline pipe;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015295 err = vkCreateComputePipelines(m_device->device(), VK_NULL_HANDLE, 1, &cpci, nullptr, &pipe);
Chris Forbes6a4991a2016-07-19 15:07:32 +120015296
15297 m_errorMonitor->VerifyNotFound();
15298
15299 if (err == VK_SUCCESS) {
15300 vkDestroyPipeline(m_device->device(), pipe, nullptr);
15301 }
15302
15303 vkDestroyPipelineLayout(m_device->device(), pl, nullptr);
15304 vkDestroyDescriptorSetLayout(m_device->device(), dsl, nullptr);
15305}
15306
Chris Forbes50020592016-07-27 13:52:41 +120015307TEST_F(VkLayerTest, DrawTimeImageViewTypeMismatchWithPipeline) {
15308 TEST_DESCRIPTION("Test that an error is produced when an image view type "
15309 "does not match the dimensionality declared in the shader");
15310
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015311 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 +120015312
15313 ASSERT_NO_FATAL_FAILURE(InitState());
15314 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
15315
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015316 char const *vsSource = "#version 450\n"
15317 "\n"
15318 "out gl_PerVertex { vec4 gl_Position; };\n"
15319 "void main() { gl_Position = vec4(0); }\n";
15320 char const *fsSource = "#version 450\n"
15321 "\n"
15322 "layout(set=0, binding=0) uniform sampler3D s;\n"
15323 "layout(location=0) out vec4 color;\n"
15324 "void main() {\n"
15325 " color = texture(s, vec3(0));\n"
15326 "}\n";
Chris Forbes50020592016-07-27 13:52:41 +120015327 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
15328 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
15329
15330 VkPipelineObj pipe(m_device);
15331 pipe.AddShader(&vs);
15332 pipe.AddShader(&fs);
15333 pipe.AddColorAttachment();
15334
15335 VkTextureObj texture(m_device, nullptr);
15336 VkSamplerObj sampler(m_device);
15337
15338 VkDescriptorSetObj descriptorSet(m_device);
15339 descriptorSet.AppendSamplerTexture(&sampler, &texture);
15340 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
15341
15342 VkResult err = pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
15343 ASSERT_VK_SUCCESS(err);
15344
15345 BeginCommandBuffer();
15346
15347 m_commandBuffer->BindPipeline(pipe);
15348 m_commandBuffer->BindDescriptorSet(descriptorSet);
15349
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015350 VkViewport viewport = {0, 0, 16, 16, 0, 1};
Chris Forbes50020592016-07-27 13:52:41 +120015351 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015352 VkRect2D scissor = {{0, 0}, {16, 16}};
Chris Forbes50020592016-07-27 13:52:41 +120015353 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
15354
15355 // error produced here.
15356 vkCmdDraw(m_commandBuffer->handle(), 3, 1, 0, 0);
15357
15358 m_errorMonitor->VerifyFound();
15359
15360 EndCommandBuffer();
15361}
15362
Chris Forbes5533bfc2016-07-27 14:12:34 +120015363TEST_F(VkLayerTest, DrawTimeImageMultisampleMismatchWithPipeline) {
15364 TEST_DESCRIPTION("Test that an error is produced when a multisampled images "
15365 "are consumed via singlesample images types in the shader, or vice versa.");
15366
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015367 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "requires bound image to have multiple samples");
Chris Forbes5533bfc2016-07-27 14:12:34 +120015368
15369 ASSERT_NO_FATAL_FAILURE(InitState());
15370 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
15371
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015372 char const *vsSource = "#version 450\n"
15373 "\n"
15374 "out gl_PerVertex { vec4 gl_Position; };\n"
15375 "void main() { gl_Position = vec4(0); }\n";
15376 char const *fsSource = "#version 450\n"
15377 "\n"
15378 "layout(set=0, binding=0) uniform sampler2DMS s;\n"
15379 "layout(location=0) out vec4 color;\n"
15380 "void main() {\n"
15381 " color = texelFetch(s, ivec2(0), 0);\n"
15382 "}\n";
Chris Forbes5533bfc2016-07-27 14:12:34 +120015383 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
15384 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
15385
15386 VkPipelineObj pipe(m_device);
15387 pipe.AddShader(&vs);
15388 pipe.AddShader(&fs);
15389 pipe.AddColorAttachment();
15390
15391 VkTextureObj texture(m_device, nullptr);
15392 VkSamplerObj sampler(m_device);
15393
15394 VkDescriptorSetObj descriptorSet(m_device);
15395 descriptorSet.AppendSamplerTexture(&sampler, &texture);
15396 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
15397
15398 VkResult err = pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
15399 ASSERT_VK_SUCCESS(err);
15400
15401 BeginCommandBuffer();
15402
15403 m_commandBuffer->BindPipeline(pipe);
15404 m_commandBuffer->BindDescriptorSet(descriptorSet);
15405
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015406 VkViewport viewport = {0, 0, 16, 16, 0, 1};
Chris Forbes5533bfc2016-07-27 14:12:34 +120015407 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015408 VkRect2D scissor = {{0, 0}, {16, 16}};
Chris Forbes5533bfc2016-07-27 14:12:34 +120015409 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
15410
15411 // error produced here.
15412 vkCmdDraw(m_commandBuffer->handle(), 3, 1, 0, 0);
15413
15414 m_errorMonitor->VerifyFound();
15415
15416 EndCommandBuffer();
15417}
15418
Mark Lobodzinski209b5292015-09-17 09:44:05 -060015419#endif // SHADER_CHECKER_TESTS
15420
15421#if DEVICE_LIMITS_TESTS
Mark Youngc48c4c12016-04-11 14:26:49 -060015422TEST_F(VkLayerTest, CreateImageLimitsViolationMaxWidth) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015423 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "CreateImage extents exceed allowable limits for format");
Mark Lobodzinski6f2274e2015-09-22 09:33:21 -060015424
15425 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinski6f2274e2015-09-22 09:33:21 -060015426
15427 // Create an image
15428 VkImage image;
15429
Karl Schultz6addd812016-02-02 17:17:23 -070015430 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
15431 const int32_t tex_width = 32;
15432 const int32_t tex_height = 32;
Mark Lobodzinski6f2274e2015-09-22 09:33:21 -060015433
15434 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070015435 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
15436 image_create_info.pNext = NULL;
15437 image_create_info.imageType = VK_IMAGE_TYPE_2D;
15438 image_create_info.format = tex_format;
15439 image_create_info.extent.width = tex_width;
Mark Lobodzinski6f2274e2015-09-22 09:33:21 -060015440 image_create_info.extent.height = tex_height;
Karl Schultz6addd812016-02-02 17:17:23 -070015441 image_create_info.extent.depth = 1;
15442 image_create_info.mipLevels = 1;
15443 image_create_info.arrayLayers = 1;
15444 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
15445 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
15446 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
15447 image_create_info.flags = 0;
Mark Lobodzinski6f2274e2015-09-22 09:33:21 -060015448
15449 // Introduce error by sending down a bogus width extent
15450 image_create_info.extent.width = 65536;
Chia-I Wuf7458c52015-10-26 21:10:41 +080015451 vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
Mark Lobodzinski6f2274e2015-09-22 09:33:21 -060015452
Chris Forbes8f36a8a2016-04-07 13:21:07 +120015453 m_errorMonitor->VerifyFound();
Mark Lobodzinski6f2274e2015-09-22 09:33:21 -060015454}
15455
Mark Youngc48c4c12016-04-11 14:26:49 -060015456TEST_F(VkLayerTest, CreateImageLimitsViolationMinWidth) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015457 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
15458 "CreateImage extents is 0 for at least one required dimension");
Mark Youngc48c4c12016-04-11 14:26:49 -060015459
15460 ASSERT_NO_FATAL_FAILURE(InitState());
15461
15462 // Create an image
15463 VkImage image;
15464
15465 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
15466 const int32_t tex_width = 32;
15467 const int32_t tex_height = 32;
15468
15469 VkImageCreateInfo image_create_info = {};
15470 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
15471 image_create_info.pNext = NULL;
15472 image_create_info.imageType = VK_IMAGE_TYPE_2D;
15473 image_create_info.format = tex_format;
15474 image_create_info.extent.width = tex_width;
15475 image_create_info.extent.height = tex_height;
15476 image_create_info.extent.depth = 1;
15477 image_create_info.mipLevels = 1;
15478 image_create_info.arrayLayers = 1;
15479 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
15480 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
15481 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
15482 image_create_info.flags = 0;
15483
15484 // Introduce error by sending down a bogus width extent
15485 image_create_info.extent.width = 0;
15486 vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
15487
15488 m_errorMonitor->VerifyFound();
15489}
Mark Lobodzinski209b5292015-09-17 09:44:05 -060015490#endif // DEVICE_LIMITS_TESTS
Chris Forbesa36d69e2015-05-25 11:13:44 +120015491
Tobin Ehliscde08892015-09-22 10:11:37 -060015492#if IMAGE_TESTS
Mark Lobodzinskidf4c57d2016-08-05 11:47:16 -060015493TEST_F(VkLayerTest, AttachmentDescriptionUndefinedFormat) {
15494 TEST_DESCRIPTION("Create a render pass with an attachment description "
15495 "format set to VK_FORMAT_UNDEFINED");
15496
15497 ASSERT_NO_FATAL_FAILURE(InitState());
15498 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
15499
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015500 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "format is VK_FORMAT_UNDEFINED");
Mark Lobodzinskidf4c57d2016-08-05 11:47:16 -060015501
15502 VkAttachmentReference color_attach = {};
15503 color_attach.layout = VK_IMAGE_LAYOUT_GENERAL;
15504 color_attach.attachment = 0;
15505 VkSubpassDescription subpass = {};
15506 subpass.colorAttachmentCount = 1;
15507 subpass.pColorAttachments = &color_attach;
15508
15509 VkRenderPassCreateInfo rpci = {};
15510 rpci.subpassCount = 1;
15511 rpci.pSubpasses = &subpass;
15512 rpci.attachmentCount = 1;
15513 VkAttachmentDescription attach_desc = {};
15514 attach_desc.format = VK_FORMAT_UNDEFINED;
15515 rpci.pAttachments = &attach_desc;
15516 rpci.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
15517 VkRenderPass rp;
15518 VkResult result = vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
15519
15520 m_errorMonitor->VerifyFound();
15521
15522 if (result == VK_SUCCESS) {
15523 vkDestroyRenderPass(m_device->device(), rp, NULL);
15524 }
15525}
15526
Karl Schultz6addd812016-02-02 17:17:23 -070015527TEST_F(VkLayerTest, InvalidImageView) {
15528 VkResult err;
Tobin Ehliscde08892015-09-22 10:11:37 -060015529
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015530 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "vkCreateImageView called with baseMipLevel 10 ");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060015531
Tobin Ehliscde08892015-09-22 10:11:37 -060015532 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehliscde08892015-09-22 10:11:37 -060015533
Mike Stroyana3082432015-09-25 13:39:21 -060015534 // Create an image and try to create a view with bad baseMipLevel
Karl Schultz6addd812016-02-02 17:17:23 -070015535 VkImage image;
Tobin Ehliscde08892015-09-22 10:11:37 -060015536
Karl Schultz6addd812016-02-02 17:17:23 -070015537 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
15538 const int32_t tex_width = 32;
15539 const int32_t tex_height = 32;
Tobin Ehliscde08892015-09-22 10:11:37 -060015540
15541 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070015542 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
15543 image_create_info.pNext = NULL;
15544 image_create_info.imageType = VK_IMAGE_TYPE_2D;
15545 image_create_info.format = tex_format;
15546 image_create_info.extent.width = tex_width;
15547 image_create_info.extent.height = tex_height;
15548 image_create_info.extent.depth = 1;
15549 image_create_info.mipLevels = 1;
15550 image_create_info.arrayLayers = 1;
15551 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
15552 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
15553 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
15554 image_create_info.flags = 0;
Tobin Ehliscde08892015-09-22 10:11:37 -060015555
Chia-I Wuf7458c52015-10-26 21:10:41 +080015556 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
Tobin Ehliscde08892015-09-22 10:11:37 -060015557 ASSERT_VK_SUCCESS(err);
15558
15559 VkImageViewCreateInfo image_view_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070015560 image_view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
15561 image_view_create_info.image = image;
15562 image_view_create_info.viewType = VK_IMAGE_VIEW_TYPE_2D;
15563 image_view_create_info.format = tex_format;
15564 image_view_create_info.subresourceRange.layerCount = 1;
15565 image_view_create_info.subresourceRange.baseMipLevel = 10; // cause an error
15566 image_view_create_info.subresourceRange.levelCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015567 image_view_create_info.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Tobin Ehliscde08892015-09-22 10:11:37 -060015568
15569 VkImageView view;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015570 err = vkCreateImageView(m_device->device(), &image_view_create_info, NULL, &view);
Tobin Ehliscde08892015-09-22 10:11:37 -060015571
Chris Forbes8f36a8a2016-04-07 13:21:07 +120015572 m_errorMonitor->VerifyFound();
Tony Barbourdf4c0042016-06-01 15:55:43 -060015573 vkDestroyImage(m_device->device(), image, NULL);
Tobin Ehliscde08892015-09-22 10:11:37 -060015574}
Mike Stroyana3082432015-09-25 13:39:21 -060015575
Mark Youngd339ba32016-05-30 13:28:35 -060015576TEST_F(VkLayerTest, CreateImageViewNoMemoryBoundToImage) {
15577 VkResult err;
15578
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015579 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "used without first calling vkBindImageMemory");
Mark Youngd339ba32016-05-30 13:28:35 -060015580
15581 ASSERT_NO_FATAL_FAILURE(InitState());
15582
15583 // Create an image and try to create a view with no memory backing the image
15584 VkImage image;
15585
15586 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
15587 const int32_t tex_width = 32;
15588 const int32_t tex_height = 32;
15589
15590 VkImageCreateInfo image_create_info = {};
15591 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
15592 image_create_info.pNext = NULL;
15593 image_create_info.imageType = VK_IMAGE_TYPE_2D;
15594 image_create_info.format = tex_format;
15595 image_create_info.extent.width = tex_width;
15596 image_create_info.extent.height = tex_height;
15597 image_create_info.extent.depth = 1;
15598 image_create_info.mipLevels = 1;
15599 image_create_info.arrayLayers = 1;
15600 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
15601 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
15602 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
15603 image_create_info.flags = 0;
15604
15605 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
15606 ASSERT_VK_SUCCESS(err);
15607
15608 VkImageViewCreateInfo image_view_create_info = {};
15609 image_view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
15610 image_view_create_info.image = image;
15611 image_view_create_info.viewType = VK_IMAGE_VIEW_TYPE_2D;
15612 image_view_create_info.format = tex_format;
15613 image_view_create_info.subresourceRange.layerCount = 1;
15614 image_view_create_info.subresourceRange.baseMipLevel = 0;
15615 image_view_create_info.subresourceRange.levelCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015616 image_view_create_info.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mark Youngd339ba32016-05-30 13:28:35 -060015617
15618 VkImageView view;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015619 err = vkCreateImageView(m_device->device(), &image_view_create_info, NULL, &view);
Mark Youngd339ba32016-05-30 13:28:35 -060015620
15621 m_errorMonitor->VerifyFound();
15622 vkDestroyImage(m_device->device(), image, NULL);
15623 // If last error is success, it still created the view, so delete it.
15624 if (err == VK_SUCCESS) {
15625 vkDestroyImageView(m_device->device(), view, NULL);
15626 }
Mark Youngd339ba32016-05-30 13:28:35 -060015627}
15628
Karl Schultz6addd812016-02-02 17:17:23 -070015629TEST_F(VkLayerTest, InvalidImageViewAspect) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015630 TEST_DESCRIPTION("Create an image and try to create a view with an invalid aspectMask");
15631 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "vkCreateImageView: Color image "
15632 "formats must have ONLY the "
15633 "VK_IMAGE_ASPECT_COLOR_BIT set");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060015634
Mark Lobodzinskidc86b852015-10-23 14:20:31 -060015635 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinskidc86b852015-10-23 14:20:31 -060015636
Karl Schultz6addd812016-02-02 17:17:23 -070015637 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
Tobin Ehlis1f567a22016-05-25 16:15:18 -060015638 VkImageObj image(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015639 image.init(32, 32, tex_format, VK_IMAGE_USAGE_SAMPLED_BIT, VK_IMAGE_TILING_LINEAR, 0);
Tobin Ehlis1f567a22016-05-25 16:15:18 -060015640 ASSERT_TRUE(image.initialized());
Mark Lobodzinskidc86b852015-10-23 14:20:31 -060015641
15642 VkImageViewCreateInfo image_view_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070015643 image_view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
Tobin Ehlis1f567a22016-05-25 16:15:18 -060015644 image_view_create_info.image = image.handle();
Karl Schultz6addd812016-02-02 17:17:23 -070015645 image_view_create_info.viewType = VK_IMAGE_VIEW_TYPE_2D;
15646 image_view_create_info.format = tex_format;
15647 image_view_create_info.subresourceRange.baseMipLevel = 0;
15648 image_view_create_info.subresourceRange.levelCount = 1;
15649 // Cause an error by setting an invalid image aspect
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015650 image_view_create_info.subresourceRange.aspectMask = VK_IMAGE_ASPECT_METADATA_BIT;
Mark Lobodzinskidc86b852015-10-23 14:20:31 -060015651
15652 VkImageView view;
Tobin Ehlis1f567a22016-05-25 16:15:18 -060015653 vkCreateImageView(m_device->device(), &image_view_create_info, NULL, &view);
Mark Lobodzinskidc86b852015-10-23 14:20:31 -060015654
Chris Forbes8f36a8a2016-04-07 13:21:07 +120015655 m_errorMonitor->VerifyFound();
Mark Lobodzinskidc86b852015-10-23 14:20:31 -060015656}
15657
Mark Lobodzinskidb117632016-03-31 10:45:56 -060015658TEST_F(VkLayerTest, CopyImageLayerCountMismatch) {
Karl Schultz6addd812016-02-02 17:17:23 -070015659 VkResult err;
15660 bool pass;
Mike Stroyana3082432015-09-25 13:39:21 -060015661
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015662 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
15663 "vkCmdCopyImage: number of layers in source and destination subresources for pRegions");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060015664
Mike Stroyana3082432015-09-25 13:39:21 -060015665 ASSERT_NO_FATAL_FAILURE(InitState());
Mike Stroyana3082432015-09-25 13:39:21 -060015666
15667 // Create two images of different types and try to copy between them
Karl Schultz6addd812016-02-02 17:17:23 -070015668 VkImage srcImage;
15669 VkImage dstImage;
15670 VkDeviceMemory srcMem;
15671 VkDeviceMemory destMem;
15672 VkMemoryRequirements memReqs;
Mike Stroyana3082432015-09-25 13:39:21 -060015673
15674 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070015675 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
15676 image_create_info.pNext = NULL;
15677 image_create_info.imageType = VK_IMAGE_TYPE_2D;
15678 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
15679 image_create_info.extent.width = 32;
15680 image_create_info.extent.height = 32;
15681 image_create_info.extent.depth = 1;
15682 image_create_info.mipLevels = 1;
Mark Lobodzinskidb117632016-03-31 10:45:56 -060015683 image_create_info.arrayLayers = 4;
Karl Schultz6addd812016-02-02 17:17:23 -070015684 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
15685 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
15686 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
15687 image_create_info.flags = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060015688
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015689 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
Mike Stroyana3082432015-09-25 13:39:21 -060015690 ASSERT_VK_SUCCESS(err);
15691
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015692 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
Mike Stroyana3082432015-09-25 13:39:21 -060015693 ASSERT_VK_SUCCESS(err);
15694
15695 // Allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015696 VkMemoryAllocateInfo memAlloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -070015697 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
15698 memAlloc.pNext = NULL;
15699 memAlloc.allocationSize = 0;
15700 memAlloc.memoryTypeIndex = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060015701
Courtney Goeltzenleuchter06d89472015-10-20 16:40:38 -060015702 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060015703 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015704 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060015705 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015706 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
Mike Stroyana3082432015-09-25 13:39:21 -060015707 ASSERT_VK_SUCCESS(err);
15708
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015709 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060015710 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015711 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Mike Stroyana3082432015-09-25 13:39:21 -060015712 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015713 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
Mike Stroyana3082432015-09-25 13:39:21 -060015714 ASSERT_VK_SUCCESS(err);
15715
15716 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
15717 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015718 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
Mike Stroyana3082432015-09-25 13:39:21 -060015719 ASSERT_VK_SUCCESS(err);
15720
15721 BeginCommandBuffer();
15722 VkImageCopy copyRegion;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080015723 copyRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060015724 copyRegion.srcSubresource.mipLevel = 0;
Courtney Goeltzenleuchter8367ce02015-10-16 09:46:00 -060015725 copyRegion.srcSubresource.baseArrayLayer = 0;
Mark Lobodzinskidb117632016-03-31 10:45:56 -060015726 copyRegion.srcSubresource.layerCount = 1;
Mike Stroyana3082432015-09-25 13:39:21 -060015727 copyRegion.srcOffset.x = 0;
15728 copyRegion.srcOffset.y = 0;
15729 copyRegion.srcOffset.z = 0;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080015730 copyRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015731 copyRegion.dstSubresource.mipLevel = 0;
15732 copyRegion.dstSubresource.baseArrayLayer = 0;
Mark Lobodzinskidb117632016-03-31 10:45:56 -060015733 // Introduce failure by forcing the dst layerCount to differ from src
15734 copyRegion.dstSubresource.layerCount = 3;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015735 copyRegion.dstOffset.x = 0;
15736 copyRegion.dstOffset.y = 0;
15737 copyRegion.dstOffset.z = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060015738 copyRegion.extent.width = 1;
15739 copyRegion.extent.height = 1;
15740 copyRegion.extent.depth = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015741 m_commandBuffer->CopyImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, VK_IMAGE_LAYOUT_GENERAL, 1, &copyRegion);
Mike Stroyana3082432015-09-25 13:39:21 -060015742 EndCommandBuffer();
15743
Chris Forbes8f36a8a2016-04-07 13:21:07 +120015744 m_errorMonitor->VerifyFound();
Mike Stroyana3082432015-09-25 13:39:21 -060015745
Chia-I Wuf7458c52015-10-26 21:10:41 +080015746 vkDestroyImage(m_device->device(), srcImage, NULL);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015747 vkDestroyImage(m_device->device(), dstImage, NULL);
Chia-I Wuf7458c52015-10-26 21:10:41 +080015748 vkFreeMemory(m_device->device(), srcMem, NULL);
15749 vkFreeMemory(m_device->device(), destMem, NULL);
Mike Stroyana3082432015-09-25 13:39:21 -060015750}
15751
Tony Barbourd6673642016-05-05 14:46:39 -060015752TEST_F(VkLayerTest, ImageLayerUnsupportedFormat) {
15753
15754 TEST_DESCRIPTION("Creating images with unsuported formats ");
15755
15756 ASSERT_NO_FATAL_FAILURE(InitState());
15757 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
15758 VkImageObj image(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015759 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 -060015760 VK_IMAGE_TILING_OPTIMAL, 0);
15761 ASSERT_TRUE(image.initialized());
15762
Mark Lobodzinskiba5c6862016-05-17 08:14:00 -060015763 // Create image with unsupported format - Expect FORMAT_UNSUPPORTED
15764 VkImageCreateInfo image_create_info;
15765 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
15766 image_create_info.pNext = NULL;
15767 image_create_info.imageType = VK_IMAGE_TYPE_2D;
15768 image_create_info.format = VK_FORMAT_UNDEFINED;
15769 image_create_info.extent.width = 32;
15770 image_create_info.extent.height = 32;
15771 image_create_info.extent.depth = 1;
15772 image_create_info.mipLevels = 1;
15773 image_create_info.arrayLayers = 1;
15774 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
15775 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
15776 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
15777 image_create_info.flags = 0;
15778
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015779 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
15780 "vkCreateImage: VkFormat for image must not be VK_FORMAT_UNDEFINED");
Mark Lobodzinskiba5c6862016-05-17 08:14:00 -060015781
15782 VkImage localImage;
15783 vkCreateImage(m_device->handle(), &image_create_info, NULL, &localImage);
15784 m_errorMonitor->VerifyFound();
15785
Tony Barbourd6673642016-05-05 14:46:39 -060015786 VkFormat unsupported = VK_FORMAT_UNDEFINED;
Mark Lobodzinskiba5c6862016-05-17 08:14:00 -060015787 // Look for a format that is COMPLETELY unsupported with this hardware
Tony Barbourd6673642016-05-05 14:46:39 -060015788 for (int f = VK_FORMAT_BEGIN_RANGE; f <= VK_FORMAT_END_RANGE; f++) {
15789 VkFormat format = static_cast<VkFormat>(f);
15790 VkFormatProperties fProps = m_device->format_properties(format);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015791 if (format != VK_FORMAT_UNDEFINED && fProps.linearTilingFeatures == 0 && fProps.optimalTilingFeatures == 0) {
Tony Barbourd6673642016-05-05 14:46:39 -060015792 unsupported = format;
15793 break;
15794 }
15795 }
Mark Lobodzinskiba5c6862016-05-17 08:14:00 -060015796
Tony Barbourd6673642016-05-05 14:46:39 -060015797 if (unsupported != VK_FORMAT_UNDEFINED) {
Tony Barbourd6673642016-05-05 14:46:39 -060015798 image_create_info.format = unsupported;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015799 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "is an unsupported format");
Tony Barbourd6673642016-05-05 14:46:39 -060015800
Mark Lobodzinskiba5c6862016-05-17 08:14:00 -060015801 vkCreateImage(m_device->handle(), &image_create_info, NULL, &localImage);
Tony Barbourd6673642016-05-05 14:46:39 -060015802 m_errorMonitor->VerifyFound();
15803 }
15804}
15805
15806TEST_F(VkLayerTest, ImageLayerViewTests) {
15807 VkResult ret;
15808 TEST_DESCRIPTION("Passing bad parameters to CreateImageView");
15809
15810 ASSERT_NO_FATAL_FAILURE(InitState());
15811
15812 VkImageObj image(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015813 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 -060015814 VK_IMAGE_TILING_OPTIMAL, 0);
15815 ASSERT_TRUE(image.initialized());
15816
15817 VkImageView imgView;
15818 VkImageViewCreateInfo imgViewInfo = {};
15819 imgViewInfo.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
15820 imgViewInfo.image = image.handle();
15821 imgViewInfo.viewType = VK_IMAGE_VIEW_TYPE_2D;
15822 imgViewInfo.format = VK_FORMAT_B8G8R8A8_UNORM;
15823 imgViewInfo.subresourceRange.layerCount = 1;
15824 imgViewInfo.subresourceRange.baseMipLevel = 0;
15825 imgViewInfo.subresourceRange.levelCount = 1;
15826 imgViewInfo.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
15827
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015828 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "vkCreateImageView called with baseMipLevel");
Tony Barbourd6673642016-05-05 14:46:39 -060015829 // View can't have baseMipLevel >= image's mipLevels - Expect
15830 // VIEW_CREATE_ERROR
15831 imgViewInfo.subresourceRange.baseMipLevel = 1;
15832 vkCreateImageView(m_device->handle(), &imgViewInfo, NULL, &imgView);
15833 m_errorMonitor->VerifyFound();
15834 imgViewInfo.subresourceRange.baseMipLevel = 0;
15835
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015836 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "vkCreateImageView called with baseArrayLayer");
Tony Barbourd6673642016-05-05 14:46:39 -060015837 // View can't have baseArrayLayer >= image's arraySize - Expect
15838 // VIEW_CREATE_ERROR
15839 imgViewInfo.subresourceRange.baseArrayLayer = 1;
15840 vkCreateImageView(m_device->handle(), &imgViewInfo, NULL, &imgView);
15841 m_errorMonitor->VerifyFound();
15842 imgViewInfo.subresourceRange.baseArrayLayer = 0;
15843
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015844 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "vkCreateImageView called with 0 in "
15845 "pCreateInfo->subresourceRange."
15846 "levelCount");
Tony Barbourd6673642016-05-05 14:46:39 -060015847 // View's levelCount can't be 0 - Expect VIEW_CREATE_ERROR
15848 imgViewInfo.subresourceRange.levelCount = 0;
15849 vkCreateImageView(m_device->handle(), &imgViewInfo, NULL, &imgView);
15850 m_errorMonitor->VerifyFound();
15851 imgViewInfo.subresourceRange.levelCount = 1;
15852
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015853 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "vkCreateImageView called with 0 in "
15854 "pCreateInfo->subresourceRange."
15855 "layerCount");
Tony Barbourd6673642016-05-05 14:46:39 -060015856 // View's layerCount can't be 0 - Expect VIEW_CREATE_ERROR
15857 imgViewInfo.subresourceRange.layerCount = 0;
15858 vkCreateImageView(m_device->handle(), &imgViewInfo, NULL, &imgView);
15859 m_errorMonitor->VerifyFound();
15860 imgViewInfo.subresourceRange.layerCount = 1;
15861
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015862 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "but both must be color formats");
Tony Barbourd6673642016-05-05 14:46:39 -060015863 // Can't use depth format for view into color image - Expect INVALID_FORMAT
15864 imgViewInfo.format = VK_FORMAT_D24_UNORM_S8_UINT;
15865 vkCreateImageView(m_device->handle(), &imgViewInfo, NULL, &imgView);
15866 m_errorMonitor->VerifyFound();
15867 imgViewInfo.format = VK_FORMAT_B8G8R8A8_UNORM;
15868
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015869 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Formats MUST be IDENTICAL unless "
15870 "VK_IMAGE_CREATE_MUTABLE_FORMAT BIT "
15871 "was set on image creation.");
Tony Barbourd6673642016-05-05 14:46:39 -060015872 // Same compatibility class but no MUTABLE_FORMAT bit - Expect
15873 // VIEW_CREATE_ERROR
15874 imgViewInfo.format = VK_FORMAT_B8G8R8A8_UINT;
15875 vkCreateImageView(m_device->handle(), &imgViewInfo, NULL, &imgView);
15876 m_errorMonitor->VerifyFound();
15877 imgViewInfo.format = VK_FORMAT_B8G8R8A8_UNORM;
15878
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015879 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "can support ImageViews with "
15880 "differing formats but they must be "
15881 "in the same compatibility class.");
Tony Barbourd6673642016-05-05 14:46:39 -060015882 // Have MUTABLE_FORMAT bit but not in same compatibility class - Expect
15883 // VIEW_CREATE_ERROR
15884 VkImageCreateInfo mutImgInfo = image.create_info();
15885 VkImage mutImage;
15886 mutImgInfo.format = VK_FORMAT_R8_UINT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015887 assert(m_device->format_properties(VK_FORMAT_R8_UINT).optimalTilingFeatures & VK_FORMAT_FEATURE_COLOR_ATTACHMENT_BIT);
Tony Barbourd6673642016-05-05 14:46:39 -060015888 mutImgInfo.flags = VK_IMAGE_CREATE_MUTABLE_FORMAT_BIT;
15889 mutImgInfo.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
15890 ret = vkCreateImage(m_device->handle(), &mutImgInfo, NULL, &mutImage);
15891 ASSERT_VK_SUCCESS(ret);
15892 imgViewInfo.image = mutImage;
15893 vkCreateImageView(m_device->handle(), &imgViewInfo, NULL, &imgView);
15894 m_errorMonitor->VerifyFound();
15895 imgViewInfo.image = image.handle();
15896 vkDestroyImage(m_device->handle(), mutImage, NULL);
15897}
15898
15899TEST_F(VkLayerTest, MiscImageLayerTests) {
15900
15901 TEST_DESCRIPTION("Image layer tests that don't belong elsewhare");
15902
15903 ASSERT_NO_FATAL_FAILURE(InitState());
15904
15905 VkImageObj image(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015906 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 -060015907 VK_IMAGE_TILING_OPTIMAL, 0);
15908 ASSERT_TRUE(image.initialized());
15909
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015910 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "number of layers in image subresource is zero");
Tony Barbourd6673642016-05-05 14:46:39 -060015911 vk_testing::Buffer buffer;
15912 VkMemoryPropertyFlags reqs = 0;
15913 buffer.init_as_src(*m_device, 128 * 128 * 4, reqs);
15914 VkBufferImageCopy region = {};
15915 region.bufferRowLength = 128;
15916 region.bufferImageHeight = 128;
15917 region.imageSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
15918 // layerCount can't be 0 - Expect MISMATCHED_IMAGE_ASPECT
15919 region.imageSubresource.layerCount = 0;
15920 region.imageExtent.height = 4;
15921 region.imageExtent.width = 4;
15922 region.imageExtent.depth = 1;
15923 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015924 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer.handle(), image.handle(),
15925 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, &region);
Tony Barbourd6673642016-05-05 14:46:39 -060015926 m_errorMonitor->VerifyFound();
15927 region.imageSubresource.layerCount = 1;
15928
Mark Lobodzinski7d8cf142016-08-19 10:53:26 -060015929 // BufferOffset must be a multiple of the calling command's VkImage parameter's texel size
15930 // Introduce failure by setting bufferOffset to 1 and 1/2 texels
15931 region.bufferOffset = 6;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015932 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "must be a multiple of this format's texel size");
15933 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer.handle(), image.handle(),
15934 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, &region);
Mark Lobodzinski7d8cf142016-08-19 10:53:26 -060015935 m_errorMonitor->VerifyFound();
15936
15937 // BufferOffset must be a multiple of 4
15938 // Introduce failure by setting bufferOffset to a value not divisible by 4
15939 region.bufferOffset = 6;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015940 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "must be a multiple of 4");
15941 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer.handle(), image.handle(),
15942 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, &region);
Mark Lobodzinski7d8cf142016-08-19 10:53:26 -060015943 m_errorMonitor->VerifyFound();
15944
15945 // BufferRowLength must be 0, or greater than or equal to the width member of imageExtent
15946 region.bufferOffset = 0;
15947 region.imageExtent.height = 128;
15948 region.imageExtent.width = 128;
15949 // Introduce failure by setting bufferRowLength > 0 but less than width
15950 region.bufferRowLength = 64;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015951 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
15952 "must be zero or greater-than-or-equal-to imageExtent.width");
15953 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer.handle(), image.handle(),
15954 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, &region);
Mark Lobodzinski7d8cf142016-08-19 10:53:26 -060015955 m_errorMonitor->VerifyFound();
15956
15957 // BufferImageHeight must be 0, or greater than or equal to the height member of imageExtent
15958 region.bufferRowLength = 128;
15959 // Introduce failure by setting bufferRowHeight > 0 but less than height
15960 region.bufferImageHeight = 64;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015961 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
15962 "must be zero or greater-than-or-equal-to imageExtent.height");
15963 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer.handle(), image.handle(),
15964 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, &region);
Mark Lobodzinski7d8cf142016-08-19 10:53:26 -060015965 m_errorMonitor->VerifyFound();
15966
15967 region.bufferImageHeight = 128;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015968 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "aspectMasks for each region must "
15969 "specify only COLOR or DEPTH or "
15970 "STENCIL");
Tony Barbourd6673642016-05-05 14:46:39 -060015971 // Expect MISMATCHED_IMAGE_ASPECT
15972 region.imageSubresource.aspectMask = VK_IMAGE_ASPECT_METADATA_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015973 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer.handle(), image.handle(),
15974 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, &region);
Tony Barbourd6673642016-05-05 14:46:39 -060015975 m_errorMonitor->VerifyFound();
15976 region.imageSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
15977
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015978 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
15979 "If the format of srcImage is a depth, stencil, depth stencil or "
15980 "integer-based format then filter must be VK_FILTER_NEAREST");
Tony Barbourd6673642016-05-05 14:46:39 -060015981 // Expect INVALID_FILTER
15982 VkImageObj intImage1(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015983 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 -060015984 VkImageObj intImage2(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015985 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 -060015986 VkImageBlit blitRegion = {};
15987 blitRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
15988 blitRegion.srcSubresource.baseArrayLayer = 0;
15989 blitRegion.srcSubresource.layerCount = 1;
15990 blitRegion.srcSubresource.mipLevel = 0;
15991 blitRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
15992 blitRegion.dstSubresource.baseArrayLayer = 0;
15993 blitRegion.dstSubresource.layerCount = 1;
15994 blitRegion.dstSubresource.mipLevel = 0;
15995
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015996 vkCmdBlitImage(m_commandBuffer->GetBufferHandle(), intImage1.handle(), intImage1.layout(), intImage2.handle(),
15997 intImage2.layout(), 16, &blitRegion, VK_FILTER_LINEAR);
Tony Barbourd6673642016-05-05 14:46:39 -060015998 m_errorMonitor->VerifyFound();
15999
Mark Lobodzinskib02ea642016-08-17 13:03:57 -060016000 // Look for NULL-blit warning
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016001 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT, "Offsets specify a zero-volume area.");
16002 vkCmdBlitImage(m_commandBuffer->GetBufferHandle(), intImage1.handle(), intImage1.layout(), intImage2.handle(),
16003 intImage2.layout(), 1, &blitRegion, VK_FILTER_LINEAR);
Mark Lobodzinskib02ea642016-08-17 13:03:57 -060016004 m_errorMonitor->VerifyFound();
16005
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016006 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "called with 0 in ppMemoryBarriers");
Tony Barbourd6673642016-05-05 14:46:39 -060016007 VkImageMemoryBarrier img_barrier;
16008 img_barrier.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
16009 img_barrier.pNext = NULL;
16010 img_barrier.srcAccessMask = VK_ACCESS_HOST_WRITE_BIT;
16011 img_barrier.dstAccessMask = VK_ACCESS_SHADER_READ_BIT;
16012 img_barrier.oldLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
16013 img_barrier.newLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
16014 img_barrier.image = image.handle();
16015 img_barrier.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
16016 img_barrier.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
16017 img_barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
16018 img_barrier.subresourceRange.baseArrayLayer = 0;
16019 img_barrier.subresourceRange.baseMipLevel = 0;
16020 // layerCount should not be 0 - Expect INVALID_IMAGE_RESOURCE
16021 img_barrier.subresourceRange.layerCount = 0;
16022 img_barrier.subresourceRange.levelCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016023 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
16024 nullptr, 0, nullptr, 1, &img_barrier);
Tony Barbourd6673642016-05-05 14:46:39 -060016025 m_errorMonitor->VerifyFound();
16026 img_barrier.subresourceRange.layerCount = 1;
16027}
16028
16029TEST_F(VkLayerTest, ImageFormatLimits) {
16030
16031 TEST_DESCRIPTION("Exceed the limits of image format ");
16032
Cody Northropc31a84f2016-08-22 10:41:47 -060016033 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016034 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "CreateImage extents exceed allowable limits for format");
Tony Barbourd6673642016-05-05 14:46:39 -060016035 VkImageCreateInfo image_create_info = {};
16036 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
16037 image_create_info.pNext = NULL;
16038 image_create_info.imageType = VK_IMAGE_TYPE_2D;
16039 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
16040 image_create_info.extent.width = 32;
16041 image_create_info.extent.height = 32;
16042 image_create_info.extent.depth = 1;
16043 image_create_info.mipLevels = 1;
16044 image_create_info.arrayLayers = 1;
16045 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
16046 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
16047 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
16048 image_create_info.initialLayout = VK_IMAGE_LAYOUT_UNDEFINED;
16049 image_create_info.flags = 0;
16050
16051 VkImage nullImg;
16052 VkImageFormatProperties imgFmtProps;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016053 vkGetPhysicalDeviceImageFormatProperties(gpu(), image_create_info.format, image_create_info.imageType, image_create_info.tiling,
16054 image_create_info.usage, image_create_info.flags, &imgFmtProps);
Tony Barbourd6673642016-05-05 14:46:39 -060016055 image_create_info.extent.depth = imgFmtProps.maxExtent.depth + 1;
16056 // Expect INVALID_FORMAT_LIMITS_VIOLATION
16057 vkCreateImage(m_device->handle(), &image_create_info, NULL, &nullImg);
16058 m_errorMonitor->VerifyFound();
16059 image_create_info.extent.depth = 1;
16060
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016061 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "exceeds allowable maximum supported by format of");
Tony Barbourd6673642016-05-05 14:46:39 -060016062 image_create_info.mipLevels = imgFmtProps.maxMipLevels + 1;
16063 // Expect INVALID_FORMAT_LIMITS_VIOLATION
16064 vkCreateImage(m_device->handle(), &image_create_info, NULL, &nullImg);
16065 m_errorMonitor->VerifyFound();
16066 image_create_info.mipLevels = 1;
16067
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016068 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "exceeds allowable maximum supported by format of");
Tony Barbourd6673642016-05-05 14:46:39 -060016069 image_create_info.arrayLayers = imgFmtProps.maxArrayLayers + 1;
16070 // Expect INVALID_FORMAT_LIMITS_VIOLATION
16071 vkCreateImage(m_device->handle(), &image_create_info, NULL, &nullImg);
16072 m_errorMonitor->VerifyFound();
16073 image_create_info.arrayLayers = 1;
16074
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016075 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "is not supported by format");
Tony Barbourd6673642016-05-05 14:46:39 -060016076 int samples = imgFmtProps.sampleCounts >> 1;
16077 image_create_info.samples = (VkSampleCountFlagBits)samples;
16078 // Expect INVALID_FORMAT_LIMITS_VIOLATION
16079 vkCreateImage(m_device->handle(), &image_create_info, NULL, &nullImg);
16080 m_errorMonitor->VerifyFound();
16081 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
16082
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016083 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "pCreateInfo->initialLayout, must be "
16084 "VK_IMAGE_LAYOUT_UNDEFINED or "
16085 "VK_IMAGE_LAYOUT_PREINITIALIZED");
Tony Barbourd6673642016-05-05 14:46:39 -060016086 image_create_info.initialLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
16087 // Expect INVALID_LAYOUT
16088 vkCreateImage(m_device->handle(), &image_create_info, NULL, &nullImg);
16089 m_errorMonitor->VerifyFound();
16090 image_create_info.initialLayout = VK_IMAGE_LAYOUT_UNDEFINED;
16091}
16092
Karl Schultz6addd812016-02-02 17:17:23 -070016093TEST_F(VkLayerTest, CopyImageFormatSizeMismatch) {
Karl Schultzbdb75952016-04-19 11:36:49 -060016094 VkResult err;
16095 bool pass;
16096
16097 // Create color images with different format sizes and try to copy between them
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016098 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
16099 "vkCmdCopyImage called with unmatched source and dest image format sizes");
Karl Schultzbdb75952016-04-19 11:36:49 -060016100
16101 ASSERT_NO_FATAL_FAILURE(InitState());
16102
16103 // Create two images of different types and try to copy between them
16104 VkImage srcImage;
16105 VkImage dstImage;
16106 VkDeviceMemory srcMem;
16107 VkDeviceMemory destMem;
16108 VkMemoryRequirements memReqs;
16109
16110 VkImageCreateInfo image_create_info = {};
16111 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
16112 image_create_info.pNext = NULL;
16113 image_create_info.imageType = VK_IMAGE_TYPE_2D;
16114 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
16115 image_create_info.extent.width = 32;
16116 image_create_info.extent.height = 32;
16117 image_create_info.extent.depth = 1;
16118 image_create_info.mipLevels = 1;
16119 image_create_info.arrayLayers = 1;
16120 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
16121 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
16122 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
16123 image_create_info.flags = 0;
16124
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016125 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
Karl Schultzbdb75952016-04-19 11:36:49 -060016126 ASSERT_VK_SUCCESS(err);
16127
16128 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT;
16129 // Introduce failure by creating second image with a different-sized format.
16130 image_create_info.format = VK_FORMAT_R5G5B5A1_UNORM_PACK16;
16131
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016132 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
Karl Schultzbdb75952016-04-19 11:36:49 -060016133 ASSERT_VK_SUCCESS(err);
16134
16135 // Allocate memory
16136 VkMemoryAllocateInfo memAlloc = {};
16137 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
16138 memAlloc.pNext = NULL;
16139 memAlloc.allocationSize = 0;
16140 memAlloc.memoryTypeIndex = 0;
16141
16142 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
16143 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016144 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Karl Schultzbdb75952016-04-19 11:36:49 -060016145 ASSERT_TRUE(pass);
16146 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
16147 ASSERT_VK_SUCCESS(err);
16148
16149 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
16150 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016151 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Karl Schultzbdb75952016-04-19 11:36:49 -060016152 ASSERT_TRUE(pass);
16153 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
16154 ASSERT_VK_SUCCESS(err);
16155
16156 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
16157 ASSERT_VK_SUCCESS(err);
16158 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
16159 ASSERT_VK_SUCCESS(err);
16160
16161 BeginCommandBuffer();
16162 VkImageCopy copyRegion;
16163 copyRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
16164 copyRegion.srcSubresource.mipLevel = 0;
16165 copyRegion.srcSubresource.baseArrayLayer = 0;
16166 copyRegion.srcSubresource.layerCount = 0;
16167 copyRegion.srcOffset.x = 0;
16168 copyRegion.srcOffset.y = 0;
16169 copyRegion.srcOffset.z = 0;
16170 copyRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
16171 copyRegion.dstSubresource.mipLevel = 0;
16172 copyRegion.dstSubresource.baseArrayLayer = 0;
16173 copyRegion.dstSubresource.layerCount = 0;
16174 copyRegion.dstOffset.x = 0;
16175 copyRegion.dstOffset.y = 0;
16176 copyRegion.dstOffset.z = 0;
16177 copyRegion.extent.width = 1;
16178 copyRegion.extent.height = 1;
16179 copyRegion.extent.depth = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016180 m_commandBuffer->CopyImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, VK_IMAGE_LAYOUT_GENERAL, 1, &copyRegion);
Karl Schultzbdb75952016-04-19 11:36:49 -060016181 EndCommandBuffer();
16182
16183 m_errorMonitor->VerifyFound();
16184
16185 vkDestroyImage(m_device->device(), srcImage, NULL);
16186 vkDestroyImage(m_device->device(), dstImage, NULL);
16187 vkFreeMemory(m_device->device(), srcMem, NULL);
16188 vkFreeMemory(m_device->device(), destMem, NULL);
Mike Stroyana3082432015-09-25 13:39:21 -060016189}
16190
Karl Schultz6addd812016-02-02 17:17:23 -070016191TEST_F(VkLayerTest, CopyImageDepthStencilFormatMismatch) {
16192 VkResult err;
16193 bool pass;
Mike Stroyana3082432015-09-25 13:39:21 -060016194
Mark Lobodzinskidb117632016-03-31 10:45:56 -060016195 // Create a color image and a depth/stencil image and try to copy between them
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016196 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
16197 "vkCmdCopyImage called with unmatched source and dest image depth");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060016198
Mike Stroyana3082432015-09-25 13:39:21 -060016199 ASSERT_NO_FATAL_FAILURE(InitState());
Mike Stroyana3082432015-09-25 13:39:21 -060016200
16201 // Create two images of different types and try to copy between them
Karl Schultz6addd812016-02-02 17:17:23 -070016202 VkImage srcImage;
16203 VkImage dstImage;
16204 VkDeviceMemory srcMem;
16205 VkDeviceMemory destMem;
16206 VkMemoryRequirements memReqs;
Mike Stroyana3082432015-09-25 13:39:21 -060016207
16208 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070016209 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
16210 image_create_info.pNext = NULL;
16211 image_create_info.imageType = VK_IMAGE_TYPE_2D;
16212 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
16213 image_create_info.extent.width = 32;
16214 image_create_info.extent.height = 32;
16215 image_create_info.extent.depth = 1;
16216 image_create_info.mipLevels = 1;
16217 image_create_info.arrayLayers = 1;
16218 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
16219 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
16220 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
16221 image_create_info.flags = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060016222
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016223 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
Mike Stroyana3082432015-09-25 13:39:21 -060016224 ASSERT_VK_SUCCESS(err);
16225
Karl Schultzbdb75952016-04-19 11:36:49 -060016226 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT;
16227
Mark Lobodzinskidb117632016-03-31 10:45:56 -060016228 // Introduce failure by creating second image with a depth/stencil format
Karl Schultz6addd812016-02-02 17:17:23 -070016229 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
Mark Lobodzinskidb117632016-03-31 10:45:56 -060016230 image_create_info.format = VK_FORMAT_D24_UNORM_S8_UINT;
16231 image_create_info.usage = VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060016232
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016233 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
Mike Stroyana3082432015-09-25 13:39:21 -060016234 ASSERT_VK_SUCCESS(err);
16235
16236 // Allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016237 VkMemoryAllocateInfo memAlloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -070016238 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
16239 memAlloc.pNext = NULL;
16240 memAlloc.allocationSize = 0;
16241 memAlloc.memoryTypeIndex = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060016242
Courtney Goeltzenleuchter06d89472015-10-20 16:40:38 -060016243 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060016244 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016245 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060016246 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016247 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
Mike Stroyana3082432015-09-25 13:39:21 -060016248 ASSERT_VK_SUCCESS(err);
16249
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016250 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060016251 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016252 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060016253 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016254 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
Mike Stroyana3082432015-09-25 13:39:21 -060016255 ASSERT_VK_SUCCESS(err);
16256
16257 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
16258 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016259 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
Mike Stroyana3082432015-09-25 13:39:21 -060016260 ASSERT_VK_SUCCESS(err);
16261
16262 BeginCommandBuffer();
16263 VkImageCopy copyRegion;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080016264 copyRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060016265 copyRegion.srcSubresource.mipLevel = 0;
Courtney Goeltzenleuchter8367ce02015-10-16 09:46:00 -060016266 copyRegion.srcSubresource.baseArrayLayer = 0;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016267 copyRegion.srcSubresource.layerCount = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060016268 copyRegion.srcOffset.x = 0;
16269 copyRegion.srcOffset.y = 0;
16270 copyRegion.srcOffset.z = 0;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080016271 copyRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016272 copyRegion.dstSubresource.mipLevel = 0;
16273 copyRegion.dstSubresource.baseArrayLayer = 0;
16274 copyRegion.dstSubresource.layerCount = 0;
16275 copyRegion.dstOffset.x = 0;
16276 copyRegion.dstOffset.y = 0;
16277 copyRegion.dstOffset.z = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060016278 copyRegion.extent.width = 1;
16279 copyRegion.extent.height = 1;
16280 copyRegion.extent.depth = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016281 m_commandBuffer->CopyImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, VK_IMAGE_LAYOUT_GENERAL, 1, &copyRegion);
Mike Stroyana3082432015-09-25 13:39:21 -060016282 EndCommandBuffer();
16283
Chris Forbes8f36a8a2016-04-07 13:21:07 +120016284 m_errorMonitor->VerifyFound();
Mike Stroyana3082432015-09-25 13:39:21 -060016285
Chia-I Wuf7458c52015-10-26 21:10:41 +080016286 vkDestroyImage(m_device->device(), srcImage, NULL);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016287 vkDestroyImage(m_device->device(), dstImage, NULL);
Chia-I Wuf7458c52015-10-26 21:10:41 +080016288 vkFreeMemory(m_device->device(), srcMem, NULL);
16289 vkFreeMemory(m_device->device(), destMem, NULL);
Mike Stroyana3082432015-09-25 13:39:21 -060016290}
16291
Karl Schultz6addd812016-02-02 17:17:23 -070016292TEST_F(VkLayerTest, ResolveImageLowSampleCount) {
16293 VkResult err;
16294 bool pass;
Mike Stroyana3082432015-09-25 13:39:21 -060016295
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016296 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
16297 "vkCmdResolveImage called with source sample count less than 2.");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060016298
Mike Stroyana3082432015-09-25 13:39:21 -060016299 ASSERT_NO_FATAL_FAILURE(InitState());
Mike Stroyana3082432015-09-25 13:39:21 -060016300
16301 // Create two images of sample count 1 and try to Resolve between them
Karl Schultz6addd812016-02-02 17:17:23 -070016302 VkImage srcImage;
16303 VkImage dstImage;
16304 VkDeviceMemory srcMem;
16305 VkDeviceMemory destMem;
16306 VkMemoryRequirements memReqs;
Mike Stroyana3082432015-09-25 13:39:21 -060016307
16308 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070016309 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
16310 image_create_info.pNext = NULL;
16311 image_create_info.imageType = VK_IMAGE_TYPE_2D;
16312 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
16313 image_create_info.extent.width = 32;
16314 image_create_info.extent.height = 1;
16315 image_create_info.extent.depth = 1;
16316 image_create_info.mipLevels = 1;
16317 image_create_info.arrayLayers = 1;
16318 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
16319 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
16320 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
16321 image_create_info.flags = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060016322
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016323 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
Mike Stroyana3082432015-09-25 13:39:21 -060016324 ASSERT_VK_SUCCESS(err);
16325
Karl Schultz6addd812016-02-02 17:17:23 -070016326 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060016327
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016328 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
Mike Stroyana3082432015-09-25 13:39:21 -060016329 ASSERT_VK_SUCCESS(err);
16330
16331 // Allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016332 VkMemoryAllocateInfo memAlloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -070016333 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
16334 memAlloc.pNext = NULL;
16335 memAlloc.allocationSize = 0;
16336 memAlloc.memoryTypeIndex = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060016337
Courtney Goeltzenleuchter06d89472015-10-20 16:40:38 -060016338 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060016339 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016340 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060016341 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016342 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
Mike Stroyana3082432015-09-25 13:39:21 -060016343 ASSERT_VK_SUCCESS(err);
16344
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016345 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060016346 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016347 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060016348 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016349 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
Mike Stroyana3082432015-09-25 13:39:21 -060016350 ASSERT_VK_SUCCESS(err);
16351
16352 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
16353 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016354 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
Mike Stroyana3082432015-09-25 13:39:21 -060016355 ASSERT_VK_SUCCESS(err);
16356
16357 BeginCommandBuffer();
16358 // Need memory barrier to VK_IMAGE_LAYOUT_GENERAL for source and dest?
Karl Schultz6addd812016-02-02 17:17:23 -070016359 // VK_IMAGE_LAYOUT_UNDEFINED = 0,
16360 // VK_IMAGE_LAYOUT_GENERAL = 1,
Mike Stroyana3082432015-09-25 13:39:21 -060016361 VkImageResolve resolveRegion;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080016362 resolveRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060016363 resolveRegion.srcSubresource.mipLevel = 0;
Courtney Goeltzenleuchter8367ce02015-10-16 09:46:00 -060016364 resolveRegion.srcSubresource.baseArrayLayer = 0;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016365 resolveRegion.srcSubresource.layerCount = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060016366 resolveRegion.srcOffset.x = 0;
16367 resolveRegion.srcOffset.y = 0;
16368 resolveRegion.srcOffset.z = 0;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080016369 resolveRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016370 resolveRegion.dstSubresource.mipLevel = 0;
16371 resolveRegion.dstSubresource.baseArrayLayer = 0;
16372 resolveRegion.dstSubresource.layerCount = 0;
16373 resolveRegion.dstOffset.x = 0;
16374 resolveRegion.dstOffset.y = 0;
16375 resolveRegion.dstOffset.z = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060016376 resolveRegion.extent.width = 1;
16377 resolveRegion.extent.height = 1;
16378 resolveRegion.extent.depth = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016379 m_commandBuffer->ResolveImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, VK_IMAGE_LAYOUT_GENERAL, 1, &resolveRegion);
Mike Stroyana3082432015-09-25 13:39:21 -060016380 EndCommandBuffer();
16381
Chris Forbes8f36a8a2016-04-07 13:21:07 +120016382 m_errorMonitor->VerifyFound();
Mike Stroyana3082432015-09-25 13:39:21 -060016383
Chia-I Wuf7458c52015-10-26 21:10:41 +080016384 vkDestroyImage(m_device->device(), srcImage, NULL);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016385 vkDestroyImage(m_device->device(), dstImage, NULL);
Chia-I Wuf7458c52015-10-26 21:10:41 +080016386 vkFreeMemory(m_device->device(), srcMem, NULL);
16387 vkFreeMemory(m_device->device(), destMem, NULL);
Mike Stroyana3082432015-09-25 13:39:21 -060016388}
16389
Karl Schultz6addd812016-02-02 17:17:23 -070016390TEST_F(VkLayerTest, ResolveImageHighSampleCount) {
16391 VkResult err;
16392 bool pass;
Mike Stroyana3082432015-09-25 13:39:21 -060016393
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016394 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
16395 "vkCmdResolveImage called with dest sample count greater than 1.");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060016396
Mike Stroyana3082432015-09-25 13:39:21 -060016397 ASSERT_NO_FATAL_FAILURE(InitState());
Mike Stroyana3082432015-09-25 13:39:21 -060016398
Chris Forbesa7530692016-05-08 12:35:39 +120016399 // Create two images of sample count 4 and try to Resolve between them
Karl Schultz6addd812016-02-02 17:17:23 -070016400 VkImage srcImage;
16401 VkImage dstImage;
16402 VkDeviceMemory srcMem;
16403 VkDeviceMemory destMem;
16404 VkMemoryRequirements memReqs;
Mike Stroyana3082432015-09-25 13:39:21 -060016405
16406 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070016407 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
16408 image_create_info.pNext = NULL;
16409 image_create_info.imageType = VK_IMAGE_TYPE_2D;
16410 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
16411 image_create_info.extent.width = 32;
16412 image_create_info.extent.height = 1;
16413 image_create_info.extent.depth = 1;
16414 image_create_info.mipLevels = 1;
16415 image_create_info.arrayLayers = 1;
Chris Forbesa7530692016-05-08 12:35:39 +120016416 image_create_info.samples = VK_SAMPLE_COUNT_4_BIT;
Karl Schultz6addd812016-02-02 17:17:23 -070016417 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
16418 // Note: Some implementations expect color attachment usage for any
16419 // multisample surface
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016420 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
Karl Schultz6addd812016-02-02 17:17:23 -070016421 image_create_info.flags = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060016422
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016423 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
Mike Stroyana3082432015-09-25 13:39:21 -060016424 ASSERT_VK_SUCCESS(err);
16425
Karl Schultz6addd812016-02-02 17:17:23 -070016426 // Note: Some implementations expect color attachment usage for any
16427 // multisample surface
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016428 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060016429
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016430 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
Mike Stroyana3082432015-09-25 13:39:21 -060016431 ASSERT_VK_SUCCESS(err);
16432
16433 // Allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016434 VkMemoryAllocateInfo memAlloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -070016435 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
16436 memAlloc.pNext = NULL;
16437 memAlloc.allocationSize = 0;
16438 memAlloc.memoryTypeIndex = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060016439
Courtney Goeltzenleuchter06d89472015-10-20 16:40:38 -060016440 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060016441 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016442 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060016443 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016444 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
Mike Stroyana3082432015-09-25 13:39:21 -060016445 ASSERT_VK_SUCCESS(err);
16446
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016447 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060016448 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016449 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060016450 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016451 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
Mike Stroyana3082432015-09-25 13:39:21 -060016452 ASSERT_VK_SUCCESS(err);
16453
16454 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
16455 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016456 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
Mike Stroyana3082432015-09-25 13:39:21 -060016457 ASSERT_VK_SUCCESS(err);
16458
16459 BeginCommandBuffer();
16460 // Need memory barrier to VK_IMAGE_LAYOUT_GENERAL for source and dest?
Karl Schultz6addd812016-02-02 17:17:23 -070016461 // VK_IMAGE_LAYOUT_UNDEFINED = 0,
16462 // VK_IMAGE_LAYOUT_GENERAL = 1,
Mike Stroyana3082432015-09-25 13:39:21 -060016463 VkImageResolve resolveRegion;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080016464 resolveRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060016465 resolveRegion.srcSubresource.mipLevel = 0;
Courtney Goeltzenleuchter8367ce02015-10-16 09:46:00 -060016466 resolveRegion.srcSubresource.baseArrayLayer = 0;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016467 resolveRegion.srcSubresource.layerCount = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060016468 resolveRegion.srcOffset.x = 0;
16469 resolveRegion.srcOffset.y = 0;
16470 resolveRegion.srcOffset.z = 0;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080016471 resolveRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016472 resolveRegion.dstSubresource.mipLevel = 0;
16473 resolveRegion.dstSubresource.baseArrayLayer = 0;
16474 resolveRegion.dstSubresource.layerCount = 0;
16475 resolveRegion.dstOffset.x = 0;
16476 resolveRegion.dstOffset.y = 0;
16477 resolveRegion.dstOffset.z = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060016478 resolveRegion.extent.width = 1;
16479 resolveRegion.extent.height = 1;
16480 resolveRegion.extent.depth = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016481 m_commandBuffer->ResolveImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, VK_IMAGE_LAYOUT_GENERAL, 1, &resolveRegion);
Mike Stroyana3082432015-09-25 13:39:21 -060016482 EndCommandBuffer();
16483
Chris Forbes8f36a8a2016-04-07 13:21:07 +120016484 m_errorMonitor->VerifyFound();
Mike Stroyana3082432015-09-25 13:39:21 -060016485
Chia-I Wuf7458c52015-10-26 21:10:41 +080016486 vkDestroyImage(m_device->device(), srcImage, NULL);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016487 vkDestroyImage(m_device->device(), dstImage, NULL);
Chia-I Wuf7458c52015-10-26 21:10:41 +080016488 vkFreeMemory(m_device->device(), srcMem, NULL);
16489 vkFreeMemory(m_device->device(), destMem, NULL);
Mike Stroyana3082432015-09-25 13:39:21 -060016490}
16491
Karl Schultz6addd812016-02-02 17:17:23 -070016492TEST_F(VkLayerTest, ResolveImageFormatMismatch) {
16493 VkResult err;
16494 bool pass;
Mike Stroyana3082432015-09-25 13:39:21 -060016495
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016496 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
16497 "vkCmdResolveImage called with unmatched source and dest formats.");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060016498
Mike Stroyana3082432015-09-25 13:39:21 -060016499 ASSERT_NO_FATAL_FAILURE(InitState());
Mike Stroyana3082432015-09-25 13:39:21 -060016500
16501 // Create two images of different types and try to copy between them
Karl Schultz6addd812016-02-02 17:17:23 -070016502 VkImage srcImage;
16503 VkImage dstImage;
16504 VkDeviceMemory srcMem;
16505 VkDeviceMemory destMem;
16506 VkMemoryRequirements memReqs;
Mike Stroyana3082432015-09-25 13:39:21 -060016507
16508 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070016509 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
16510 image_create_info.pNext = NULL;
16511 image_create_info.imageType = VK_IMAGE_TYPE_2D;
16512 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
16513 image_create_info.extent.width = 32;
16514 image_create_info.extent.height = 1;
16515 image_create_info.extent.depth = 1;
16516 image_create_info.mipLevels = 1;
16517 image_create_info.arrayLayers = 1;
16518 image_create_info.samples = VK_SAMPLE_COUNT_2_BIT;
16519 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
16520 // Note: Some implementations expect color attachment usage for any
16521 // multisample surface
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016522 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
Karl Schultz6addd812016-02-02 17:17:23 -070016523 image_create_info.flags = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060016524
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016525 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
Mike Stroyana3082432015-09-25 13:39:21 -060016526 ASSERT_VK_SUCCESS(err);
16527
Karl Schultz6addd812016-02-02 17:17:23 -070016528 // Set format to something other than source image
16529 image_create_info.format = VK_FORMAT_R32_SFLOAT;
16530 // Note: Some implementations expect color attachment usage for any
16531 // multisample surface
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016532 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
Karl Schultz6addd812016-02-02 17:17:23 -070016533 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060016534
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016535 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
Mike Stroyana3082432015-09-25 13:39:21 -060016536 ASSERT_VK_SUCCESS(err);
16537
16538 // Allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016539 VkMemoryAllocateInfo memAlloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -070016540 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
16541 memAlloc.pNext = NULL;
16542 memAlloc.allocationSize = 0;
16543 memAlloc.memoryTypeIndex = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060016544
Courtney Goeltzenleuchter06d89472015-10-20 16:40:38 -060016545 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060016546 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016547 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060016548 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016549 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
Mike Stroyana3082432015-09-25 13:39:21 -060016550 ASSERT_VK_SUCCESS(err);
16551
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016552 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060016553 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016554 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060016555 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016556 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
Mike Stroyana3082432015-09-25 13:39:21 -060016557 ASSERT_VK_SUCCESS(err);
16558
16559 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
16560 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016561 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
Mike Stroyana3082432015-09-25 13:39:21 -060016562 ASSERT_VK_SUCCESS(err);
16563
16564 BeginCommandBuffer();
16565 // Need memory barrier to VK_IMAGE_LAYOUT_GENERAL for source and dest?
Karl Schultz6addd812016-02-02 17:17:23 -070016566 // VK_IMAGE_LAYOUT_UNDEFINED = 0,
16567 // VK_IMAGE_LAYOUT_GENERAL = 1,
Mike Stroyana3082432015-09-25 13:39:21 -060016568 VkImageResolve resolveRegion;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080016569 resolveRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060016570 resolveRegion.srcSubresource.mipLevel = 0;
Courtney Goeltzenleuchter8367ce02015-10-16 09:46:00 -060016571 resolveRegion.srcSubresource.baseArrayLayer = 0;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016572 resolveRegion.srcSubresource.layerCount = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060016573 resolveRegion.srcOffset.x = 0;
16574 resolveRegion.srcOffset.y = 0;
16575 resolveRegion.srcOffset.z = 0;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080016576 resolveRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016577 resolveRegion.dstSubresource.mipLevel = 0;
16578 resolveRegion.dstSubresource.baseArrayLayer = 0;
16579 resolveRegion.dstSubresource.layerCount = 0;
16580 resolveRegion.dstOffset.x = 0;
16581 resolveRegion.dstOffset.y = 0;
16582 resolveRegion.dstOffset.z = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060016583 resolveRegion.extent.width = 1;
16584 resolveRegion.extent.height = 1;
16585 resolveRegion.extent.depth = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016586 m_commandBuffer->ResolveImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, VK_IMAGE_LAYOUT_GENERAL, 1, &resolveRegion);
Mike Stroyana3082432015-09-25 13:39:21 -060016587 EndCommandBuffer();
16588
Chris Forbes8f36a8a2016-04-07 13:21:07 +120016589 m_errorMonitor->VerifyFound();
Mike Stroyana3082432015-09-25 13:39:21 -060016590
Chia-I Wuf7458c52015-10-26 21:10:41 +080016591 vkDestroyImage(m_device->device(), srcImage, NULL);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016592 vkDestroyImage(m_device->device(), dstImage, NULL);
Chia-I Wuf7458c52015-10-26 21:10:41 +080016593 vkFreeMemory(m_device->device(), srcMem, NULL);
16594 vkFreeMemory(m_device->device(), destMem, NULL);
Mike Stroyana3082432015-09-25 13:39:21 -060016595}
16596
Karl Schultz6addd812016-02-02 17:17:23 -070016597TEST_F(VkLayerTest, ResolveImageTypeMismatch) {
16598 VkResult err;
16599 bool pass;
Mike Stroyana3082432015-09-25 13:39:21 -060016600
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016601 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
16602 "vkCmdResolveImage called with unmatched source and dest image types.");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060016603
Mike Stroyana3082432015-09-25 13:39:21 -060016604 ASSERT_NO_FATAL_FAILURE(InitState());
Mike Stroyana3082432015-09-25 13:39:21 -060016605
16606 // Create two images of different types and try to copy between them
Karl Schultz6addd812016-02-02 17:17:23 -070016607 VkImage srcImage;
16608 VkImage dstImage;
16609 VkDeviceMemory srcMem;
16610 VkDeviceMemory destMem;
16611 VkMemoryRequirements memReqs;
Mike Stroyana3082432015-09-25 13:39:21 -060016612
16613 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070016614 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
16615 image_create_info.pNext = NULL;
16616 image_create_info.imageType = VK_IMAGE_TYPE_2D;
16617 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
16618 image_create_info.extent.width = 32;
16619 image_create_info.extent.height = 1;
16620 image_create_info.extent.depth = 1;
16621 image_create_info.mipLevels = 1;
16622 image_create_info.arrayLayers = 1;
16623 image_create_info.samples = VK_SAMPLE_COUNT_2_BIT;
16624 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
16625 // Note: Some implementations expect color attachment usage for any
16626 // multisample surface
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016627 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
Karl Schultz6addd812016-02-02 17:17:23 -070016628 image_create_info.flags = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060016629
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016630 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
Mike Stroyana3082432015-09-25 13:39:21 -060016631 ASSERT_VK_SUCCESS(err);
16632
Karl Schultz6addd812016-02-02 17:17:23 -070016633 image_create_info.imageType = VK_IMAGE_TYPE_1D;
16634 // Note: Some implementations expect color attachment usage for any
16635 // multisample surface
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016636 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
Karl Schultz6addd812016-02-02 17:17:23 -070016637 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060016638
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016639 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
Mike Stroyana3082432015-09-25 13:39:21 -060016640 ASSERT_VK_SUCCESS(err);
16641
16642 // Allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016643 VkMemoryAllocateInfo memAlloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -070016644 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
16645 memAlloc.pNext = NULL;
16646 memAlloc.allocationSize = 0;
16647 memAlloc.memoryTypeIndex = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060016648
Courtney Goeltzenleuchter06d89472015-10-20 16:40:38 -060016649 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060016650 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016651 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060016652 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016653 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
Mike Stroyana3082432015-09-25 13:39:21 -060016654 ASSERT_VK_SUCCESS(err);
16655
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016656 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060016657 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016658 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060016659 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016660 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
Mike Stroyana3082432015-09-25 13:39:21 -060016661 ASSERT_VK_SUCCESS(err);
16662
16663 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
16664 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016665 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
Mike Stroyana3082432015-09-25 13:39:21 -060016666 ASSERT_VK_SUCCESS(err);
16667
16668 BeginCommandBuffer();
16669 // Need memory barrier to VK_IMAGE_LAYOUT_GENERAL for source and dest?
Karl Schultz6addd812016-02-02 17:17:23 -070016670 // VK_IMAGE_LAYOUT_UNDEFINED = 0,
16671 // VK_IMAGE_LAYOUT_GENERAL = 1,
Mike Stroyana3082432015-09-25 13:39:21 -060016672 VkImageResolve resolveRegion;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080016673 resolveRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060016674 resolveRegion.srcSubresource.mipLevel = 0;
Courtney Goeltzenleuchter8367ce02015-10-16 09:46:00 -060016675 resolveRegion.srcSubresource.baseArrayLayer = 0;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016676 resolveRegion.srcSubresource.layerCount = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060016677 resolveRegion.srcOffset.x = 0;
16678 resolveRegion.srcOffset.y = 0;
16679 resolveRegion.srcOffset.z = 0;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080016680 resolveRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016681 resolveRegion.dstSubresource.mipLevel = 0;
16682 resolveRegion.dstSubresource.baseArrayLayer = 0;
16683 resolveRegion.dstSubresource.layerCount = 0;
16684 resolveRegion.dstOffset.x = 0;
16685 resolveRegion.dstOffset.y = 0;
16686 resolveRegion.dstOffset.z = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060016687 resolveRegion.extent.width = 1;
16688 resolveRegion.extent.height = 1;
16689 resolveRegion.extent.depth = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016690 m_commandBuffer->ResolveImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, VK_IMAGE_LAYOUT_GENERAL, 1, &resolveRegion);
Mike Stroyana3082432015-09-25 13:39:21 -060016691 EndCommandBuffer();
16692
Chris Forbes8f36a8a2016-04-07 13:21:07 +120016693 m_errorMonitor->VerifyFound();
Mike Stroyana3082432015-09-25 13:39:21 -060016694
Chia-I Wuf7458c52015-10-26 21:10:41 +080016695 vkDestroyImage(m_device->device(), srcImage, NULL);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016696 vkDestroyImage(m_device->device(), dstImage, NULL);
Chia-I Wuf7458c52015-10-26 21:10:41 +080016697 vkFreeMemory(m_device->device(), srcMem, NULL);
16698 vkFreeMemory(m_device->device(), destMem, NULL);
Mike Stroyana3082432015-09-25 13:39:21 -060016699}
Tobin Ehlisa1c28562015-10-23 16:00:08 -060016700
Karl Schultz6addd812016-02-02 17:17:23 -070016701TEST_F(VkLayerTest, DepthStencilImageViewWithColorAspectBitError) {
Tobin Ehlisa1c28562015-10-23 16:00:08 -060016702 // Create a single Image descriptor and cause it to first hit an error due
Karl Schultz6addd812016-02-02 17:17:23 -070016703 // to using a DS format, then cause it to hit error due to COLOR_BIT not
16704 // set in aspect
Tobin Ehlisa1c28562015-10-23 16:00:08 -060016705 // The image format check comes 2nd in validation so we trigger it first,
16706 // then when we cause aspect fail next, bad format check will be preempted
Karl Schultz6addd812016-02-02 17:17:23 -070016707 VkResult err;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060016708
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016709 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
16710 "Combination depth/stencil image formats can have only the ");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060016711
Tobin Ehlisa1c28562015-10-23 16:00:08 -060016712 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060016713
Chia-I Wu1b99bb22015-10-27 19:25:11 +080016714 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -070016715 ds_type_count.type = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE;
16716 ds_type_count.descriptorCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060016717
16718 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070016719 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
16720 ds_pool_ci.pNext = NULL;
16721 ds_pool_ci.maxSets = 1;
16722 ds_pool_ci.poolSizeCount = 1;
16723 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060016724
16725 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016726 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060016727 ASSERT_VK_SUCCESS(err);
16728
16729 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -070016730 dsl_binding.binding = 0;
16731 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE;
16732 dsl_binding.descriptorCount = 1;
16733 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
16734 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060016735
16736 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070016737 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
16738 ds_layout_ci.pNext = NULL;
16739 ds_layout_ci.bindingCount = 1;
16740 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060016741 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016742 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060016743 ASSERT_VK_SUCCESS(err);
16744
16745 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016746 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +080016747 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -070016748 alloc_info.descriptorSetCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060016749 alloc_info.descriptorPool = ds_pool;
16750 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016751 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060016752 ASSERT_VK_SUCCESS(err);
16753
Karl Schultz6addd812016-02-02 17:17:23 -070016754 VkImage image_bad;
16755 VkImage image_good;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060016756 // One bad format and one good format for Color attachment
Tobin Ehlis269f0322016-05-25 16:24:21 -060016757 const VkFormat tex_format_bad = VK_FORMAT_D24_UNORM_S8_UINT;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060016758 const VkFormat tex_format_good = VK_FORMAT_B8G8R8A8_UNORM;
Karl Schultz6addd812016-02-02 17:17:23 -070016759 const int32_t tex_width = 32;
16760 const int32_t tex_height = 32;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060016761
16762 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070016763 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
16764 image_create_info.pNext = NULL;
16765 image_create_info.imageType = VK_IMAGE_TYPE_2D;
16766 image_create_info.format = tex_format_bad;
16767 image_create_info.extent.width = tex_width;
16768 image_create_info.extent.height = tex_height;
16769 image_create_info.extent.depth = 1;
16770 image_create_info.mipLevels = 1;
16771 image_create_info.arrayLayers = 1;
16772 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
16773 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016774 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT | VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT;
Karl Schultz6addd812016-02-02 17:17:23 -070016775 image_create_info.flags = 0;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060016776
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016777 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image_bad);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060016778 ASSERT_VK_SUCCESS(err);
16779 image_create_info.format = tex_format_good;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016780 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
16781 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image_good);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060016782 ASSERT_VK_SUCCESS(err);
16783
16784 VkImageViewCreateInfo image_view_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070016785 image_view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
16786 image_view_create_info.image = image_bad;
16787 image_view_create_info.viewType = VK_IMAGE_VIEW_TYPE_2D;
16788 image_view_create_info.format = tex_format_bad;
16789 image_view_create_info.subresourceRange.baseArrayLayer = 0;
16790 image_view_create_info.subresourceRange.baseMipLevel = 0;
16791 image_view_create_info.subresourceRange.layerCount = 1;
16792 image_view_create_info.subresourceRange.levelCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016793 image_view_create_info.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060016794
16795 VkImageView view;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016796 err = vkCreateImageView(m_device->device(), &image_view_create_info, NULL, &view);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060016797
Chris Forbes8f36a8a2016-04-07 13:21:07 +120016798 m_errorMonitor->VerifyFound();
Tobin Ehlisa1c28562015-10-23 16:00:08 -060016799
Chia-I Wuf7458c52015-10-26 21:10:41 +080016800 vkDestroyImage(m_device->device(), image_bad, NULL);
16801 vkDestroyImage(m_device->device(), image_good, NULL);
Chia-I Wuf7458c52015-10-26 21:10:41 +080016802 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
16803 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060016804}
Tobin Ehlis6e23d772016-05-19 11:08:34 -060016805
16806TEST_F(VkLayerTest, ClearImageErrors) {
16807 TEST_DESCRIPTION("Call ClearColorImage w/ a depth|stencil image and "
16808 "ClearDepthStencilImage with a color image.");
16809
16810 ASSERT_NO_FATAL_FAILURE(InitState());
16811 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
16812
16813 // Renderpass is started here so end it as Clear cmds can't be in renderpass
16814 BeginCommandBuffer();
16815 m_commandBuffer->EndRenderPass();
16816
16817 // Color image
16818 VkClearColorValue clear_color;
16819 memset(clear_color.uint32, 0, sizeof(uint32_t) * 4);
16820 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
16821 const VkFormat color_format = VK_FORMAT_B8G8R8A8_UNORM;
16822 const int32_t img_width = 32;
16823 const int32_t img_height = 32;
16824 VkImageCreateInfo image_create_info = {};
16825 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
16826 image_create_info.pNext = NULL;
16827 image_create_info.imageType = VK_IMAGE_TYPE_2D;
16828 image_create_info.format = color_format;
16829 image_create_info.extent.width = img_width;
16830 image_create_info.extent.height = img_height;
16831 image_create_info.extent.depth = 1;
16832 image_create_info.mipLevels = 1;
16833 image_create_info.arrayLayers = 1;
16834 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
16835 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
16836 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
16837
16838 vk_testing::Image color_image;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016839 color_image.init(*m_device, (const VkImageCreateInfo &)image_create_info, reqs);
Tobin Ehlis6e23d772016-05-19 11:08:34 -060016840
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016841 const VkImageSubresourceRange color_range = vk_testing::Image::subresource_range(image_create_info, VK_IMAGE_ASPECT_COLOR_BIT);
Tobin Ehlis6e23d772016-05-19 11:08:34 -060016842
16843 // Depth/Stencil image
16844 VkClearDepthStencilValue clear_value = {0};
16845 reqs = 0; // don't need HOST_VISIBLE DS image
16846 VkImageCreateInfo ds_image_create_info = vk_testing::Image::create_info();
16847 ds_image_create_info.imageType = VK_IMAGE_TYPE_2D;
16848 ds_image_create_info.format = VK_FORMAT_D24_UNORM_S8_UINT;
16849 ds_image_create_info.extent.width = 64;
16850 ds_image_create_info.extent.height = 64;
16851 ds_image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
16852 ds_image_create_info.usage = VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT;
16853
16854 vk_testing::Image ds_image;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016855 ds_image.init(*m_device, (const VkImageCreateInfo &)ds_image_create_info, reqs);
Tobin Ehlis6e23d772016-05-19 11:08:34 -060016856
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016857 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 -060016858
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016859 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "vkCmdClearColorImage called with depth/stencil image.");
Tobin Ehlis6e23d772016-05-19 11:08:34 -060016860
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016861 vkCmdClearColorImage(m_commandBuffer->GetBufferHandle(), ds_image.handle(), VK_IMAGE_LAYOUT_GENERAL, &clear_color, 1,
Tobin Ehlis6e23d772016-05-19 11:08:34 -060016862 &color_range);
16863
16864 m_errorMonitor->VerifyFound();
16865
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016866 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "vkCmdClearColorImage called with "
16867 "image created without "
16868 "VK_IMAGE_USAGE_TRANSFER_DST_BIT");
Tony Barbour26434b92016-06-02 09:43:50 -060016869
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016870 vkCmdClearColorImage(m_commandBuffer->GetBufferHandle(), ds_image.handle(), VK_IMAGE_LAYOUT_GENERAL, &clear_color, 1,
Tony Barbour26434b92016-06-02 09:43:50 -060016871 &color_range);
16872
16873 m_errorMonitor->VerifyFound();
16874
Tobin Ehlis6e23d772016-05-19 11:08:34 -060016875 // Call CmdClearDepthStencilImage with color image
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016876 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
16877 "vkCmdClearDepthStencilImage called without a depth/stencil image.");
Tobin Ehlis6e23d772016-05-19 11:08:34 -060016878
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016879 vkCmdClearDepthStencilImage(m_commandBuffer->GetBufferHandle(), color_image.handle(),
16880 VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL, &clear_value, 1, &ds_range);
Tobin Ehlis6e23d772016-05-19 11:08:34 -060016881
16882 m_errorMonitor->VerifyFound();
16883}
Tobin Ehliscde08892015-09-22 10:11:37 -060016884#endif // IMAGE_TESTS
16885
Cody Northrop1242dfd2016-07-13 17:24:59 -060016886#if defined(ANDROID) && defined(VALIDATION_APK)
16887static bool initialized = false;
16888static bool active = false;
16889
16890// Convert Intents to argv
16891// Ported from Hologram sample, only difference is flexible key
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016892std::vector<std::string> get_args(android_app &app, const char *intent_extra_data_key) {
Cody Northrop1242dfd2016-07-13 17:24:59 -060016893 std::vector<std::string> args;
16894 JavaVM &vm = *app.activity->vm;
16895 JNIEnv *p_env;
16896 if (vm.AttachCurrentThread(&p_env, nullptr) != JNI_OK)
16897 return args;
16898
16899 JNIEnv &env = *p_env;
16900 jobject activity = app.activity->clazz;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016901 jmethodID get_intent_method = env.GetMethodID(env.GetObjectClass(activity), "getIntent", "()Landroid/content/Intent;");
Cody Northrop1242dfd2016-07-13 17:24:59 -060016902 jobject intent = env.CallObjectMethod(activity, get_intent_method);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016903 jmethodID get_string_extra_method =
16904 env.GetMethodID(env.GetObjectClass(intent), "getStringExtra", "(Ljava/lang/String;)Ljava/lang/String;");
Cody Northrop1242dfd2016-07-13 17:24:59 -060016905 jvalue get_string_extra_args;
16906 get_string_extra_args.l = env.NewStringUTF(intent_extra_data_key);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016907 jstring extra_str = static_cast<jstring>(env.CallObjectMethodA(intent, get_string_extra_method, &get_string_extra_args));
Cody Northrop1242dfd2016-07-13 17:24:59 -060016908
16909 std::string args_str;
16910 if (extra_str) {
16911 const char *extra_utf = env.GetStringUTFChars(extra_str, nullptr);
16912 args_str = extra_utf;
16913 env.ReleaseStringUTFChars(extra_str, extra_utf);
16914 env.DeleteLocalRef(extra_str);
16915 }
16916
16917 env.DeleteLocalRef(get_string_extra_args.l);
16918 env.DeleteLocalRef(intent);
16919 vm.DetachCurrentThread();
16920
16921 // split args_str
16922 std::stringstream ss(args_str);
16923 std::string arg;
16924 while (std::getline(ss, arg, ' ')) {
16925 if (!arg.empty())
16926 args.push_back(arg);
16927 }
16928
16929 return args;
16930}
16931
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016932static int32_t processInput(struct android_app *app, AInputEvent *event) { return 0; }
Cody Northrop1242dfd2016-07-13 17:24:59 -060016933
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016934static void processCommand(struct android_app *app, int32_t cmd) {
16935 switch (cmd) {
16936 case APP_CMD_INIT_WINDOW: {
16937 if (app->window) {
16938 initialized = true;
Cody Northrop1242dfd2016-07-13 17:24:59 -060016939 }
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016940 break;
16941 }
16942 case APP_CMD_GAINED_FOCUS: {
16943 active = true;
16944 break;
16945 }
16946 case APP_CMD_LOST_FOCUS: {
16947 active = false;
16948 break;
16949 }
Cody Northrop1242dfd2016-07-13 17:24:59 -060016950 }
16951}
16952
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016953void android_main(struct android_app *app) {
Cody Northrop1242dfd2016-07-13 17:24:59 -060016954 app_dummy();
16955
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016956 const char *appTag = "VulkanLayerValidationTests";
Cody Northrop1242dfd2016-07-13 17:24:59 -060016957
16958 int vulkanSupport = InitVulkan();
16959 if (vulkanSupport == 0) {
16960 __android_log_print(ANDROID_LOG_INFO, appTag, "==== FAILED ==== No Vulkan support found");
16961 return;
16962 }
16963
16964 app->onAppCmd = processCommand;
16965 app->onInputEvent = processInput;
16966
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016967 while (1) {
Cody Northrop1242dfd2016-07-13 17:24:59 -060016968 int events;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016969 struct android_poll_source *source;
16970 while (ALooper_pollAll(active ? 0 : -1, NULL, &events, (void **)&source) >= 0) {
Cody Northrop1242dfd2016-07-13 17:24:59 -060016971 if (source) {
16972 source->process(app, source);
16973 }
16974
16975 if (app->destroyRequested != 0) {
16976 VkTestFramework::Finish();
16977 return;
16978 }
16979 }
16980
16981 if (initialized && active) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016982 // Use the following key to send arguments to gtest, i.e.
16983 // --es args "--gtest_filter=-VkLayerTest.foo"
16984 const char key[] = "args";
16985 std::vector<std::string> args = get_args(*app, key);
Cody Northrop1242dfd2016-07-13 17:24:59 -060016986
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016987 std::string filter = "";
16988 if (args.size() > 0) {
16989 __android_log_print(ANDROID_LOG_INFO, appTag, "Intent args = %s", args[0].c_str());
16990 filter += args[0];
16991 } else {
16992 __android_log_print(ANDROID_LOG_INFO, appTag, "No Intent args detected");
16993 }
Cody Northrop1242dfd2016-07-13 17:24:59 -060016994
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016995 int argc = 2;
16996 char *argv[] = {(char *)"foo", (char *)filter.c_str()};
16997 __android_log_print(ANDROID_LOG_DEBUG, appTag, "filter = %s", argv[1]);
Cody Northrop1242dfd2016-07-13 17:24:59 -060016998
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016999 // Route output to files until we can override the gtest output
17000 freopen("/sdcard/Android/data/com.example.VulkanLayerValidationTests/files/out.txt", "w", stdout);
17001 freopen("/sdcard/Android/data/com.example.VulkanLayerValidationTests/files/err.txt", "w", stderr);
Cody Northrop1242dfd2016-07-13 17:24:59 -060017002
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017003 ::testing::InitGoogleTest(&argc, argv);
17004 VkTestFramework::InitArgs(&argc, argv);
17005 ::testing::AddGlobalTestEnvironment(new TestEnvironment);
Cody Northrop1242dfd2016-07-13 17:24:59 -060017006
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017007 int result = RUN_ALL_TESTS();
Cody Northrop1242dfd2016-07-13 17:24:59 -060017008
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017009 if (result != 0) {
17010 __android_log_print(ANDROID_LOG_INFO, appTag, "==== Tests FAILED ====");
17011 } else {
17012 __android_log_print(ANDROID_LOG_INFO, appTag, "==== Tests PASSED ====");
17013 }
Cody Northrop1242dfd2016-07-13 17:24:59 -060017014
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017015 VkTestFramework::Finish();
Cody Northrop1242dfd2016-07-13 17:24:59 -060017016
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017017 fclose(stdout);
17018 fclose(stderr);
Cody Northrop1242dfd2016-07-13 17:24:59 -060017019
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017020 ANativeActivity_finish(app->activity);
Cody Northrop1242dfd2016-07-13 17:24:59 -060017021
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017022 return;
Cody Northrop1242dfd2016-07-13 17:24:59 -060017023 }
17024 }
17025}
17026#endif
17027
Tony Barbour300a6082015-04-07 13:44:53 -060017028int main(int argc, char **argv) {
17029 int result;
17030
Cody Northrop8e54a402016-03-08 22:25:52 -070017031#ifdef ANDROID
17032 int vulkanSupport = InitVulkan();
17033 if (vulkanSupport == 0)
17034 return 1;
17035#endif
17036
Tony Barbour300a6082015-04-07 13:44:53 -060017037 ::testing::InitGoogleTest(&argc, argv);
Tony Barbour6918cd52015-04-09 12:58:51 -060017038 VkTestFramework::InitArgs(&argc, argv);
Tony Barbour300a6082015-04-07 13:44:53 -060017039
17040 ::testing::AddGlobalTestEnvironment(new TestEnvironment);
17041
17042 result = RUN_ALL_TESTS();
17043
Tony Barbour6918cd52015-04-09 12:58:51 -060017044 VkTestFramework::Finish();
Tony Barbour300a6082015-04-07 13:44:53 -060017045 return result;
17046}