blob: 017c81a1dde79030d20cae713ddc076ee2c9640f [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;
6948 buf_info.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
6949 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;
7072 // No dynamic state
7073 VkPipelineDynamicStateCreateInfo dyn_state_ci = {};
7074 dyn_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_DYNAMIC_STATE_CREATE_INFO;
7075
7076 VkPipelineShaderStageCreateInfo shaderStages[2];
7077 memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo));
7078
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007079 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
7080 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this); // We shouldn't need a fragment shader
7081 // but add it to be able to run on more devices
Tobin Ehlis24130d92016-07-08 15:50:53 -06007082 shaderStages[0] = vs.GetStageCreateInfo();
7083 shaderStages[1] = fs.GetStageCreateInfo();
7084
7085 VkPipelineVertexInputStateCreateInfo vi_ci = {};
7086 vi_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
7087
7088 VkPipelineInputAssemblyStateCreateInfo ia_ci = {};
7089 ia_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
7090 ia_ci.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP;
7091
7092 VkPipelineRasterizationStateCreateInfo rs_ci = {};
7093 rs_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
7094
7095 VkPipelineColorBlendAttachmentState att = {};
7096 att.blendEnable = VK_FALSE;
7097 att.colorWriteMask = 0xf;
7098
7099 VkPipelineColorBlendStateCreateInfo cb_ci = {};
7100 cb_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO;
7101 cb_ci.attachmentCount = 1;
7102 cb_ci.pAttachments = &att;
7103
7104 VkGraphicsPipelineCreateInfo gp_ci = {};
7105 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
7106 gp_ci.stageCount = 2;
7107 gp_ci.pStages = shaderStages;
7108 gp_ci.pVertexInputState = &vi_ci;
7109 gp_ci.pInputAssemblyState = &ia_ci;
7110 gp_ci.pViewportState = &vp_state_ci;
7111 gp_ci.pRasterizationState = &rs_ci;
7112 gp_ci.pColorBlendState = &cb_ci;
7113 gp_ci.pDynamicState = &dyn_state_ci;
7114 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
7115 gp_ci.layout = pipeline_layout;
7116 gp_ci.renderPass = renderPass();
7117
7118 VkPipelineCacheCreateInfo pc_ci = {};
7119 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
7120
7121 VkPipeline pipeline;
7122 VkPipelineCache pipelineCache;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007123 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Tobin Ehlis24130d92016-07-08 15:50:53 -06007124 ASSERT_VK_SUCCESS(err);
7125
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007126 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Tobin Ehlis24130d92016-07-08 15:50:53 -06007127 ASSERT_VK_SUCCESS(err);
7128
7129 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007130 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline);
Tobin Ehlis24130d92016-07-08 15:50:53 -06007131 m_commandBuffer->EndCommandBuffer();
7132 // Now destroy pipeline in order to cause error when submitting
7133 vkDestroyPipeline(m_device->device(), pipeline, nullptr);
7134
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007135 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " that is invalid because bound pipeline ");
Tobin Ehlis24130d92016-07-08 15:50:53 -06007136
7137 VkSubmitInfo submit_info = {};
7138 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
7139 submit_info.commandBufferCount = 1;
7140 submit_info.pCommandBuffers = &m_commandBuffer->handle();
7141 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
7142
7143 m_errorMonitor->VerifyFound();
7144 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
7145 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
7146}
7147
Tobin Ehlis31289162016-08-17 14:57:58 -06007148TEST_F(VkLayerTest, InvalidCmdBufferDescriptorSetBufferDestroyed) {
7149 TEST_DESCRIPTION("Attempt to draw with a command buffer that is invalid "
7150 "due to a bound descriptor set with a buffer dependency "
7151 "being destroyed.");
7152 ASSERT_NO_FATAL_FAILURE(InitState());
7153 ASSERT_NO_FATAL_FAILURE(InitViewport());
7154 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
7155
7156 VkDescriptorPoolSize ds_type_count = {};
7157 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
7158 ds_type_count.descriptorCount = 1;
7159
7160 VkDescriptorPoolCreateInfo ds_pool_ci = {};
7161 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
7162 ds_pool_ci.pNext = NULL;
7163 ds_pool_ci.maxSets = 1;
7164 ds_pool_ci.poolSizeCount = 1;
7165 ds_pool_ci.pPoolSizes = &ds_type_count;
7166
7167 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007168 VkResult err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis31289162016-08-17 14:57:58 -06007169 ASSERT_VK_SUCCESS(err);
7170
7171 VkDescriptorSetLayoutBinding dsl_binding = {};
7172 dsl_binding.binding = 0;
7173 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
7174 dsl_binding.descriptorCount = 1;
7175 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
7176 dsl_binding.pImmutableSamplers = NULL;
7177
7178 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
7179 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
7180 ds_layout_ci.pNext = NULL;
7181 ds_layout_ci.bindingCount = 1;
7182 ds_layout_ci.pBindings = &dsl_binding;
7183 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007184 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis31289162016-08-17 14:57:58 -06007185 ASSERT_VK_SUCCESS(err);
7186
7187 VkDescriptorSet descriptorSet;
7188 VkDescriptorSetAllocateInfo alloc_info = {};
7189 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
7190 alloc_info.descriptorSetCount = 1;
7191 alloc_info.descriptorPool = ds_pool;
7192 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007193 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis31289162016-08-17 14:57:58 -06007194 ASSERT_VK_SUCCESS(err);
7195
7196 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
7197 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
7198 pipeline_layout_ci.pNext = NULL;
7199 pipeline_layout_ci.setLayoutCount = 1;
7200 pipeline_layout_ci.pSetLayouts = &ds_layout;
7201
7202 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007203 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis31289162016-08-17 14:57:58 -06007204 ASSERT_VK_SUCCESS(err);
7205
7206 // Create a buffer to update the descriptor with
7207 uint32_t qfi = 0;
7208 VkBufferCreateInfo buffCI = {};
7209 buffCI.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
7210 buffCI.size = 1024;
7211 buffCI.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
7212 buffCI.queueFamilyIndexCount = 1;
7213 buffCI.pQueueFamilyIndices = &qfi;
7214
7215 VkBuffer buffer;
7216 err = vkCreateBuffer(m_device->device(), &buffCI, NULL, &buffer);
7217 ASSERT_VK_SUCCESS(err);
7218 // Allocate memory and bind to buffer so we can make it to the appropriate
7219 // error
7220 VkMemoryAllocateInfo mem_alloc = {};
7221 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
7222 mem_alloc.pNext = NULL;
7223 mem_alloc.allocationSize = 1024;
7224 mem_alloc.memoryTypeIndex = 0;
7225
7226 VkMemoryRequirements memReqs;
7227 vkGetBufferMemoryRequirements(m_device->device(), buffer, &memReqs);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007228 bool pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &mem_alloc, 0);
Tobin Ehlis31289162016-08-17 14:57:58 -06007229 if (!pass) {
7230 vkDestroyBuffer(m_device->device(), buffer, NULL);
7231 return;
7232 }
7233
7234 VkDeviceMemory mem;
7235 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem);
7236 ASSERT_VK_SUCCESS(err);
7237 err = vkBindBufferMemory(m_device->device(), buffer, mem, 0);
7238 ASSERT_VK_SUCCESS(err);
7239 // Correctly update descriptor to avoid "NOT_UPDATED" error
7240 VkDescriptorBufferInfo buffInfo = {};
7241 buffInfo.buffer = buffer;
7242 buffInfo.offset = 0;
7243 buffInfo.range = 1024;
7244
7245 VkWriteDescriptorSet descriptor_write;
7246 memset(&descriptor_write, 0, sizeof(descriptor_write));
7247 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
7248 descriptor_write.dstSet = descriptorSet;
7249 descriptor_write.dstBinding = 0;
7250 descriptor_write.descriptorCount = 1;
7251 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
7252 descriptor_write.pBufferInfo = &buffInfo;
7253
7254 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
7255
7256 // Create PSO to be used for draw-time errors below
7257 char const *vsSource = "#version 450\n"
7258 "\n"
7259 "out gl_PerVertex { \n"
7260 " vec4 gl_Position;\n"
7261 "};\n"
7262 "void main(){\n"
7263 " gl_Position = vec4(1);\n"
7264 "}\n";
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007265 char const *fsSource = "#version 450\n"
7266 "\n"
7267 "layout(location=0) out vec4 x;\n"
7268 "layout(set=0) layout(binding=0) uniform foo { int x; int y; } bar;\n"
7269 "void main(){\n"
7270 " x = vec4(bar.y);\n"
7271 "}\n";
Tobin Ehlis31289162016-08-17 14:57:58 -06007272 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
7273 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
7274 VkPipelineObj pipe(m_device);
7275 pipe.AddShader(&vs);
7276 pipe.AddShader(&fs);
7277 pipe.AddColorAttachment();
7278 pipe.CreateVKPipeline(pipeline_layout, renderPass());
7279
7280 BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007281 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
7282 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
7283 &descriptorSet, 0, NULL);
Tobin Ehlis31289162016-08-17 14:57:58 -06007284 Draw(1, 0, 0, 0);
7285 EndCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007286 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " that is invalid because bound buffer ");
Tobin Ehlis31289162016-08-17 14:57:58 -06007287 // Destroy buffer should invalidate the cmd buffer, causing error on submit
7288 vkDestroyBuffer(m_device->device(), buffer, NULL);
7289 // Attempt to submit cmd buffer
7290 VkSubmitInfo submit_info = {};
7291 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
7292 submit_info.commandBufferCount = 1;
7293 submit_info.pCommandBuffers = &m_commandBuffer->handle();
7294 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
7295 m_errorMonitor->VerifyFound();
7296 // Cleanup
7297 vkFreeMemory(m_device->device(), mem, NULL);
7298
7299 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
7300 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
7301 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
7302}
7303
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06007304TEST_F(VkLayerTest, InvalidCmdBufferDescriptorSetImageSamplerDestroyed) {
7305 TEST_DESCRIPTION("Attempt to draw with a command buffer that is invalid "
7306 "due to a bound descriptor sets with a combined image "
7307 "sampler having their image, sampler, and descriptor set "
7308 "each respectively destroyed and then attempting to "
Mark Mueller917f6bc2016-08-30 10:57:19 -06007309 "submit associated cmd buffers. Attempt to destroy a "
7310 "DescriptorSet that is in use.");
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06007311 ASSERT_NO_FATAL_FAILURE(InitState());
7312 ASSERT_NO_FATAL_FAILURE(InitViewport());
7313 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
7314
7315 VkDescriptorPoolSize ds_type_count = {};
7316 ds_type_count.type = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
7317 ds_type_count.descriptorCount = 1;
7318
7319 VkDescriptorPoolCreateInfo ds_pool_ci = {};
7320 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
7321 ds_pool_ci.pNext = NULL;
7322 ds_pool_ci.maxSets = 1;
7323 ds_pool_ci.poolSizeCount = 1;
7324 ds_pool_ci.pPoolSizes = &ds_type_count;
7325
7326 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007327 VkResult err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06007328 ASSERT_VK_SUCCESS(err);
7329
7330 VkDescriptorSetLayoutBinding dsl_binding = {};
7331 dsl_binding.binding = 0;
7332 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
7333 dsl_binding.descriptorCount = 1;
7334 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
7335 dsl_binding.pImmutableSamplers = NULL;
7336
7337 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
7338 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
7339 ds_layout_ci.pNext = NULL;
7340 ds_layout_ci.bindingCount = 1;
7341 ds_layout_ci.pBindings = &dsl_binding;
7342 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007343 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06007344 ASSERT_VK_SUCCESS(err);
7345
7346 VkDescriptorSet descriptorSet;
7347 VkDescriptorSetAllocateInfo alloc_info = {};
7348 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
7349 alloc_info.descriptorSetCount = 1;
7350 alloc_info.descriptorPool = ds_pool;
7351 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007352 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06007353 ASSERT_VK_SUCCESS(err);
7354
7355 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
7356 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
7357 pipeline_layout_ci.pNext = NULL;
7358 pipeline_layout_ci.setLayoutCount = 1;
7359 pipeline_layout_ci.pSetLayouts = &ds_layout;
7360
7361 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007362 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06007363 ASSERT_VK_SUCCESS(err);
7364
7365 // Create images to update the descriptor with
7366 VkImage image;
7367 VkImage image2;
7368 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
7369 const int32_t tex_width = 32;
7370 const int32_t tex_height = 32;
7371 VkImageCreateInfo image_create_info = {};
7372 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
7373 image_create_info.pNext = NULL;
7374 image_create_info.imageType = VK_IMAGE_TYPE_2D;
7375 image_create_info.format = tex_format;
7376 image_create_info.extent.width = tex_width;
7377 image_create_info.extent.height = tex_height;
7378 image_create_info.extent.depth = 1;
7379 image_create_info.mipLevels = 1;
7380 image_create_info.arrayLayers = 1;
7381 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
7382 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
7383 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
7384 image_create_info.flags = 0;
7385 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
7386 ASSERT_VK_SUCCESS(err);
7387 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image2);
7388 ASSERT_VK_SUCCESS(err);
7389
7390 VkMemoryRequirements memory_reqs;
7391 VkDeviceMemory image_memory;
7392 bool pass;
7393 VkMemoryAllocateInfo memory_info = {};
7394 memory_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
7395 memory_info.pNext = NULL;
7396 memory_info.allocationSize = 0;
7397 memory_info.memoryTypeIndex = 0;
7398 vkGetImageMemoryRequirements(m_device->device(), image, &memory_reqs);
7399 // Allocate enough memory for both images
7400 memory_info.allocationSize = memory_reqs.size * 2;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007401 pass = m_device->phy().set_memory_type(memory_reqs.memoryTypeBits, &memory_info, 0);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06007402 ASSERT_TRUE(pass);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007403 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &image_memory);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06007404 ASSERT_VK_SUCCESS(err);
7405 err = vkBindImageMemory(m_device->device(), image, image_memory, 0);
7406 ASSERT_VK_SUCCESS(err);
7407 // Bind second image to memory right after first image
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007408 err = vkBindImageMemory(m_device->device(), image2, image_memory, memory_reqs.size);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06007409 ASSERT_VK_SUCCESS(err);
7410
7411 VkImageViewCreateInfo image_view_create_info = {};
7412 image_view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
7413 image_view_create_info.image = image;
7414 image_view_create_info.viewType = VK_IMAGE_VIEW_TYPE_2D;
7415 image_view_create_info.format = tex_format;
7416 image_view_create_info.subresourceRange.layerCount = 1;
7417 image_view_create_info.subresourceRange.baseMipLevel = 0;
7418 image_view_create_info.subresourceRange.levelCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007419 image_view_create_info.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06007420
7421 VkImageView view;
7422 VkImageView view2;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007423 err = vkCreateImageView(m_device->device(), &image_view_create_info, NULL, &view);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06007424 ASSERT_VK_SUCCESS(err);
7425 image_view_create_info.image = image2;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007426 err = vkCreateImageView(m_device->device(), &image_view_create_info, NULL, &view2);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06007427 ASSERT_VK_SUCCESS(err);
7428 // Create Samplers
7429 VkSamplerCreateInfo sampler_ci = {};
7430 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
7431 sampler_ci.pNext = NULL;
7432 sampler_ci.magFilter = VK_FILTER_NEAREST;
7433 sampler_ci.minFilter = VK_FILTER_NEAREST;
7434 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
7435 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
7436 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
7437 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
7438 sampler_ci.mipLodBias = 1.0;
7439 sampler_ci.anisotropyEnable = VK_FALSE;
7440 sampler_ci.maxAnisotropy = 1;
7441 sampler_ci.compareEnable = VK_FALSE;
7442 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
7443 sampler_ci.minLod = 1.0;
7444 sampler_ci.maxLod = 1.0;
7445 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
7446 sampler_ci.unnormalizedCoordinates = VK_FALSE;
7447 VkSampler sampler;
7448 VkSampler sampler2;
7449 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
7450 ASSERT_VK_SUCCESS(err);
7451 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler2);
7452 ASSERT_VK_SUCCESS(err);
7453 // Update descriptor with image and sampler
7454 VkDescriptorImageInfo img_info = {};
7455 img_info.sampler = sampler;
7456 img_info.imageView = view;
7457 img_info.imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
7458
7459 VkWriteDescriptorSet descriptor_write;
7460 memset(&descriptor_write, 0, sizeof(descriptor_write));
7461 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
7462 descriptor_write.dstSet = descriptorSet;
7463 descriptor_write.dstBinding = 0;
7464 descriptor_write.descriptorCount = 1;
7465 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
7466 descriptor_write.pImageInfo = &img_info;
7467
7468 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
7469
7470 // Create PSO to be used for draw-time errors below
7471 char const *vsSource = "#version 450\n"
7472 "\n"
7473 "out gl_PerVertex { \n"
7474 " vec4 gl_Position;\n"
7475 "};\n"
7476 "void main(){\n"
7477 " gl_Position = vec4(1);\n"
7478 "}\n";
7479 char const *fsSource = "#version 450\n"
7480 "\n"
7481 "layout(set=0, binding=0) uniform sampler2D s;\n"
7482 "layout(location=0) out vec4 x;\n"
7483 "void main(){\n"
7484 " x = texture(s, vec2(1));\n"
7485 "}\n";
7486 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
7487 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
7488 VkPipelineObj pipe(m_device);
7489 pipe.AddShader(&vs);
7490 pipe.AddShader(&fs);
7491 pipe.AddColorAttachment();
7492 pipe.CreateVKPipeline(pipeline_layout, renderPass());
7493
7494 // First error case is destroying sampler prior to cmd buffer submission
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007495 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Cannot submit cmd buffer using deleted sampler ");
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06007496 BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007497 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
7498 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
7499 &descriptorSet, 0, NULL);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06007500 Draw(1, 0, 0, 0);
7501 EndCommandBuffer();
7502 // Destroy sampler invalidates the cmd buffer, causing error on submit
7503 vkDestroySampler(m_device->device(), sampler, NULL);
7504 // Attempt to submit cmd buffer
7505 VkSubmitInfo submit_info = {};
7506 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
7507 submit_info.commandBufferCount = 1;
7508 submit_info.pCommandBuffers = &m_commandBuffer->handle();
7509 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
7510 m_errorMonitor->VerifyFound();
7511 // Now re-update descriptor with valid sampler and delete image
7512 img_info.sampler = sampler2;
7513 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007514 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " that is invalid because bound image ");
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06007515 BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007516 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
7517 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
7518 &descriptorSet, 0, NULL);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06007519 Draw(1, 0, 0, 0);
7520 EndCommandBuffer();
7521 // Destroy image invalidates the cmd buffer, causing error on submit
7522 vkDestroyImage(m_device->device(), image, NULL);
7523 // Attempt to submit cmd buffer
7524 submit_info = {};
7525 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
7526 submit_info.commandBufferCount = 1;
7527 submit_info.pCommandBuffers = &m_commandBuffer->handle();
7528 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
7529 m_errorMonitor->VerifyFound();
7530 // Now update descriptor to be valid, but then free descriptor
7531 img_info.imageView = view2;
7532 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007533 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " that is invalid because bound descriptor set ");
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06007534 BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007535 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
7536 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
7537 &descriptorSet, 0, NULL);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06007538 Draw(1, 0, 0, 0);
7539 EndCommandBuffer();
7540 // Destroy descriptor set invalidates the cb, causing error on submit
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007541 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Cannot call vkFreeDescriptorSets() on descriptor set 0x");
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06007542 vkFreeDescriptorSets(m_device->device(), ds_pool, 1, &descriptorSet);
Mark Mueller917f6bc2016-08-30 10:57:19 -06007543 m_errorMonitor->VerifyFound();
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06007544 // Attempt to submit cmd buffer
7545 submit_info = {};
7546 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
7547 submit_info.commandBufferCount = 1;
7548 submit_info.pCommandBuffers = &m_commandBuffer->handle();
7549 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
7550 m_errorMonitor->VerifyFound();
7551 // Cleanup
7552 vkFreeMemory(m_device->device(), image_memory, NULL);
7553 vkDestroySampler(m_device->device(), sampler2, NULL);
7554 vkDestroyImage(m_device->device(), image2, NULL);
7555 vkDestroyImageView(m_device->device(), view, NULL);
7556 vkDestroyImageView(m_device->device(), view2, NULL);
7557 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
7558 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
7559 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
7560}
7561
Karl Schultz6addd812016-02-02 17:17:23 -07007562TEST_F(VkLayerTest, InvalidPipeline) {
Karl Schultzbdb75952016-04-19 11:36:49 -06007563 // Attempt to bind an invalid Pipeline to a valid Command Buffer
7564 // ObjectTracker should catch this.
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06007565 // Create a valid cmd buffer
7566 // call vkCmdBindPipeline w/ false Pipeline
Mark Lobodzinski02bf89d2016-05-10 14:45:13 -06007567 uint64_t fake_pipeline_handle = 0xbaad6001;
7568 VkPipeline bad_pipeline = reinterpret_cast<VkPipeline &>(fake_pipeline_handle);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007569 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Invalid Pipeline Object 0xbaad6001");
Karl Schultzbdb75952016-04-19 11:36:49 -06007570 ASSERT_NO_FATAL_FAILURE(InitState());
7571 BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007572 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, bad_pipeline);
Karl Schultzbdb75952016-04-19 11:36:49 -06007573 m_errorMonitor->VerifyFound();
Tobin Ehlisb8b6b272016-05-02 13:26:06 -06007574 // Now issue a draw call with no pipeline bound
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007575 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 -06007576
Tobin Ehlisb8b6b272016-05-02 13:26:06 -06007577 BeginCommandBuffer();
7578 Draw(1, 0, 0, 0);
7579 m_errorMonitor->VerifyFound();
7580 // Finally same check once more but with Dispatch/Compute
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007581 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 -06007582 BeginCommandBuffer();
7583 vkCmdDispatch(m_commandBuffer->GetBufferHandle(), 0, 0, 0);
7584 m_errorMonitor->VerifyFound();
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06007585}
7586
Karl Schultz6addd812016-02-02 17:17:23 -07007587TEST_F(VkLayerTest, DescriptorSetNotUpdated) {
Tobin Ehlis5a5f5ef2016-08-17 13:56:55 -06007588 TEST_DESCRIPTION("Bind a descriptor set that hasn't been updated.");
Karl Schultz6addd812016-02-02 17:17:23 -07007589 VkResult err;
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06007590
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007591 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT, " bound but it was never updated. ");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06007592
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06007593 ASSERT_NO_FATAL_FAILURE(InitState());
Mike Stroyan713b2d72015-08-04 10:49:29 -06007594 ASSERT_NO_FATAL_FAILURE(InitViewport());
7595 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chia-I Wu1b99bb22015-10-27 19:25:11 +08007596 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007597 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
7598 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -06007599
7600 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007601 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
7602 ds_pool_ci.pNext = NULL;
7603 ds_pool_ci.maxSets = 1;
7604 ds_pool_ci.poolSizeCount = 1;
7605 ds_pool_ci.pPoolSizes = &ds_type_count;
Mike Stroyan713b2d72015-08-04 10:49:29 -06007606
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06007607 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007608 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06007609 ASSERT_VK_SUCCESS(err);
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06007610
Tony Barboureb254902015-07-15 12:50:33 -06007611 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007612 dsl_binding.binding = 0;
7613 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
7614 dsl_binding.descriptorCount = 1;
7615 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
7616 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06007617
Tony Barboureb254902015-07-15 12:50:33 -06007618 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007619 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
7620 ds_layout_ci.pNext = NULL;
7621 ds_layout_ci.bindingCount = 1;
7622 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06007623 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007624 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06007625 ASSERT_VK_SUCCESS(err);
7626
7627 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08007628 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08007629 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07007630 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06007631 alloc_info.descriptorPool = ds_pool;
7632 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007633 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06007634 ASSERT_VK_SUCCESS(err);
7635
Tony Barboureb254902015-07-15 12:50:33 -06007636 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007637 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
7638 pipeline_layout_ci.pNext = NULL;
7639 pipeline_layout_ci.setLayoutCount = 1;
7640 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06007641
7642 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007643 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06007644 ASSERT_VK_SUCCESS(err);
7645
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007646 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
Karl Schultzbdb75952016-04-19 11:36:49 -06007647 // We shouldn't need a fragment shader but add it to be able to run
Karl Schultz6addd812016-02-02 17:17:23 -07007648 // on more devices
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007649 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06007650
Tony Barbourc95e4ac2015-08-04 17:05:26 -06007651 VkPipelineObj pipe(m_device);
7652 pipe.AddShader(&vs);
Tony Barbour1c94d372015-08-06 11:21:08 -06007653 pipe.AddShader(&fs);
Mark Youngc89c6312016-03-31 16:03:20 -06007654 pipe.AddColorAttachment();
Tony Barbourc95e4ac2015-08-04 17:05:26 -06007655 pipe.CreateVKPipeline(pipeline_layout, renderPass());
Tony Barbourfe3351b2015-07-28 10:17:20 -06007656
7657 BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007658 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
7659 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
7660 &descriptorSet, 0, NULL);
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06007661
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007662 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06007663
Chia-I Wuf7458c52015-10-26 21:10:41 +08007664 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
7665 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
7666 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06007667}
7668
Karl Schultz6addd812016-02-02 17:17:23 -07007669TEST_F(VkLayerTest, InvalidBufferViewObject) {
Tobin Ehlisba31cab2015-11-02 15:24:32 -07007670 // Create a single TEXEL_BUFFER descriptor and send it an invalid bufferView
Karl Schultz6addd812016-02-02 17:17:23 -07007671 VkResult err;
Tobin Ehlisba31cab2015-11-02 15:24:32 -07007672
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007673 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Attempted write update to texel buffer "
7674 "descriptor with invalid buffer view");
Tobin Ehlisba31cab2015-11-02 15:24:32 -07007675
7676 ASSERT_NO_FATAL_FAILURE(InitState());
7677 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007678 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER;
7679 ds_type_count.descriptorCount = 1;
Tobin Ehlisba31cab2015-11-02 15:24:32 -07007680
7681 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007682 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
7683 ds_pool_ci.pNext = NULL;
7684 ds_pool_ci.maxSets = 1;
7685 ds_pool_ci.poolSizeCount = 1;
7686 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlisba31cab2015-11-02 15:24:32 -07007687
7688 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007689 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlisba31cab2015-11-02 15:24:32 -07007690 ASSERT_VK_SUCCESS(err);
7691
7692 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007693 dsl_binding.binding = 0;
7694 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER;
7695 dsl_binding.descriptorCount = 1;
7696 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
7697 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlisba31cab2015-11-02 15:24:32 -07007698
7699 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007700 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
7701 ds_layout_ci.pNext = NULL;
7702 ds_layout_ci.bindingCount = 1;
7703 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlisba31cab2015-11-02 15:24:32 -07007704 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007705 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlisba31cab2015-11-02 15:24:32 -07007706 ASSERT_VK_SUCCESS(err);
7707
7708 VkDescriptorSet descriptorSet;
7709 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08007710 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07007711 alloc_info.descriptorSetCount = 1;
Tobin Ehlisba31cab2015-11-02 15:24:32 -07007712 alloc_info.descriptorPool = ds_pool;
7713 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007714 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlisba31cab2015-11-02 15:24:32 -07007715 ASSERT_VK_SUCCESS(err);
7716
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007717 VkBufferView view = (VkBufferView)((size_t)0xbaadbeef); // invalid bufferView object
Tobin Ehlisba31cab2015-11-02 15:24:32 -07007718 VkWriteDescriptorSet descriptor_write;
7719 memset(&descriptor_write, 0, sizeof(descriptor_write));
7720 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
7721 descriptor_write.dstSet = descriptorSet;
7722 descriptor_write.dstBinding = 0;
7723 descriptor_write.descriptorCount = 1;
7724 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER;
7725 descriptor_write.pTexelBufferView = &view;
7726
7727 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
7728
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007729 m_errorMonitor->VerifyFound();
Tobin Ehlisba31cab2015-11-02 15:24:32 -07007730
7731 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
7732 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
7733}
7734
Mark Youngd339ba32016-05-30 13:28:35 -06007735TEST_F(VkLayerTest, CreateBufferViewNoMemoryBoundToBuffer) {
7736 TEST_DESCRIPTION("Attempt to create a buffer view with a buffer that has"
7737 " no memory bound to it.");
7738
7739 VkResult err;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007740 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "used without first calling vkBindBufferMemory");
Mark Youngd339ba32016-05-30 13:28:35 -06007741
7742 ASSERT_NO_FATAL_FAILURE(InitState());
7743
7744 // Create a buffer with no bound memory and then attempt to create
7745 // a buffer view.
7746 VkBufferCreateInfo buff_ci = {};
7747 buff_ci.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
Chris Forbes4538d242016-09-13 18:13:58 +12007748 buff_ci.usage = VK_BUFFER_USAGE_UNIFORM_TEXEL_BUFFER_BIT;
Mark Youngd339ba32016-05-30 13:28:35 -06007749 buff_ci.size = 256;
7750 buff_ci.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
7751 VkBuffer buffer;
7752 err = vkCreateBuffer(m_device->device(), &buff_ci, NULL, &buffer);
7753 ASSERT_VK_SUCCESS(err);
7754
7755 VkBufferViewCreateInfo buff_view_ci = {};
7756 buff_view_ci.sType = VK_STRUCTURE_TYPE_BUFFER_VIEW_CREATE_INFO;
7757 buff_view_ci.buffer = buffer;
7758 buff_view_ci.format = VK_FORMAT_R8_UNORM;
7759 buff_view_ci.range = VK_WHOLE_SIZE;
7760 VkBufferView buff_view;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007761 err = vkCreateBufferView(m_device->device(), &buff_view_ci, NULL, &buff_view);
Mark Youngd339ba32016-05-30 13:28:35 -06007762
7763 m_errorMonitor->VerifyFound();
7764 vkDestroyBuffer(m_device->device(), buffer, NULL);
7765 // If last error is success, it still created the view, so delete it.
7766 if (err == VK_SUCCESS) {
7767 vkDestroyBufferView(m_device->device(), buff_view, NULL);
7768 }
7769}
7770
Karl Schultz6addd812016-02-02 17:17:23 -07007771TEST_F(VkLayerTest, InvalidDynamicOffsetCases) {
7772 // Create a descriptorSet w/ dynamic descriptor and then hit 3 offset error
7773 // cases:
Tobin Ehlisf6585052015-12-17 11:48:42 -07007774 // 1. No dynamicOffset supplied
7775 // 2. Too many dynamicOffsets supplied
7776 // 3. Dynamic offset oversteps buffer being updated
Karl Schultz6addd812016-02-02 17:17:23 -07007777 VkResult err;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007778 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " requires 1 dynamicOffsets, but only "
7779 "0 dynamicOffsets are left in "
7780 "pDynamicOffsets ");
Tobin Ehlis49f903e2015-11-04 13:30:34 -07007781
7782 ASSERT_NO_FATAL_FAILURE(InitState());
7783 ASSERT_NO_FATAL_FAILURE(InitViewport());
7784 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
7785
7786 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007787 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
7788 ds_type_count.descriptorCount = 1;
Tobin Ehlis49f903e2015-11-04 13:30:34 -07007789
7790 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007791 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
7792 ds_pool_ci.pNext = NULL;
7793 ds_pool_ci.maxSets = 1;
7794 ds_pool_ci.poolSizeCount = 1;
7795 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlis49f903e2015-11-04 13:30:34 -07007796
7797 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007798 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis49f903e2015-11-04 13:30:34 -07007799 ASSERT_VK_SUCCESS(err);
7800
7801 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007802 dsl_binding.binding = 0;
7803 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
7804 dsl_binding.descriptorCount = 1;
7805 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
7806 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis49f903e2015-11-04 13:30:34 -07007807
7808 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007809 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
7810 ds_layout_ci.pNext = NULL;
7811 ds_layout_ci.bindingCount = 1;
7812 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlis49f903e2015-11-04 13:30:34 -07007813 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007814 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis49f903e2015-11-04 13:30:34 -07007815 ASSERT_VK_SUCCESS(err);
7816
7817 VkDescriptorSet descriptorSet;
7818 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08007819 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07007820 alloc_info.descriptorSetCount = 1;
Tobin Ehlis49f903e2015-11-04 13:30:34 -07007821 alloc_info.descriptorPool = ds_pool;
7822 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007823 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis49f903e2015-11-04 13:30:34 -07007824 ASSERT_VK_SUCCESS(err);
7825
7826 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007827 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
7828 pipeline_layout_ci.pNext = NULL;
7829 pipeline_layout_ci.setLayoutCount = 1;
7830 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlis49f903e2015-11-04 13:30:34 -07007831
7832 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007833 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis49f903e2015-11-04 13:30:34 -07007834 ASSERT_VK_SUCCESS(err);
7835
7836 // Create a buffer to update the descriptor with
7837 uint32_t qfi = 0;
7838 VkBufferCreateInfo buffCI = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007839 buffCI.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
7840 buffCI.size = 1024;
7841 buffCI.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
7842 buffCI.queueFamilyIndexCount = 1;
7843 buffCI.pQueueFamilyIndices = &qfi;
Tobin Ehlis49f903e2015-11-04 13:30:34 -07007844
7845 VkBuffer dyub;
7846 err = vkCreateBuffer(m_device->device(), &buffCI, NULL, &dyub);
7847 ASSERT_VK_SUCCESS(err);
Tobin Ehlis0a43bde2016-05-03 08:31:08 -06007848 // Allocate memory and bind to buffer so we can make it to the appropriate
7849 // error
7850 VkMemoryAllocateInfo mem_alloc = {};
7851 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
7852 mem_alloc.pNext = NULL;
7853 mem_alloc.allocationSize = 1024;
Chris Forbesb6116cc2016-05-08 11:39:59 +12007854 mem_alloc.memoryTypeIndex = 0;
7855
7856 VkMemoryRequirements memReqs;
7857 vkGetBufferMemoryRequirements(m_device->device(), dyub, &memReqs);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007858 bool pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &mem_alloc, 0);
Chris Forbesb6116cc2016-05-08 11:39:59 +12007859 if (!pass) {
7860 vkDestroyBuffer(m_device->device(), dyub, NULL);
7861 return;
7862 }
7863
Tobin Ehlis0a43bde2016-05-03 08:31:08 -06007864 VkDeviceMemory mem;
7865 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem);
7866 ASSERT_VK_SUCCESS(err);
7867 err = vkBindBufferMemory(m_device->device(), dyub, mem, 0);
7868 ASSERT_VK_SUCCESS(err);
Tobin Ehlis49f903e2015-11-04 13:30:34 -07007869 // Correctly update descriptor to avoid "NOT_UPDATED" error
7870 VkDescriptorBufferInfo buffInfo = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007871 buffInfo.buffer = dyub;
7872 buffInfo.offset = 0;
7873 buffInfo.range = 1024;
Tobin Ehlis49f903e2015-11-04 13:30:34 -07007874
7875 VkWriteDescriptorSet descriptor_write;
7876 memset(&descriptor_write, 0, sizeof(descriptor_write));
7877 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
7878 descriptor_write.dstSet = descriptorSet;
7879 descriptor_write.dstBinding = 0;
7880 descriptor_write.descriptorCount = 1;
7881 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
7882 descriptor_write.pBufferInfo = &buffInfo;
7883
7884 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
7885
7886 BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007887 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
7888 &descriptorSet, 0, NULL);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007889 m_errorMonitor->VerifyFound();
Tobin Ehlisf6585052015-12-17 11:48:42 -07007890 uint32_t pDynOff[2] = {512, 756};
7891 // Now cause error b/c too many dynOffsets in array for # of dyn descriptors
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007892 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
7893 "Attempting to bind 1 descriptorSets with 1 dynamic descriptors, but ");
7894 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
7895 &descriptorSet, 2, pDynOff);
Chris Forbes7b342802016-04-07 13:20:10 +12007896 m_errorMonitor->VerifyFound();
Tobin Ehlisf6585052015-12-17 11:48:42 -07007897 // Finally cause error due to dynamicOffset being too big
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007898 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " dynamic offset 512 combined with "
7899 "offset 0 and range 1024 that "
7900 "oversteps the buffer size of 1024");
Tobin Ehlisf6585052015-12-17 11:48:42 -07007901 // Create PSO to be used for draw-time errors below
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007902 char const *vsSource = "#version 450\n"
7903 "\n"
7904 "out gl_PerVertex { \n"
7905 " vec4 gl_Position;\n"
7906 "};\n"
7907 "void main(){\n"
7908 " gl_Position = vec4(1);\n"
7909 "}\n";
7910 char const *fsSource = "#version 450\n"
7911 "\n"
7912 "layout(location=0) out vec4 x;\n"
7913 "layout(set=0) layout(binding=0) uniform foo { int x; int y; } bar;\n"
7914 "void main(){\n"
7915 " x = vec4(bar.y);\n"
7916 "}\n";
Tobin Ehlisf6585052015-12-17 11:48:42 -07007917 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
7918 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
7919 VkPipelineObj pipe(m_device);
7920 pipe.AddShader(&vs);
7921 pipe.AddShader(&fs);
7922 pipe.AddColorAttachment();
7923 pipe.CreateVKPipeline(pipeline_layout, renderPass());
7924
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007925 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Karl Schultz6addd812016-02-02 17:17:23 -07007926 // This update should succeed, but offset size of 512 will overstep buffer
7927 // /w range 1024 & size 1024
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007928 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
7929 &descriptorSet, 1, pDynOff);
Tobin Ehlisf6585052015-12-17 11:48:42 -07007930 Draw(1, 0, 0, 0);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007931 m_errorMonitor->VerifyFound();
Tobin Ehlis49f903e2015-11-04 13:30:34 -07007932
Tobin Ehlis0a43bde2016-05-03 08:31:08 -06007933 vkDestroyBuffer(m_device->device(), dyub, NULL);
Tobin Ehlis512098e2016-05-05 09:06:12 -06007934 vkFreeMemory(m_device->device(), mem, NULL);
Tobin Ehlis0a43bde2016-05-03 08:31:08 -06007935
Tobin Ehlis49f903e2015-11-04 13:30:34 -07007936 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
Tony Barbourdf4c0042016-06-01 15:55:43 -06007937 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
Tobin Ehlis49f903e2015-11-04 13:30:34 -07007938 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
7939}
7940
Tobin Ehlis8ef479c2016-07-20 16:14:49 -06007941TEST_F(VkLayerTest, DescriptorBufferUpdateNoMemoryBound) {
7942 TEST_DESCRIPTION("Attempt to update a descriptor with a non-sparse buffer "
7943 "that doesn't have memory bound");
7944 VkResult err;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007945 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " used without first calling vkBindBufferMemory.");
Tobin Ehlis8ef479c2016-07-20 16:14:49 -06007946
7947 ASSERT_NO_FATAL_FAILURE(InitState());
7948 ASSERT_NO_FATAL_FAILURE(InitViewport());
7949 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
7950
7951 VkDescriptorPoolSize ds_type_count = {};
7952 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
7953 ds_type_count.descriptorCount = 1;
7954
7955 VkDescriptorPoolCreateInfo ds_pool_ci = {};
7956 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
7957 ds_pool_ci.pNext = NULL;
7958 ds_pool_ci.maxSets = 1;
7959 ds_pool_ci.poolSizeCount = 1;
7960 ds_pool_ci.pPoolSizes = &ds_type_count;
7961
7962 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007963 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis8ef479c2016-07-20 16:14:49 -06007964 ASSERT_VK_SUCCESS(err);
7965
7966 VkDescriptorSetLayoutBinding dsl_binding = {};
7967 dsl_binding.binding = 0;
7968 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
7969 dsl_binding.descriptorCount = 1;
7970 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
7971 dsl_binding.pImmutableSamplers = NULL;
7972
7973 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
7974 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
7975 ds_layout_ci.pNext = NULL;
7976 ds_layout_ci.bindingCount = 1;
7977 ds_layout_ci.pBindings = &dsl_binding;
7978 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007979 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis8ef479c2016-07-20 16:14:49 -06007980 ASSERT_VK_SUCCESS(err);
7981
7982 VkDescriptorSet descriptorSet;
7983 VkDescriptorSetAllocateInfo alloc_info = {};
7984 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
7985 alloc_info.descriptorSetCount = 1;
7986 alloc_info.descriptorPool = ds_pool;
7987 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007988 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis8ef479c2016-07-20 16:14:49 -06007989 ASSERT_VK_SUCCESS(err);
7990
7991 // Create a buffer to update the descriptor with
7992 uint32_t qfi = 0;
7993 VkBufferCreateInfo buffCI = {};
7994 buffCI.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
7995 buffCI.size = 1024;
7996 buffCI.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
7997 buffCI.queueFamilyIndexCount = 1;
7998 buffCI.pQueueFamilyIndices = &qfi;
7999
8000 VkBuffer dyub;
8001 err = vkCreateBuffer(m_device->device(), &buffCI, NULL, &dyub);
8002 ASSERT_VK_SUCCESS(err);
8003
8004 // Attempt to update descriptor without binding memory to it
8005 VkDescriptorBufferInfo buffInfo = {};
8006 buffInfo.buffer = dyub;
8007 buffInfo.offset = 0;
8008 buffInfo.range = 1024;
8009
8010 VkWriteDescriptorSet descriptor_write;
8011 memset(&descriptor_write, 0, sizeof(descriptor_write));
8012 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
8013 descriptor_write.dstSet = descriptorSet;
8014 descriptor_write.dstBinding = 0;
8015 descriptor_write.descriptorCount = 1;
8016 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
8017 descriptor_write.pBufferInfo = &buffInfo;
8018
8019 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
8020 m_errorMonitor->VerifyFound();
8021
8022 vkDestroyBuffer(m_device->device(), dyub, NULL);
8023 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
8024 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
8025}
8026
Tobin Ehlis3a23b6a2016-02-17 10:35:18 -07008027TEST_F(VkLayerTest, InvalidPushConstants) {
Tobin Ehlis3a23b6a2016-02-17 10:35:18 -07008028 VkResult err;
Tobin Ehlis3a23b6a2016-02-17 10:35:18 -07008029 ASSERT_NO_FATAL_FAILURE(InitState());
8030 ASSERT_NO_FATAL_FAILURE(InitViewport());
8031 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
8032
Karl Schultzfc8eaf12016-05-06 13:56:42 -06008033 VkPipelineLayout pipeline_layout;
Tobin Ehlis3a23b6a2016-02-17 10:35:18 -07008034 VkPushConstantRange pc_range = {};
Tobin Ehlis3a23b6a2016-02-17 10:35:18 -07008035 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
8036 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
8037 pipeline_layout_ci.pushConstantRangeCount = 1;
8038 pipeline_layout_ci.pPushConstantRanges = &pc_range;
8039
Karl Schultzfc8eaf12016-05-06 13:56:42 -06008040 //
8041 // Check for invalid push constant ranges in pipeline layouts.
8042 //
8043 struct PipelineLayoutTestCase {
Karl Schultzc81037d2016-05-12 08:11:23 -06008044 VkPushConstantRange const range;
Karl Schultzfc8eaf12016-05-06 13:56:42 -06008045 char const *msg;
8046 };
Tobin Ehlis3a23b6a2016-02-17 10:35:18 -07008047
Karl Schultzc81037d2016-05-12 08:11:23 -06008048 const uint32_t too_big = m_device->props.limits.maxPushConstantsSize + 0x4;
8049 const std::array<PipelineLayoutTestCase, 10> range_tests = {{
8050 {{VK_SHADER_STAGE_VERTEX_BIT, 0, 0},
8051 "vkCreatePipelineLayout() call has push constants index 0 with "
8052 "size 0."},
8053 {{VK_SHADER_STAGE_VERTEX_BIT, 0, 1},
8054 "vkCreatePipelineLayout() call has push constants index 0 with "
8055 "size 1."},
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06008056 {{VK_SHADER_STAGE_VERTEX_BIT, 4, 1},
Karl Schultzc81037d2016-05-12 08:11:23 -06008057 "vkCreatePipelineLayout() call has push constants index 0 with "
8058 "size 1."},
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06008059 {{VK_SHADER_STAGE_VERTEX_BIT, 4, 0},
Karl Schultzc81037d2016-05-12 08:11:23 -06008060 "vkCreatePipelineLayout() call has push constants index 0 with "
8061 "size 0."},
8062 {{VK_SHADER_STAGE_VERTEX_BIT, 1, 4},
8063 "vkCreatePipelineLayout() call has push constants index 0 with "
8064 "offset 1. Offset must"},
8065 {{VK_SHADER_STAGE_VERTEX_BIT, 0, too_big},
8066 "vkCreatePipelineLayout() call has push constants index 0 "
8067 "with offset "},
8068 {{VK_SHADER_STAGE_VERTEX_BIT, too_big, too_big},
8069 "vkCreatePipelineLayout() call has push constants "
8070 "index 0 with offset "},
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06008071 {{VK_SHADER_STAGE_VERTEX_BIT, too_big, 4},
Karl Schultzc81037d2016-05-12 08:11:23 -06008072 "vkCreatePipelineLayout() call has push constants index 0 "
8073 "with offset "},
8074 {{VK_SHADER_STAGE_VERTEX_BIT, 0xFFFFFFF0, 0x00000020},
8075 "vkCreatePipelineLayout() call has push "
8076 "constants index 0 with offset "},
8077 {{VK_SHADER_STAGE_VERTEX_BIT, 0x00000020, 0xFFFFFFF0},
8078 "vkCreatePipelineLayout() call has push "
8079 "constants index 0 with offset "},
Karl Schultzfc8eaf12016-05-06 13:56:42 -06008080 }};
8081
8082 // Check for invalid offset and size
Karl Schultzc81037d2016-05-12 08:11:23 -06008083 for (const auto &iter : range_tests) {
8084 pc_range = iter.range;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008085 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, iter.msg);
8086 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Karl Schultzfc8eaf12016-05-06 13:56:42 -06008087 m_errorMonitor->VerifyFound();
8088 if (VK_SUCCESS == err) {
8089 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
8090 }
8091 }
8092
8093 // Check for invalid stage flag
8094 pc_range.offset = 0;
8095 pc_range.size = 16;
8096 pc_range.stageFlags = 0;
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06008097 m_errorMonitor->SetDesiredFailureMsg(
8098 VK_DEBUG_REPORT_ERROR_BIT_EXT,
8099 "vkCreatePipelineLayout: value of pCreateInfo->pPushConstantRanges[0].stageFlags must not be 0");
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008100 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008101 m_errorMonitor->VerifyFound();
Karl Schultzfc8eaf12016-05-06 13:56:42 -06008102 if (VK_SUCCESS == err) {
8103 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
8104 }
8105
8106 // Check for overlapping ranges
Karl Schultzc81037d2016-05-12 08:11:23 -06008107 const uint32_t ranges_per_test = 5;
Karl Schultzfc8eaf12016-05-06 13:56:42 -06008108 struct OverlappingRangeTestCase {
Karl Schultzc81037d2016-05-12 08:11:23 -06008109 VkPushConstantRange const ranges[ranges_per_test];
Karl Schultzfc8eaf12016-05-06 13:56:42 -06008110 char const *msg;
8111 };
8112
Karl Schultzc81037d2016-05-12 08:11:23 -06008113 const std::array<OverlappingRangeTestCase, 5> overlapping_range_tests = {
Karl Schultzfc8eaf12016-05-06 13:56:42 -06008114 {{{{VK_SHADER_STAGE_VERTEX_BIT, 0, 4},
8115 {VK_SHADER_STAGE_VERTEX_BIT, 0, 4},
8116 {VK_SHADER_STAGE_VERTEX_BIT, 0, 4},
8117 {VK_SHADER_STAGE_VERTEX_BIT, 0, 4},
8118 {VK_SHADER_STAGE_VERTEX_BIT, 0, 4}},
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06008119 "vkCreatePipelineLayout() call has push constants with overlapping ranges:"},
Karl Schultzfc8eaf12016-05-06 13:56:42 -06008120 {
8121 {{VK_SHADER_STAGE_VERTEX_BIT, 0, 4},
8122 {VK_SHADER_STAGE_VERTEX_BIT, 4, 4},
8123 {VK_SHADER_STAGE_VERTEX_BIT, 8, 4},
8124 {VK_SHADER_STAGE_VERTEX_BIT, 12, 8},
8125 {VK_SHADER_STAGE_VERTEX_BIT, 16, 4}},
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06008126 "vkCreatePipelineLayout() call has push constants with overlapping ranges: 3:[12, 20), 4:[16, 20)",
Karl Schultzfc8eaf12016-05-06 13:56:42 -06008127 },
8128 {
8129 {{VK_SHADER_STAGE_VERTEX_BIT, 16, 4},
8130 {VK_SHADER_STAGE_VERTEX_BIT, 12, 8},
8131 {VK_SHADER_STAGE_VERTEX_BIT, 8, 4},
8132 {VK_SHADER_STAGE_VERTEX_BIT, 4, 4},
8133 {VK_SHADER_STAGE_VERTEX_BIT, 0, 4}},
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06008134 "vkCreatePipelineLayout() call has push constants with overlapping ranges: 0:[16, 20), 1:[12, 20)",
Karl Schultzfc8eaf12016-05-06 13:56:42 -06008135 },
8136 {
8137 {{VK_SHADER_STAGE_VERTEX_BIT, 16, 4},
8138 {VK_SHADER_STAGE_VERTEX_BIT, 8, 4},
8139 {VK_SHADER_STAGE_VERTEX_BIT, 4, 4},
8140 {VK_SHADER_STAGE_VERTEX_BIT, 12, 8},
8141 {VK_SHADER_STAGE_VERTEX_BIT, 0, 4}},
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06008142 "vkCreatePipelineLayout() call has push constants with overlapping ranges: 0:[16, 20), 3:[12, 20)",
Karl Schultzfc8eaf12016-05-06 13:56:42 -06008143 },
8144 {
8145 {{VK_SHADER_STAGE_VERTEX_BIT, 16, 4},
8146 {VK_SHADER_STAGE_VERTEX_BIT, 32, 4},
8147 {VK_SHADER_STAGE_VERTEX_BIT, 4, 96},
8148 {VK_SHADER_STAGE_VERTEX_BIT, 40, 8},
8149 {VK_SHADER_STAGE_VERTEX_BIT, 52, 4}},
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06008150 "vkCreatePipelineLayout() call has push constants with overlapping ranges:",
Karl Schultzfc8eaf12016-05-06 13:56:42 -06008151 }}};
Karl Schultzfc8eaf12016-05-06 13:56:42 -06008152
Karl Schultzc81037d2016-05-12 08:11:23 -06008153 for (const auto &iter : overlapping_range_tests) {
Karl Schultzfc8eaf12016-05-06 13:56:42 -06008154 pipeline_layout_ci.pPushConstantRanges = iter.ranges;
Karl Schultzc81037d2016-05-12 08:11:23 -06008155 pipeline_layout_ci.pushConstantRangeCount = ranges_per_test;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008156 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT, iter.msg);
8157 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Karl Schultzfc8eaf12016-05-06 13:56:42 -06008158 m_errorMonitor->VerifyFound();
8159 if (VK_SUCCESS == err) {
8160 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
8161 }
8162 }
8163
8164 // Run some positive tests to make sure overlap checking in the layer is OK
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008165 const std::array<OverlappingRangeTestCase, 2> overlapping_range_tests_pos = {{{{{VK_SHADER_STAGE_VERTEX_BIT, 0, 4},
8166 {VK_SHADER_STAGE_VERTEX_BIT, 4, 4},
8167 {VK_SHADER_STAGE_VERTEX_BIT, 8, 4},
8168 {VK_SHADER_STAGE_VERTEX_BIT, 12, 4},
8169 {VK_SHADER_STAGE_VERTEX_BIT, 16, 4}},
8170 ""},
8171 {{{VK_SHADER_STAGE_VERTEX_BIT, 92, 24},
8172 {VK_SHADER_STAGE_VERTEX_BIT, 80, 4},
8173 {VK_SHADER_STAGE_VERTEX_BIT, 64, 8},
8174 {VK_SHADER_STAGE_VERTEX_BIT, 4, 16},
8175 {VK_SHADER_STAGE_VERTEX_BIT, 0, 4}},
8176 ""}}};
Karl Schultzc81037d2016-05-12 08:11:23 -06008177 for (const auto &iter : overlapping_range_tests_pos) {
Karl Schultzfc8eaf12016-05-06 13:56:42 -06008178 pipeline_layout_ci.pPushConstantRanges = iter.ranges;
8179 m_errorMonitor->ExpectSuccess();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008180 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Karl Schultzfc8eaf12016-05-06 13:56:42 -06008181 m_errorMonitor->VerifyNotFound();
8182 if (VK_SUCCESS == err) {
8183 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
8184 }
8185 }
8186
8187 //
8188 // CmdPushConstants tests
8189 //
Karl Schultzc81037d2016-05-12 08:11:23 -06008190 const uint8_t dummy_values[100] = {};
Karl Schultzfc8eaf12016-05-06 13:56:42 -06008191
8192 // Check for invalid offset and size and if range is within layout range(s)
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06008193 const std::array<PipelineLayoutTestCase, 11> cmd_range_tests = {{
8194 {{VK_SHADER_STAGE_VERTEX_BIT, 0, 0}, "vkCmdPushConstants: parameter size must be greater than 0"},
Karl Schultzc81037d2016-05-12 08:11:23 -06008195 {{VK_SHADER_STAGE_VERTEX_BIT, 0, 1},
8196 "vkCmdPushConstants() call has push constants with size 1. Size "
8197 "must be greater than zero and a multiple of 4."},
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06008198 {{VK_SHADER_STAGE_VERTEX_BIT, 4, 1},
Karl Schultzc81037d2016-05-12 08:11:23 -06008199 "vkCmdPushConstants() call has push constants with size 1. Size "
8200 "must be greater than zero and a multiple of 4."},
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06008201 {{VK_SHADER_STAGE_VERTEX_BIT, 1, 4},
Karl Schultzc81037d2016-05-12 08:11:23 -06008202 "vkCmdPushConstants() call has push constants with offset 1. "
8203 "Offset must be a multiple of 4."},
8204 {{VK_SHADER_STAGE_VERTEX_BIT, 1, 4},
8205 "vkCmdPushConstants() call has push constants with offset 1. "
8206 "Offset must be a multiple of 4."},
8207 {{VK_SHADER_STAGE_VERTEX_BIT, 0, 20},
8208 "vkCmdPushConstants() Push constant range [0, 20) with stageFlags = "
8209 "0x1 not within flag-matching ranges in pipeline layout"},
8210 {{VK_SHADER_STAGE_VERTEX_BIT, 60, 8},
8211 "vkCmdPushConstants() Push constant range [60, 68) with stageFlags = "
8212 "0x1 not within flag-matching ranges in pipeline layout"},
8213 {{VK_SHADER_STAGE_VERTEX_BIT, 76, 8},
8214 "vkCmdPushConstants() Push constant range [76, 84) with stageFlags = "
8215 "0x1 not within flag-matching ranges in pipeline layout"},
8216 {{VK_SHADER_STAGE_VERTEX_BIT, 0, 80},
8217 "vkCmdPushConstants() Push constant range [0, 80) with stageFlags = "
8218 "0x1 not within flag-matching ranges in pipeline layout"},
8219 {{VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT, 0, 4},
8220 "vkCmdPushConstants() stageFlags = 0x2 do not match the stageFlags in "
8221 "any of the ranges in pipeline layout"},
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008222 {{VK_SHADER_STAGE_VERTEX_BIT | VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT, 0, 16},
Karl Schultzc81037d2016-05-12 08:11:23 -06008223 "vkCmdPushConstants() stageFlags = 0x3 do not match the stageFlags in "
8224 "any of the ranges in pipeline layout"},
Karl Schultzfc8eaf12016-05-06 13:56:42 -06008225 }};
8226
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06008227 BeginCommandBuffer();
8228
8229 // Setup ranges: [0,16) [64,80)
Karl Schultzc81037d2016-05-12 08:11:23 -06008230 const VkPushConstantRange pc_range2[] = {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008231 {VK_SHADER_STAGE_VERTEX_BIT, 64, 16}, {VK_SHADER_STAGE_VERTEX_BIT, 0, 16},
Karl Schultzfc8eaf12016-05-06 13:56:42 -06008232 };
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008233 pipeline_layout_ci.pushConstantRangeCount = sizeof(pc_range2) / sizeof(VkPushConstantRange);
Karl Schultzfc8eaf12016-05-06 13:56:42 -06008234 pipeline_layout_ci.pPushConstantRanges = pc_range2;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008235 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis3a23b6a2016-02-17 10:35:18 -07008236 ASSERT_VK_SUCCESS(err);
Karl Schultzc81037d2016-05-12 08:11:23 -06008237 for (const auto &iter : cmd_range_tests) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008238 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, iter.msg);
8239 vkCmdPushConstants(m_commandBuffer->GetBufferHandle(), pipeline_layout, iter.range.stageFlags, iter.range.offset,
Karl Schultzc81037d2016-05-12 08:11:23 -06008240 iter.range.size, dummy_values);
Karl Schultzfc8eaf12016-05-06 13:56:42 -06008241 m_errorMonitor->VerifyFound();
8242 }
8243
8244 // Check for invalid stage flag
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06008245 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "vkCmdPushConstants: value of stageFlags must not be 0");
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008246 vkCmdPushConstants(m_commandBuffer->GetBufferHandle(), pipeline_layout, 0, 0, 16, dummy_values);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008247 m_errorMonitor->VerifyFound();
Karl Schultzc81037d2016-05-12 08:11:23 -06008248 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
Karl Schultzfc8eaf12016-05-06 13:56:42 -06008249
Karl Schultzc81037d2016-05-12 08:11:23 -06008250 // overlapping range tests with cmd
8251 const std::array<PipelineLayoutTestCase, 3> cmd_overlap_tests = {{
8252 {{VK_SHADER_STAGE_VERTEX_BIT, 0, 20},
8253 "vkCmdPushConstants() Push constant range [0, 20) with stageFlags = "
8254 "0x1 not within flag-matching ranges in pipeline layout"},
8255 {{VK_SHADER_STAGE_VERTEX_BIT, 16, 4},
8256 "vkCmdPushConstants() Push constant range [16, 20) with stageFlags = "
8257 "0x1 not within flag-matching ranges in pipeline layout"},
8258 {{VK_SHADER_STAGE_VERTEX_BIT, 40, 16},
8259 "vkCmdPushConstants() Push constant range [40, 56) with stageFlags = "
8260 "0x1 not within flag-matching ranges in pipeline layout"},
8261 }};
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06008262 // Setup ranges: [0,16), [20,36), [36,44), [44,52), [80,92)
Karl Schultzc81037d2016-05-12 08:11:23 -06008263 const VkPushConstantRange pc_range3[] = {
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06008264 {VK_SHADER_STAGE_VERTEX_BIT, 20, 16}, {VK_SHADER_STAGE_VERTEX_BIT, 0, 16}, {VK_SHADER_STAGE_VERTEX_BIT, 44, 8},
8265 {VK_SHADER_STAGE_VERTEX_BIT, 80, 12}, {VK_SHADER_STAGE_VERTEX_BIT, 36, 8},
Karl Schultzc81037d2016-05-12 08:11:23 -06008266 };
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008267 pipeline_layout_ci.pushConstantRangeCount = sizeof(pc_range3) / sizeof(VkPushConstantRange);
Karl Schultzc81037d2016-05-12 08:11:23 -06008268 pipeline_layout_ci.pPushConstantRanges = pc_range3;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008269 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Karl Schultzc81037d2016-05-12 08:11:23 -06008270 ASSERT_VK_SUCCESS(err);
Karl Schultzc81037d2016-05-12 08:11:23 -06008271 for (const auto &iter : cmd_overlap_tests) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008272 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, iter.msg);
8273 vkCmdPushConstants(m_commandBuffer->GetBufferHandle(), pipeline_layout, iter.range.stageFlags, iter.range.offset,
Karl Schultzc81037d2016-05-12 08:11:23 -06008274 iter.range.size, dummy_values);
8275 m_errorMonitor->VerifyFound();
8276 }
Karl Schultzc81037d2016-05-12 08:11:23 -06008277 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
8278
8279 // positive overlapping range tests with cmd
8280 const std::array<PipelineLayoutTestCase, 4> cmd_overlap_tests_pos = {{
8281 {{VK_SHADER_STAGE_VERTEX_BIT, 0, 16}, ""},
8282 {{VK_SHADER_STAGE_VERTEX_BIT, 0, 4}, ""},
8283 {{VK_SHADER_STAGE_VERTEX_BIT, 20, 12}, ""},
8284 {{VK_SHADER_STAGE_VERTEX_BIT, 56, 36}, ""},
8285 }};
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06008286 // Setup ranges: [0,16) [20,36) [36,44) [44,52) [56,80) [80,92)
Karl Schultzc81037d2016-05-12 08:11:23 -06008287 const VkPushConstantRange pc_range4[] = {
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06008288 {VK_SHADER_STAGE_VERTEX_BIT, 20, 16}, {VK_SHADER_STAGE_VERTEX_BIT, 0, 16}, {VK_SHADER_STAGE_VERTEX_BIT, 44, 8},
8289 {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 -06008290 };
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008291 pipeline_layout_ci.pushConstantRangeCount = sizeof(pc_range4) / sizeof(VkPushConstantRange);
Karl Schultzc81037d2016-05-12 08:11:23 -06008292 pipeline_layout_ci.pPushConstantRanges = pc_range4;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008293 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Karl Schultzc81037d2016-05-12 08:11:23 -06008294 ASSERT_VK_SUCCESS(err);
Karl Schultzc81037d2016-05-12 08:11:23 -06008295 for (const auto &iter : cmd_overlap_tests_pos) {
8296 m_errorMonitor->ExpectSuccess();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008297 vkCmdPushConstants(m_commandBuffer->GetBufferHandle(), pipeline_layout, iter.range.stageFlags, iter.range.offset,
Karl Schultzc81037d2016-05-12 08:11:23 -06008298 iter.range.size, dummy_values);
8299 m_errorMonitor->VerifyNotFound();
8300 }
Tobin Ehlis3a23b6a2016-02-17 10:35:18 -07008301 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06008302
8303 EndCommandBuffer();
Tobin Ehlis3a23b6a2016-02-17 10:35:18 -07008304}
8305
Karl Schultz6addd812016-02-02 17:17:23 -07008306TEST_F(VkLayerTest, DescriptorSetCompatibility) {
Tobin Ehlis559c6382015-11-05 09:52:49 -07008307 // Test various desriptorSet errors with bad binding combinations
Karl Schultz6addd812016-02-02 17:17:23 -07008308 VkResult err;
Tobin Ehlis559c6382015-11-05 09:52:49 -07008309
8310 ASSERT_NO_FATAL_FAILURE(InitState());
8311 ASSERT_NO_FATAL_FAILURE(InitViewport());
8312 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
8313
Mike Stroyanb8a61002016-06-20 16:00:28 -06008314 const VkFormat tex_format = VK_FORMAT_R8G8B8A8_UNORM;
8315 VkImageTiling tiling;
8316 VkFormatProperties format_properties;
8317 vkGetPhysicalDeviceFormatProperties(gpu(), tex_format, &format_properties);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008318 if (format_properties.linearTilingFeatures & VK_FORMAT_FEATURE_STORAGE_IMAGE_BIT) {
Mike Stroyanb8a61002016-06-20 16:00:28 -06008319 tiling = VK_IMAGE_TILING_LINEAR;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008320 } else if (format_properties.optimalTilingFeatures & VK_FORMAT_FEATURE_STORAGE_IMAGE_BIT) {
Mike Stroyanb8a61002016-06-20 16:00:28 -06008321 tiling = VK_IMAGE_TILING_OPTIMAL;
8322 } else {
8323 printf("Device does not support VK_FORMAT_FEATURE_STORAGE_IMAGE_BIT; "
8324 "skipped.\n");
8325 return;
8326 }
8327
Tobin Ehlis559c6382015-11-05 09:52:49 -07008328 static const uint32_t NUM_DESCRIPTOR_TYPES = 5;
8329 VkDescriptorPoolSize ds_type_count[NUM_DESCRIPTOR_TYPES] = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008330 ds_type_count[0].type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
8331 ds_type_count[0].descriptorCount = 10;
8332 ds_type_count[1].type = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE;
8333 ds_type_count[1].descriptorCount = 2;
8334 ds_type_count[2].type = VK_DESCRIPTOR_TYPE_STORAGE_IMAGE;
8335 ds_type_count[2].descriptorCount = 2;
8336 ds_type_count[3].type = VK_DESCRIPTOR_TYPE_SAMPLER;
8337 ds_type_count[3].descriptorCount = 5;
8338 // TODO : LunarG ILO driver currently asserts in desc.c w/ INPUT_ATTACHMENT
8339 // type
8340 // ds_type_count[4].type = VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT;
8341 ds_type_count[4].type = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
8342 ds_type_count[4].descriptorCount = 2;
Tobin Ehlis559c6382015-11-05 09:52:49 -07008343
8344 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008345 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
8346 ds_pool_ci.pNext = NULL;
8347 ds_pool_ci.maxSets = 5;
8348 ds_pool_ci.poolSizeCount = NUM_DESCRIPTOR_TYPES;
8349 ds_pool_ci.pPoolSizes = ds_type_count;
Tobin Ehlis559c6382015-11-05 09:52:49 -07008350
8351 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008352 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis559c6382015-11-05 09:52:49 -07008353 ASSERT_VK_SUCCESS(err);
8354
8355 static const uint32_t MAX_DS_TYPES_IN_LAYOUT = 2;
8356 VkDescriptorSetLayoutBinding dsl_binding[MAX_DS_TYPES_IN_LAYOUT] = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008357 dsl_binding[0].binding = 0;
8358 dsl_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
8359 dsl_binding[0].descriptorCount = 5;
8360 dsl_binding[0].stageFlags = VK_SHADER_STAGE_ALL;
8361 dsl_binding[0].pImmutableSamplers = NULL;
Tobin Ehlis559c6382015-11-05 09:52:49 -07008362
Tobin Ehlis8fab6562015-12-01 09:57:09 -07008363 // Create layout identical to set0 layout but w/ different stageFlags
8364 VkDescriptorSetLayoutBinding dsl_fs_stage_only = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008365 dsl_fs_stage_only.binding = 0;
8366 dsl_fs_stage_only.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
8367 dsl_fs_stage_only.descriptorCount = 5;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008368 dsl_fs_stage_only.stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT; // Different stageFlags to cause error at
8369 // bind time
Karl Schultz6addd812016-02-02 17:17:23 -07008370 dsl_fs_stage_only.pImmutableSamplers = NULL;
Tobin Ehlis559c6382015-11-05 09:52:49 -07008371 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008372 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
8373 ds_layout_ci.pNext = NULL;
8374 ds_layout_ci.bindingCount = 1;
8375 ds_layout_ci.pBindings = dsl_binding;
Tobin Ehlis559c6382015-11-05 09:52:49 -07008376 static const uint32_t NUM_LAYOUTS = 4;
8377 VkDescriptorSetLayout ds_layout[NUM_LAYOUTS] = {};
Tobin Ehlis8fab6562015-12-01 09:57:09 -07008378 VkDescriptorSetLayout ds_layout_fs_only = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008379 // Create 4 unique layouts for full pipelineLayout, and 1 special fs-only
8380 // layout for error case
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008381 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout[0]);
Tobin Ehlis559c6382015-11-05 09:52:49 -07008382 ASSERT_VK_SUCCESS(err);
Jon Ashburn6e23c1f2015-12-30 18:01:16 -07008383 ds_layout_ci.pBindings = &dsl_fs_stage_only;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008384 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout_fs_only);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07008385 ASSERT_VK_SUCCESS(err);
Tobin Ehlis559c6382015-11-05 09:52:49 -07008386 dsl_binding[0].binding = 0;
8387 dsl_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE;
Tobin Ehlis8fab6562015-12-01 09:57:09 -07008388 dsl_binding[0].descriptorCount = 2;
Mike Stroyan9c70cdb2016-01-06 14:14:17 -07008389 dsl_binding[1].binding = 1;
8390 dsl_binding[1].descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_IMAGE;
8391 dsl_binding[1].descriptorCount = 2;
8392 dsl_binding[1].stageFlags = VK_SHADER_STAGE_ALL;
8393 dsl_binding[1].pImmutableSamplers = NULL;
Jon Ashburn6e23c1f2015-12-30 18:01:16 -07008394 ds_layout_ci.pBindings = dsl_binding;
Tobin Ehlis559c6382015-11-05 09:52:49 -07008395 ds_layout_ci.bindingCount = 2;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008396 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout[1]);
Tobin Ehlis559c6382015-11-05 09:52:49 -07008397 ASSERT_VK_SUCCESS(err);
8398 dsl_binding[0].binding = 0;
8399 dsl_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
Tobin Ehlis8fab6562015-12-01 09:57:09 -07008400 dsl_binding[0].descriptorCount = 5;
Tobin Ehlis559c6382015-11-05 09:52:49 -07008401 ds_layout_ci.bindingCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008402 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout[2]);
Tobin Ehlis559c6382015-11-05 09:52:49 -07008403 ASSERT_VK_SUCCESS(err);
8404 dsl_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
Tobin Ehlis8fab6562015-12-01 09:57:09 -07008405 dsl_binding[0].descriptorCount = 2;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008406 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout[3]);
Tobin Ehlis559c6382015-11-05 09:52:49 -07008407 ASSERT_VK_SUCCESS(err);
8408
8409 static const uint32_t NUM_SETS = 4;
8410 VkDescriptorSet descriptorSet[NUM_SETS] = {};
8411 VkDescriptorSetAllocateInfo alloc_info = {};
Tobin Ehlis8fab6562015-12-01 09:57:09 -07008412 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07008413 alloc_info.descriptorSetCount = NUM_LAYOUTS;
Tobin Ehlis559c6382015-11-05 09:52:49 -07008414 alloc_info.descriptorPool = ds_pool;
8415 alloc_info.pSetLayouts = ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008416 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, descriptorSet);
Tobin Ehlis559c6382015-11-05 09:52:49 -07008417 ASSERT_VK_SUCCESS(err);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07008418 VkDescriptorSet ds0_fs_only = {};
Jon Ashburnf19916e2016-01-11 13:12:43 -07008419 alloc_info.descriptorSetCount = 1;
Tobin Ehlis8fab6562015-12-01 09:57:09 -07008420 alloc_info.pSetLayouts = &ds_layout_fs_only;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008421 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &ds0_fs_only);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07008422 ASSERT_VK_SUCCESS(err);
Tobin Ehlis559c6382015-11-05 09:52:49 -07008423
8424 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008425 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
8426 pipeline_layout_ci.pNext = NULL;
8427 pipeline_layout_ci.setLayoutCount = NUM_LAYOUTS;
8428 pipeline_layout_ci.pSetLayouts = ds_layout;
Tobin Ehlis559c6382015-11-05 09:52:49 -07008429
8430 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008431 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis559c6382015-11-05 09:52:49 -07008432 ASSERT_VK_SUCCESS(err);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07008433 // Create pipelineLayout with only one setLayout
8434 pipeline_layout_ci.setLayoutCount = 1;
8435 VkPipelineLayout single_pipe_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008436 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &single_pipe_layout);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07008437 ASSERT_VK_SUCCESS(err);
8438 // Create pipelineLayout with 2 descriptor setLayout at index 0
8439 pipeline_layout_ci.pSetLayouts = &ds_layout[3];
8440 VkPipelineLayout pipe_layout_one_desc;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008441 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipe_layout_one_desc);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07008442 ASSERT_VK_SUCCESS(err);
8443 // Create pipelineLayout with 5 SAMPLER descriptor setLayout at index 0
8444 pipeline_layout_ci.pSetLayouts = &ds_layout[2];
8445 VkPipelineLayout pipe_layout_five_samp;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008446 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipe_layout_five_samp);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07008447 ASSERT_VK_SUCCESS(err);
8448 // Create pipelineLayout with UB type, but stageFlags for FS only
8449 pipeline_layout_ci.pSetLayouts = &ds_layout_fs_only;
8450 VkPipelineLayout pipe_layout_fs_only;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008451 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipe_layout_fs_only);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07008452 ASSERT_VK_SUCCESS(err);
8453 // Create pipelineLayout w/ incompatible set0 layout, but set1 is fine
8454 VkDescriptorSetLayout pl_bad_s0[2] = {};
8455 pl_bad_s0[0] = ds_layout_fs_only;
8456 pl_bad_s0[1] = ds_layout[1];
8457 pipeline_layout_ci.setLayoutCount = 2;
8458 pipeline_layout_ci.pSetLayouts = pl_bad_s0;
8459 VkPipelineLayout pipe_layout_bad_set0;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008460 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipe_layout_bad_set0);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07008461 ASSERT_VK_SUCCESS(err);
Tobin Ehlis559c6382015-11-05 09:52:49 -07008462
8463 // Create a buffer to update the descriptor with
8464 uint32_t qfi = 0;
8465 VkBufferCreateInfo buffCI = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008466 buffCI.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
8467 buffCI.size = 1024;
8468 buffCI.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
8469 buffCI.queueFamilyIndexCount = 1;
8470 buffCI.pQueueFamilyIndices = &qfi;
Tobin Ehlis559c6382015-11-05 09:52:49 -07008471
8472 VkBuffer dyub;
8473 err = vkCreateBuffer(m_device->device(), &buffCI, NULL, &dyub);
8474 ASSERT_VK_SUCCESS(err);
8475 // Correctly update descriptor to avoid "NOT_UPDATED" error
8476 static const uint32_t NUM_BUFFS = 5;
8477 VkDescriptorBufferInfo buffInfo[NUM_BUFFS] = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008478 for (uint32_t i = 0; i < NUM_BUFFS; ++i) {
Tobin Ehlis559c6382015-11-05 09:52:49 -07008479 buffInfo[i].buffer = dyub;
8480 buffInfo[i].offset = 0;
8481 buffInfo[i].range = 1024;
8482 }
Karl Schultz6addd812016-02-02 17:17:23 -07008483 VkImage image;
Karl Schultz6addd812016-02-02 17:17:23 -07008484 const int32_t tex_width = 32;
8485 const int32_t tex_height = 32;
Tobin Ehlis8fab6562015-12-01 09:57:09 -07008486 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008487 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
8488 image_create_info.pNext = NULL;
8489 image_create_info.imageType = VK_IMAGE_TYPE_2D;
8490 image_create_info.format = tex_format;
8491 image_create_info.extent.width = tex_width;
8492 image_create_info.extent.height = tex_height;
8493 image_create_info.extent.depth = 1;
8494 image_create_info.mipLevels = 1;
8495 image_create_info.arrayLayers = 1;
8496 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
Mike Stroyanb8a61002016-06-20 16:00:28 -06008497 image_create_info.tiling = tiling;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008498 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT | VK_IMAGE_USAGE_STORAGE_BIT;
Karl Schultz6addd812016-02-02 17:17:23 -07008499 image_create_info.flags = 0;
Tobin Ehlis8fab6562015-12-01 09:57:09 -07008500 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
8501 ASSERT_VK_SUCCESS(err);
Tobin Ehlis559c6382015-11-05 09:52:49 -07008502
Karl Schultz6addd812016-02-02 17:17:23 -07008503 VkMemoryRequirements memReqs;
8504 VkDeviceMemory imageMem;
8505 bool pass;
Mike Stroyan9c70cdb2016-01-06 14:14:17 -07008506 VkMemoryAllocateInfo memAlloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008507 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
8508 memAlloc.pNext = NULL;
8509 memAlloc.allocationSize = 0;
8510 memAlloc.memoryTypeIndex = 0;
Mike Stroyan9c70cdb2016-01-06 14:14:17 -07008511 vkGetImageMemoryRequirements(m_device->device(), image, &memReqs);
8512 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008513 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Mike Stroyan9c70cdb2016-01-06 14:14:17 -07008514 ASSERT_TRUE(pass);
8515 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &imageMem);
8516 ASSERT_VK_SUCCESS(err);
8517 err = vkBindImageMemory(m_device->device(), image, imageMem, 0);
8518 ASSERT_VK_SUCCESS(err);
8519
Tobin Ehlis8fab6562015-12-01 09:57:09 -07008520 VkImageViewCreateInfo image_view_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008521 image_view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
8522 image_view_create_info.image = image;
8523 image_view_create_info.viewType = VK_IMAGE_VIEW_TYPE_2D;
8524 image_view_create_info.format = tex_format;
8525 image_view_create_info.subresourceRange.layerCount = 1;
8526 image_view_create_info.subresourceRange.baseMipLevel = 0;
8527 image_view_create_info.subresourceRange.levelCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008528 image_view_create_info.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Tobin Ehlis559c6382015-11-05 09:52:49 -07008529
Tobin Ehlis8fab6562015-12-01 09:57:09 -07008530 VkImageView view;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008531 err = vkCreateImageView(m_device->device(), &image_view_create_info, NULL, &view);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07008532 ASSERT_VK_SUCCESS(err);
Tobin Ehlis991d45a2016-01-06 08:48:41 -07008533 VkDescriptorImageInfo imageInfo[4] = {};
Tobin Ehlis8fab6562015-12-01 09:57:09 -07008534 imageInfo[0].imageView = view;
8535 imageInfo[0].imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
8536 imageInfo[1].imageView = view;
8537 imageInfo[1].imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
Tobin Ehlis991d45a2016-01-06 08:48:41 -07008538 imageInfo[2].imageView = view;
8539 imageInfo[2].imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
8540 imageInfo[3].imageView = view;
8541 imageInfo[3].imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
Tobin Ehlis8fab6562015-12-01 09:57:09 -07008542
8543 static const uint32_t NUM_SET_UPDATES = 3;
8544 VkWriteDescriptorSet descriptor_write[NUM_SET_UPDATES] = {};
8545 descriptor_write[0].sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
8546 descriptor_write[0].dstSet = descriptorSet[0];
8547 descriptor_write[0].dstBinding = 0;
8548 descriptor_write[0].descriptorCount = 5;
8549 descriptor_write[0].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
8550 descriptor_write[0].pBufferInfo = buffInfo;
8551 descriptor_write[1].sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
8552 descriptor_write[1].dstSet = descriptorSet[1];
8553 descriptor_write[1].dstBinding = 0;
8554 descriptor_write[1].descriptorCount = 2;
8555 descriptor_write[1].descriptorType = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE;
8556 descriptor_write[1].pImageInfo = imageInfo;
8557 descriptor_write[2].sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
8558 descriptor_write[2].dstSet = descriptorSet[1];
8559 descriptor_write[2].dstBinding = 1;
8560 descriptor_write[2].descriptorCount = 2;
8561 descriptor_write[2].descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_IMAGE;
Tobin Ehlis991d45a2016-01-06 08:48:41 -07008562 descriptor_write[2].pImageInfo = &imageInfo[2];
Tobin Ehlis8fab6562015-12-01 09:57:09 -07008563
8564 vkUpdateDescriptorSets(m_device->device(), 3, descriptor_write, 0, NULL);
Tobin Ehlis559c6382015-11-05 09:52:49 -07008565
Tobin Ehlis88452832015-12-03 09:40:56 -07008566 // Create PSO to be used for draw-time errors below
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008567 char const *vsSource = "#version 450\n"
8568 "\n"
8569 "out gl_PerVertex {\n"
8570 " vec4 gl_Position;\n"
8571 "};\n"
8572 "void main(){\n"
8573 " gl_Position = vec4(1);\n"
8574 "}\n";
8575 char const *fsSource = "#version 450\n"
8576 "\n"
8577 "layout(location=0) out vec4 x;\n"
8578 "layout(set=0) layout(binding=0) uniform foo { int x; int y; } bar;\n"
8579 "void main(){\n"
8580 " x = vec4(bar.y);\n"
8581 "}\n";
Tobin Ehlis88452832015-12-03 09:40:56 -07008582 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
8583 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Tobin Ehlis559c6382015-11-05 09:52:49 -07008584 VkPipelineObj pipe(m_device);
8585 pipe.AddShader(&vs);
8586 pipe.AddShader(&fs);
Tobin Ehlis88452832015-12-03 09:40:56 -07008587 pipe.AddColorAttachment();
8588 pipe.CreateVKPipeline(pipe_layout_fs_only, renderPass());
Tobin Ehlis559c6382015-11-05 09:52:49 -07008589
8590 BeginCommandBuffer();
Tobin Ehlis88452832015-12-03 09:40:56 -07008591
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008592 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Karl Schultz6addd812016-02-02 17:17:23 -07008593 // NOTE : I believe LunarG ilo driver has bug (LX#189) that requires binding
8594 // of PSO
8595 // here before binding DSs. Otherwise we assert in cmd_copy_dset_data() of
8596 // cmd_pipeline.c
8597 // due to the fact that cmd_alloc_dset_data() has not been called in
8598 // cmd_bind_graphics_pipeline()
8599 // TODO : Want to cause various binding incompatibility issues here to test
8600 // DrawState
Tobin Ehlis559c6382015-11-05 09:52:49 -07008601 // First cause various verify_layout_compatibility() fails
8602 // Second disturb early and late sets and verify INFO msgs
Tobin Ehlis8fab6562015-12-01 09:57:09 -07008603 // verify_set_layout_compatibility fail cases:
8604 // 1. invalid VkPipelineLayout (layout) passed into vkCmdBindDescriptorSets
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008605 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Invalid Pipeline Layout Object ");
8606 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS,
8607 (VkPipelineLayout)((size_t)0xbaadb1be), 0, 1, &descriptorSet[0], 0, NULL);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008608 m_errorMonitor->VerifyFound();
8609
Tobin Ehlis8fab6562015-12-01 09:57:09 -07008610 // 2. layoutIndex exceeds # of layouts in layout
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008611 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " attempting to bind set to index 1");
8612 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, single_pipe_layout, 0, 2,
8613 &descriptorSet[0], 0, NULL);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008614 m_errorMonitor->VerifyFound();
8615
Tobin Ehlis8fab6562015-12-01 09:57:09 -07008616 vkDestroyPipelineLayout(m_device->device(), single_pipe_layout, NULL);
Karl Schultz6addd812016-02-02 17:17:23 -07008617 // 3. Pipeline setLayout[0] has 2 descriptors, but set being bound has 5
8618 // descriptors
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008619 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " has 2 descriptors, but DescriptorSetLayout ");
8620 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe_layout_one_desc, 0, 1,
8621 &descriptorSet[0], 0, NULL);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008622 m_errorMonitor->VerifyFound();
8623
Tobin Ehlis8fab6562015-12-01 09:57:09 -07008624 vkDestroyPipelineLayout(m_device->device(), pipe_layout_one_desc, NULL);
8625 // 4. same # of descriptors but mismatch in type
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008626 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " is type 'VK_DESCRIPTOR_TYPE_SAMPLER' but binding ");
8627 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe_layout_five_samp, 0, 1,
8628 &descriptorSet[0], 0, NULL);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008629 m_errorMonitor->VerifyFound();
8630
Tobin Ehlis8fab6562015-12-01 09:57:09 -07008631 vkDestroyPipelineLayout(m_device->device(), pipe_layout_five_samp, NULL);
8632 // 5. same # of descriptors but mismatch in stageFlags
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008633 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
8634 " has stageFlags 16 but binding 0 for DescriptorSetLayout ");
8635 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe_layout_fs_only, 0, 1,
8636 &descriptorSet[0], 0, NULL);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008637 m_errorMonitor->VerifyFound();
8638
Tobin Ehlis8fab6562015-12-01 09:57:09 -07008639 // Cause INFO messages due to disturbing previously bound Sets
8640 // First bind sets 0 & 1
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008641 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 2,
8642 &descriptorSet[0], 0, NULL);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07008643 // 1. Disturb bound set0 by re-binding set1 w/ updated pipelineLayout
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008644 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT, " previously bound as set #0 was disturbed ");
8645 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe_layout_bad_set0, 1, 1,
8646 &descriptorSet[1], 0, NULL);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008647 m_errorMonitor->VerifyFound();
8648
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008649 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 2,
8650 &descriptorSet[0], 0, NULL);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07008651 // 2. Disturb set after last bound set
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008652 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT, " newly bound as set #0 so set #1 and "
8653 "any subsequent sets were disturbed ");
8654 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe_layout_fs_only, 0, 1,
8655 &ds0_fs_only, 0, NULL);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008656 m_errorMonitor->VerifyFound();
8657
Tobin Ehlis10fad692016-07-07 12:00:36 -06008658 // Now that we're done actively using the pipelineLayout that gfx pipeline
8659 // was created with, we should be able to delete it. Do that now to verify
8660 // that validation obeys pipelineLayout lifetime
8661 vkDestroyPipelineLayout(m_device->device(), pipe_layout_fs_only, NULL);
8662
Tobin Ehlis88452832015-12-03 09:40:56 -07008663 // Cause draw-time errors due to PSO incompatibilities
Karl Schultz6addd812016-02-02 17:17:23 -07008664 // 1. Error due to not binding required set (we actually use same code as
8665 // above to disturb set0)
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008666 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 2,
8667 &descriptorSet[0], 0, NULL);
8668 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe_layout_bad_set0, 1, 1,
8669 &descriptorSet[1], 0, NULL);
8670 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 -07008671 Draw(1, 0, 0, 0);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008672 m_errorMonitor->VerifyFound();
8673
Tobin Ehlis991d45a2016-01-06 08:48:41 -07008674 vkDestroyPipelineLayout(m_device->device(), pipe_layout_bad_set0, NULL);
Karl Schultz6addd812016-02-02 17:17:23 -07008675 // 2. Error due to bound set not being compatible with PSO's
8676 // VkPipelineLayout (diff stageFlags in this case)
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008677 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 2,
8678 &descriptorSet[0], 0, NULL);
8679 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " bound as set #0 is not compatible with ");
Tobin Ehlis88452832015-12-03 09:40:56 -07008680 Draw(1, 0, 0, 0);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008681 m_errorMonitor->VerifyFound();
8682
Tobin Ehlis8fab6562015-12-01 09:57:09 -07008683 // Remaining clean-up
Karl Schultz6addd812016-02-02 17:17:23 -07008684 for (uint32_t i = 0; i < NUM_LAYOUTS; ++i) {
Tobin Ehlis8fab6562015-12-01 09:57:09 -07008685 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout[i], NULL);
8686 }
8687 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout_fs_only, NULL);
Tobin Ehlis9bfd4492016-05-05 15:09:11 -06008688 vkFreeDescriptorSets(m_device->device(), ds_pool, 1, &ds0_fs_only);
8689 vkFreeDescriptorSets(m_device->device(), ds_pool, NUM_SETS, descriptorSet);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07008690 vkDestroyBuffer(m_device->device(), dyub, NULL);
Tobin Ehlis559c6382015-11-05 09:52:49 -07008691 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
8692 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tony Barbourdf4c0042016-06-01 15:55:43 -06008693 vkFreeMemory(m_device->device(), imageMem, NULL);
8694 vkDestroyImage(m_device->device(), image, NULL);
8695 vkDestroyImageView(m_device->device(), view, NULL);
Tobin Ehlis559c6382015-11-05 09:52:49 -07008696}
Tobin Ehlis559c6382015-11-05 09:52:49 -07008697
Karl Schultz6addd812016-02-02 17:17:23 -07008698TEST_F(VkLayerTest, NoBeginCommandBuffer) {
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06008699
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008700 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
8701 "You must call vkBeginCommandBuffer() before this call to ");
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06008702
8703 ASSERT_NO_FATAL_FAILURE(InitState());
Chia-I Wu3432a0c2015-10-27 18:04:07 +08008704 VkCommandBufferObj commandBuffer(m_device, m_commandPool);
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06008705 // Call EndCommandBuffer() w/o calling BeginCommandBuffer()
Chia-I Wu3432a0c2015-10-27 18:04:07 +08008706 vkEndCommandBuffer(commandBuffer.GetBufferHandle());
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06008707
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008708 m_errorMonitor->VerifyFound();
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06008709}
8710
Karl Schultz6addd812016-02-02 17:17:23 -07008711TEST_F(VkLayerTest, SecondaryCommandBufferNullRenderpass) {
8712 VkResult err;
8713 VkCommandBuffer draw_cmd;
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06008714
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008715 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " must specify a valid renderpass parameter.");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06008716
Mark Lobodzinskid9139a62015-08-04 16:24:20 -06008717 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinskid9139a62015-08-04 16:24:20 -06008718
Chia-I Wu3432a0c2015-10-27 18:04:07 +08008719 VkCommandBufferAllocateInfo cmd = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08008720 cmd.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
Cody Northropb4569702015-08-04 17:35:57 -06008721 cmd.pNext = NULL;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08008722 cmd.commandPool = m_commandPool;
8723 cmd.level = VK_COMMAND_BUFFER_LEVEL_SECONDARY;
Jon Ashburnf19916e2016-01-11 13:12:43 -07008724 cmd.commandBufferCount = 1;
Cody Northropb4569702015-08-04 17:35:57 -06008725
Chia-I Wu3432a0c2015-10-27 18:04:07 +08008726 err = vkAllocateCommandBuffers(m_device->device(), &cmd, &draw_cmd);
Mike Stroyand1c84a52015-08-18 14:40:24 -06008727 ASSERT_VK_SUCCESS(err);
Mark Lobodzinskid9139a62015-08-04 16:24:20 -06008728
8729 // Force the failure by not setting the Renderpass and Framebuffer fields
Chia-I Wu3432a0c2015-10-27 18:04:07 +08008730 VkCommandBufferBeginInfo cmd_buf_info = {};
Jon Ashburnf19916e2016-01-11 13:12:43 -07008731 VkCommandBufferInheritanceInfo cmd_buf_hinfo = {};
Chia-I Wu3432a0c2015-10-27 18:04:07 +08008732 cmd_buf_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
Cody Northropb4569702015-08-04 17:35:57 -06008733 cmd_buf_info.pNext = NULL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008734 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 -07008735 cmd_buf_info.pInheritanceInfo = &cmd_buf_hinfo;
Mark Lobodzinskid9139a62015-08-04 16:24:20 -06008736
8737 // The error should be caught by validation of the BeginCommandBuffer call
8738 vkBeginCommandBuffer(draw_cmd, &cmd_buf_info);
8739
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008740 m_errorMonitor->VerifyFound();
Chia-I Wu3432a0c2015-10-27 18:04:07 +08008741 vkFreeCommandBuffers(m_device->device(), m_commandPool, 1, &draw_cmd);
Mark Lobodzinskid9139a62015-08-04 16:24:20 -06008742}
8743
Karl Schultz6addd812016-02-02 17:17:23 -07008744TEST_F(VkLayerTest, CommandBufferResetErrors) {
Tobin Ehlisac0ef842015-12-14 13:46:38 -07008745 // Cause error due to Begin while recording CB
8746 // Then cause 2 errors for attempting to reset CB w/o having
8747 // VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT set for the pool from
8748 // which CBs were allocated. Note that this bit is off by default.
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008749 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Cannot call Begin on CB");
Tobin Ehlisac0ef842015-12-14 13:46:38 -07008750
8751 ASSERT_NO_FATAL_FAILURE(InitState());
8752
8753 // Calls AllocateCommandBuffers
8754 VkCommandBufferObj commandBuffer(m_device, m_commandPool);
8755
Karl Schultz6addd812016-02-02 17:17:23 -07008756 // Force the failure by setting the Renderpass and Framebuffer fields with
8757 // (fake) data
Tobin Ehlisac0ef842015-12-14 13:46:38 -07008758 VkCommandBufferBeginInfo cmd_buf_info = {};
Jon Ashburnf19916e2016-01-11 13:12:43 -07008759 VkCommandBufferInheritanceInfo cmd_buf_hinfo = {};
Tobin Ehlisac0ef842015-12-14 13:46:38 -07008760 cmd_buf_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
8761 cmd_buf_info.pNext = NULL;
8762 cmd_buf_info.flags = VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT;
Jon Ashburnf19916e2016-01-11 13:12:43 -07008763 cmd_buf_info.pInheritanceInfo = &cmd_buf_hinfo;
Tobin Ehlisac0ef842015-12-14 13:46:38 -07008764
8765 // Begin CB to transition to recording state
8766 vkBeginCommandBuffer(commandBuffer.GetBufferHandle(), &cmd_buf_info);
8767 // Can't re-begin. This should trigger error
8768 vkBeginCommandBuffer(commandBuffer.GetBufferHandle(), &cmd_buf_info);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008769 m_errorMonitor->VerifyFound();
8770
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008771 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Attempt to reset command buffer ");
Tobin Ehlisac0ef842015-12-14 13:46:38 -07008772 VkCommandBufferResetFlags flags = 0; // Don't care about flags for this test
8773 // Reset attempt will trigger error due to incorrect CommandPool state
8774 vkResetCommandBuffer(commandBuffer.GetBufferHandle(), flags);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008775 m_errorMonitor->VerifyFound();
8776
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008777 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " attempts to implicitly reset cmdBuffer created from ");
Tobin Ehlisac0ef842015-12-14 13:46:38 -07008778 // Transition CB to RECORDED state
8779 vkEndCommandBuffer(commandBuffer.GetBufferHandle());
8780 // Now attempting to Begin will implicitly reset, which triggers error
8781 vkBeginCommandBuffer(commandBuffer.GetBufferHandle(), &cmd_buf_info);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008782 m_errorMonitor->VerifyFound();
Tobin Ehlisac0ef842015-12-14 13:46:38 -07008783}
8784
Karl Schultz6addd812016-02-02 17:17:23 -07008785TEST_F(VkLayerTest, InvalidPipelineCreateState) {
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06008786 // Attempt to Create Gfx Pipeline w/o a VS
Karl Schultz6addd812016-02-02 17:17:23 -07008787 VkResult err;
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06008788
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008789 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Invalid Pipeline CreateInfo State: Vtx Shader required");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06008790
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06008791 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06008792 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Mark Lobodzinski209b5292015-09-17 09:44:05 -06008793
Chia-I Wu1b99bb22015-10-27 19:25:11 +08008794 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008795 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
8796 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -06008797
8798 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008799 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
8800 ds_pool_ci.pNext = NULL;
8801 ds_pool_ci.maxSets = 1;
8802 ds_pool_ci.poolSizeCount = 1;
8803 ds_pool_ci.pPoolSizes = &ds_type_count;
Mark Lobodzinski209b5292015-09-17 09:44:05 -06008804
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06008805 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008806 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06008807 ASSERT_VK_SUCCESS(err);
8808
Tony Barboureb254902015-07-15 12:50:33 -06008809 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008810 dsl_binding.binding = 0;
8811 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
8812 dsl_binding.descriptorCount = 1;
8813 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
8814 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06008815
Tony Barboureb254902015-07-15 12:50:33 -06008816 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008817 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
8818 ds_layout_ci.pNext = NULL;
8819 ds_layout_ci.bindingCount = 1;
8820 ds_layout_ci.pBindings = &dsl_binding;
Tony Barboureb254902015-07-15 12:50:33 -06008821
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06008822 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008823 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06008824 ASSERT_VK_SUCCESS(err);
8825
8826 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08008827 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08008828 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07008829 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06008830 alloc_info.descriptorPool = ds_pool;
8831 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008832 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06008833 ASSERT_VK_SUCCESS(err);
8834
Tony Barboureb254902015-07-15 12:50:33 -06008835 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008836 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
8837 pipeline_layout_ci.setLayoutCount = 1;
8838 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06008839
8840 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008841 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06008842 ASSERT_VK_SUCCESS(err);
8843
Tobin Ehlise68360f2015-10-01 11:15:13 -06008844 VkViewport vp = {}; // Just need dummy vp to point to
Karl Schultz6addd812016-02-02 17:17:23 -07008845 VkRect2D sc = {}; // dummy scissor to point to
Tobin Ehlise68360f2015-10-01 11:15:13 -06008846
8847 VkPipelineViewportStateCreateInfo vp_state_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008848 vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
8849 vp_state_ci.scissorCount = 1;
8850 vp_state_ci.pScissors = &sc;
8851 vp_state_ci.viewportCount = 1;
8852 vp_state_ci.pViewports = &vp;
Tobin Ehlise68360f2015-10-01 11:15:13 -06008853
Karl Schultzdfdb8d42016-03-08 10:30:21 -07008854 VkPipelineRasterizationStateCreateInfo rs_state_ci = {};
8855 rs_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
8856 rs_state_ci.polygonMode = VK_POLYGON_MODE_FILL;
8857 rs_state_ci.cullMode = VK_CULL_MODE_BACK_BIT;
8858 rs_state_ci.frontFace = VK_FRONT_FACE_COUNTER_CLOCKWISE;
8859 rs_state_ci.depthClampEnable = VK_FALSE;
8860 rs_state_ci.rasterizerDiscardEnable = VK_FALSE;
8861 rs_state_ci.depthBiasEnable = VK_FALSE;
8862
Tony Barboureb254902015-07-15 12:50:33 -06008863 VkGraphicsPipelineCreateInfo gp_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008864 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
8865 gp_ci.pViewportState = &vp_state_ci;
Karl Schultzdfdb8d42016-03-08 10:30:21 -07008866 gp_ci.pRasterizationState = &rs_state_ci;
Karl Schultz6addd812016-02-02 17:17:23 -07008867 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
8868 gp_ci.layout = pipeline_layout;
8869 gp_ci.renderPass = renderPass();
Tony Barboureb254902015-07-15 12:50:33 -06008870
8871 VkPipelineCacheCreateInfo pc_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008872 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
8873 pc_ci.initialDataSize = 0;
8874 pc_ci.pInitialData = 0;
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06008875
8876 VkPipeline pipeline;
Jon Ashburnc669cc62015-07-09 15:02:25 -06008877 VkPipelineCache pipelineCache;
8878
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008879 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Jon Ashburnc669cc62015-07-09 15:02:25 -06008880 ASSERT_VK_SUCCESS(err);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008881 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06008882
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008883 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06008884
Chia-I Wuf7458c52015-10-26 21:10:41 +08008885 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
8886 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
8887 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
8888 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06008889}
Tobin Ehlis912df022015-09-17 08:46:18 -06008890/*// TODO : This test should be good, but needs Tess support in compiler to run
8891TEST_F(VkLayerTest, InvalidPatchControlPoints)
8892{
8893 // Attempt to Create Gfx Pipeline w/o a VS
Tobin Ehlis912df022015-09-17 08:46:18 -06008894 VkResult err;
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06008895
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07008896 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Karl Schultz6addd812016-02-02 17:17:23 -07008897 "Invalid Pipeline CreateInfo State: VK_PRIMITIVE_TOPOLOGY_PATCH
8898primitive ");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06008899
Tobin Ehlis912df022015-09-17 08:46:18 -06008900 ASSERT_NO_FATAL_FAILURE(InitState());
8901 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlis912df022015-09-17 08:46:18 -06008902
Chia-I Wu1b99bb22015-10-27 19:25:11 +08008903 VkDescriptorPoolSize ds_type_count = {};
Tobin Ehlis912df022015-09-17 08:46:18 -06008904 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Chia-I Wud50a7d72015-10-26 20:48:51 +08008905 ds_type_count.descriptorCount = 1;
Tobin Ehlis912df022015-09-17 08:46:18 -06008906
8907 VkDescriptorPoolCreateInfo ds_pool_ci = {};
8908 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
8909 ds_pool_ci.pNext = NULL;
Chia-I Wu1b99bb22015-10-27 19:25:11 +08008910 ds_pool_ci.poolSizeCount = 1;
8911 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlis912df022015-09-17 08:46:18 -06008912
8913 VkDescriptorPool ds_pool;
Karl Schultz6addd812016-02-02 17:17:23 -07008914 err = vkCreateDescriptorPool(m_device->device(),
8915VK_DESCRIPTOR_POOL_USAGE_NON_FREE, 1, &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis912df022015-09-17 08:46:18 -06008916 ASSERT_VK_SUCCESS(err);
8917
8918 VkDescriptorSetLayoutBinding dsl_binding = {};
Chia-I Wud46e6ae2015-10-31 00:31:16 +08008919 dsl_binding.binding = 0;
Tobin Ehlis912df022015-09-17 08:46:18 -06008920 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Chia-I Wu02124482015-11-06 06:42:02 +08008921 dsl_binding.descriptorCount = 1;
Tobin Ehlis912df022015-09-17 08:46:18 -06008922 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
8923 dsl_binding.pImmutableSamplers = NULL;
8924
8925 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008926 ds_layout_ci.sType =
8927VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
Tobin Ehlis912df022015-09-17 08:46:18 -06008928 ds_layout_ci.pNext = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08008929 ds_layout_ci.bindingCount = 1;
Jon Ashburn6e23c1f2015-12-30 18:01:16 -07008930 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlis912df022015-09-17 08:46:18 -06008931
8932 VkDescriptorSetLayout ds_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07008933 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL,
8934&ds_layout);
Tobin Ehlis912df022015-09-17 08:46:18 -06008935 ASSERT_VK_SUCCESS(err);
8936
8937 VkDescriptorSet descriptorSet;
Karl Schultz6addd812016-02-02 17:17:23 -07008938 err = vkAllocateDescriptorSets(m_device->device(), ds_pool,
8939VK_DESCRIPTOR_SET_USAGE_NON_FREE, 1, &ds_layout, &descriptorSet);
Tobin Ehlis912df022015-09-17 08:46:18 -06008940 ASSERT_VK_SUCCESS(err);
8941
8942 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008943 pipeline_layout_ci.sType =
8944VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
Tobin Ehlis912df022015-09-17 08:46:18 -06008945 pipeline_layout_ci.pNext = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08008946 pipeline_layout_ci.setLayoutCount = 1;
Tobin Ehlis912df022015-09-17 08:46:18 -06008947 pipeline_layout_ci.pSetLayouts = &ds_layout;
8948
8949 VkPipelineLayout pipeline_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07008950 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL,
8951&pipeline_layout);
Tobin Ehlis912df022015-09-17 08:46:18 -06008952 ASSERT_VK_SUCCESS(err);
8953
8954 VkPipelineShaderStageCreateInfo shaderStages[3];
8955 memset(&shaderStages, 0, 3 * sizeof(VkPipelineShaderStageCreateInfo));
8956
Karl Schultz6addd812016-02-02 17:17:23 -07008957 VkShaderObj vs(m_device,bindStateVertShaderText,VK_SHADER_STAGE_VERTEX_BIT,
8958this);
Tobin Ehlis912df022015-09-17 08:46:18 -06008959 // Just using VS txt for Tess shaders as we don't care about functionality
Karl Schultz6addd812016-02-02 17:17:23 -07008960 VkShaderObj
8961tc(m_device,bindStateVertShaderText,VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT,
8962this);
8963 VkShaderObj
8964te(m_device,bindStateVertShaderText,VK_SHADER_STAGE_TESSELLATION_EVALUATION_BIT,
8965this);
Tobin Ehlis912df022015-09-17 08:46:18 -06008966
Karl Schultz6addd812016-02-02 17:17:23 -07008967 shaderStages[0].sType =
8968VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO;
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -06008969 shaderStages[0].stage = VK_SHADER_STAGE_VERTEX_BIT;
Tobin Ehlis912df022015-09-17 08:46:18 -06008970 shaderStages[0].shader = vs.handle();
Karl Schultz6addd812016-02-02 17:17:23 -07008971 shaderStages[1].sType =
8972VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO;
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -06008973 shaderStages[1].stage = VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT;
Tobin Ehlis912df022015-09-17 08:46:18 -06008974 shaderStages[1].shader = tc.handle();
Karl Schultz6addd812016-02-02 17:17:23 -07008975 shaderStages[2].sType =
8976VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO;
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -06008977 shaderStages[2].stage = VK_SHADER_STAGE_TESSELLATION_EVALUATION_BIT;
Tobin Ehlis912df022015-09-17 08:46:18 -06008978 shaderStages[2].shader = te.handle();
8979
8980 VkPipelineInputAssemblyStateCreateInfo iaCI = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008981 iaCI.sType =
8982VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
Chia-I Wu515eb8f2015-10-31 00:31:16 +08008983 iaCI.topology = VK_PRIMITIVE_TOPOLOGY_PATCH_LIST;
Tobin Ehlis912df022015-09-17 08:46:18 -06008984
8985 VkPipelineTessellationStateCreateInfo tsCI = {};
8986 tsCI.sType = VK_STRUCTURE_TYPE_PIPELINE_TESSELLATION_STATE_CREATE_INFO;
8987 tsCI.patchControlPoints = 0; // This will cause an error
8988
8989 VkGraphicsPipelineCreateInfo gp_ci = {};
8990 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
8991 gp_ci.pNext = NULL;
8992 gp_ci.stageCount = 3;
8993 gp_ci.pStages = shaderStages;
8994 gp_ci.pVertexInputState = NULL;
8995 gp_ci.pInputAssemblyState = &iaCI;
8996 gp_ci.pTessellationState = &tsCI;
8997 gp_ci.pViewportState = NULL;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08008998 gp_ci.pRasterizationState = NULL;
Tobin Ehlis912df022015-09-17 08:46:18 -06008999 gp_ci.pMultisampleState = NULL;
9000 gp_ci.pDepthStencilState = NULL;
9001 gp_ci.pColorBlendState = NULL;
9002 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
9003 gp_ci.layout = pipeline_layout;
9004 gp_ci.renderPass = renderPass();
9005
9006 VkPipelineCacheCreateInfo pc_ci = {};
9007 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
9008 pc_ci.pNext = NULL;
9009 pc_ci.initialSize = 0;
9010 pc_ci.initialData = 0;
9011 pc_ci.maxSize = 0;
9012
9013 VkPipeline pipeline;
9014 VkPipelineCache pipelineCache;
9015
Karl Schultz6addd812016-02-02 17:17:23 -07009016 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL,
9017&pipelineCache);
Tobin Ehlis912df022015-09-17 08:46:18 -06009018 ASSERT_VK_SUCCESS(err);
Karl Schultz6addd812016-02-02 17:17:23 -07009019 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1,
9020&gp_ci, NULL, &pipeline);
Tobin Ehlis912df022015-09-17 08:46:18 -06009021
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009022 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06009023
Chia-I Wuf7458c52015-10-26 21:10:41 +08009024 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
9025 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
9026 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
9027 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis912df022015-09-17 08:46:18 -06009028}
9029*/
Tobin Ehlise68360f2015-10-01 11:15:13 -06009030// Set scissor and viewport counts to different numbers
Karl Schultz6addd812016-02-02 17:17:23 -07009031TEST_F(VkLayerTest, PSOViewportScissorCountMismatch) {
Karl Schultz6addd812016-02-02 17:17:23 -07009032 VkResult err;
Tobin Ehlise68360f2015-10-01 11:15:13 -06009033
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009034 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
9035 "Gfx Pipeline viewport count (1) must match scissor count (0).");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06009036
Tobin Ehlise68360f2015-10-01 11:15:13 -06009037 ASSERT_NO_FATAL_FAILURE(InitState());
9038 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlise68360f2015-10-01 11:15:13 -06009039
Chia-I Wu1b99bb22015-10-27 19:25:11 +08009040 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009041 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
9042 ds_type_count.descriptorCount = 1;
Tobin Ehlise68360f2015-10-01 11:15:13 -06009043
9044 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009045 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
9046 ds_pool_ci.maxSets = 1;
9047 ds_pool_ci.poolSizeCount = 1;
9048 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlise68360f2015-10-01 11:15:13 -06009049
9050 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009051 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlise68360f2015-10-01 11:15:13 -06009052 ASSERT_VK_SUCCESS(err);
9053
9054 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009055 dsl_binding.binding = 0;
9056 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
9057 dsl_binding.descriptorCount = 1;
9058 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
Tobin Ehlise68360f2015-10-01 11:15:13 -06009059
9060 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009061 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
9062 ds_layout_ci.bindingCount = 1;
9063 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlise68360f2015-10-01 11:15:13 -06009064
9065 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009066 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlise68360f2015-10-01 11:15:13 -06009067 ASSERT_VK_SUCCESS(err);
9068
9069 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009070 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08009071 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07009072 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06009073 alloc_info.descriptorPool = ds_pool;
9074 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009075 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlise68360f2015-10-01 11:15:13 -06009076 ASSERT_VK_SUCCESS(err);
9077
9078 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009079 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
9080 pipeline_layout_ci.setLayoutCount = 1;
9081 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlise68360f2015-10-01 11:15:13 -06009082
9083 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009084 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlise68360f2015-10-01 11:15:13 -06009085 ASSERT_VK_SUCCESS(err);
9086
9087 VkViewport vp = {}; // Just need dummy vp to point to
9088
9089 VkPipelineViewportStateCreateInfo vp_state_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009090 vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
9091 vp_state_ci.scissorCount = 0;
9092 vp_state_ci.viewportCount = 1; // Count mismatch should cause error
9093 vp_state_ci.pViewports = &vp;
Tobin Ehlise68360f2015-10-01 11:15:13 -06009094
Karl Schultzdfdb8d42016-03-08 10:30:21 -07009095 VkPipelineRasterizationStateCreateInfo rs_state_ci = {};
9096 rs_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
9097 rs_state_ci.polygonMode = VK_POLYGON_MODE_FILL;
9098 rs_state_ci.cullMode = VK_CULL_MODE_BACK_BIT;
9099 rs_state_ci.frontFace = VK_FRONT_FACE_COUNTER_CLOCKWISE;
9100 rs_state_ci.depthClampEnable = VK_FALSE;
9101 rs_state_ci.rasterizerDiscardEnable = VK_FALSE;
9102 rs_state_ci.depthBiasEnable = VK_FALSE;
9103
Cody Northropeb3a6c12015-10-05 14:44:45 -06009104 VkPipelineShaderStageCreateInfo shaderStages[2];
Karl Schultz6addd812016-02-02 17:17:23 -07009105 memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo));
Tobin Ehlise68360f2015-10-01 11:15:13 -06009106
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009107 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
9108 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this); // We shouldn't need a fragment shader
9109 // but add it to be able to run on more devices
Chia-I Wu28e06912015-10-31 00:31:16 +08009110 shaderStages[0] = vs.GetStageCreateInfo();
9111 shaderStages[1] = fs.GetStageCreateInfo();
Tobin Ehlise68360f2015-10-01 11:15:13 -06009112
9113 VkGraphicsPipelineCreateInfo gp_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009114 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
9115 gp_ci.stageCount = 2;
9116 gp_ci.pStages = shaderStages;
9117 gp_ci.pViewportState = &vp_state_ci;
Karl Schultzdfdb8d42016-03-08 10:30:21 -07009118 gp_ci.pRasterizationState = &rs_state_ci;
Karl Schultz6addd812016-02-02 17:17:23 -07009119 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
9120 gp_ci.layout = pipeline_layout;
9121 gp_ci.renderPass = renderPass();
Tobin Ehlise68360f2015-10-01 11:15:13 -06009122
9123 VkPipelineCacheCreateInfo pc_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009124 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
Tobin Ehlise68360f2015-10-01 11:15:13 -06009125
9126 VkPipeline pipeline;
9127 VkPipelineCache pipelineCache;
9128
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009129 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Tobin Ehlise68360f2015-10-01 11:15:13 -06009130 ASSERT_VK_SUCCESS(err);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009131 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Tobin Ehlise68360f2015-10-01 11:15:13 -06009132
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009133 m_errorMonitor->VerifyFound();
Tobin Ehlise68360f2015-10-01 11:15:13 -06009134
Chia-I Wuf7458c52015-10-26 21:10:41 +08009135 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
9136 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
9137 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
9138 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlise68360f2015-10-01 11:15:13 -06009139}
Karl Schultz6addd812016-02-02 17:17:23 -07009140// Don't set viewport state in PSO. This is an error b/c we always need this
9141// state
Tobin Ehlisd332f282015-10-02 11:00:56 -06009142// for the counts even if the data is going to be set dynamically.
Karl Schultz6addd812016-02-02 17:17:23 -07009143TEST_F(VkLayerTest, PSOViewportStateNotSet) {
Tobin Ehlise68360f2015-10-01 11:15:13 -06009144 // Attempt to Create Gfx Pipeline w/o a VS
Karl Schultz6addd812016-02-02 17:17:23 -07009145 VkResult err;
Tobin Ehlise68360f2015-10-01 11:15:13 -06009146
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009147 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Gfx Pipeline pViewportState is null. Even if ");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06009148
Tobin Ehlise68360f2015-10-01 11:15:13 -06009149 ASSERT_NO_FATAL_FAILURE(InitState());
9150 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlise68360f2015-10-01 11:15:13 -06009151
Chia-I Wu1b99bb22015-10-27 19:25:11 +08009152 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009153 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
9154 ds_type_count.descriptorCount = 1;
Tobin Ehlise68360f2015-10-01 11:15:13 -06009155
9156 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009157 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
9158 ds_pool_ci.maxSets = 1;
9159 ds_pool_ci.poolSizeCount = 1;
9160 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlise68360f2015-10-01 11:15:13 -06009161
9162 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009163 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlise68360f2015-10-01 11:15:13 -06009164 ASSERT_VK_SUCCESS(err);
9165
9166 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009167 dsl_binding.binding = 0;
9168 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
9169 dsl_binding.descriptorCount = 1;
9170 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
Tobin Ehlise68360f2015-10-01 11:15:13 -06009171
9172 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009173 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
9174 ds_layout_ci.bindingCount = 1;
9175 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlise68360f2015-10-01 11:15:13 -06009176
9177 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009178 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlise68360f2015-10-01 11:15:13 -06009179 ASSERT_VK_SUCCESS(err);
9180
9181 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009182 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08009183 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07009184 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06009185 alloc_info.descriptorPool = ds_pool;
9186 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009187 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlise68360f2015-10-01 11:15:13 -06009188 ASSERT_VK_SUCCESS(err);
9189
9190 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009191 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
9192 pipeline_layout_ci.setLayoutCount = 1;
9193 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlise68360f2015-10-01 11:15:13 -06009194
9195 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009196 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlise68360f2015-10-01 11:15:13 -06009197 ASSERT_VK_SUCCESS(err);
9198
9199 VkDynamicState sc_state = VK_DYNAMIC_STATE_SCISSOR;
9200 // Set scissor as dynamic to avoid second error
9201 VkPipelineDynamicStateCreateInfo dyn_state_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009202 dyn_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_DYNAMIC_STATE_CREATE_INFO;
9203 dyn_state_ci.dynamicStateCount = 1;
9204 dyn_state_ci.pDynamicStates = &sc_state;
Tobin Ehlise68360f2015-10-01 11:15:13 -06009205
Cody Northropeb3a6c12015-10-05 14:44:45 -06009206 VkPipelineShaderStageCreateInfo shaderStages[2];
Karl Schultz6addd812016-02-02 17:17:23 -07009207 memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo));
Tobin Ehlise68360f2015-10-01 11:15:13 -06009208
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009209 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
9210 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this); // We shouldn't need a fragment shader
9211 // but add it to be able to run on more devices
Chia-I Wu28e06912015-10-31 00:31:16 +08009212 shaderStages[0] = vs.GetStageCreateInfo();
9213 shaderStages[1] = fs.GetStageCreateInfo();
Tobin Ehlise68360f2015-10-01 11:15:13 -06009214
Karl Schultzdfdb8d42016-03-08 10:30:21 -07009215 VkPipelineRasterizationStateCreateInfo rs_state_ci = {};
9216 rs_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
9217 rs_state_ci.polygonMode = VK_POLYGON_MODE_FILL;
9218 rs_state_ci.cullMode = VK_CULL_MODE_BACK_BIT;
9219 rs_state_ci.frontFace = VK_FRONT_FACE_COUNTER_CLOCKWISE;
9220 rs_state_ci.depthClampEnable = VK_FALSE;
9221 rs_state_ci.rasterizerDiscardEnable = VK_FALSE;
9222 rs_state_ci.depthBiasEnable = VK_FALSE;
9223
Tobin Ehlise68360f2015-10-01 11:15:13 -06009224 VkGraphicsPipelineCreateInfo gp_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009225 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
9226 gp_ci.stageCount = 2;
9227 gp_ci.pStages = shaderStages;
Karl Schultzdfdb8d42016-03-08 10:30:21 -07009228 gp_ci.pRasterizationState = &rs_state_ci;
Karl Schultz6addd812016-02-02 17:17:23 -07009229 gp_ci.pViewportState = NULL; // Not setting VP state w/o dynamic vp state
9230 // should cause validation error
9231 gp_ci.pDynamicState = &dyn_state_ci;
9232 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
9233 gp_ci.layout = pipeline_layout;
9234 gp_ci.renderPass = renderPass();
Tobin Ehlise68360f2015-10-01 11:15:13 -06009235
9236 VkPipelineCacheCreateInfo pc_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009237 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
Tobin Ehlise68360f2015-10-01 11:15:13 -06009238
9239 VkPipeline pipeline;
9240 VkPipelineCache pipelineCache;
9241
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009242 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Tobin Ehlise68360f2015-10-01 11:15:13 -06009243 ASSERT_VK_SUCCESS(err);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009244 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Tobin Ehlise68360f2015-10-01 11:15:13 -06009245
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009246 m_errorMonitor->VerifyFound();
Tobin Ehlise68360f2015-10-01 11:15:13 -06009247
Chia-I Wuf7458c52015-10-26 21:10:41 +08009248 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
9249 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
9250 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
9251 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlise68360f2015-10-01 11:15:13 -06009252}
9253// Create PSO w/o non-zero viewportCount but no viewport data
Karl Schultz6addd812016-02-02 17:17:23 -07009254// Then run second test where dynamic scissor count doesn't match PSO scissor
9255// count
9256TEST_F(VkLayerTest, PSOViewportCountWithoutDataAndDynScissorMismatch) {
9257 VkResult err;
Tobin Ehlise68360f2015-10-01 11:15:13 -06009258
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009259 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
9260 "Gfx Pipeline viewportCount is 1, but pViewports is NULL. ");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06009261
Tobin Ehlise68360f2015-10-01 11:15:13 -06009262 ASSERT_NO_FATAL_FAILURE(InitState());
Chris Forbesc08a6ca2016-07-28 14:14:07 +12009263
9264 if (!m_device->phy().features().multiViewport) {
9265 printf("Device does not support multiple viewports/scissors; skipped.\n");
9266 return;
9267 }
9268
Tobin Ehlise68360f2015-10-01 11:15:13 -06009269 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlise68360f2015-10-01 11:15:13 -06009270
Chia-I Wu1b99bb22015-10-27 19:25:11 +08009271 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009272 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
9273 ds_type_count.descriptorCount = 1;
Tobin Ehlise68360f2015-10-01 11:15:13 -06009274
9275 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009276 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
9277 ds_pool_ci.maxSets = 1;
9278 ds_pool_ci.poolSizeCount = 1;
9279 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlise68360f2015-10-01 11:15:13 -06009280
9281 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009282 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlise68360f2015-10-01 11:15:13 -06009283 ASSERT_VK_SUCCESS(err);
9284
9285 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009286 dsl_binding.binding = 0;
9287 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
9288 dsl_binding.descriptorCount = 1;
9289 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
Tobin Ehlise68360f2015-10-01 11:15:13 -06009290
9291 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009292 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
9293 ds_layout_ci.bindingCount = 1;
9294 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlise68360f2015-10-01 11:15:13 -06009295
9296 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009297 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlise68360f2015-10-01 11:15:13 -06009298 ASSERT_VK_SUCCESS(err);
9299
9300 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009301 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08009302 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07009303 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06009304 alloc_info.descriptorPool = ds_pool;
9305 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009306 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlise68360f2015-10-01 11:15:13 -06009307 ASSERT_VK_SUCCESS(err);
9308
9309 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009310 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
9311 pipeline_layout_ci.setLayoutCount = 1;
9312 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlise68360f2015-10-01 11:15:13 -06009313
9314 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009315 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlise68360f2015-10-01 11:15:13 -06009316 ASSERT_VK_SUCCESS(err);
9317
9318 VkPipelineViewportStateCreateInfo vp_state_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009319 vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
9320 vp_state_ci.viewportCount = 1;
9321 vp_state_ci.pViewports = NULL; // Null vp w/ count of 1 should cause error
9322 vp_state_ci.scissorCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009323 vp_state_ci.pScissors = NULL; // Scissor is dynamic (below) so this won't cause error
Tobin Ehlise68360f2015-10-01 11:15:13 -06009324
9325 VkDynamicState sc_state = VK_DYNAMIC_STATE_SCISSOR;
9326 // Set scissor as dynamic to avoid that error
9327 VkPipelineDynamicStateCreateInfo dyn_state_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009328 dyn_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_DYNAMIC_STATE_CREATE_INFO;
9329 dyn_state_ci.dynamicStateCount = 1;
9330 dyn_state_ci.pDynamicStates = &sc_state;
Tobin Ehlise68360f2015-10-01 11:15:13 -06009331
Cody Northropeb3a6c12015-10-05 14:44:45 -06009332 VkPipelineShaderStageCreateInfo shaderStages[2];
Karl Schultz6addd812016-02-02 17:17:23 -07009333 memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo));
Tobin Ehlise68360f2015-10-01 11:15:13 -06009334
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009335 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
9336 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this); // We shouldn't need a fragment shader
9337 // but add it to be able to run on more devices
Chia-I Wu28e06912015-10-31 00:31:16 +08009338 shaderStages[0] = vs.GetStageCreateInfo();
9339 shaderStages[1] = fs.GetStageCreateInfo();
Tobin Ehlise68360f2015-10-01 11:15:13 -06009340
Cody Northropf6622dc2015-10-06 10:33:21 -06009341 VkPipelineVertexInputStateCreateInfo vi_ci = {};
9342 vi_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
9343 vi_ci.pNext = nullptr;
Chia-I Wud50a7d72015-10-26 20:48:51 +08009344 vi_ci.vertexBindingDescriptionCount = 0;
Cody Northropf6622dc2015-10-06 10:33:21 -06009345 vi_ci.pVertexBindingDescriptions = nullptr;
Chia-I Wud50a7d72015-10-26 20:48:51 +08009346 vi_ci.vertexAttributeDescriptionCount = 0;
Cody Northropf6622dc2015-10-06 10:33:21 -06009347 vi_ci.pVertexAttributeDescriptions = nullptr;
9348
9349 VkPipelineInputAssemblyStateCreateInfo ia_ci = {};
9350 ia_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
9351 ia_ci.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP;
9352
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009353 VkPipelineRasterizationStateCreateInfo rs_ci = {};
Chia-I Wu1b99bb22015-10-27 19:25:11 +08009354 rs_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
Cody Northropf6622dc2015-10-06 10:33:21 -06009355 rs_ci.pNext = nullptr;
9356
Mark Youngc89c6312016-03-31 16:03:20 -06009357 VkPipelineColorBlendAttachmentState att = {};
9358 att.blendEnable = VK_FALSE;
9359 att.colorWriteMask = 0xf;
9360
Cody Northropf6622dc2015-10-06 10:33:21 -06009361 VkPipelineColorBlendStateCreateInfo cb_ci = {};
9362 cb_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO;
9363 cb_ci.pNext = nullptr;
Mark Youngc89c6312016-03-31 16:03:20 -06009364 cb_ci.attachmentCount = 1;
9365 cb_ci.pAttachments = &att;
Cody Northropf6622dc2015-10-06 10:33:21 -06009366
Tobin Ehlise68360f2015-10-01 11:15:13 -06009367 VkGraphicsPipelineCreateInfo gp_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009368 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
9369 gp_ci.stageCount = 2;
9370 gp_ci.pStages = shaderStages;
9371 gp_ci.pVertexInputState = &vi_ci;
9372 gp_ci.pInputAssemblyState = &ia_ci;
9373 gp_ci.pViewportState = &vp_state_ci;
9374 gp_ci.pRasterizationState = &rs_ci;
9375 gp_ci.pColorBlendState = &cb_ci;
9376 gp_ci.pDynamicState = &dyn_state_ci;
9377 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
9378 gp_ci.layout = pipeline_layout;
9379 gp_ci.renderPass = renderPass();
Tobin Ehlise68360f2015-10-01 11:15:13 -06009380
9381 VkPipelineCacheCreateInfo pc_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009382 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
Tobin Ehlise68360f2015-10-01 11:15:13 -06009383
9384 VkPipeline pipeline;
9385 VkPipelineCache pipelineCache;
9386
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009387 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Tobin Ehlise68360f2015-10-01 11:15:13 -06009388 ASSERT_VK_SUCCESS(err);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009389 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Tobin Ehlise68360f2015-10-01 11:15:13 -06009390
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009391 m_errorMonitor->VerifyFound();
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06009392
Tobin Ehlisd332f282015-10-02 11:00:56 -06009393 // Now hit second fail case where we set scissor w/ different count than PSO
Karl Schultz6addd812016-02-02 17:17:23 -07009394 // First need to successfully create the PSO from above by setting
9395 // pViewports
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009396 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Dynamic scissor(s) 0 are used by PSO, ");
Karl Schultz6addd812016-02-02 17:17:23 -07009397
9398 VkViewport vp = {}; // Just need dummy vp to point to
9399 vp_state_ci.pViewports = &vp;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009400 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Karl Schultz6addd812016-02-02 17:17:23 -07009401 ASSERT_VK_SUCCESS(err);
9402 BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009403 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline);
Chris Forbesc08a6ca2016-07-28 14:14:07 +12009404 VkRect2D scissors[1] = {}; // don't care about data
Karl Schultz6addd812016-02-02 17:17:23 -07009405 // Count of 2 doesn't match PSO count of 1
Chris Forbesc08a6ca2016-07-28 14:14:07 +12009406 vkCmdSetScissor(m_commandBuffer->GetBufferHandle(), 1, 1, scissors);
Karl Schultz6addd812016-02-02 17:17:23 -07009407 Draw(1, 0, 0, 0);
9408
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009409 m_errorMonitor->VerifyFound();
Karl Schultz6addd812016-02-02 17:17:23 -07009410
9411 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
9412 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
9413 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
9414 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tony Barbourdf4c0042016-06-01 15:55:43 -06009415 vkDestroyPipeline(m_device->device(), pipeline, NULL);
Karl Schultz6addd812016-02-02 17:17:23 -07009416}
9417// Create PSO w/o non-zero scissorCount but no scissor data
9418// Then run second test where dynamic viewportCount doesn't match PSO
9419// viewportCount
9420TEST_F(VkLayerTest, PSOScissorCountWithoutDataAndDynViewportMismatch) {
9421 VkResult err;
9422
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009423 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 -07009424
9425 ASSERT_NO_FATAL_FAILURE(InitState());
Chris Forbesc08a6ca2016-07-28 14:14:07 +12009426
9427 if (!m_device->phy().features().multiViewport) {
9428 printf("Device does not support multiple viewports/scissors; skipped.\n");
9429 return;
9430 }
9431
Karl Schultz6addd812016-02-02 17:17:23 -07009432 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
9433
9434 VkDescriptorPoolSize ds_type_count = {};
9435 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
9436 ds_type_count.descriptorCount = 1;
9437
9438 VkDescriptorPoolCreateInfo ds_pool_ci = {};
9439 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
9440 ds_pool_ci.maxSets = 1;
9441 ds_pool_ci.poolSizeCount = 1;
9442 ds_pool_ci.pPoolSizes = &ds_type_count;
9443
9444 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009445 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Karl Schultz6addd812016-02-02 17:17:23 -07009446 ASSERT_VK_SUCCESS(err);
9447
9448 VkDescriptorSetLayoutBinding dsl_binding = {};
9449 dsl_binding.binding = 0;
9450 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
9451 dsl_binding.descriptorCount = 1;
9452 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
9453
9454 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
9455 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
9456 ds_layout_ci.bindingCount = 1;
9457 ds_layout_ci.pBindings = &dsl_binding;
9458
9459 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009460 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Karl Schultz6addd812016-02-02 17:17:23 -07009461 ASSERT_VK_SUCCESS(err);
9462
9463 VkDescriptorSet descriptorSet;
9464 VkDescriptorSetAllocateInfo alloc_info = {};
9465 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
9466 alloc_info.descriptorSetCount = 1;
9467 alloc_info.descriptorPool = ds_pool;
9468 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009469 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Karl Schultz6addd812016-02-02 17:17:23 -07009470 ASSERT_VK_SUCCESS(err);
9471
9472 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
9473 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
9474 pipeline_layout_ci.setLayoutCount = 1;
9475 pipeline_layout_ci.pSetLayouts = &ds_layout;
9476
9477 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009478 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Karl Schultz6addd812016-02-02 17:17:23 -07009479 ASSERT_VK_SUCCESS(err);
9480
9481 VkPipelineViewportStateCreateInfo vp_state_ci = {};
9482 vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
9483 vp_state_ci.scissorCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009484 vp_state_ci.pScissors = NULL; // Null scissor w/ count of 1 should cause error
Karl Schultz6addd812016-02-02 17:17:23 -07009485 vp_state_ci.viewportCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009486 vp_state_ci.pViewports = NULL; // vp is dynamic (below) so this won't cause error
Karl Schultz6addd812016-02-02 17:17:23 -07009487
9488 VkDynamicState vp_state = VK_DYNAMIC_STATE_VIEWPORT;
9489 // Set scissor as dynamic to avoid that error
9490 VkPipelineDynamicStateCreateInfo dyn_state_ci = {};
9491 dyn_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_DYNAMIC_STATE_CREATE_INFO;
9492 dyn_state_ci.dynamicStateCount = 1;
9493 dyn_state_ci.pDynamicStates = &vp_state;
9494
9495 VkPipelineShaderStageCreateInfo shaderStages[2];
9496 memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo));
9497
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009498 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
9499 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this); // We shouldn't need a fragment shader
9500 // but add it to be able to run on more devices
Karl Schultz6addd812016-02-02 17:17:23 -07009501 shaderStages[0] = vs.GetStageCreateInfo();
9502 shaderStages[1] = fs.GetStageCreateInfo();
9503
9504 VkPipelineVertexInputStateCreateInfo vi_ci = {};
9505 vi_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
9506 vi_ci.pNext = nullptr;
9507 vi_ci.vertexBindingDescriptionCount = 0;
9508 vi_ci.pVertexBindingDescriptions = nullptr;
9509 vi_ci.vertexAttributeDescriptionCount = 0;
9510 vi_ci.pVertexAttributeDescriptions = nullptr;
9511
9512 VkPipelineInputAssemblyStateCreateInfo ia_ci = {};
9513 ia_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
9514 ia_ci.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP;
9515
9516 VkPipelineRasterizationStateCreateInfo rs_ci = {};
9517 rs_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
9518 rs_ci.pNext = nullptr;
9519
Mark Youngc89c6312016-03-31 16:03:20 -06009520 VkPipelineColorBlendAttachmentState att = {};
9521 att.blendEnable = VK_FALSE;
9522 att.colorWriteMask = 0xf;
9523
Karl Schultz6addd812016-02-02 17:17:23 -07009524 VkPipelineColorBlendStateCreateInfo cb_ci = {};
9525 cb_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO;
9526 cb_ci.pNext = nullptr;
Mark Youngc89c6312016-03-31 16:03:20 -06009527 cb_ci.attachmentCount = 1;
9528 cb_ci.pAttachments = &att;
Karl Schultz6addd812016-02-02 17:17:23 -07009529
9530 VkGraphicsPipelineCreateInfo gp_ci = {};
9531 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
9532 gp_ci.stageCount = 2;
9533 gp_ci.pStages = shaderStages;
9534 gp_ci.pVertexInputState = &vi_ci;
9535 gp_ci.pInputAssemblyState = &ia_ci;
9536 gp_ci.pViewportState = &vp_state_ci;
9537 gp_ci.pRasterizationState = &rs_ci;
9538 gp_ci.pColorBlendState = &cb_ci;
9539 gp_ci.pDynamicState = &dyn_state_ci;
9540 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
9541 gp_ci.layout = pipeline_layout;
9542 gp_ci.renderPass = renderPass();
9543
9544 VkPipelineCacheCreateInfo pc_ci = {};
9545 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
9546
9547 VkPipeline pipeline;
9548 VkPipelineCache pipelineCache;
9549
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009550 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Karl Schultz6addd812016-02-02 17:17:23 -07009551 ASSERT_VK_SUCCESS(err);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009552 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Karl Schultz6addd812016-02-02 17:17:23 -07009553
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009554 m_errorMonitor->VerifyFound();
Karl Schultz6addd812016-02-02 17:17:23 -07009555
9556 // Now hit second fail case where we set scissor w/ different count than PSO
9557 // First need to successfully create the PSO from above by setting
9558 // pViewports
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009559 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Dynamic viewport(s) 0 are used by PSO, ");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06009560
Tobin Ehlisd332f282015-10-02 11:00:56 -06009561 VkRect2D sc = {}; // Just need dummy vp to point to
9562 vp_state_ci.pScissors = &sc;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009563 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Tobin Ehlisd332f282015-10-02 11:00:56 -06009564 ASSERT_VK_SUCCESS(err);
9565 BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009566 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline);
Chris Forbesc08a6ca2016-07-28 14:14:07 +12009567 VkViewport viewports[1] = {}; // don't care about data
Tobin Ehlisd332f282015-10-02 11:00:56 -06009568 // Count of 2 doesn't match PSO count of 1
Chris Forbesc08a6ca2016-07-28 14:14:07 +12009569 vkCmdSetViewport(m_commandBuffer->GetBufferHandle(), 1, 1, viewports);
Tobin Ehlisd332f282015-10-02 11:00:56 -06009570 Draw(1, 0, 0, 0);
9571
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009572 m_errorMonitor->VerifyFound();
Tobin Ehlise68360f2015-10-01 11:15:13 -06009573
Chia-I Wuf7458c52015-10-26 21:10:41 +08009574 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
9575 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
9576 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
9577 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tony Barbourdf4c0042016-06-01 15:55:43 -06009578 vkDestroyPipeline(m_device->device(), pipeline, NULL);
Tobin Ehlise68360f2015-10-01 11:15:13 -06009579}
9580
Mark Young7394fdd2016-03-31 14:56:43 -06009581TEST_F(VkLayerTest, PSOLineWidthInvalid) {
9582 VkResult err;
9583
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009584 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Attempt to set lineWidth to -1");
Mark Young7394fdd2016-03-31 14:56:43 -06009585
9586 ASSERT_NO_FATAL_FAILURE(InitState());
9587 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
9588
9589 VkDescriptorPoolSize ds_type_count = {};
9590 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
9591 ds_type_count.descriptorCount = 1;
9592
9593 VkDescriptorPoolCreateInfo ds_pool_ci = {};
9594 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
9595 ds_pool_ci.maxSets = 1;
9596 ds_pool_ci.poolSizeCount = 1;
9597 ds_pool_ci.pPoolSizes = &ds_type_count;
9598
9599 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009600 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Mark Young7394fdd2016-03-31 14:56:43 -06009601 ASSERT_VK_SUCCESS(err);
9602
9603 VkDescriptorSetLayoutBinding dsl_binding = {};
9604 dsl_binding.binding = 0;
9605 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
9606 dsl_binding.descriptorCount = 1;
9607 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
9608
9609 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
9610 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
9611 ds_layout_ci.bindingCount = 1;
9612 ds_layout_ci.pBindings = &dsl_binding;
9613
9614 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009615 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Mark Young7394fdd2016-03-31 14:56:43 -06009616 ASSERT_VK_SUCCESS(err);
9617
9618 VkDescriptorSet descriptorSet;
9619 VkDescriptorSetAllocateInfo alloc_info = {};
9620 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
9621 alloc_info.descriptorSetCount = 1;
9622 alloc_info.descriptorPool = ds_pool;
9623 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009624 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Mark Young7394fdd2016-03-31 14:56:43 -06009625 ASSERT_VK_SUCCESS(err);
9626
9627 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
9628 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
9629 pipeline_layout_ci.setLayoutCount = 1;
9630 pipeline_layout_ci.pSetLayouts = &ds_layout;
9631
9632 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009633 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Mark Young7394fdd2016-03-31 14:56:43 -06009634 ASSERT_VK_SUCCESS(err);
9635
9636 VkPipelineViewportStateCreateInfo vp_state_ci = {};
9637 vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
9638 vp_state_ci.scissorCount = 1;
9639 vp_state_ci.pScissors = NULL;
9640 vp_state_ci.viewportCount = 1;
9641 vp_state_ci.pViewports = NULL;
9642
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009643 VkDynamicState dynamic_states[3] = {VK_DYNAMIC_STATE_VIEWPORT, VK_DYNAMIC_STATE_SCISSOR, VK_DYNAMIC_STATE_LINE_WIDTH};
Mark Young7394fdd2016-03-31 14:56:43 -06009644 // Set scissor as dynamic to avoid that error
9645 VkPipelineDynamicStateCreateInfo dyn_state_ci = {};
9646 dyn_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_DYNAMIC_STATE_CREATE_INFO;
9647 dyn_state_ci.dynamicStateCount = 2;
9648 dyn_state_ci.pDynamicStates = dynamic_states;
9649
9650 VkPipelineShaderStageCreateInfo shaderStages[2];
9651 memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo));
9652
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009653 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
9654 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT,
Mark Young7394fdd2016-03-31 14:56:43 -06009655 this); // TODO - We shouldn't need a fragment shader
9656 // but add it to be able to run on more devices
9657 shaderStages[0] = vs.GetStageCreateInfo();
9658 shaderStages[1] = fs.GetStageCreateInfo();
9659
9660 VkPipelineVertexInputStateCreateInfo vi_ci = {};
9661 vi_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
9662 vi_ci.pNext = nullptr;
9663 vi_ci.vertexBindingDescriptionCount = 0;
9664 vi_ci.pVertexBindingDescriptions = nullptr;
9665 vi_ci.vertexAttributeDescriptionCount = 0;
9666 vi_ci.pVertexAttributeDescriptions = nullptr;
9667
9668 VkPipelineInputAssemblyStateCreateInfo ia_ci = {};
9669 ia_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
9670 ia_ci.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP;
9671
9672 VkPipelineRasterizationStateCreateInfo rs_ci = {};
9673 rs_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
9674 rs_ci.pNext = nullptr;
9675
Mark Young47107952016-05-02 15:59:55 -06009676 // Check too low (line width of -1.0f).
9677 rs_ci.lineWidth = -1.0f;
Mark Young7394fdd2016-03-31 14:56:43 -06009678
9679 VkPipelineColorBlendAttachmentState att = {};
9680 att.blendEnable = VK_FALSE;
9681 att.colorWriteMask = 0xf;
9682
9683 VkPipelineColorBlendStateCreateInfo cb_ci = {};
9684 cb_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO;
9685 cb_ci.pNext = nullptr;
9686 cb_ci.attachmentCount = 1;
9687 cb_ci.pAttachments = &att;
9688
9689 VkGraphicsPipelineCreateInfo gp_ci = {};
9690 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
9691 gp_ci.stageCount = 2;
9692 gp_ci.pStages = shaderStages;
9693 gp_ci.pVertexInputState = &vi_ci;
9694 gp_ci.pInputAssemblyState = &ia_ci;
9695 gp_ci.pViewportState = &vp_state_ci;
9696 gp_ci.pRasterizationState = &rs_ci;
9697 gp_ci.pColorBlendState = &cb_ci;
9698 gp_ci.pDynamicState = &dyn_state_ci;
9699 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
9700 gp_ci.layout = pipeline_layout;
9701 gp_ci.renderPass = renderPass();
9702
9703 VkPipelineCacheCreateInfo pc_ci = {};
9704 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
9705
9706 VkPipeline pipeline;
9707 VkPipelineCache pipelineCache;
9708
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009709 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Mark Young7394fdd2016-03-31 14:56:43 -06009710 ASSERT_VK_SUCCESS(err);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009711 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Mark Young7394fdd2016-03-31 14:56:43 -06009712
9713 m_errorMonitor->VerifyFound();
Tony Barbourdf4c0042016-06-01 15:55:43 -06009714 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
Mark Young7394fdd2016-03-31 14:56:43 -06009715
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009716 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Attempt to set lineWidth to 65536");
Mark Young7394fdd2016-03-31 14:56:43 -06009717
9718 // Check too high (line width of 65536.0f).
9719 rs_ci.lineWidth = 65536.0f;
9720
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009721 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Mark Young7394fdd2016-03-31 14:56:43 -06009722 ASSERT_VK_SUCCESS(err);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009723 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Mark Young7394fdd2016-03-31 14:56:43 -06009724
9725 m_errorMonitor->VerifyFound();
Tony Barbourdf4c0042016-06-01 15:55:43 -06009726 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
Mark Young7394fdd2016-03-31 14:56:43 -06009727
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009728 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Attempt to set lineWidth to -1");
Mark Young7394fdd2016-03-31 14:56:43 -06009729
9730 dyn_state_ci.dynamicStateCount = 3;
9731
9732 rs_ci.lineWidth = 1.0f;
9733
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009734 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Mark Young7394fdd2016-03-31 14:56:43 -06009735 ASSERT_VK_SUCCESS(err);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009736 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Mark Young7394fdd2016-03-31 14:56:43 -06009737 BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009738 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline);
Mark Young7394fdd2016-03-31 14:56:43 -06009739
9740 // Check too low with dynamic setting.
Mark Young47107952016-05-02 15:59:55 -06009741 vkCmdSetLineWidth(m_commandBuffer->GetBufferHandle(), -1.0f);
Mark Young7394fdd2016-03-31 14:56:43 -06009742 m_errorMonitor->VerifyFound();
9743
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009744 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Attempt to set lineWidth to 65536");
Mark Young7394fdd2016-03-31 14:56:43 -06009745
9746 // Check too high with dynamic setting.
9747 vkCmdSetLineWidth(m_commandBuffer->GetBufferHandle(), 65536.0f);
9748 m_errorMonitor->VerifyFound();
9749 EndCommandBuffer();
9750
9751 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
9752 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
9753 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
9754 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tony Barbourdf4c0042016-06-01 15:55:43 -06009755 vkDestroyPipeline(m_device->device(), pipeline, NULL);
Mark Young7394fdd2016-03-31 14:56:43 -06009756}
9757
Karl Schultz6addd812016-02-02 17:17:23 -07009758TEST_F(VkLayerTest, NullRenderPass) {
Tobin Ehlis98aa0ed2015-06-25 16:27:19 -06009759 // Bind a NULL RenderPass
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009760 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
9761 "You cannot use a NULL RenderPass object in vkCmdBeginRenderPass()");
Tobin Ehlis98aa0ed2015-06-25 16:27:19 -06009762
9763 ASSERT_NO_FATAL_FAILURE(InitState());
9764 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlis98aa0ed2015-06-25 16:27:19 -06009765
Tony Barbourfe3351b2015-07-28 10:17:20 -06009766 BeginCommandBuffer();
Karl Schultz6addd812016-02-02 17:17:23 -07009767 // Don't care about RenderPass handle b/c error should be flagged before
9768 // that
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009769 vkCmdBeginRenderPass(m_commandBuffer->GetBufferHandle(), NULL, VK_SUBPASS_CONTENTS_INLINE);
Tobin Ehlis98aa0ed2015-06-25 16:27:19 -06009770
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009771 m_errorMonitor->VerifyFound();
Tobin Ehlis98aa0ed2015-06-25 16:27:19 -06009772}
9773
Karl Schultz6addd812016-02-02 17:17:23 -07009774TEST_F(VkLayerTest, RenderPassWithinRenderPass) {
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06009775 // Bind a BeginRenderPass within an active RenderPass
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009776 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
9777 "It is invalid to issue this call inside an active render pass");
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06009778
9779 ASSERT_NO_FATAL_FAILURE(InitState());
9780 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06009781
Tony Barbourfe3351b2015-07-28 10:17:20 -06009782 BeginCommandBuffer();
Karl Schultz6addd812016-02-02 17:17:23 -07009783 // Just create a dummy Renderpass that's non-NULL so we can get to the
9784 // proper error
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009785 vkCmdBeginRenderPass(m_commandBuffer->GetBufferHandle(), &m_renderPassBeginInfo, VK_SUBPASS_CONTENTS_INLINE);
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06009786
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009787 m_errorMonitor->VerifyFound();
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06009788}
9789
Chris Forbes2eeabe32016-06-21 20:52:34 +12009790TEST_F(VkLayerTest, RenderPassSecondaryCommandBuffersMultipleTimes) {
9791 m_errorMonitor->ExpectSuccess();
9792
9793 ASSERT_NO_FATAL_FAILURE(InitState());
9794 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
9795
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009796 BeginCommandBuffer(); // framework implicitly begins the renderpass.
Chris Forbes2eeabe32016-06-21 20:52:34 +12009797 vkCmdEndRenderPass(m_commandBuffer->GetBufferHandle()); // end implicit.
9798
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009799 vkCmdBeginRenderPass(m_commandBuffer->GetBufferHandle(), &m_renderPassBeginInfo, VK_SUBPASS_CONTENTS_SECONDARY_COMMAND_BUFFERS);
Chris Forbes2eeabe32016-06-21 20:52:34 +12009800 vkCmdEndRenderPass(m_commandBuffer->GetBufferHandle());
9801 m_errorMonitor->VerifyNotFound();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009802 vkCmdBeginRenderPass(m_commandBuffer->GetBufferHandle(), &m_renderPassBeginInfo, VK_SUBPASS_CONTENTS_INLINE);
Chris Forbes2eeabe32016-06-21 20:52:34 +12009803 m_errorMonitor->VerifyNotFound();
9804 vkCmdEndRenderPass(m_commandBuffer->GetBufferHandle());
9805 m_errorMonitor->VerifyNotFound();
9806
9807 m_commandBuffer->EndCommandBuffer();
9808 m_errorMonitor->VerifyNotFound();
9809}
9810
Tobin Ehlis5a1c0332016-05-31 13:59:26 -06009811TEST_F(VkLayerTest, RenderPassClearOpMismatch) {
9812 TEST_DESCRIPTION("Begin a renderPass where clearValueCount is less than"
9813 "the number of renderPass attachments that use loadOp"
9814 "VK_ATTACHMENT_LOAD_OP_CLEAR.");
9815
9816 ASSERT_NO_FATAL_FAILURE(InitState());
9817 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
9818
9819 // Create a renderPass with a single attachment that uses loadOp CLEAR
9820 VkAttachmentReference attach = {};
9821 attach.layout = VK_IMAGE_LAYOUT_GENERAL;
9822 VkSubpassDescription subpass = {};
9823 subpass.inputAttachmentCount = 1;
9824 subpass.pInputAttachments = &attach;
9825 VkRenderPassCreateInfo rpci = {};
9826 rpci.subpassCount = 1;
9827 rpci.pSubpasses = &subpass;
9828 rpci.attachmentCount = 1;
9829 VkAttachmentDescription attach_desc = {};
9830 attach_desc.format = VK_FORMAT_UNDEFINED;
9831 // Set loadOp to CLEAR
9832 attach_desc.loadOp = VK_ATTACHMENT_LOAD_OP_CLEAR;
9833 rpci.pAttachments = &attach_desc;
9834 rpci.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
9835 VkRenderPass rp;
9836 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
9837
9838 VkCommandBufferInheritanceInfo hinfo = {};
9839 hinfo.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_INHERITANCE_INFO;
9840 hinfo.renderPass = VK_NULL_HANDLE;
9841 hinfo.subpass = 0;
9842 hinfo.framebuffer = VK_NULL_HANDLE;
9843 hinfo.occlusionQueryEnable = VK_FALSE;
9844 hinfo.queryFlags = 0;
9845 hinfo.pipelineStatistics = 0;
9846 VkCommandBufferBeginInfo info = {};
9847 info.flags = VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT;
9848 info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
9849 info.pInheritanceInfo = &hinfo;
9850
9851 vkBeginCommandBuffer(m_commandBuffer->handle(), &info);
9852 VkRenderPassBeginInfo rp_begin = {};
9853 rp_begin.sType = VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO;
9854 rp_begin.pNext = NULL;
9855 rp_begin.renderPass = renderPass();
9856 rp_begin.framebuffer = framebuffer();
9857 rp_begin.clearValueCount = 0; // Should be 1
9858
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009859 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " has a clearValueCount of 0 but "
9860 "there must be at least 1 entries in "
9861 "pClearValues array to account for ");
Tobin Ehlis5a1c0332016-05-31 13:59:26 -06009862
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009863 vkCmdBeginRenderPass(m_commandBuffer->GetBufferHandle(), &rp_begin, VK_SUBPASS_CONTENTS_INLINE);
Tobin Ehlis5a1c0332016-05-31 13:59:26 -06009864
9865 m_errorMonitor->VerifyFound();
Mark Lobodzinski5c70ebd2016-06-09 13:45:00 -06009866
9867 vkDestroyRenderPass(m_device->device(), rp, NULL);
Tobin Ehlis5a1c0332016-05-31 13:59:26 -06009868}
9869
Cody Northrop3bb4d962016-05-09 16:15:57 -06009870TEST_F(VkLayerTest, EndCommandBufferWithinRenderPass) {
9871
9872 TEST_DESCRIPTION("End a command buffer with an active render pass");
9873
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009874 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
9875 "It is invalid to issue this call inside an active render pass");
Cody Northrop3bb4d962016-05-09 16:15:57 -06009876
9877 ASSERT_NO_FATAL_FAILURE(InitState());
9878 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
9879
9880 // The framework's BeginCommandBuffer calls CreateRenderPass
9881 BeginCommandBuffer();
9882
9883 // Call directly into vkEndCommandBuffer instead of the
9884 // the framework's EndCommandBuffer, which inserts a
9885 // vkEndRenderPass
9886 vkEndCommandBuffer(m_commandBuffer->GetBufferHandle());
9887
9888 m_errorMonitor->VerifyFound();
9889
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009890 // TODO: Add test for VK_COMMAND_BUFFER_LEVEL_SECONDARY
9891 // TODO: Add test for VK_COMMAND_BUFFER_USAGE_RENDER_PASS_CONTINUE_BIT
Cody Northrop3bb4d962016-05-09 16:15:57 -06009892}
9893
Karl Schultz6addd812016-02-02 17:17:23 -07009894TEST_F(VkLayerTest, FillBufferWithinRenderPass) {
Mark Lobodzinskid5639502015-09-24 09:51:47 -06009895 // Call CmdFillBuffer within an active renderpass
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009896 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
9897 "It is invalid to issue this call inside an active render pass");
Mark Lobodzinskid5639502015-09-24 09:51:47 -06009898
9899 ASSERT_NO_FATAL_FAILURE(InitState());
9900 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Mark Lobodzinskid5639502015-09-24 09:51:47 -06009901
9902 // Renderpass is started here
9903 BeginCommandBuffer();
9904
9905 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009906 vk_testing::Buffer dstBuffer;
9907 dstBuffer.init_as_dst(*m_device, (VkDeviceSize)1024, reqs);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06009908
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009909 m_commandBuffer->FillBuffer(dstBuffer.handle(), 0, 4, 0x11111111);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06009910
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009911 m_errorMonitor->VerifyFound();
Mark Lobodzinskid5639502015-09-24 09:51:47 -06009912}
9913
Karl Schultz6addd812016-02-02 17:17:23 -07009914TEST_F(VkLayerTest, UpdateBufferWithinRenderPass) {
Mark Lobodzinskid5639502015-09-24 09:51:47 -06009915 // Call CmdUpdateBuffer within an active renderpass
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009916 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
9917 "It is invalid to issue this call inside an active render pass");
Mark Lobodzinskid5639502015-09-24 09:51:47 -06009918
9919 ASSERT_NO_FATAL_FAILURE(InitState());
9920 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Mark Lobodzinskid5639502015-09-24 09:51:47 -06009921
9922 // Renderpass is started here
9923 BeginCommandBuffer();
9924
9925 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009926 vk_testing::Buffer dstBuffer;
9927 dstBuffer.init_as_dst(*m_device, (VkDeviceSize)1024, reqs);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06009928
Karl Schultz6addd812016-02-02 17:17:23 -07009929 VkDeviceSize dstOffset = 0;
9930 VkDeviceSize dataSize = 1024;
Karl Schultzee344492016-07-11 15:09:57 -06009931 const void *pData = NULL;
Mark Lobodzinskid5639502015-09-24 09:51:47 -06009932
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009933 vkCmdUpdateBuffer(m_commandBuffer->GetBufferHandle(), dstBuffer.handle(), dstOffset, dataSize, pData);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06009934
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009935 m_errorMonitor->VerifyFound();
Mark Lobodzinskid5639502015-09-24 09:51:47 -06009936}
9937
Karl Schultz6addd812016-02-02 17:17:23 -07009938TEST_F(VkLayerTest, ClearColorImageWithinRenderPass) {
Mark Lobodzinskid5639502015-09-24 09:51:47 -06009939 // Call CmdClearColorImage within an active RenderPass
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009940 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
9941 "It is invalid to issue this call inside an active render pass");
Mark Lobodzinskid5639502015-09-24 09:51:47 -06009942
9943 ASSERT_NO_FATAL_FAILURE(InitState());
9944 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Mark Lobodzinskid5639502015-09-24 09:51:47 -06009945
9946 // Renderpass is started here
9947 BeginCommandBuffer();
9948
Michael Lentine0a369f62016-02-03 16:51:46 -06009949 VkClearColorValue clear_color;
9950 memset(clear_color.uint32, 0, sizeof(uint32_t) * 4);
Karl Schultz6addd812016-02-02 17:17:23 -07009951 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
9952 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
9953 const int32_t tex_width = 32;
9954 const int32_t tex_height = 32;
9955 VkImageCreateInfo image_create_info = {};
9956 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
9957 image_create_info.pNext = NULL;
9958 image_create_info.imageType = VK_IMAGE_TYPE_2D;
9959 image_create_info.format = tex_format;
9960 image_create_info.extent.width = tex_width;
9961 image_create_info.extent.height = tex_height;
9962 image_create_info.extent.depth = 1;
9963 image_create_info.mipLevels = 1;
9964 image_create_info.arrayLayers = 1;
9965 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
9966 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
9967 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
Mark Lobodzinskid5639502015-09-24 09:51:47 -06009968
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009969 vk_testing::Image dstImage;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009970 dstImage.init(*m_device, (const VkImageCreateInfo &)image_create_info, reqs);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06009971
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009972 const VkImageSubresourceRange range = vk_testing::Image::subresource_range(image_create_info, VK_IMAGE_ASPECT_COLOR_BIT);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06009973
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009974 vkCmdClearColorImage(m_commandBuffer->GetBufferHandle(), dstImage.handle(), VK_IMAGE_LAYOUT_GENERAL, &clear_color, 1, &range);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06009975
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009976 m_errorMonitor->VerifyFound();
Mark Lobodzinskid5639502015-09-24 09:51:47 -06009977}
9978
Karl Schultz6addd812016-02-02 17:17:23 -07009979TEST_F(VkLayerTest, ClearDepthStencilImageWithinRenderPass) {
Mark Lobodzinskid5639502015-09-24 09:51:47 -06009980 // Call CmdClearDepthStencilImage within an active RenderPass
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009981 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
9982 "It is invalid to issue this call inside an active render pass");
Mark Lobodzinskid5639502015-09-24 09:51:47 -06009983
9984 ASSERT_NO_FATAL_FAILURE(InitState());
9985 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Mark Lobodzinskid5639502015-09-24 09:51:47 -06009986
9987 // Renderpass is started here
9988 BeginCommandBuffer();
9989
9990 VkClearDepthStencilValue clear_value = {0};
Dustin Gravesa2e5c942016-02-11 18:28:06 -07009991 VkMemoryPropertyFlags reqs = 0;
Karl Schultz6addd812016-02-02 17:17:23 -07009992 VkImageCreateInfo image_create_info = vk_testing::Image::create_info();
9993 image_create_info.imageType = VK_IMAGE_TYPE_2D;
9994 image_create_info.format = VK_FORMAT_D24_UNORM_S8_UINT;
9995 image_create_info.extent.width = 64;
9996 image_create_info.extent.height = 64;
9997 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
9998 image_create_info.usage = VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT;
Mark Lobodzinskid5639502015-09-24 09:51:47 -06009999
Chia-I Wu3432a0c2015-10-27 18:04:07 +080010000 vk_testing::Image dstImage;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010001 dstImage.init(*m_device, (const VkImageCreateInfo &)image_create_info, reqs);
Mark Lobodzinskid5639502015-09-24 09:51:47 -060010002
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010003 const VkImageSubresourceRange range = vk_testing::Image::subresource_range(image_create_info, VK_IMAGE_ASPECT_DEPTH_BIT);
Mark Lobodzinskid5639502015-09-24 09:51:47 -060010004
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010005 vkCmdClearDepthStencilImage(m_commandBuffer->GetBufferHandle(), dstImage.handle(),
10006 VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL, &clear_value, 1, &range);
Mark Lobodzinskid5639502015-09-24 09:51:47 -060010007
Chris Forbes8f36a8a2016-04-07 13:21:07 +120010008 m_errorMonitor->VerifyFound();
Mark Lobodzinskid5639502015-09-24 09:51:47 -060010009}
10010
Karl Schultz6addd812016-02-02 17:17:23 -070010011TEST_F(VkLayerTest, ClearColorAttachmentsOutsideRenderPass) {
Courtney Goeltzenleuchterc9323e02015-10-15 16:51:05 -060010012 // Call CmdClearAttachmentss outside of an active RenderPass
Karl Schultz6addd812016-02-02 17:17:23 -070010013 VkResult err;
Mark Lobodzinskid5639502015-09-24 09:51:47 -060010014
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010015 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "vkCmdClearAttachments(): This call "
10016 "must be issued inside an active "
10017 "render pass");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060010018
Mark Lobodzinskid5639502015-09-24 09:51:47 -060010019 ASSERT_NO_FATAL_FAILURE(InitState());
10020 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Mark Lobodzinskid5639502015-09-24 09:51:47 -060010021
10022 // Start no RenderPass
Chia-I Wu3432a0c2015-10-27 18:04:07 +080010023 err = m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskid5639502015-09-24 09:51:47 -060010024 ASSERT_VK_SUCCESS(err);
10025
Courtney Goeltzenleuchterc9323e02015-10-15 16:51:05 -060010026 VkClearAttachment color_attachment;
10027 color_attachment.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
10028 color_attachment.clearValue.color.float32[0] = 0;
10029 color_attachment.clearValue.color.float32[1] = 0;
10030 color_attachment.clearValue.color.float32[2] = 0;
10031 color_attachment.clearValue.color.float32[3] = 0;
10032 color_attachment.colorAttachment = 0;
Karl Schultz6addd812016-02-02 17:17:23 -070010033 VkClearRect clear_rect = {{{0, 0}, {32, 32}}};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010034 vkCmdClearAttachments(m_commandBuffer->GetBufferHandle(), 1, &color_attachment, 1, &clear_rect);
Mark Lobodzinskid5639502015-09-24 09:51:47 -060010035
Chris Forbes8f36a8a2016-04-07 13:21:07 +120010036 m_errorMonitor->VerifyFound();
Mark Lobodzinskid5639502015-09-24 09:51:47 -060010037}
10038
Chris Forbes3b97e932016-09-07 11:29:24 +120010039TEST_F(VkLayerTest, RenderPassExcessiveNextSubpass) {
10040 TEST_DESCRIPTION("Test that an error is produced when CmdNextSubpass is "
10041 "called too many times in a renderpass instance");
10042
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010043 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "vkCmdNextSubpass(): Attempted to advance "
10044 "beyond final subpass");
Chris Forbes3b97e932016-09-07 11:29:24 +120010045
10046 ASSERT_NO_FATAL_FAILURE(InitState());
10047 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
10048
10049 BeginCommandBuffer();
10050
10051 // error here.
10052 vkCmdNextSubpass(m_commandBuffer->GetBufferHandle(), VK_SUBPASS_CONTENTS_INLINE);
10053 m_errorMonitor->VerifyFound();
10054
10055 EndCommandBuffer();
10056}
10057
Chris Forbes6d624702016-09-07 13:57:05 +120010058TEST_F(VkLayerTest, RenderPassEndedBeforeFinalSubpass) {
10059 TEST_DESCRIPTION("Test that an error is produced when CmdEndRenderPass is "
10060 "called before the final subpass has been reached");
10061
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010062 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "vkCmdEndRenderPass(): Called before reaching "
10063 "final subpass");
Chris Forbes6d624702016-09-07 13:57:05 +120010064
10065 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010066 VkSubpassDescription sd[2] = {{0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 0, nullptr, nullptr, nullptr, 0, nullptr},
10067 {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 0, nullptr, nullptr, nullptr, 0, nullptr}};
Chris Forbes6d624702016-09-07 13:57:05 +120010068
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010069 VkRenderPassCreateInfo rcpi = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 0, nullptr, 2, sd, 0, nullptr};
Chris Forbes6d624702016-09-07 13:57:05 +120010070
10071 VkRenderPass rp;
10072 VkResult err = vkCreateRenderPass(m_device->device(), &rcpi, nullptr, &rp);
10073 ASSERT_VK_SUCCESS(err);
10074
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010075 VkFramebufferCreateInfo fbci = {VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr, 0, rp, 0, nullptr, 16, 16, 1};
Chris Forbes6d624702016-09-07 13:57:05 +120010076
10077 VkFramebuffer fb;
10078 err = vkCreateFramebuffer(m_device->device(), &fbci, nullptr, &fb);
10079 ASSERT_VK_SUCCESS(err);
10080
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010081 m_commandBuffer->BeginCommandBuffer(); // no implicit RP begin
Chris Forbes6d624702016-09-07 13:57:05 +120010082
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010083 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 +120010084
10085 vkCmdBeginRenderPass(m_commandBuffer->GetBufferHandle(), &rpbi, VK_SUBPASS_CONTENTS_INLINE);
10086
10087 // Error here.
10088 vkCmdEndRenderPass(m_commandBuffer->GetBufferHandle());
10089 m_errorMonitor->VerifyFound();
10090
10091 // Clean up.
10092 vkDestroyFramebuffer(m_device->device(), fb, nullptr);
10093 vkDestroyRenderPass(m_device->device(), rp, nullptr);
10094}
10095
Karl Schultz9e66a292016-04-21 15:57:51 -060010096TEST_F(VkLayerTest, BufferMemoryBarrierNoBuffer) {
10097 // Try to add a buffer memory barrier with no buffer.
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010098 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
10099 "required parameter pBufferMemoryBarriers[0].buffer specified as VK_NULL_HANDLE");
Karl Schultz9e66a292016-04-21 15:57:51 -060010100
10101 ASSERT_NO_FATAL_FAILURE(InitState());
10102 BeginCommandBuffer();
10103
10104 VkBufferMemoryBarrier buf_barrier = {};
10105 buf_barrier.sType = VK_STRUCTURE_TYPE_BUFFER_MEMORY_BARRIER;
10106 buf_barrier.srcAccessMask = VK_ACCESS_HOST_WRITE_BIT;
10107 buf_barrier.dstAccessMask = VK_ACCESS_SHADER_READ_BIT;
10108 buf_barrier.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
10109 buf_barrier.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
10110 buf_barrier.buffer = VK_NULL_HANDLE;
10111 buf_barrier.offset = 0;
10112 buf_barrier.size = VK_WHOLE_SIZE;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010113 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
10114 nullptr, 1, &buf_barrier, 0, nullptr);
Karl Schultz9e66a292016-04-21 15:57:51 -060010115
10116 m_errorMonitor->VerifyFound();
10117}
10118
Tony Barbour7fd5c0f2016-05-03 16:11:53 -060010119TEST_F(VkLayerTest, InvalidBarriers) {
10120 TEST_DESCRIPTION("A variety of ways to get VK_INVALID_BARRIER ");
10121
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010122 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Barriers cannot be set during subpass");
Tony Barbour7fd5c0f2016-05-03 16:11:53 -060010123
10124 ASSERT_NO_FATAL_FAILURE(InitState());
10125 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
10126
10127 VkMemoryBarrier mem_barrier = {};
10128 mem_barrier.sType = VK_STRUCTURE_TYPE_MEMORY_BARRIER;
10129 mem_barrier.pNext = NULL;
10130 mem_barrier.srcAccessMask = VK_ACCESS_HOST_WRITE_BIT;
10131 mem_barrier.dstAccessMask = VK_ACCESS_SHADER_READ_BIT;
10132 BeginCommandBuffer();
10133 // BeginCommandBuffer() starts a render pass
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010134 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 1,
Tony Barbour7fd5c0f2016-05-03 16:11:53 -060010135 &mem_barrier, 0, nullptr, 0, nullptr);
10136 m_errorMonitor->VerifyFound();
10137
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010138 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Image Layout cannot be transitioned to UNDEFINED");
Tony Barbour7fd5c0f2016-05-03 16:11:53 -060010139 VkImageObj image(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010140 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 -060010141 ASSERT_TRUE(image.initialized());
10142 VkImageMemoryBarrier img_barrier = {};
10143 img_barrier.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
10144 img_barrier.pNext = NULL;
10145 img_barrier.srcAccessMask = VK_ACCESS_HOST_WRITE_BIT;
10146 img_barrier.dstAccessMask = VK_ACCESS_SHADER_READ_BIT;
10147 img_barrier.oldLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
10148 // New layout can't be UNDEFINED
10149 img_barrier.newLayout = VK_IMAGE_LAYOUT_UNDEFINED;
10150 img_barrier.image = image.handle();
10151 img_barrier.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
10152 img_barrier.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
10153 img_barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
10154 img_barrier.subresourceRange.baseArrayLayer = 0;
10155 img_barrier.subresourceRange.baseMipLevel = 0;
10156 img_barrier.subresourceRange.layerCount = 1;
10157 img_barrier.subresourceRange.levelCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010158 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
10159 nullptr, 0, nullptr, 1, &img_barrier);
Tony Barbour7fd5c0f2016-05-03 16:11:53 -060010160 m_errorMonitor->VerifyFound();
10161 img_barrier.newLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
10162
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010163 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Subresource must have the sum of the "
10164 "baseArrayLayer");
Tony Barbour7fd5c0f2016-05-03 16:11:53 -060010165 // baseArrayLayer + layerCount must be <= image's arrayLayers
10166 img_barrier.subresourceRange.baseArrayLayer = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010167 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
10168 nullptr, 0, nullptr, 1, &img_barrier);
Tony Barbour7fd5c0f2016-05-03 16:11:53 -060010169 m_errorMonitor->VerifyFound();
10170 img_barrier.subresourceRange.baseArrayLayer = 0;
10171
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010172 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Subresource must have the sum of the baseMipLevel");
Tony Barbour7fd5c0f2016-05-03 16:11:53 -060010173 // baseMipLevel + levelCount must be <= image's mipLevels
10174 img_barrier.subresourceRange.baseMipLevel = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010175 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
10176 nullptr, 0, nullptr, 1, &img_barrier);
Tony Barbour7fd5c0f2016-05-03 16:11:53 -060010177 m_errorMonitor->VerifyFound();
10178 img_barrier.subresourceRange.baseMipLevel = 0;
10179
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010180 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 -060010181 vk_testing::Buffer buffer;
10182 buffer.init(*m_device, 256);
10183 VkBufferMemoryBarrier buf_barrier = {};
10184 buf_barrier.sType = VK_STRUCTURE_TYPE_BUFFER_MEMORY_BARRIER;
10185 buf_barrier.pNext = NULL;
10186 buf_barrier.srcAccessMask = VK_ACCESS_HOST_WRITE_BIT;
10187 buf_barrier.dstAccessMask = VK_ACCESS_SHADER_READ_BIT;
10188 buf_barrier.buffer = buffer.handle();
10189 buf_barrier.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
10190 buf_barrier.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
10191 buf_barrier.offset = 0;
10192 buf_barrier.size = VK_WHOLE_SIZE;
10193 // Can't send buffer barrier during a render pass
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010194 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
10195 nullptr, 1, &buf_barrier, 0, nullptr);
Tony Barbour7fd5c0f2016-05-03 16:11:53 -060010196 m_errorMonitor->VerifyFound();
10197 vkCmdEndRenderPass(m_commandBuffer->GetBufferHandle());
10198
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010199 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "which is not less than total size");
Tony Barbour7fd5c0f2016-05-03 16:11:53 -060010200 buf_barrier.offset = 257;
10201 // Offset greater than total size
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010202 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
10203 nullptr, 1, &buf_barrier, 0, nullptr);
Tony Barbour7fd5c0f2016-05-03 16:11:53 -060010204 m_errorMonitor->VerifyFound();
10205 buf_barrier.offset = 0;
10206
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010207 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "whose sum is greater than total size");
Tony Barbour7fd5c0f2016-05-03 16:11:53 -060010208 buf_barrier.size = 257;
10209 // Size greater than total size
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010210 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
10211 nullptr, 1, &buf_barrier, 0, nullptr);
Tony Barbour7fd5c0f2016-05-03 16:11:53 -060010212 m_errorMonitor->VerifyFound();
Tony Barbour7fd5c0f2016-05-03 16:11:53 -060010213
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -060010214 // Now exercise barrier aspect bit errors, first DS
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010215 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Image is a depth and stencil format and thus must "
10216 "have either one or both of VK_IMAGE_ASPECT_DEPTH_BIT and "
10217 "VK_IMAGE_ASPECT_STENCIL_BIT set.");
Tony Barbour7fd5c0f2016-05-03 16:11:53 -060010218 VkDepthStencilObj ds_image(m_device);
10219 ds_image.Init(m_device, 128, 128, VK_FORMAT_D24_UNORM_S8_UINT);
10220 ASSERT_TRUE(ds_image.initialized());
Tobin Ehlis15684a02016-07-21 14:55:26 -060010221 img_barrier.oldLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
10222 img_barrier.newLayout = VK_IMAGE_LAYOUT_GENERAL;
Tony Barbour7fd5c0f2016-05-03 16:11:53 -060010223 img_barrier.image = ds_image.handle();
Tobin Ehlis15684a02016-07-21 14:55:26 -060010224 // Use of COLOR aspect on DS image is error
10225 img_barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010226 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
10227 nullptr, 0, nullptr, 1, &img_barrier);
Tony Barbour7fd5c0f2016-05-03 16:11:53 -060010228 m_errorMonitor->VerifyFound();
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -060010229 // Now test depth-only
10230 VkFormatProperties format_props;
10231
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010232 vkGetPhysicalDeviceFormatProperties(m_device->phy().handle(), VK_FORMAT_D16_UNORM, &format_props);
10233 if (format_props.optimalTilingFeatures & VK_FORMAT_FEATURE_DEPTH_STENCIL_ATTACHMENT_BIT) {
10234 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Image is a depth-only format and thus must "
10235 "have VK_IMAGE_ASPECT_DEPTH_BIT set.");
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -060010236 VkDepthStencilObj d_image(m_device);
10237 d_image.Init(m_device, 128, 128, VK_FORMAT_D16_UNORM);
10238 ASSERT_TRUE(d_image.initialized());
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010239 img_barrier.oldLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
Tobin Ehlis15684a02016-07-21 14:55:26 -060010240 img_barrier.newLayout = VK_IMAGE_LAYOUT_GENERAL;
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -060010241 img_barrier.image = d_image.handle();
Tobin Ehlis15684a02016-07-21 14:55:26 -060010242 // Use of COLOR aspect on depth image is error
10243 img_barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010244 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0,
10245 0, nullptr, 0, nullptr, 1, &img_barrier);
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -060010246 m_errorMonitor->VerifyFound();
10247 }
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010248 vkGetPhysicalDeviceFormatProperties(m_device->phy().handle(), VK_FORMAT_S8_UINT, &format_props);
10249 if (format_props.optimalTilingFeatures & VK_FORMAT_FEATURE_DEPTH_STENCIL_ATTACHMENT_BIT) {
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -060010250 // Now test stencil-only
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010251 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Image is a stencil-only format and thus must "
10252 "have VK_IMAGE_ASPECT_STENCIL_BIT set.");
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -060010253 VkDepthStencilObj s_image(m_device);
10254 s_image.Init(m_device, 128, 128, VK_FORMAT_S8_UINT);
10255 ASSERT_TRUE(s_image.initialized());
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010256 img_barrier.oldLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
Tobin Ehlis15684a02016-07-21 14:55:26 -060010257 img_barrier.newLayout = VK_IMAGE_LAYOUT_GENERAL;
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -060010258 img_barrier.image = s_image.handle();
Tobin Ehlis15684a02016-07-21 14:55:26 -060010259 // Use of COLOR aspect on depth image is error
10260 img_barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010261 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0,
10262 0, nullptr, 0, nullptr, 1, &img_barrier);
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -060010263 m_errorMonitor->VerifyFound();
10264 }
10265 // Finally test color
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010266 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Image is a color format and thus must "
10267 "have VK_IMAGE_ASPECT_COLOR_BIT set.");
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -060010268 VkImageObj c_image(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010269 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 -060010270 ASSERT_TRUE(c_image.initialized());
10271 img_barrier.oldLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
10272 img_barrier.newLayout = VK_IMAGE_LAYOUT_GENERAL;
10273 img_barrier.image = c_image.handle();
10274 // Set aspect to depth (non-color)
10275 img_barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010276 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
10277 nullptr, 0, nullptr, 1, &img_barrier);
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -060010278 m_errorMonitor->VerifyFound();
Tony Barbour7fd5c0f2016-05-03 16:11:53 -060010279}
10280
Karl Schultz6addd812016-02-02 17:17:23 -070010281TEST_F(VkLayerTest, IdxBufferAlignmentError) {
Tobin Ehlisc4c23182015-09-17 12:24:13 -060010282 // Bind a BeginRenderPass within an active RenderPass
Karl Schultz6addd812016-02-02 17:17:23 -070010283 VkResult err;
Tobin Ehlisc4c23182015-09-17 12:24:13 -060010284
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010285 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "vkCmdBindIndexBuffer() offset (0x7) does not fall on ");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060010286
Tobin Ehlisc4c23182015-09-17 12:24:13 -060010287 ASSERT_NO_FATAL_FAILURE(InitState());
10288 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlisc4c23182015-09-17 12:24:13 -060010289 uint32_t qfi = 0;
10290 VkBufferCreateInfo buffCI = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010291 buffCI.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
10292 buffCI.size = 1024;
10293 buffCI.usage = VK_BUFFER_USAGE_INDEX_BUFFER_BIT;
10294 buffCI.queueFamilyIndexCount = 1;
10295 buffCI.pQueueFamilyIndices = &qfi;
Tobin Ehlisc4c23182015-09-17 12:24:13 -060010296
10297 VkBuffer ib;
Chia-I Wuf7458c52015-10-26 21:10:41 +080010298 err = vkCreateBuffer(m_device->device(), &buffCI, NULL, &ib);
Tobin Ehlisc4c23182015-09-17 12:24:13 -060010299 ASSERT_VK_SUCCESS(err);
10300
10301 BeginCommandBuffer();
10302 ASSERT_VK_SUCCESS(err);
Karl Schultz6addd812016-02-02 17:17:23 -070010303 // vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(),
10304 // VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Tobin Ehlisc4c23182015-09-17 12:24:13 -060010305 // Should error before calling to driver so don't care about actual data
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010306 vkCmdBindIndexBuffer(m_commandBuffer->GetBufferHandle(), ib, 7, VK_INDEX_TYPE_UINT16);
Tobin Ehlisc4c23182015-09-17 12:24:13 -060010307
Chris Forbes8f36a8a2016-04-07 13:21:07 +120010308 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -060010309
Chia-I Wuf7458c52015-10-26 21:10:41 +080010310 vkDestroyBuffer(m_device->device(), ib, NULL);
Tobin Ehlisc4c23182015-09-17 12:24:13 -060010311}
10312
Mark Lobodzinski52a6e7d2016-02-25 15:09:52 -070010313TEST_F(VkLayerTest, InvalidQueueFamilyIndex) {
10314 // Create an out-of-range queueFamilyIndex
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010315 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
10316 "vkCreateBuffer: pCreateInfo->pQueueFamilyIndices[0] (777) must be one "
10317 "of the indices specified when the device was created, via the "
10318 "VkDeviceQueueCreateInfo structure.");
Mark Lobodzinski52a6e7d2016-02-25 15:09:52 -070010319
10320 ASSERT_NO_FATAL_FAILURE(InitState());
10321 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
10322 VkBufferCreateInfo buffCI = {};
10323 buffCI.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
10324 buffCI.size = 1024;
10325 buffCI.usage = VK_BUFFER_USAGE_INDEX_BUFFER_BIT;
10326 buffCI.queueFamilyIndexCount = 1;
10327 // Introduce failure by specifying invalid queue_family_index
10328 uint32_t qfi = 777;
10329 buffCI.pQueueFamilyIndices = &qfi;
Tobin Ehlis24aab042016-03-24 10:54:18 -060010330 buffCI.sharingMode = VK_SHARING_MODE_CONCURRENT; // qfi only matters in CONCURRENT mode
Mark Lobodzinski52a6e7d2016-02-25 15:09:52 -070010331
10332 VkBuffer ib;
10333 vkCreateBuffer(m_device->device(), &buffCI, NULL, &ib);
10334
Chris Forbes8f36a8a2016-04-07 13:21:07 +120010335 m_errorMonitor->VerifyFound();
Tony Barbourdf4c0042016-06-01 15:55:43 -060010336 vkDestroyBuffer(m_device->device(), ib, NULL);
Mark Lobodzinski52a6e7d2016-02-25 15:09:52 -070010337}
10338
Karl Schultz6addd812016-02-02 17:17:23 -070010339TEST_F(VkLayerTest, ExecuteCommandsPrimaryCB) {
Tobin Ehlis0c94db02016-07-19 10:49:32 -060010340 TEST_DESCRIPTION("Attempt vkCmdExecuteCommands w/ a primary cmd buffer"
10341 " (should only be secondary)");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060010342
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010343 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "vkCmdExecuteCommands() called w/ Primary Cmd Buffer ");
Tobin Ehlis4b34ddc2015-09-17 14:18:16 -060010344
10345 ASSERT_NO_FATAL_FAILURE(InitState());
10346 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlis4b34ddc2015-09-17 14:18:16 -060010347
10348 BeginCommandBuffer();
Tobin Ehlis0c94db02016-07-19 10:49:32 -060010349
Chia-I Wu3432a0c2015-10-27 18:04:07 +080010350 VkCommandBuffer primCB = m_commandBuffer->GetBufferHandle();
10351 vkCmdExecuteCommands(m_commandBuffer->GetBufferHandle(), 1, &primCB);
Tobin Ehlis4b34ddc2015-09-17 14:18:16 -060010352
Chris Forbes8f36a8a2016-04-07 13:21:07 +120010353 m_errorMonitor->VerifyFound();
Tobin Ehlis4b34ddc2015-09-17 14:18:16 -060010354}
10355
Tobin Ehlis17826bd2016-05-25 11:12:50 -060010356TEST_F(VkLayerTest, DSUsageBitsErrors) {
10357 TEST_DESCRIPTION("Attempt to update descriptor sets for images and buffers "
10358 "that do not have correct usage bits sets.");
10359 VkResult err;
10360
10361 ASSERT_NO_FATAL_FAILURE(InitState());
10362 VkDescriptorPoolSize ds_type_count[VK_DESCRIPTOR_TYPE_RANGE_SIZE] = {};
10363 for (uint32_t i = 0; i < VK_DESCRIPTOR_TYPE_RANGE_SIZE; ++i) {
10364 ds_type_count[i].type = VkDescriptorType(i);
10365 ds_type_count[i].descriptorCount = 1;
10366 }
10367 VkDescriptorPoolCreateInfo ds_pool_ci = {};
10368 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
10369 ds_pool_ci.pNext = NULL;
10370 ds_pool_ci.maxSets = VK_DESCRIPTOR_TYPE_RANGE_SIZE;
10371 ds_pool_ci.poolSizeCount = VK_DESCRIPTOR_TYPE_RANGE_SIZE;
10372 ds_pool_ci.pPoolSizes = ds_type_count;
10373
10374 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010375 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis17826bd2016-05-25 11:12:50 -060010376 ASSERT_VK_SUCCESS(err);
10377
10378 // Create 10 layouts where each has a single descriptor of different type
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010379 VkDescriptorSetLayoutBinding dsl_binding[VK_DESCRIPTOR_TYPE_RANGE_SIZE] = {};
Tobin Ehlis17826bd2016-05-25 11:12:50 -060010380 for (uint32_t i = 0; i < VK_DESCRIPTOR_TYPE_RANGE_SIZE; ++i) {
10381 dsl_binding[i].binding = 0;
10382 dsl_binding[i].descriptorType = VkDescriptorType(i);
10383 dsl_binding[i].descriptorCount = 1;
10384 dsl_binding[i].stageFlags = VK_SHADER_STAGE_ALL;
10385 dsl_binding[i].pImmutableSamplers = NULL;
10386 }
10387
10388 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
10389 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
10390 ds_layout_ci.pNext = NULL;
10391 ds_layout_ci.bindingCount = 1;
10392 VkDescriptorSetLayout ds_layouts[VK_DESCRIPTOR_TYPE_RANGE_SIZE];
10393 for (uint32_t i = 0; i < VK_DESCRIPTOR_TYPE_RANGE_SIZE; ++i) {
10394 ds_layout_ci.pBindings = dsl_binding + i;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010395 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, ds_layouts + i);
Tobin Ehlis17826bd2016-05-25 11:12:50 -060010396 ASSERT_VK_SUCCESS(err);
10397 }
10398 VkDescriptorSet descriptor_sets[VK_DESCRIPTOR_TYPE_RANGE_SIZE] = {};
10399 VkDescriptorSetAllocateInfo alloc_info = {};
10400 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
10401 alloc_info.descriptorSetCount = VK_DESCRIPTOR_TYPE_RANGE_SIZE;
10402 alloc_info.descriptorPool = ds_pool;
10403 alloc_info.pSetLayouts = ds_layouts;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010404 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, descriptor_sets);
Tobin Ehlis17826bd2016-05-25 11:12:50 -060010405 ASSERT_VK_SUCCESS(err);
10406
10407 // Create a buffer & bufferView to be used for invalid updates
10408 VkBufferCreateInfo buff_ci = {};
10409 buff_ci.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
10410 // This usage is not valid for any descriptor type
10411 buff_ci.usage = VK_BUFFER_USAGE_TRANSFER_SRC_BIT;
10412 buff_ci.size = 256;
10413 buff_ci.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
10414 VkBuffer buffer;
10415 err = vkCreateBuffer(m_device->device(), &buff_ci, NULL, &buffer);
10416 ASSERT_VK_SUCCESS(err);
10417
10418 VkBufferViewCreateInfo buff_view_ci = {};
10419 buff_view_ci.sType = VK_STRUCTURE_TYPE_BUFFER_VIEW_CREATE_INFO;
10420 buff_view_ci.buffer = buffer;
10421 buff_view_ci.format = VK_FORMAT_R8_UNORM;
10422 buff_view_ci.range = VK_WHOLE_SIZE;
10423 VkBufferView buff_view;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010424 err = vkCreateBufferView(m_device->device(), &buff_view_ci, NULL, &buff_view);
Tobin Ehlis17826bd2016-05-25 11:12:50 -060010425 ASSERT_VK_SUCCESS(err);
10426
10427 // Create an image to be used for invalid updates
10428 VkImageCreateInfo image_ci = {};
10429 image_ci.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
10430 image_ci.imageType = VK_IMAGE_TYPE_2D;
10431 image_ci.format = VK_FORMAT_R8G8B8A8_UNORM;
10432 image_ci.extent.width = 64;
10433 image_ci.extent.height = 64;
10434 image_ci.extent.depth = 1;
10435 image_ci.mipLevels = 1;
10436 image_ci.arrayLayers = 1;
10437 image_ci.samples = VK_SAMPLE_COUNT_1_BIT;
10438 image_ci.tiling = VK_IMAGE_TILING_LINEAR;
10439 image_ci.initialLayout = VK_IMAGE_LAYOUT_PREINITIALIZED;
10440 // This usage is not valid for any descriptor type
10441 image_ci.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
10442 image_ci.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
10443 VkImage image;
10444 err = vkCreateImage(m_device->device(), &image_ci, NULL, &image);
10445 ASSERT_VK_SUCCESS(err);
10446 // Bind memory to image
10447 VkMemoryRequirements mem_reqs;
10448 VkDeviceMemory image_mem;
10449 bool pass;
10450 VkMemoryAllocateInfo mem_alloc = {};
10451 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
10452 mem_alloc.pNext = NULL;
10453 mem_alloc.allocationSize = 0;
10454 mem_alloc.memoryTypeIndex = 0;
10455 vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs);
10456 mem_alloc.allocationSize = mem_reqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010457 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0);
Tobin Ehlis17826bd2016-05-25 11:12:50 -060010458 ASSERT_TRUE(pass);
10459 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &image_mem);
10460 ASSERT_VK_SUCCESS(err);
10461 err = vkBindImageMemory(m_device->device(), image, image_mem, 0);
10462 ASSERT_VK_SUCCESS(err);
10463 // Now create view for image
10464 VkImageViewCreateInfo image_view_ci = {};
10465 image_view_ci.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
10466 image_view_ci.image = image;
10467 image_view_ci.format = VK_FORMAT_R8G8B8A8_UNORM;
10468 image_view_ci.viewType = VK_IMAGE_VIEW_TYPE_2D;
10469 image_view_ci.subresourceRange.layerCount = 1;
10470 image_view_ci.subresourceRange.baseArrayLayer = 0;
10471 image_view_ci.subresourceRange.levelCount = 1;
10472 image_view_ci.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
10473 VkImageView image_view;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010474 err = vkCreateImageView(m_device->device(), &image_view_ci, NULL, &image_view);
Tobin Ehlis17826bd2016-05-25 11:12:50 -060010475 ASSERT_VK_SUCCESS(err);
10476
10477 VkDescriptorBufferInfo buff_info = {};
10478 buff_info.buffer = buffer;
10479 VkDescriptorImageInfo img_info = {};
10480 img_info.imageView = image_view;
10481 VkWriteDescriptorSet descriptor_write = {};
10482 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
10483 descriptor_write.dstBinding = 0;
10484 descriptor_write.descriptorCount = 1;
10485 descriptor_write.pTexelBufferView = &buff_view;
10486 descriptor_write.pBufferInfo = &buff_info;
10487 descriptor_write.pImageInfo = &img_info;
10488
10489 // These error messages align with VkDescriptorType struct
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010490 const char *error_msgs[] = {"", // placeholder, no error for SAMPLER descriptor
10491 " does not have VK_IMAGE_USAGE_SAMPLED_BIT set.",
10492 " does not have VK_IMAGE_USAGE_SAMPLED_BIT set.",
10493 " does not have VK_IMAGE_USAGE_STORAGE_BIT set.",
10494 " does not have VK_BUFFER_USAGE_UNIFORM_TEXEL_BUFFER_BIT set.",
10495 " does not have VK_BUFFER_USAGE_STORAGE_TEXEL_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_BUFFER_USAGE_UNIFORM_BUFFER_BIT set.",
10499 " does not have VK_BUFFER_USAGE_STORAGE_BUFFER_BIT set.",
10500 " does not have VK_IMAGE_USAGE_INPUT_ATTACHMENT_BIT set."};
Tobin Ehlis17826bd2016-05-25 11:12:50 -060010501 // Start loop at 1 as SAMPLER desc type has no usage bit error
10502 for (uint32_t i = 1; i < VK_DESCRIPTOR_TYPE_RANGE_SIZE; ++i) {
10503 descriptor_write.descriptorType = VkDescriptorType(i);
10504 descriptor_write.dstSet = descriptor_sets[i];
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010505 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, error_msgs[i]);
Tobin Ehlis17826bd2016-05-25 11:12:50 -060010506
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010507 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
Tobin Ehlis17826bd2016-05-25 11:12:50 -060010508
10509 m_errorMonitor->VerifyFound();
10510 vkDestroyDescriptorSetLayout(m_device->device(), ds_layouts[i], NULL);
10511 }
10512 vkDestroyDescriptorSetLayout(m_device->device(), ds_layouts[0], NULL);
10513 vkDestroyImage(m_device->device(), image, NULL);
Tony Barbourdf4c0042016-06-01 15:55:43 -060010514 vkFreeMemory(m_device->device(), image_mem, NULL);
Tobin Ehlis17826bd2016-05-25 11:12:50 -060010515 vkDestroyImageView(m_device->device(), image_view, NULL);
10516 vkDestroyBuffer(m_device->device(), buffer, NULL);
10517 vkDestroyBufferView(m_device->device(), buff_view, NULL);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010518 vkFreeDescriptorSets(m_device->device(), ds_pool, VK_DESCRIPTOR_TYPE_RANGE_SIZE, descriptor_sets);
Tobin Ehlis17826bd2016-05-25 11:12:50 -060010519 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
10520}
10521
Tobin Ehlis585f66d2016-07-01 18:23:58 -060010522TEST_F(VkLayerTest, DSBufferInfoErrors) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010523 TEST_DESCRIPTION("Attempt to update buffer descriptor set that has incorrect "
10524 "parameters in VkDescriptorBufferInfo struct. This includes:\n"
10525 "1. offset value greater than buffer size\n"
10526 "2. range value of 0\n"
10527 "3. range value greater than buffer (size - offset)");
Tobin Ehlis585f66d2016-07-01 18:23:58 -060010528 VkResult err;
10529
10530 ASSERT_NO_FATAL_FAILURE(InitState());
10531 VkDescriptorPoolSize ds_type_count = {};
10532 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
10533 ds_type_count.descriptorCount = 1;
10534
10535 VkDescriptorPoolCreateInfo ds_pool_ci = {};
10536 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
10537 ds_pool_ci.pNext = NULL;
10538 ds_pool_ci.maxSets = 1;
10539 ds_pool_ci.poolSizeCount = 1;
10540 ds_pool_ci.pPoolSizes = &ds_type_count;
10541
10542 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010543 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis585f66d2016-07-01 18:23:58 -060010544 ASSERT_VK_SUCCESS(err);
10545
10546 // Create layout with single uniform buffer descriptor
10547 VkDescriptorSetLayoutBinding dsl_binding = {};
10548 dsl_binding.binding = 0;
10549 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
10550 dsl_binding.descriptorCount = 1;
10551 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
10552 dsl_binding.pImmutableSamplers = NULL;
10553
10554 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
10555 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
10556 ds_layout_ci.pNext = NULL;
10557 ds_layout_ci.bindingCount = 1;
10558 ds_layout_ci.pBindings = &dsl_binding;
10559 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010560 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis585f66d2016-07-01 18:23:58 -060010561 ASSERT_VK_SUCCESS(err);
10562
10563 VkDescriptorSet descriptor_set = {};
10564 VkDescriptorSetAllocateInfo alloc_info = {};
10565 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
10566 alloc_info.descriptorSetCount = 1;
10567 alloc_info.descriptorPool = ds_pool;
10568 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010569 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
Tobin Ehlis585f66d2016-07-01 18:23:58 -060010570 ASSERT_VK_SUCCESS(err);
10571
10572 // Create a buffer to be used for invalid updates
10573 VkBufferCreateInfo buff_ci = {};
10574 buff_ci.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
10575 buff_ci.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
10576 buff_ci.size = 256;
10577 buff_ci.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
10578 VkBuffer buffer;
10579 err = vkCreateBuffer(m_device->device(), &buff_ci, NULL, &buffer);
10580 ASSERT_VK_SUCCESS(err);
10581 // Have to bind memory to buffer before descriptor update
10582 VkMemoryAllocateInfo mem_alloc = {};
10583 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
10584 mem_alloc.pNext = NULL;
10585 mem_alloc.allocationSize = 256;
10586 mem_alloc.memoryTypeIndex = 0;
10587
10588 VkMemoryRequirements mem_reqs;
10589 vkGetBufferMemoryRequirements(m_device->device(), buffer, &mem_reqs);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010590 bool pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0);
Tobin Ehlis585f66d2016-07-01 18:23:58 -060010591 if (!pass) {
10592 vkDestroyBuffer(m_device->device(), buffer, NULL);
10593 return;
10594 }
10595
10596 VkDeviceMemory mem;
10597 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem);
10598 ASSERT_VK_SUCCESS(err);
10599 err = vkBindBufferMemory(m_device->device(), buffer, mem, 0);
10600 ASSERT_VK_SUCCESS(err);
10601
10602 VkDescriptorBufferInfo buff_info = {};
10603 buff_info.buffer = buffer;
10604 // First make offset 1 larger than buffer size
10605 buff_info.offset = 257;
10606 buff_info.range = VK_WHOLE_SIZE;
10607 VkWriteDescriptorSet descriptor_write = {};
10608 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
10609 descriptor_write.dstBinding = 0;
10610 descriptor_write.descriptorCount = 1;
10611 descriptor_write.pTexelBufferView = nullptr;
10612 descriptor_write.pBufferInfo = &buff_info;
10613 descriptor_write.pImageInfo = nullptr;
10614
10615 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
10616 descriptor_write.dstSet = descriptor_set;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010617 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " offset of 257 is greater than buffer ");
Tobin Ehlis585f66d2016-07-01 18:23:58 -060010618
10619 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
10620
10621 m_errorMonitor->VerifyFound();
10622 // Now cause error due to range of 0
10623 buff_info.offset = 0;
10624 buff_info.range = 0;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010625 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
10626 " range is not VK_WHOLE_SIZE and is zero, which is not allowed.");
Tobin Ehlis585f66d2016-07-01 18:23:58 -060010627
10628 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
10629
10630 m_errorMonitor->VerifyFound();
10631 // Now cause error due to range exceeding buffer size - offset
10632 buff_info.offset = 128;
10633 buff_info.range = 200;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010634 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 -060010635
10636 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
10637
10638 m_errorMonitor->VerifyFound();
Mark Lobodzinski4bb54092016-07-06 14:27:19 -060010639 vkFreeMemory(m_device->device(), mem, NULL);
Tobin Ehlis585f66d2016-07-01 18:23:58 -060010640 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
10641 vkDestroyBuffer(m_device->device(), buffer, NULL);
10642 vkFreeDescriptorSets(m_device->device(), ds_pool, 1, &descriptor_set);
10643 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
10644}
10645
Tobin Ehlis2fc296b2016-06-15 14:05:27 -060010646TEST_F(VkLayerTest, DSAspectBitsErrors) {
10647 // TODO : Initially only catching case where DEPTH & STENCIL aspect bits
10648 // are set, but could expand this test to hit more cases.
10649 TEST_DESCRIPTION("Attempt to update descriptor sets for images "
10650 "that do not have correct aspect bits sets.");
10651 VkResult err;
10652
10653 ASSERT_NO_FATAL_FAILURE(InitState());
10654 VkDescriptorPoolSize ds_type_count = {};
10655 ds_type_count.type = VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT;
10656 ds_type_count.descriptorCount = 1;
10657
10658 VkDescriptorPoolCreateInfo ds_pool_ci = {};
10659 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
10660 ds_pool_ci.pNext = NULL;
10661 ds_pool_ci.maxSets = 5;
10662 ds_pool_ci.poolSizeCount = 1;
10663 ds_pool_ci.pPoolSizes = &ds_type_count;
10664
10665 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010666 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis2fc296b2016-06-15 14:05:27 -060010667 ASSERT_VK_SUCCESS(err);
10668
10669 VkDescriptorSetLayoutBinding dsl_binding = {};
10670 dsl_binding.binding = 0;
10671 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT;
10672 dsl_binding.descriptorCount = 1;
10673 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
10674 dsl_binding.pImmutableSamplers = NULL;
10675
10676 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
10677 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
10678 ds_layout_ci.pNext = NULL;
10679 ds_layout_ci.bindingCount = 1;
10680 ds_layout_ci.pBindings = &dsl_binding;
10681 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010682 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis2fc296b2016-06-15 14:05:27 -060010683 ASSERT_VK_SUCCESS(err);
10684
10685 VkDescriptorSet descriptor_set = {};
10686 VkDescriptorSetAllocateInfo alloc_info = {};
10687 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
10688 alloc_info.descriptorSetCount = 1;
10689 alloc_info.descriptorPool = ds_pool;
10690 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010691 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
Tobin Ehlis2fc296b2016-06-15 14:05:27 -060010692 ASSERT_VK_SUCCESS(err);
10693
10694 // Create an image to be used for invalid updates
10695 VkImageCreateInfo image_ci = {};
10696 image_ci.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
10697 image_ci.imageType = VK_IMAGE_TYPE_2D;
10698 image_ci.format = VK_FORMAT_D24_UNORM_S8_UINT;
10699 image_ci.extent.width = 64;
10700 image_ci.extent.height = 64;
10701 image_ci.extent.depth = 1;
10702 image_ci.mipLevels = 1;
10703 image_ci.arrayLayers = 1;
10704 image_ci.samples = VK_SAMPLE_COUNT_1_BIT;
10705 image_ci.tiling = VK_IMAGE_TILING_LINEAR;
10706 image_ci.initialLayout = VK_IMAGE_LAYOUT_PREINITIALIZED;
10707 image_ci.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
10708 image_ci.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
10709 VkImage image;
10710 err = vkCreateImage(m_device->device(), &image_ci, NULL, &image);
10711 ASSERT_VK_SUCCESS(err);
10712 // Bind memory to image
10713 VkMemoryRequirements mem_reqs;
10714 VkDeviceMemory image_mem;
10715 bool pass;
10716 VkMemoryAllocateInfo mem_alloc = {};
10717 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
10718 mem_alloc.pNext = NULL;
10719 mem_alloc.allocationSize = 0;
10720 mem_alloc.memoryTypeIndex = 0;
10721 vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs);
10722 mem_alloc.allocationSize = mem_reqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010723 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0);
Tobin Ehlis2fc296b2016-06-15 14:05:27 -060010724 ASSERT_TRUE(pass);
10725 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &image_mem);
10726 ASSERT_VK_SUCCESS(err);
10727 err = vkBindImageMemory(m_device->device(), image, image_mem, 0);
10728 ASSERT_VK_SUCCESS(err);
10729 // Now create view for image
10730 VkImageViewCreateInfo image_view_ci = {};
10731 image_view_ci.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
10732 image_view_ci.image = image;
10733 image_view_ci.format = VK_FORMAT_D24_UNORM_S8_UINT;
10734 image_view_ci.viewType = VK_IMAGE_VIEW_TYPE_2D;
10735 image_view_ci.subresourceRange.layerCount = 1;
10736 image_view_ci.subresourceRange.baseArrayLayer = 0;
10737 image_view_ci.subresourceRange.levelCount = 1;
10738 // Setting both depth & stencil aspect bits is illegal for descriptor
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010739 image_view_ci.subresourceRange.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT;
Tobin Ehlis2fc296b2016-06-15 14:05:27 -060010740
10741 VkImageView image_view;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010742 err = vkCreateImageView(m_device->device(), &image_view_ci, NULL, &image_view);
Tobin Ehlis2fc296b2016-06-15 14:05:27 -060010743 ASSERT_VK_SUCCESS(err);
10744
10745 VkDescriptorImageInfo img_info = {};
10746 img_info.imageView = image_view;
10747 VkWriteDescriptorSet descriptor_write = {};
10748 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
10749 descriptor_write.dstBinding = 0;
10750 descriptor_write.descriptorCount = 1;
10751 descriptor_write.pTexelBufferView = NULL;
10752 descriptor_write.pBufferInfo = NULL;
10753 descriptor_write.pImageInfo = &img_info;
10754 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT;
10755 descriptor_write.dstSet = descriptor_set;
10756 const char *error_msg = " please only set either VK_IMAGE_ASPECT_DEPTH_BIT "
10757 "or VK_IMAGE_ASPECT_STENCIL_BIT ";
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010758 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, error_msg);
Tobin Ehlis2fc296b2016-06-15 14:05:27 -060010759
10760 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
10761
10762 m_errorMonitor->VerifyFound();
10763 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
10764 vkDestroyImage(m_device->device(), image, NULL);
10765 vkFreeMemory(m_device->device(), image_mem, NULL);
10766 vkDestroyImageView(m_device->device(), image_view, NULL);
10767 vkFreeDescriptorSets(m_device->device(), ds_pool, 1, &descriptor_set);
10768 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
10769}
10770
Karl Schultz6addd812016-02-02 17:17:23 -070010771TEST_F(VkLayerTest, DSTypeMismatch) {
Tobin Ehlis49eb23d2015-05-22 12:38:55 -060010772 // Create DS w/ layout of one type and attempt Update w/ mis-matched type
Karl Schultz6addd812016-02-02 17:17:23 -070010773 VkResult err;
Tobin Ehlis3b780662015-05-28 12:11:26 -060010774
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010775 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
10776 " binding #0 with type VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER but update "
10777 "type is VK_DESCRIPTOR_TYPE_SAMPLER");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060010778
Tobin Ehlis3b780662015-05-28 12:11:26 -060010779 ASSERT_NO_FATAL_FAILURE(InitState());
Karl Schultz6addd812016-02-02 17:17:23 -070010780 // VkDescriptorSetObj descriptorSet(m_device);
Chia-I Wu1b99bb22015-10-27 19:25:11 +080010781 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010782 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
10783 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -060010784
10785 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010786 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
10787 ds_pool_ci.pNext = NULL;
10788 ds_pool_ci.maxSets = 1;
10789 ds_pool_ci.poolSizeCount = 1;
10790 ds_pool_ci.pPoolSizes = &ds_type_count;
Tony Barboureb254902015-07-15 12:50:33 -060010791
Tobin Ehlis3b780662015-05-28 12:11:26 -060010792 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010793 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis3b780662015-05-28 12:11:26 -060010794 ASSERT_VK_SUCCESS(err);
Tony Barboureb254902015-07-15 12:50:33 -060010795 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010796 dsl_binding.binding = 0;
10797 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
10798 dsl_binding.descriptorCount = 1;
10799 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
10800 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis3b780662015-05-28 12:11:26 -060010801
Tony Barboureb254902015-07-15 12:50:33 -060010802 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010803 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
10804 ds_layout_ci.pNext = NULL;
10805 ds_layout_ci.bindingCount = 1;
10806 ds_layout_ci.pBindings = &dsl_binding;
Tony Barboureb254902015-07-15 12:50:33 -060010807
Tobin Ehlis3b780662015-05-28 12:11:26 -060010808 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010809 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis3b780662015-05-28 12:11:26 -060010810 ASSERT_VK_SUCCESS(err);
10811
10812 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080010813 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +080010814 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -070010815 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -060010816 alloc_info.descriptorPool = ds_pool;
10817 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010818 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis3b780662015-05-28 12:11:26 -060010819 ASSERT_VK_SUCCESS(err);
Tobin Ehlis3b780662015-05-28 12:11:26 -060010820
Tobin Ehlis30db8f82016-05-05 08:19:48 -060010821 VkSamplerCreateInfo sampler_ci = {};
10822 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
10823 sampler_ci.pNext = NULL;
10824 sampler_ci.magFilter = VK_FILTER_NEAREST;
10825 sampler_ci.minFilter = VK_FILTER_NEAREST;
10826 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
10827 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
10828 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
10829 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
10830 sampler_ci.mipLodBias = 1.0;
10831 sampler_ci.anisotropyEnable = VK_FALSE;
10832 sampler_ci.maxAnisotropy = 1;
10833 sampler_ci.compareEnable = VK_FALSE;
10834 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
10835 sampler_ci.minLod = 1.0;
10836 sampler_ci.maxLod = 1.0;
10837 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
10838 sampler_ci.unnormalizedCoordinates = VK_FALSE;
10839 VkSampler sampler;
10840 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
10841 ASSERT_VK_SUCCESS(err);
10842
10843 VkDescriptorImageInfo info = {};
10844 info.sampler = sampler;
Chia-I Wu9d00ed72015-05-25 16:27:55 +080010845
10846 VkWriteDescriptorSet descriptor_write;
10847 memset(&descriptor_write, 0, sizeof(descriptor_write));
10848 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080010849 descriptor_write.dstSet = descriptorSet;
Chia-I Wud50a7d72015-10-26 20:48:51 +080010850 descriptor_write.descriptorCount = 1;
Tobin Ehlis3b780662015-05-28 12:11:26 -060010851 // This is a mismatched type for the layout which expects BUFFER
Chia-I Wu9d00ed72015-05-25 16:27:55 +080010852 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
Courtney Goeltzenleuchter4cb6d922015-10-23 13:38:14 -060010853 descriptor_write.pImageInfo = &info;
Chia-I Wu9d00ed72015-05-25 16:27:55 +080010854
10855 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
10856
Chris Forbes8f36a8a2016-04-07 13:21:07 +120010857 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -060010858
Chia-I Wuf7458c52015-10-26 21:10:41 +080010859 vkDestroySampler(m_device->device(), sampler, NULL);
10860 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
10861 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis49eb23d2015-05-22 12:38:55 -060010862}
10863
Karl Schultz6addd812016-02-02 17:17:23 -070010864TEST_F(VkLayerTest, DSUpdateOutOfBounds) {
Tobin Ehlis49eb23d2015-05-22 12:38:55 -060010865 // For overlapping Update, have arrayIndex exceed that of layout
Karl Schultz6addd812016-02-02 17:17:23 -070010866 VkResult err;
Tobin Ehlis3b780662015-05-28 12:11:26 -060010867
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010868 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
10869 " binding #0 with 1 total descriptors but update of 1 descriptors "
10870 "starting at binding offset of 0 combined with update array element "
10871 "offset of 1 oversteps the size of this descriptor set.");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060010872
Tobin Ehlis3b780662015-05-28 12:11:26 -060010873 ASSERT_NO_FATAL_FAILURE(InitState());
Karl Schultz6addd812016-02-02 17:17:23 -070010874 // VkDescriptorSetObj descriptorSet(m_device);
Chia-I Wu1b99bb22015-10-27 19:25:11 +080010875 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010876 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
10877 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -060010878
10879 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010880 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
10881 ds_pool_ci.pNext = NULL;
10882 ds_pool_ci.maxSets = 1;
10883 ds_pool_ci.poolSizeCount = 1;
10884 ds_pool_ci.pPoolSizes = &ds_type_count;
Tony Barboureb254902015-07-15 12:50:33 -060010885
Tobin Ehlis3b780662015-05-28 12:11:26 -060010886 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010887 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis3b780662015-05-28 12:11:26 -060010888 ASSERT_VK_SUCCESS(err);
Tobin Ehlis3b780662015-05-28 12:11:26 -060010889
Tony Barboureb254902015-07-15 12:50:33 -060010890 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010891 dsl_binding.binding = 0;
10892 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
10893 dsl_binding.descriptorCount = 1;
10894 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
10895 dsl_binding.pImmutableSamplers = NULL;
Tony Barboureb254902015-07-15 12:50:33 -060010896
10897 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010898 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
10899 ds_layout_ci.pNext = NULL;
10900 ds_layout_ci.bindingCount = 1;
10901 ds_layout_ci.pBindings = &dsl_binding;
Tony Barboureb254902015-07-15 12:50:33 -060010902
Tobin Ehlis3b780662015-05-28 12:11:26 -060010903 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010904 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis3b780662015-05-28 12:11:26 -060010905 ASSERT_VK_SUCCESS(err);
10906
10907 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080010908 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +080010909 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -070010910 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -060010911 alloc_info.descriptorPool = ds_pool;
10912 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010913 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis3b780662015-05-28 12:11:26 -060010914 ASSERT_VK_SUCCESS(err);
Tobin Ehlis3b780662015-05-28 12:11:26 -060010915
Tobin Ehlis30db8f82016-05-05 08:19:48 -060010916 // Correctly update descriptor to avoid "NOT_UPDATED" error
10917 VkDescriptorBufferInfo buff_info = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010918 buff_info.buffer = VkBuffer(0); // Don't care about buffer handle for this test
Tobin Ehlis30db8f82016-05-05 08:19:48 -060010919 buff_info.offset = 0;
10920 buff_info.range = 1024;
Chia-I Wu9d00ed72015-05-25 16:27:55 +080010921
10922 VkWriteDescriptorSet descriptor_write;
10923 memset(&descriptor_write, 0, sizeof(descriptor_write));
10924 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080010925 descriptor_write.dstSet = descriptorSet;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010926 descriptor_write.dstArrayElement = 1; /* This index out of bounds for the update */
Chia-I Wud50a7d72015-10-26 20:48:51 +080010927 descriptor_write.descriptorCount = 1;
Tobin Ehlis0a43bde2016-05-03 08:31:08 -060010928 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
10929 descriptor_write.pBufferInfo = &buff_info;
Chia-I Wu9d00ed72015-05-25 16:27:55 +080010930
10931 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
10932
Chris Forbes8f36a8a2016-04-07 13:21:07 +120010933 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -060010934
Chia-I Wuf7458c52015-10-26 21:10:41 +080010935 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
10936 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis49eb23d2015-05-22 12:38:55 -060010937}
10938
Karl Schultz6addd812016-02-02 17:17:23 -070010939TEST_F(VkLayerTest, InvalidDSUpdateIndex) {
10940 // Create layout w/ count of 1 and attempt update to that layout w/ binding
10941 // index 2
10942 VkResult err;
Tobin Ehlis3b780662015-05-28 12:11:26 -060010943
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010944 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " does not have binding 2.");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060010945
Tobin Ehlis3b780662015-05-28 12:11:26 -060010946 ASSERT_NO_FATAL_FAILURE(InitState());
Karl Schultz6addd812016-02-02 17:17:23 -070010947 // VkDescriptorSetObj descriptorSet(m_device);
Chia-I Wu1b99bb22015-10-27 19:25:11 +080010948 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010949 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
10950 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -060010951
10952 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010953 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
10954 ds_pool_ci.pNext = NULL;
10955 ds_pool_ci.maxSets = 1;
10956 ds_pool_ci.poolSizeCount = 1;
10957 ds_pool_ci.pPoolSizes = &ds_type_count;
Courtney Goeltzenleuchterfe908d32015-09-16 16:12:45 -060010958
Tobin Ehlis3b780662015-05-28 12:11:26 -060010959 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010960 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis3b780662015-05-28 12:11:26 -060010961 ASSERT_VK_SUCCESS(err);
Tobin Ehlis3b780662015-05-28 12:11:26 -060010962
Tony Barboureb254902015-07-15 12:50:33 -060010963 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010964 dsl_binding.binding = 0;
10965 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
10966 dsl_binding.descriptorCount = 1;
10967 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
10968 dsl_binding.pImmutableSamplers = NULL;
Tony Barboureb254902015-07-15 12:50:33 -060010969
10970 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010971 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
10972 ds_layout_ci.pNext = NULL;
10973 ds_layout_ci.bindingCount = 1;
10974 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlis3b780662015-05-28 12:11:26 -060010975 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010976 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis3b780662015-05-28 12:11:26 -060010977 ASSERT_VK_SUCCESS(err);
10978
10979 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080010980 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +080010981 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -070010982 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -060010983 alloc_info.descriptorPool = ds_pool;
10984 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010985 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis3b780662015-05-28 12:11:26 -060010986 ASSERT_VK_SUCCESS(err);
Tobin Ehlis3b780662015-05-28 12:11:26 -060010987
Tony Barboureb254902015-07-15 12:50:33 -060010988 VkSamplerCreateInfo sampler_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010989 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
10990 sampler_ci.pNext = NULL;
10991 sampler_ci.magFilter = VK_FILTER_NEAREST;
10992 sampler_ci.minFilter = VK_FILTER_NEAREST;
10993 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
10994 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
10995 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
10996 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
10997 sampler_ci.mipLodBias = 1.0;
10998 sampler_ci.anisotropyEnable = VK_FALSE;
10999 sampler_ci.maxAnisotropy = 1;
11000 sampler_ci.compareEnable = VK_FALSE;
11001 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
11002 sampler_ci.minLod = 1.0;
11003 sampler_ci.maxLod = 1.0;
11004 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
11005 sampler_ci.unnormalizedCoordinates = VK_FALSE;
Tony Barboureb254902015-07-15 12:50:33 -060011006
Tobin Ehlis3b780662015-05-28 12:11:26 -060011007 VkSampler sampler;
Chia-I Wuf7458c52015-10-26 21:10:41 +080011008 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
Tobin Ehlis3b780662015-05-28 12:11:26 -060011009 ASSERT_VK_SUCCESS(err);
Chia-I Wu9d00ed72015-05-25 16:27:55 +080011010
Courtney Goeltzenleuchter4cb6d922015-10-23 13:38:14 -060011011 VkDescriptorImageInfo info = {};
11012 info.sampler = sampler;
Chia-I Wu9d00ed72015-05-25 16:27:55 +080011013
11014 VkWriteDescriptorSet descriptor_write;
11015 memset(&descriptor_write, 0, sizeof(descriptor_write));
11016 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080011017 descriptor_write.dstSet = descriptorSet;
11018 descriptor_write.dstBinding = 2;
Chia-I Wud50a7d72015-10-26 20:48:51 +080011019 descriptor_write.descriptorCount = 1;
Tobin Ehlis3b780662015-05-28 12:11:26 -060011020 // This is the wrong type, but out of bounds will be flagged first
Chia-I Wu9d00ed72015-05-25 16:27:55 +080011021 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
Courtney Goeltzenleuchter4cb6d922015-10-23 13:38:14 -060011022 descriptor_write.pImageInfo = &info;
Chia-I Wu9d00ed72015-05-25 16:27:55 +080011023
11024 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
11025
Chris Forbes8f36a8a2016-04-07 13:21:07 +120011026 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -060011027
Chia-I Wuf7458c52015-10-26 21:10:41 +080011028 vkDestroySampler(m_device->device(), sampler, NULL);
11029 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
11030 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis49eb23d2015-05-22 12:38:55 -060011031}
11032
Karl Schultz6addd812016-02-02 17:17:23 -070011033TEST_F(VkLayerTest, InvalidDSUpdateStruct) {
11034 // Call UpdateDS w/ struct type other than valid VK_STRUCTUR_TYPE_UPDATE_*
11035 // types
11036 VkResult err;
Tobin Ehlis3b780662015-05-28 12:11:26 -060011037
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011038 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 -060011039
Tobin Ehlis3b780662015-05-28 12:11:26 -060011040 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinski209b5292015-09-17 09:44:05 -060011041
Chia-I Wu1b99bb22015-10-27 19:25:11 +080011042 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011043 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
11044 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -060011045
11046 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011047 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
11048 ds_pool_ci.pNext = NULL;
11049 ds_pool_ci.maxSets = 1;
11050 ds_pool_ci.poolSizeCount = 1;
11051 ds_pool_ci.pPoolSizes = &ds_type_count;
Courtney Goeltzenleuchterfe908d32015-09-16 16:12:45 -060011052
Tobin Ehlis3b780662015-05-28 12:11:26 -060011053 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011054 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis3b780662015-05-28 12:11:26 -060011055 ASSERT_VK_SUCCESS(err);
Tony Barboureb254902015-07-15 12:50:33 -060011056 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011057 dsl_binding.binding = 0;
11058 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
11059 dsl_binding.descriptorCount = 1;
11060 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
11061 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis3b780662015-05-28 12:11:26 -060011062
Tony Barboureb254902015-07-15 12:50:33 -060011063 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011064 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
11065 ds_layout_ci.pNext = NULL;
11066 ds_layout_ci.bindingCount = 1;
11067 ds_layout_ci.pBindings = &dsl_binding;
Tony Barboureb254902015-07-15 12:50:33 -060011068
Tobin Ehlis3b780662015-05-28 12:11:26 -060011069 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011070 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis3b780662015-05-28 12:11:26 -060011071 ASSERT_VK_SUCCESS(err);
11072
11073 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080011074 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +080011075 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -070011076 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -060011077 alloc_info.descriptorPool = ds_pool;
11078 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011079 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis3b780662015-05-28 12:11:26 -060011080 ASSERT_VK_SUCCESS(err);
Tobin Ehlis3b780662015-05-28 12:11:26 -060011081
Tony Barboureb254902015-07-15 12:50:33 -060011082 VkSamplerCreateInfo sampler_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011083 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
11084 sampler_ci.pNext = NULL;
11085 sampler_ci.magFilter = VK_FILTER_NEAREST;
11086 sampler_ci.minFilter = VK_FILTER_NEAREST;
11087 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
11088 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
11089 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
11090 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
11091 sampler_ci.mipLodBias = 1.0;
11092 sampler_ci.anisotropyEnable = VK_FALSE;
11093 sampler_ci.maxAnisotropy = 1;
11094 sampler_ci.compareEnable = VK_FALSE;
11095 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
11096 sampler_ci.minLod = 1.0;
11097 sampler_ci.maxLod = 1.0;
11098 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
11099 sampler_ci.unnormalizedCoordinates = VK_FALSE;
Tobin Ehlis3b780662015-05-28 12:11:26 -060011100 VkSampler sampler;
Chia-I Wuf7458c52015-10-26 21:10:41 +080011101 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
Tobin Ehlis3b780662015-05-28 12:11:26 -060011102 ASSERT_VK_SUCCESS(err);
Chia-I Wu9d00ed72015-05-25 16:27:55 +080011103
Courtney Goeltzenleuchter4cb6d922015-10-23 13:38:14 -060011104 VkDescriptorImageInfo info = {};
11105 info.sampler = sampler;
Chia-I Wu9d00ed72015-05-25 16:27:55 +080011106
11107 VkWriteDescriptorSet descriptor_write;
11108 memset(&descriptor_write, 0, sizeof(descriptor_write));
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011109 descriptor_write.sType = (VkStructureType)0x99999999; /* Intentionally broken struct type */
Chia-I Wu3432a0c2015-10-27 18:04:07 +080011110 descriptor_write.dstSet = descriptorSet;
Chia-I Wud50a7d72015-10-26 20:48:51 +080011111 descriptor_write.descriptorCount = 1;
Tobin Ehlis3b780662015-05-28 12:11:26 -060011112 // This is the wrong type, but out of bounds will be flagged first
Chia-I Wu9d00ed72015-05-25 16:27:55 +080011113 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
Courtney Goeltzenleuchter4cb6d922015-10-23 13:38:14 -060011114 descriptor_write.pImageInfo = &info;
Chia-I Wu9d00ed72015-05-25 16:27:55 +080011115
11116 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
11117
Chris Forbes8f36a8a2016-04-07 13:21:07 +120011118 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -060011119
Chia-I Wuf7458c52015-10-26 21:10:41 +080011120 vkDestroySampler(m_device->device(), sampler, NULL);
11121 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
11122 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis49eb23d2015-05-22 12:38:55 -060011123}
11124
Karl Schultz6addd812016-02-02 17:17:23 -070011125TEST_F(VkLayerTest, SampleDescriptorUpdateError) {
Tobin Ehlisa1c28562015-10-23 16:00:08 -060011126 // Create a single Sampler descriptor and send it an invalid Sampler
Karl Schultz6addd812016-02-02 17:17:23 -070011127 VkResult err;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060011128
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011129 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
11130 "Attempted write update to sampler descriptor with invalid sampler");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060011131
Tobin Ehlisa1c28562015-10-23 16:00:08 -060011132 ASSERT_NO_FATAL_FAILURE(InitState());
Karl Schultz6addd812016-02-02 17:17:23 -070011133 // TODO : Farm Descriptor setup code to helper function(s) to reduce copied
11134 // code
Chia-I Wu1b99bb22015-10-27 19:25:11 +080011135 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011136 ds_type_count.type = VK_DESCRIPTOR_TYPE_SAMPLER;
11137 ds_type_count.descriptorCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060011138
11139 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011140 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
11141 ds_pool_ci.pNext = NULL;
11142 ds_pool_ci.maxSets = 1;
11143 ds_pool_ci.poolSizeCount = 1;
11144 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060011145
11146 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011147 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060011148 ASSERT_VK_SUCCESS(err);
11149
11150 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011151 dsl_binding.binding = 0;
11152 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
11153 dsl_binding.descriptorCount = 1;
11154 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
11155 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060011156
11157 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011158 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
11159 ds_layout_ci.pNext = NULL;
11160 ds_layout_ci.bindingCount = 1;
11161 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060011162 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011163 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060011164 ASSERT_VK_SUCCESS(err);
11165
11166 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080011167 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +080011168 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -070011169 alloc_info.descriptorSetCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060011170 alloc_info.descriptorPool = ds_pool;
11171 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011172 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060011173 ASSERT_VK_SUCCESS(err);
11174
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011175 VkSampler sampler = (VkSampler)((size_t)0xbaadbeef); // Sampler with invalid handle
Tobin Ehlisa1c28562015-10-23 16:00:08 -060011176
11177 VkDescriptorImageInfo descriptor_info;
11178 memset(&descriptor_info, 0, sizeof(VkDescriptorImageInfo));
11179 descriptor_info.sampler = sampler;
11180
11181 VkWriteDescriptorSet descriptor_write;
11182 memset(&descriptor_write, 0, sizeof(descriptor_write));
11183 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080011184 descriptor_write.dstSet = descriptorSet;
11185 descriptor_write.dstBinding = 0;
Chia-I Wud50a7d72015-10-26 20:48:51 +080011186 descriptor_write.descriptorCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060011187 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
11188 descriptor_write.pImageInfo = &descriptor_info;
11189
11190 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
11191
Chris Forbes8f36a8a2016-04-07 13:21:07 +120011192 m_errorMonitor->VerifyFound();
Tobin Ehlisa1c28562015-10-23 16:00:08 -060011193
Chia-I Wuf7458c52015-10-26 21:10:41 +080011194 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
11195 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060011196}
11197
Karl Schultz6addd812016-02-02 17:17:23 -070011198TEST_F(VkLayerTest, ImageViewDescriptorUpdateError) {
11199 // Create a single combined Image/Sampler descriptor and send it an invalid
11200 // imageView
11201 VkResult err;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060011202
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011203 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Attempted write update to combined "
11204 "image sampler descriptor failed due "
11205 "to: Invalid VkImageView:");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060011206
Tobin Ehlisa1c28562015-10-23 16:00:08 -060011207 ASSERT_NO_FATAL_FAILURE(InitState());
Chia-I Wu1b99bb22015-10-27 19:25:11 +080011208 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011209 ds_type_count.type = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
11210 ds_type_count.descriptorCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060011211
11212 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011213 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
11214 ds_pool_ci.pNext = NULL;
11215 ds_pool_ci.maxSets = 1;
11216 ds_pool_ci.poolSizeCount = 1;
11217 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060011218
11219 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011220 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060011221 ASSERT_VK_SUCCESS(err);
11222
11223 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011224 dsl_binding.binding = 0;
11225 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
11226 dsl_binding.descriptorCount = 1;
11227 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
11228 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060011229
11230 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011231 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
11232 ds_layout_ci.pNext = NULL;
11233 ds_layout_ci.bindingCount = 1;
11234 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060011235 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011236 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060011237 ASSERT_VK_SUCCESS(err);
11238
11239 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080011240 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +080011241 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -070011242 alloc_info.descriptorSetCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060011243 alloc_info.descriptorPool = ds_pool;
11244 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011245 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060011246 ASSERT_VK_SUCCESS(err);
11247
11248 VkSamplerCreateInfo sampler_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011249 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
11250 sampler_ci.pNext = NULL;
11251 sampler_ci.magFilter = VK_FILTER_NEAREST;
11252 sampler_ci.minFilter = VK_FILTER_NEAREST;
11253 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
11254 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
11255 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
11256 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
11257 sampler_ci.mipLodBias = 1.0;
11258 sampler_ci.anisotropyEnable = VK_FALSE;
11259 sampler_ci.maxAnisotropy = 1;
11260 sampler_ci.compareEnable = VK_FALSE;
11261 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
11262 sampler_ci.minLod = 1.0;
11263 sampler_ci.maxLod = 1.0;
11264 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
11265 sampler_ci.unnormalizedCoordinates = VK_FALSE;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060011266
11267 VkSampler sampler;
Chia-I Wuf7458c52015-10-26 21:10:41 +080011268 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060011269 ASSERT_VK_SUCCESS(err);
11270
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011271 VkImageView view = (VkImageView)((size_t)0xbaadbeef); // invalid imageView object
Tobin Ehlisa1c28562015-10-23 16:00:08 -060011272
11273 VkDescriptorImageInfo descriptor_info;
11274 memset(&descriptor_info, 0, sizeof(VkDescriptorImageInfo));
11275 descriptor_info.sampler = sampler;
11276 descriptor_info.imageView = view;
11277
11278 VkWriteDescriptorSet descriptor_write;
11279 memset(&descriptor_write, 0, sizeof(descriptor_write));
11280 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080011281 descriptor_write.dstSet = descriptorSet;
11282 descriptor_write.dstBinding = 0;
Chia-I Wud50a7d72015-10-26 20:48:51 +080011283 descriptor_write.descriptorCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060011284 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
11285 descriptor_write.pImageInfo = &descriptor_info;
11286
11287 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
11288
Chris Forbes8f36a8a2016-04-07 13:21:07 +120011289 m_errorMonitor->VerifyFound();
Tobin Ehlisa1c28562015-10-23 16:00:08 -060011290
Chia-I Wuf7458c52015-10-26 21:10:41 +080011291 vkDestroySampler(m_device->device(), sampler, NULL);
11292 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
11293 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060011294}
11295
Karl Schultz6addd812016-02-02 17:17:23 -070011296TEST_F(VkLayerTest, CopyDescriptorUpdateErrors) {
11297 // Create DS w/ layout of 2 types, write update 1 and attempt to copy-update
11298 // into the other
11299 VkResult err;
Tobin Ehlis04356f92015-10-27 16:35:27 -060011300
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011301 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " binding #1 with type "
11302 "VK_DESCRIPTOR_TYPE_SAMPLER. Types do "
11303 "not match.");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060011304
Tobin Ehlis04356f92015-10-27 16:35:27 -060011305 ASSERT_NO_FATAL_FAILURE(InitState());
Karl Schultz6addd812016-02-02 17:17:23 -070011306 // VkDescriptorSetObj descriptorSet(m_device);
Chia-I Wu1b99bb22015-10-27 19:25:11 +080011307 VkDescriptorPoolSize ds_type_count[2] = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011308 ds_type_count[0].type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
11309 ds_type_count[0].descriptorCount = 1;
11310 ds_type_count[1].type = VK_DESCRIPTOR_TYPE_SAMPLER;
11311 ds_type_count[1].descriptorCount = 1;
Tobin Ehlis04356f92015-10-27 16:35:27 -060011312
11313 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011314 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
11315 ds_pool_ci.pNext = NULL;
11316 ds_pool_ci.maxSets = 1;
11317 ds_pool_ci.poolSizeCount = 2;
11318 ds_pool_ci.pPoolSizes = ds_type_count;
Tobin Ehlis04356f92015-10-27 16:35:27 -060011319
11320 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011321 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis04356f92015-10-27 16:35:27 -060011322 ASSERT_VK_SUCCESS(err);
11323 VkDescriptorSetLayoutBinding dsl_binding[2] = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011324 dsl_binding[0].binding = 0;
11325 dsl_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
11326 dsl_binding[0].descriptorCount = 1;
11327 dsl_binding[0].stageFlags = VK_SHADER_STAGE_ALL;
11328 dsl_binding[0].pImmutableSamplers = NULL;
11329 dsl_binding[1].binding = 1;
11330 dsl_binding[1].descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
11331 dsl_binding[1].descriptorCount = 1;
11332 dsl_binding[1].stageFlags = VK_SHADER_STAGE_ALL;
11333 dsl_binding[1].pImmutableSamplers = NULL;
Tobin Ehlis04356f92015-10-27 16:35:27 -060011334
11335 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011336 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
11337 ds_layout_ci.pNext = NULL;
11338 ds_layout_ci.bindingCount = 2;
11339 ds_layout_ci.pBindings = dsl_binding;
Tobin Ehlis04356f92015-10-27 16:35:27 -060011340
11341 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011342 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis04356f92015-10-27 16:35:27 -060011343 ASSERT_VK_SUCCESS(err);
11344
11345 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080011346 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +080011347 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -070011348 alloc_info.descriptorSetCount = 1;
Tobin Ehlis04356f92015-10-27 16:35:27 -060011349 alloc_info.descriptorPool = ds_pool;
11350 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011351 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis04356f92015-10-27 16:35:27 -060011352 ASSERT_VK_SUCCESS(err);
11353
11354 VkSamplerCreateInfo sampler_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011355 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
11356 sampler_ci.pNext = NULL;
11357 sampler_ci.magFilter = VK_FILTER_NEAREST;
11358 sampler_ci.minFilter = VK_FILTER_NEAREST;
11359 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
11360 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
11361 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
11362 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
11363 sampler_ci.mipLodBias = 1.0;
11364 sampler_ci.anisotropyEnable = VK_FALSE;
11365 sampler_ci.maxAnisotropy = 1;
11366 sampler_ci.compareEnable = VK_FALSE;
11367 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
11368 sampler_ci.minLod = 1.0;
11369 sampler_ci.maxLod = 1.0;
11370 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
11371 sampler_ci.unnormalizedCoordinates = VK_FALSE;
Tobin Ehlis04356f92015-10-27 16:35:27 -060011372
11373 VkSampler sampler;
Chia-I Wuf7458c52015-10-26 21:10:41 +080011374 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
Tobin Ehlis04356f92015-10-27 16:35:27 -060011375 ASSERT_VK_SUCCESS(err);
11376
11377 VkDescriptorImageInfo info = {};
11378 info.sampler = sampler;
11379
11380 VkWriteDescriptorSet descriptor_write;
11381 memset(&descriptor_write, 0, sizeof(VkWriteDescriptorSet));
11382 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080011383 descriptor_write.dstSet = descriptorSet;
11384 descriptor_write.dstBinding = 1; // SAMPLER binding from layout above
Chia-I Wud50a7d72015-10-26 20:48:51 +080011385 descriptor_write.descriptorCount = 1;
Tobin Ehlis04356f92015-10-27 16:35:27 -060011386 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
11387 descriptor_write.pImageInfo = &info;
11388 // This write update should succeed
11389 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
11390 // Now perform a copy update that fails due to type mismatch
11391 VkCopyDescriptorSet copy_ds_update;
11392 memset(&copy_ds_update, 0, sizeof(VkCopyDescriptorSet));
11393 copy_ds_update.sType = VK_STRUCTURE_TYPE_COPY_DESCRIPTOR_SET;
11394 copy_ds_update.srcSet = descriptorSet;
Mark Young29927482016-05-04 14:38:51 -060011395 copy_ds_update.srcBinding = 1; // Copy from SAMPLER binding
Chia-I Wu3432a0c2015-10-27 18:04:07 +080011396 copy_ds_update.dstSet = descriptorSet;
Karl Schultz6addd812016-02-02 17:17:23 -070011397 copy_ds_update.dstBinding = 0; // ERROR : copy to UNIFORM binding
Chia-I Wud50a7d72015-10-26 20:48:51 +080011398 copy_ds_update.descriptorCount = 1; // copy 1 descriptor
Tobin Ehlis04356f92015-10-27 16:35:27 -060011399 vkUpdateDescriptorSets(m_device->device(), 0, NULL, 1, &copy_ds_update);
11400
Chris Forbes8f36a8a2016-04-07 13:21:07 +120011401 m_errorMonitor->VerifyFound();
Tobin Ehlis04356f92015-10-27 16:35:27 -060011402 // Now perform a copy update that fails due to binding out of bounds
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011403 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 -060011404 memset(&copy_ds_update, 0, sizeof(VkCopyDescriptorSet));
11405 copy_ds_update.sType = VK_STRUCTURE_TYPE_COPY_DESCRIPTOR_SET;
11406 copy_ds_update.srcSet = descriptorSet;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011407 copy_ds_update.srcBinding = 3; // ERROR : Invalid binding for matching layout
Chia-I Wu3432a0c2015-10-27 18:04:07 +080011408 copy_ds_update.dstSet = descriptorSet;
11409 copy_ds_update.dstBinding = 0;
Mark Young29927482016-05-04 14:38:51 -060011410 copy_ds_update.descriptorCount = 1; // Copy 1 descriptor
Tobin Ehlis04356f92015-10-27 16:35:27 -060011411 vkUpdateDescriptorSets(m_device->device(), 0, NULL, 1, &copy_ds_update);
11412
Chris Forbes8f36a8a2016-04-07 13:21:07 +120011413 m_errorMonitor->VerifyFound();
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060011414
Tobin Ehlis04356f92015-10-27 16:35:27 -060011415 // Now perform a copy update that fails due to binding out of bounds
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011416 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " binding#1 with offset index of 1 plus "
11417 "update array offset of 0 and update of "
11418 "5 descriptors oversteps total number "
11419 "of descriptors in set: 2.");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060011420
Tobin Ehlis04356f92015-10-27 16:35:27 -060011421 memset(&copy_ds_update, 0, sizeof(VkCopyDescriptorSet));
11422 copy_ds_update.sType = VK_STRUCTURE_TYPE_COPY_DESCRIPTOR_SET;
11423 copy_ds_update.srcSet = descriptorSet;
11424 copy_ds_update.srcBinding = 1;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080011425 copy_ds_update.dstSet = descriptorSet;
11426 copy_ds_update.dstBinding = 0;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011427 copy_ds_update.descriptorCount = 5; // ERROR copy 5 descriptors (out of bounds for layout)
Tobin Ehlis04356f92015-10-27 16:35:27 -060011428 vkUpdateDescriptorSets(m_device->device(), 0, NULL, 1, &copy_ds_update);
11429
Chris Forbes8f36a8a2016-04-07 13:21:07 +120011430 m_errorMonitor->VerifyFound();
Tobin Ehlis04356f92015-10-27 16:35:27 -060011431
Chia-I Wuf7458c52015-10-26 21:10:41 +080011432 vkDestroySampler(m_device->device(), sampler, NULL);
11433 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
11434 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis04356f92015-10-27 16:35:27 -060011435}
11436
Karl Schultz6addd812016-02-02 17:17:23 -070011437TEST_F(VkLayerTest, NumSamplesMismatch) {
11438 // Create CommandBuffer where MSAA samples doesn't match RenderPass
11439 // sampleCount
11440 VkResult err;
Tobin Ehlis3b780662015-05-28 12:11:26 -060011441
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011442 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Num samples mismatch! ");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060011443
Tobin Ehlis3b780662015-05-28 12:11:26 -060011444 ASSERT_NO_FATAL_FAILURE(InitState());
11445 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chia-I Wu1b99bb22015-10-27 19:25:11 +080011446 VkDescriptorPoolSize ds_type_count = {};
Tony Barboureb254902015-07-15 12:50:33 -060011447 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Chia-I Wud50a7d72015-10-26 20:48:51 +080011448 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -060011449
11450 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011451 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
11452 ds_pool_ci.pNext = NULL;
11453 ds_pool_ci.maxSets = 1;
11454 ds_pool_ci.poolSizeCount = 1;
11455 ds_pool_ci.pPoolSizes = &ds_type_count;
Courtney Goeltzenleuchterfe908d32015-09-16 16:12:45 -060011456
Tobin Ehlis3b780662015-05-28 12:11:26 -060011457 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011458 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis3b780662015-05-28 12:11:26 -060011459 ASSERT_VK_SUCCESS(err);
Tobin Ehlis3b780662015-05-28 12:11:26 -060011460
Tony Barboureb254902015-07-15 12:50:33 -060011461 VkDescriptorSetLayoutBinding dsl_binding = {};
Chia-I Wud46e6ae2015-10-31 00:31:16 +080011462 dsl_binding.binding = 0;
Tony Barboureb254902015-07-15 12:50:33 -060011463 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Chia-I Wu02124482015-11-06 06:42:02 +080011464 dsl_binding.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -060011465 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
11466 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis3b780662015-05-28 12:11:26 -060011467
Tony Barboureb254902015-07-15 12:50:33 -060011468 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
11469 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
11470 ds_layout_ci.pNext = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +080011471 ds_layout_ci.bindingCount = 1;
Jon Ashburn6e23c1f2015-12-30 18:01:16 -070011472 ds_layout_ci.pBindings = &dsl_binding;
Tony Barboureb254902015-07-15 12:50:33 -060011473
Tobin Ehlis3b780662015-05-28 12:11:26 -060011474 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011475 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis3b780662015-05-28 12:11:26 -060011476 ASSERT_VK_SUCCESS(err);
11477
11478 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080011479 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +080011480 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -070011481 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -060011482 alloc_info.descriptorPool = ds_pool;
11483 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011484 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis3b780662015-05-28 12:11:26 -060011485 ASSERT_VK_SUCCESS(err);
11486
Tony Barboureb254902015-07-15 12:50:33 -060011487 VkPipelineMultisampleStateCreateInfo pipe_ms_state_ci = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011488 pipe_ms_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
Karl Schultz6addd812016-02-02 17:17:23 -070011489 pipe_ms_state_ci.pNext = NULL;
11490 pipe_ms_state_ci.rasterizationSamples = VK_SAMPLE_COUNT_4_BIT;
11491 pipe_ms_state_ci.sampleShadingEnable = 0;
11492 pipe_ms_state_ci.minSampleShading = 1.0;
11493 pipe_ms_state_ci.pSampleMask = NULL;
Tobin Ehlis3b780662015-05-28 12:11:26 -060011494
Tony Barboureb254902015-07-15 12:50:33 -060011495 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011496 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
11497 pipeline_layout_ci.pNext = NULL;
11498 pipeline_layout_ci.setLayoutCount = 1;
11499 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlis3b780662015-05-28 12:11:26 -060011500
11501 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011502 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis3b780662015-05-28 12:11:26 -060011503 ASSERT_VK_SUCCESS(err);
11504
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011505 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
11506 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this); // We shouldn't need a fragment shader
11507 // but add it to be able to run on more devices
Tony Barbour62e1a5b2015-08-06 10:16:07 -060011508 VkPipelineObj pipe(m_device);
11509 pipe.AddShader(&vs);
Tony Barbour1c94d372015-08-06 11:21:08 -060011510 pipe.AddShader(&fs);
Mark Youngc89c6312016-03-31 16:03:20 -060011511 pipe.AddColorAttachment();
Tony Barbour62e1a5b2015-08-06 10:16:07 -060011512 pipe.SetMSAA(&pipe_ms_state_ci);
11513 pipe.CreateVKPipeline(pipeline_layout, renderPass());
Tobin Ehlis3b780662015-05-28 12:11:26 -060011514
Tony Barbourfe3351b2015-07-28 10:17:20 -060011515 BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011516 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Tobin Ehlis3b780662015-05-28 12:11:26 -060011517
Mark Young29927482016-05-04 14:38:51 -060011518 // Render triangle (the error should trigger on the attempt to draw).
11519 Draw(3, 1, 0, 0);
11520
11521 // Finalize recording of the command buffer
11522 EndCommandBuffer();
11523
Chris Forbes8f36a8a2016-04-07 13:21:07 +120011524 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -060011525
Chia-I Wuf7458c52015-10-26 21:10:41 +080011526 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
11527 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
11528 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis49eb23d2015-05-22 12:38:55 -060011529}
Mark Young29927482016-05-04 14:38:51 -060011530
Tobin Ehlis85aa15a2016-06-15 10:52:37 -060011531TEST_F(VkLayerTest, RenderPassIncompatible) {
11532 TEST_DESCRIPTION("Hit RenderPass incompatible cases. "
11533 "Initial case is drawing with an active renderpass that's "
11534 "not compatible with the bound PSO's creation renderpass");
11535 VkResult err;
11536
11537 ASSERT_NO_FATAL_FAILURE(InitState());
11538 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
11539
11540 VkDescriptorSetLayoutBinding dsl_binding = {};
11541 dsl_binding.binding = 0;
11542 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
11543 dsl_binding.descriptorCount = 1;
11544 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
11545 dsl_binding.pImmutableSamplers = NULL;
11546
11547 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
11548 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
11549 ds_layout_ci.pNext = NULL;
11550 ds_layout_ci.bindingCount = 1;
11551 ds_layout_ci.pBindings = &dsl_binding;
11552
11553 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011554 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis85aa15a2016-06-15 10:52:37 -060011555 ASSERT_VK_SUCCESS(err);
11556
11557 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
11558 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
11559 pipeline_layout_ci.pNext = NULL;
11560 pipeline_layout_ci.setLayoutCount = 1;
11561 pipeline_layout_ci.pSetLayouts = &ds_layout;
11562
11563 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011564 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis85aa15a2016-06-15 10:52:37 -060011565 ASSERT_VK_SUCCESS(err);
11566
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011567 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
11568 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this); // We shouldn't need a fragment shader
11569 // but add it to be able to run on more devices
Tobin Ehlis85aa15a2016-06-15 10:52:37 -060011570 // Create a renderpass that will be incompatible with default renderpass
11571 VkAttachmentReference attach = {};
11572 attach.layout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
11573 VkAttachmentReference color_att = {};
11574 color_att.layout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
11575 VkSubpassDescription subpass = {};
11576 subpass.inputAttachmentCount = 1;
11577 subpass.pInputAttachments = &attach;
11578 subpass.colorAttachmentCount = 1;
11579 subpass.pColorAttachments = &color_att;
11580 VkRenderPassCreateInfo rpci = {};
11581 rpci.subpassCount = 1;
11582 rpci.pSubpasses = &subpass;
11583 rpci.attachmentCount = 1;
11584 VkAttachmentDescription attach_desc = {};
11585 attach_desc.samples = VK_SAMPLE_COUNT_1_BIT;
Cody Northropbd16af12016-06-21 09:25:48 -060011586 // Format incompatible with PSO RP color attach format B8G8R8A8_UNORM
11587 attach_desc.format = VK_FORMAT_R8G8B8A8_UNORM;
Tobin Ehlis85aa15a2016-06-15 10:52:37 -060011588 rpci.pAttachments = &attach_desc;
11589 rpci.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
11590 VkRenderPass rp;
11591 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
11592 VkPipelineObj pipe(m_device);
11593 pipe.AddShader(&vs);
11594 pipe.AddShader(&fs);
11595 pipe.AddColorAttachment();
11596 VkViewport view_port = {};
11597 m_viewports.push_back(view_port);
11598 pipe.SetViewport(m_viewports);
11599 VkRect2D rect = {};
11600 m_scissors.push_back(rect);
11601 pipe.SetScissor(m_scissors);
11602 pipe.CreateVKPipeline(pipeline_layout, renderPass());
11603
11604 VkCommandBufferInheritanceInfo cbii = {};
11605 cbii.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_INHERITANCE_INFO;
11606 cbii.renderPass = rp;
11607 cbii.subpass = 0;
11608 VkCommandBufferBeginInfo cbbi = {};
11609 cbbi.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
11610 cbbi.pInheritanceInfo = &cbii;
11611 vkBeginCommandBuffer(m_commandBuffer->handle(), &cbbi);
11612 VkRenderPassBeginInfo rpbi = {};
11613 rpbi.sType = VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO;
11614 rpbi.framebuffer = m_framebuffer;
11615 rpbi.renderPass = rp;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011616 vkCmdBeginRenderPass(m_commandBuffer->GetBufferHandle(), &rpbi, VK_SUBPASS_CONTENTS_INLINE);
11617 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Tobin Ehlis85aa15a2016-06-15 10:52:37 -060011618
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011619 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " is incompatible w/ gfx pipeline ");
Tobin Ehlis85aa15a2016-06-15 10:52:37 -060011620 // Render triangle (the error should trigger on the attempt to draw).
11621 Draw(3, 1, 0, 0);
11622
11623 // Finalize recording of the command buffer
11624 EndCommandBuffer();
11625
11626 m_errorMonitor->VerifyFound();
11627
11628 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
11629 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
11630 vkDestroyRenderPass(m_device->device(), rp, NULL);
11631}
11632
Mark Youngc89c6312016-03-31 16:03:20 -060011633TEST_F(VkLayerTest, NumBlendAttachMismatch) {
11634 // Create Pipeline where the number of blend attachments doesn't match the
11635 // number of color attachments. In this case, we don't add any color
11636 // blend attachments even though we have a color attachment.
11637 VkResult err;
11638
11639 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011640 "Render pass subpass 0 mismatch with blending state defined and blend state attachment");
Mark Youngc89c6312016-03-31 16:03:20 -060011641
11642 ASSERT_NO_FATAL_FAILURE(InitState());
11643 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
11644 VkDescriptorPoolSize ds_type_count = {};
11645 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
11646 ds_type_count.descriptorCount = 1;
11647
11648 VkDescriptorPoolCreateInfo ds_pool_ci = {};
11649 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
11650 ds_pool_ci.pNext = NULL;
11651 ds_pool_ci.maxSets = 1;
11652 ds_pool_ci.poolSizeCount = 1;
11653 ds_pool_ci.pPoolSizes = &ds_type_count;
11654
11655 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011656 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Mark Youngc89c6312016-03-31 16:03:20 -060011657 ASSERT_VK_SUCCESS(err);
11658
11659 VkDescriptorSetLayoutBinding dsl_binding = {};
11660 dsl_binding.binding = 0;
11661 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
11662 dsl_binding.descriptorCount = 1;
11663 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
11664 dsl_binding.pImmutableSamplers = NULL;
11665
11666 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
11667 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
11668 ds_layout_ci.pNext = NULL;
11669 ds_layout_ci.bindingCount = 1;
11670 ds_layout_ci.pBindings = &dsl_binding;
11671
11672 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011673 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Mark Youngc89c6312016-03-31 16:03:20 -060011674 ASSERT_VK_SUCCESS(err);
11675
11676 VkDescriptorSet descriptorSet;
11677 VkDescriptorSetAllocateInfo alloc_info = {};
11678 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
11679 alloc_info.descriptorSetCount = 1;
11680 alloc_info.descriptorPool = ds_pool;
11681 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011682 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Mark Youngc89c6312016-03-31 16:03:20 -060011683 ASSERT_VK_SUCCESS(err);
11684
11685 VkPipelineMultisampleStateCreateInfo pipe_ms_state_ci = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011686 pipe_ms_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
Mark Youngc89c6312016-03-31 16:03:20 -060011687 pipe_ms_state_ci.pNext = NULL;
11688 pipe_ms_state_ci.rasterizationSamples = VK_SAMPLE_COUNT_1_BIT;
11689 pipe_ms_state_ci.sampleShadingEnable = 0;
11690 pipe_ms_state_ci.minSampleShading = 1.0;
11691 pipe_ms_state_ci.pSampleMask = NULL;
11692
11693 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
11694 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
11695 pipeline_layout_ci.pNext = NULL;
11696 pipeline_layout_ci.setLayoutCount = 1;
11697 pipeline_layout_ci.pSetLayouts = &ds_layout;
11698
11699 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011700 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Mark Youngc89c6312016-03-31 16:03:20 -060011701 ASSERT_VK_SUCCESS(err);
11702
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011703 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
11704 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this); // We shouldn't need a fragment shader
11705 // but add it to be able to run on more devices
Mark Youngc89c6312016-03-31 16:03:20 -060011706 VkPipelineObj pipe(m_device);
11707 pipe.AddShader(&vs);
11708 pipe.AddShader(&fs);
11709 pipe.SetMSAA(&pipe_ms_state_ci);
11710 pipe.CreateVKPipeline(pipeline_layout, renderPass());
11711
11712 BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011713 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Mark Youngc89c6312016-03-31 16:03:20 -060011714
Mark Young29927482016-05-04 14:38:51 -060011715 // Render triangle (the error should trigger on the attempt to draw).
11716 Draw(3, 1, 0, 0);
11717
11718 // Finalize recording of the command buffer
11719 EndCommandBuffer();
11720
Chris Forbes8f36a8a2016-04-07 13:21:07 +120011721 m_errorMonitor->VerifyFound();
Mark Youngc89c6312016-03-31 16:03:20 -060011722
11723 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
11724 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
11725 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
11726}
Mark Young29927482016-05-04 14:38:51 -060011727
Mark Muellerd4914412016-06-13 17:52:06 -060011728TEST_F(VkLayerTest, MissingClearAttachment) {
11729 TEST_DESCRIPTION("Points to a wrong colorAttachment index in a VkClearAttachment "
11730 "structure passed to vkCmdClearAttachments");
Cody Northropc31a84f2016-08-22 10:41:47 -060011731 ASSERT_NO_FATAL_FAILURE(InitState());
Chris Forbesda6ae6f2016-09-09 14:36:33 +120011732 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Chris Forbesef5e2842016-09-08 15:25:24 +120011733 "vkCmdClearAttachments() color attachment index 1 out of range for active subpass 0; ignored");
Mark Muellerd4914412016-06-13 17:52:06 -060011734
11735 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailCmdClearAttachments);
11736 m_errorMonitor->VerifyFound();
11737}
11738
Karl Schultz6addd812016-02-02 17:17:23 -070011739TEST_F(VkLayerTest, ClearCmdNoDraw) {
11740 // Create CommandBuffer where we add ClearCmd for FB Color attachment prior
11741 // to issuing a Draw
11742 VkResult err;
Tobin Ehlis53eddda2015-07-01 16:46:13 -060011743
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011744 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
11745 "vkCmdClearAttachments() issued on CB object ");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060011746
Tobin Ehlis53eddda2015-07-01 16:46:13 -060011747 ASSERT_NO_FATAL_FAILURE(InitState());
11748 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barboureb254902015-07-15 12:50:33 -060011749
Chia-I Wu1b99bb22015-10-27 19:25:11 +080011750 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011751 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
11752 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -060011753
11754 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011755 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
11756 ds_pool_ci.pNext = NULL;
11757 ds_pool_ci.maxSets = 1;
11758 ds_pool_ci.poolSizeCount = 1;
11759 ds_pool_ci.pPoolSizes = &ds_type_count;
Tony Barboureb254902015-07-15 12:50:33 -060011760
Tobin Ehlis53eddda2015-07-01 16:46:13 -060011761 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011762 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis53eddda2015-07-01 16:46:13 -060011763 ASSERT_VK_SUCCESS(err);
11764
Tony Barboureb254902015-07-15 12:50:33 -060011765 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011766 dsl_binding.binding = 0;
11767 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
11768 dsl_binding.descriptorCount = 1;
11769 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
11770 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis53eddda2015-07-01 16:46:13 -060011771
Tony Barboureb254902015-07-15 12:50:33 -060011772 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011773 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
11774 ds_layout_ci.pNext = NULL;
11775 ds_layout_ci.bindingCount = 1;
11776 ds_layout_ci.pBindings = &dsl_binding;
Mark Lobodzinski209b5292015-09-17 09:44:05 -060011777
Tobin Ehlis53eddda2015-07-01 16:46:13 -060011778 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011779 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis53eddda2015-07-01 16:46:13 -060011780 ASSERT_VK_SUCCESS(err);
11781
11782 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080011783 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +080011784 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -070011785 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -060011786 alloc_info.descriptorPool = ds_pool;
11787 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011788 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis53eddda2015-07-01 16:46:13 -060011789 ASSERT_VK_SUCCESS(err);
11790
Tony Barboureb254902015-07-15 12:50:33 -060011791 VkPipelineMultisampleStateCreateInfo pipe_ms_state_ci = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011792 pipe_ms_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
Karl Schultz6addd812016-02-02 17:17:23 -070011793 pipe_ms_state_ci.pNext = NULL;
11794 pipe_ms_state_ci.rasterizationSamples = VK_SAMPLE_COUNT_4_BIT;
11795 pipe_ms_state_ci.sampleShadingEnable = 0;
11796 pipe_ms_state_ci.minSampleShading = 1.0;
11797 pipe_ms_state_ci.pSampleMask = NULL;
Tobin Ehlis53eddda2015-07-01 16:46:13 -060011798
Tony Barboureb254902015-07-15 12:50:33 -060011799 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011800 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
11801 pipeline_layout_ci.pNext = NULL;
11802 pipeline_layout_ci.setLayoutCount = 1;
11803 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlis53eddda2015-07-01 16:46:13 -060011804
11805 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011806 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis53eddda2015-07-01 16:46:13 -060011807 ASSERT_VK_SUCCESS(err);
Mark Lobodzinski209b5292015-09-17 09:44:05 -060011808
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011809 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
Karl Schultzbdb75952016-04-19 11:36:49 -060011810 // We shouldn't need a fragment shader but add it to be able to run
Karl Schultz6addd812016-02-02 17:17:23 -070011811 // on more devices
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011812 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060011813
Tony Barbour62e1a5b2015-08-06 10:16:07 -060011814 VkPipelineObj pipe(m_device);
11815 pipe.AddShader(&vs);
Tony Barbour1c94d372015-08-06 11:21:08 -060011816 pipe.AddShader(&fs);
Tony Barbour62e1a5b2015-08-06 10:16:07 -060011817 pipe.SetMSAA(&pipe_ms_state_ci);
11818 pipe.CreateVKPipeline(pipeline_layout, renderPass());
Tony Barbourfe3351b2015-07-28 10:17:20 -060011819
11820 BeginCommandBuffer();
Tobin Ehlis53eddda2015-07-01 16:46:13 -060011821
Karl Schultz6addd812016-02-02 17:17:23 -070011822 // Main thing we care about for this test is that the VkImage obj we're
11823 // clearing matches Color Attachment of FB
Tobin Ehlis53eddda2015-07-01 16:46:13 -060011824 // Also pass down other dummy params to keep driver and paramchecker happy
Courtney Goeltzenleuchterc9323e02015-10-15 16:51:05 -060011825 VkClearAttachment color_attachment;
11826 color_attachment.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
11827 color_attachment.clearValue.color.float32[0] = 1.0;
11828 color_attachment.clearValue.color.float32[1] = 1.0;
11829 color_attachment.clearValue.color.float32[2] = 1.0;
11830 color_attachment.clearValue.color.float32[3] = 1.0;
11831 color_attachment.colorAttachment = 0;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011832 VkClearRect clear_rect = {{{0, 0}, {(uint32_t)m_width, (uint32_t)m_height}}};
Tobin Ehlis53eddda2015-07-01 16:46:13 -060011833
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011834 vkCmdClearAttachments(m_commandBuffer->GetBufferHandle(), 1, &color_attachment, 1, &clear_rect);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060011835
Chris Forbes8f36a8a2016-04-07 13:21:07 +120011836 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -060011837
Chia-I Wuf7458c52015-10-26 21:10:41 +080011838 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
11839 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
11840 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis53eddda2015-07-01 16:46:13 -060011841}
11842
Karl Schultz6addd812016-02-02 17:17:23 -070011843TEST_F(VkLayerTest, VtxBufferBadIndex) {
11844 VkResult err;
Tobin Ehlis502480b2015-06-24 15:53:07 -060011845
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011846 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
11847 "but no vertex buffers are attached to this Pipeline State Object");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060011848
Tobin Ehlis502480b2015-06-24 15:53:07 -060011849 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisd332f282015-10-02 11:00:56 -060011850 ASSERT_NO_FATAL_FAILURE(InitViewport());
Tobin Ehlis502480b2015-06-24 15:53:07 -060011851 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barboureb254902015-07-15 12:50:33 -060011852
Chia-I Wu1b99bb22015-10-27 19:25:11 +080011853 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011854 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
11855 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -060011856
11857 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011858 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
11859 ds_pool_ci.pNext = NULL;
11860 ds_pool_ci.maxSets = 1;
11861 ds_pool_ci.poolSizeCount = 1;
11862 ds_pool_ci.pPoolSizes = &ds_type_count;
Tony Barboureb254902015-07-15 12:50:33 -060011863
Courtney Goeltzenleuchterfe908d32015-09-16 16:12:45 -060011864 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011865 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis502480b2015-06-24 15:53:07 -060011866 ASSERT_VK_SUCCESS(err);
11867
Tony Barboureb254902015-07-15 12:50:33 -060011868 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011869 dsl_binding.binding = 0;
11870 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
11871 dsl_binding.descriptorCount = 1;
11872 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
11873 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis502480b2015-06-24 15:53:07 -060011874
Tony Barboureb254902015-07-15 12:50:33 -060011875 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011876 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
11877 ds_layout_ci.pNext = NULL;
11878 ds_layout_ci.bindingCount = 1;
11879 ds_layout_ci.pBindings = &dsl_binding;
Tony Barboureb254902015-07-15 12:50:33 -060011880
Tobin Ehlis502480b2015-06-24 15:53:07 -060011881 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011882 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis502480b2015-06-24 15:53:07 -060011883 ASSERT_VK_SUCCESS(err);
11884
11885 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080011886 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +080011887 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -070011888 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -060011889 alloc_info.descriptorPool = ds_pool;
11890 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011891 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis502480b2015-06-24 15:53:07 -060011892 ASSERT_VK_SUCCESS(err);
11893
Tony Barboureb254902015-07-15 12:50:33 -060011894 VkPipelineMultisampleStateCreateInfo pipe_ms_state_ci = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011895 pipe_ms_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
Karl Schultz6addd812016-02-02 17:17:23 -070011896 pipe_ms_state_ci.pNext = NULL;
11897 pipe_ms_state_ci.rasterizationSamples = VK_SAMPLE_COUNT_1_BIT;
11898 pipe_ms_state_ci.sampleShadingEnable = 0;
11899 pipe_ms_state_ci.minSampleShading = 1.0;
11900 pipe_ms_state_ci.pSampleMask = NULL;
Tobin Ehlis502480b2015-06-24 15:53:07 -060011901
Tony Barboureb254902015-07-15 12:50:33 -060011902 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011903 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
11904 pipeline_layout_ci.pNext = NULL;
11905 pipeline_layout_ci.setLayoutCount = 1;
11906 pipeline_layout_ci.pSetLayouts = &ds_layout;
11907 VkPipelineLayout pipeline_layout;
Tobin Ehlis502480b2015-06-24 15:53:07 -060011908
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011909 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis502480b2015-06-24 15:53:07 -060011910 ASSERT_VK_SUCCESS(err);
11911
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011912 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
11913 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this); // We shouldn't need a fragment shader
11914 // but add it to be able to run on more devices
Tony Barbour62e1a5b2015-08-06 10:16:07 -060011915 VkPipelineObj pipe(m_device);
11916 pipe.AddShader(&vs);
Tony Barbour1c94d372015-08-06 11:21:08 -060011917 pipe.AddShader(&fs);
Mark Youngc89c6312016-03-31 16:03:20 -060011918 pipe.AddColorAttachment();
Tony Barbour62e1a5b2015-08-06 10:16:07 -060011919 pipe.SetMSAA(&pipe_ms_state_ci);
Tobin Ehlisd332f282015-10-02 11:00:56 -060011920 pipe.SetViewport(m_viewports);
11921 pipe.SetScissor(m_scissors);
Tony Barbour62e1a5b2015-08-06 10:16:07 -060011922 pipe.CreateVKPipeline(pipeline_layout, renderPass());
Tony Barbourfe3351b2015-07-28 10:17:20 -060011923
11924 BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011925 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Tobin Ehlisf7bf4502015-09-09 15:12:35 -060011926 // Don't care about actual data, just need to get to draw to flag error
11927 static const float vbo_data[3] = {1.f, 0.f, 1.f};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011928 VkConstantBufferObj vbo(m_device, sizeof(vbo_data), sizeof(float), (const void *)&vbo_data);
Tobin Ehlisf7bf4502015-09-09 15:12:35 -060011929 BindVertexBuffer(&vbo, (VkDeviceSize)0, 1); // VBO idx 1, but no VBO in PSO
Courtney Goeltzenleuchter08c26372015-09-23 12:31:50 -060011930 Draw(1, 0, 0, 0);
Tobin Ehlis502480b2015-06-24 15:53:07 -060011931
Chris Forbes8f36a8a2016-04-07 13:21:07 +120011932 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -060011933
Chia-I Wuf7458c52015-10-26 21:10:41 +080011934 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
11935 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
11936 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis502480b2015-06-24 15:53:07 -060011937}
Mark Muellerdfe37552016-07-07 14:47:42 -060011938
Mark Mueller2ee294f2016-08-04 12:59:48 -060011939TEST_F(VkLayerTest, MismatchCountQueueCreateRequestedFeature) {
11940 TEST_DESCRIPTION("Use an invalid count in a vkEnumeratePhysicalDevices call."
11941 "Use invalid Queue Family Index in vkCreateDevice");
Cody Northropc31a84f2016-08-22 10:41:47 -060011942 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Mueller2ee294f2016-08-04 12:59:48 -060011943
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011944 const char *mismatch_count_message = "Call to vkEnumeratePhysicalDevices() "
11945 "w/ pPhysicalDeviceCount value ";
Mark Mueller2ee294f2016-08-04 12:59:48 -060011946
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011947 const char *invalid_queueFamilyIndex_message = "Invalid queue create request in vkCreateDevice(). Invalid "
11948 "queueFamilyIndex ";
Mark Mueller2ee294f2016-08-04 12:59:48 -060011949
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011950 const char *unavailable_feature_message = "While calling vkCreateDevice(), requesting feature #";
Mark Mueller2ee294f2016-08-04 12:59:48 -060011951
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011952 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT, mismatch_count_message);
Mark Mueller880fce52016-08-17 15:23:23 -060011953 // The following test fails with recent NVidia drivers.
11954 // By the time core_validation is reached, the NVidia
11955 // driver has sanitized the invalid condition and core_validation
11956 // is not introduced to the failure condition. This is not the case
11957 // with AMD and Mesa drivers. Futher investigation is required
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011958 // uint32_t count = static_cast<uint32_t>(~0);
11959 // VkPhysicalDevice physical_device;
11960 // vkEnumeratePhysicalDevices(instance(), &count, &physical_device);
11961 // m_errorMonitor->VerifyFound();
Mark Mueller2ee294f2016-08-04 12:59:48 -060011962
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011963 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, invalid_queueFamilyIndex_message);
Mark Mueller2ee294f2016-08-04 12:59:48 -060011964 float queue_priority = 0.0;
11965
11966 VkDeviceQueueCreateInfo queue_create_info = {};
11967 queue_create_info.sType = VK_STRUCTURE_TYPE_DEVICE_QUEUE_CREATE_INFO;
11968 queue_create_info.queueCount = 1;
11969 queue_create_info.pQueuePriorities = &queue_priority;
11970 queue_create_info.queueFamilyIndex = static_cast<uint32_t>(~0);
11971
11972 VkPhysicalDeviceFeatures features = m_device->phy().features();
11973 VkDevice testDevice;
11974 VkDeviceCreateInfo device_create_info = {};
11975 device_create_info.sType = VK_STRUCTURE_TYPE_DEVICE_CREATE_INFO;
11976 device_create_info.queueCreateInfoCount = 1;
11977 device_create_info.pQueueCreateInfos = &queue_create_info;
11978 device_create_info.pEnabledFeatures = &features;
11979 vkCreateDevice(gpu(), &device_create_info, nullptr, &testDevice);
11980 m_errorMonitor->VerifyFound();
11981
11982 queue_create_info.queueFamilyIndex = 1;
11983
11984 unsigned feature_count = sizeof(VkPhysicalDeviceFeatures) / sizeof(VkBool32);
11985 VkBool32 *feature_array = reinterpret_cast<VkBool32 *>(&features);
11986 for (unsigned i = 0; i < feature_count; i++) {
11987 if (VK_FALSE == feature_array[i]) {
11988 feature_array[i] = VK_TRUE;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011989 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, unavailable_feature_message);
Mark Mueller2ee294f2016-08-04 12:59:48 -060011990 device_create_info.pEnabledFeatures = &features;
11991 vkCreateDevice(gpu(), &device_create_info, nullptr, &testDevice);
11992 m_errorMonitor->VerifyFound();
11993 break;
11994 }
11995 }
11996}
11997
11998TEST_F(VkLayerTest, InvalidQueueIndexInvalidQuery) {
11999 TEST_DESCRIPTION("Use an invalid queue index in a vkCmdWaitEvents call."
12000 "End a command buffer with a query still in progress.");
12001
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012002 const char *invalid_queue_index = "was created with sharingMode of VK_SHARING_MODE_EXCLUSIVE. If one "
12003 "of src- or dstQueueFamilyIndex is VK_QUEUE_FAMILY_IGNORED, both "
12004 "must be.";
Mark Mueller2ee294f2016-08-04 12:59:48 -060012005
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012006 const char *invalid_query = "Ending command buffer with in progress query: queryPool 0x";
Mark Mueller2ee294f2016-08-04 12:59:48 -060012007
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012008 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, invalid_queue_index);
Mark Mueller2ee294f2016-08-04 12:59:48 -060012009
12010 ASSERT_NO_FATAL_FAILURE(InitState());
12011
12012 VkEvent event;
12013 VkEventCreateInfo event_create_info{};
12014 event_create_info.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO;
12015 vkCreateEvent(m_device->device(), &event_create_info, nullptr, &event);
12016
Mark Mueller2ee294f2016-08-04 12:59:48 -060012017 VkQueue queue = VK_NULL_HANDLE;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012018 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 0, &queue);
Mark Mueller2ee294f2016-08-04 12:59:48 -060012019
12020 BeginCommandBuffer();
12021
12022 VkImageObj image(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012023 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 -060012024 ASSERT_TRUE(image.initialized());
12025 VkImageMemoryBarrier img_barrier = {};
12026 img_barrier.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
12027 img_barrier.pNext = NULL;
12028 img_barrier.srcAccessMask = VK_ACCESS_HOST_WRITE_BIT;
12029 img_barrier.dstAccessMask = VK_ACCESS_SHADER_READ_BIT;
12030 img_barrier.oldLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
12031 img_barrier.newLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
12032 img_barrier.image = image.handle();
12033 img_barrier.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
Mark Lobodzinski2a74c5c2016-08-17 13:26:28 -060012034
12035 // QueueFamilyIndex must be VK_QUEUE_FAMILY_IGNORED, this verifies
12036 // that layer validation catches the case when it is not.
12037 img_barrier.dstQueueFamilyIndex = 0;
Mark Mueller2ee294f2016-08-04 12:59:48 -060012038 img_barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
12039 img_barrier.subresourceRange.baseArrayLayer = 0;
12040 img_barrier.subresourceRange.baseMipLevel = 0;
12041 img_barrier.subresourceRange.layerCount = 1;
12042 img_barrier.subresourceRange.levelCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012043 vkCmdWaitEvents(m_commandBuffer->handle(), 1, &event, VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0,
12044 nullptr, 0, nullptr, 1, &img_barrier);
Mark Mueller2ee294f2016-08-04 12:59:48 -060012045 m_errorMonitor->VerifyFound();
12046
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012047 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, invalid_query);
Mark Mueller2ee294f2016-08-04 12:59:48 -060012048
12049 VkQueryPool query_pool;
12050 VkQueryPoolCreateInfo query_pool_create_info = {};
12051 query_pool_create_info.sType = VK_STRUCTURE_TYPE_QUERY_POOL_CREATE_INFO;
12052 query_pool_create_info.queryType = VK_QUERY_TYPE_OCCLUSION;
12053 query_pool_create_info.queryCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012054 vkCreateQueryPool(m_device->device(), &query_pool_create_info, nullptr, &query_pool);
Mark Mueller2ee294f2016-08-04 12:59:48 -060012055
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012056 vkCmdResetQueryPool(m_commandBuffer->handle(), query_pool, 0 /*startQuery*/, 1 /*queryCount*/);
Mark Mueller2ee294f2016-08-04 12:59:48 -060012057 vkCmdBeginQuery(m_commandBuffer->handle(), query_pool, 0, 0);
12058
12059 vkEndCommandBuffer(m_commandBuffer->handle());
12060 m_errorMonitor->VerifyFound();
12061
12062 vkDestroyQueryPool(m_device->device(), query_pool, nullptr);
12063 vkDestroyEvent(m_device->device(), event, nullptr);
12064}
12065
Mark Muellerdfe37552016-07-07 14:47:42 -060012066TEST_F(VkLayerTest, VertexBufferInvalid) {
12067 TEST_DESCRIPTION("Submit a command buffer using deleted vertex buffer, "
12068 "delete a buffer twice, use an invalid offset for each "
12069 "buffer type, and attempt to bind a null buffer");
12070
12071 const char *deleted_buffer_in_command_buffer = "Cannot submit cmd buffer "
12072 "using deleted buffer ";
12073 const char *double_destroy_message = "Cannot free buffer 0x";
12074 const char *invalid_offset_message = "vkBindBufferMemory(): "
12075 "memoryOffset is 0x";
12076 const char *invalid_storage_buffer_offset_message = "vkBindBufferMemory(): "
12077 "storage memoryOffset "
12078 "is 0x";
12079 const char *invalid_texel_buffer_offset_message = "vkBindBufferMemory(): "
12080 "texel memoryOffset "
12081 "is 0x";
12082 const char *invalid_uniform_buffer_offset_message = "vkBindBufferMemory(): "
12083 "uniform memoryOffset "
12084 "is 0x";
12085 const char *bind_null_buffer_message = "In vkBindBufferMemory, attempting"
12086 " to Bind Obj(0x";
12087 const char *free_invalid_buffer_message = "Request to delete memory "
12088 "object 0x";
12089
12090 ASSERT_NO_FATAL_FAILURE(InitState());
12091 ASSERT_NO_FATAL_FAILURE(InitViewport());
12092 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12093
12094 VkPipelineMultisampleStateCreateInfo pipe_ms_state_ci = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012095 pipe_ms_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
Mark Muellerdfe37552016-07-07 14:47:42 -060012096 pipe_ms_state_ci.pNext = NULL;
12097 pipe_ms_state_ci.rasterizationSamples = VK_SAMPLE_COUNT_1_BIT;
12098 pipe_ms_state_ci.sampleShadingEnable = 0;
12099 pipe_ms_state_ci.minSampleShading = 1.0;
12100 pipe_ms_state_ci.pSampleMask = nullptr;
12101
12102 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
12103 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
12104 VkPipelineLayout pipeline_layout;
12105
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012106 VkResult err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, nullptr, &pipeline_layout);
Mark Muellerdfe37552016-07-07 14:47:42 -060012107 ASSERT_VK_SUCCESS(err);
12108
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012109 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
12110 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Mark Muellerdfe37552016-07-07 14:47:42 -060012111 VkPipelineObj pipe(m_device);
12112 pipe.AddShader(&vs);
12113 pipe.AddShader(&fs);
12114 pipe.AddColorAttachment();
12115 pipe.SetMSAA(&pipe_ms_state_ci);
12116 pipe.SetViewport(m_viewports);
12117 pipe.SetScissor(m_scissors);
12118 pipe.CreateVKPipeline(pipeline_layout, renderPass());
12119
12120 BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012121 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Mark Muellerdfe37552016-07-07 14:47:42 -060012122
12123 {
12124 // Create and bind a vertex buffer in a reduced scope, which will cause
12125 // it to be deleted upon leaving this scope
12126 const float vbo_data[3] = {1.f, 0.f, 1.f};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012127 VkVerticesObj draw_verticies(m_device, 1, 1, sizeof(vbo_data), 3, vbo_data);
Mark Muellerdfe37552016-07-07 14:47:42 -060012128 draw_verticies.BindVertexBuffers(m_commandBuffer->handle());
12129 draw_verticies.AddVertexInputToPipe(pipe);
12130 }
12131
12132 Draw(1, 0, 0, 0);
12133
12134 EndCommandBuffer();
12135
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012136 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, deleted_buffer_in_command_buffer);
Mark Muellerdfe37552016-07-07 14:47:42 -060012137 QueueCommandBuffer(false);
12138 m_errorMonitor->VerifyFound();
12139
12140 {
12141 // Create and bind a vertex buffer in a reduced scope, and delete it
12142 // twice, the second through the destructor
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012143 VkBufferTest buffer_test(m_device, VK_BUFFER_USAGE_STORAGE_BUFFER_BIT, VkBufferTest::eDoubleDelete);
12144 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, double_destroy_message);
Mark Muellerdfe37552016-07-07 14:47:42 -060012145 buffer_test.TestDoubleDestroy();
12146 }
12147 m_errorMonitor->VerifyFound();
12148
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012149 if (VkBufferTest::GetTestConditionValid(m_device, VkBufferTest::eInvalidMemoryOffset)) {
Mark Muellerdfe37552016-07-07 14:47:42 -060012150 // Create and bind a memory buffer with an invalid offset.
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012151 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, invalid_offset_message);
12152 VkBufferTest buffer_test(m_device, VK_BUFFER_USAGE_UNIFORM_TEXEL_BUFFER_BIT, VkBufferTest::eInvalidMemoryOffset);
12153 (void)buffer_test;
Mark Muellerdfe37552016-07-07 14:47:42 -060012154 m_errorMonitor->VerifyFound();
12155 }
12156
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012157 if (VkBufferTest::GetTestConditionValid(m_device, VkBufferTest::eInvalidDeviceOffset,
12158 VK_BUFFER_USAGE_UNIFORM_TEXEL_BUFFER_BIT)) {
Mark Muellerdfe37552016-07-07 14:47:42 -060012159 // Create and bind a memory buffer with an invalid offset again,
12160 // but look for a texel buffer message.
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012161 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, invalid_texel_buffer_offset_message);
12162 VkBufferTest buffer_test(m_device, VK_BUFFER_USAGE_UNIFORM_TEXEL_BUFFER_BIT, VkBufferTest::eInvalidDeviceOffset);
12163 (void)buffer_test;
Mark Muellerdfe37552016-07-07 14:47:42 -060012164 m_errorMonitor->VerifyFound();
12165 }
12166
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012167 if (VkBufferTest::GetTestConditionValid(m_device, VkBufferTest::eInvalidDeviceOffset, VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT)) {
Mark Muellerdfe37552016-07-07 14:47:42 -060012168 // Create and bind a memory buffer with an invalid offset again, but
12169 // look for a uniform buffer message.
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012170 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, invalid_uniform_buffer_offset_message);
12171 VkBufferTest buffer_test(m_device, VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT, VkBufferTest::eInvalidDeviceOffset);
12172 (void)buffer_test;
Mark Muellerdfe37552016-07-07 14:47:42 -060012173 m_errorMonitor->VerifyFound();
12174 }
12175
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012176 if (VkBufferTest::GetTestConditionValid(m_device, VkBufferTest::eInvalidDeviceOffset, VK_BUFFER_USAGE_STORAGE_BUFFER_BIT)) {
Mark Muellerdfe37552016-07-07 14:47:42 -060012177 // Create and bind a memory buffer with an invalid offset again, but
12178 // look for a storage buffer message.
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012179 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, invalid_storage_buffer_offset_message);
12180 VkBufferTest buffer_test(m_device, VK_BUFFER_USAGE_STORAGE_BUFFER_BIT, VkBufferTest::eInvalidDeviceOffset);
12181 (void)buffer_test;
Mark Muellerdfe37552016-07-07 14:47:42 -060012182 m_errorMonitor->VerifyFound();
12183 }
12184
12185 {
12186 // Attempt to bind a null buffer.
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012187 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, bind_null_buffer_message);
12188 VkBufferTest buffer_test(m_device, VK_BUFFER_USAGE_STORAGE_BUFFER_BIT, VkBufferTest::eBindNullBuffer);
12189 (void)buffer_test;
Mark Muellerdfe37552016-07-07 14:47:42 -060012190 m_errorMonitor->VerifyFound();
12191 }
12192
12193 {
12194 // Attempt to use an invalid handle to delete a buffer.
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012195 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, free_invalid_buffer_message);
12196 VkBufferTest buffer_test(m_device, VK_BUFFER_USAGE_STORAGE_BUFFER_BIT, VkBufferTest::eFreeInvalidHandle);
12197 (void)buffer_test;
Mark Muellerdfe37552016-07-07 14:47:42 -060012198 }
12199 m_errorMonitor->VerifyFound();
12200
12201 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
12202}
12203
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060012204// INVALID_IMAGE_LAYOUT tests (one other case is hit by MapMemWithoutHostVisibleBit and not here)
12205TEST_F(VkLayerTest, InvalidImageLayout) {
12206 TEST_DESCRIPTION("Hit all possible validation checks associated with the "
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012207 "DRAWSTATE_INVALID_IMAGE_LAYOUT enum. Generally these involve having"
12208 "images in the wrong layout when they're copied or transitioned.");
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060012209 // 3 in ValidateCmdBufImageLayouts
12210 // * -1 Attempt to submit cmd buf w/ deleted image
12211 // * -2 Cmd buf submit of image w/ layout not matching first use w/ subresource
12212 // * -3 Cmd buf submit of image w/ layout not matching first use w/o subresource
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012213 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
12214 "Layout for input image should be TRANSFER_SRC_OPTIMAL instead of GENERAL.");
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060012215
12216 ASSERT_NO_FATAL_FAILURE(InitState());
12217 // Create src & dst images to use for copy operations
12218 VkImage src_image;
12219 VkImage dst_image;
12220
12221 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
12222 const int32_t tex_width = 32;
12223 const int32_t tex_height = 32;
12224
12225 VkImageCreateInfo image_create_info = {};
12226 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
12227 image_create_info.pNext = NULL;
12228 image_create_info.imageType = VK_IMAGE_TYPE_2D;
12229 image_create_info.format = tex_format;
12230 image_create_info.extent.width = tex_width;
12231 image_create_info.extent.height = tex_height;
12232 image_create_info.extent.depth = 1;
12233 image_create_info.mipLevels = 1;
12234 image_create_info.arrayLayers = 4;
12235 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
12236 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
12237 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
12238 image_create_info.flags = 0;
12239
12240 VkResult err = vkCreateImage(m_device->device(), &image_create_info, NULL, &src_image);
12241 ASSERT_VK_SUCCESS(err);
12242 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &dst_image);
12243 ASSERT_VK_SUCCESS(err);
12244
12245 BeginCommandBuffer();
12246 VkImageCopy copyRegion;
12247 copyRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
12248 copyRegion.srcSubresource.mipLevel = 0;
12249 copyRegion.srcSubresource.baseArrayLayer = 0;
12250 copyRegion.srcSubresource.layerCount = 1;
12251 copyRegion.srcOffset.x = 0;
12252 copyRegion.srcOffset.y = 0;
12253 copyRegion.srcOffset.z = 0;
12254 copyRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
12255 copyRegion.dstSubresource.mipLevel = 0;
12256 copyRegion.dstSubresource.baseArrayLayer = 0;
12257 copyRegion.dstSubresource.layerCount = 1;
12258 copyRegion.dstOffset.x = 0;
12259 copyRegion.dstOffset.y = 0;
12260 copyRegion.dstOffset.z = 0;
12261 copyRegion.extent.width = 1;
12262 copyRegion.extent.height = 1;
12263 copyRegion.extent.depth = 1;
12264 m_commandBuffer->CopyImage(src_image, VK_IMAGE_LAYOUT_GENERAL, dst_image, VK_IMAGE_LAYOUT_GENERAL, 1, &copyRegion);
12265 m_errorMonitor->VerifyFound();
12266 // Now cause error due to src image layout changing
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012267 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Cannot copy from an image whose source layout is "
12268 "VK_IMAGE_LAYOUT_UNDEFINED and doesn't match the current "
12269 "layout VK_IMAGE_LAYOUT_GENERAL.");
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060012270 m_commandBuffer->CopyImage(src_image, VK_IMAGE_LAYOUT_UNDEFINED, dst_image, VK_IMAGE_LAYOUT_GENERAL, 1, &copyRegion);
12271 m_errorMonitor->VerifyFound();
12272 // Final src error is due to bad layout type
12273 m_errorMonitor->SetDesiredFailureMsg(
12274 VK_DEBUG_REPORT_ERROR_BIT_EXT,
12275 "Layout for input image is VK_IMAGE_LAYOUT_UNDEFINED but can only be TRANSFER_SRC_OPTIMAL or GENERAL.");
12276 m_commandBuffer->CopyImage(src_image, VK_IMAGE_LAYOUT_UNDEFINED, dst_image, VK_IMAGE_LAYOUT_GENERAL, 1, &copyRegion);
12277 m_errorMonitor->VerifyFound();
12278 // Now verify same checks for dst
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012279 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
12280 "Layout for output image should be TRANSFER_DST_OPTIMAL instead of GENERAL.");
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060012281 m_commandBuffer->CopyImage(src_image, VK_IMAGE_LAYOUT_GENERAL, dst_image, VK_IMAGE_LAYOUT_GENERAL, 1, &copyRegion);
12282 m_errorMonitor->VerifyFound();
12283 // Now cause error due to src image layout changing
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012284 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Cannot copy from an image whose dest layout is "
12285 "VK_IMAGE_LAYOUT_UNDEFINED and doesn't match the current "
12286 "layout VK_IMAGE_LAYOUT_GENERAL.");
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060012287 m_commandBuffer->CopyImage(src_image, VK_IMAGE_LAYOUT_GENERAL, dst_image, VK_IMAGE_LAYOUT_UNDEFINED, 1, &copyRegion);
12288 m_errorMonitor->VerifyFound();
12289 m_errorMonitor->SetDesiredFailureMsg(
12290 VK_DEBUG_REPORT_ERROR_BIT_EXT,
12291 "Layout for output image is VK_IMAGE_LAYOUT_UNDEFINED but can only be TRANSFER_DST_OPTIMAL or GENERAL.");
12292 m_commandBuffer->CopyImage(src_image, VK_IMAGE_LAYOUT_GENERAL, dst_image, VK_IMAGE_LAYOUT_UNDEFINED, 1, &copyRegion);
12293 m_errorMonitor->VerifyFound();
12294 // Now cause error due to bad image layout transition in PipelineBarrier
12295 VkImageMemoryBarrier image_barrier[1] = {};
12296 image_barrier[0].oldLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL;
12297 image_barrier[0].image = src_image;
12298 image_barrier[0].subresourceRange.layerCount = 2;
12299 image_barrier[0].subresourceRange.levelCount = 2;
12300 image_barrier[0].subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012301 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "You cannot transition the layout from "
12302 "VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL when "
12303 "current layout is VK_IMAGE_LAYOUT_GENERAL.");
12304 vkCmdPipelineBarrier(m_commandBuffer->handle(), VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0,
12305 NULL, 0, NULL, 1, image_barrier);
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060012306 m_errorMonitor->VerifyFound();
12307
12308 // Finally some layout errors at RenderPass create time
12309 // Just hacking in specific state to get to the errors we want so don't copy this unless you know what you're doing.
12310 VkAttachmentReference attach = {};
12311 // perf warning for GENERAL layout w/ non-DS input attachment
12312 attach.layout = VK_IMAGE_LAYOUT_GENERAL;
12313 VkSubpassDescription subpass = {};
12314 subpass.inputAttachmentCount = 1;
12315 subpass.pInputAttachments = &attach;
12316 VkRenderPassCreateInfo rpci = {};
12317 rpci.subpassCount = 1;
12318 rpci.pSubpasses = &subpass;
12319 rpci.attachmentCount = 1;
12320 VkAttachmentDescription attach_desc = {};
12321 attach_desc.format = VK_FORMAT_UNDEFINED;
12322 rpci.pAttachments = &attach_desc;
Tobin Ehlis1efce022016-05-11 10:40:34 -060012323 rpci.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060012324 VkRenderPass rp;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012325 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
12326 "Layout for input attachment is GENERAL but should be READ_ONLY_OPTIMAL.");
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060012327 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
12328 m_errorMonitor->VerifyFound();
12329 // error w/ non-general layout
12330 attach.layout = VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL;
12331
12332 m_errorMonitor->SetDesiredFailureMsg(
12333 VK_DEBUG_REPORT_ERROR_BIT_EXT,
12334 "Layout for input attachment is VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL but can only be READ_ONLY_OPTIMAL or GENERAL.");
12335 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
12336 m_errorMonitor->VerifyFound();
12337 subpass.inputAttachmentCount = 0;
12338 subpass.colorAttachmentCount = 1;
12339 subpass.pColorAttachments = &attach;
12340 attach.layout = VK_IMAGE_LAYOUT_GENERAL;
12341 // perf warning for GENERAL layout on color attachment
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012342 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
12343 "Layout for color attachment is GENERAL but should be COLOR_ATTACHMENT_OPTIMAL.");
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060012344 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
12345 m_errorMonitor->VerifyFound();
12346 // error w/ non-color opt or GENERAL layout for color attachment
12347 attach.layout = VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL;
12348 m_errorMonitor->SetDesiredFailureMsg(
12349 VK_DEBUG_REPORT_ERROR_BIT_EXT,
12350 "Layout for color attachment is VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL but can only be COLOR_ATTACHMENT_OPTIMAL or GENERAL.");
12351 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
12352 m_errorMonitor->VerifyFound();
12353 subpass.colorAttachmentCount = 0;
12354 subpass.pDepthStencilAttachment = &attach;
12355 attach.layout = VK_IMAGE_LAYOUT_GENERAL;
12356 // perf warning for GENERAL layout on DS attachment
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012357 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
12358 "GENERAL layout for depth attachment may not give optimal performance.");
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060012359 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
12360 m_errorMonitor->VerifyFound();
12361 // error w/ non-ds opt or GENERAL layout for color attachment
12362 attach.layout = VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012363 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
12364 "Layout for depth attachment is VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL but can only be "
12365 "DEPTH_STENCIL_ATTACHMENT_OPTIMAL, DEPTH_STENCIL_READ_ONLY_OPTIMAL or GENERAL.");
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060012366 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
12367 m_errorMonitor->VerifyFound();
Tobin Ehlis1efce022016-05-11 10:40:34 -060012368 // For this error we need a valid renderpass so create default one
12369 attach.layout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL;
12370 attach.attachment = 0;
12371 attach_desc.format = VK_FORMAT_D24_UNORM_S8_UINT;
12372 attach_desc.samples = VK_SAMPLE_COUNT_1_BIT;
12373 attach_desc.storeOp = VK_ATTACHMENT_STORE_OP_STORE;
12374 attach_desc.stencilLoadOp = VK_ATTACHMENT_LOAD_OP_DONT_CARE;
12375 attach_desc.stencilStoreOp = VK_ATTACHMENT_STORE_OP_DONT_CARE;
12376 // Can't do a CLEAR load on READ_ONLY initialLayout
12377 attach_desc.loadOp = VK_ATTACHMENT_LOAD_OP_CLEAR;
12378 attach_desc.initialLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL;
12379 attach_desc.finalLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012380 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " with invalid first layout "
12381 "VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_"
12382 "ONLY_OPTIMAL");
Tobin Ehlis1efce022016-05-11 10:40:34 -060012383 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
12384 m_errorMonitor->VerifyFound();
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060012385
12386 vkDestroyImage(m_device->device(), src_image, NULL);
12387 vkDestroyImage(m_device->device(), dst_image, NULL);
12388}
Tobin Ehlisd8d89182016-07-18 20:13:11 -060012389
12390TEST_F(VkLayerTest, ValidRenderPassAttachmentLayoutWithLoadOp) {
12391 TEST_DESCRIPTION("Positive test where we create a renderpass with an "
12392 "attachment that uses LOAD_OP_CLEAR, the first subpass "
12393 "has a valid layout, and a second subpass then uses a "
12394 "valid *READ_ONLY* layout.");
12395 m_errorMonitor->ExpectSuccess();
12396 ASSERT_NO_FATAL_FAILURE(InitState());
12397
12398 VkAttachmentReference attach[2] = {};
12399 attach[0].attachment = 0;
12400 attach[0].layout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
12401 attach[1].attachment = 0;
12402 attach[1].layout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL;
12403 VkSubpassDescription subpasses[2] = {};
12404 // First subpass clears DS attach on load
12405 subpasses[0].pDepthStencilAttachment = &attach[0];
12406 // 2nd subpass reads in DS as input attachment
12407 subpasses[1].inputAttachmentCount = 1;
12408 subpasses[1].pInputAttachments = &attach[1];
12409 VkAttachmentDescription attach_desc = {};
12410 attach_desc.format = VK_FORMAT_D24_UNORM_S8_UINT;
12411 attach_desc.samples = VK_SAMPLE_COUNT_1_BIT;
12412 attach_desc.storeOp = VK_ATTACHMENT_STORE_OP_STORE;
12413 attach_desc.stencilStoreOp = VK_ATTACHMENT_STORE_OP_DONT_CARE;
12414 attach_desc.loadOp = VK_ATTACHMENT_LOAD_OP_CLEAR;
12415 attach_desc.stencilLoadOp = VK_ATTACHMENT_LOAD_OP_CLEAR;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012416 attach_desc.initialLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
Tobin Ehlisd8d89182016-07-18 20:13:11 -060012417 attach_desc.finalLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL;
12418 VkRenderPassCreateInfo rpci = {};
12419 rpci.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
12420 rpci.attachmentCount = 1;
12421 rpci.pAttachments = &attach_desc;
12422 rpci.subpassCount = 2;
12423 rpci.pSubpasses = subpasses;
12424
12425 // Now create RenderPass and verify no errors
12426 VkRenderPass rp;
12427 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
12428 m_errorMonitor->VerifyNotFound();
12429
12430 vkDestroyRenderPass(m_device->device(), rp, NULL);
12431}
Tobin Ehlis4af23302016-07-19 10:50:30 -060012432
Mark Mueller93b938f2016-08-18 10:27:40 -060012433TEST_F(VkLayerTest, SimultaneousUse) {
12434 TEST_DESCRIPTION("Use vkCmdExecuteCommands with invalid state "
12435 "in primary and secondary command buffers.");
12436
12437 ASSERT_NO_FATAL_FAILURE(InitState());
12438 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12439
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012440 const char *simultaneous_use_message1 = "w/o VK_COMMAND_BUFFER_USAGE_SIMULTANEOUS_USE_BIT set!";
12441 const char *simultaneous_use_message2 = "does not have VK_COMMAND_BUFFER_USAGE_SIMULTANEOUS_USE_BIT set and "
12442 "will cause primary command buffer";
Mark Mueller93b938f2016-08-18 10:27:40 -060012443
12444 VkCommandBufferAllocateInfo command_buffer_allocate_info = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012445 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
Mark Mueller93b938f2016-08-18 10:27:40 -060012446 command_buffer_allocate_info.commandPool = m_commandPool;
12447 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_SECONDARY;
12448 command_buffer_allocate_info.commandBufferCount = 1;
12449
12450 VkCommandBuffer secondary_command_buffer;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012451 ASSERT_VK_SUCCESS(vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, &secondary_command_buffer));
Mark Mueller93b938f2016-08-18 10:27:40 -060012452 VkCommandBufferBeginInfo command_buffer_begin_info = {};
12453 VkCommandBufferInheritanceInfo command_buffer_inheritance_info = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012454 command_buffer_inheritance_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_INHERITANCE_INFO;
Mark Mueller93b938f2016-08-18 10:27:40 -060012455 command_buffer_inheritance_info.renderPass = m_renderPass;
12456 command_buffer_inheritance_info.framebuffer = m_framebuffer;
12457 command_buffer_begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012458 command_buffer_begin_info.flags =
12459 VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT | VK_COMMAND_BUFFER_USAGE_RENDER_PASS_CONTINUE_BIT;
Mark Mueller93b938f2016-08-18 10:27:40 -060012460 command_buffer_begin_info.pInheritanceInfo = &command_buffer_inheritance_info;
12461
12462 vkBeginCommandBuffer(secondary_command_buffer, &command_buffer_begin_info);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012463 vkCmdBeginRenderPass(m_commandBuffer->handle(), &renderPassBeginInfo(), VK_SUBPASS_CONTENTS_SECONDARY_COMMAND_BUFFERS);
12464 vkCmdExecuteCommands(m_commandBuffer->handle(), 1, &secondary_command_buffer);
Mark Mueller4042b652016-09-05 22:52:21 -060012465 vkCmdEndRenderPass(m_commandBuffer->GetBufferHandle());
Mark Mueller93b938f2016-08-18 10:27:40 -060012466 vkEndCommandBuffer(secondary_command_buffer);
12467
Mark Mueller93b938f2016-08-18 10:27:40 -060012468 VkSubmitInfo submit_info = {};
12469 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
12470 submit_info.commandBufferCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012471 submit_info.pCommandBuffers = &m_commandBuffer->handle();
Mark Mueller4042b652016-09-05 22:52:21 -060012472 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
Mark Mueller93b938f2016-08-18 10:27:40 -060012473
Mark Mueller4042b652016-09-05 22:52:21 -060012474 vkBeginCommandBuffer(m_commandBuffer->handle(), &command_buffer_begin_info);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012475 vkCmdBeginRenderPass(m_commandBuffer->handle(), &renderPassBeginInfo(), VK_SUBPASS_CONTENTS_SECONDARY_COMMAND_BUFFERS);
12476 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, simultaneous_use_message1);
12477 vkCmdExecuteCommands(m_commandBuffer->handle(), 1, &secondary_command_buffer);
Mark Mueller93b938f2016-08-18 10:27:40 -060012478 m_errorMonitor->VerifyFound();
Mark Mueller4042b652016-09-05 22:52:21 -060012479 vkCmdEndRenderPass(m_commandBuffer->GetBufferHandle());
12480 vkEndCommandBuffer(m_commandBuffer->handle());
Mark Mueller93b938f2016-08-18 10:27:40 -060012481
12482 m_errorMonitor->SetDesiredFailureMsg(0, "");
Mark Mueller93b938f2016-08-18 10:27:40 -060012483 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
12484
Mark Mueller4042b652016-09-05 22:52:21 -060012485 command_buffer_begin_info.flags = VK_COMMAND_BUFFER_USAGE_SIMULTANEOUS_USE_BIT;
Mark Mueller93b938f2016-08-18 10:27:40 -060012486 vkBeginCommandBuffer(m_commandBuffer->handle(), &command_buffer_begin_info);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012487 vkCmdBeginRenderPass(m_commandBuffer->handle(), &renderPassBeginInfo(), VK_SUBPASS_CONTENTS_SECONDARY_COMMAND_BUFFERS);
Mark Mueller4042b652016-09-05 22:52:21 -060012488
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012489 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT, simultaneous_use_message2);
12490 vkCmdExecuteCommands(m_commandBuffer->handle(), 1, &secondary_command_buffer);
Mark Mueller93b938f2016-08-18 10:27:40 -060012491 m_errorMonitor->VerifyFound();
Mark Mueller4042b652016-09-05 22:52:21 -060012492 vkCmdEndRenderPass(m_commandBuffer->GetBufferHandle());
12493 vkEndCommandBuffer(m_commandBuffer->handle());
Mark Mueller93b938f2016-08-18 10:27:40 -060012494}
12495
Mark Mueller917f6bc2016-08-30 10:57:19 -060012496TEST_F(VkLayerTest, InUseDestroyedSignaled) {
12497 TEST_DESCRIPTION("Use vkCmdExecuteCommands with invalid state "
12498 "in primary and secondary command buffers. "
Mark Muellerc8d441e2016-08-23 17:36:00 -060012499 "Delete objects that are inuse. Call VkQueueSubmit "
12500 "with an event that has been deleted.");
Mark Mueller917f6bc2016-08-30 10:57:19 -060012501
12502 ASSERT_NO_FATAL_FAILURE(InitState());
12503 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12504
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012505 const char *submit_with_deleted_event_message = "Cannot submit cmd buffer using deleted event 0x";
12506 const char *cannot_delete_event_message = "Cannot delete event 0x";
12507 const char *cannot_delete_semaphore_message = "Cannot delete semaphore 0x";
12508 const char *cannot_destroy_fence_message = "Fence 0x";
Mark Mueller917f6bc2016-08-30 10:57:19 -060012509
12510 BeginCommandBuffer();
12511
12512 VkEvent event;
12513 VkEventCreateInfo event_create_info = {};
12514 event_create_info.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO;
12515 vkCreateEvent(m_device->device(), &event_create_info, nullptr, &event);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012516 vkCmdSetEvent(m_commandBuffer->handle(), event, VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT);
Mark Mueller917f6bc2016-08-30 10:57:19 -060012517
Mark Muellerc8d441e2016-08-23 17:36:00 -060012518 EndCommandBuffer();
12519 vkDestroyEvent(m_device->device(), event, nullptr);
12520
12521 VkSubmitInfo submit_info = {};
12522 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
12523 submit_info.commandBufferCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012524 submit_info.pCommandBuffers = &m_commandBuffer->handle();
12525 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, submit_with_deleted_event_message);
Mark Muellerc8d441e2016-08-23 17:36:00 -060012526 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
12527 m_errorMonitor->VerifyFound();
12528
12529 m_errorMonitor->SetDesiredFailureMsg(0, "");
12530 vkResetCommandBuffer(m_commandBuffer->handle(), 0);
12531
12532 vkCreateEvent(m_device->device(), &event_create_info, nullptr, &event);
12533
Mark Mueller917f6bc2016-08-30 10:57:19 -060012534 VkSemaphoreCreateInfo semaphore_create_info = {};
12535 semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
12536 VkSemaphore semaphore;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012537 ASSERT_VK_SUCCESS(vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr, &semaphore));
Mark Mueller917f6bc2016-08-30 10:57:19 -060012538 VkFenceCreateInfo fence_create_info = {};
12539 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
12540 VkFence fence;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012541 ASSERT_VK_SUCCESS(vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence));
Mark Mueller917f6bc2016-08-30 10:57:19 -060012542
12543 VkDescriptorPoolSize descriptor_pool_type_count = {};
Mark Mueller4042b652016-09-05 22:52:21 -060012544 descriptor_pool_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Mark Mueller917f6bc2016-08-30 10:57:19 -060012545 descriptor_pool_type_count.descriptorCount = 1;
12546
12547 VkDescriptorPoolCreateInfo descriptor_pool_create_info = {};
12548 descriptor_pool_create_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
12549 descriptor_pool_create_info.maxSets = 1;
12550 descriptor_pool_create_info.poolSizeCount = 1;
12551 descriptor_pool_create_info.pPoolSizes = &descriptor_pool_type_count;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012552 descriptor_pool_create_info.flags = VK_DESCRIPTOR_POOL_CREATE_FREE_DESCRIPTOR_SET_BIT;
Mark Mueller917f6bc2016-08-30 10:57:19 -060012553
12554 VkDescriptorPool descriptorset_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012555 ASSERT_VK_SUCCESS(vkCreateDescriptorPool(m_device->device(), &descriptor_pool_create_info, nullptr, &descriptorset_pool));
Mark Mueller917f6bc2016-08-30 10:57:19 -060012556
12557 VkDescriptorSetLayoutBinding descriptorset_layout_binding = {};
Mark Mueller4042b652016-09-05 22:52:21 -060012558 descriptorset_layout_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Mark Mueller917f6bc2016-08-30 10:57:19 -060012559 descriptorset_layout_binding.descriptorCount = 1;
12560 descriptorset_layout_binding.stageFlags = VK_SHADER_STAGE_ALL;
12561
12562 VkDescriptorSetLayoutCreateInfo descriptorset_layout_create_info = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012563 descriptorset_layout_create_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
Mark Mueller917f6bc2016-08-30 10:57:19 -060012564 descriptorset_layout_create_info.bindingCount = 1;
12565 descriptorset_layout_create_info.pBindings = &descriptorset_layout_binding;
12566
12567 VkDescriptorSetLayout descriptorset_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012568 ASSERT_VK_SUCCESS(
12569 vkCreateDescriptorSetLayout(m_device->device(), &descriptorset_layout_create_info, nullptr, &descriptorset_layout));
Mark Mueller917f6bc2016-08-30 10:57:19 -060012570
12571 VkDescriptorSet descriptorset;
12572 VkDescriptorSetAllocateInfo descriptorset_allocate_info = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012573 descriptorset_allocate_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Mark Mueller917f6bc2016-08-30 10:57:19 -060012574 descriptorset_allocate_info.descriptorSetCount = 1;
12575 descriptorset_allocate_info.descriptorPool = descriptorset_pool;
12576 descriptorset_allocate_info.pSetLayouts = &descriptorset_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012577 ASSERT_VK_SUCCESS(vkAllocateDescriptorSets(m_device->device(), &descriptorset_allocate_info, &descriptorset));
Mark Mueller917f6bc2016-08-30 10:57:19 -060012578
Mark Mueller4042b652016-09-05 22:52:21 -060012579 VkBufferTest buffer_test(m_device, VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT);
12580
12581 VkDescriptorBufferInfo buffer_info = {};
12582 buffer_info.buffer = buffer_test.GetBuffer();
12583 buffer_info.offset = 0;
12584 buffer_info.range = 1024;
12585
12586 VkWriteDescriptorSet write_descriptor_set = {};
12587 write_descriptor_set.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
12588 write_descriptor_set.dstSet = descriptorset;
12589 write_descriptor_set.descriptorCount = 1;
12590 write_descriptor_set.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
12591 write_descriptor_set.pBufferInfo = &buffer_info;
12592
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012593 vkUpdateDescriptorSets(m_device->device(), 1, &write_descriptor_set, 0, nullptr);
Mark Mueller4042b652016-09-05 22:52:21 -060012594
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012595 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
12596 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Mark Mueller917f6bc2016-08-30 10:57:19 -060012597
12598 VkPipelineObj pipe(m_device);
12599 pipe.AddColorAttachment();
12600 pipe.AddShader(&vs);
12601 pipe.AddShader(&fs);
12602
12603 VkPipelineLayoutCreateInfo pipeline_layout_create_info = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012604 pipeline_layout_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
Mark Mueller917f6bc2016-08-30 10:57:19 -060012605 pipeline_layout_create_info.setLayoutCount = 1;
12606 pipeline_layout_create_info.pSetLayouts = &descriptorset_layout;
12607
12608 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012609 ASSERT_VK_SUCCESS(vkCreatePipelineLayout(m_device->device(), &pipeline_layout_create_info, nullptr, &pipeline_layout));
Mark Mueller917f6bc2016-08-30 10:57:19 -060012610
12611 pipe.CreateVKPipeline(pipeline_layout, m_renderPass);
12612
Mark Muellerc8d441e2016-08-23 17:36:00 -060012613 BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012614 vkCmdSetEvent(m_commandBuffer->handle(), event, VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT);
Mark Muellerc8d441e2016-08-23 17:36:00 -060012615
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012616 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
12617 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
12618 &descriptorset, 0, NULL);
Mark Mueller917f6bc2016-08-30 10:57:19 -060012619
Mark Muellerc8d441e2016-08-23 17:36:00 -060012620 EndCommandBuffer();
Mark Mueller917f6bc2016-08-30 10:57:19 -060012621
Mark Mueller917f6bc2016-08-30 10:57:19 -060012622 submit_info.signalSemaphoreCount = 1;
12623 submit_info.pSignalSemaphores = &semaphore;
12624 vkQueueSubmit(m_device->m_queue, 1, &submit_info, fence);
Mark Muellerc8d441e2016-08-23 17:36:00 -060012625
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012626 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, cannot_delete_event_message);
Mark Mueller917f6bc2016-08-30 10:57:19 -060012627 vkDestroyEvent(m_device->device(), event, nullptr);
12628 m_errorMonitor->VerifyFound();
12629
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012630 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, cannot_delete_semaphore_message);
Mark Mueller917f6bc2016-08-30 10:57:19 -060012631 vkDestroySemaphore(m_device->device(), semaphore, nullptr);
12632 m_errorMonitor->VerifyFound();
12633
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012634 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, cannot_destroy_fence_message);
Mark Mueller917f6bc2016-08-30 10:57:19 -060012635 vkDestroyFence(m_device->device(), fence, nullptr);
12636 m_errorMonitor->VerifyFound();
12637
Tobin Ehlis122207b2016-09-01 08:50:06 -070012638 vkQueueWaitIdle(m_device->m_queue);
Mark Mueller917f6bc2016-08-30 10:57:19 -060012639 vkDestroySemaphore(m_device->device(), semaphore, nullptr);
12640 vkDestroyFence(m_device->device(), fence, nullptr);
12641 vkDestroyEvent(m_device->device(), event, nullptr);
12642 vkDestroyDescriptorPool(m_device->device(), descriptorset_pool, nullptr);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012643 vkDestroyDescriptorSetLayout(m_device->device(), descriptorset_layout, nullptr);
Mark Mueller917f6bc2016-08-30 10:57:19 -060012644 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, nullptr);
12645}
12646
Tobin Ehlis2adda372016-09-01 08:51:06 -070012647TEST_F(VkLayerTest, QueryPoolInUseDestroyedSignaled) {
12648 TEST_DESCRIPTION("Delete in-use query pool.");
12649
12650 ASSERT_NO_FATAL_FAILURE(InitState());
12651 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12652
12653 VkQueryPool query_pool;
12654 VkQueryPoolCreateInfo query_pool_ci{};
12655 query_pool_ci.sType = VK_STRUCTURE_TYPE_QUERY_POOL_CREATE_INFO;
12656 query_pool_ci.queryType = VK_QUERY_TYPE_TIMESTAMP;
12657 query_pool_ci.queryCount = 1;
12658 vkCreateQueryPool(m_device->device(), &query_pool_ci, nullptr, &query_pool);
12659 BeginCommandBuffer();
12660 // Reset query pool to create binding with cmd buffer
12661 vkCmdResetQueryPool(m_commandBuffer->handle(), query_pool, 0, 1);
12662
12663 EndCommandBuffer();
12664
12665 VkSubmitInfo submit_info = {};
12666 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
12667 submit_info.commandBufferCount = 1;
12668 submit_info.pCommandBuffers = &m_commandBuffer->handle();
12669 // Submit cmd buffer and then destroy query pool while in-flight
12670 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
12671
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012672 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Cannot delete query pool 0x");
Tobin Ehlis2adda372016-09-01 08:51:06 -070012673 vkDestroyQueryPool(m_device->handle(), query_pool, NULL);
12674 m_errorMonitor->VerifyFound();
12675
12676 vkQueueWaitIdle(m_device->m_queue);
12677 // Now that cmd buffer done we can safely destroy query_pool
12678 vkDestroyQueryPool(m_device->handle(), query_pool, NULL);
12679}
12680
Tobin Ehlisfafab2d2016-09-07 13:51:24 -060012681TEST_F(VkLayerTest, PipelineInUseDestroyedSignaled) {
12682 TEST_DESCRIPTION("Delete in-use pipeline.");
12683
12684 ASSERT_NO_FATAL_FAILURE(InitState());
12685 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12686
12687 // Empty pipeline layout used for binding PSO
12688 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
12689 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
12690 pipeline_layout_ci.setLayoutCount = 0;
12691 pipeline_layout_ci.pSetLayouts = NULL;
12692
12693 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012694 VkResult err = vkCreatePipelineLayout(m_device->handle(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlisfafab2d2016-09-07 13:51:24 -060012695 ASSERT_VK_SUCCESS(err);
12696
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012697 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Cannot delete pipeline 0x");
Tobin Ehlisfafab2d2016-09-07 13:51:24 -060012698 // Create PSO to be used for draw-time errors below
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012699 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
12700 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Tobin Ehlisfafab2d2016-09-07 13:51:24 -060012701 // Store pipeline handle so we can actually delete it before test finishes
12702 VkPipeline delete_this_pipeline;
12703 { // Scope pipeline so it will be auto-deleted
12704 VkPipelineObj pipe(m_device);
12705 pipe.AddShader(&vs);
12706 pipe.AddShader(&fs);
12707 pipe.AddColorAttachment();
12708 pipe.CreateVKPipeline(pipeline_layout, renderPass());
12709 delete_this_pipeline = pipe.handle();
12710
12711 BeginCommandBuffer();
12712 // Bind pipeline to cmd buffer
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012713 vkCmdBindPipeline(m_commandBuffer->handle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Tobin Ehlisfafab2d2016-09-07 13:51:24 -060012714
12715 EndCommandBuffer();
12716
12717 VkSubmitInfo submit_info = {};
12718 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
12719 submit_info.commandBufferCount = 1;
12720 submit_info.pCommandBuffers = &m_commandBuffer->handle();
12721 // Submit cmd buffer and then pipeline destroyed while in-flight
12722 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
12723 } // Pipeline deletion triggered here
12724 m_errorMonitor->VerifyFound();
12725 // Make sure queue finished and then actually delete pipeline
12726 vkQueueWaitIdle(m_device->m_queue);
12727 vkDestroyPipeline(m_device->handle(), delete_this_pipeline, nullptr);
12728 vkDestroyPipelineLayout(m_device->handle(), pipeline_layout, nullptr);
12729}
12730
Tobin Ehlis209532e2016-09-07 13:52:18 -060012731TEST_F(VkLayerTest, SamplerInUseDestroyedSignaled) {
12732 TEST_DESCRIPTION("Delete in-use sampler.");
12733
12734 ASSERT_NO_FATAL_FAILURE(InitState());
12735 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12736
12737 VkDescriptorPoolSize ds_type_count;
12738 ds_type_count.type = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
12739 ds_type_count.descriptorCount = 1;
12740
12741 VkDescriptorPoolCreateInfo ds_pool_ci = {};
12742 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
12743 ds_pool_ci.maxSets = 1;
12744 ds_pool_ci.poolSizeCount = 1;
12745 ds_pool_ci.pPoolSizes = &ds_type_count;
12746
12747 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012748 VkResult err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis209532e2016-09-07 13:52:18 -060012749 ASSERT_VK_SUCCESS(err);
12750
12751 VkSamplerCreateInfo sampler_ci = {};
12752 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
12753 sampler_ci.pNext = NULL;
12754 sampler_ci.magFilter = VK_FILTER_NEAREST;
12755 sampler_ci.minFilter = VK_FILTER_NEAREST;
12756 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
12757 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
12758 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
12759 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
12760 sampler_ci.mipLodBias = 1.0;
12761 sampler_ci.anisotropyEnable = VK_FALSE;
12762 sampler_ci.maxAnisotropy = 1;
12763 sampler_ci.compareEnable = VK_FALSE;
12764 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
12765 sampler_ci.minLod = 1.0;
12766 sampler_ci.maxLod = 1.0;
12767 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
12768 sampler_ci.unnormalizedCoordinates = VK_FALSE;
12769 VkSampler sampler;
12770
12771 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
12772 ASSERT_VK_SUCCESS(err);
12773
12774 VkDescriptorSetLayoutBinding layout_binding;
12775 layout_binding.binding = 0;
12776 layout_binding.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
12777 layout_binding.descriptorCount = 1;
12778 layout_binding.stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
12779 layout_binding.pImmutableSamplers = NULL;
12780
12781 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
12782 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
12783 ds_layout_ci.bindingCount = 1;
12784 ds_layout_ci.pBindings = &layout_binding;
12785 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012786 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis209532e2016-09-07 13:52:18 -060012787 ASSERT_VK_SUCCESS(err);
12788
12789 VkDescriptorSetAllocateInfo alloc_info = {};
12790 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
12791 alloc_info.descriptorSetCount = 1;
12792 alloc_info.descriptorPool = ds_pool;
12793 alloc_info.pSetLayouts = &ds_layout;
12794 VkDescriptorSet descriptor_set;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012795 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
Tobin Ehlis209532e2016-09-07 13:52:18 -060012796 ASSERT_VK_SUCCESS(err);
12797
12798 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
12799 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
12800 pipeline_layout_ci.pNext = NULL;
12801 pipeline_layout_ci.setLayoutCount = 1;
12802 pipeline_layout_ci.pSetLayouts = &ds_layout;
12803
12804 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012805 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis209532e2016-09-07 13:52:18 -060012806 ASSERT_VK_SUCCESS(err);
12807
12808 VkImageObj image(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012809 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 -060012810 ASSERT_TRUE(image.initialized());
12811
12812 VkImageView view;
12813 VkImageViewCreateInfo ivci = {};
12814 ivci.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
12815 ivci.image = image.handle();
12816 ivci.viewType = VK_IMAGE_VIEW_TYPE_2D;
12817 ivci.format = VK_FORMAT_R8G8B8A8_UNORM;
12818 ivci.subresourceRange.layerCount = 1;
12819 ivci.subresourceRange.baseMipLevel = 0;
12820 ivci.subresourceRange.levelCount = 1;
12821 ivci.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
12822
12823 err = vkCreateImageView(m_device->device(), &ivci, NULL, &view);
12824 ASSERT_VK_SUCCESS(err);
12825
12826 VkDescriptorImageInfo image_info{};
12827 image_info.imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
12828 image_info.imageView = view;
12829 image_info.sampler = sampler;
12830
12831 VkWriteDescriptorSet descriptor_write = {};
12832 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
12833 descriptor_write.dstSet = descriptor_set;
12834 descriptor_write.dstBinding = 0;
12835 descriptor_write.descriptorCount = 1;
12836 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
12837 descriptor_write.pImageInfo = &image_info;
12838
12839 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
12840
12841 // Create PSO to use the sampler
12842 char const *vsSource = "#version 450\n"
12843 "\n"
12844 "out gl_PerVertex { \n"
12845 " vec4 gl_Position;\n"
12846 "};\n"
12847 "void main(){\n"
12848 " gl_Position = vec4(1);\n"
12849 "}\n";
12850 char const *fsSource = "#version 450\n"
12851 "\n"
12852 "layout(set=0, binding=0) uniform sampler2D s;\n"
12853 "layout(location=0) out vec4 x;\n"
12854 "void main(){\n"
12855 " x = texture(s, vec2(1));\n"
12856 "}\n";
12857 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
12858 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
12859 VkPipelineObj pipe(m_device);
12860 pipe.AddShader(&vs);
12861 pipe.AddShader(&fs);
12862 pipe.AddColorAttachment();
12863 pipe.CreateVKPipeline(pipeline_layout, renderPass());
12864
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012865 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Cannot delete sampler 0x");
Tobin Ehlis209532e2016-09-07 13:52:18 -060012866
12867 BeginCommandBuffer();
12868 // Bind pipeline to cmd buffer
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012869 vkCmdBindPipeline(m_commandBuffer->handle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
12870 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
12871 &descriptor_set, 0, nullptr);
Tobin Ehlis209532e2016-09-07 13:52:18 -060012872 Draw(1, 0, 0, 0);
12873 EndCommandBuffer();
12874 // Submit cmd buffer then destroy sampler
12875 VkSubmitInfo submit_info = {};
12876 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
12877 submit_info.commandBufferCount = 1;
12878 submit_info.pCommandBuffers = &m_commandBuffer->handle();
12879 // Submit cmd buffer and then destroy sampler while in-flight
12880 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
12881
12882 vkDestroySampler(m_device->device(), sampler, nullptr);
12883 m_errorMonitor->VerifyFound();
12884 vkQueueWaitIdle(m_device->m_queue);
12885 // Now we can actually destroy sampler
12886 vkDestroySampler(m_device->device(), sampler, nullptr);
12887 vkDestroyImageView(m_device->device(), view, NULL);
12888 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
12889 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
12890 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
12891}
12892
Mark Mueller1cd9f412016-08-25 13:23:52 -060012893TEST_F(VkLayerTest, QueueForwardProgressFenceWait) {
Mark Mueller96a56d52016-08-24 10:28:05 -060012894 TEST_DESCRIPTION("Call VkQueueSubmit with a semaphore that is already "
Mark Mueller1cd9f412016-08-25 13:23:52 -060012895 "signaled but not waited on by the queue. Wait on a "
12896 "fence that has not yet been submitted to a queue.");
Mark Mueller96a56d52016-08-24 10:28:05 -060012897
12898 ASSERT_NO_FATAL_FAILURE(InitState());
12899 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12900
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012901 const char *queue_forward_progress_message = " that has already been signaled but not waited on by queue 0x";
12902 const char *invalid_fence_wait_message = " which has not been submitted on a Queue or during "
12903 "acquire next image.";
Mark Mueller96a56d52016-08-24 10:28:05 -060012904
12905 BeginCommandBuffer();
12906 EndCommandBuffer();
12907
12908 VkSemaphoreCreateInfo semaphore_create_info = {};
12909 semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
12910 VkSemaphore semaphore;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012911 ASSERT_VK_SUCCESS(vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr, &semaphore));
Mark Mueller96a56d52016-08-24 10:28:05 -060012912 VkSubmitInfo submit_info = {};
12913 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
12914 submit_info.commandBufferCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012915 submit_info.pCommandBuffers = &m_commandBuffer->handle();
Mark Mueller96a56d52016-08-24 10:28:05 -060012916 submit_info.signalSemaphoreCount = 1;
12917 submit_info.pSignalSemaphores = &semaphore;
12918 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
12919 m_errorMonitor->SetDesiredFailureMsg(0, "");
12920 vkResetCommandBuffer(m_commandBuffer->handle(), 0);
12921 BeginCommandBuffer();
12922 EndCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012923 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, queue_forward_progress_message);
Mark Mueller96a56d52016-08-24 10:28:05 -060012924 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
12925 m_errorMonitor->VerifyFound();
12926
Mark Mueller1cd9f412016-08-25 13:23:52 -060012927 VkFenceCreateInfo fence_create_info = {};
12928 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
12929 VkFence fence;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012930 ASSERT_VK_SUCCESS(vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence));
Mark Mueller1cd9f412016-08-25 13:23:52 -060012931
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012932 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT, invalid_fence_wait_message);
Mark Mueller1cd9f412016-08-25 13:23:52 -060012933 vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
12934 m_errorMonitor->VerifyFound();
12935
Mark Mueller4042b652016-09-05 22:52:21 -060012936 vkDeviceWaitIdle(m_device->device());
Mark Mueller1cd9f412016-08-25 13:23:52 -060012937 vkDestroyFence(m_device->device(), fence, nullptr);
Mark Mueller96a56d52016-08-24 10:28:05 -060012938 vkDestroySemaphore(m_device->device(), semaphore, nullptr);
12939}
12940
Tobin Ehlis4af23302016-07-19 10:50:30 -060012941TEST_F(VkLayerTest, FramebufferIncompatible) {
12942 TEST_DESCRIPTION("Bind a secondary command buffer with with a framebuffer "
12943 "that does not match the framebuffer for the active "
12944 "renderpass.");
12945 ASSERT_NO_FATAL_FAILURE(InitState());
12946 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12947
12948 // A renderpass with one color attachment.
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012949 VkAttachmentDescription attachment = {0,
12950 VK_FORMAT_B8G8R8A8_UNORM,
12951 VK_SAMPLE_COUNT_1_BIT,
12952 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
12953 VK_ATTACHMENT_STORE_OP_STORE,
12954 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
12955 VK_ATTACHMENT_STORE_OP_DONT_CARE,
12956 VK_IMAGE_LAYOUT_UNDEFINED,
12957 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL};
Tobin Ehlis4af23302016-07-19 10:50:30 -060012958
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012959 VkAttachmentReference att_ref = {0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL};
Tobin Ehlis4af23302016-07-19 10:50:30 -060012960
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012961 VkSubpassDescription subpass = {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 1, &att_ref, nullptr, nullptr, 0, nullptr};
Tobin Ehlis4af23302016-07-19 10:50:30 -060012962
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012963 VkRenderPassCreateInfo rpci = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 1, &attachment, 1, &subpass, 0, nullptr};
Tobin Ehlis4af23302016-07-19 10:50:30 -060012964
12965 VkRenderPass rp;
12966 VkResult err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
12967 ASSERT_VK_SUCCESS(err);
12968
12969 // A compatible framebuffer.
12970 VkImageObj image(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012971 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 -060012972 ASSERT_TRUE(image.initialized());
12973
12974 VkImageViewCreateInfo ivci = {
12975 VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO,
12976 nullptr,
12977 0,
12978 image.handle(),
12979 VK_IMAGE_VIEW_TYPE_2D,
12980 VK_FORMAT_B8G8R8A8_UNORM,
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012981 {VK_COMPONENT_SWIZZLE_IDENTITY, VK_COMPONENT_SWIZZLE_IDENTITY, VK_COMPONENT_SWIZZLE_IDENTITY,
12982 VK_COMPONENT_SWIZZLE_IDENTITY},
Tobin Ehlis4af23302016-07-19 10:50:30 -060012983 {VK_IMAGE_ASPECT_COLOR_BIT, 0, 1, 0, 1},
12984 };
12985 VkImageView view;
12986 err = vkCreateImageView(m_device->device(), &ivci, nullptr, &view);
12987 ASSERT_VK_SUCCESS(err);
12988
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012989 VkFramebufferCreateInfo fci = {VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr, 0, rp, 1, &view, 32, 32, 1};
Tobin Ehlis4af23302016-07-19 10:50:30 -060012990 VkFramebuffer fb;
12991 err = vkCreateFramebuffer(m_device->device(), &fci, nullptr, &fb);
12992 ASSERT_VK_SUCCESS(err);
12993
12994 VkCommandBufferAllocateInfo cbai = {};
12995 cbai.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
12996 cbai.commandPool = m_commandPool;
12997 cbai.level = VK_COMMAND_BUFFER_LEVEL_SECONDARY;
12998 cbai.commandBufferCount = 1;
12999
13000 VkCommandBuffer sec_cb;
13001 err = vkAllocateCommandBuffers(m_device->device(), &cbai, &sec_cb);
13002 ASSERT_VK_SUCCESS(err);
13003 VkCommandBufferBeginInfo cbbi = {};
13004 VkCommandBufferInheritanceInfo cbii = {};
13005 cbii.renderPass = renderPass();
13006 cbii.framebuffer = fb;
13007 cbbi.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
13008 cbbi.pNext = NULL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013009 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 -060013010 cbbi.pInheritanceInfo = &cbii;
13011 vkBeginCommandBuffer(sec_cb, &cbbi);
13012 vkEndCommandBuffer(sec_cb);
13013
Chris Forbes3400bc52016-09-13 18:10:34 +120013014 VkCommandBufferBeginInfo cbbi2 = {
13015 VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO, nullptr,
13016 0, nullptr
13017 };
13018 vkBeginCommandBuffer(m_commandBuffer->GetBufferHandle(), &cbbi2);
13019 vkCmdBeginRenderPass(m_commandBuffer->GetBufferHandle(), &m_renderPassBeginInfo, VK_SUBPASS_CONTENTS_SECONDARY_COMMAND_BUFFERS);
Tobin Ehlis4af23302016-07-19 10:50:30 -060013020
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013021 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
13022 " that is not the same as the primaryCB's current active framebuffer ");
Tobin Ehlis4af23302016-07-19 10:50:30 -060013023 vkCmdExecuteCommands(m_commandBuffer->GetBufferHandle(), 1, &sec_cb);
13024 m_errorMonitor->VerifyFound();
13025 // Cleanup
13026 vkDestroyImageView(m_device->device(), view, NULL);
13027 vkDestroyRenderPass(m_device->device(), rp, NULL);
13028 vkDestroyFramebuffer(m_device->device(), fb, NULL);
13029}
Tobin Ehlis52b504f2016-07-19 13:25:12 -060013030
13031TEST_F(VkLayerTest, ColorBlendLogicOpTests) {
13032 TEST_DESCRIPTION("If logicOp is available on the device, set it to an "
13033 "invalid value. If logicOp is not available, attempt to "
13034 "use it and verify that we see the correct error.");
13035 ASSERT_NO_FATAL_FAILURE(InitState());
13036 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13037
13038 auto features = m_device->phy().features();
13039 // Set the expected error depending on whether or not logicOp available
13040 if (VK_FALSE == features.logicOp) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013041 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "If logic operations feature not "
13042 "enabled, logicOpEnable must be "
13043 "VK_FALSE");
Tobin Ehlis52b504f2016-07-19 13:25:12 -060013044 } else {
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013045 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, ", logicOp must be a valid VkLogicOp value");
Tobin Ehlis52b504f2016-07-19 13:25:12 -060013046 }
13047 // Create a pipeline using logicOp
13048 VkResult err;
13049
13050 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
13051 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
13052
13053 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013054 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis52b504f2016-07-19 13:25:12 -060013055 ASSERT_VK_SUCCESS(err);
13056
13057 VkPipelineViewportStateCreateInfo vp_state_ci = {};
13058 vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
13059 vp_state_ci.viewportCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013060 VkViewport vp = {}; // Just need dummy vp to point to
Tobin Ehlis52b504f2016-07-19 13:25:12 -060013061 vp_state_ci.pViewports = &vp;
13062 vp_state_ci.scissorCount = 1;
13063 VkRect2D scissors = {}; // Dummy scissors to point to
13064 vp_state_ci.pScissors = &scissors;
13065 // No dynamic state
13066 VkPipelineDynamicStateCreateInfo dyn_state_ci = {};
13067 dyn_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_DYNAMIC_STATE_CREATE_INFO;
13068
13069 VkPipelineShaderStageCreateInfo shaderStages[2];
13070 memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo));
13071
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013072 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
13073 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Tobin Ehlis52b504f2016-07-19 13:25:12 -060013074 shaderStages[0] = vs.GetStageCreateInfo();
13075 shaderStages[1] = fs.GetStageCreateInfo();
13076
13077 VkPipelineVertexInputStateCreateInfo vi_ci = {};
13078 vi_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
13079
13080 VkPipelineInputAssemblyStateCreateInfo ia_ci = {};
13081 ia_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
13082 ia_ci.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP;
13083
13084 VkPipelineRasterizationStateCreateInfo rs_ci = {};
13085 rs_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
13086
13087 VkPipelineColorBlendAttachmentState att = {};
13088 att.blendEnable = VK_FALSE;
13089 att.colorWriteMask = 0xf;
13090
13091 VkPipelineColorBlendStateCreateInfo cb_ci = {};
13092 cb_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO;
13093 // Enable logicOp & set logicOp to value 1 beyond allowed entries
13094 cb_ci.logicOpEnable = VK_TRUE;
13095 cb_ci.logicOp = VK_LOGIC_OP_RANGE_SIZE; // This should cause an error
13096 cb_ci.attachmentCount = 1;
13097 cb_ci.pAttachments = &att;
13098
13099 VkGraphicsPipelineCreateInfo gp_ci = {};
13100 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
13101 gp_ci.stageCount = 2;
13102 gp_ci.pStages = shaderStages;
13103 gp_ci.pVertexInputState = &vi_ci;
13104 gp_ci.pInputAssemblyState = &ia_ci;
13105 gp_ci.pViewportState = &vp_state_ci;
13106 gp_ci.pRasterizationState = &rs_ci;
13107 gp_ci.pColorBlendState = &cb_ci;
13108 gp_ci.pDynamicState = &dyn_state_ci;
13109 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
13110 gp_ci.layout = pipeline_layout;
13111 gp_ci.renderPass = renderPass();
13112
13113 VkPipelineCacheCreateInfo pc_ci = {};
13114 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
13115
13116 VkPipeline pipeline;
13117 VkPipelineCache pipelineCache;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013118 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Tobin Ehlis52b504f2016-07-19 13:25:12 -060013119 ASSERT_VK_SUCCESS(err);
13120
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013121 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Tobin Ehlis52b504f2016-07-19 13:25:12 -060013122 m_errorMonitor->VerifyFound();
13123 if (VK_SUCCESS == err) {
13124 vkDestroyPipeline(m_device->device(), pipeline, NULL);
13125 }
13126 m_errorMonitor->VerifyFound();
13127 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
13128 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
13129}
Mark Lobodzinski209b5292015-09-17 09:44:05 -060013130#endif // DRAW_STATE_TESTS
13131
Tobin Ehlis0788f522015-05-26 16:11:58 -060013132#if THREADING_TESTS
Mike Stroyanaccf7692015-05-12 16:00:45 -060013133#if GTEST_IS_THREADSAFE
13134struct thread_data_struct {
Chia-I Wu3432a0c2015-10-27 18:04:07 +080013135 VkCommandBuffer commandBuffer;
Mike Stroyanaccf7692015-05-12 16:00:45 -060013136 VkEvent event;
13137 bool bailout;
13138};
13139
Karl Schultz6addd812016-02-02 17:17:23 -070013140extern "C" void *AddToCommandBuffer(void *arg) {
13141 struct thread_data_struct *data = (struct thread_data_struct *)arg;
Mike Stroyanaccf7692015-05-12 16:00:45 -060013142
Mike Stroyana6d14942016-07-13 15:10:05 -060013143 for (int i = 0; i < 80000; i++) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013144 vkCmdSetEvent(data->commandBuffer, data->event, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT);
Mike Stroyanaccf7692015-05-12 16:00:45 -060013145 if (data->bailout) {
13146 break;
13147 }
13148 }
13149 return NULL;
13150}
13151
Karl Schultz6addd812016-02-02 17:17:23 -070013152TEST_F(VkLayerTest, ThreadCommandBufferCollision) {
Mike Stroyan4268d1f2015-07-13 14:45:35 -060013153 test_platform_thread thread;
Mike Stroyanaccf7692015-05-12 16:00:45 -060013154
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013155 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "THREADING ERROR");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060013156
Mike Stroyanaccf7692015-05-12 16:00:45 -060013157 ASSERT_NO_FATAL_FAILURE(InitState());
13158 ASSERT_NO_FATAL_FAILURE(InitViewport());
13159 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13160
Chia-I Wu3432a0c2015-10-27 18:04:07 +080013161 // Calls AllocateCommandBuffers
13162 VkCommandBufferObj commandBuffer(m_device, m_commandPool);
Mark Lobodzinski5495d132015-09-30 16:19:16 -060013163
13164 // Avoid creating RenderPass
Chia-I Wu3432a0c2015-10-27 18:04:07 +080013165 commandBuffer.BeginCommandBuffer();
Mike Stroyanaccf7692015-05-12 16:00:45 -060013166
13167 VkEventCreateInfo event_info;
13168 VkEvent event;
Mike Stroyanaccf7692015-05-12 16:00:45 -060013169 VkResult err;
13170
13171 memset(&event_info, 0, sizeof(event_info));
13172 event_info.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO;
13173
Chia-I Wuf7458c52015-10-26 21:10:41 +080013174 err = vkCreateEvent(device(), &event_info, NULL, &event);
Mike Stroyanaccf7692015-05-12 16:00:45 -060013175 ASSERT_VK_SUCCESS(err);
13176
Mike Stroyanaccf7692015-05-12 16:00:45 -060013177 err = vkResetEvent(device(), event);
13178 ASSERT_VK_SUCCESS(err);
13179
13180 struct thread_data_struct data;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080013181 data.commandBuffer = commandBuffer.GetBufferHandle();
Mike Stroyanaccf7692015-05-12 16:00:45 -060013182 data.event = event;
13183 data.bailout = false;
13184 m_errorMonitor->SetBailout(&data.bailout);
Mike Stroyana6d14942016-07-13 15:10:05 -060013185
13186 // First do some correct operations using multiple threads.
13187 // Add many entries to command buffer from another thread.
13188 test_platform_thread_create(&thread, AddToCommandBuffer, (void *)&data);
13189 // Make non-conflicting calls from this thread at the same time.
13190 for (int i = 0; i < 80000; i++) {
Mike Stroyand6343902016-07-14 08:56:16 -060013191 uint32_t count;
13192 vkEnumeratePhysicalDevices(instance(), &count, NULL);
Mike Stroyana6d14942016-07-13 15:10:05 -060013193 }
13194 test_platform_thread_join(thread, NULL);
13195
13196 // Then do some incorrect operations using multiple threads.
Mike Stroyanaccf7692015-05-12 16:00:45 -060013197 // Add many entries to command buffer from another thread.
Mike Stroyan4268d1f2015-07-13 14:45:35 -060013198 test_platform_thread_create(&thread, AddToCommandBuffer, (void *)&data);
Mike Stroyanaccf7692015-05-12 16:00:45 -060013199 // Add many entries to command buffer from this thread at the same time.
13200 AddToCommandBuffer(&data);
Mark Lobodzinski5495d132015-09-30 16:19:16 -060013201
Mike Stroyan4268d1f2015-07-13 14:45:35 -060013202 test_platform_thread_join(thread, NULL);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080013203 commandBuffer.EndCommandBuffer();
Mike Stroyanaccf7692015-05-12 16:00:45 -060013204
Mike Stroyan10b8cb72016-01-22 15:22:03 -070013205 m_errorMonitor->SetBailout(NULL);
13206
Chris Forbes8f36a8a2016-04-07 13:21:07 +120013207 m_errorMonitor->VerifyFound();
Mike Stroyanaccf7692015-05-12 16:00:45 -060013208
Chia-I Wuf7458c52015-10-26 21:10:41 +080013209 vkDestroyEvent(device(), event, NULL);
Mike Stroyanaccf7692015-05-12 16:00:45 -060013210}
Mark Lobodzinski209b5292015-09-17 09:44:05 -060013211#endif // GTEST_IS_THREADSAFE
13212#endif // THREADING_TESTS
13213
Chris Forbes9f7ff632015-05-25 11:13:08 +120013214#if SHADER_CHECKER_TESTS
Karl Schultz6addd812016-02-02 17:17:23 -070013215TEST_F(VkLayerTest, InvalidSPIRVCodeSize) {
Chris Forbes1cc79542016-07-20 11:13:44 +120013216 TEST_DESCRIPTION("Test that an error is produced for a spirv module "
13217 "with an impossible code size");
13218
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013219 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Invalid SPIR-V header");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060013220
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060013221 ASSERT_NO_FATAL_FAILURE(InitState());
13222 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13223
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060013224 VkShaderModule module;
13225 VkShaderModuleCreateInfo moduleCreateInfo;
13226 struct icd_spv_header spv;
13227
13228 spv.magic = ICD_SPV_MAGIC;
13229 spv.version = ICD_SPV_VERSION;
13230 spv.gen_magic = 0;
13231
13232 moduleCreateInfo.sType = VK_STRUCTURE_TYPE_SHADER_MODULE_CREATE_INFO;
13233 moduleCreateInfo.pNext = NULL;
Karl Schultz6addd812016-02-02 17:17:23 -070013234 moduleCreateInfo.pCode = (const uint32_t *)&spv;
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060013235 moduleCreateInfo.codeSize = 4;
13236 moduleCreateInfo.flags = 0;
Chia-I Wuf7458c52015-10-26 21:10:41 +080013237 vkCreateShaderModule(m_device->device(), &moduleCreateInfo, NULL, &module);
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060013238
Chris Forbes8f36a8a2016-04-07 13:21:07 +120013239 m_errorMonitor->VerifyFound();
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060013240}
13241
Karl Schultz6addd812016-02-02 17:17:23 -070013242TEST_F(VkLayerTest, InvalidSPIRVMagic) {
Chris Forbes1cc79542016-07-20 11:13:44 +120013243 TEST_DESCRIPTION("Test that an error is produced for a spirv module "
13244 "with a bad magic number");
13245
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013246 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Invalid SPIR-V magic number");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060013247
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060013248 ASSERT_NO_FATAL_FAILURE(InitState());
13249 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13250
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060013251 VkShaderModule module;
13252 VkShaderModuleCreateInfo moduleCreateInfo;
13253 struct icd_spv_header spv;
13254
13255 spv.magic = ~ICD_SPV_MAGIC;
13256 spv.version = ICD_SPV_VERSION;
13257 spv.gen_magic = 0;
13258
13259 moduleCreateInfo.sType = VK_STRUCTURE_TYPE_SHADER_MODULE_CREATE_INFO;
13260 moduleCreateInfo.pNext = NULL;
Karl Schultz6addd812016-02-02 17:17:23 -070013261 moduleCreateInfo.pCode = (const uint32_t *)&spv;
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060013262 moduleCreateInfo.codeSize = sizeof(spv) + 10;
13263 moduleCreateInfo.flags = 0;
Chia-I Wuf7458c52015-10-26 21:10:41 +080013264 vkCreateShaderModule(m_device->device(), &moduleCreateInfo, NULL, &module);
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060013265
Chris Forbes8f36a8a2016-04-07 13:21:07 +120013266 m_errorMonitor->VerifyFound();
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060013267}
13268
Chris Forbesb4afd0f2016-04-04 10:48:35 +120013269#if 0
13270// Not currently covered by SPIRV-Tools validator
Karl Schultz6addd812016-02-02 17:17:23 -070013271TEST_F(VkLayerTest, InvalidSPIRVVersion) {
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -070013272 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Chris Forbesb4afd0f2016-04-04 10:48:35 +120013273 "Invalid SPIR-V header");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060013274
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060013275 ASSERT_NO_FATAL_FAILURE(InitState());
13276 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13277
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060013278 VkShaderModule module;
13279 VkShaderModuleCreateInfo moduleCreateInfo;
13280 struct icd_spv_header spv;
13281
13282 spv.magic = ICD_SPV_MAGIC;
13283 spv.version = ~ICD_SPV_VERSION;
13284 spv.gen_magic = 0;
13285
13286 moduleCreateInfo.sType = VK_STRUCTURE_TYPE_SHADER_MODULE_CREATE_INFO;
13287 moduleCreateInfo.pNext = NULL;
13288
Karl Schultz6addd812016-02-02 17:17:23 -070013289 moduleCreateInfo.pCode = (const uint32_t *)&spv;
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060013290 moduleCreateInfo.codeSize = sizeof(spv) + 10;
13291 moduleCreateInfo.flags = 0;
Chia-I Wuf7458c52015-10-26 21:10:41 +080013292 vkCreateShaderModule(m_device->device(), &moduleCreateInfo, NULL, &module);
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060013293
Chris Forbes8f36a8a2016-04-07 13:21:07 +120013294 m_errorMonitor->VerifyFound();
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060013295}
Chris Forbesb4afd0f2016-04-04 10:48:35 +120013296#endif
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060013297
Karl Schultz6addd812016-02-02 17:17:23 -070013298TEST_F(VkLayerTest, CreatePipelineVertexOutputNotConsumed) {
Chris Forbes1cc79542016-07-20 11:13:44 +120013299 TEST_DESCRIPTION("Test that a warning is produced for a vertex output that "
13300 "is not consumed by the fragment stage");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013301 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT, "not consumed by fragment shader");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060013302
Chris Forbes9f7ff632015-05-25 11:13:08 +120013303 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -060013304 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbes9f7ff632015-05-25 11:13:08 +120013305
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013306 char const *vsSource = "#version 450\n"
13307 "\n"
13308 "layout(location=0) out float x;\n"
13309 "out gl_PerVertex {\n"
13310 " vec4 gl_Position;\n"
13311 "};\n"
13312 "void main(){\n"
13313 " gl_Position = vec4(1);\n"
13314 " x = 0;\n"
13315 "}\n";
13316 char const *fsSource = "#version 450\n"
13317 "\n"
13318 "layout(location=0) out vec4 color;\n"
13319 "void main(){\n"
13320 " color = vec4(1);\n"
13321 "}\n";
Chris Forbes9f7ff632015-05-25 11:13:08 +120013322
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060013323 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13324 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbes9f7ff632015-05-25 11:13:08 +120013325
13326 VkPipelineObj pipe(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +080013327 pipe.AddColorAttachment();
Chris Forbes9f7ff632015-05-25 11:13:08 +120013328 pipe.AddShader(&vs);
13329 pipe.AddShader(&fs);
13330
Chris Forbes9f7ff632015-05-25 11:13:08 +120013331 VkDescriptorSetObj descriptorSet(m_device);
13332 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080013333 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbes9f7ff632015-05-25 11:13:08 +120013334
Tony Barbour5781e8f2015-08-04 16:23:11 -060013335 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbes9f7ff632015-05-25 11:13:08 +120013336
Chris Forbes8f36a8a2016-04-07 13:21:07 +120013337 m_errorMonitor->VerifyFound();
Chris Forbes9f7ff632015-05-25 11:13:08 +120013338}
Chris Forbes9f7ff632015-05-25 11:13:08 +120013339
Karl Schultz6addd812016-02-02 17:17:23 -070013340TEST_F(VkLayerTest, CreatePipelineFragmentInputNotProvided) {
Chris Forbes1cc79542016-07-20 11:13:44 +120013341 TEST_DESCRIPTION("Test that an error is produced for a fragment shader input "
13342 "which is not present in the outputs of the previous stage");
13343
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013344 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "not written by vertex shader");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060013345
Chris Forbes59cb88d2015-05-25 11:13:13 +120013346 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -060013347 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbes59cb88d2015-05-25 11:13:13 +120013348
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013349 char const *vsSource = "#version 450\n"
13350 "\n"
13351 "out gl_PerVertex {\n"
13352 " vec4 gl_Position;\n"
13353 "};\n"
13354 "void main(){\n"
13355 " gl_Position = vec4(1);\n"
13356 "}\n";
13357 char const *fsSource = "#version 450\n"
13358 "\n"
13359 "layout(location=0) in float x;\n"
13360 "layout(location=0) out vec4 color;\n"
13361 "void main(){\n"
13362 " color = vec4(x);\n"
13363 "}\n";
Chris Forbes59cb88d2015-05-25 11:13:13 +120013364
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060013365 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13366 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbes59cb88d2015-05-25 11:13:13 +120013367
13368 VkPipelineObj pipe(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +080013369 pipe.AddColorAttachment();
Chris Forbes59cb88d2015-05-25 11:13:13 +120013370 pipe.AddShader(&vs);
13371 pipe.AddShader(&fs);
13372
Chris Forbes59cb88d2015-05-25 11:13:13 +120013373 VkDescriptorSetObj descriptorSet(m_device);
13374 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080013375 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbes59cb88d2015-05-25 11:13:13 +120013376
Tony Barbour5781e8f2015-08-04 16:23:11 -060013377 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbes59cb88d2015-05-25 11:13:13 +120013378
Chris Forbes8f36a8a2016-04-07 13:21:07 +120013379 m_errorMonitor->VerifyFound();
Chris Forbes59cb88d2015-05-25 11:13:13 +120013380}
13381
Karl Schultz6addd812016-02-02 17:17:23 -070013382TEST_F(VkLayerTest, CreatePipelineFragmentInputNotProvidedInBlock) {
Chris Forbes1cc79542016-07-20 11:13:44 +120013383 TEST_DESCRIPTION("Test that an error is produced for a fragment shader input "
13384 "within an interace block, which is not present in the outputs "
13385 "of the previous stage.");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013386 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "not written by vertex shader");
Chris Forbesa3e85f62016-01-15 14:53:11 +130013387
13388 ASSERT_NO_FATAL_FAILURE(InitState());
13389 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13390
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013391 char const *vsSource = "#version 450\n"
13392 "\n"
13393 "out gl_PerVertex {\n"
13394 " vec4 gl_Position;\n"
13395 "};\n"
13396 "void main(){\n"
13397 " gl_Position = vec4(1);\n"
13398 "}\n";
13399 char const *fsSource = "#version 450\n"
13400 "\n"
13401 "in block { layout(location=0) float x; } ins;\n"
13402 "layout(location=0) out vec4 color;\n"
13403 "void main(){\n"
13404 " color = vec4(ins.x);\n"
13405 "}\n";
Chris Forbesa3e85f62016-01-15 14:53:11 +130013406
13407 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13408 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
13409
13410 VkPipelineObj pipe(m_device);
13411 pipe.AddColorAttachment();
13412 pipe.AddShader(&vs);
13413 pipe.AddShader(&fs);
13414
13415 VkDescriptorSetObj descriptorSet(m_device);
13416 descriptorSet.AppendDummy();
13417 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
13418
13419 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
13420
Chris Forbes8f36a8a2016-04-07 13:21:07 +120013421 m_errorMonitor->VerifyFound();
Chris Forbesa3e85f62016-01-15 14:53:11 +130013422}
13423
Karl Schultz6addd812016-02-02 17:17:23 -070013424TEST_F(VkLayerTest, CreatePipelineVsFsTypeMismatchArraySize) {
Chris Forbes1cc79542016-07-20 11:13:44 +120013425 TEST_DESCRIPTION("Test that an error is produced for mismatched array sizes "
13426 "across the VS->FS interface");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013427 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Type mismatch on location 0.0: 'ptr to "
13428 "output arr[2] of float32' vs 'ptr to "
13429 "input arr[3] of float32'");
Chris Forbes0036fd12016-01-26 14:19:49 +130013430
13431 ASSERT_NO_FATAL_FAILURE(InitState());
13432 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13433
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013434 char const *vsSource = "#version 450\n"
13435 "\n"
13436 "layout(location=0) out float x[2];\n"
13437 "out gl_PerVertex {\n"
13438 " vec4 gl_Position;\n"
13439 "};\n"
13440 "void main(){\n"
13441 " x[0] = 0; x[1] = 0;\n"
13442 " gl_Position = vec4(1);\n"
13443 "}\n";
13444 char const *fsSource = "#version 450\n"
13445 "\n"
13446 "layout(location=0) in float x[3];\n"
13447 "layout(location=0) out vec4 color;\n"
13448 "void main(){\n"
13449 " color = vec4(x[0] + x[1] + x[2]);\n"
13450 "}\n";
Chris Forbes0036fd12016-01-26 14:19:49 +130013451
13452 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13453 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
13454
13455 VkPipelineObj pipe(m_device);
13456 pipe.AddColorAttachment();
13457 pipe.AddShader(&vs);
13458 pipe.AddShader(&fs);
13459
13460 VkDescriptorSetObj descriptorSet(m_device);
13461 descriptorSet.AppendDummy();
13462 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
13463
13464 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
13465
Chris Forbes8f36a8a2016-04-07 13:21:07 +120013466 m_errorMonitor->VerifyFound();
Chris Forbes0036fd12016-01-26 14:19:49 +130013467}
13468
Karl Schultz6addd812016-02-02 17:17:23 -070013469TEST_F(VkLayerTest, CreatePipelineVsFsTypeMismatch) {
Chris Forbes1cc79542016-07-20 11:13:44 +120013470 TEST_DESCRIPTION("Test that an error is produced for mismatched types across "
13471 "the VS->FS interface");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013472 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Type mismatch on location 0");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060013473
Chris Forbesb56af562015-05-25 11:13:17 +120013474 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -060013475 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbesb56af562015-05-25 11:13:17 +120013476
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013477 char const *vsSource = "#version 450\n"
13478 "\n"
13479 "layout(location=0) out int x;\n"
13480 "out gl_PerVertex {\n"
13481 " vec4 gl_Position;\n"
13482 "};\n"
13483 "void main(){\n"
13484 " x = 0;\n"
13485 " gl_Position = vec4(1);\n"
13486 "}\n";
13487 char const *fsSource = "#version 450\n"
13488 "\n"
13489 "layout(location=0) in float x;\n" /* VS writes int */
13490 "layout(location=0) out vec4 color;\n"
13491 "void main(){\n"
13492 " color = vec4(x);\n"
13493 "}\n";
Chris Forbesb56af562015-05-25 11:13:17 +120013494
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060013495 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13496 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbesb56af562015-05-25 11:13:17 +120013497
13498 VkPipelineObj pipe(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +080013499 pipe.AddColorAttachment();
Chris Forbesb56af562015-05-25 11:13:17 +120013500 pipe.AddShader(&vs);
13501 pipe.AddShader(&fs);
13502
Chris Forbesb56af562015-05-25 11:13:17 +120013503 VkDescriptorSetObj descriptorSet(m_device);
13504 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080013505 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbesb56af562015-05-25 11:13:17 +120013506
Tony Barbour5781e8f2015-08-04 16:23:11 -060013507 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbesb56af562015-05-25 11:13:17 +120013508
Chris Forbes8f36a8a2016-04-07 13:21:07 +120013509 m_errorMonitor->VerifyFound();
Chris Forbesb56af562015-05-25 11:13:17 +120013510}
13511
Karl Schultz6addd812016-02-02 17:17:23 -070013512TEST_F(VkLayerTest, CreatePipelineVsFsTypeMismatchInBlock) {
Chris Forbes1cc79542016-07-20 11:13:44 +120013513 TEST_DESCRIPTION("Test that an error is produced for mismatched types across "
13514 "the VS->FS interface, when the variable is contained within "
13515 "an interface block");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013516 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Type mismatch on location 0");
Chris Forbesa3e85f62016-01-15 14:53:11 +130013517
13518 ASSERT_NO_FATAL_FAILURE(InitState());
13519 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13520
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013521 char const *vsSource = "#version 450\n"
13522 "\n"
13523 "out block { layout(location=0) int x; } outs;\n"
13524 "out gl_PerVertex {\n"
13525 " vec4 gl_Position;\n"
13526 "};\n"
13527 "void main(){\n"
13528 " outs.x = 0;\n"
13529 " gl_Position = vec4(1);\n"
13530 "}\n";
13531 char const *fsSource = "#version 450\n"
13532 "\n"
13533 "in block { layout(location=0) float x; } ins;\n" /* VS writes int */
13534 "layout(location=0) out vec4 color;\n"
13535 "void main(){\n"
13536 " color = vec4(ins.x);\n"
13537 "}\n";
Chris Forbesa3e85f62016-01-15 14:53:11 +130013538
13539 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13540 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
13541
13542 VkPipelineObj pipe(m_device);
13543 pipe.AddColorAttachment();
13544 pipe.AddShader(&vs);
13545 pipe.AddShader(&fs);
13546
13547 VkDescriptorSetObj descriptorSet(m_device);
13548 descriptorSet.AppendDummy();
13549 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
13550
13551 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
13552
Chris Forbes8f36a8a2016-04-07 13:21:07 +120013553 m_errorMonitor->VerifyFound();
Chris Forbese9928822016-02-17 14:44:52 +130013554}
13555
13556TEST_F(VkLayerTest, CreatePipelineVsFsMismatchByLocation) {
Chris Forbes1cc79542016-07-20 11:13:44 +120013557 TEST_DESCRIPTION("Test that an error is produced for location mismatches across "
13558 "the VS->FS interface; This should manifest as a not-written/not-consumed "
13559 "pair, but flushes out broken walking of the interfaces");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013560 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 +130013561
13562 ASSERT_NO_FATAL_FAILURE(InitState());
13563 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13564
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013565 char const *vsSource = "#version 450\n"
13566 "\n"
13567 "out block { layout(location=1) float x; } outs;\n"
13568 "out gl_PerVertex {\n"
13569 " vec4 gl_Position;\n"
13570 "};\n"
13571 "void main(){\n"
13572 " outs.x = 0;\n"
13573 " gl_Position = vec4(1);\n"
13574 "}\n";
13575 char const *fsSource = "#version 450\n"
13576 "\n"
13577 "in block { layout(location=0) float x; } ins;\n"
13578 "layout(location=0) out vec4 color;\n"
13579 "void main(){\n"
13580 " color = vec4(ins.x);\n"
13581 "}\n";
Chris Forbese9928822016-02-17 14:44:52 +130013582
13583 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13584 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
13585
13586 VkPipelineObj pipe(m_device);
13587 pipe.AddColorAttachment();
13588 pipe.AddShader(&vs);
13589 pipe.AddShader(&fs);
13590
13591 VkDescriptorSetObj descriptorSet(m_device);
13592 descriptorSet.AppendDummy();
13593 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
13594
13595 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
13596
Chris Forbes8f36a8a2016-04-07 13:21:07 +120013597 m_errorMonitor->VerifyFound();
Chris Forbese9928822016-02-17 14:44:52 +130013598}
13599
13600TEST_F(VkLayerTest, CreatePipelineVsFsMismatchByComponent) {
Chris Forbes1cc79542016-07-20 11:13:44 +120013601 TEST_DESCRIPTION("Test that an error is produced for component mismatches across the "
13602 "VS->FS interface. It's not enough to have the same set of locations in "
13603 "use; matching is defined in terms of spirv variables.");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013604 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 +130013605
13606 ASSERT_NO_FATAL_FAILURE(InitState());
13607 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13608
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013609 char const *vsSource = "#version 450\n"
13610 "\n"
13611 "out block { layout(location=0, component=0) float x; } outs;\n"
13612 "out gl_PerVertex {\n"
13613 " vec4 gl_Position;\n"
13614 "};\n"
13615 "void main(){\n"
13616 " outs.x = 0;\n"
13617 " gl_Position = vec4(1);\n"
13618 "}\n";
13619 char const *fsSource = "#version 450\n"
13620 "\n"
13621 "in block { layout(location=0, component=1) float x; } ins;\n"
13622 "layout(location=0) out vec4 color;\n"
13623 "void main(){\n"
13624 " color = vec4(ins.x);\n"
13625 "}\n";
Chris Forbese9928822016-02-17 14:44:52 +130013626
13627 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13628 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
13629
13630 VkPipelineObj pipe(m_device);
13631 pipe.AddColorAttachment();
13632 pipe.AddShader(&vs);
13633 pipe.AddShader(&fs);
13634
13635 VkDescriptorSetObj descriptorSet(m_device);
13636 descriptorSet.AppendDummy();
13637 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
13638
13639 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
13640
Chris Forbes8f36a8a2016-04-07 13:21:07 +120013641 m_errorMonitor->VerifyFound();
Chris Forbesa3e85f62016-01-15 14:53:11 +130013642}
13643
Karl Schultz6addd812016-02-02 17:17:23 -070013644TEST_F(VkLayerTest, CreatePipelineAttribNotConsumed) {
Chris Forbes1cc79542016-07-20 11:13:44 +120013645 TEST_DESCRIPTION("Test that a warning is produced for a vertex attribute which is "
13646 "not consumed by the vertex shader");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013647 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT, "location 0 not consumed by VS");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060013648
Chris Forbesde136e02015-05-25 11:13:28 +120013649 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -060013650 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbesde136e02015-05-25 11:13:28 +120013651
13652 VkVertexInputBindingDescription input_binding;
13653 memset(&input_binding, 0, sizeof(input_binding));
13654
13655 VkVertexInputAttributeDescription input_attrib;
13656 memset(&input_attrib, 0, sizeof(input_attrib));
13657 input_attrib.format = VK_FORMAT_R32_SFLOAT;
13658
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013659 char const *vsSource = "#version 450\n"
13660 "\n"
13661 "out gl_PerVertex {\n"
13662 " vec4 gl_Position;\n"
13663 "};\n"
13664 "void main(){\n"
13665 " gl_Position = vec4(1);\n"
13666 "}\n";
13667 char const *fsSource = "#version 450\n"
13668 "\n"
13669 "layout(location=0) out vec4 color;\n"
13670 "void main(){\n"
13671 " color = vec4(1);\n"
13672 "}\n";
Chris Forbesde136e02015-05-25 11:13:28 +120013673
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060013674 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13675 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbesde136e02015-05-25 11:13:28 +120013676
13677 VkPipelineObj pipe(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +080013678 pipe.AddColorAttachment();
Chris Forbesde136e02015-05-25 11:13:28 +120013679 pipe.AddShader(&vs);
13680 pipe.AddShader(&fs);
13681
13682 pipe.AddVertexInputBindings(&input_binding, 1);
13683 pipe.AddVertexInputAttribs(&input_attrib, 1);
13684
Chris Forbesde136e02015-05-25 11:13:28 +120013685 VkDescriptorSetObj descriptorSet(m_device);
13686 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080013687 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbesde136e02015-05-25 11:13:28 +120013688
Tony Barbour5781e8f2015-08-04 16:23:11 -060013689 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbesde136e02015-05-25 11:13:28 +120013690
Chris Forbes8f36a8a2016-04-07 13:21:07 +120013691 m_errorMonitor->VerifyFound();
Chris Forbesde136e02015-05-25 11:13:28 +120013692}
13693
Karl Schultz6addd812016-02-02 17:17:23 -070013694TEST_F(VkLayerTest, CreatePipelineAttribLocationMismatch) {
Chris Forbes1cc79542016-07-20 11:13:44 +120013695 TEST_DESCRIPTION("Test that a warning is produced for a location mismatch on "
13696 "vertex attributes. This flushes out bad behavior in the interface walker");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013697 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT, "location 0 not consumed by VS");
Chris Forbes7d83cd52016-01-15 11:32:03 +130013698
13699 ASSERT_NO_FATAL_FAILURE(InitState());
13700 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13701
13702 VkVertexInputBindingDescription input_binding;
13703 memset(&input_binding, 0, sizeof(input_binding));
13704
13705 VkVertexInputAttributeDescription input_attrib;
13706 memset(&input_attrib, 0, sizeof(input_attrib));
13707 input_attrib.format = VK_FORMAT_R32_SFLOAT;
13708
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013709 char const *vsSource = "#version 450\n"
13710 "\n"
13711 "layout(location=1) in float x;\n"
13712 "out gl_PerVertex {\n"
13713 " vec4 gl_Position;\n"
13714 "};\n"
13715 "void main(){\n"
13716 " gl_Position = vec4(x);\n"
13717 "}\n";
13718 char const *fsSource = "#version 450\n"
13719 "\n"
13720 "layout(location=0) out vec4 color;\n"
13721 "void main(){\n"
13722 " color = vec4(1);\n"
13723 "}\n";
Chris Forbes7d83cd52016-01-15 11:32:03 +130013724
13725 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13726 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
13727
13728 VkPipelineObj pipe(m_device);
13729 pipe.AddColorAttachment();
13730 pipe.AddShader(&vs);
13731 pipe.AddShader(&fs);
13732
13733 pipe.AddVertexInputBindings(&input_binding, 1);
13734 pipe.AddVertexInputAttribs(&input_attrib, 1);
13735
13736 VkDescriptorSetObj descriptorSet(m_device);
13737 descriptorSet.AppendDummy();
13738 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
13739
13740 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
13741
Chris Forbes8f36a8a2016-04-07 13:21:07 +120013742 m_errorMonitor->VerifyFound();
Chris Forbes7d83cd52016-01-15 11:32:03 +130013743}
13744
Karl Schultz6addd812016-02-02 17:17:23 -070013745TEST_F(VkLayerTest, CreatePipelineAttribNotProvided) {
Chris Forbes1cc79542016-07-20 11:13:44 +120013746 TEST_DESCRIPTION("Test that an error is produced for a VS input which is not "
13747 "provided by a vertex attribute");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013748 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 -060013749
Chris Forbes62e8e502015-05-25 11:13:29 +120013750 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -060013751 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbes62e8e502015-05-25 11:13:29 +120013752
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013753 char const *vsSource = "#version 450\n"
13754 "\n"
13755 "layout(location=0) in vec4 x;\n" /* not provided */
13756 "out gl_PerVertex {\n"
13757 " vec4 gl_Position;\n"
13758 "};\n"
13759 "void main(){\n"
13760 " gl_Position = x;\n"
13761 "}\n";
13762 char const *fsSource = "#version 450\n"
13763 "\n"
13764 "layout(location=0) out vec4 color;\n"
13765 "void main(){\n"
13766 " color = vec4(1);\n"
13767 "}\n";
Chris Forbes62e8e502015-05-25 11:13:29 +120013768
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060013769 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13770 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbes62e8e502015-05-25 11:13:29 +120013771
13772 VkPipelineObj pipe(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +080013773 pipe.AddColorAttachment();
Chris Forbes62e8e502015-05-25 11:13:29 +120013774 pipe.AddShader(&vs);
13775 pipe.AddShader(&fs);
13776
Chris Forbes62e8e502015-05-25 11:13:29 +120013777 VkDescriptorSetObj descriptorSet(m_device);
13778 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080013779 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbes62e8e502015-05-25 11:13:29 +120013780
Tony Barbour5781e8f2015-08-04 16:23:11 -060013781 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbes62e8e502015-05-25 11:13:29 +120013782
Chris Forbes8f36a8a2016-04-07 13:21:07 +120013783 m_errorMonitor->VerifyFound();
Chris Forbes62e8e502015-05-25 11:13:29 +120013784}
13785
Karl Schultz6addd812016-02-02 17:17:23 -070013786TEST_F(VkLayerTest, CreatePipelineAttribTypeMismatch) {
Chris Forbes1cc79542016-07-20 11:13:44 +120013787 TEST_DESCRIPTION("Test that an error is produced for a mismatch between the "
13788 "fundamental type (float/int/uint) of an attribute and the "
13789 "VS input that consumes it");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013790 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "location 0 does not match VS input type");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060013791
Chris Forbesc97d98e2015-05-25 11:13:31 +120013792 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -060013793 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbesc97d98e2015-05-25 11:13:31 +120013794
13795 VkVertexInputBindingDescription input_binding;
13796 memset(&input_binding, 0, sizeof(input_binding));
13797
13798 VkVertexInputAttributeDescription input_attrib;
13799 memset(&input_attrib, 0, sizeof(input_attrib));
13800 input_attrib.format = VK_FORMAT_R32_SFLOAT;
13801
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013802 char const *vsSource = "#version 450\n"
13803 "\n"
13804 "layout(location=0) in int x;\n" /* attrib provided float */
13805 "out gl_PerVertex {\n"
13806 " vec4 gl_Position;\n"
13807 "};\n"
13808 "void main(){\n"
13809 " gl_Position = vec4(x);\n"
13810 "}\n";
13811 char const *fsSource = "#version 450\n"
13812 "\n"
13813 "layout(location=0) out vec4 color;\n"
13814 "void main(){\n"
13815 " color = vec4(1);\n"
13816 "}\n";
Chris Forbesc97d98e2015-05-25 11:13:31 +120013817
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060013818 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13819 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbesc97d98e2015-05-25 11:13:31 +120013820
13821 VkPipelineObj pipe(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +080013822 pipe.AddColorAttachment();
Chris Forbesc97d98e2015-05-25 11:13:31 +120013823 pipe.AddShader(&vs);
13824 pipe.AddShader(&fs);
13825
13826 pipe.AddVertexInputBindings(&input_binding, 1);
13827 pipe.AddVertexInputAttribs(&input_attrib, 1);
13828
Chris Forbesc97d98e2015-05-25 11:13:31 +120013829 VkDescriptorSetObj descriptorSet(m_device);
13830 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080013831 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbesc97d98e2015-05-25 11:13:31 +120013832
Tony Barbour5781e8f2015-08-04 16:23:11 -060013833 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbesc97d98e2015-05-25 11:13:31 +120013834
Chris Forbes8f36a8a2016-04-07 13:21:07 +120013835 m_errorMonitor->VerifyFound();
Chris Forbesc97d98e2015-05-25 11:13:31 +120013836}
13837
Chris Forbesc68b43c2016-04-06 11:18:47 +120013838TEST_F(VkLayerTest, CreatePipelineDuplicateStage) {
Chris Forbes1cc79542016-07-20 11:13:44 +120013839 TEST_DESCRIPTION("Test that an error is produced for a pipeline containing multiple "
13840 "shaders for the same stage");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013841 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
13842 "Multiple shaders provided for stage VK_SHADER_STAGE_VERTEX_BIT");
Chris Forbesc68b43c2016-04-06 11:18:47 +120013843
13844 ASSERT_NO_FATAL_FAILURE(InitState());
13845 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13846
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013847 char const *vsSource = "#version 450\n"
13848 "\n"
13849 "out gl_PerVertex {\n"
13850 " vec4 gl_Position;\n"
13851 "};\n"
13852 "void main(){\n"
13853 " gl_Position = vec4(1);\n"
13854 "}\n";
13855 char const *fsSource = "#version 450\n"
13856 "\n"
13857 "layout(location=0) out vec4 color;\n"
13858 "void main(){\n"
13859 " color = vec4(1);\n"
13860 "}\n";
Chris Forbesc68b43c2016-04-06 11:18:47 +120013861
13862 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13863 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
13864
13865 VkPipelineObj pipe(m_device);
13866 pipe.AddColorAttachment();
13867 pipe.AddShader(&vs);
13868 pipe.AddShader(&vs);
13869 pipe.AddShader(&fs);
13870
13871 VkDescriptorSetObj descriptorSet(m_device);
13872 descriptorSet.AppendDummy();
13873 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
13874
13875 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
13876
Chris Forbes8f36a8a2016-04-07 13:21:07 +120013877 m_errorMonitor->VerifyFound();
Chris Forbesc68b43c2016-04-06 11:18:47 +120013878}
13879
Karl Schultz6addd812016-02-02 17:17:23 -070013880TEST_F(VkLayerTest, CreatePipelineAttribMatrixType) {
Chris Forbes1cc79542016-07-20 11:13:44 +120013881 TEST_DESCRIPTION("Test that pipeline validation accepts matrices passed "
13882 "as vertex attributes");
Chris Forbes8f36a8a2016-04-07 13:21:07 +120013883 m_errorMonitor->ExpectSuccess();
Chris Forbes2682b242015-11-24 11:13:14 +130013884
13885 ASSERT_NO_FATAL_FAILURE(InitState());
13886 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13887
13888 VkVertexInputBindingDescription input_binding;
13889 memset(&input_binding, 0, sizeof(input_binding));
13890
13891 VkVertexInputAttributeDescription input_attribs[2];
13892 memset(input_attribs, 0, sizeof(input_attribs));
13893
13894 for (int i = 0; i < 2; i++) {
13895 input_attribs[i].format = VK_FORMAT_R32G32B32A32_SFLOAT;
13896 input_attribs[i].location = i;
13897 }
13898
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013899 char const *vsSource = "#version 450\n"
13900 "\n"
13901 "layout(location=0) in mat2x4 x;\n"
13902 "out gl_PerVertex {\n"
13903 " vec4 gl_Position;\n"
13904 "};\n"
13905 "void main(){\n"
13906 " gl_Position = x[0] + x[1];\n"
13907 "}\n";
13908 char const *fsSource = "#version 450\n"
13909 "\n"
13910 "layout(location=0) out vec4 color;\n"
13911 "void main(){\n"
13912 " color = vec4(1);\n"
13913 "}\n";
Chris Forbes2682b242015-11-24 11:13:14 +130013914
13915 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13916 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
13917
13918 VkPipelineObj pipe(m_device);
13919 pipe.AddColorAttachment();
13920 pipe.AddShader(&vs);
13921 pipe.AddShader(&fs);
13922
13923 pipe.AddVertexInputBindings(&input_binding, 1);
13924 pipe.AddVertexInputAttribs(input_attribs, 2);
13925
13926 VkDescriptorSetObj descriptorSet(m_device);
13927 descriptorSet.AppendDummy();
13928 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
13929
13930 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
13931
13932 /* expect success */
Chris Forbes8f36a8a2016-04-07 13:21:07 +120013933 m_errorMonitor->VerifyNotFound();
Chris Forbes2682b242015-11-24 11:13:14 +130013934}
13935
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013936TEST_F(VkLayerTest, CreatePipelineAttribArrayType) {
Chris Forbes8f36a8a2016-04-07 13:21:07 +120013937 m_errorMonitor->ExpectSuccess();
Chris Forbes2682b242015-11-24 11:13:14 +130013938
13939 ASSERT_NO_FATAL_FAILURE(InitState());
13940 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13941
13942 VkVertexInputBindingDescription input_binding;
13943 memset(&input_binding, 0, sizeof(input_binding));
13944
13945 VkVertexInputAttributeDescription input_attribs[2];
13946 memset(input_attribs, 0, sizeof(input_attribs));
13947
13948 for (int i = 0; i < 2; i++) {
13949 input_attribs[i].format = VK_FORMAT_R32G32B32A32_SFLOAT;
13950 input_attribs[i].location = i;
13951 }
13952
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013953 char const *vsSource = "#version 450\n"
13954 "\n"
13955 "layout(location=0) in vec4 x[2];\n"
13956 "out gl_PerVertex {\n"
13957 " vec4 gl_Position;\n"
13958 "};\n"
13959 "void main(){\n"
13960 " gl_Position = x[0] + x[1];\n"
13961 "}\n";
13962 char const *fsSource = "#version 450\n"
13963 "\n"
13964 "layout(location=0) out vec4 color;\n"
13965 "void main(){\n"
13966 " color = vec4(1);\n"
13967 "}\n";
Chris Forbes2682b242015-11-24 11:13:14 +130013968
13969 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13970 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
13971
13972 VkPipelineObj pipe(m_device);
13973 pipe.AddColorAttachment();
13974 pipe.AddShader(&vs);
13975 pipe.AddShader(&fs);
13976
13977 pipe.AddVertexInputBindings(&input_binding, 1);
13978 pipe.AddVertexInputAttribs(input_attribs, 2);
13979
13980 VkDescriptorSetObj descriptorSet(m_device);
13981 descriptorSet.AppendDummy();
13982 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
13983
13984 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
13985
Chris Forbes8f36a8a2016-04-07 13:21:07 +120013986 m_errorMonitor->VerifyNotFound();
Chris Forbes2682b242015-11-24 11:13:14 +130013987}
Chris Forbes2682b242015-11-24 11:13:14 +130013988
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013989TEST_F(VkLayerTest, CreatePipelineAttribComponents) {
Chris Forbes1cc79542016-07-20 11:13:44 +120013990 TEST_DESCRIPTION("Test that pipeline validation accepts consuming a vertex attribute "
13991 "through multiple VS inputs, each consuming a different subset of the "
13992 "components.");
Chris Forbesbc290ce2016-07-06 12:01:49 +120013993 m_errorMonitor->ExpectSuccess();
13994
13995 ASSERT_NO_FATAL_FAILURE(InitState());
13996 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13997
13998 VkVertexInputBindingDescription input_binding;
13999 memset(&input_binding, 0, sizeof(input_binding));
14000
14001 VkVertexInputAttributeDescription input_attribs[3];
14002 memset(input_attribs, 0, sizeof(input_attribs));
14003
14004 for (int i = 0; i < 3; i++) {
14005 input_attribs[i].format = VK_FORMAT_R32G32B32A32_SFLOAT;
14006 input_attribs[i].location = i;
14007 }
14008
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014009 char const *vsSource = "#version 450\n"
14010 "\n"
14011 "layout(location=0) in vec4 x;\n"
14012 "layout(location=1) in vec3 y1;\n"
14013 "layout(location=1, component=3) in float y2;\n"
14014 "layout(location=2) in vec4 z;\n"
14015 "out gl_PerVertex {\n"
14016 " vec4 gl_Position;\n"
14017 "};\n"
14018 "void main(){\n"
14019 " gl_Position = x + vec4(y1, y2) + z;\n"
14020 "}\n";
14021 char const *fsSource = "#version 450\n"
14022 "\n"
14023 "layout(location=0) out vec4 color;\n"
14024 "void main(){\n"
14025 " color = vec4(1);\n"
14026 "}\n";
Chris Forbesbc290ce2016-07-06 12:01:49 +120014027
14028 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
14029 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
14030
14031 VkPipelineObj pipe(m_device);
14032 pipe.AddColorAttachment();
14033 pipe.AddShader(&vs);
14034 pipe.AddShader(&fs);
14035
14036 pipe.AddVertexInputBindings(&input_binding, 1);
14037 pipe.AddVertexInputAttribs(input_attribs, 3);
14038
14039 VkDescriptorSetObj descriptorSet(m_device);
14040 descriptorSet.AppendDummy();
14041 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
14042
14043 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
14044
14045 m_errorMonitor->VerifyNotFound();
14046}
14047
Chris Forbes82ff92a2016-09-09 10:50:24 +120014048TEST_F(VkLayerTest, CreatePipelineMissingEntrypoint) {
14049 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
14050 "No entrypoint found named `foo`");
14051
14052 ASSERT_NO_FATAL_FAILURE(InitState());
14053 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
14054
14055 char const *vsSource = "#version 450\n"
14056 "out gl_PerVertex {\n"
14057 " vec4 gl_Position;\n"
14058 "};\n"
14059 "void main(){\n"
14060 " gl_Position = vec4(0);\n"
14061 "}\n";
14062 char const *fsSource = "#version 450\n"
14063 "\n"
14064 "layout(location=0) out vec4 color;\n"
14065 "void main(){\n"
14066 " color = vec4(1);\n"
14067 "}\n";
14068
14069 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
14070 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this, "foo");
14071
14072 VkPipelineObj pipe(m_device);
14073 pipe.AddColorAttachment();
14074 pipe.AddShader(&vs);
14075 pipe.AddShader(&fs);
14076
14077 VkDescriptorSetObj descriptorSet(m_device);
14078 descriptorSet.AppendDummy();
14079 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
14080
14081 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
14082
14083 m_errorMonitor->VerifyFound();
14084}
14085
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014086TEST_F(VkLayerTest, CreatePipelineSimplePositive) {
Chris Forbes8f36a8a2016-04-07 13:21:07 +120014087 m_errorMonitor->ExpectSuccess();
Chris Forbes4ea14fc2016-04-04 18:52:54 +120014088
14089 ASSERT_NO_FATAL_FAILURE(InitState());
14090 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
14091
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014092 char const *vsSource = "#version 450\n"
14093 "out gl_PerVertex {\n"
14094 " vec4 gl_Position;\n"
14095 "};\n"
14096 "void main(){\n"
14097 " gl_Position = vec4(0);\n"
14098 "}\n";
14099 char const *fsSource = "#version 450\n"
14100 "\n"
14101 "layout(location=0) out vec4 color;\n"
14102 "void main(){\n"
14103 " color = vec4(1);\n"
14104 "}\n";
Chris Forbes4ea14fc2016-04-04 18:52:54 +120014105
14106 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
14107 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
14108
14109 VkPipelineObj pipe(m_device);
14110 pipe.AddColorAttachment();
14111 pipe.AddShader(&vs);
14112 pipe.AddShader(&fs);
14113
14114 VkDescriptorSetObj descriptorSet(m_device);
14115 descriptorSet.AppendDummy();
14116 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
14117
14118 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
14119
Chris Forbes8f36a8a2016-04-07 13:21:07 +120014120 m_errorMonitor->VerifyNotFound();
Chris Forbes4ea14fc2016-04-04 18:52:54 +120014121}
14122
Chris Forbesae9d8cd2016-09-13 16:32:57 +120014123TEST_F(VkLayerTest, CreatePipelineDepthStencilRequired) {
14124 m_errorMonitor->SetDesiredFailureMsg(
14125 VK_DEBUG_REPORT_ERROR_BIT_EXT,
14126 "pDepthStencilState is NULL when rasterization is enabled and subpass "
14127 "uses a depth/stencil attachment");
14128
14129 ASSERT_NO_FATAL_FAILURE(InitState());
14130 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
14131
14132 char const *vsSource = "#version 450\n"
14133 "void main(){ gl_Position = vec4(0); }\n";
14134 char const *fsSource = "#version 450\n"
14135 "\n"
14136 "layout(location=0) out vec4 color;\n"
14137 "void main(){\n"
14138 " color = vec4(1);\n"
14139 "}\n";
14140
14141 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
14142 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
14143
14144 VkPipelineObj pipe(m_device);
14145 pipe.AddColorAttachment();
14146 pipe.AddShader(&vs);
14147 pipe.AddShader(&fs);
14148
14149 VkDescriptorSetObj descriptorSet(m_device);
14150 descriptorSet.AppendDummy();
14151 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
14152
14153 VkAttachmentDescription attachments[] = {
14154 { 0, VK_FORMAT_B8G8R8A8_UNORM, VK_SAMPLE_COUNT_1_BIT,
14155 VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE,
14156 VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE,
14157 VK_IMAGE_LAYOUT_UNDEFINED, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
14158 },
14159 { 0, VK_FORMAT_D16_UNORM, VK_SAMPLE_COUNT_1_BIT,
14160 VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE,
14161 VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE,
14162 VK_IMAGE_LAYOUT_UNDEFINED, VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL,
14163 },
14164 };
14165 VkAttachmentReference refs[] = {
14166 { 0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL },
14167 { 1, VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL },
14168 };
14169 VkSubpassDescription subpass = {
14170 0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr,
14171 1, &refs[0], nullptr, &refs[1],
14172 0, nullptr
14173 };
14174 VkRenderPassCreateInfo rpci = {
14175 VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr,
14176 0, 2, attachments, 1, &subpass, 0, nullptr
14177 };
14178 VkRenderPass rp;
14179 VkResult err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
14180 ASSERT_VK_SUCCESS(err);
14181
14182 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), rp);
14183
14184 m_errorMonitor->VerifyFound();
14185
14186 vkDestroyRenderPass(m_device->device(), rp, nullptr);
14187}
14188
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014189TEST_F(VkLayerTest, CreatePipelineRelaxedTypeMatch) {
Chris Forbes1cc79542016-07-20 11:13:44 +120014190 TEST_DESCRIPTION("Test that pipeline validation accepts the relaxed type matching rules "
14191 "set out in 14.1.3: fundamental type must match, and producer side must "
14192 "have at least as many components");
Chris Forbes8f36a8a2016-04-07 13:21:07 +120014193 m_errorMonitor->ExpectSuccess();
Chris Forbes912c9192016-04-05 17:50:35 +120014194
14195 // VK 1.0.8 Specification, 14.1.3 "Additionally,..." block
14196
14197 ASSERT_NO_FATAL_FAILURE(InitState());
14198 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
14199
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014200 char const *vsSource = "#version 450\n"
14201 "out gl_PerVertex {\n"
14202 " vec4 gl_Position;\n"
14203 "};\n"
14204 "layout(location=0) out vec3 x;\n"
14205 "layout(location=1) out ivec3 y;\n"
14206 "layout(location=2) out vec3 z;\n"
14207 "void main(){\n"
14208 " gl_Position = vec4(0);\n"
14209 " x = vec3(0); y = ivec3(0); z = vec3(0);\n"
14210 "}\n";
14211 char const *fsSource = "#version 450\n"
14212 "\n"
14213 "layout(location=0) out vec4 color;\n"
14214 "layout(location=0) in float x;\n"
14215 "layout(location=1) flat in int y;\n"
14216 "layout(location=2) in vec2 z;\n"
14217 "void main(){\n"
14218 " color = vec4(1 + x + y + z.x);\n"
14219 "}\n";
Chris Forbes912c9192016-04-05 17:50:35 +120014220
14221 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
14222 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
14223
14224 VkPipelineObj pipe(m_device);
14225 pipe.AddColorAttachment();
14226 pipe.AddShader(&vs);
14227 pipe.AddShader(&fs);
14228
14229 VkDescriptorSetObj descriptorSet(m_device);
14230 descriptorSet.AppendDummy();
14231 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
14232
Mike Stroyan255e9582016-06-24 09:49:32 -060014233 VkResult err = VK_SUCCESS;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014234 err = pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Mike Stroyan255e9582016-06-24 09:49:32 -060014235 ASSERT_VK_SUCCESS(err);
14236
Chris Forbes8f36a8a2016-04-07 13:21:07 +120014237 m_errorMonitor->VerifyNotFound();
Chris Forbes912c9192016-04-05 17:50:35 +120014238}
14239
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014240TEST_F(VkLayerTest, CreatePipelineTessPerVertex) {
Chris Forbes1cc79542016-07-20 11:13:44 +120014241 TEST_DESCRIPTION("Test that pipeline validation accepts per-vertex variables "
14242 "passed between the TCS and TES stages");
Chris Forbes8f36a8a2016-04-07 13:21:07 +120014243 m_errorMonitor->ExpectSuccess();
Chris Forbes4ea14fc2016-04-04 18:52:54 +120014244
14245 ASSERT_NO_FATAL_FAILURE(InitState());
14246 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
14247
Chris Forbesc1e852d2016-04-04 19:26:42 +120014248 if (!m_device->phy().features().tessellationShader) {
14249 printf("Device does not support tessellation shaders; skipped.\n");
14250 return;
14251 }
14252
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014253 char const *vsSource = "#version 450\n"
14254 "void main(){}\n";
14255 char const *tcsSource = "#version 450\n"
14256 "layout(location=0) out int x[];\n"
14257 "layout(vertices=3) out;\n"
14258 "void main(){\n"
14259 " gl_TessLevelOuter[0] = gl_TessLevelOuter[1] = gl_TessLevelOuter[2] = 1;\n"
14260 " gl_TessLevelInner[0] = 1;\n"
14261 " x[gl_InvocationID] = gl_InvocationID;\n"
14262 "}\n";
14263 char const *tesSource = "#version 450\n"
14264 "layout(triangles, equal_spacing, cw) in;\n"
14265 "layout(location=0) in int x[];\n"
14266 "out gl_PerVertex { vec4 gl_Position; };\n"
14267 "void main(){\n"
14268 " gl_Position.xyz = gl_TessCoord;\n"
14269 " gl_Position.w = x[0] + x[1] + x[2];\n"
14270 "}\n";
14271 char const *fsSource = "#version 450\n"
14272 "layout(location=0) out vec4 color;\n"
14273 "void main(){\n"
14274 " color = vec4(1);\n"
14275 "}\n";
Chris Forbes4ea14fc2016-04-04 18:52:54 +120014276
14277 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
14278 VkShaderObj tcs(m_device, tcsSource, VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT, this);
14279 VkShaderObj tes(m_device, tesSource, VK_SHADER_STAGE_TESSELLATION_EVALUATION_BIT, this);
14280 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
14281
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014282 VkPipelineInputAssemblyStateCreateInfo iasci{VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO, nullptr, 0,
14283 VK_PRIMITIVE_TOPOLOGY_PATCH_LIST, VK_FALSE};
Chris Forbes4ea14fc2016-04-04 18:52:54 +120014284
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014285 VkPipelineTessellationStateCreateInfo tsci{VK_STRUCTURE_TYPE_PIPELINE_TESSELLATION_STATE_CREATE_INFO, nullptr, 0, 3};
Chris Forbesb4cacb62016-04-04 19:15:00 +120014286
Chris Forbes4ea14fc2016-04-04 18:52:54 +120014287 VkPipelineObj pipe(m_device);
14288 pipe.SetInputAssembly(&iasci);
Chris Forbesb4cacb62016-04-04 19:15:00 +120014289 pipe.SetTessellation(&tsci);
Chris Forbes4ea14fc2016-04-04 18:52:54 +120014290 pipe.AddColorAttachment();
14291 pipe.AddShader(&vs);
14292 pipe.AddShader(&tcs);
14293 pipe.AddShader(&tes);
14294 pipe.AddShader(&fs);
14295
14296 VkDescriptorSetObj descriptorSet(m_device);
14297 descriptorSet.AppendDummy();
14298 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
14299
14300 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
14301
Chris Forbes8f36a8a2016-04-07 13:21:07 +120014302 m_errorMonitor->VerifyNotFound();
Chris Forbes4ea14fc2016-04-04 18:52:54 +120014303}
14304
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014305TEST_F(VkLayerTest, CreatePipelineGeometryInputBlockPositive) {
Chris Forbes1cc79542016-07-20 11:13:44 +120014306 TEST_DESCRIPTION("Test that pipeline validation accepts a user-defined "
14307 "interface block passed into the geometry shader. This "
14308 "is interesting because the 'extra' array level is not "
14309 "present on the member type, but on the block instance.");
Chris Forbesa0ab8152016-04-20 13:34:27 +120014310 m_errorMonitor->ExpectSuccess();
14311
14312 ASSERT_NO_FATAL_FAILURE(InitState());
14313 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
14314
14315 if (!m_device->phy().features().geometryShader) {
14316 printf("Device does not support geometry shaders; skipped.\n");
14317 return;
14318 }
14319
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014320 char const *vsSource = "#version 450\n"
14321 "layout(location=0) out VertexData { vec4 x; } vs_out;\n"
14322 "void main(){\n"
14323 " vs_out.x = vec4(1);\n"
14324 "}\n";
14325 char const *gsSource = "#version 450\n"
14326 "layout(triangles) in;\n"
14327 "layout(triangle_strip, max_vertices=3) out;\n"
14328 "layout(location=0) in VertexData { vec4 x; } gs_in[];\n"
14329 "out gl_PerVertex { vec4 gl_Position; };\n"
14330 "void main() {\n"
14331 " gl_Position = gs_in[0].x;\n"
14332 " EmitVertex();\n"
14333 "}\n";
14334 char const *fsSource = "#version 450\n"
14335 "layout(location=0) out vec4 color;\n"
14336 "void main(){\n"
14337 " color = vec4(1);\n"
14338 "}\n";
Chris Forbesa0ab8152016-04-20 13:34:27 +120014339
14340 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
14341 VkShaderObj gs(m_device, gsSource, VK_SHADER_STAGE_GEOMETRY_BIT, this);
14342 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
14343
14344 VkPipelineObj pipe(m_device);
14345 pipe.AddColorAttachment();
14346 pipe.AddShader(&vs);
14347 pipe.AddShader(&gs);
14348 pipe.AddShader(&fs);
14349
14350 VkDescriptorSetObj descriptorSet(m_device);
14351 descriptorSet.AppendDummy();
14352 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
14353
14354 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
14355
14356 m_errorMonitor->VerifyNotFound();
14357}
14358
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014359TEST_F(VkLayerTest, CreatePipelineTessPatchDecorationMismatch) {
Chris Forbes1cc79542016-07-20 11:13:44 +120014360 TEST_DESCRIPTION("Test that an error is produced for a variable output from "
14361 "the TCS without the patch decoration, but consumed in the TES "
14362 "with the decoration.");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014363 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "is per-vertex in tessellation control shader stage "
14364 "but per-patch in tessellation evaluation shader stage");
Chris Forbesa0193bc2016-04-04 19:19:47 +120014365
14366 ASSERT_NO_FATAL_FAILURE(InitState());
14367 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
14368
Chris Forbesc1e852d2016-04-04 19:26:42 +120014369 if (!m_device->phy().features().tessellationShader) {
14370 printf("Device does not support tessellation shaders; skipped.\n");
14371 return;
14372 }
14373
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014374 char const *vsSource = "#version 450\n"
14375 "void main(){}\n";
14376 char const *tcsSource = "#version 450\n"
14377 "layout(location=0) out int x[];\n"
14378 "layout(vertices=3) out;\n"
14379 "void main(){\n"
14380 " gl_TessLevelOuter[0] = gl_TessLevelOuter[1] = gl_TessLevelOuter[2] = 1;\n"
14381 " gl_TessLevelInner[0] = 1;\n"
14382 " x[gl_InvocationID] = gl_InvocationID;\n"
14383 "}\n";
14384 char const *tesSource = "#version 450\n"
14385 "layout(triangles, equal_spacing, cw) in;\n"
14386 "layout(location=0) patch in int x;\n"
14387 "out gl_PerVertex { vec4 gl_Position; };\n"
14388 "void main(){\n"
14389 " gl_Position.xyz = gl_TessCoord;\n"
14390 " gl_Position.w = x;\n"
14391 "}\n";
14392 char const *fsSource = "#version 450\n"
14393 "layout(location=0) out vec4 color;\n"
14394 "void main(){\n"
14395 " color = vec4(1);\n"
14396 "}\n";
Chris Forbesa0193bc2016-04-04 19:19:47 +120014397
14398 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
14399 VkShaderObj tcs(m_device, tcsSource, VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT, this);
14400 VkShaderObj tes(m_device, tesSource, VK_SHADER_STAGE_TESSELLATION_EVALUATION_BIT, this);
14401 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
14402
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014403 VkPipelineInputAssemblyStateCreateInfo iasci{VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO, nullptr, 0,
14404 VK_PRIMITIVE_TOPOLOGY_PATCH_LIST, VK_FALSE};
Chris Forbesa0193bc2016-04-04 19:19:47 +120014405
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014406 VkPipelineTessellationStateCreateInfo tsci{VK_STRUCTURE_TYPE_PIPELINE_TESSELLATION_STATE_CREATE_INFO, nullptr, 0, 3};
Chris Forbesa0193bc2016-04-04 19:19:47 +120014407
14408 VkPipelineObj pipe(m_device);
14409 pipe.SetInputAssembly(&iasci);
14410 pipe.SetTessellation(&tsci);
14411 pipe.AddColorAttachment();
14412 pipe.AddShader(&vs);
14413 pipe.AddShader(&tcs);
14414 pipe.AddShader(&tes);
14415 pipe.AddShader(&fs);
14416
14417 VkDescriptorSetObj descriptorSet(m_device);
14418 descriptorSet.AppendDummy();
14419 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
14420
14421 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
14422
Chris Forbes8f36a8a2016-04-07 13:21:07 +120014423 m_errorMonitor->VerifyFound();
Chris Forbesa0193bc2016-04-04 19:19:47 +120014424}
14425
Karl Schultz6addd812016-02-02 17:17:23 -070014426TEST_F(VkLayerTest, CreatePipelineAttribBindingConflict) {
Chris Forbes1cc79542016-07-20 11:13:44 +120014427 TEST_DESCRIPTION("Test that an error is produced for a vertex attribute setup where multiple "
14428 "bindings provide the same location");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014429 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
14430 "Duplicate vertex input binding descriptions for binding 0");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060014431
Chris Forbes280ba2c2015-06-12 11:16:41 +120014432 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -060014433 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbes280ba2c2015-06-12 11:16:41 +120014434
14435 /* Two binding descriptions for binding 0 */
14436 VkVertexInputBindingDescription input_bindings[2];
14437 memset(input_bindings, 0, sizeof(input_bindings));
14438
14439 VkVertexInputAttributeDescription input_attrib;
14440 memset(&input_attrib, 0, sizeof(input_attrib));
14441 input_attrib.format = VK_FORMAT_R32_SFLOAT;
14442
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014443 char const *vsSource = "#version 450\n"
14444 "\n"
14445 "layout(location=0) in float x;\n" /* attrib provided float */
14446 "out gl_PerVertex {\n"
14447 " vec4 gl_Position;\n"
14448 "};\n"
14449 "void main(){\n"
14450 " gl_Position = vec4(x);\n"
14451 "}\n";
14452 char const *fsSource = "#version 450\n"
14453 "\n"
14454 "layout(location=0) out vec4 color;\n"
14455 "void main(){\n"
14456 " color = vec4(1);\n"
14457 "}\n";
Chris Forbes280ba2c2015-06-12 11:16:41 +120014458
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060014459 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
14460 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbes280ba2c2015-06-12 11:16:41 +120014461
14462 VkPipelineObj pipe(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +080014463 pipe.AddColorAttachment();
Chris Forbes280ba2c2015-06-12 11:16:41 +120014464 pipe.AddShader(&vs);
14465 pipe.AddShader(&fs);
14466
14467 pipe.AddVertexInputBindings(input_bindings, 2);
14468 pipe.AddVertexInputAttribs(&input_attrib, 1);
14469
Chris Forbes280ba2c2015-06-12 11:16:41 +120014470 VkDescriptorSetObj descriptorSet(m_device);
14471 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014472 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbes280ba2c2015-06-12 11:16:41 +120014473
Tony Barbour5781e8f2015-08-04 16:23:11 -060014474 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbes280ba2c2015-06-12 11:16:41 +120014475
Chris Forbes8f36a8a2016-04-07 13:21:07 +120014476 m_errorMonitor->VerifyFound();
Chris Forbes280ba2c2015-06-12 11:16:41 +120014477}
Chris Forbes8f68b562015-05-25 11:13:32 +120014478
Chris Forbes35efec72016-04-21 14:32:08 +120014479TEST_F(VkLayerTest, CreatePipeline64BitAttributesPositive) {
Chris Forbes1cc79542016-07-20 11:13:44 +120014480 TEST_DESCRIPTION("Test that pipeline validation accepts basic use of 64bit vertex "
14481 "attributes. This is interesting because they consume multiple "
14482 "locations.");
Chris Forbes35efec72016-04-21 14:32:08 +120014483 m_errorMonitor->ExpectSuccess();
14484
14485 ASSERT_NO_FATAL_FAILURE(InitState());
14486 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
14487
Chris Forbes91cf3a82016-06-28 17:51:35 +120014488 if (!m_device->phy().features().shaderFloat64) {
Chris Forbes35efec72016-04-21 14:32:08 +120014489 printf("Device does not support 64bit vertex attributes; skipped.\n");
14490 return;
14491 }
14492
14493 VkVertexInputBindingDescription input_bindings[1];
14494 memset(input_bindings, 0, sizeof(input_bindings));
14495
14496 VkVertexInputAttributeDescription input_attribs[4];
14497 memset(input_attribs, 0, sizeof(input_attribs));
14498 input_attribs[0].location = 0;
14499 input_attribs[0].offset = 0;
14500 input_attribs[0].format = VK_FORMAT_R64G64B64A64_SFLOAT;
14501 input_attribs[1].location = 2;
14502 input_attribs[1].offset = 32;
14503 input_attribs[1].format = VK_FORMAT_R64G64B64A64_SFLOAT;
14504 input_attribs[2].location = 4;
14505 input_attribs[2].offset = 64;
14506 input_attribs[2].format = VK_FORMAT_R64G64B64A64_SFLOAT;
14507 input_attribs[3].location = 6;
14508 input_attribs[3].offset = 96;
14509 input_attribs[3].format = VK_FORMAT_R64G64B64A64_SFLOAT;
14510
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014511 char const *vsSource = "#version 450\n"
14512 "\n"
14513 "layout(location=0) in dmat4 x;\n"
14514 "out gl_PerVertex {\n"
14515 " vec4 gl_Position;\n"
14516 "};\n"
14517 "void main(){\n"
14518 " gl_Position = vec4(x[0][0]);\n"
14519 "}\n";
14520 char const *fsSource = "#version 450\n"
14521 "\n"
14522 "layout(location=0) out vec4 color;\n"
14523 "void main(){\n"
14524 " color = vec4(1);\n"
14525 "}\n";
Chris Forbes35efec72016-04-21 14:32:08 +120014526
14527 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
14528 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
14529
14530 VkPipelineObj pipe(m_device);
14531 pipe.AddColorAttachment();
14532 pipe.AddShader(&vs);
14533 pipe.AddShader(&fs);
14534
14535 pipe.AddVertexInputBindings(input_bindings, 1);
14536 pipe.AddVertexInputAttribs(input_attribs, 4);
14537
14538 VkDescriptorSetObj descriptorSet(m_device);
14539 descriptorSet.AppendDummy();
14540 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
14541
14542 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
14543
14544 m_errorMonitor->VerifyNotFound();
14545}
14546
Karl Schultz6addd812016-02-02 17:17:23 -070014547TEST_F(VkLayerTest, CreatePipelineFragmentOutputNotWritten) {
Chris Forbes1cc79542016-07-20 11:13:44 +120014548 TEST_DESCRIPTION("Test that an error is produced for a FS which does not "
14549 "provide an output for one of the pipeline's color attachments");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014550 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Attachment 0 not written by FS");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060014551
Chris Forbes4d6d1e52015-05-25 11:13:40 +120014552 ASSERT_NO_FATAL_FAILURE(InitState());
Chris Forbes4d6d1e52015-05-25 11:13:40 +120014553
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014554 char const *vsSource = "#version 450\n"
14555 "\n"
14556 "out gl_PerVertex {\n"
14557 " vec4 gl_Position;\n"
14558 "};\n"
14559 "void main(){\n"
14560 " gl_Position = vec4(1);\n"
14561 "}\n";
14562 char const *fsSource = "#version 450\n"
14563 "\n"
14564 "void main(){\n"
14565 "}\n";
Chris Forbes4d6d1e52015-05-25 11:13:40 +120014566
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060014567 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
14568 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbes4d6d1e52015-05-25 11:13:40 +120014569
14570 VkPipelineObj pipe(m_device);
14571 pipe.AddShader(&vs);
14572 pipe.AddShader(&fs);
14573
Chia-I Wu08accc62015-07-07 11:50:03 +080014574 /* set up CB 0, not written */
14575 pipe.AddColorAttachment();
14576 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbes4d6d1e52015-05-25 11:13:40 +120014577
Chris Forbes4d6d1e52015-05-25 11:13:40 +120014578 VkDescriptorSetObj descriptorSet(m_device);
14579 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014580 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbes4d6d1e52015-05-25 11:13:40 +120014581
Tony Barbour5781e8f2015-08-04 16:23:11 -060014582 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbes4d6d1e52015-05-25 11:13:40 +120014583
Chris Forbes8f36a8a2016-04-07 13:21:07 +120014584 m_errorMonitor->VerifyFound();
Chris Forbes4d6d1e52015-05-25 11:13:40 +120014585}
14586
Karl Schultz6addd812016-02-02 17:17:23 -070014587TEST_F(VkLayerTest, CreatePipelineFragmentOutputNotConsumed) {
Chris Forbes1cc79542016-07-20 11:13:44 +120014588 TEST_DESCRIPTION("Test that a warning is produced for a FS which provides a spurious "
14589 "output with no matching attachment");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014590 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT,
14591 "FS writes to output location 1 with no matching attachment");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060014592
Chris Forbesf3fffaa2015-05-25 11:13:43 +120014593 ASSERT_NO_FATAL_FAILURE(InitState());
Chris Forbesf3fffaa2015-05-25 11:13:43 +120014594
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014595 char const *vsSource = "#version 450\n"
14596 "\n"
14597 "out gl_PerVertex {\n"
14598 " vec4 gl_Position;\n"
14599 "};\n"
14600 "void main(){\n"
14601 " gl_Position = vec4(1);\n"
14602 "}\n";
14603 char const *fsSource = "#version 450\n"
14604 "\n"
14605 "layout(location=0) out vec4 x;\n"
14606 "layout(location=1) out vec4 y;\n" /* no matching attachment for this */
14607 "void main(){\n"
14608 " x = vec4(1);\n"
14609 " y = vec4(1);\n"
14610 "}\n";
Chris Forbesf3fffaa2015-05-25 11:13:43 +120014611
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060014612 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
14613 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbesf3fffaa2015-05-25 11:13:43 +120014614
14615 VkPipelineObj pipe(m_device);
14616 pipe.AddShader(&vs);
14617 pipe.AddShader(&fs);
14618
Chia-I Wu08accc62015-07-07 11:50:03 +080014619 /* set up CB 0, not written */
14620 pipe.AddColorAttachment();
14621 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbesf3fffaa2015-05-25 11:13:43 +120014622 /* FS writes CB 1, but we don't configure it */
14623
Chris Forbesf3fffaa2015-05-25 11:13:43 +120014624 VkDescriptorSetObj descriptorSet(m_device);
14625 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014626 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbesf3fffaa2015-05-25 11:13:43 +120014627
Tony Barbour5781e8f2015-08-04 16:23:11 -060014628 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbesf3fffaa2015-05-25 11:13:43 +120014629
Chris Forbes8f36a8a2016-04-07 13:21:07 +120014630 m_errorMonitor->VerifyFound();
Chris Forbesf3fffaa2015-05-25 11:13:43 +120014631}
14632
Karl Schultz6addd812016-02-02 17:17:23 -070014633TEST_F(VkLayerTest, CreatePipelineFragmentOutputTypeMismatch) {
Chris Forbes1cc79542016-07-20 11:13:44 +120014634 TEST_DESCRIPTION("Test that an error is produced for a mismatch between the fundamental "
14635 "type of an FS output variable, and the format of the corresponding attachment");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014636 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "does not match FS output type");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060014637
Chris Forbesa36d69e2015-05-25 11:13:44 +120014638 ASSERT_NO_FATAL_FAILURE(InitState());
Chris Forbesa36d69e2015-05-25 11:13:44 +120014639
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014640 char const *vsSource = "#version 450\n"
14641 "\n"
14642 "out gl_PerVertex {\n"
14643 " vec4 gl_Position;\n"
14644 "};\n"
14645 "void main(){\n"
14646 " gl_Position = vec4(1);\n"
14647 "}\n";
14648 char const *fsSource = "#version 450\n"
14649 "\n"
14650 "layout(location=0) out ivec4 x;\n" /* not UNORM */
14651 "void main(){\n"
14652 " x = ivec4(1);\n"
14653 "}\n";
Chris Forbesa36d69e2015-05-25 11:13:44 +120014654
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060014655 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
14656 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbesa36d69e2015-05-25 11:13:44 +120014657
14658 VkPipelineObj pipe(m_device);
14659 pipe.AddShader(&vs);
14660 pipe.AddShader(&fs);
14661
Chia-I Wu08accc62015-07-07 11:50:03 +080014662 /* set up CB 0; type is UNORM by default */
14663 pipe.AddColorAttachment();
14664 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbesa36d69e2015-05-25 11:13:44 +120014665
Chris Forbesa36d69e2015-05-25 11:13:44 +120014666 VkDescriptorSetObj descriptorSet(m_device);
14667 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014668 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbesa36d69e2015-05-25 11:13:44 +120014669
Tony Barbour5781e8f2015-08-04 16:23:11 -060014670 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbesa36d69e2015-05-25 11:13:44 +120014671
Chris Forbes8f36a8a2016-04-07 13:21:07 +120014672 m_errorMonitor->VerifyFound();
Chris Forbesa36d69e2015-05-25 11:13:44 +120014673}
Chris Forbes7b1b8932015-06-05 14:43:36 +120014674
Karl Schultz6addd812016-02-02 17:17:23 -070014675TEST_F(VkLayerTest, CreatePipelineUniformBlockNotProvided) {
Chris Forbes1cc79542016-07-20 11:13:44 +120014676 TEST_DESCRIPTION("Test that an error is produced for a shader consuming a uniform "
14677 "block which has no corresponding binding in the pipeline layout");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014678 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "not declared in pipeline layout");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060014679
Chris Forbes556c76c2015-08-14 12:04:59 +120014680 ASSERT_NO_FATAL_FAILURE(InitState());
Chris Forbes556c76c2015-08-14 12:04:59 +120014681
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014682 char const *vsSource = "#version 450\n"
14683 "\n"
14684 "out gl_PerVertex {\n"
14685 " vec4 gl_Position;\n"
14686 "};\n"
14687 "void main(){\n"
14688 " gl_Position = vec4(1);\n"
14689 "}\n";
14690 char const *fsSource = "#version 450\n"
14691 "\n"
14692 "layout(location=0) out vec4 x;\n"
14693 "layout(set=0) layout(binding=0) uniform foo { int x; int y; } bar;\n"
14694 "void main(){\n"
14695 " x = vec4(bar.y);\n"
14696 "}\n";
Chris Forbes556c76c2015-08-14 12:04:59 +120014697
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060014698 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
14699 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbes556c76c2015-08-14 12:04:59 +120014700
Chris Forbes556c76c2015-08-14 12:04:59 +120014701 VkPipelineObj pipe(m_device);
14702 pipe.AddShader(&vs);
14703 pipe.AddShader(&fs);
14704
14705 /* set up CB 0; type is UNORM by default */
14706 pipe.AddColorAttachment();
14707 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
14708
14709 VkDescriptorSetObj descriptorSet(m_device);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014710 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbes556c76c2015-08-14 12:04:59 +120014711
14712 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
14713
Chris Forbes8f36a8a2016-04-07 13:21:07 +120014714 m_errorMonitor->VerifyFound();
Chris Forbes556c76c2015-08-14 12:04:59 +120014715}
14716
Chris Forbes5c59e902016-02-26 16:56:09 +130014717TEST_F(VkLayerTest, CreatePipelinePushConstantsNotInLayout) {
Chris Forbes1cc79542016-07-20 11:13:44 +120014718 TEST_DESCRIPTION("Test that an error is produced for a shader consuming push constants "
14719 "which are not provided in the pipeline layout");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014720 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "not declared in layout");
Chris Forbes5c59e902016-02-26 16:56:09 +130014721
14722 ASSERT_NO_FATAL_FAILURE(InitState());
14723
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014724 char const *vsSource = "#version 450\n"
14725 "\n"
14726 "layout(push_constant, std430) uniform foo { float x; } consts;\n"
14727 "out gl_PerVertex {\n"
14728 " vec4 gl_Position;\n"
14729 "};\n"
14730 "void main(){\n"
14731 " gl_Position = vec4(consts.x);\n"
14732 "}\n";
14733 char const *fsSource = "#version 450\n"
14734 "\n"
14735 "layout(location=0) out vec4 x;\n"
14736 "void main(){\n"
14737 " x = vec4(1);\n"
14738 "}\n";
Chris Forbes5c59e902016-02-26 16:56:09 +130014739
14740 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
14741 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
14742
14743 VkPipelineObj pipe(m_device);
14744 pipe.AddShader(&vs);
14745 pipe.AddShader(&fs);
14746
14747 /* set up CB 0; type is UNORM by default */
14748 pipe.AddColorAttachment();
14749 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
14750
14751 VkDescriptorSetObj descriptorSet(m_device);
14752 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
14753
14754 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
14755
14756 /* should have generated an error -- no push constant ranges provided! */
Chris Forbes8f36a8a2016-04-07 13:21:07 +120014757 m_errorMonitor->VerifyFound();
Chris Forbes5c59e902016-02-26 16:56:09 +130014758}
14759
Chris Forbes3fb17902016-08-22 14:57:55 +120014760TEST_F(VkLayerTest, CreatePipelineInputAttachmentMissing) {
14761 TEST_DESCRIPTION("Test that an error is produced for a shader consuming an input attachment "
14762 "which is not included in the subpass description");
14763 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
14764 "consumes input attachment index 0 but not provided in subpass");
14765
14766 ASSERT_NO_FATAL_FAILURE(InitState());
14767
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014768 char const *vsSource = "#version 450\n"
14769 "\n"
14770 "out gl_PerVertex {\n"
14771 " vec4 gl_Position;\n"
14772 "};\n"
14773 "void main(){\n"
14774 " gl_Position = vec4(1);\n"
14775 "}\n";
14776 char const *fsSource = "#version 450\n"
14777 "\n"
14778 "layout(input_attachment_index=0, set=0, binding=0) uniform subpassInput x;\n"
14779 "layout(location=0) out vec4 color;\n"
14780 "void main() {\n"
14781 " color = subpassLoad(x);\n"
14782 "}\n";
Chris Forbes3fb17902016-08-22 14:57:55 +120014783
14784 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
14785 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
14786
14787 VkPipelineObj pipe(m_device);
14788 pipe.AddShader(&vs);
14789 pipe.AddShader(&fs);
14790 pipe.AddColorAttachment();
14791 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
14792
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014793 VkDescriptorSetLayoutBinding dslb = {0, VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT, 1, VK_SHADER_STAGE_FRAGMENT_BIT, nullptr};
14794 VkDescriptorSetLayoutCreateInfo dslci = {VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dslb};
Chris Forbes3fb17902016-08-22 14:57:55 +120014795 VkDescriptorSetLayout dsl;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014796 VkResult err = vkCreateDescriptorSetLayout(m_device->device(), &dslci, nullptr, &dsl);
Chris Forbes3fb17902016-08-22 14:57:55 +120014797 ASSERT_VK_SUCCESS(err);
14798
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014799 VkPipelineLayoutCreateInfo plci = {VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dsl, 0, nullptr};
Chris Forbes3fb17902016-08-22 14:57:55 +120014800 VkPipelineLayout pl;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014801 err = vkCreatePipelineLayout(m_device->device(), &plci, nullptr, &pl);
Chris Forbes3fb17902016-08-22 14:57:55 +120014802 ASSERT_VK_SUCCESS(err);
14803
14804 // error here.
14805 pipe.CreateVKPipeline(pl, renderPass());
14806
14807 m_errorMonitor->VerifyFound();
14808
14809 vkDestroyPipelineLayout(m_device->device(), pl, nullptr);
14810 vkDestroyDescriptorSetLayout(m_device->device(), dsl, nullptr);
14811}
14812
Chris Forbes663b5a82016-08-22 16:14:06 +120014813TEST_F(VkLayerTest, CreatePipelineInputAttachmentPositive) {
14814 TEST_DESCRIPTION("Positive test for a correctly matched input attachment");
14815 m_errorMonitor->ExpectSuccess();
14816
14817 ASSERT_NO_FATAL_FAILURE(InitState());
14818
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014819 char const *vsSource = "#version 450\n"
14820 "\n"
14821 "out gl_PerVertex {\n"
14822 " vec4 gl_Position;\n"
14823 "};\n"
14824 "void main(){\n"
14825 " gl_Position = vec4(1);\n"
14826 "}\n";
14827 char const *fsSource = "#version 450\n"
14828 "\n"
14829 "layout(input_attachment_index=0, set=0, binding=0) uniform subpassInput x;\n"
14830 "layout(location=0) out vec4 color;\n"
14831 "void main() {\n"
14832 " color = subpassLoad(x);\n"
14833 "}\n";
Chris Forbes663b5a82016-08-22 16:14:06 +120014834
14835 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
14836 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
14837
14838 VkPipelineObj pipe(m_device);
14839 pipe.AddShader(&vs);
14840 pipe.AddShader(&fs);
14841 pipe.AddColorAttachment();
14842 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
14843
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014844 VkDescriptorSetLayoutBinding dslb = {0, VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT, 1, VK_SHADER_STAGE_FRAGMENT_BIT, nullptr};
14845 VkDescriptorSetLayoutCreateInfo dslci = {VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dslb};
Chris Forbes663b5a82016-08-22 16:14:06 +120014846 VkDescriptorSetLayout dsl;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014847 VkResult err = vkCreateDescriptorSetLayout(m_device->device(), &dslci, nullptr, &dsl);
Chris Forbes663b5a82016-08-22 16:14:06 +120014848 ASSERT_VK_SUCCESS(err);
14849
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014850 VkPipelineLayoutCreateInfo plci = {VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dsl, 0, nullptr};
Chris Forbes663b5a82016-08-22 16:14:06 +120014851 VkPipelineLayout pl;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014852 err = vkCreatePipelineLayout(m_device->device(), &plci, nullptr, &pl);
Chris Forbes663b5a82016-08-22 16:14:06 +120014853 ASSERT_VK_SUCCESS(err);
14854
14855 VkAttachmentDescription descs[2] = {
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014856 {0, VK_FORMAT_R8G8B8A8_UNORM, VK_SAMPLE_COUNT_1_BIT, VK_ATTACHMENT_LOAD_OP_LOAD, VK_ATTACHMENT_STORE_OP_STORE,
14857 VK_ATTACHMENT_LOAD_OP_LOAD, VK_ATTACHMENT_STORE_OP_STORE, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
14858 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL},
14859 {0, VK_FORMAT_R8G8B8A8_UNORM, VK_SAMPLE_COUNT_1_BIT, VK_ATTACHMENT_LOAD_OP_LOAD, VK_ATTACHMENT_STORE_OP_STORE,
14860 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 +120014861 };
14862 VkAttachmentReference color = {
14863 0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
14864 };
14865 VkAttachmentReference input = {
14866 1, VK_IMAGE_LAYOUT_GENERAL,
14867 };
14868
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014869 VkSubpassDescription sd = {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 1, &input, 1, &color, nullptr, nullptr, 0, nullptr};
Chris Forbes663b5a82016-08-22 16:14:06 +120014870
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014871 VkRenderPassCreateInfo rpci = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 2, descs, 1, &sd, 0, nullptr};
Chris Forbes663b5a82016-08-22 16:14:06 +120014872 VkRenderPass rp;
14873 err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
14874 ASSERT_VK_SUCCESS(err);
14875
14876 // should be OK. would go wrong here if it's going to...
14877 pipe.CreateVKPipeline(pl, rp);
14878
14879 m_errorMonitor->VerifyNotFound();
14880
14881 vkDestroyRenderPass(m_device->device(), rp, nullptr);
14882 vkDestroyPipelineLayout(m_device->device(), pl, nullptr);
14883 vkDestroyDescriptorSetLayout(m_device->device(), dsl, nullptr);
14884}
14885
Chris Forbes5a9a0472016-08-22 16:02:09 +120014886TEST_F(VkLayerTest, CreatePipelineInputAttachmentTypeMismatch) {
14887 TEST_DESCRIPTION("Test that an error is produced for a shader consuming an input attachment "
14888 "with a format having a different fundamental type");
14889 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
14890 "input attachment 0 format of VK_FORMAT_R8G8B8A8_UINT does not match");
14891
14892 ASSERT_NO_FATAL_FAILURE(InitState());
14893
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014894 char const *vsSource = "#version 450\n"
14895 "\n"
14896 "out gl_PerVertex {\n"
14897 " vec4 gl_Position;\n"
14898 "};\n"
14899 "void main(){\n"
14900 " gl_Position = vec4(1);\n"
14901 "}\n";
14902 char const *fsSource = "#version 450\n"
14903 "\n"
14904 "layout(input_attachment_index=0, set=0, binding=0) uniform subpassInput x;\n"
14905 "layout(location=0) out vec4 color;\n"
14906 "void main() {\n"
14907 " color = subpassLoad(x);\n"
14908 "}\n";
Chris Forbes5a9a0472016-08-22 16:02:09 +120014909
14910 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
14911 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
14912
14913 VkPipelineObj pipe(m_device);
14914 pipe.AddShader(&vs);
14915 pipe.AddShader(&fs);
14916 pipe.AddColorAttachment();
14917 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
14918
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014919 VkDescriptorSetLayoutBinding dslb = {0, VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT, 1, VK_SHADER_STAGE_FRAGMENT_BIT, nullptr};
14920 VkDescriptorSetLayoutCreateInfo dslci = {VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dslb};
Chris Forbes5a9a0472016-08-22 16:02:09 +120014921 VkDescriptorSetLayout dsl;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014922 VkResult err = vkCreateDescriptorSetLayout(m_device->device(), &dslci, nullptr, &dsl);
Chris Forbes5a9a0472016-08-22 16:02:09 +120014923 ASSERT_VK_SUCCESS(err);
14924
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014925 VkPipelineLayoutCreateInfo plci = {VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dsl, 0, nullptr};
Chris Forbes5a9a0472016-08-22 16:02:09 +120014926 VkPipelineLayout pl;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014927 err = vkCreatePipelineLayout(m_device->device(), &plci, nullptr, &pl);
Chris Forbes5a9a0472016-08-22 16:02:09 +120014928 ASSERT_VK_SUCCESS(err);
14929
14930 VkAttachmentDescription descs[2] = {
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014931 {0, VK_FORMAT_R8G8B8A8_UNORM, VK_SAMPLE_COUNT_1_BIT, VK_ATTACHMENT_LOAD_OP_LOAD, VK_ATTACHMENT_STORE_OP_STORE,
14932 VK_ATTACHMENT_LOAD_OP_LOAD, VK_ATTACHMENT_STORE_OP_STORE, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
14933 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL},
14934 {0, VK_FORMAT_R8G8B8A8_UINT, VK_SAMPLE_COUNT_1_BIT, VK_ATTACHMENT_LOAD_OP_LOAD, VK_ATTACHMENT_STORE_OP_STORE,
14935 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 +120014936 };
14937 VkAttachmentReference color = {
14938 0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
14939 };
14940 VkAttachmentReference input = {
14941 1, VK_IMAGE_LAYOUT_GENERAL,
14942 };
14943
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014944 VkSubpassDescription sd = {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 1, &input, 1, &color, nullptr, nullptr, 0, nullptr};
Chris Forbes5a9a0472016-08-22 16:02:09 +120014945
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014946 VkRenderPassCreateInfo rpci = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 2, descs, 1, &sd, 0, nullptr};
Chris Forbes5a9a0472016-08-22 16:02:09 +120014947 VkRenderPass rp;
14948 err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
14949 ASSERT_VK_SUCCESS(err);
14950
14951 // error here.
14952 pipe.CreateVKPipeline(pl, rp);
14953
14954 m_errorMonitor->VerifyFound();
14955
14956 vkDestroyRenderPass(m_device->device(), rp, nullptr);
14957 vkDestroyPipelineLayout(m_device->device(), pl, nullptr);
14958 vkDestroyDescriptorSetLayout(m_device->device(), dsl, nullptr);
14959}
14960
Chris Forbes541f7b02016-08-22 15:30:27 +120014961TEST_F(VkLayerTest, CreatePipelineInputAttachmentMissingArray) {
14962 TEST_DESCRIPTION("Test that an error is produced for a shader consuming an input attachment "
14963 "which is not included in the subpass description -- array case");
14964 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
14965 "consumes input attachment index 1 but not provided in subpass");
14966
14967 ASSERT_NO_FATAL_FAILURE(InitState());
14968
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014969 char const *vsSource = "#version 450\n"
14970 "\n"
14971 "out gl_PerVertex {\n"
14972 " vec4 gl_Position;\n"
14973 "};\n"
14974 "void main(){\n"
14975 " gl_Position = vec4(1);\n"
14976 "}\n";
14977 char const *fsSource = "#version 450\n"
14978 "\n"
14979 "layout(input_attachment_index=0, set=0, binding=0) uniform subpassInput xs[2];\n"
14980 "layout(location=0) out vec4 color;\n"
14981 "void main() {\n"
14982 " color = subpassLoad(xs[1]);\n"
14983 "}\n";
Chris Forbes541f7b02016-08-22 15:30:27 +120014984
14985 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
14986 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
14987
14988 VkPipelineObj pipe(m_device);
14989 pipe.AddShader(&vs);
14990 pipe.AddShader(&fs);
14991 pipe.AddColorAttachment();
14992 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
14993
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014994 VkDescriptorSetLayoutBinding dslb = {0, VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT, 2, VK_SHADER_STAGE_FRAGMENT_BIT, nullptr};
14995 VkDescriptorSetLayoutCreateInfo dslci = {VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dslb};
Chris Forbes541f7b02016-08-22 15:30:27 +120014996 VkDescriptorSetLayout dsl;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014997 VkResult err = vkCreateDescriptorSetLayout(m_device->device(), &dslci, nullptr, &dsl);
Chris Forbes541f7b02016-08-22 15:30:27 +120014998 ASSERT_VK_SUCCESS(err);
14999
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015000 VkPipelineLayoutCreateInfo plci = {VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dsl, 0, nullptr};
Chris Forbes541f7b02016-08-22 15:30:27 +120015001 VkPipelineLayout pl;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015002 err = vkCreatePipelineLayout(m_device->device(), &plci, nullptr, &pl);
Chris Forbes541f7b02016-08-22 15:30:27 +120015003 ASSERT_VK_SUCCESS(err);
15004
15005 // error here.
15006 pipe.CreateVKPipeline(pl, renderPass());
15007
15008 m_errorMonitor->VerifyFound();
15009
15010 vkDestroyPipelineLayout(m_device->device(), pl, nullptr);
15011 vkDestroyDescriptorSetLayout(m_device->device(), dsl, nullptr);
15012}
15013
Chris Forbes10eb9ae2016-05-31 16:09:42 +120015014TEST_F(VkLayerTest, CreateComputePipelineMissingDescriptor) {
Chris Forbes1cc79542016-07-20 11:13:44 +120015015 TEST_DESCRIPTION("Test that an error is produced for a compute pipeline consuming a "
15016 "descriptor which is not provided in the pipeline layout");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015017 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Shader uses descriptor slot 0.0");
Chris Forbes10eb9ae2016-05-31 16:09:42 +120015018
15019 ASSERT_NO_FATAL_FAILURE(InitState());
15020
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015021 char const *csSource = "#version 450\n"
15022 "\n"
15023 "layout(local_size_x=1) in;\n"
15024 "layout(set=0, binding=0) buffer block { vec4 x; };\n"
15025 "void main(){\n"
15026 " x = vec4(1);\n"
15027 "}\n";
Chris Forbes10eb9ae2016-05-31 16:09:42 +120015028
15029 VkShaderObj cs(m_device, csSource, VK_SHADER_STAGE_COMPUTE_BIT, this);
15030
15031 VkDescriptorSetObj descriptorSet(m_device);
15032 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
15033
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015034 VkComputePipelineCreateInfo cpci = {VK_STRUCTURE_TYPE_COMPUTE_PIPELINE_CREATE_INFO,
15035 nullptr,
15036 0,
15037 {VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO, nullptr, 0,
15038 VK_SHADER_STAGE_COMPUTE_BIT, cs.handle(), "main", nullptr},
15039 descriptorSet.GetPipelineLayout(),
15040 VK_NULL_HANDLE,
15041 -1};
Chris Forbes10eb9ae2016-05-31 16:09:42 +120015042
15043 VkPipeline pipe;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015044 VkResult err = vkCreateComputePipelines(m_device->device(), VK_NULL_HANDLE, 1, &cpci, nullptr, &pipe);
Chris Forbes10eb9ae2016-05-31 16:09:42 +120015045
15046 m_errorMonitor->VerifyFound();
15047
15048 if (err == VK_SUCCESS) {
15049 vkDestroyPipeline(m_device->device(), pipe, nullptr);
15050 }
15051}
15052
15053TEST_F(VkLayerTest, CreateComputePipelineMissingDescriptorUnusedPositive) {
Chris Forbes1cc79542016-07-20 11:13:44 +120015054 TEST_DESCRIPTION("Test that pipeline validation accepts a compute pipeline which declares a "
15055 "descriptor-backed resource which is not provided, but the shader does not "
15056 "statically use it. This is interesting because it requires compute pipelines "
15057 "to have a proper descriptor use walk, which they didn't for some time.");
Chris Forbes10eb9ae2016-05-31 16:09:42 +120015058 m_errorMonitor->ExpectSuccess();
15059
15060 ASSERT_NO_FATAL_FAILURE(InitState());
15061
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015062 char const *csSource = "#version 450\n"
15063 "\n"
15064 "layout(local_size_x=1) in;\n"
15065 "layout(set=0, binding=0) buffer block { vec4 x; };\n"
15066 "void main(){\n"
15067 " // x is not used.\n"
15068 "}\n";
Chris Forbes10eb9ae2016-05-31 16:09:42 +120015069
15070 VkShaderObj cs(m_device, csSource, VK_SHADER_STAGE_COMPUTE_BIT, this);
15071
15072 VkDescriptorSetObj descriptorSet(m_device);
15073 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
15074
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015075 VkComputePipelineCreateInfo cpci = {VK_STRUCTURE_TYPE_COMPUTE_PIPELINE_CREATE_INFO,
15076 nullptr,
15077 0,
15078 {VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO, nullptr, 0,
15079 VK_SHADER_STAGE_COMPUTE_BIT, cs.handle(), "main", nullptr},
15080 descriptorSet.GetPipelineLayout(),
15081 VK_NULL_HANDLE,
15082 -1};
Chris Forbes10eb9ae2016-05-31 16:09:42 +120015083
15084 VkPipeline pipe;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015085 VkResult err = vkCreateComputePipelines(m_device->device(), VK_NULL_HANDLE, 1, &cpci, nullptr, &pipe);
Chris Forbes10eb9ae2016-05-31 16:09:42 +120015086
15087 m_errorMonitor->VerifyNotFound();
15088
15089 if (err == VK_SUCCESS) {
15090 vkDestroyPipeline(m_device->device(), pipe, nullptr);
15091 }
15092}
15093
Chris Forbes22a9b092016-07-19 14:34:05 +120015094TEST_F(VkLayerTest, CreateComputePipelineDescriptorTypeMismatch) {
Chris Forbes1cc79542016-07-20 11:13:44 +120015095 TEST_DESCRIPTION("Test that an error is produced for a pipeline consuming a "
15096 "descriptor-backed resource of a mismatched type");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015097 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
15098 "but descriptor of type VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER");
Chris Forbes22a9b092016-07-19 14:34:05 +120015099
15100 ASSERT_NO_FATAL_FAILURE(InitState());
15101
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015102 VkDescriptorSetLayoutBinding binding = {0, VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, 1, VK_SHADER_STAGE_COMPUTE_BIT, nullptr};
15103 VkDescriptorSetLayoutCreateInfo dslci = {VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO, nullptr, 0, 1, &binding};
Chris Forbes22a9b092016-07-19 14:34:05 +120015104 VkDescriptorSetLayout dsl;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015105 VkResult err = vkCreateDescriptorSetLayout(m_device->device(), &dslci, nullptr, &dsl);
Chris Forbes22a9b092016-07-19 14:34:05 +120015106 ASSERT_VK_SUCCESS(err);
15107
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015108 VkPipelineLayoutCreateInfo plci = {VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dsl, 0, nullptr};
Chris Forbes22a9b092016-07-19 14:34:05 +120015109 VkPipelineLayout pl;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015110 err = vkCreatePipelineLayout(m_device->device(), &plci, nullptr, &pl);
Chris Forbes22a9b092016-07-19 14:34:05 +120015111 ASSERT_VK_SUCCESS(err);
15112
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015113 char const *csSource = "#version 450\n"
15114 "\n"
15115 "layout(local_size_x=1) in;\n"
15116 "layout(set=0, binding=0) buffer block { vec4 x; };\n"
15117 "void main() {\n"
15118 " x.x = 1.0f;\n"
15119 "}\n";
Chris Forbes22a9b092016-07-19 14:34:05 +120015120 VkShaderObj cs(m_device, csSource, VK_SHADER_STAGE_COMPUTE_BIT, this);
15121
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015122 VkComputePipelineCreateInfo cpci = {VK_STRUCTURE_TYPE_COMPUTE_PIPELINE_CREATE_INFO,
15123 nullptr,
15124 0,
15125 {VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO, nullptr, 0,
15126 VK_SHADER_STAGE_COMPUTE_BIT, cs.handle(), "main", nullptr},
15127 pl,
15128 VK_NULL_HANDLE,
15129 -1};
Chris Forbes22a9b092016-07-19 14:34:05 +120015130
15131 VkPipeline pipe;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015132 err = vkCreateComputePipelines(m_device->device(), VK_NULL_HANDLE, 1, &cpci, nullptr, &pipe);
Chris Forbes22a9b092016-07-19 14:34:05 +120015133
15134 m_errorMonitor->VerifyFound();
15135
15136 if (err == VK_SUCCESS) {
15137 vkDestroyPipeline(m_device->device(), pipe, nullptr);
15138 }
15139
15140 vkDestroyPipelineLayout(m_device->device(), pl, nullptr);
15141 vkDestroyDescriptorSetLayout(m_device->device(), dsl, nullptr);
15142}
15143
Chris Forbese10a51f2016-07-19 14:42:51 +120015144TEST_F(VkLayerTest, CreateComputePipelineCombinedImageSamplerConsumedAsSampler) {
Chris Forbes1cc79542016-07-20 11:13:44 +120015145 TEST_DESCRIPTION("Test that pipeline validation accepts a shader consuming only the "
15146 "sampler portion of a combined image + sampler");
Chris Forbese10a51f2016-07-19 14:42:51 +120015147 m_errorMonitor->ExpectSuccess();
15148
15149 ASSERT_NO_FATAL_FAILURE(InitState());
15150
15151 VkDescriptorSetLayoutBinding bindings[] = {
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015152 {0, VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, 1, VK_SHADER_STAGE_COMPUTE_BIT, nullptr},
15153 {1, VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE, 1, VK_SHADER_STAGE_COMPUTE_BIT, nullptr},
15154 {2, VK_DESCRIPTOR_TYPE_STORAGE_BUFFER, 1, VK_SHADER_STAGE_COMPUTE_BIT, nullptr},
Chris Forbese10a51f2016-07-19 14:42:51 +120015155 };
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015156 VkDescriptorSetLayoutCreateInfo dslci = {VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO, nullptr, 0, 3, bindings};
Chris Forbese10a51f2016-07-19 14:42:51 +120015157 VkDescriptorSetLayout dsl;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015158 VkResult err = vkCreateDescriptorSetLayout(m_device->device(), &dslci, nullptr, &dsl);
Chris Forbese10a51f2016-07-19 14:42:51 +120015159 ASSERT_VK_SUCCESS(err);
15160
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015161 VkPipelineLayoutCreateInfo plci = {VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dsl, 0, nullptr};
Chris Forbese10a51f2016-07-19 14:42:51 +120015162 VkPipelineLayout pl;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015163 err = vkCreatePipelineLayout(m_device->device(), &plci, nullptr, &pl);
Chris Forbese10a51f2016-07-19 14:42:51 +120015164 ASSERT_VK_SUCCESS(err);
15165
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015166 char const *csSource = "#version 450\n"
15167 "\n"
15168 "layout(local_size_x=1) in;\n"
15169 "layout(set=0, binding=0) uniform sampler s;\n"
15170 "layout(set=0, binding=1) uniform texture2D t;\n"
15171 "layout(set=0, binding=2) buffer block { vec4 x; };\n"
15172 "void main() {\n"
15173 " x = texture(sampler2D(t, s), vec2(0));\n"
15174 "}\n";
Chris Forbese10a51f2016-07-19 14:42:51 +120015175 VkShaderObj cs(m_device, csSource, VK_SHADER_STAGE_COMPUTE_BIT, this);
15176
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015177 VkComputePipelineCreateInfo cpci = {VK_STRUCTURE_TYPE_COMPUTE_PIPELINE_CREATE_INFO,
15178 nullptr,
15179 0,
15180 {VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO, nullptr, 0,
15181 VK_SHADER_STAGE_COMPUTE_BIT, cs.handle(), "main", nullptr},
15182 pl,
15183 VK_NULL_HANDLE,
15184 -1};
Chris Forbese10a51f2016-07-19 14:42:51 +120015185
15186 VkPipeline pipe;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015187 err = vkCreateComputePipelines(m_device->device(), VK_NULL_HANDLE, 1, &cpci, nullptr, &pipe);
Chris Forbese10a51f2016-07-19 14:42:51 +120015188
15189 m_errorMonitor->VerifyNotFound();
15190
15191 if (err == VK_SUCCESS) {
15192 vkDestroyPipeline(m_device->device(), pipe, nullptr);
15193 }
15194
15195 vkDestroyPipelineLayout(m_device->device(), pl, nullptr);
15196 vkDestroyDescriptorSetLayout(m_device->device(), dsl, nullptr);
15197}
15198
Chris Forbes91c3b2a2016-07-19 14:46:38 +120015199TEST_F(VkLayerTest, CreateComputePipelineCombinedImageSamplerConsumedAsImage) {
Chris Forbes1cc79542016-07-20 11:13:44 +120015200 TEST_DESCRIPTION("Test that pipeline validation accepts a shader consuming only the "
15201 "image portion of a combined image + sampler");
Chris Forbes91c3b2a2016-07-19 14:46:38 +120015202 m_errorMonitor->ExpectSuccess();
15203
15204 ASSERT_NO_FATAL_FAILURE(InitState());
15205
15206 VkDescriptorSetLayoutBinding bindings[] = {
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015207 {0, VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, 1, VK_SHADER_STAGE_COMPUTE_BIT, nullptr},
15208 {1, VK_DESCRIPTOR_TYPE_SAMPLER, 1, VK_SHADER_STAGE_COMPUTE_BIT, nullptr},
15209 {2, VK_DESCRIPTOR_TYPE_STORAGE_BUFFER, 1, VK_SHADER_STAGE_COMPUTE_BIT, nullptr},
Chris Forbes91c3b2a2016-07-19 14:46:38 +120015210 };
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015211 VkDescriptorSetLayoutCreateInfo dslci = {VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO, nullptr, 0, 3, bindings};
Chris Forbes91c3b2a2016-07-19 14:46:38 +120015212 VkDescriptorSetLayout dsl;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015213 VkResult err = vkCreateDescriptorSetLayout(m_device->device(), &dslci, nullptr, &dsl);
Chris Forbes91c3b2a2016-07-19 14:46:38 +120015214 ASSERT_VK_SUCCESS(err);
15215
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015216 VkPipelineLayoutCreateInfo plci = {VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dsl, 0, nullptr};
Chris Forbes91c3b2a2016-07-19 14:46:38 +120015217 VkPipelineLayout pl;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015218 err = vkCreatePipelineLayout(m_device->device(), &plci, nullptr, &pl);
Chris Forbes91c3b2a2016-07-19 14:46:38 +120015219 ASSERT_VK_SUCCESS(err);
15220
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015221 char const *csSource = "#version 450\n"
15222 "\n"
15223 "layout(local_size_x=1) in;\n"
15224 "layout(set=0, binding=0) uniform texture2D t;\n"
15225 "layout(set=0, binding=1) uniform sampler s;\n"
15226 "layout(set=0, binding=2) buffer block { vec4 x; };\n"
15227 "void main() {\n"
15228 " x = texture(sampler2D(t, s), vec2(0));\n"
15229 "}\n";
Chris Forbes91c3b2a2016-07-19 14:46:38 +120015230 VkShaderObj cs(m_device, csSource, VK_SHADER_STAGE_COMPUTE_BIT, this);
15231
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015232 VkComputePipelineCreateInfo cpci = {VK_STRUCTURE_TYPE_COMPUTE_PIPELINE_CREATE_INFO,
15233 nullptr,
15234 0,
15235 {VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO, nullptr, 0,
15236 VK_SHADER_STAGE_COMPUTE_BIT, cs.handle(), "main", nullptr},
15237 pl,
15238 VK_NULL_HANDLE,
15239 -1};
Chris Forbes91c3b2a2016-07-19 14:46:38 +120015240
15241 VkPipeline pipe;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015242 err = vkCreateComputePipelines(m_device->device(), VK_NULL_HANDLE, 1, &cpci, nullptr, &pipe);
Chris Forbes91c3b2a2016-07-19 14:46:38 +120015243
15244 m_errorMonitor->VerifyNotFound();
15245
15246 if (err == VK_SUCCESS) {
15247 vkDestroyPipeline(m_device->device(), pipe, nullptr);
15248 }
15249
15250 vkDestroyPipelineLayout(m_device->device(), pl, nullptr);
15251 vkDestroyDescriptorSetLayout(m_device->device(), dsl, nullptr);
15252}
15253
Chris Forbes6a4991a2016-07-19 15:07:32 +120015254TEST_F(VkLayerTest, CreateComputePipelineCombinedImageSamplerConsumedAsBoth) {
Chris Forbes1cc79542016-07-20 11:13:44 +120015255 TEST_DESCRIPTION("Test that pipeline validation accepts a shader consuming "
15256 "both the sampler and the image of a combined image+sampler "
15257 "but via separate variables");
Chris Forbes6a4991a2016-07-19 15:07:32 +120015258 m_errorMonitor->ExpectSuccess();
15259
15260 ASSERT_NO_FATAL_FAILURE(InitState());
15261
15262 VkDescriptorSetLayoutBinding bindings[] = {
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015263 {0, VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, 1, VK_SHADER_STAGE_COMPUTE_BIT, nullptr},
15264 {1, VK_DESCRIPTOR_TYPE_STORAGE_BUFFER, 1, VK_SHADER_STAGE_COMPUTE_BIT, nullptr},
Chris Forbes6a4991a2016-07-19 15:07:32 +120015265 };
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015266 VkDescriptorSetLayoutCreateInfo dslci = {VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO, nullptr, 0, 2, bindings};
Chris Forbes6a4991a2016-07-19 15:07:32 +120015267 VkDescriptorSetLayout dsl;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015268 VkResult err = vkCreateDescriptorSetLayout(m_device->device(), &dslci, nullptr, &dsl);
Chris Forbes6a4991a2016-07-19 15:07:32 +120015269 ASSERT_VK_SUCCESS(err);
15270
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015271 VkPipelineLayoutCreateInfo plci = {VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dsl, 0, nullptr};
Chris Forbes6a4991a2016-07-19 15:07:32 +120015272 VkPipelineLayout pl;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015273 err = vkCreatePipelineLayout(m_device->device(), &plci, nullptr, &pl);
Chris Forbes6a4991a2016-07-19 15:07:32 +120015274 ASSERT_VK_SUCCESS(err);
15275
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015276 char const *csSource = "#version 450\n"
15277 "\n"
15278 "layout(local_size_x=1) in;\n"
15279 "layout(set=0, binding=0) uniform texture2D t;\n"
15280 "layout(set=0, binding=0) uniform sampler s; // both binding 0!\n"
15281 "layout(set=0, binding=1) buffer block { vec4 x; };\n"
15282 "void main() {\n"
15283 " x = texture(sampler2D(t, s), vec2(0));\n"
15284 "}\n";
Chris Forbes6a4991a2016-07-19 15:07:32 +120015285 VkShaderObj cs(m_device, csSource, VK_SHADER_STAGE_COMPUTE_BIT, this);
15286
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015287 VkComputePipelineCreateInfo cpci = {VK_STRUCTURE_TYPE_COMPUTE_PIPELINE_CREATE_INFO,
15288 nullptr,
15289 0,
15290 {VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO, nullptr, 0,
15291 VK_SHADER_STAGE_COMPUTE_BIT, cs.handle(), "main", nullptr},
15292 pl,
15293 VK_NULL_HANDLE,
15294 -1};
Chris Forbes6a4991a2016-07-19 15:07:32 +120015295
15296 VkPipeline pipe;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015297 err = vkCreateComputePipelines(m_device->device(), VK_NULL_HANDLE, 1, &cpci, nullptr, &pipe);
Chris Forbes6a4991a2016-07-19 15:07:32 +120015298
15299 m_errorMonitor->VerifyNotFound();
15300
15301 if (err == VK_SUCCESS) {
15302 vkDestroyPipeline(m_device->device(), pipe, nullptr);
15303 }
15304
15305 vkDestroyPipelineLayout(m_device->device(), pl, nullptr);
15306 vkDestroyDescriptorSetLayout(m_device->device(), dsl, nullptr);
15307}
15308
Chris Forbes50020592016-07-27 13:52:41 +120015309TEST_F(VkLayerTest, DrawTimeImageViewTypeMismatchWithPipeline) {
15310 TEST_DESCRIPTION("Test that an error is produced when an image view type "
15311 "does not match the dimensionality declared in the shader");
15312
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015313 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 +120015314
15315 ASSERT_NO_FATAL_FAILURE(InitState());
15316 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
15317
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015318 char const *vsSource = "#version 450\n"
15319 "\n"
15320 "out gl_PerVertex { vec4 gl_Position; };\n"
15321 "void main() { gl_Position = vec4(0); }\n";
15322 char const *fsSource = "#version 450\n"
15323 "\n"
15324 "layout(set=0, binding=0) uniform sampler3D s;\n"
15325 "layout(location=0) out vec4 color;\n"
15326 "void main() {\n"
15327 " color = texture(s, vec3(0));\n"
15328 "}\n";
Chris Forbes50020592016-07-27 13:52:41 +120015329 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
15330 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
15331
15332 VkPipelineObj pipe(m_device);
15333 pipe.AddShader(&vs);
15334 pipe.AddShader(&fs);
15335 pipe.AddColorAttachment();
15336
15337 VkTextureObj texture(m_device, nullptr);
15338 VkSamplerObj sampler(m_device);
15339
15340 VkDescriptorSetObj descriptorSet(m_device);
15341 descriptorSet.AppendSamplerTexture(&sampler, &texture);
15342 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
15343
15344 VkResult err = pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
15345 ASSERT_VK_SUCCESS(err);
15346
15347 BeginCommandBuffer();
15348
15349 m_commandBuffer->BindPipeline(pipe);
15350 m_commandBuffer->BindDescriptorSet(descriptorSet);
15351
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015352 VkViewport viewport = {0, 0, 16, 16, 0, 1};
Chris Forbes50020592016-07-27 13:52:41 +120015353 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015354 VkRect2D scissor = {{0, 0}, {16, 16}};
Chris Forbes50020592016-07-27 13:52:41 +120015355 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
15356
15357 // error produced here.
15358 vkCmdDraw(m_commandBuffer->handle(), 3, 1, 0, 0);
15359
15360 m_errorMonitor->VerifyFound();
15361
15362 EndCommandBuffer();
15363}
15364
Chris Forbes5533bfc2016-07-27 14:12:34 +120015365TEST_F(VkLayerTest, DrawTimeImageMultisampleMismatchWithPipeline) {
15366 TEST_DESCRIPTION("Test that an error is produced when a multisampled images "
15367 "are consumed via singlesample images types in the shader, or vice versa.");
15368
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015369 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "requires bound image to have multiple samples");
Chris Forbes5533bfc2016-07-27 14:12:34 +120015370
15371 ASSERT_NO_FATAL_FAILURE(InitState());
15372 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
15373
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015374 char const *vsSource = "#version 450\n"
15375 "\n"
15376 "out gl_PerVertex { vec4 gl_Position; };\n"
15377 "void main() { gl_Position = vec4(0); }\n";
15378 char const *fsSource = "#version 450\n"
15379 "\n"
15380 "layout(set=0, binding=0) uniform sampler2DMS s;\n"
15381 "layout(location=0) out vec4 color;\n"
15382 "void main() {\n"
15383 " color = texelFetch(s, ivec2(0), 0);\n"
15384 "}\n";
Chris Forbes5533bfc2016-07-27 14:12:34 +120015385 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
15386 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
15387
15388 VkPipelineObj pipe(m_device);
15389 pipe.AddShader(&vs);
15390 pipe.AddShader(&fs);
15391 pipe.AddColorAttachment();
15392
15393 VkTextureObj texture(m_device, nullptr);
15394 VkSamplerObj sampler(m_device);
15395
15396 VkDescriptorSetObj descriptorSet(m_device);
15397 descriptorSet.AppendSamplerTexture(&sampler, &texture);
15398 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
15399
15400 VkResult err = pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
15401 ASSERT_VK_SUCCESS(err);
15402
15403 BeginCommandBuffer();
15404
15405 m_commandBuffer->BindPipeline(pipe);
15406 m_commandBuffer->BindDescriptorSet(descriptorSet);
15407
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015408 VkViewport viewport = {0, 0, 16, 16, 0, 1};
Chris Forbes5533bfc2016-07-27 14:12:34 +120015409 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015410 VkRect2D scissor = {{0, 0}, {16, 16}};
Chris Forbes5533bfc2016-07-27 14:12:34 +120015411 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
15412
15413 // error produced here.
15414 vkCmdDraw(m_commandBuffer->handle(), 3, 1, 0, 0);
15415
15416 m_errorMonitor->VerifyFound();
15417
15418 EndCommandBuffer();
15419}
15420
Mark Lobodzinski209b5292015-09-17 09:44:05 -060015421#endif // SHADER_CHECKER_TESTS
15422
15423#if DEVICE_LIMITS_TESTS
Mark Youngc48c4c12016-04-11 14:26:49 -060015424TEST_F(VkLayerTest, CreateImageLimitsViolationMaxWidth) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015425 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "CreateImage extents exceed allowable limits for format");
Mark Lobodzinski6f2274e2015-09-22 09:33:21 -060015426
15427 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinski6f2274e2015-09-22 09:33:21 -060015428
15429 // Create an image
15430 VkImage image;
15431
Karl Schultz6addd812016-02-02 17:17:23 -070015432 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
15433 const int32_t tex_width = 32;
15434 const int32_t tex_height = 32;
Mark Lobodzinski6f2274e2015-09-22 09:33:21 -060015435
15436 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070015437 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
15438 image_create_info.pNext = NULL;
15439 image_create_info.imageType = VK_IMAGE_TYPE_2D;
15440 image_create_info.format = tex_format;
15441 image_create_info.extent.width = tex_width;
Mark Lobodzinski6f2274e2015-09-22 09:33:21 -060015442 image_create_info.extent.height = tex_height;
Karl Schultz6addd812016-02-02 17:17:23 -070015443 image_create_info.extent.depth = 1;
15444 image_create_info.mipLevels = 1;
15445 image_create_info.arrayLayers = 1;
15446 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
15447 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
15448 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
15449 image_create_info.flags = 0;
Mark Lobodzinski6f2274e2015-09-22 09:33:21 -060015450
15451 // Introduce error by sending down a bogus width extent
15452 image_create_info.extent.width = 65536;
Chia-I Wuf7458c52015-10-26 21:10:41 +080015453 vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
Mark Lobodzinski6f2274e2015-09-22 09:33:21 -060015454
Chris Forbes8f36a8a2016-04-07 13:21:07 +120015455 m_errorMonitor->VerifyFound();
Mark Lobodzinski6f2274e2015-09-22 09:33:21 -060015456}
15457
Mark Youngc48c4c12016-04-11 14:26:49 -060015458TEST_F(VkLayerTest, CreateImageLimitsViolationMinWidth) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015459 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
15460 "CreateImage extents is 0 for at least one required dimension");
Mark Youngc48c4c12016-04-11 14:26:49 -060015461
15462 ASSERT_NO_FATAL_FAILURE(InitState());
15463
15464 // Create an image
15465 VkImage image;
15466
15467 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
15468 const int32_t tex_width = 32;
15469 const int32_t tex_height = 32;
15470
15471 VkImageCreateInfo image_create_info = {};
15472 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
15473 image_create_info.pNext = NULL;
15474 image_create_info.imageType = VK_IMAGE_TYPE_2D;
15475 image_create_info.format = tex_format;
15476 image_create_info.extent.width = tex_width;
15477 image_create_info.extent.height = tex_height;
15478 image_create_info.extent.depth = 1;
15479 image_create_info.mipLevels = 1;
15480 image_create_info.arrayLayers = 1;
15481 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
15482 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
15483 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
15484 image_create_info.flags = 0;
15485
15486 // Introduce error by sending down a bogus width extent
15487 image_create_info.extent.width = 0;
15488 vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
15489
15490 m_errorMonitor->VerifyFound();
15491}
Mark Lobodzinski209b5292015-09-17 09:44:05 -060015492#endif // DEVICE_LIMITS_TESTS
Chris Forbesa36d69e2015-05-25 11:13:44 +120015493
Tobin Ehliscde08892015-09-22 10:11:37 -060015494#if IMAGE_TESTS
Mark Lobodzinskidf4c57d2016-08-05 11:47:16 -060015495TEST_F(VkLayerTest, AttachmentDescriptionUndefinedFormat) {
15496 TEST_DESCRIPTION("Create a render pass with an attachment description "
15497 "format set to VK_FORMAT_UNDEFINED");
15498
15499 ASSERT_NO_FATAL_FAILURE(InitState());
15500 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
15501
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015502 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "format is VK_FORMAT_UNDEFINED");
Mark Lobodzinskidf4c57d2016-08-05 11:47:16 -060015503
15504 VkAttachmentReference color_attach = {};
15505 color_attach.layout = VK_IMAGE_LAYOUT_GENERAL;
15506 color_attach.attachment = 0;
15507 VkSubpassDescription subpass = {};
15508 subpass.colorAttachmentCount = 1;
15509 subpass.pColorAttachments = &color_attach;
15510
15511 VkRenderPassCreateInfo rpci = {};
15512 rpci.subpassCount = 1;
15513 rpci.pSubpasses = &subpass;
15514 rpci.attachmentCount = 1;
15515 VkAttachmentDescription attach_desc = {};
15516 attach_desc.format = VK_FORMAT_UNDEFINED;
15517 rpci.pAttachments = &attach_desc;
15518 rpci.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
15519 VkRenderPass rp;
15520 VkResult result = vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
15521
15522 m_errorMonitor->VerifyFound();
15523
15524 if (result == VK_SUCCESS) {
15525 vkDestroyRenderPass(m_device->device(), rp, NULL);
15526 }
15527}
15528
Karl Schultz6addd812016-02-02 17:17:23 -070015529TEST_F(VkLayerTest, InvalidImageView) {
15530 VkResult err;
Tobin Ehliscde08892015-09-22 10:11:37 -060015531
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015532 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "vkCreateImageView called with baseMipLevel 10 ");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060015533
Tobin Ehliscde08892015-09-22 10:11:37 -060015534 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehliscde08892015-09-22 10:11:37 -060015535
Mike Stroyana3082432015-09-25 13:39:21 -060015536 // Create an image and try to create a view with bad baseMipLevel
Karl Schultz6addd812016-02-02 17:17:23 -070015537 VkImage image;
Tobin Ehliscde08892015-09-22 10:11:37 -060015538
Karl Schultz6addd812016-02-02 17:17:23 -070015539 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
15540 const int32_t tex_width = 32;
15541 const int32_t tex_height = 32;
Tobin Ehliscde08892015-09-22 10:11:37 -060015542
15543 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070015544 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
15545 image_create_info.pNext = NULL;
15546 image_create_info.imageType = VK_IMAGE_TYPE_2D;
15547 image_create_info.format = tex_format;
15548 image_create_info.extent.width = tex_width;
15549 image_create_info.extent.height = tex_height;
15550 image_create_info.extent.depth = 1;
15551 image_create_info.mipLevels = 1;
15552 image_create_info.arrayLayers = 1;
15553 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
15554 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
15555 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
15556 image_create_info.flags = 0;
Tobin Ehliscde08892015-09-22 10:11:37 -060015557
Chia-I Wuf7458c52015-10-26 21:10:41 +080015558 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
Tobin Ehliscde08892015-09-22 10:11:37 -060015559 ASSERT_VK_SUCCESS(err);
15560
15561 VkImageViewCreateInfo image_view_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070015562 image_view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
15563 image_view_create_info.image = image;
15564 image_view_create_info.viewType = VK_IMAGE_VIEW_TYPE_2D;
15565 image_view_create_info.format = tex_format;
15566 image_view_create_info.subresourceRange.layerCount = 1;
15567 image_view_create_info.subresourceRange.baseMipLevel = 10; // cause an error
15568 image_view_create_info.subresourceRange.levelCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015569 image_view_create_info.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Tobin Ehliscde08892015-09-22 10:11:37 -060015570
15571 VkImageView view;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015572 err = vkCreateImageView(m_device->device(), &image_view_create_info, NULL, &view);
Tobin Ehliscde08892015-09-22 10:11:37 -060015573
Chris Forbes8f36a8a2016-04-07 13:21:07 +120015574 m_errorMonitor->VerifyFound();
Tony Barbourdf4c0042016-06-01 15:55:43 -060015575 vkDestroyImage(m_device->device(), image, NULL);
Tobin Ehliscde08892015-09-22 10:11:37 -060015576}
Mike Stroyana3082432015-09-25 13:39:21 -060015577
Mark Youngd339ba32016-05-30 13:28:35 -060015578TEST_F(VkLayerTest, CreateImageViewNoMemoryBoundToImage) {
15579 VkResult err;
15580
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015581 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "used without first calling vkBindImageMemory");
Mark Youngd339ba32016-05-30 13:28:35 -060015582
15583 ASSERT_NO_FATAL_FAILURE(InitState());
15584
15585 // Create an image and try to create a view with no memory backing the image
15586 VkImage image;
15587
15588 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
15589 const int32_t tex_width = 32;
15590 const int32_t tex_height = 32;
15591
15592 VkImageCreateInfo image_create_info = {};
15593 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
15594 image_create_info.pNext = NULL;
15595 image_create_info.imageType = VK_IMAGE_TYPE_2D;
15596 image_create_info.format = tex_format;
15597 image_create_info.extent.width = tex_width;
15598 image_create_info.extent.height = tex_height;
15599 image_create_info.extent.depth = 1;
15600 image_create_info.mipLevels = 1;
15601 image_create_info.arrayLayers = 1;
15602 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
15603 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
15604 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
15605 image_create_info.flags = 0;
15606
15607 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
15608 ASSERT_VK_SUCCESS(err);
15609
15610 VkImageViewCreateInfo image_view_create_info = {};
15611 image_view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
15612 image_view_create_info.image = image;
15613 image_view_create_info.viewType = VK_IMAGE_VIEW_TYPE_2D;
15614 image_view_create_info.format = tex_format;
15615 image_view_create_info.subresourceRange.layerCount = 1;
15616 image_view_create_info.subresourceRange.baseMipLevel = 0;
15617 image_view_create_info.subresourceRange.levelCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015618 image_view_create_info.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mark Youngd339ba32016-05-30 13:28:35 -060015619
15620 VkImageView view;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015621 err = vkCreateImageView(m_device->device(), &image_view_create_info, NULL, &view);
Mark Youngd339ba32016-05-30 13:28:35 -060015622
15623 m_errorMonitor->VerifyFound();
15624 vkDestroyImage(m_device->device(), image, NULL);
15625 // If last error is success, it still created the view, so delete it.
15626 if (err == VK_SUCCESS) {
15627 vkDestroyImageView(m_device->device(), view, NULL);
15628 }
Mark Youngd339ba32016-05-30 13:28:35 -060015629}
15630
Karl Schultz6addd812016-02-02 17:17:23 -070015631TEST_F(VkLayerTest, InvalidImageViewAspect) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015632 TEST_DESCRIPTION("Create an image and try to create a view with an invalid aspectMask");
15633 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "vkCreateImageView: Color image "
15634 "formats must have ONLY the "
15635 "VK_IMAGE_ASPECT_COLOR_BIT set");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060015636
Mark Lobodzinskidc86b852015-10-23 14:20:31 -060015637 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinskidc86b852015-10-23 14:20:31 -060015638
Karl Schultz6addd812016-02-02 17:17:23 -070015639 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
Tobin Ehlis1f567a22016-05-25 16:15:18 -060015640 VkImageObj image(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015641 image.init(32, 32, tex_format, VK_IMAGE_USAGE_SAMPLED_BIT, VK_IMAGE_TILING_LINEAR, 0);
Tobin Ehlis1f567a22016-05-25 16:15:18 -060015642 ASSERT_TRUE(image.initialized());
Mark Lobodzinskidc86b852015-10-23 14:20:31 -060015643
15644 VkImageViewCreateInfo image_view_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070015645 image_view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
Tobin Ehlis1f567a22016-05-25 16:15:18 -060015646 image_view_create_info.image = image.handle();
Karl Schultz6addd812016-02-02 17:17:23 -070015647 image_view_create_info.viewType = VK_IMAGE_VIEW_TYPE_2D;
15648 image_view_create_info.format = tex_format;
15649 image_view_create_info.subresourceRange.baseMipLevel = 0;
15650 image_view_create_info.subresourceRange.levelCount = 1;
15651 // Cause an error by setting an invalid image aspect
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015652 image_view_create_info.subresourceRange.aspectMask = VK_IMAGE_ASPECT_METADATA_BIT;
Mark Lobodzinskidc86b852015-10-23 14:20:31 -060015653
15654 VkImageView view;
Tobin Ehlis1f567a22016-05-25 16:15:18 -060015655 vkCreateImageView(m_device->device(), &image_view_create_info, NULL, &view);
Mark Lobodzinskidc86b852015-10-23 14:20:31 -060015656
Chris Forbes8f36a8a2016-04-07 13:21:07 +120015657 m_errorMonitor->VerifyFound();
Mark Lobodzinskidc86b852015-10-23 14:20:31 -060015658}
15659
Mark Lobodzinskidb117632016-03-31 10:45:56 -060015660TEST_F(VkLayerTest, CopyImageLayerCountMismatch) {
Karl Schultz6addd812016-02-02 17:17:23 -070015661 VkResult err;
15662 bool pass;
Mike Stroyana3082432015-09-25 13:39:21 -060015663
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015664 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
15665 "vkCmdCopyImage: number of layers in source and destination subresources for pRegions");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060015666
Mike Stroyana3082432015-09-25 13:39:21 -060015667 ASSERT_NO_FATAL_FAILURE(InitState());
Mike Stroyana3082432015-09-25 13:39:21 -060015668
15669 // Create two images of different types and try to copy between them
Karl Schultz6addd812016-02-02 17:17:23 -070015670 VkImage srcImage;
15671 VkImage dstImage;
15672 VkDeviceMemory srcMem;
15673 VkDeviceMemory destMem;
15674 VkMemoryRequirements memReqs;
Mike Stroyana3082432015-09-25 13:39:21 -060015675
15676 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070015677 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
15678 image_create_info.pNext = NULL;
15679 image_create_info.imageType = VK_IMAGE_TYPE_2D;
15680 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
15681 image_create_info.extent.width = 32;
15682 image_create_info.extent.height = 32;
15683 image_create_info.extent.depth = 1;
15684 image_create_info.mipLevels = 1;
Mark Lobodzinskidb117632016-03-31 10:45:56 -060015685 image_create_info.arrayLayers = 4;
Karl Schultz6addd812016-02-02 17:17:23 -070015686 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
15687 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
15688 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
15689 image_create_info.flags = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060015690
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015691 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
Mike Stroyana3082432015-09-25 13:39:21 -060015692 ASSERT_VK_SUCCESS(err);
15693
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015694 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
Mike Stroyana3082432015-09-25 13:39:21 -060015695 ASSERT_VK_SUCCESS(err);
15696
15697 // Allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015698 VkMemoryAllocateInfo memAlloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -070015699 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
15700 memAlloc.pNext = NULL;
15701 memAlloc.allocationSize = 0;
15702 memAlloc.memoryTypeIndex = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060015703
Courtney Goeltzenleuchter06d89472015-10-20 16:40:38 -060015704 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060015705 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015706 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060015707 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015708 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
Mike Stroyana3082432015-09-25 13:39:21 -060015709 ASSERT_VK_SUCCESS(err);
15710
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015711 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060015712 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015713 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Mike Stroyana3082432015-09-25 13:39:21 -060015714 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015715 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
Mike Stroyana3082432015-09-25 13:39:21 -060015716 ASSERT_VK_SUCCESS(err);
15717
15718 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
15719 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015720 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
Mike Stroyana3082432015-09-25 13:39:21 -060015721 ASSERT_VK_SUCCESS(err);
15722
15723 BeginCommandBuffer();
15724 VkImageCopy copyRegion;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080015725 copyRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060015726 copyRegion.srcSubresource.mipLevel = 0;
Courtney Goeltzenleuchter8367ce02015-10-16 09:46:00 -060015727 copyRegion.srcSubresource.baseArrayLayer = 0;
Mark Lobodzinskidb117632016-03-31 10:45:56 -060015728 copyRegion.srcSubresource.layerCount = 1;
Mike Stroyana3082432015-09-25 13:39:21 -060015729 copyRegion.srcOffset.x = 0;
15730 copyRegion.srcOffset.y = 0;
15731 copyRegion.srcOffset.z = 0;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080015732 copyRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015733 copyRegion.dstSubresource.mipLevel = 0;
15734 copyRegion.dstSubresource.baseArrayLayer = 0;
Mark Lobodzinskidb117632016-03-31 10:45:56 -060015735 // Introduce failure by forcing the dst layerCount to differ from src
15736 copyRegion.dstSubresource.layerCount = 3;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015737 copyRegion.dstOffset.x = 0;
15738 copyRegion.dstOffset.y = 0;
15739 copyRegion.dstOffset.z = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060015740 copyRegion.extent.width = 1;
15741 copyRegion.extent.height = 1;
15742 copyRegion.extent.depth = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015743 m_commandBuffer->CopyImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, VK_IMAGE_LAYOUT_GENERAL, 1, &copyRegion);
Mike Stroyana3082432015-09-25 13:39:21 -060015744 EndCommandBuffer();
15745
Chris Forbes8f36a8a2016-04-07 13:21:07 +120015746 m_errorMonitor->VerifyFound();
Mike Stroyana3082432015-09-25 13:39:21 -060015747
Chia-I Wuf7458c52015-10-26 21:10:41 +080015748 vkDestroyImage(m_device->device(), srcImage, NULL);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015749 vkDestroyImage(m_device->device(), dstImage, NULL);
Chia-I Wuf7458c52015-10-26 21:10:41 +080015750 vkFreeMemory(m_device->device(), srcMem, NULL);
15751 vkFreeMemory(m_device->device(), destMem, NULL);
Mike Stroyana3082432015-09-25 13:39:21 -060015752}
15753
Tony Barbourd6673642016-05-05 14:46:39 -060015754TEST_F(VkLayerTest, ImageLayerUnsupportedFormat) {
15755
15756 TEST_DESCRIPTION("Creating images with unsuported formats ");
15757
15758 ASSERT_NO_FATAL_FAILURE(InitState());
15759 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
15760 VkImageObj image(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015761 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 -060015762 VK_IMAGE_TILING_OPTIMAL, 0);
15763 ASSERT_TRUE(image.initialized());
15764
Mark Lobodzinskiba5c6862016-05-17 08:14:00 -060015765 // Create image with unsupported format - Expect FORMAT_UNSUPPORTED
15766 VkImageCreateInfo image_create_info;
15767 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
15768 image_create_info.pNext = NULL;
15769 image_create_info.imageType = VK_IMAGE_TYPE_2D;
15770 image_create_info.format = VK_FORMAT_UNDEFINED;
15771 image_create_info.extent.width = 32;
15772 image_create_info.extent.height = 32;
15773 image_create_info.extent.depth = 1;
15774 image_create_info.mipLevels = 1;
15775 image_create_info.arrayLayers = 1;
15776 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
15777 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
15778 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
15779 image_create_info.flags = 0;
15780
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015781 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
15782 "vkCreateImage: VkFormat for image must not be VK_FORMAT_UNDEFINED");
Mark Lobodzinskiba5c6862016-05-17 08:14:00 -060015783
15784 VkImage localImage;
15785 vkCreateImage(m_device->handle(), &image_create_info, NULL, &localImage);
15786 m_errorMonitor->VerifyFound();
15787
Tony Barbourd6673642016-05-05 14:46:39 -060015788 VkFormat unsupported = VK_FORMAT_UNDEFINED;
Mark Lobodzinskiba5c6862016-05-17 08:14:00 -060015789 // Look for a format that is COMPLETELY unsupported with this hardware
Tony Barbourd6673642016-05-05 14:46:39 -060015790 for (int f = VK_FORMAT_BEGIN_RANGE; f <= VK_FORMAT_END_RANGE; f++) {
15791 VkFormat format = static_cast<VkFormat>(f);
15792 VkFormatProperties fProps = m_device->format_properties(format);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015793 if (format != VK_FORMAT_UNDEFINED && fProps.linearTilingFeatures == 0 && fProps.optimalTilingFeatures == 0) {
Tony Barbourd6673642016-05-05 14:46:39 -060015794 unsupported = format;
15795 break;
15796 }
15797 }
Mark Lobodzinskiba5c6862016-05-17 08:14:00 -060015798
Tony Barbourd6673642016-05-05 14:46:39 -060015799 if (unsupported != VK_FORMAT_UNDEFINED) {
Tony Barbourd6673642016-05-05 14:46:39 -060015800 image_create_info.format = unsupported;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015801 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "is an unsupported format");
Tony Barbourd6673642016-05-05 14:46:39 -060015802
Mark Lobodzinskiba5c6862016-05-17 08:14:00 -060015803 vkCreateImage(m_device->handle(), &image_create_info, NULL, &localImage);
Tony Barbourd6673642016-05-05 14:46:39 -060015804 m_errorMonitor->VerifyFound();
15805 }
15806}
15807
15808TEST_F(VkLayerTest, ImageLayerViewTests) {
15809 VkResult ret;
15810 TEST_DESCRIPTION("Passing bad parameters to CreateImageView");
15811
15812 ASSERT_NO_FATAL_FAILURE(InitState());
15813
15814 VkImageObj image(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015815 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 -060015816 VK_IMAGE_TILING_OPTIMAL, 0);
15817 ASSERT_TRUE(image.initialized());
15818
15819 VkImageView imgView;
15820 VkImageViewCreateInfo imgViewInfo = {};
15821 imgViewInfo.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
15822 imgViewInfo.image = image.handle();
15823 imgViewInfo.viewType = VK_IMAGE_VIEW_TYPE_2D;
15824 imgViewInfo.format = VK_FORMAT_B8G8R8A8_UNORM;
15825 imgViewInfo.subresourceRange.layerCount = 1;
15826 imgViewInfo.subresourceRange.baseMipLevel = 0;
15827 imgViewInfo.subresourceRange.levelCount = 1;
15828 imgViewInfo.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
15829
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015830 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "vkCreateImageView called with baseMipLevel");
Tony Barbourd6673642016-05-05 14:46:39 -060015831 // View can't have baseMipLevel >= image's mipLevels - Expect
15832 // VIEW_CREATE_ERROR
15833 imgViewInfo.subresourceRange.baseMipLevel = 1;
15834 vkCreateImageView(m_device->handle(), &imgViewInfo, NULL, &imgView);
15835 m_errorMonitor->VerifyFound();
15836 imgViewInfo.subresourceRange.baseMipLevel = 0;
15837
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015838 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "vkCreateImageView called with baseArrayLayer");
Tony Barbourd6673642016-05-05 14:46:39 -060015839 // View can't have baseArrayLayer >= image's arraySize - Expect
15840 // VIEW_CREATE_ERROR
15841 imgViewInfo.subresourceRange.baseArrayLayer = 1;
15842 vkCreateImageView(m_device->handle(), &imgViewInfo, NULL, &imgView);
15843 m_errorMonitor->VerifyFound();
15844 imgViewInfo.subresourceRange.baseArrayLayer = 0;
15845
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015846 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "vkCreateImageView called with 0 in "
15847 "pCreateInfo->subresourceRange."
15848 "levelCount");
Tony Barbourd6673642016-05-05 14:46:39 -060015849 // View's levelCount can't be 0 - Expect VIEW_CREATE_ERROR
15850 imgViewInfo.subresourceRange.levelCount = 0;
15851 vkCreateImageView(m_device->handle(), &imgViewInfo, NULL, &imgView);
15852 m_errorMonitor->VerifyFound();
15853 imgViewInfo.subresourceRange.levelCount = 1;
15854
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015855 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "vkCreateImageView called with 0 in "
15856 "pCreateInfo->subresourceRange."
15857 "layerCount");
Tony Barbourd6673642016-05-05 14:46:39 -060015858 // View's layerCount can't be 0 - Expect VIEW_CREATE_ERROR
15859 imgViewInfo.subresourceRange.layerCount = 0;
15860 vkCreateImageView(m_device->handle(), &imgViewInfo, NULL, &imgView);
15861 m_errorMonitor->VerifyFound();
15862 imgViewInfo.subresourceRange.layerCount = 1;
15863
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015864 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "but both must be color formats");
Tony Barbourd6673642016-05-05 14:46:39 -060015865 // Can't use depth format for view into color image - Expect INVALID_FORMAT
15866 imgViewInfo.format = VK_FORMAT_D24_UNORM_S8_UINT;
15867 vkCreateImageView(m_device->handle(), &imgViewInfo, NULL, &imgView);
15868 m_errorMonitor->VerifyFound();
15869 imgViewInfo.format = VK_FORMAT_B8G8R8A8_UNORM;
15870
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015871 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Formats MUST be IDENTICAL unless "
15872 "VK_IMAGE_CREATE_MUTABLE_FORMAT BIT "
15873 "was set on image creation.");
Tony Barbourd6673642016-05-05 14:46:39 -060015874 // Same compatibility class but no MUTABLE_FORMAT bit - Expect
15875 // VIEW_CREATE_ERROR
15876 imgViewInfo.format = VK_FORMAT_B8G8R8A8_UINT;
15877 vkCreateImageView(m_device->handle(), &imgViewInfo, NULL, &imgView);
15878 m_errorMonitor->VerifyFound();
15879 imgViewInfo.format = VK_FORMAT_B8G8R8A8_UNORM;
15880
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015881 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "can support ImageViews with "
15882 "differing formats but they must be "
15883 "in the same compatibility class.");
Tony Barbourd6673642016-05-05 14:46:39 -060015884 // Have MUTABLE_FORMAT bit but not in same compatibility class - Expect
15885 // VIEW_CREATE_ERROR
15886 VkImageCreateInfo mutImgInfo = image.create_info();
15887 VkImage mutImage;
15888 mutImgInfo.format = VK_FORMAT_R8_UINT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015889 assert(m_device->format_properties(VK_FORMAT_R8_UINT).optimalTilingFeatures & VK_FORMAT_FEATURE_COLOR_ATTACHMENT_BIT);
Tony Barbourd6673642016-05-05 14:46:39 -060015890 mutImgInfo.flags = VK_IMAGE_CREATE_MUTABLE_FORMAT_BIT;
15891 mutImgInfo.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
15892 ret = vkCreateImage(m_device->handle(), &mutImgInfo, NULL, &mutImage);
15893 ASSERT_VK_SUCCESS(ret);
15894 imgViewInfo.image = mutImage;
15895 vkCreateImageView(m_device->handle(), &imgViewInfo, NULL, &imgView);
15896 m_errorMonitor->VerifyFound();
15897 imgViewInfo.image = image.handle();
15898 vkDestroyImage(m_device->handle(), mutImage, NULL);
15899}
15900
15901TEST_F(VkLayerTest, MiscImageLayerTests) {
15902
15903 TEST_DESCRIPTION("Image layer tests that don't belong elsewhare");
15904
15905 ASSERT_NO_FATAL_FAILURE(InitState());
15906
15907 VkImageObj image(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015908 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 -060015909 VK_IMAGE_TILING_OPTIMAL, 0);
15910 ASSERT_TRUE(image.initialized());
15911
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015912 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "number of layers in image subresource is zero");
Tony Barbourd6673642016-05-05 14:46:39 -060015913 vk_testing::Buffer buffer;
15914 VkMemoryPropertyFlags reqs = 0;
15915 buffer.init_as_src(*m_device, 128 * 128 * 4, reqs);
15916 VkBufferImageCopy region = {};
15917 region.bufferRowLength = 128;
15918 region.bufferImageHeight = 128;
15919 region.imageSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
15920 // layerCount can't be 0 - Expect MISMATCHED_IMAGE_ASPECT
15921 region.imageSubresource.layerCount = 0;
15922 region.imageExtent.height = 4;
15923 region.imageExtent.width = 4;
15924 region.imageExtent.depth = 1;
15925 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015926 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer.handle(), image.handle(),
15927 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, &region);
Tony Barbourd6673642016-05-05 14:46:39 -060015928 m_errorMonitor->VerifyFound();
15929 region.imageSubresource.layerCount = 1;
15930
Mark Lobodzinski7d8cf142016-08-19 10:53:26 -060015931 // BufferOffset must be a multiple of the calling command's VkImage parameter's texel size
15932 // Introduce failure by setting bufferOffset to 1 and 1/2 texels
15933 region.bufferOffset = 6;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015934 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "must be a multiple of this format's texel size");
15935 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer.handle(), image.handle(),
15936 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, &region);
Mark Lobodzinski7d8cf142016-08-19 10:53:26 -060015937 m_errorMonitor->VerifyFound();
15938
15939 // BufferOffset must be a multiple of 4
15940 // Introduce failure by setting bufferOffset to a value not divisible by 4
15941 region.bufferOffset = 6;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015942 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "must be a multiple of 4");
15943 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer.handle(), image.handle(),
15944 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, &region);
Mark Lobodzinski7d8cf142016-08-19 10:53:26 -060015945 m_errorMonitor->VerifyFound();
15946
15947 // BufferRowLength must be 0, or greater than or equal to the width member of imageExtent
15948 region.bufferOffset = 0;
15949 region.imageExtent.height = 128;
15950 region.imageExtent.width = 128;
15951 // Introduce failure by setting bufferRowLength > 0 but less than width
15952 region.bufferRowLength = 64;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015953 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
15954 "must be zero or greater-than-or-equal-to imageExtent.width");
15955 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer.handle(), image.handle(),
15956 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, &region);
Mark Lobodzinski7d8cf142016-08-19 10:53:26 -060015957 m_errorMonitor->VerifyFound();
15958
15959 // BufferImageHeight must be 0, or greater than or equal to the height member of imageExtent
15960 region.bufferRowLength = 128;
15961 // Introduce failure by setting bufferRowHeight > 0 but less than height
15962 region.bufferImageHeight = 64;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015963 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
15964 "must be zero or greater-than-or-equal-to imageExtent.height");
15965 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer.handle(), image.handle(),
15966 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, &region);
Mark Lobodzinski7d8cf142016-08-19 10:53:26 -060015967 m_errorMonitor->VerifyFound();
15968
15969 region.bufferImageHeight = 128;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015970 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "aspectMasks for each region must "
15971 "specify only COLOR or DEPTH or "
15972 "STENCIL");
Tony Barbourd6673642016-05-05 14:46:39 -060015973 // Expect MISMATCHED_IMAGE_ASPECT
15974 region.imageSubresource.aspectMask = VK_IMAGE_ASPECT_METADATA_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015975 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer.handle(), image.handle(),
15976 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, &region);
Tony Barbourd6673642016-05-05 14:46:39 -060015977 m_errorMonitor->VerifyFound();
15978 region.imageSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
15979
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015980 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
15981 "If the format of srcImage is a depth, stencil, depth stencil or "
15982 "integer-based format then filter must be VK_FILTER_NEAREST");
Tony Barbourd6673642016-05-05 14:46:39 -060015983 // Expect INVALID_FILTER
15984 VkImageObj intImage1(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015985 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 -060015986 VkImageObj intImage2(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015987 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 -060015988 VkImageBlit blitRegion = {};
15989 blitRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
15990 blitRegion.srcSubresource.baseArrayLayer = 0;
15991 blitRegion.srcSubresource.layerCount = 1;
15992 blitRegion.srcSubresource.mipLevel = 0;
15993 blitRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
15994 blitRegion.dstSubresource.baseArrayLayer = 0;
15995 blitRegion.dstSubresource.layerCount = 1;
15996 blitRegion.dstSubresource.mipLevel = 0;
15997
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015998 vkCmdBlitImage(m_commandBuffer->GetBufferHandle(), intImage1.handle(), intImage1.layout(), intImage2.handle(),
15999 intImage2.layout(), 16, &blitRegion, VK_FILTER_LINEAR);
Tony Barbourd6673642016-05-05 14:46:39 -060016000 m_errorMonitor->VerifyFound();
16001
Mark Lobodzinskib02ea642016-08-17 13:03:57 -060016002 // Look for NULL-blit warning
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016003 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT, "Offsets specify a zero-volume area.");
16004 vkCmdBlitImage(m_commandBuffer->GetBufferHandle(), intImage1.handle(), intImage1.layout(), intImage2.handle(),
16005 intImage2.layout(), 1, &blitRegion, VK_FILTER_LINEAR);
Mark Lobodzinskib02ea642016-08-17 13:03:57 -060016006 m_errorMonitor->VerifyFound();
16007
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016008 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "called with 0 in ppMemoryBarriers");
Tony Barbourd6673642016-05-05 14:46:39 -060016009 VkImageMemoryBarrier img_barrier;
16010 img_barrier.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
16011 img_barrier.pNext = NULL;
16012 img_barrier.srcAccessMask = VK_ACCESS_HOST_WRITE_BIT;
16013 img_barrier.dstAccessMask = VK_ACCESS_SHADER_READ_BIT;
16014 img_barrier.oldLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
16015 img_barrier.newLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
16016 img_barrier.image = image.handle();
16017 img_barrier.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
16018 img_barrier.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
16019 img_barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
16020 img_barrier.subresourceRange.baseArrayLayer = 0;
16021 img_barrier.subresourceRange.baseMipLevel = 0;
16022 // layerCount should not be 0 - Expect INVALID_IMAGE_RESOURCE
16023 img_barrier.subresourceRange.layerCount = 0;
16024 img_barrier.subresourceRange.levelCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016025 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
16026 nullptr, 0, nullptr, 1, &img_barrier);
Tony Barbourd6673642016-05-05 14:46:39 -060016027 m_errorMonitor->VerifyFound();
16028 img_barrier.subresourceRange.layerCount = 1;
16029}
16030
16031TEST_F(VkLayerTest, ImageFormatLimits) {
16032
16033 TEST_DESCRIPTION("Exceed the limits of image format ");
16034
Cody Northropc31a84f2016-08-22 10:41:47 -060016035 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016036 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "CreateImage extents exceed allowable limits for format");
Tony Barbourd6673642016-05-05 14:46:39 -060016037 VkImageCreateInfo image_create_info = {};
16038 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
16039 image_create_info.pNext = NULL;
16040 image_create_info.imageType = VK_IMAGE_TYPE_2D;
16041 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
16042 image_create_info.extent.width = 32;
16043 image_create_info.extent.height = 32;
16044 image_create_info.extent.depth = 1;
16045 image_create_info.mipLevels = 1;
16046 image_create_info.arrayLayers = 1;
16047 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
16048 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
16049 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
16050 image_create_info.initialLayout = VK_IMAGE_LAYOUT_UNDEFINED;
16051 image_create_info.flags = 0;
16052
16053 VkImage nullImg;
16054 VkImageFormatProperties imgFmtProps;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016055 vkGetPhysicalDeviceImageFormatProperties(gpu(), image_create_info.format, image_create_info.imageType, image_create_info.tiling,
16056 image_create_info.usage, image_create_info.flags, &imgFmtProps);
Tony Barbourd6673642016-05-05 14:46:39 -060016057 image_create_info.extent.depth = imgFmtProps.maxExtent.depth + 1;
16058 // Expect INVALID_FORMAT_LIMITS_VIOLATION
16059 vkCreateImage(m_device->handle(), &image_create_info, NULL, &nullImg);
16060 m_errorMonitor->VerifyFound();
16061 image_create_info.extent.depth = 1;
16062
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016063 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "exceeds allowable maximum supported by format of");
Tony Barbourd6673642016-05-05 14:46:39 -060016064 image_create_info.mipLevels = imgFmtProps.maxMipLevels + 1;
16065 // Expect INVALID_FORMAT_LIMITS_VIOLATION
16066 vkCreateImage(m_device->handle(), &image_create_info, NULL, &nullImg);
16067 m_errorMonitor->VerifyFound();
16068 image_create_info.mipLevels = 1;
16069
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016070 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "exceeds allowable maximum supported by format of");
Tony Barbourd6673642016-05-05 14:46:39 -060016071 image_create_info.arrayLayers = imgFmtProps.maxArrayLayers + 1;
16072 // Expect INVALID_FORMAT_LIMITS_VIOLATION
16073 vkCreateImage(m_device->handle(), &image_create_info, NULL, &nullImg);
16074 m_errorMonitor->VerifyFound();
16075 image_create_info.arrayLayers = 1;
16076
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016077 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "is not supported by format");
Tony Barbourd6673642016-05-05 14:46:39 -060016078 int samples = imgFmtProps.sampleCounts >> 1;
16079 image_create_info.samples = (VkSampleCountFlagBits)samples;
16080 // Expect INVALID_FORMAT_LIMITS_VIOLATION
16081 vkCreateImage(m_device->handle(), &image_create_info, NULL, &nullImg);
16082 m_errorMonitor->VerifyFound();
16083 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
16084
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016085 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "pCreateInfo->initialLayout, must be "
16086 "VK_IMAGE_LAYOUT_UNDEFINED or "
16087 "VK_IMAGE_LAYOUT_PREINITIALIZED");
Tony Barbourd6673642016-05-05 14:46:39 -060016088 image_create_info.initialLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
16089 // Expect INVALID_LAYOUT
16090 vkCreateImage(m_device->handle(), &image_create_info, NULL, &nullImg);
16091 m_errorMonitor->VerifyFound();
16092 image_create_info.initialLayout = VK_IMAGE_LAYOUT_UNDEFINED;
16093}
16094
Karl Schultz6addd812016-02-02 17:17:23 -070016095TEST_F(VkLayerTest, CopyImageFormatSizeMismatch) {
Karl Schultzbdb75952016-04-19 11:36:49 -060016096 VkResult err;
16097 bool pass;
16098
16099 // Create color images with different format sizes and try to copy between them
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016100 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
16101 "vkCmdCopyImage called with unmatched source and dest image format sizes");
Karl Schultzbdb75952016-04-19 11:36:49 -060016102
16103 ASSERT_NO_FATAL_FAILURE(InitState());
16104
16105 // Create two images of different types and try to copy between them
16106 VkImage srcImage;
16107 VkImage dstImage;
16108 VkDeviceMemory srcMem;
16109 VkDeviceMemory destMem;
16110 VkMemoryRequirements memReqs;
16111
16112 VkImageCreateInfo image_create_info = {};
16113 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
16114 image_create_info.pNext = NULL;
16115 image_create_info.imageType = VK_IMAGE_TYPE_2D;
16116 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
16117 image_create_info.extent.width = 32;
16118 image_create_info.extent.height = 32;
16119 image_create_info.extent.depth = 1;
16120 image_create_info.mipLevels = 1;
16121 image_create_info.arrayLayers = 1;
16122 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
16123 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
16124 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
16125 image_create_info.flags = 0;
16126
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016127 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
Karl Schultzbdb75952016-04-19 11:36:49 -060016128 ASSERT_VK_SUCCESS(err);
16129
16130 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT;
16131 // Introduce failure by creating second image with a different-sized format.
16132 image_create_info.format = VK_FORMAT_R5G5B5A1_UNORM_PACK16;
16133
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016134 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
Karl Schultzbdb75952016-04-19 11:36:49 -060016135 ASSERT_VK_SUCCESS(err);
16136
16137 // Allocate memory
16138 VkMemoryAllocateInfo memAlloc = {};
16139 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
16140 memAlloc.pNext = NULL;
16141 memAlloc.allocationSize = 0;
16142 memAlloc.memoryTypeIndex = 0;
16143
16144 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
16145 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016146 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Karl Schultzbdb75952016-04-19 11:36:49 -060016147 ASSERT_TRUE(pass);
16148 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
16149 ASSERT_VK_SUCCESS(err);
16150
16151 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
16152 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016153 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Karl Schultzbdb75952016-04-19 11:36:49 -060016154 ASSERT_TRUE(pass);
16155 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
16156 ASSERT_VK_SUCCESS(err);
16157
16158 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
16159 ASSERT_VK_SUCCESS(err);
16160 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
16161 ASSERT_VK_SUCCESS(err);
16162
16163 BeginCommandBuffer();
16164 VkImageCopy copyRegion;
16165 copyRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
16166 copyRegion.srcSubresource.mipLevel = 0;
16167 copyRegion.srcSubresource.baseArrayLayer = 0;
16168 copyRegion.srcSubresource.layerCount = 0;
16169 copyRegion.srcOffset.x = 0;
16170 copyRegion.srcOffset.y = 0;
16171 copyRegion.srcOffset.z = 0;
16172 copyRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
16173 copyRegion.dstSubresource.mipLevel = 0;
16174 copyRegion.dstSubresource.baseArrayLayer = 0;
16175 copyRegion.dstSubresource.layerCount = 0;
16176 copyRegion.dstOffset.x = 0;
16177 copyRegion.dstOffset.y = 0;
16178 copyRegion.dstOffset.z = 0;
16179 copyRegion.extent.width = 1;
16180 copyRegion.extent.height = 1;
16181 copyRegion.extent.depth = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016182 m_commandBuffer->CopyImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, VK_IMAGE_LAYOUT_GENERAL, 1, &copyRegion);
Karl Schultzbdb75952016-04-19 11:36:49 -060016183 EndCommandBuffer();
16184
16185 m_errorMonitor->VerifyFound();
16186
16187 vkDestroyImage(m_device->device(), srcImage, NULL);
16188 vkDestroyImage(m_device->device(), dstImage, NULL);
16189 vkFreeMemory(m_device->device(), srcMem, NULL);
16190 vkFreeMemory(m_device->device(), destMem, NULL);
Mike Stroyana3082432015-09-25 13:39:21 -060016191}
16192
Karl Schultz6addd812016-02-02 17:17:23 -070016193TEST_F(VkLayerTest, CopyImageDepthStencilFormatMismatch) {
16194 VkResult err;
16195 bool pass;
Mike Stroyana3082432015-09-25 13:39:21 -060016196
Mark Lobodzinskidb117632016-03-31 10:45:56 -060016197 // Create a color image and a depth/stencil image and try to copy between them
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016198 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
16199 "vkCmdCopyImage called with unmatched source and dest image depth");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060016200
Mike Stroyana3082432015-09-25 13:39:21 -060016201 ASSERT_NO_FATAL_FAILURE(InitState());
Mike Stroyana3082432015-09-25 13:39:21 -060016202
16203 // Create two images of different types and try to copy between them
Karl Schultz6addd812016-02-02 17:17:23 -070016204 VkImage srcImage;
16205 VkImage dstImage;
16206 VkDeviceMemory srcMem;
16207 VkDeviceMemory destMem;
16208 VkMemoryRequirements memReqs;
Mike Stroyana3082432015-09-25 13:39:21 -060016209
16210 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070016211 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
16212 image_create_info.pNext = NULL;
16213 image_create_info.imageType = VK_IMAGE_TYPE_2D;
16214 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
16215 image_create_info.extent.width = 32;
16216 image_create_info.extent.height = 32;
16217 image_create_info.extent.depth = 1;
16218 image_create_info.mipLevels = 1;
16219 image_create_info.arrayLayers = 1;
16220 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
16221 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
16222 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
16223 image_create_info.flags = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060016224
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016225 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
Mike Stroyana3082432015-09-25 13:39:21 -060016226 ASSERT_VK_SUCCESS(err);
16227
Karl Schultzbdb75952016-04-19 11:36:49 -060016228 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT;
16229
Mark Lobodzinskidb117632016-03-31 10:45:56 -060016230 // Introduce failure by creating second image with a depth/stencil format
Karl Schultz6addd812016-02-02 17:17:23 -070016231 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
Mark Lobodzinskidb117632016-03-31 10:45:56 -060016232 image_create_info.format = VK_FORMAT_D24_UNORM_S8_UINT;
16233 image_create_info.usage = VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060016234
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016235 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
Mike Stroyana3082432015-09-25 13:39:21 -060016236 ASSERT_VK_SUCCESS(err);
16237
16238 // Allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016239 VkMemoryAllocateInfo memAlloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -070016240 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
16241 memAlloc.pNext = NULL;
16242 memAlloc.allocationSize = 0;
16243 memAlloc.memoryTypeIndex = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060016244
Courtney Goeltzenleuchter06d89472015-10-20 16:40:38 -060016245 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060016246 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016247 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060016248 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016249 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
Mike Stroyana3082432015-09-25 13:39:21 -060016250 ASSERT_VK_SUCCESS(err);
16251
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016252 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060016253 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016254 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060016255 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016256 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
Mike Stroyana3082432015-09-25 13:39:21 -060016257 ASSERT_VK_SUCCESS(err);
16258
16259 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
16260 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016261 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
Mike Stroyana3082432015-09-25 13:39:21 -060016262 ASSERT_VK_SUCCESS(err);
16263
16264 BeginCommandBuffer();
16265 VkImageCopy copyRegion;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080016266 copyRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060016267 copyRegion.srcSubresource.mipLevel = 0;
Courtney Goeltzenleuchter8367ce02015-10-16 09:46:00 -060016268 copyRegion.srcSubresource.baseArrayLayer = 0;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016269 copyRegion.srcSubresource.layerCount = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060016270 copyRegion.srcOffset.x = 0;
16271 copyRegion.srcOffset.y = 0;
16272 copyRegion.srcOffset.z = 0;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080016273 copyRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016274 copyRegion.dstSubresource.mipLevel = 0;
16275 copyRegion.dstSubresource.baseArrayLayer = 0;
16276 copyRegion.dstSubresource.layerCount = 0;
16277 copyRegion.dstOffset.x = 0;
16278 copyRegion.dstOffset.y = 0;
16279 copyRegion.dstOffset.z = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060016280 copyRegion.extent.width = 1;
16281 copyRegion.extent.height = 1;
16282 copyRegion.extent.depth = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016283 m_commandBuffer->CopyImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, VK_IMAGE_LAYOUT_GENERAL, 1, &copyRegion);
Mike Stroyana3082432015-09-25 13:39:21 -060016284 EndCommandBuffer();
16285
Chris Forbes8f36a8a2016-04-07 13:21:07 +120016286 m_errorMonitor->VerifyFound();
Mike Stroyana3082432015-09-25 13:39:21 -060016287
Chia-I Wuf7458c52015-10-26 21:10:41 +080016288 vkDestroyImage(m_device->device(), srcImage, NULL);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016289 vkDestroyImage(m_device->device(), dstImage, NULL);
Chia-I Wuf7458c52015-10-26 21:10:41 +080016290 vkFreeMemory(m_device->device(), srcMem, NULL);
16291 vkFreeMemory(m_device->device(), destMem, NULL);
Mike Stroyana3082432015-09-25 13:39:21 -060016292}
16293
Karl Schultz6addd812016-02-02 17:17:23 -070016294TEST_F(VkLayerTest, ResolveImageLowSampleCount) {
16295 VkResult err;
16296 bool pass;
Mike Stroyana3082432015-09-25 13:39:21 -060016297
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016298 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
16299 "vkCmdResolveImage called with source sample count less than 2.");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060016300
Mike Stroyana3082432015-09-25 13:39:21 -060016301 ASSERT_NO_FATAL_FAILURE(InitState());
Mike Stroyana3082432015-09-25 13:39:21 -060016302
16303 // Create two images of sample count 1 and try to Resolve between them
Karl Schultz6addd812016-02-02 17:17:23 -070016304 VkImage srcImage;
16305 VkImage dstImage;
16306 VkDeviceMemory srcMem;
16307 VkDeviceMemory destMem;
16308 VkMemoryRequirements memReqs;
Mike Stroyana3082432015-09-25 13:39:21 -060016309
16310 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070016311 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
16312 image_create_info.pNext = NULL;
16313 image_create_info.imageType = VK_IMAGE_TYPE_2D;
16314 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
16315 image_create_info.extent.width = 32;
16316 image_create_info.extent.height = 1;
16317 image_create_info.extent.depth = 1;
16318 image_create_info.mipLevels = 1;
16319 image_create_info.arrayLayers = 1;
16320 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
16321 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
16322 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
16323 image_create_info.flags = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060016324
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016325 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
Mike Stroyana3082432015-09-25 13:39:21 -060016326 ASSERT_VK_SUCCESS(err);
16327
Karl Schultz6addd812016-02-02 17:17:23 -070016328 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060016329
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016330 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
Mike Stroyana3082432015-09-25 13:39:21 -060016331 ASSERT_VK_SUCCESS(err);
16332
16333 // Allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016334 VkMemoryAllocateInfo memAlloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -070016335 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
16336 memAlloc.pNext = NULL;
16337 memAlloc.allocationSize = 0;
16338 memAlloc.memoryTypeIndex = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060016339
Courtney Goeltzenleuchter06d89472015-10-20 16:40:38 -060016340 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060016341 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016342 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060016343 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016344 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
Mike Stroyana3082432015-09-25 13:39:21 -060016345 ASSERT_VK_SUCCESS(err);
16346
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016347 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060016348 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016349 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060016350 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016351 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
Mike Stroyana3082432015-09-25 13:39:21 -060016352 ASSERT_VK_SUCCESS(err);
16353
16354 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
16355 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016356 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
Mike Stroyana3082432015-09-25 13:39:21 -060016357 ASSERT_VK_SUCCESS(err);
16358
16359 BeginCommandBuffer();
16360 // Need memory barrier to VK_IMAGE_LAYOUT_GENERAL for source and dest?
Karl Schultz6addd812016-02-02 17:17:23 -070016361 // VK_IMAGE_LAYOUT_UNDEFINED = 0,
16362 // VK_IMAGE_LAYOUT_GENERAL = 1,
Mike Stroyana3082432015-09-25 13:39:21 -060016363 VkImageResolve resolveRegion;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080016364 resolveRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060016365 resolveRegion.srcSubresource.mipLevel = 0;
Courtney Goeltzenleuchter8367ce02015-10-16 09:46:00 -060016366 resolveRegion.srcSubresource.baseArrayLayer = 0;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016367 resolveRegion.srcSubresource.layerCount = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060016368 resolveRegion.srcOffset.x = 0;
16369 resolveRegion.srcOffset.y = 0;
16370 resolveRegion.srcOffset.z = 0;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080016371 resolveRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016372 resolveRegion.dstSubresource.mipLevel = 0;
16373 resolveRegion.dstSubresource.baseArrayLayer = 0;
16374 resolveRegion.dstSubresource.layerCount = 0;
16375 resolveRegion.dstOffset.x = 0;
16376 resolveRegion.dstOffset.y = 0;
16377 resolveRegion.dstOffset.z = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060016378 resolveRegion.extent.width = 1;
16379 resolveRegion.extent.height = 1;
16380 resolveRegion.extent.depth = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016381 m_commandBuffer->ResolveImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, VK_IMAGE_LAYOUT_GENERAL, 1, &resolveRegion);
Mike Stroyana3082432015-09-25 13:39:21 -060016382 EndCommandBuffer();
16383
Chris Forbes8f36a8a2016-04-07 13:21:07 +120016384 m_errorMonitor->VerifyFound();
Mike Stroyana3082432015-09-25 13:39:21 -060016385
Chia-I Wuf7458c52015-10-26 21:10:41 +080016386 vkDestroyImage(m_device->device(), srcImage, NULL);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016387 vkDestroyImage(m_device->device(), dstImage, NULL);
Chia-I Wuf7458c52015-10-26 21:10:41 +080016388 vkFreeMemory(m_device->device(), srcMem, NULL);
16389 vkFreeMemory(m_device->device(), destMem, NULL);
Mike Stroyana3082432015-09-25 13:39:21 -060016390}
16391
Karl Schultz6addd812016-02-02 17:17:23 -070016392TEST_F(VkLayerTest, ResolveImageHighSampleCount) {
16393 VkResult err;
16394 bool pass;
Mike Stroyana3082432015-09-25 13:39:21 -060016395
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016396 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
16397 "vkCmdResolveImage called with dest sample count greater than 1.");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060016398
Mike Stroyana3082432015-09-25 13:39:21 -060016399 ASSERT_NO_FATAL_FAILURE(InitState());
Mike Stroyana3082432015-09-25 13:39:21 -060016400
Chris Forbesa7530692016-05-08 12:35:39 +120016401 // Create two images of sample count 4 and try to Resolve between them
Karl Schultz6addd812016-02-02 17:17:23 -070016402 VkImage srcImage;
16403 VkImage dstImage;
16404 VkDeviceMemory srcMem;
16405 VkDeviceMemory destMem;
16406 VkMemoryRequirements memReqs;
Mike Stroyana3082432015-09-25 13:39:21 -060016407
16408 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070016409 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
16410 image_create_info.pNext = NULL;
16411 image_create_info.imageType = VK_IMAGE_TYPE_2D;
16412 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
16413 image_create_info.extent.width = 32;
16414 image_create_info.extent.height = 1;
16415 image_create_info.extent.depth = 1;
16416 image_create_info.mipLevels = 1;
16417 image_create_info.arrayLayers = 1;
Chris Forbesa7530692016-05-08 12:35:39 +120016418 image_create_info.samples = VK_SAMPLE_COUNT_4_BIT;
Karl Schultz6addd812016-02-02 17:17:23 -070016419 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
16420 // Note: Some implementations expect color attachment usage for any
16421 // multisample surface
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016422 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
Karl Schultz6addd812016-02-02 17:17:23 -070016423 image_create_info.flags = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060016424
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016425 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
Mike Stroyana3082432015-09-25 13:39:21 -060016426 ASSERT_VK_SUCCESS(err);
16427
Karl Schultz6addd812016-02-02 17:17:23 -070016428 // Note: Some implementations expect color attachment usage for any
16429 // multisample surface
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016430 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060016431
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016432 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
Mike Stroyana3082432015-09-25 13:39:21 -060016433 ASSERT_VK_SUCCESS(err);
16434
16435 // Allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016436 VkMemoryAllocateInfo memAlloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -070016437 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
16438 memAlloc.pNext = NULL;
16439 memAlloc.allocationSize = 0;
16440 memAlloc.memoryTypeIndex = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060016441
Courtney Goeltzenleuchter06d89472015-10-20 16:40:38 -060016442 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060016443 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016444 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060016445 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016446 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
Mike Stroyana3082432015-09-25 13:39:21 -060016447 ASSERT_VK_SUCCESS(err);
16448
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016449 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060016450 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016451 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060016452 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016453 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
Mike Stroyana3082432015-09-25 13:39:21 -060016454 ASSERT_VK_SUCCESS(err);
16455
16456 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
16457 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016458 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
Mike Stroyana3082432015-09-25 13:39:21 -060016459 ASSERT_VK_SUCCESS(err);
16460
16461 BeginCommandBuffer();
16462 // Need memory barrier to VK_IMAGE_LAYOUT_GENERAL for source and dest?
Karl Schultz6addd812016-02-02 17:17:23 -070016463 // VK_IMAGE_LAYOUT_UNDEFINED = 0,
16464 // VK_IMAGE_LAYOUT_GENERAL = 1,
Mike Stroyana3082432015-09-25 13:39:21 -060016465 VkImageResolve resolveRegion;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080016466 resolveRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060016467 resolveRegion.srcSubresource.mipLevel = 0;
Courtney Goeltzenleuchter8367ce02015-10-16 09:46:00 -060016468 resolveRegion.srcSubresource.baseArrayLayer = 0;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016469 resolveRegion.srcSubresource.layerCount = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060016470 resolveRegion.srcOffset.x = 0;
16471 resolveRegion.srcOffset.y = 0;
16472 resolveRegion.srcOffset.z = 0;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080016473 resolveRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016474 resolveRegion.dstSubresource.mipLevel = 0;
16475 resolveRegion.dstSubresource.baseArrayLayer = 0;
16476 resolveRegion.dstSubresource.layerCount = 0;
16477 resolveRegion.dstOffset.x = 0;
16478 resolveRegion.dstOffset.y = 0;
16479 resolveRegion.dstOffset.z = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060016480 resolveRegion.extent.width = 1;
16481 resolveRegion.extent.height = 1;
16482 resolveRegion.extent.depth = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016483 m_commandBuffer->ResolveImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, VK_IMAGE_LAYOUT_GENERAL, 1, &resolveRegion);
Mike Stroyana3082432015-09-25 13:39:21 -060016484 EndCommandBuffer();
16485
Chris Forbes8f36a8a2016-04-07 13:21:07 +120016486 m_errorMonitor->VerifyFound();
Mike Stroyana3082432015-09-25 13:39:21 -060016487
Chia-I Wuf7458c52015-10-26 21:10:41 +080016488 vkDestroyImage(m_device->device(), srcImage, NULL);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016489 vkDestroyImage(m_device->device(), dstImage, NULL);
Chia-I Wuf7458c52015-10-26 21:10:41 +080016490 vkFreeMemory(m_device->device(), srcMem, NULL);
16491 vkFreeMemory(m_device->device(), destMem, NULL);
Mike Stroyana3082432015-09-25 13:39:21 -060016492}
16493
Karl Schultz6addd812016-02-02 17:17:23 -070016494TEST_F(VkLayerTest, ResolveImageFormatMismatch) {
16495 VkResult err;
16496 bool pass;
Mike Stroyana3082432015-09-25 13:39:21 -060016497
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016498 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
16499 "vkCmdResolveImage called with unmatched source and dest formats.");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060016500
Mike Stroyana3082432015-09-25 13:39:21 -060016501 ASSERT_NO_FATAL_FAILURE(InitState());
Mike Stroyana3082432015-09-25 13:39:21 -060016502
16503 // Create two images of different types and try to copy between them
Karl Schultz6addd812016-02-02 17:17:23 -070016504 VkImage srcImage;
16505 VkImage dstImage;
16506 VkDeviceMemory srcMem;
16507 VkDeviceMemory destMem;
16508 VkMemoryRequirements memReqs;
Mike Stroyana3082432015-09-25 13:39:21 -060016509
16510 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070016511 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
16512 image_create_info.pNext = NULL;
16513 image_create_info.imageType = VK_IMAGE_TYPE_2D;
16514 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
16515 image_create_info.extent.width = 32;
16516 image_create_info.extent.height = 1;
16517 image_create_info.extent.depth = 1;
16518 image_create_info.mipLevels = 1;
16519 image_create_info.arrayLayers = 1;
16520 image_create_info.samples = VK_SAMPLE_COUNT_2_BIT;
16521 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
16522 // Note: Some implementations expect color attachment usage for any
16523 // multisample surface
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016524 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
Karl Schultz6addd812016-02-02 17:17:23 -070016525 image_create_info.flags = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060016526
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016527 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
Mike Stroyana3082432015-09-25 13:39:21 -060016528 ASSERT_VK_SUCCESS(err);
16529
Karl Schultz6addd812016-02-02 17:17:23 -070016530 // Set format to something other than source image
16531 image_create_info.format = VK_FORMAT_R32_SFLOAT;
16532 // Note: Some implementations expect color attachment usage for any
16533 // multisample surface
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016534 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
Karl Schultz6addd812016-02-02 17:17:23 -070016535 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060016536
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016537 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
Mike Stroyana3082432015-09-25 13:39:21 -060016538 ASSERT_VK_SUCCESS(err);
16539
16540 // Allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016541 VkMemoryAllocateInfo memAlloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -070016542 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
16543 memAlloc.pNext = NULL;
16544 memAlloc.allocationSize = 0;
16545 memAlloc.memoryTypeIndex = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060016546
Courtney Goeltzenleuchter06d89472015-10-20 16:40:38 -060016547 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060016548 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016549 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060016550 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016551 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
Mike Stroyana3082432015-09-25 13:39:21 -060016552 ASSERT_VK_SUCCESS(err);
16553
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016554 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060016555 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016556 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060016557 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016558 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
Mike Stroyana3082432015-09-25 13:39:21 -060016559 ASSERT_VK_SUCCESS(err);
16560
16561 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
16562 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016563 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
Mike Stroyana3082432015-09-25 13:39:21 -060016564 ASSERT_VK_SUCCESS(err);
16565
16566 BeginCommandBuffer();
16567 // Need memory barrier to VK_IMAGE_LAYOUT_GENERAL for source and dest?
Karl Schultz6addd812016-02-02 17:17:23 -070016568 // VK_IMAGE_LAYOUT_UNDEFINED = 0,
16569 // VK_IMAGE_LAYOUT_GENERAL = 1,
Mike Stroyana3082432015-09-25 13:39:21 -060016570 VkImageResolve resolveRegion;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080016571 resolveRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060016572 resolveRegion.srcSubresource.mipLevel = 0;
Courtney Goeltzenleuchter8367ce02015-10-16 09:46:00 -060016573 resolveRegion.srcSubresource.baseArrayLayer = 0;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016574 resolveRegion.srcSubresource.layerCount = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060016575 resolveRegion.srcOffset.x = 0;
16576 resolveRegion.srcOffset.y = 0;
16577 resolveRegion.srcOffset.z = 0;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080016578 resolveRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016579 resolveRegion.dstSubresource.mipLevel = 0;
16580 resolveRegion.dstSubresource.baseArrayLayer = 0;
16581 resolveRegion.dstSubresource.layerCount = 0;
16582 resolveRegion.dstOffset.x = 0;
16583 resolveRegion.dstOffset.y = 0;
16584 resolveRegion.dstOffset.z = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060016585 resolveRegion.extent.width = 1;
16586 resolveRegion.extent.height = 1;
16587 resolveRegion.extent.depth = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016588 m_commandBuffer->ResolveImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, VK_IMAGE_LAYOUT_GENERAL, 1, &resolveRegion);
Mike Stroyana3082432015-09-25 13:39:21 -060016589 EndCommandBuffer();
16590
Chris Forbes8f36a8a2016-04-07 13:21:07 +120016591 m_errorMonitor->VerifyFound();
Mike Stroyana3082432015-09-25 13:39:21 -060016592
Chia-I Wuf7458c52015-10-26 21:10:41 +080016593 vkDestroyImage(m_device->device(), srcImage, NULL);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016594 vkDestroyImage(m_device->device(), dstImage, NULL);
Chia-I Wuf7458c52015-10-26 21:10:41 +080016595 vkFreeMemory(m_device->device(), srcMem, NULL);
16596 vkFreeMemory(m_device->device(), destMem, NULL);
Mike Stroyana3082432015-09-25 13:39:21 -060016597}
16598
Karl Schultz6addd812016-02-02 17:17:23 -070016599TEST_F(VkLayerTest, ResolveImageTypeMismatch) {
16600 VkResult err;
16601 bool pass;
Mike Stroyana3082432015-09-25 13:39:21 -060016602
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016603 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
16604 "vkCmdResolveImage called with unmatched source and dest image types.");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060016605
Mike Stroyana3082432015-09-25 13:39:21 -060016606 ASSERT_NO_FATAL_FAILURE(InitState());
Mike Stroyana3082432015-09-25 13:39:21 -060016607
16608 // Create two images of different types and try to copy between them
Karl Schultz6addd812016-02-02 17:17:23 -070016609 VkImage srcImage;
16610 VkImage dstImage;
16611 VkDeviceMemory srcMem;
16612 VkDeviceMemory destMem;
16613 VkMemoryRequirements memReqs;
Mike Stroyana3082432015-09-25 13:39:21 -060016614
16615 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070016616 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
16617 image_create_info.pNext = NULL;
16618 image_create_info.imageType = VK_IMAGE_TYPE_2D;
16619 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
16620 image_create_info.extent.width = 32;
16621 image_create_info.extent.height = 1;
16622 image_create_info.extent.depth = 1;
16623 image_create_info.mipLevels = 1;
16624 image_create_info.arrayLayers = 1;
16625 image_create_info.samples = VK_SAMPLE_COUNT_2_BIT;
16626 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
16627 // Note: Some implementations expect color attachment usage for any
16628 // multisample surface
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016629 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
Karl Schultz6addd812016-02-02 17:17:23 -070016630 image_create_info.flags = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060016631
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016632 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
Mike Stroyana3082432015-09-25 13:39:21 -060016633 ASSERT_VK_SUCCESS(err);
16634
Karl Schultz6addd812016-02-02 17:17:23 -070016635 image_create_info.imageType = VK_IMAGE_TYPE_1D;
16636 // Note: Some implementations expect color attachment usage for any
16637 // multisample surface
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016638 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
Karl Schultz6addd812016-02-02 17:17:23 -070016639 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060016640
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016641 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
Mike Stroyana3082432015-09-25 13:39:21 -060016642 ASSERT_VK_SUCCESS(err);
16643
16644 // Allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016645 VkMemoryAllocateInfo memAlloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -070016646 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
16647 memAlloc.pNext = NULL;
16648 memAlloc.allocationSize = 0;
16649 memAlloc.memoryTypeIndex = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060016650
Courtney Goeltzenleuchter06d89472015-10-20 16:40:38 -060016651 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060016652 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016653 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060016654 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016655 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
Mike Stroyana3082432015-09-25 13:39:21 -060016656 ASSERT_VK_SUCCESS(err);
16657
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016658 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060016659 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016660 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060016661 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016662 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
Mike Stroyana3082432015-09-25 13:39:21 -060016663 ASSERT_VK_SUCCESS(err);
16664
16665 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
16666 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016667 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
Mike Stroyana3082432015-09-25 13:39:21 -060016668 ASSERT_VK_SUCCESS(err);
16669
16670 BeginCommandBuffer();
16671 // Need memory barrier to VK_IMAGE_LAYOUT_GENERAL for source and dest?
Karl Schultz6addd812016-02-02 17:17:23 -070016672 // VK_IMAGE_LAYOUT_UNDEFINED = 0,
16673 // VK_IMAGE_LAYOUT_GENERAL = 1,
Mike Stroyana3082432015-09-25 13:39:21 -060016674 VkImageResolve resolveRegion;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080016675 resolveRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060016676 resolveRegion.srcSubresource.mipLevel = 0;
Courtney Goeltzenleuchter8367ce02015-10-16 09:46:00 -060016677 resolveRegion.srcSubresource.baseArrayLayer = 0;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016678 resolveRegion.srcSubresource.layerCount = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060016679 resolveRegion.srcOffset.x = 0;
16680 resolveRegion.srcOffset.y = 0;
16681 resolveRegion.srcOffset.z = 0;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080016682 resolveRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016683 resolveRegion.dstSubresource.mipLevel = 0;
16684 resolveRegion.dstSubresource.baseArrayLayer = 0;
16685 resolveRegion.dstSubresource.layerCount = 0;
16686 resolveRegion.dstOffset.x = 0;
16687 resolveRegion.dstOffset.y = 0;
16688 resolveRegion.dstOffset.z = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060016689 resolveRegion.extent.width = 1;
16690 resolveRegion.extent.height = 1;
16691 resolveRegion.extent.depth = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016692 m_commandBuffer->ResolveImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, VK_IMAGE_LAYOUT_GENERAL, 1, &resolveRegion);
Mike Stroyana3082432015-09-25 13:39:21 -060016693 EndCommandBuffer();
16694
Chris Forbes8f36a8a2016-04-07 13:21:07 +120016695 m_errorMonitor->VerifyFound();
Mike Stroyana3082432015-09-25 13:39:21 -060016696
Chia-I Wuf7458c52015-10-26 21:10:41 +080016697 vkDestroyImage(m_device->device(), srcImage, NULL);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016698 vkDestroyImage(m_device->device(), dstImage, NULL);
Chia-I Wuf7458c52015-10-26 21:10:41 +080016699 vkFreeMemory(m_device->device(), srcMem, NULL);
16700 vkFreeMemory(m_device->device(), destMem, NULL);
Mike Stroyana3082432015-09-25 13:39:21 -060016701}
Tobin Ehlisa1c28562015-10-23 16:00:08 -060016702
Karl Schultz6addd812016-02-02 17:17:23 -070016703TEST_F(VkLayerTest, DepthStencilImageViewWithColorAspectBitError) {
Tobin Ehlisa1c28562015-10-23 16:00:08 -060016704 // Create a single Image descriptor and cause it to first hit an error due
Karl Schultz6addd812016-02-02 17:17:23 -070016705 // to using a DS format, then cause it to hit error due to COLOR_BIT not
16706 // set in aspect
Tobin Ehlisa1c28562015-10-23 16:00:08 -060016707 // The image format check comes 2nd in validation so we trigger it first,
16708 // then when we cause aspect fail next, bad format check will be preempted
Karl Schultz6addd812016-02-02 17:17:23 -070016709 VkResult err;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060016710
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016711 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
16712 "Combination depth/stencil image formats can have only the ");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060016713
Tobin Ehlisa1c28562015-10-23 16:00:08 -060016714 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060016715
Chia-I Wu1b99bb22015-10-27 19:25:11 +080016716 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -070016717 ds_type_count.type = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE;
16718 ds_type_count.descriptorCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060016719
16720 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070016721 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
16722 ds_pool_ci.pNext = NULL;
16723 ds_pool_ci.maxSets = 1;
16724 ds_pool_ci.poolSizeCount = 1;
16725 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060016726
16727 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016728 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060016729 ASSERT_VK_SUCCESS(err);
16730
16731 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -070016732 dsl_binding.binding = 0;
16733 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE;
16734 dsl_binding.descriptorCount = 1;
16735 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
16736 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060016737
16738 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070016739 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
16740 ds_layout_ci.pNext = NULL;
16741 ds_layout_ci.bindingCount = 1;
16742 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060016743 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016744 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060016745 ASSERT_VK_SUCCESS(err);
16746
16747 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016748 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +080016749 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -070016750 alloc_info.descriptorSetCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060016751 alloc_info.descriptorPool = ds_pool;
16752 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016753 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060016754 ASSERT_VK_SUCCESS(err);
16755
Karl Schultz6addd812016-02-02 17:17:23 -070016756 VkImage image_bad;
16757 VkImage image_good;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060016758 // One bad format and one good format for Color attachment
Tobin Ehlis269f0322016-05-25 16:24:21 -060016759 const VkFormat tex_format_bad = VK_FORMAT_D24_UNORM_S8_UINT;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060016760 const VkFormat tex_format_good = VK_FORMAT_B8G8R8A8_UNORM;
Karl Schultz6addd812016-02-02 17:17:23 -070016761 const int32_t tex_width = 32;
16762 const int32_t tex_height = 32;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060016763
16764 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070016765 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
16766 image_create_info.pNext = NULL;
16767 image_create_info.imageType = VK_IMAGE_TYPE_2D;
16768 image_create_info.format = tex_format_bad;
16769 image_create_info.extent.width = tex_width;
16770 image_create_info.extent.height = tex_height;
16771 image_create_info.extent.depth = 1;
16772 image_create_info.mipLevels = 1;
16773 image_create_info.arrayLayers = 1;
16774 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
16775 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016776 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT | VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT;
Karl Schultz6addd812016-02-02 17:17:23 -070016777 image_create_info.flags = 0;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060016778
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016779 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image_bad);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060016780 ASSERT_VK_SUCCESS(err);
16781 image_create_info.format = tex_format_good;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016782 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
16783 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image_good);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060016784 ASSERT_VK_SUCCESS(err);
16785
16786 VkImageViewCreateInfo image_view_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070016787 image_view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
16788 image_view_create_info.image = image_bad;
16789 image_view_create_info.viewType = VK_IMAGE_VIEW_TYPE_2D;
16790 image_view_create_info.format = tex_format_bad;
16791 image_view_create_info.subresourceRange.baseArrayLayer = 0;
16792 image_view_create_info.subresourceRange.baseMipLevel = 0;
16793 image_view_create_info.subresourceRange.layerCount = 1;
16794 image_view_create_info.subresourceRange.levelCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016795 image_view_create_info.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060016796
16797 VkImageView view;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016798 err = vkCreateImageView(m_device->device(), &image_view_create_info, NULL, &view);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060016799
Chris Forbes8f36a8a2016-04-07 13:21:07 +120016800 m_errorMonitor->VerifyFound();
Tobin Ehlisa1c28562015-10-23 16:00:08 -060016801
Chia-I Wuf7458c52015-10-26 21:10:41 +080016802 vkDestroyImage(m_device->device(), image_bad, NULL);
16803 vkDestroyImage(m_device->device(), image_good, NULL);
Chia-I Wuf7458c52015-10-26 21:10:41 +080016804 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
16805 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060016806}
Tobin Ehlis6e23d772016-05-19 11:08:34 -060016807
16808TEST_F(VkLayerTest, ClearImageErrors) {
16809 TEST_DESCRIPTION("Call ClearColorImage w/ a depth|stencil image and "
16810 "ClearDepthStencilImage with a color image.");
16811
16812 ASSERT_NO_FATAL_FAILURE(InitState());
16813 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
16814
16815 // Renderpass is started here so end it as Clear cmds can't be in renderpass
16816 BeginCommandBuffer();
16817 m_commandBuffer->EndRenderPass();
16818
16819 // Color image
16820 VkClearColorValue clear_color;
16821 memset(clear_color.uint32, 0, sizeof(uint32_t) * 4);
16822 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
16823 const VkFormat color_format = VK_FORMAT_B8G8R8A8_UNORM;
16824 const int32_t img_width = 32;
16825 const int32_t img_height = 32;
16826 VkImageCreateInfo image_create_info = {};
16827 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
16828 image_create_info.pNext = NULL;
16829 image_create_info.imageType = VK_IMAGE_TYPE_2D;
16830 image_create_info.format = color_format;
16831 image_create_info.extent.width = img_width;
16832 image_create_info.extent.height = img_height;
16833 image_create_info.extent.depth = 1;
16834 image_create_info.mipLevels = 1;
16835 image_create_info.arrayLayers = 1;
16836 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
16837 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
16838 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
16839
16840 vk_testing::Image color_image;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016841 color_image.init(*m_device, (const VkImageCreateInfo &)image_create_info, reqs);
Tobin Ehlis6e23d772016-05-19 11:08:34 -060016842
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016843 const VkImageSubresourceRange color_range = vk_testing::Image::subresource_range(image_create_info, VK_IMAGE_ASPECT_COLOR_BIT);
Tobin Ehlis6e23d772016-05-19 11:08:34 -060016844
16845 // Depth/Stencil image
16846 VkClearDepthStencilValue clear_value = {0};
16847 reqs = 0; // don't need HOST_VISIBLE DS image
16848 VkImageCreateInfo ds_image_create_info = vk_testing::Image::create_info();
16849 ds_image_create_info.imageType = VK_IMAGE_TYPE_2D;
16850 ds_image_create_info.format = VK_FORMAT_D24_UNORM_S8_UINT;
16851 ds_image_create_info.extent.width = 64;
16852 ds_image_create_info.extent.height = 64;
16853 ds_image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
16854 ds_image_create_info.usage = VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT;
16855
16856 vk_testing::Image ds_image;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016857 ds_image.init(*m_device, (const VkImageCreateInfo &)ds_image_create_info, reqs);
Tobin Ehlis6e23d772016-05-19 11:08:34 -060016858
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016859 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 -060016860
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016861 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "vkCmdClearColorImage called with depth/stencil image.");
Tobin Ehlis6e23d772016-05-19 11:08:34 -060016862
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016863 vkCmdClearColorImage(m_commandBuffer->GetBufferHandle(), ds_image.handle(), VK_IMAGE_LAYOUT_GENERAL, &clear_color, 1,
Tobin Ehlis6e23d772016-05-19 11:08:34 -060016864 &color_range);
16865
16866 m_errorMonitor->VerifyFound();
16867
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016868 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "vkCmdClearColorImage called with "
16869 "image created without "
16870 "VK_IMAGE_USAGE_TRANSFER_DST_BIT");
Tony Barbour26434b92016-06-02 09:43:50 -060016871
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016872 vkCmdClearColorImage(m_commandBuffer->GetBufferHandle(), ds_image.handle(), VK_IMAGE_LAYOUT_GENERAL, &clear_color, 1,
Tony Barbour26434b92016-06-02 09:43:50 -060016873 &color_range);
16874
16875 m_errorMonitor->VerifyFound();
16876
Tobin Ehlis6e23d772016-05-19 11:08:34 -060016877 // Call CmdClearDepthStencilImage with color image
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016878 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
16879 "vkCmdClearDepthStencilImage called without a depth/stencil image.");
Tobin Ehlis6e23d772016-05-19 11:08:34 -060016880
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016881 vkCmdClearDepthStencilImage(m_commandBuffer->GetBufferHandle(), color_image.handle(),
16882 VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL, &clear_value, 1, &ds_range);
Tobin Ehlis6e23d772016-05-19 11:08:34 -060016883
16884 m_errorMonitor->VerifyFound();
16885}
Tobin Ehliscde08892015-09-22 10:11:37 -060016886#endif // IMAGE_TESTS
16887
Cody Northrop1242dfd2016-07-13 17:24:59 -060016888#if defined(ANDROID) && defined(VALIDATION_APK)
16889static bool initialized = false;
16890static bool active = false;
16891
16892// Convert Intents to argv
16893// Ported from Hologram sample, only difference is flexible key
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016894std::vector<std::string> get_args(android_app &app, const char *intent_extra_data_key) {
Cody Northrop1242dfd2016-07-13 17:24:59 -060016895 std::vector<std::string> args;
16896 JavaVM &vm = *app.activity->vm;
16897 JNIEnv *p_env;
16898 if (vm.AttachCurrentThread(&p_env, nullptr) != JNI_OK)
16899 return args;
16900
16901 JNIEnv &env = *p_env;
16902 jobject activity = app.activity->clazz;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016903 jmethodID get_intent_method = env.GetMethodID(env.GetObjectClass(activity), "getIntent", "()Landroid/content/Intent;");
Cody Northrop1242dfd2016-07-13 17:24:59 -060016904 jobject intent = env.CallObjectMethod(activity, get_intent_method);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016905 jmethodID get_string_extra_method =
16906 env.GetMethodID(env.GetObjectClass(intent), "getStringExtra", "(Ljava/lang/String;)Ljava/lang/String;");
Cody Northrop1242dfd2016-07-13 17:24:59 -060016907 jvalue get_string_extra_args;
16908 get_string_extra_args.l = env.NewStringUTF(intent_extra_data_key);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016909 jstring extra_str = static_cast<jstring>(env.CallObjectMethodA(intent, get_string_extra_method, &get_string_extra_args));
Cody Northrop1242dfd2016-07-13 17:24:59 -060016910
16911 std::string args_str;
16912 if (extra_str) {
16913 const char *extra_utf = env.GetStringUTFChars(extra_str, nullptr);
16914 args_str = extra_utf;
16915 env.ReleaseStringUTFChars(extra_str, extra_utf);
16916 env.DeleteLocalRef(extra_str);
16917 }
16918
16919 env.DeleteLocalRef(get_string_extra_args.l);
16920 env.DeleteLocalRef(intent);
16921 vm.DetachCurrentThread();
16922
16923 // split args_str
16924 std::stringstream ss(args_str);
16925 std::string arg;
16926 while (std::getline(ss, arg, ' ')) {
16927 if (!arg.empty())
16928 args.push_back(arg);
16929 }
16930
16931 return args;
16932}
16933
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016934static int32_t processInput(struct android_app *app, AInputEvent *event) { return 0; }
Cody Northrop1242dfd2016-07-13 17:24:59 -060016935
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016936static void processCommand(struct android_app *app, int32_t cmd) {
16937 switch (cmd) {
16938 case APP_CMD_INIT_WINDOW: {
16939 if (app->window) {
16940 initialized = true;
Cody Northrop1242dfd2016-07-13 17:24:59 -060016941 }
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016942 break;
16943 }
16944 case APP_CMD_GAINED_FOCUS: {
16945 active = true;
16946 break;
16947 }
16948 case APP_CMD_LOST_FOCUS: {
16949 active = false;
16950 break;
16951 }
Cody Northrop1242dfd2016-07-13 17:24:59 -060016952 }
16953}
16954
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016955void android_main(struct android_app *app) {
Cody Northrop1242dfd2016-07-13 17:24:59 -060016956 app_dummy();
16957
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016958 const char *appTag = "VulkanLayerValidationTests";
Cody Northrop1242dfd2016-07-13 17:24:59 -060016959
16960 int vulkanSupport = InitVulkan();
16961 if (vulkanSupport == 0) {
16962 __android_log_print(ANDROID_LOG_INFO, appTag, "==== FAILED ==== No Vulkan support found");
16963 return;
16964 }
16965
16966 app->onAppCmd = processCommand;
16967 app->onInputEvent = processInput;
16968
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016969 while (1) {
Cody Northrop1242dfd2016-07-13 17:24:59 -060016970 int events;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016971 struct android_poll_source *source;
16972 while (ALooper_pollAll(active ? 0 : -1, NULL, &events, (void **)&source) >= 0) {
Cody Northrop1242dfd2016-07-13 17:24:59 -060016973 if (source) {
16974 source->process(app, source);
16975 }
16976
16977 if (app->destroyRequested != 0) {
16978 VkTestFramework::Finish();
16979 return;
16980 }
16981 }
16982
16983 if (initialized && active) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016984 // Use the following key to send arguments to gtest, i.e.
16985 // --es args "--gtest_filter=-VkLayerTest.foo"
16986 const char key[] = "args";
16987 std::vector<std::string> args = get_args(*app, key);
Cody Northrop1242dfd2016-07-13 17:24:59 -060016988
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016989 std::string filter = "";
16990 if (args.size() > 0) {
16991 __android_log_print(ANDROID_LOG_INFO, appTag, "Intent args = %s", args[0].c_str());
16992 filter += args[0];
16993 } else {
16994 __android_log_print(ANDROID_LOG_INFO, appTag, "No Intent args detected");
16995 }
Cody Northrop1242dfd2016-07-13 17:24:59 -060016996
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016997 int argc = 2;
16998 char *argv[] = {(char *)"foo", (char *)filter.c_str()};
16999 __android_log_print(ANDROID_LOG_DEBUG, appTag, "filter = %s", argv[1]);
Cody Northrop1242dfd2016-07-13 17:24:59 -060017000
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017001 // Route output to files until we can override the gtest output
17002 freopen("/sdcard/Android/data/com.example.VulkanLayerValidationTests/files/out.txt", "w", stdout);
17003 freopen("/sdcard/Android/data/com.example.VulkanLayerValidationTests/files/err.txt", "w", stderr);
Cody Northrop1242dfd2016-07-13 17:24:59 -060017004
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017005 ::testing::InitGoogleTest(&argc, argv);
17006 VkTestFramework::InitArgs(&argc, argv);
17007 ::testing::AddGlobalTestEnvironment(new TestEnvironment);
Cody Northrop1242dfd2016-07-13 17:24:59 -060017008
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017009 int result = RUN_ALL_TESTS();
Cody Northrop1242dfd2016-07-13 17:24:59 -060017010
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017011 if (result != 0) {
17012 __android_log_print(ANDROID_LOG_INFO, appTag, "==== Tests FAILED ====");
17013 } else {
17014 __android_log_print(ANDROID_LOG_INFO, appTag, "==== Tests PASSED ====");
17015 }
Cody Northrop1242dfd2016-07-13 17:24:59 -060017016
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017017 VkTestFramework::Finish();
Cody Northrop1242dfd2016-07-13 17:24:59 -060017018
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017019 fclose(stdout);
17020 fclose(stderr);
Cody Northrop1242dfd2016-07-13 17:24:59 -060017021
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017022 ANativeActivity_finish(app->activity);
Cody Northrop1242dfd2016-07-13 17:24:59 -060017023
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017024 return;
Cody Northrop1242dfd2016-07-13 17:24:59 -060017025 }
17026 }
17027}
17028#endif
17029
Tony Barbour300a6082015-04-07 13:44:53 -060017030int main(int argc, char **argv) {
17031 int result;
17032
Cody Northrop8e54a402016-03-08 22:25:52 -070017033#ifdef ANDROID
17034 int vulkanSupport = InitVulkan();
17035 if (vulkanSupport == 0)
17036 return 1;
17037#endif
17038
Tony Barbour300a6082015-04-07 13:44:53 -060017039 ::testing::InitGoogleTest(&argc, argv);
Tony Barbour6918cd52015-04-09 12:58:51 -060017040 VkTestFramework::InitArgs(&argc, argv);
Tony Barbour300a6082015-04-07 13:44:53 -060017041
17042 ::testing::AddGlobalTestEnvironment(new TestEnvironment);
17043
17044 result = RUN_ALL_TESTS();
17045
Tony Barbour6918cd52015-04-09 12:58:51 -060017046 VkTestFramework::Finish();
Tony Barbour300a6082015-04-07 13:44:53 -060017047 return result;
17048}