blob: 341f557e7aa5fc6a4d5f8102d33f1cbc308848bf [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);
Mark Lobodzinski510e20d2016-02-11 09:26:16 -0700122 m_msgFlags = VK_DEBUG_REPORT_INFORMATION_BIT_EXT;
Karl Schultz6addd812016-02-02 17:17:23 -0700123 m_bailout = NULL;
Mike Stroyan4268d1f2015-07-13 14:45:35 -0600124 test_platform_thread_unlock_mutex(&m_mutex);
Tony Barbour300a6082015-04-07 13:44:53 -0600125 }
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600126
Dustin Graves48458142016-04-29 16:11:55 -0600127 ~ErrorMonitor() { test_platform_thread_delete_mutex(&m_mutex); }
128
Karl Schultz6addd812016-02-02 17:17:23 -0700129 void SetDesiredFailureMsg(VkFlags msgFlags, const char *msgString) {
Chris Forbes8f36a8a2016-04-07 13:21:07 +1200130 // also discard all collected messages to this point
Mike Stroyan4268d1f2015-07-13 14:45:35 -0600131 test_platform_thread_lock_mutex(&m_mutex);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600132 m_failureMsg.clear();
133 m_otherMsgs.clear();
134 m_desiredMsg = msgString;
Karl Schultz6addd812016-02-02 17:17:23 -0700135 m_msgFound = VK_FALSE;
136 m_msgFlags = msgFlags;
Mike Stroyan4268d1f2015-07-13 14:45:35 -0600137 test_platform_thread_unlock_mutex(&m_mutex);
Tony Barbour300a6082015-04-07 13:44:53 -0600138 }
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600139
Mark Lobodzinski7a588452016-08-03 14:04:26 -0600140 VkBool32 CheckForDesiredMsg(const char *msgString) {
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600141 VkBool32 result = VK_FALSE;
Mike Stroyan4268d1f2015-07-13 14:45:35 -0600142 test_platform_thread_lock_mutex(&m_mutex);
Mike Stroyanaccf7692015-05-12 16:00:45 -0600143 if (m_bailout != NULL) {
144 *m_bailout = true;
145 }
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600146 string errorString(msgString);
Mark Lobodzinski7a588452016-08-03 14:04:26 -0600147 if (errorString.find(m_desiredMsg) != string::npos) {
148 if (m_msgFound) { // If multiple matches, don't lose all but the last!
149 m_otherMsgs.push_back(m_failureMsg);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600150 }
Mark Lobodzinski7a588452016-08-03 14:04:26 -0600151 m_failureMsg = errorString;
152 m_msgFound = VK_TRUE;
153 result = VK_TRUE;
154 } else {
Chris Forbes5b9442b2016-09-13 16:49:57 +1200155 printf("Unexpected: %s\n", msgString);
Mark Lobodzinski7a588452016-08-03 14:04:26 -0600156 m_otherMsgs.push_back(errorString);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600157 }
Mike Stroyan4268d1f2015-07-13 14:45:35 -0600158 test_platform_thread_unlock_mutex(&m_mutex);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600159 return result;
Mike Stroyanaccf7692015-05-12 16:00:45 -0600160 }
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600161
Karl Schultz6addd812016-02-02 17:17:23 -0700162 vector<string> GetOtherFailureMsgs(void) { return m_otherMsgs; }
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600163
Karl Schultz6addd812016-02-02 17:17:23 -0700164 string GetFailureMsg(void) { return m_failureMsg; }
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600165
Mark Lobodzinski7a588452016-08-03 14:04:26 -0600166 VkDebugReportFlagsEXT GetMessageFlags(void) { return m_msgFlags; }
167
Karl Schultz6addd812016-02-02 17:17:23 -0700168 VkBool32 DesiredMsgFound(void) { return m_msgFound; }
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600169
Karl Schultz6addd812016-02-02 17:17:23 -0700170 void SetBailout(bool *bailout) { m_bailout = bailout; }
Tony Barbour300a6082015-04-07 13:44:53 -0600171
Karl Schultz6addd812016-02-02 17:17:23 -0700172 void DumpFailureMsgs(void) {
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600173 vector<string> otherMsgs = GetOtherFailureMsgs();
174 cout << "Other error messages logged for this test were:" << endl;
175 for (auto iter = otherMsgs.begin(); iter != otherMsgs.end(); iter++) {
176 cout << " " << *iter << endl;
177 }
178 }
179
Mark Lobodzinski7a588452016-08-03 14:04:26 -0600180 // Helpers
Chris Forbes8f36a8a2016-04-07 13:21:07 +1200181
Mark Lobodzinski7a588452016-08-03 14:04:26 -0600182 // ExpectSuccess now takes an optional argument allowing a custom combination of debug flags
183 void ExpectSuccess(VkDebugReportFlagsEXT message_flag_mask = VK_DEBUG_REPORT_ERROR_BIT_EXT) {
184 m_msgFlags = message_flag_mask;
185 // Match ANY message matching specified type
186 SetDesiredFailureMsg(message_flag_mask, "");
Chris Forbes8f36a8a2016-04-07 13:21:07 +1200187 }
188
189 void VerifyFound() {
190 // Not seeing the desired message is a failure. /Before/ throwing, dump
191 // any other messages.
192 if (!DesiredMsgFound()) {
193 DumpFailureMsgs();
194 FAIL() << "Did not receive expected error '" << m_desiredMsg << "'";
195 }
196 }
197
198 void VerifyNotFound() {
199 // ExpectSuccess() configured us to match anything. Any error is a
200 // failure.
201 if (DesiredMsgFound()) {
202 DumpFailureMsgs();
203 FAIL() << "Expected to succeed but got error: " << GetFailureMsg();
204 }
205 }
206
Karl Schultz6addd812016-02-02 17:17:23 -0700207 private:
208 VkFlags m_msgFlags;
209 string m_desiredMsg;
210 string m_failureMsg;
211 vector<string> m_otherMsgs;
Mike Stroyan4268d1f2015-07-13 14:45:35 -0600212 test_platform_thread_mutex m_mutex;
Karl Schultz6addd812016-02-02 17:17:23 -0700213 bool *m_bailout;
214 VkBool32 m_msgFound;
Tony Barbour300a6082015-04-07 13:44:53 -0600215};
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500216
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600217static VKAPI_ATTR VkBool32 VKAPI_CALL myDbgFunc(VkFlags msgFlags, VkDebugReportObjectTypeEXT objType, uint64_t srcObject,
218 size_t location, int32_t msgCode, const char *pLayerPrefix, const char *pMsg,
219 void *pUserData) {
Mark Lobodzinski7a588452016-08-03 14:04:26 -0600220 ErrorMonitor *errMonitor = (ErrorMonitor *)pUserData;
221 if (msgFlags & errMonitor->GetMessageFlags()) {
222 return errMonitor->CheckForDesiredMsg(pMsg);
Tony Barbour0b4d9562015-04-09 10:48:04 -0600223 }
Courtney Goeltzenleuchter06640832015-09-04 13:52:24 -0600224 return false;
Tony Barbour300a6082015-04-07 13:44:53 -0600225}
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500226
Karl Schultz6addd812016-02-02 17:17:23 -0700227class VkLayerTest : public VkRenderFramework {
228 public:
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800229 VkResult BeginCommandBuffer(VkCommandBufferObj &commandBuffer);
230 VkResult EndCommandBuffer(VkCommandBufferObj &commandBuffer);
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600231 void VKTriangleTest(const char *vertShaderText, const char *fragShaderText, BsoFailSelect failMask);
232 void GenericDrawPreparation(VkCommandBufferObj *commandBuffer, VkPipelineObj &pipelineobj, VkDescriptorSetObj &descriptorSet,
Karl Schultz6addd812016-02-02 17:17:23 -0700233 BsoFailSelect failMask);
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600234 void GenericDrawPreparation(VkPipelineObj &pipelineobj, VkDescriptorSetObj &descriptorSet, BsoFailSelect failMask) {
235 GenericDrawPreparation(m_commandBuffer, pipelineobj, descriptorSet, failMask);
Karl Schultz6addd812016-02-02 17:17:23 -0700236 }
Tony Barbour300a6082015-04-07 13:44:53 -0600237
Tony Barbourfe3351b2015-07-28 10:17:20 -0600238 /* Convenience functions that use built-in command buffer */
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600239 VkResult BeginCommandBuffer() { return BeginCommandBuffer(*m_commandBuffer); }
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800240 VkResult EndCommandBuffer() { return EndCommandBuffer(*m_commandBuffer); }
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600241 void Draw(uint32_t vertexCount, uint32_t instanceCount, uint32_t firstVertex, uint32_t firstInstance) {
242 m_commandBuffer->Draw(vertexCount, instanceCount, firstVertex, firstInstance);
Karl Schultz6addd812016-02-02 17:17:23 -0700243 }
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600244 void DrawIndexed(uint32_t indexCount, uint32_t instanceCount, uint32_t firstIndex, int32_t vertexOffset,
Karl Schultz6addd812016-02-02 17:17:23 -0700245 uint32_t firstInstance) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600246 m_commandBuffer->DrawIndexed(indexCount, instanceCount, firstIndex, vertexOffset, firstInstance);
Karl Schultz6addd812016-02-02 17:17:23 -0700247 }
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600248 void QueueCommandBuffer(bool checkSuccess = true) { m_commandBuffer->QueueCommandBuffer(checkSuccess); }
249 void QueueCommandBuffer(const VkFence &fence) { m_commandBuffer->QueueCommandBuffer(fence); }
250 void BindVertexBuffer(VkConstantBufferObj *vertexBuffer, VkDeviceSize offset, uint32_t binding) {
Karl Schultz6addd812016-02-02 17:17:23 -0700251 m_commandBuffer->BindVertexBuffer(vertexBuffer, offset, binding);
252 }
253 void BindIndexBuffer(VkIndexBufferObj *indexBuffer, VkDeviceSize offset) {
254 m_commandBuffer->BindIndexBuffer(indexBuffer, offset);
255 }
256
257 protected:
258 ErrorMonitor *m_errorMonitor;
Ian Elliott2c1daf52016-05-12 09:41:46 -0600259 bool m_enableWSI;
Tony Barbour300a6082015-04-07 13:44:53 -0600260
261 virtual void SetUp() {
Courtney Goeltzenleuchtercd69eee2015-07-06 09:10:47 -0600262 std::vector<const char *> instance_layer_names;
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -0600263 std::vector<const char *> instance_extension_names;
264 std::vector<const char *> device_extension_names;
Tony Barbour3fdff9e2015-04-23 12:55:36 -0600265
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -0700266 instance_extension_names.push_back(VK_EXT_DEBUG_REPORT_EXTENSION_NAME);
Courtney Goeltzenleuchterc2b06fe2015-06-16 15:59:11 -0600267 /*
268 * Since CreateDbgMsgCallback is an instance level extension call
269 * any extension / layer that utilizes that feature also needs
270 * to be enabled at create instance time.
271 */
Karl Schultz6addd812016-02-02 17:17:23 -0700272 // Use Threading layer first to protect others from
273 // ThreadCommandBufferCollision test
Courtney Goeltzenleuchter76885322016-02-06 17:11:22 -0700274 instance_layer_names.push_back("VK_LAYER_GOOGLE_threading");
Tobin Ehlis24aab042016-03-24 10:54:18 -0600275 instance_layer_names.push_back("VK_LAYER_LUNARG_parameter_validation");
Michael Lentine03107b42015-12-11 10:49:51 -0800276 instance_layer_names.push_back("VK_LAYER_LUNARG_object_tracker");
Tobin Ehlisc96f8062016-03-09 16:12:48 -0700277 instance_layer_names.push_back("VK_LAYER_LUNARG_core_validation");
Michael Lentine03107b42015-12-11 10:49:51 -0800278 instance_layer_names.push_back("VK_LAYER_LUNARG_image");
Ian Elliotte48a1382016-04-28 14:22:58 -0600279 instance_layer_names.push_back("VK_LAYER_LUNARG_swapchain");
Dustin Graveseaa78cd2016-01-26 16:30:22 -0700280 instance_layer_names.push_back("VK_LAYER_GOOGLE_unique_objects");
Courtney Goeltzenleuchterd971b612015-06-17 20:51:59 -0600281
Ian Elliott2c1daf52016-05-12 09:41:46 -0600282 if (m_enableWSI) {
283 instance_extension_names.push_back(VK_KHR_SURFACE_EXTENSION_NAME);
284 device_extension_names.push_back(VK_KHR_SWAPCHAIN_EXTENSION_NAME);
285#ifdef NEED_TO_TEST_THIS_ON_PLATFORM
286#if defined(VK_USE_PLATFORM_ANDROID_KHR)
287 instance_extension_names.push_back(VK_KHR_ANDROID_SURFACE_EXTENSION_NAME);
288#endif // VK_USE_PLATFORM_ANDROID_KHR
289#if defined(VK_USE_PLATFORM_MIR_KHR)
290 instance_extension_names.push_back(VK_KHR_MIR_SURFACE_EXTENSION_NAME);
291#endif // VK_USE_PLATFORM_MIR_KHR
292#if defined(VK_USE_PLATFORM_WAYLAND_KHR)
293 instance_extension_names.push_back(VK_KHR_WAYLAND_SURFACE_EXTENSION_NAME);
294#endif // VK_USE_PLATFORM_WAYLAND_KHR
295#if defined(VK_USE_PLATFORM_WIN32_KHR)
296 instance_extension_names.push_back(VK_KHR_WIN32_SURFACE_EXTENSION_NAME);
297#endif // VK_USE_PLATFORM_WIN32_KHR
298#endif // NEED_TO_TEST_THIS_ON_PLATFORM
299#if defined(VK_USE_PLATFORM_XCB_KHR)
300 instance_extension_names.push_back(VK_KHR_XCB_SURFACE_EXTENSION_NAME);
301#elif defined(VK_USE_PLATFORM_XLIB_KHR)
302 instance_extension_names.push_back(VK_KHR_XLIB_SURFACE_EXTENSION_NAME);
303#endif // VK_USE_PLATFORM_XLIB_KHR
304 }
305
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600306 this->app_info.sType = VK_STRUCTURE_TYPE_APPLICATION_INFO;
Tony Barbour300a6082015-04-07 13:44:53 -0600307 this->app_info.pNext = NULL;
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800308 this->app_info.pApplicationName = "layer_tests";
309 this->app_info.applicationVersion = 1;
Tony Barbour300a6082015-04-07 13:44:53 -0600310 this->app_info.pEngineName = "unittest";
311 this->app_info.engineVersion = 1;
Jon Ashburnc5012ff2016-03-22 13:57:46 -0600312 this->app_info.apiVersion = VK_API_VERSION_1_0;
Tony Barbour300a6082015-04-07 13:44:53 -0600313
Tony Barbour15524c32015-04-29 17:34:29 -0600314 m_errorMonitor = new ErrorMonitor;
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600315 InitFramework(instance_layer_names, instance_extension_names, device_extension_names, myDbgFunc, m_errorMonitor);
Tony Barbour300a6082015-04-07 13:44:53 -0600316 }
317
318 virtual void TearDown() {
319 // Clean up resources before we reset
Tony Barbour300a6082015-04-07 13:44:53 -0600320 ShutdownFramework();
Tony Barbour0b4d9562015-04-09 10:48:04 -0600321 delete m_errorMonitor;
Tony Barbour300a6082015-04-07 13:44:53 -0600322 }
Ian Elliott2c1daf52016-05-12 09:41:46 -0600323
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600324 VkLayerTest() { m_enableWSI = false; }
Tony Barbour300a6082015-04-07 13:44:53 -0600325};
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500326
Karl Schultz6addd812016-02-02 17:17:23 -0700327VkResult VkLayerTest::BeginCommandBuffer(VkCommandBufferObj &commandBuffer) {
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600328 VkResult result;
Tony Barbour300a6082015-04-07 13:44:53 -0600329
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800330 result = commandBuffer.BeginCommandBuffer();
Tony Barbour300a6082015-04-07 13:44:53 -0600331
332 /*
333 * For render test all drawing happens in a single render pass
334 * on a single command buffer.
335 */
Chris Forbes76a5eeb2015-06-16 14:05:59 +1200336 if (VK_SUCCESS == result && renderPass()) {
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800337 commandBuffer.BeginRenderPass(renderPassBeginInfo());
Tony Barbour300a6082015-04-07 13:44:53 -0600338 }
339
340 return result;
341}
342
Karl Schultz6addd812016-02-02 17:17:23 -0700343VkResult VkLayerTest::EndCommandBuffer(VkCommandBufferObj &commandBuffer) {
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600344 VkResult result;
Tony Barbour300a6082015-04-07 13:44:53 -0600345
Chris Forbes76a5eeb2015-06-16 14:05:59 +1200346 if (renderPass()) {
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800347 commandBuffer.EndRenderPass();
Chris Forbes76a5eeb2015-06-16 14:05:59 +1200348 }
Tony Barbour300a6082015-04-07 13:44:53 -0600349
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800350 result = commandBuffer.EndCommandBuffer();
Tony Barbour300a6082015-04-07 13:44:53 -0600351
352 return result;
353}
354
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600355void VkLayerTest::VKTriangleTest(const char *vertShaderText, const char *fragShaderText, BsoFailSelect failMask) {
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500356 // Create identity matrix
357 int i;
358 struct vktriangle_vs_uniform data;
359
360 glm::mat4 Projection = glm::mat4(1.0f);
Karl Schultz6addd812016-02-02 17:17:23 -0700361 glm::mat4 View = glm::mat4(1.0f);
362 glm::mat4 Model = glm::mat4(1.0f);
363 glm::mat4 MVP = Projection * View * Model;
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500364 const int matrixSize = sizeof(MVP);
Karl Schultz6addd812016-02-02 17:17:23 -0700365 const int bufSize = sizeof(vktriangle_vs_uniform) / sizeof(float);
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500366
367 memcpy(&data.mvp, &MVP[0][0], matrixSize);
368
Karl Schultz6addd812016-02-02 17:17:23 -0700369 static const Vertex tri_data[] = {
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600370 {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 -0500371 };
372
Karl Schultz6addd812016-02-02 17:17:23 -0700373 for (i = 0; i < 3; i++) {
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500374 data.position[i][0] = tri_data[i].posX;
375 data.position[i][1] = tri_data[i].posY;
376 data.position[i][2] = tri_data[i].posZ;
377 data.position[i][3] = tri_data[i].posW;
Karl Schultz6addd812016-02-02 17:17:23 -0700378 data.color[i][0] = tri_data[i].r;
379 data.color[i][1] = tri_data[i].g;
380 data.color[i][2] = tri_data[i].b;
381 data.color[i][3] = tri_data[i].a;
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500382 }
383
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500384 ASSERT_NO_FATAL_FAILURE(InitViewport());
385
Chris Forbesbcfaadd2016-09-16 14:13:53 +1200386 VkConstantBufferObj constantBuffer(m_device, bufSize * 2, sizeof(float), (const void *)&data,
387 VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT);
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500388
Karl Schultz6addd812016-02-02 17:17:23 -0700389 VkShaderObj vs(m_device, vertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600390 VkShaderObj ps(m_device, fragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500391
392 VkPipelineObj pipelineobj(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +0800393 pipelineobj.AddColorAttachment();
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500394 pipelineobj.AddShader(&vs);
395 pipelineobj.AddShader(&ps);
Courtney Goeltzenleuchter507ba972015-09-30 16:16:57 -0600396 if (failMask & BsoFailLineWidth) {
397 pipelineobj.MakeDynamic(VK_DYNAMIC_STATE_LINE_WIDTH);
Tobin Ehlis7a1d2352016-03-28 11:18:19 -0600398 VkPipelineInputAssemblyStateCreateInfo ia_state = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600399 ia_state.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
Tobin Ehlis7a1d2352016-03-28 11:18:19 -0600400 ia_state.topology = VK_PRIMITIVE_TOPOLOGY_LINE_LIST;
401 pipelineobj.SetInputAssembly(&ia_state);
Courtney Goeltzenleuchter507ba972015-09-30 16:16:57 -0600402 }
403 if (failMask & BsoFailDepthBias) {
404 pipelineobj.MakeDynamic(VK_DYNAMIC_STATE_DEPTH_BIAS);
Tobin Ehlis7a1d2352016-03-28 11:18:19 -0600405 VkPipelineRasterizationStateCreateInfo rs_state = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600406 rs_state.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
Tobin Ehlis7a1d2352016-03-28 11:18:19 -0600407 rs_state.depthBiasEnable = VK_TRUE;
Mark Young7394fdd2016-03-31 14:56:43 -0600408 rs_state.lineWidth = 1.0f;
Tobin Ehlis7a1d2352016-03-28 11:18:19 -0600409 pipelineobj.SetRasterization(&rs_state);
Courtney Goeltzenleuchter507ba972015-09-30 16:16:57 -0600410 }
Karl Schultz6addd812016-02-02 17:17:23 -0700411 // Viewport and scissors must stay in synch or other errors will occur than
412 // the ones we want
Courtney Goeltzenleuchter507ba972015-09-30 16:16:57 -0600413 if (failMask & BsoFailViewport) {
414 pipelineobj.MakeDynamic(VK_DYNAMIC_STATE_VIEWPORT);
Tobin Ehlisd332f282015-10-02 11:00:56 -0600415 m_viewports.clear();
416 m_scissors.clear();
Courtney Goeltzenleuchter507ba972015-09-30 16:16:57 -0600417 }
418 if (failMask & BsoFailScissor) {
419 pipelineobj.MakeDynamic(VK_DYNAMIC_STATE_SCISSOR);
Tobin Ehlisd332f282015-10-02 11:00:56 -0600420 m_scissors.clear();
421 m_viewports.clear();
Courtney Goeltzenleuchter507ba972015-09-30 16:16:57 -0600422 }
423 if (failMask & BsoFailBlend) {
424 pipelineobj.MakeDynamic(VK_DYNAMIC_STATE_BLEND_CONSTANTS);
Tobin Ehlis7a1d2352016-03-28 11:18:19 -0600425 VkPipelineColorBlendAttachmentState att_state = {};
426 att_state.dstAlphaBlendFactor = VK_BLEND_FACTOR_CONSTANT_COLOR;
427 att_state.blendEnable = VK_TRUE;
428 pipelineobj.AddColorAttachment(0, &att_state);
Courtney Goeltzenleuchter507ba972015-09-30 16:16:57 -0600429 }
430 if (failMask & BsoFailDepthBounds) {
431 pipelineobj.MakeDynamic(VK_DYNAMIC_STATE_DEPTH_BOUNDS);
432 }
433 if (failMask & BsoFailStencilReadMask) {
434 pipelineobj.MakeDynamic(VK_DYNAMIC_STATE_STENCIL_COMPARE_MASK);
435 }
436 if (failMask & BsoFailStencilWriteMask) {
437 pipelineobj.MakeDynamic(VK_DYNAMIC_STATE_STENCIL_WRITE_MASK);
438 }
439 if (failMask & BsoFailStencilReference) {
440 pipelineobj.MakeDynamic(VK_DYNAMIC_STATE_STENCIL_REFERENCE);
441 }
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500442
443 VkDescriptorSetObj descriptorSet(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600444 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, constantBuffer);
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500445
446 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barbourfe3351b2015-07-28 10:17:20 -0600447 ASSERT_VK_SUCCESS(BeginCommandBuffer());
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500448
Tony Barbourfe3351b2015-07-28 10:17:20 -0600449 GenericDrawPreparation(pipelineobj, descriptorSet, failMask);
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500450
451 // render triangle
Tobin Ehlis379ba3b2016-07-19 11:22:29 -0600452 if (failMask & BsoFailIndexBuffer) {
453 // Use DrawIndexed w/o an index buffer bound
454 DrawIndexed(3, 1, 0, 0, 0);
455 } else {
456 Draw(3, 1, 0, 0);
457 }
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500458
Mark Muellerd4914412016-06-13 17:52:06 -0600459 if (failMask & BsoFailCmdClearAttachments) {
460 VkClearAttachment color_attachment = {};
461 color_attachment.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
462 color_attachment.colorAttachment = 1; // Someone who knew what they were doing would use 0 for the index;
463 VkClearRect clear_rect = {{{0, 0}, {static_cast<uint32_t>(m_width), static_cast<uint32_t>(m_height)}}, 0, 0};
464
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600465 vkCmdClearAttachments(m_commandBuffer->GetBufferHandle(), 1, &color_attachment, 1, &clear_rect);
Mark Muellerd4914412016-06-13 17:52:06 -0600466 }
467
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500468 // finalize recording of the command buffer
Tony Barbourfe3351b2015-07-28 10:17:20 -0600469 EndCommandBuffer();
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500470
Tony Barbourfe3351b2015-07-28 10:17:20 -0600471 QueueCommandBuffer();
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500472}
473
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600474void VkLayerTest::GenericDrawPreparation(VkCommandBufferObj *commandBuffer, VkPipelineObj &pipelineobj,
475 VkDescriptorSetObj &descriptorSet, BsoFailSelect failMask) {
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500476 if (m_depthStencil->Initialized()) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600477 commandBuffer->ClearAllBuffers(m_clear_color, m_depth_clear_color, m_stencil_clear_color, m_depthStencil);
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500478 } else {
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600479 commandBuffer->ClearAllBuffers(m_clear_color, m_depth_clear_color, m_stencil_clear_color, NULL);
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500480 }
481
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800482 commandBuffer->PrepareAttachments();
Karl Schultz6addd812016-02-02 17:17:23 -0700483 // Make sure depthWriteEnable is set so that Depth fail test will work
484 // correctly
485 // Make sure stencilTestEnable is set so that Stencil fail test will work
486 // correctly
Tony Barboureb254902015-07-15 12:50:33 -0600487 VkStencilOpState stencil = {};
Chia-I Wu1b99bb22015-10-27 19:25:11 +0800488 stencil.failOp = VK_STENCIL_OP_KEEP;
489 stencil.passOp = VK_STENCIL_OP_KEEP;
490 stencil.depthFailOp = VK_STENCIL_OP_KEEP;
491 stencil.compareOp = VK_COMPARE_OP_NEVER;
Tony Barboureb254902015-07-15 12:50:33 -0600492
493 VkPipelineDepthStencilStateCreateInfo ds_ci = {};
494 ds_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_DEPTH_STENCIL_STATE_CREATE_INFO;
Courtney Goeltzenleuchter507ba972015-09-30 16:16:57 -0600495 ds_ci.pNext = NULL;
496 ds_ci.depthTestEnable = VK_FALSE;
497 ds_ci.depthWriteEnable = VK_TRUE;
498 ds_ci.depthCompareOp = VK_COMPARE_OP_NEVER;
499 ds_ci.depthBoundsTestEnable = VK_FALSE;
Tobin Ehlis7a1d2352016-03-28 11:18:19 -0600500 if (failMask & BsoFailDepthBounds) {
501 ds_ci.depthBoundsTestEnable = VK_TRUE;
Tobin Ehlis21c88352016-05-26 06:15:45 -0600502 ds_ci.maxDepthBounds = 0.0f;
503 ds_ci.minDepthBounds = 0.0f;
Tobin Ehlis7a1d2352016-03-28 11:18:19 -0600504 }
Courtney Goeltzenleuchter507ba972015-09-30 16:16:57 -0600505 ds_ci.stencilTestEnable = VK_TRUE;
506 ds_ci.front = stencil;
507 ds_ci.back = stencil;
Tony Barboureb254902015-07-15 12:50:33 -0600508
Tobin Ehlis4bf96d12015-06-25 11:58:41 -0600509 pipelineobj.SetDepthStencil(&ds_ci);
Tobin Ehlisd332f282015-10-02 11:00:56 -0600510 pipelineobj.SetViewport(m_viewports);
511 pipelineobj.SetScissor(m_scissors);
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800512 descriptorSet.CreateVKDescriptorSet(commandBuffer);
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600513 VkResult err = pipelineobj.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Cody Northrop29a08f22015-08-27 10:20:35 -0600514 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800515 commandBuffer->BindPipeline(pipelineobj);
516 commandBuffer->BindDescriptorSet(descriptorSet);
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500517}
518
Ian Elliott2c1daf52016-05-12 09:41:46 -0600519class VkWsiEnabledLayerTest : public VkLayerTest {
520 public:
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600521 protected:
522 VkWsiEnabledLayerTest() { m_enableWSI = true; }
Ian Elliott2c1daf52016-05-12 09:41:46 -0600523};
524
Mark Muellerdfe37552016-07-07 14:47:42 -0600525class VkBufferTest {
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600526 public:
Mark Muellerdfe37552016-07-07 14:47:42 -0600527 enum eTestEnFlags {
528 eDoubleDelete,
529 eInvalidDeviceOffset,
530 eInvalidMemoryOffset,
531 eBindNullBuffer,
532 eFreeInvalidHandle,
Mark Mueller4042b652016-09-05 22:52:21 -0600533 eNone,
Mark Muellerdfe37552016-07-07 14:47:42 -0600534 };
535
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600536 enum eTestConditions { eOffsetAlignment = 1 };
Mark Muellerdfe37552016-07-07 14:47:42 -0600537
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600538 static bool GetTestConditionValid(VkDeviceObj *aVulkanDevice, eTestEnFlags aTestFlag, VkBufferUsageFlags aBufferUsage = 0) {
539 if (eInvalidDeviceOffset != aTestFlag && eInvalidMemoryOffset != aTestFlag) {
Mark Muellerdfe37552016-07-07 14:47:42 -0600540 return true;
541 }
542 VkDeviceSize offset_limit = 0;
543 if (eInvalidMemoryOffset == aTestFlag) {
544 VkBuffer vulkanBuffer;
545 VkBufferCreateInfo buffer_create_info = {};
546 buffer_create_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
547 buffer_create_info.size = 32;
548 buffer_create_info.usage = aBufferUsage;
549
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600550 vkCreateBuffer(aVulkanDevice->device(), &buffer_create_info, nullptr, &vulkanBuffer);
Mark Mueller4042b652016-09-05 22:52:21 -0600551 VkMemoryRequirements memory_reqs = {};
Mark Muellerdfe37552016-07-07 14:47:42 -0600552
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600553 vkGetBufferMemoryRequirements(aVulkanDevice->device(), vulkanBuffer, &memory_reqs);
Mark Muellerdfe37552016-07-07 14:47:42 -0600554 vkDestroyBuffer(aVulkanDevice->device(), vulkanBuffer, nullptr);
555 offset_limit = memory_reqs.alignment;
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600556 } else if ((VK_BUFFER_USAGE_UNIFORM_TEXEL_BUFFER_BIT | VK_BUFFER_USAGE_STORAGE_TEXEL_BUFFER_BIT) & aBufferUsage) {
557 offset_limit = aVulkanDevice->props.limits.minTexelBufferOffsetAlignment;
Mark Muellerdfe37552016-07-07 14:47:42 -0600558 } else if (VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT & aBufferUsage) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600559 offset_limit = aVulkanDevice->props.limits.minUniformBufferOffsetAlignment;
Mark Muellerdfe37552016-07-07 14:47:42 -0600560 } else if (VK_BUFFER_USAGE_STORAGE_BUFFER_BIT & aBufferUsage) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600561 offset_limit = aVulkanDevice->props.limits.minStorageBufferOffsetAlignment;
Mark Muellerdfe37552016-07-07 14:47:42 -0600562 }
563 if (eOffsetAlignment < offset_limit) {
564 return true;
565 }
566 return false;
567 }
568
569 // A constructor which performs validation tests within construction.
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600570 VkBufferTest(VkDeviceObj *aVulkanDevice, VkBufferUsageFlags aBufferUsage, eTestEnFlags aTestFlag = eNone)
571 : AllocateCurrent(false), BoundCurrent(false), CreateCurrent(false), VulkanDevice(aVulkanDevice->device()) {
Mark Muellerdfe37552016-07-07 14:47:42 -0600572
573 if (eBindNullBuffer == aTestFlag) {
574 VulkanMemory = 0;
575 vkBindBufferMemory(VulkanDevice, VulkanBuffer, VulkanMemory, 0);
576 } else {
577 VkBufferCreateInfo buffer_create_info = {};
578 buffer_create_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
579 buffer_create_info.size = 32;
580 buffer_create_info.usage = aBufferUsage;
581
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600582 vkCreateBuffer(VulkanDevice, &buffer_create_info, nullptr, &VulkanBuffer);
Mark Muellerdfe37552016-07-07 14:47:42 -0600583
584 CreateCurrent = true;
585
586 VkMemoryRequirements memory_requirements;
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600587 vkGetBufferMemoryRequirements(VulkanDevice, VulkanBuffer, &memory_requirements);
Mark Muellerdfe37552016-07-07 14:47:42 -0600588
589 VkMemoryAllocateInfo memory_allocate_info = {};
590 memory_allocate_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
591 memory_allocate_info.allocationSize = memory_requirements.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600592 bool pass = aVulkanDevice->phy().set_memory_type(memory_requirements.memoryTypeBits, &memory_allocate_info,
593 VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT);
Mark Muellerdfe37552016-07-07 14:47:42 -0600594 if (!pass) {
595 vkDestroyBuffer(VulkanDevice, VulkanBuffer, nullptr);
596 return;
597 }
598
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600599 vkAllocateMemory(VulkanDevice, &memory_allocate_info, NULL, &VulkanMemory);
Mark Muellerdfe37552016-07-07 14:47:42 -0600600 AllocateCurrent = true;
601 // NB: 1 is intentionally an invalid offset value
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600602 const bool offset_en = eInvalidDeviceOffset == aTestFlag || eInvalidMemoryOffset == aTestFlag;
603 vkBindBufferMemory(VulkanDevice, VulkanBuffer, VulkanMemory, offset_en ? eOffsetAlignment : 0);
Mark Muellerdfe37552016-07-07 14:47:42 -0600604 BoundCurrent = true;
605
606 InvalidDeleteEn = (eFreeInvalidHandle == aTestFlag);
607 }
608 }
609
610 ~VkBufferTest() {
611 if (CreateCurrent) {
612 vkDestroyBuffer(VulkanDevice, VulkanBuffer, nullptr);
613 }
614 if (AllocateCurrent) {
615 if (InvalidDeleteEn) {
616 union {
617 VkDeviceMemory device_memory;
618 unsigned long long index_access;
619 } bad_index;
620
621 bad_index.device_memory = VulkanMemory;
622 bad_index.index_access++;
623
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600624 vkFreeMemory(VulkanDevice, bad_index.device_memory, nullptr);
Mark Muellerdfe37552016-07-07 14:47:42 -0600625 }
626 vkFreeMemory(VulkanDevice, VulkanMemory, nullptr);
627 }
628 }
629
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600630 bool GetBufferCurrent() { return AllocateCurrent && BoundCurrent && CreateCurrent; }
Mark Muellerdfe37552016-07-07 14:47:42 -0600631
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600632 const VkBuffer &GetBuffer() { return VulkanBuffer; }
Mark Muellerdfe37552016-07-07 14:47:42 -0600633
634 void TestDoubleDestroy() {
635 // Destroy the buffer but leave the flag set, which will cause
636 // the buffer to be destroyed again in the destructor.
637 vkDestroyBuffer(VulkanDevice, VulkanBuffer, nullptr);
638 }
639
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600640 protected:
Mark Muellerdfe37552016-07-07 14:47:42 -0600641 bool AllocateCurrent;
642 bool BoundCurrent;
643 bool CreateCurrent;
644 bool InvalidDeleteEn;
645
646 VkBuffer VulkanBuffer;
647 VkDevice VulkanDevice;
648 VkDeviceMemory VulkanMemory;
Mark Muellerdfe37552016-07-07 14:47:42 -0600649};
650
651class VkVerticesObj {
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600652 public:
653 VkVerticesObj(VkDeviceObj *aVulkanDevice, unsigned aAttributeCount, unsigned aBindingCount, unsigned aByteStride,
Mark Muellerdfe37552016-07-07 14:47:42 -0600654 VkDeviceSize aVertexCount, const float *aVerticies)
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600655 : BoundCurrent(false), AttributeCount(aAttributeCount), BindingCount(aBindingCount), BindId(BindIdGenerator),
Mark Muellerdfe37552016-07-07 14:47:42 -0600656 PipelineVertexInputStateCreateInfo(),
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600657 VulkanMemoryBuffer(aVulkanDevice, 1, static_cast<int>(aByteStride * aVertexCount),
658 reinterpret_cast<const void *>(aVerticies), VK_BUFFER_USAGE_VERTEX_BUFFER_BIT) {
Mark Muellerdfe37552016-07-07 14:47:42 -0600659 BindIdGenerator++; // NB: This can wrap w/misuse
660
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600661 VertexInputAttributeDescription = new VkVertexInputAttributeDescription[AttributeCount];
662 VertexInputBindingDescription = new VkVertexInputBindingDescription[BindingCount];
Mark Muellerdfe37552016-07-07 14:47:42 -0600663
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600664 PipelineVertexInputStateCreateInfo.pVertexAttributeDescriptions = VertexInputAttributeDescription;
665 PipelineVertexInputStateCreateInfo.vertexAttributeDescriptionCount = AttributeCount;
666 PipelineVertexInputStateCreateInfo.pVertexBindingDescriptions = VertexInputBindingDescription;
667 PipelineVertexInputStateCreateInfo.vertexBindingDescriptionCount = BindingCount;
668 PipelineVertexInputStateCreateInfo.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
Mark Muellerdfe37552016-07-07 14:47:42 -0600669
670 unsigned i = 0;
671 do {
672 VertexInputAttributeDescription[i].binding = BindId;
673 VertexInputAttributeDescription[i].location = i;
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600674 VertexInputAttributeDescription[i].format = VK_FORMAT_R32G32B32_SFLOAT;
675 VertexInputAttributeDescription[i].offset = sizeof(float) * aByteStride;
Mark Muellerdfe37552016-07-07 14:47:42 -0600676 i++;
677 } while (AttributeCount < i);
678
679 i = 0;
680 do {
681 VertexInputBindingDescription[i].binding = BindId;
682 VertexInputBindingDescription[i].stride = aByteStride;
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600683 VertexInputBindingDescription[i].inputRate = VK_VERTEX_INPUT_RATE_VERTEX;
Mark Muellerdfe37552016-07-07 14:47:42 -0600684 i++;
685 } while (BindingCount < i);
686 }
687
688 ~VkVerticesObj() {
689 if (VertexInputAttributeDescription) {
690 delete[] VertexInputAttributeDescription;
691 }
692 if (VertexInputBindingDescription) {
693 delete[] VertexInputBindingDescription;
694 }
695 }
696
697 bool AddVertexInputToPipe(VkPipelineObj &aPipelineObj) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600698 aPipelineObj.AddVertexInputAttribs(VertexInputAttributeDescription, AttributeCount);
699 aPipelineObj.AddVertexInputBindings(VertexInputBindingDescription, BindingCount);
Mark Muellerdfe37552016-07-07 14:47:42 -0600700 return true;
701 }
702
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600703 void BindVertexBuffers(VkCommandBuffer aCommandBuffer, unsigned aOffsetCount = 0, VkDeviceSize *aOffsetList = nullptr) {
Mark Muellerdfe37552016-07-07 14:47:42 -0600704 VkDeviceSize *offsetList;
705 unsigned offsetCount;
706
707 if (aOffsetCount) {
708 offsetList = aOffsetList;
709 offsetCount = aOffsetCount;
710 } else {
711 offsetList = new VkDeviceSize[1]();
712 offsetCount = 1;
713 }
714
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600715 vkCmdBindVertexBuffers(aCommandBuffer, BindId, offsetCount, &VulkanMemoryBuffer.handle(), offsetList);
Mark Muellerdfe37552016-07-07 14:47:42 -0600716 BoundCurrent = true;
717
718 if (!aOffsetCount) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600719 delete[] offsetList;
Mark Muellerdfe37552016-07-07 14:47:42 -0600720 }
721 }
722
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600723 protected:
Mark Muellerdfe37552016-07-07 14:47:42 -0600724 static uint32_t BindIdGenerator;
725
726 bool BoundCurrent;
727 unsigned AttributeCount;
728 unsigned BindingCount;
729 uint32_t BindId;
730
731 VkPipelineVertexInputStateCreateInfo PipelineVertexInputStateCreateInfo;
732 VkVertexInputAttributeDescription *VertexInputAttributeDescription;
733 VkVertexInputBindingDescription *VertexInputBindingDescription;
734 VkConstantBufferObj VulkanMemoryBuffer;
735};
736
737uint32_t VkVerticesObj::BindIdGenerator;
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500738// ********************************************************************************************************************
739// ********************************************************************************************************************
740// ********************************************************************************************************************
741// ********************************************************************************************************************
Dustin Gravesffa90fa2016-05-06 11:20:38 -0600742#if PARAMETER_VALIDATION_TESTS
743TEST_F(VkLayerTest, RequiredParameter) {
744 TEST_DESCRIPTION("Specify VK_NULL_HANDLE, NULL, and 0 for required handle, "
745 "pointer, array, and array count parameters");
746
747 ASSERT_NO_FATAL_FAILURE(InitState());
748
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600749 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "required parameter pFeatures specified as NULL");
Dustin Gravesffa90fa2016-05-06 11:20:38 -0600750 // Specify NULL for a pointer to a handle
751 // Expected to trigger an error with
752 // parameter_validation::validate_required_pointer
753 vkGetPhysicalDeviceFeatures(gpu(), NULL);
754 m_errorMonitor->VerifyFound();
755
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600756 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
757 "required parameter pQueueFamilyPropertyCount specified as NULL");
Dustin Gravesffa90fa2016-05-06 11:20:38 -0600758 // Specify NULL for pointer to array count
759 // Expected to trigger an error with parameter_validation::validate_array
Dustin Gravesa4bb8c12016-05-16 17:22:51 -0600760 vkGetPhysicalDeviceQueueFamilyProperties(gpu(), NULL, NULL);
Dustin Gravesffa90fa2016-05-06 11:20:38 -0600761 m_errorMonitor->VerifyFound();
762
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600763 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "parameter viewportCount must be greater than 0");
Dustin Gravesffa90fa2016-05-06 11:20:38 -0600764 // Specify 0 for a required array count
765 // Expected to trigger an error with parameter_validation::validate_array
766 VkViewport view_port = {};
767 m_commandBuffer->SetViewport(0, 0, &view_port);
768 m_errorMonitor->VerifyFound();
769
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600770 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "required parameter pViewports specified as NULL");
Dustin Gravesffa90fa2016-05-06 11:20:38 -0600771 // Specify NULL for a required array
772 // Expected to trigger an error with parameter_validation::validate_array
773 m_commandBuffer->SetViewport(0, 1, NULL);
774 m_errorMonitor->VerifyFound();
775
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600776 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "required parameter memory specified as VK_NULL_HANDLE");
Dustin Gravesffa90fa2016-05-06 11:20:38 -0600777 // Specify VK_NULL_HANDLE for a required handle
778 // Expected to trigger an error with
779 // parameter_validation::validate_required_handle
780 vkUnmapMemory(device(), VK_NULL_HANDLE);
781 m_errorMonitor->VerifyFound();
782
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600783 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
784 "required parameter pFences[0] specified as VK_NULL_HANDLE");
Dustin Gravesffa90fa2016-05-06 11:20:38 -0600785 // Specify VK_NULL_HANDLE for a required handle array entry
786 // Expected to trigger an error with
787 // parameter_validation::validate_required_handle_array
788 VkFence fence = VK_NULL_HANDLE;
789 vkResetFences(device(), 1, &fence);
790 m_errorMonitor->VerifyFound();
791
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600792 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "required parameter pAllocateInfo specified as NULL");
Dustin Gravesffa90fa2016-05-06 11:20:38 -0600793 // Specify NULL for a required struct pointer
794 // Expected to trigger an error with
795 // parameter_validation::validate_struct_type
796 VkDeviceMemory memory = VK_NULL_HANDLE;
797 vkAllocateMemory(device(), NULL, NULL, &memory);
798 m_errorMonitor->VerifyFound();
799
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600800 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "value of faceMask must not be 0");
Dustin Gravesffa90fa2016-05-06 11:20:38 -0600801 // Specify 0 for a required VkFlags parameter
802 // Expected to trigger an error with parameter_validation::validate_flags
803 m_commandBuffer->SetStencilReference(0, 0);
804 m_errorMonitor->VerifyFound();
805
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600806 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 -0600807 // Specify 0 for a required VkFlags array entry
808 // Expected to trigger an error with
809 // parameter_validation::validate_flags_array
810 VkSemaphore semaphore = VK_NULL_HANDLE;
811 VkPipelineStageFlags stageFlags = 0;
812 VkSubmitInfo submitInfo = {};
813 submitInfo.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
814 submitInfo.waitSemaphoreCount = 1;
815 submitInfo.pWaitSemaphores = &semaphore;
816 submitInfo.pWaitDstStageMask = &stageFlags;
817 vkQueueSubmit(m_device->m_queue, 1, &submitInfo, VK_NULL_HANDLE);
818 m_errorMonitor->VerifyFound();
819}
Dustin Gravesc99cf5a2016-05-09 14:40:29 -0600820
Dustin Gravesfce74c02016-05-10 11:42:58 -0600821TEST_F(VkLayerTest, ReservedParameter) {
822 TEST_DESCRIPTION("Specify a non-zero value for a reserved parameter");
823
824 ASSERT_NO_FATAL_FAILURE(InitState());
825
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600826 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " must be 0");
Dustin Gravesfce74c02016-05-10 11:42:58 -0600827 // Specify 0 for a reserved VkFlags parameter
828 // Expected to trigger an error with
829 // parameter_validation::validate_reserved_flags
830 VkEvent event_handle = VK_NULL_HANDLE;
831 VkEventCreateInfo event_info = {};
832 event_info.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO;
833 event_info.flags = 1;
834 vkCreateEvent(device(), &event_info, NULL, &event_handle);
835 m_errorMonitor->VerifyFound();
836}
837
Dustin Gravesc99cf5a2016-05-09 14:40:29 -0600838TEST_F(VkLayerTest, InvalidStructSType) {
839 TEST_DESCRIPTION("Specify an invalid VkStructureType for a Vulkan "
840 "structure's sType field");
841
842 ASSERT_NO_FATAL_FAILURE(InitState());
843
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600844 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "parameter pAllocateInfo->sType must be");
Dustin Gravesc99cf5a2016-05-09 14:40:29 -0600845 // Zero struct memory, effectively setting sType to
846 // VK_STRUCTURE_TYPE_APPLICATION_INFO
847 // Expected to trigger an error with
848 // parameter_validation::validate_struct_type
849 VkMemoryAllocateInfo alloc_info = {};
850 VkDeviceMemory memory = VK_NULL_HANDLE;
851 vkAllocateMemory(device(), &alloc_info, NULL, &memory);
852 m_errorMonitor->VerifyFound();
853
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600854 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "parameter pSubmits[0].sType must be");
Dustin Gravesc99cf5a2016-05-09 14:40:29 -0600855 // Zero struct memory, effectively setting sType to
856 // VK_STRUCTURE_TYPE_APPLICATION_INFO
857 // Expected to trigger an error with
858 // parameter_validation::validate_struct_type_array
859 VkSubmitInfo submit_info = {};
860 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
861 m_errorMonitor->VerifyFound();
862}
863
864TEST_F(VkLayerTest, InvalidStructPNext) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600865 TEST_DESCRIPTION("Specify an invalid value for a Vulkan structure's pNext field");
Dustin Gravesc99cf5a2016-05-09 14:40:29 -0600866
867 ASSERT_NO_FATAL_FAILURE(InitState());
868
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600869 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT, "value of pCreateInfo->pNext must be NULL");
Dustin Gravesc99cf5a2016-05-09 14:40:29 -0600870 // Set VkMemoryAllocateInfo::pNext to a non-NULL value, when pNext must be
Karl Schultz38b50992016-07-11 16:09:09 -0600871 // NULL.
872 // Need to pick a function that has no allowed pNext structure types.
873 // Expected to trigger an error with
874 // parameter_validation::validate_struct_pnext
875 VkEvent event = VK_NULL_HANDLE;
Karl Schultz70db3902016-07-11 16:22:10 -0600876 VkEventCreateInfo event_alloc_info = {};
Karl Schultz38b50992016-07-11 16:09:09 -0600877 // Zero-initialization will provide the correct sType
878 VkApplicationInfo app_info = {};
879 event_alloc_info.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO;
880 event_alloc_info.pNext = &app_info;
881 vkCreateEvent(device(), &event_alloc_info, NULL, &event);
882 m_errorMonitor->VerifyFound();
883
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600884 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT,
885 " chain includes a structure with unexpected VkStructureType ");
Karl Schultz38b50992016-07-11 16:09:09 -0600886 // Set VkMemoryAllocateInfo::pNext to a non-NULL value, but use
887 // a function that has allowed pNext structure types and specify
888 // a structure type that is not allowed.
Dustin Gravesc99cf5a2016-05-09 14:40:29 -0600889 // Expected to trigger an error with
890 // parameter_validation::validate_struct_pnext
891 VkDeviceMemory memory = VK_NULL_HANDLE;
Dustin Graves47b6cba2016-05-10 17:34:38 -0600892 VkMemoryAllocateInfo memory_alloc_info = {};
893 memory_alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
894 memory_alloc_info.pNext = &app_info;
895 vkAllocateMemory(device(), &memory_alloc_info, NULL, &memory);
Dustin Gravesc99cf5a2016-05-09 14:40:29 -0600896 m_errorMonitor->VerifyFound();
897
Dustin Gravesfd1c8fe2016-07-15 11:40:20 -0600898 // Positive test to check parameter_validation and unique_objects support
899 // for NV_dedicated_allocation
900 uint32_t extension_count = 0;
901 bool supports_nv_dedicated_allocation = false;
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600902 VkResult err = vkEnumerateDeviceExtensionProperties(gpu(), nullptr, &extension_count, nullptr);
Dustin Gravesfd1c8fe2016-07-15 11:40:20 -0600903 ASSERT_VK_SUCCESS(err);
904
905 if (extension_count > 0) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600906 std::vector<VkExtensionProperties> available_extensions(extension_count);
Dustin Gravesfd1c8fe2016-07-15 11:40:20 -0600907
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600908 err = vkEnumerateDeviceExtensionProperties(gpu(), nullptr, &extension_count, &available_extensions[0]);
Dustin Gravesfd1c8fe2016-07-15 11:40:20 -0600909 ASSERT_VK_SUCCESS(err);
910
911 for (const auto &extension_props : available_extensions) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600912 if (strcmp(extension_props.extensionName, VK_NV_DEDICATED_ALLOCATION_EXTENSION_NAME) == 0) {
Dustin Gravesfd1c8fe2016-07-15 11:40:20 -0600913 supports_nv_dedicated_allocation = true;
914 }
915 }
916 }
917
918 if (supports_nv_dedicated_allocation) {
919 m_errorMonitor->ExpectSuccess();
920
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600921 VkDedicatedAllocationBufferCreateInfoNV dedicated_buffer_create_info = {};
922 dedicated_buffer_create_info.sType = VK_STRUCTURE_TYPE_DEDICATED_ALLOCATION_BUFFER_CREATE_INFO_NV;
Dustin Gravesfd1c8fe2016-07-15 11:40:20 -0600923 dedicated_buffer_create_info.pNext = nullptr;
924 dedicated_buffer_create_info.dedicatedAllocation = VK_TRUE;
925
926 uint32_t queue_family_index = 0;
927 VkBufferCreateInfo buffer_create_info = {};
928 buffer_create_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
929 buffer_create_info.pNext = &dedicated_buffer_create_info;
930 buffer_create_info.size = 1024;
931 buffer_create_info.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
932 buffer_create_info.queueFamilyIndexCount = 1;
933 buffer_create_info.pQueueFamilyIndices = &queue_family_index;
934
935 VkBuffer buffer;
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600936 VkResult err = vkCreateBuffer(m_device->device(), &buffer_create_info, NULL, &buffer);
Dustin Gravesfd1c8fe2016-07-15 11:40:20 -0600937 ASSERT_VK_SUCCESS(err);
938
939 VkMemoryRequirements memory_reqs;
940 vkGetBufferMemoryRequirements(m_device->device(), buffer, &memory_reqs);
941
942 VkDedicatedAllocationMemoryAllocateInfoNV dedicated_memory_info = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600943 dedicated_memory_info.sType = VK_STRUCTURE_TYPE_DEDICATED_ALLOCATION_MEMORY_ALLOCATE_INFO_NV;
Dustin Gravesfd1c8fe2016-07-15 11:40:20 -0600944 dedicated_memory_info.pNext = nullptr;
945 dedicated_memory_info.buffer = buffer;
946 dedicated_memory_info.image = VK_NULL_HANDLE;
947
948 VkMemoryAllocateInfo memory_info = {};
949 memory_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
950 memory_info.pNext = &dedicated_memory_info;
951 memory_info.allocationSize = memory_reqs.size;
952
953 bool pass;
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600954 pass = m_device->phy().set_memory_type(memory_reqs.memoryTypeBits, &memory_info, 0);
Dustin Gravesfd1c8fe2016-07-15 11:40:20 -0600955 ASSERT_TRUE(pass);
956
957 VkDeviceMemory buffer_memory;
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600958 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &buffer_memory);
Dustin Gravesfd1c8fe2016-07-15 11:40:20 -0600959 ASSERT_VK_SUCCESS(err);
960
961 err = vkBindBufferMemory(m_device->device(), buffer, buffer_memory, 0);
962 ASSERT_VK_SUCCESS(err);
963
964 vkDestroyBuffer(m_device->device(), buffer, NULL);
965 vkFreeMemory(m_device->device(), buffer_memory, NULL);
966
967 m_errorMonitor->VerifyNotFound();
968 }
Dustin Gravesc99cf5a2016-05-09 14:40:29 -0600969}
Dustin Graves5d33d532016-05-09 16:21:12 -0600970
971TEST_F(VkLayerTest, UnrecognizedValue) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600972 TEST_DESCRIPTION("Specify unrecognized Vulkan enumeration, flags, and VkBool32 values");
Dustin Graves5d33d532016-05-09 16:21:12 -0600973
974 ASSERT_NO_FATAL_FAILURE(InitState());
975
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600976 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "does not fall within the begin..end "
977 "range of the core VkFormat "
978 "enumeration tokens");
Dustin Graves5d33d532016-05-09 16:21:12 -0600979 // Specify an invalid VkFormat value
980 // Expected to trigger an error with
981 // parameter_validation::validate_ranged_enum
982 VkFormatProperties format_properties;
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600983 vkGetPhysicalDeviceFormatProperties(gpu(), static_cast<VkFormat>(8000), &format_properties);
Dustin Graves5d33d532016-05-09 16:21:12 -0600984 m_errorMonitor->VerifyFound();
985
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600986 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 -0600987 // Specify an invalid VkFlags bitmask value
988 // Expected to trigger an error with parameter_validation::validate_flags
989 VkImageFormatProperties image_format_properties;
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600990 vkGetPhysicalDeviceImageFormatProperties(gpu(), VK_FORMAT_R8G8B8A8_UNORM, VK_IMAGE_TYPE_2D, VK_IMAGE_TILING_OPTIMAL,
991 static_cast<VkImageUsageFlags>(1 << 25), 0, &image_format_properties);
Dustin Graves5d33d532016-05-09 16:21:12 -0600992 m_errorMonitor->VerifyFound();
993
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600994 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 -0600995 // Specify an invalid VkFlags array entry
996 // Expected to trigger an error with
997 // parameter_validation::validate_flags_array
998 VkSemaphore semaphore = VK_NULL_HANDLE;
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600999 VkPipelineStageFlags stage_flags = static_cast<VkPipelineStageFlags>(1 << 25);
Dustin Graves5d33d532016-05-09 16:21:12 -06001000 VkSubmitInfo submit_info = {};
1001 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
1002 submit_info.waitSemaphoreCount = 1;
1003 submit_info.pWaitSemaphores = &semaphore;
1004 submit_info.pWaitDstStageMask = &stage_flags;
1005 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
1006 m_errorMonitor->VerifyFound();
1007
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001008 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT, "is neither VK_TRUE nor VK_FALSE");
Dustin Graves5d33d532016-05-09 16:21:12 -06001009 // Specify an invalid VkBool32 value
1010 // Expected to trigger a warning with
1011 // parameter_validation::validate_bool32
1012 VkSampler sampler = VK_NULL_HANDLE;
1013 VkSamplerCreateInfo sampler_info = {};
1014 sampler_info.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
1015 sampler_info.pNext = NULL;
1016 sampler_info.magFilter = VK_FILTER_NEAREST;
1017 sampler_info.minFilter = VK_FILTER_NEAREST;
1018 sampler_info.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
1019 sampler_info.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
1020 sampler_info.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
1021 sampler_info.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
1022 sampler_info.mipLodBias = 1.0;
1023 sampler_info.maxAnisotropy = 1;
1024 sampler_info.compareEnable = VK_FALSE;
1025 sampler_info.compareOp = VK_COMPARE_OP_NEVER;
1026 sampler_info.minLod = 1.0;
1027 sampler_info.maxLod = 1.0;
1028 sampler_info.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
1029 sampler_info.unnormalizedCoordinates = VK_FALSE;
1030 // Not VK_TRUE or VK_FALSE
1031 sampler_info.anisotropyEnable = 3;
1032 vkCreateSampler(m_device->device(), &sampler_info, NULL, &sampler);
1033 m_errorMonitor->VerifyFound();
1034}
Dustin Gravesfce74c02016-05-10 11:42:58 -06001035
1036TEST_F(VkLayerTest, FailedReturnValue) {
1037 TEST_DESCRIPTION("Check for a message describing a VkResult failure code");
1038
1039 ASSERT_NO_FATAL_FAILURE(InitState());
1040
Dustin Graves13c1e2b2016-05-16 15:31:02 -06001041 // Find an unsupported image format
1042 VkFormat unsupported = VK_FORMAT_UNDEFINED;
1043 for (int f = VK_FORMAT_BEGIN_RANGE; f <= VK_FORMAT_END_RANGE; f++) {
1044 VkFormat format = static_cast<VkFormat>(f);
1045 VkFormatProperties fProps = m_device->format_properties(format);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001046 if (format != VK_FORMAT_UNDEFINED && fProps.linearTilingFeatures == 0 && fProps.optimalTilingFeatures == 0) {
Dustin Graves13c1e2b2016-05-16 15:31:02 -06001047 unsupported = format;
1048 break;
1049 }
1050 }
1051
1052 if (unsupported != VK_FORMAT_UNDEFINED) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001053 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT,
1054 "the requested format is not supported on this device");
Dustin Graves13c1e2b2016-05-16 15:31:02 -06001055 // Specify an unsupported VkFormat value to generate a
1056 // VK_ERROR_FORMAT_NOT_SUPPORTED return code
1057 // Expected to trigger a warning from
1058 // parameter_validation::validate_result
1059 VkImageFormatProperties image_format_properties;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001060 VkResult err = vkGetPhysicalDeviceImageFormatProperties(gpu(), unsupported, VK_IMAGE_TYPE_2D, VK_IMAGE_TILING_OPTIMAL,
1061 VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT, 0, &image_format_properties);
Dustin Graves13c1e2b2016-05-16 15:31:02 -06001062 ASSERT_TRUE(err == VK_ERROR_FORMAT_NOT_SUPPORTED);
1063 m_errorMonitor->VerifyFound();
1064 }
Dustin Gravesfce74c02016-05-10 11:42:58 -06001065}
Mark Lobodzinskie090fef2016-06-09 17:04:56 -06001066
1067TEST_F(VkLayerTest, UpdateBufferAlignment) {
1068 TEST_DESCRIPTION("Check alignment parameters for vkCmdUpdateBuffer");
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001069 uint32_t updateData[] = {1, 2, 3, 4, 5, 6, 7, 8};
Mark Lobodzinskie090fef2016-06-09 17:04:56 -06001070
1071 ASSERT_NO_FATAL_FAILURE(InitState());
1072
1073 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
1074 vk_testing::Buffer buffer;
1075 buffer.init_as_dst(*m_device, (VkDeviceSize)20, reqs);
1076
1077 BeginCommandBuffer();
1078 // Introduce failure by using dstOffset that is not multiple of 4
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001079 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " is not a multiple of 4");
Mark Lobodzinskie090fef2016-06-09 17:04:56 -06001080 m_commandBuffer->UpdateBuffer(buffer.handle(), 1, 4, updateData);
1081 m_errorMonitor->VerifyFound();
1082
1083 // Introduce failure by using dataSize that is not multiple of 4
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001084 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " is not a multiple of 4");
Mark Lobodzinskie090fef2016-06-09 17:04:56 -06001085 m_commandBuffer->UpdateBuffer(buffer.handle(), 0, 6, updateData);
1086 m_errorMonitor->VerifyFound();
1087
1088 // Introduce failure by using dataSize that is < 0
1089 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001090 "must be greater than zero and less than or equal to 65536");
Mark Lobodzinskie090fef2016-06-09 17:04:56 -06001091 m_commandBuffer->UpdateBuffer(buffer.handle(), 0, -44, updateData);
1092 m_errorMonitor->VerifyFound();
1093
1094 // Introduce failure by using dataSize that is > 65536
1095 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001096 "must be greater than zero and less than or equal to 65536");
Mark Lobodzinskie090fef2016-06-09 17:04:56 -06001097 m_commandBuffer->UpdateBuffer(buffer.handle(), 0, 80000, updateData);
1098 m_errorMonitor->VerifyFound();
1099
1100 EndCommandBuffer();
1101}
1102
1103TEST_F(VkLayerTest, FillBufferAlignment) {
1104 TEST_DESCRIPTION("Check alignment parameters for vkCmdFillBuffer");
1105
1106 ASSERT_NO_FATAL_FAILURE(InitState());
1107
1108 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
1109 vk_testing::Buffer buffer;
1110 buffer.init_as_dst(*m_device, (VkDeviceSize)20, reqs);
1111
1112 BeginCommandBuffer();
1113
1114 // Introduce failure by using dstOffset that is not multiple of 4
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001115 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " is not a multiple of 4");
Mark Lobodzinskie090fef2016-06-09 17:04:56 -06001116 m_commandBuffer->FillBuffer(buffer.handle(), 1, 4, 0x11111111);
1117 m_errorMonitor->VerifyFound();
1118
1119 // Introduce failure by using size that is not multiple of 4
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001120 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " is not a multiple of 4");
Mark Lobodzinskie090fef2016-06-09 17:04:56 -06001121 m_commandBuffer->FillBuffer(buffer.handle(), 0, 6, 0x11111111);
1122 m_errorMonitor->VerifyFound();
1123
1124 // Introduce failure by using size that is zero
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001125 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "must be greater than zero");
Mark Lobodzinskie090fef2016-06-09 17:04:56 -06001126 m_commandBuffer->FillBuffer(buffer.handle(), 0, 0, 0x11111111);
1127 m_errorMonitor->VerifyFound();
1128
1129 EndCommandBuffer();
1130}
Dustin Graves40f35822016-06-23 11:12:53 -06001131
1132// This is a positive test. No failures are expected.
1133TEST_F(VkLayerTest, IgnoreUnrelatedDescriptor) {
1134 TEST_DESCRIPTION("Ensure that the vkUpdateDescriptorSet validation code "
1135 "is ignoring VkWriteDescriptorSet members that are not "
1136 "related to the descriptor type specified by "
1137 "VkWriteDescriptorSet::descriptorType. Correct "
1138 "validation behavior will result in the test running to "
1139 "completion without validation errors.");
1140
Dustin Graves5e2d8fc2016-07-07 16:18:49 -06001141 const uintptr_t invalid_ptr = 0xcdcdcdcd;
1142
Dustin Graves40f35822016-06-23 11:12:53 -06001143 ASSERT_NO_FATAL_FAILURE(InitState());
1144
1145 // Image Case
1146 {
1147 m_errorMonitor->ExpectSuccess();
1148
1149 VkImage image;
1150 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
1151 const int32_t tex_width = 32;
1152 const int32_t tex_height = 32;
1153 VkImageCreateInfo image_create_info = {};
1154 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
1155 image_create_info.pNext = NULL;
1156 image_create_info.imageType = VK_IMAGE_TYPE_2D;
1157 image_create_info.format = tex_format;
1158 image_create_info.extent.width = tex_width;
1159 image_create_info.extent.height = tex_height;
1160 image_create_info.extent.depth = 1;
1161 image_create_info.mipLevels = 1;
1162 image_create_info.arrayLayers = 1;
1163 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
Tobin Ehlis51cde412016-07-11 16:08:30 -06001164 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
Dustin Graves40f35822016-06-23 11:12:53 -06001165 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
1166 image_create_info.flags = 0;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001167 VkResult err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
Dustin Graves40f35822016-06-23 11:12:53 -06001168 ASSERT_VK_SUCCESS(err);
1169
1170 VkMemoryRequirements memory_reqs;
1171 VkDeviceMemory image_memory;
1172 bool pass;
1173 VkMemoryAllocateInfo memory_info = {};
1174 memory_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
1175 memory_info.pNext = NULL;
1176 memory_info.allocationSize = 0;
1177 memory_info.memoryTypeIndex = 0;
1178 vkGetImageMemoryRequirements(m_device->device(), image, &memory_reqs);
1179 memory_info.allocationSize = memory_reqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001180 pass = m_device->phy().set_memory_type(memory_reqs.memoryTypeBits, &memory_info, 0);
Dustin Graves40f35822016-06-23 11:12:53 -06001181 ASSERT_TRUE(pass);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001182 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &image_memory);
Dustin Graves40f35822016-06-23 11:12:53 -06001183 ASSERT_VK_SUCCESS(err);
1184 err = vkBindImageMemory(m_device->device(), image, image_memory, 0);
1185 ASSERT_VK_SUCCESS(err);
1186
1187 VkImageViewCreateInfo image_view_create_info = {};
1188 image_view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
1189 image_view_create_info.image = image;
1190 image_view_create_info.viewType = VK_IMAGE_VIEW_TYPE_2D;
1191 image_view_create_info.format = tex_format;
1192 image_view_create_info.subresourceRange.layerCount = 1;
1193 image_view_create_info.subresourceRange.baseMipLevel = 0;
1194 image_view_create_info.subresourceRange.levelCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001195 image_view_create_info.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Dustin Graves40f35822016-06-23 11:12:53 -06001196
1197 VkImageView view;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001198 err = vkCreateImageView(m_device->device(), &image_view_create_info, NULL, &view);
Dustin Graves40f35822016-06-23 11:12:53 -06001199 ASSERT_VK_SUCCESS(err);
1200
1201 VkDescriptorPoolSize ds_type_count = {};
1202 ds_type_count.type = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE;
1203 ds_type_count.descriptorCount = 1;
1204
1205 VkDescriptorPoolCreateInfo ds_pool_ci = {};
1206 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
1207 ds_pool_ci.pNext = NULL;
1208 ds_pool_ci.maxSets = 1;
1209 ds_pool_ci.poolSizeCount = 1;
1210 ds_pool_ci.pPoolSizes = &ds_type_count;
1211
1212 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001213 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Dustin Graves40f35822016-06-23 11:12:53 -06001214 ASSERT_VK_SUCCESS(err);
1215
1216 VkDescriptorSetLayoutBinding dsl_binding = {};
1217 dsl_binding.binding = 0;
1218 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE;
1219 dsl_binding.descriptorCount = 1;
1220 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
1221 dsl_binding.pImmutableSamplers = NULL;
1222
1223 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001224 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
Dustin Graves40f35822016-06-23 11:12:53 -06001225 ds_layout_ci.pNext = NULL;
1226 ds_layout_ci.bindingCount = 1;
1227 ds_layout_ci.pBindings = &dsl_binding;
1228 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001229 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Dustin Graves40f35822016-06-23 11:12:53 -06001230 ASSERT_VK_SUCCESS(err);
1231
1232 VkDescriptorSet descriptor_set;
1233 VkDescriptorSetAllocateInfo alloc_info = {};
1234 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
1235 alloc_info.descriptorSetCount = 1;
1236 alloc_info.descriptorPool = ds_pool;
1237 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001238 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
Dustin Graves40f35822016-06-23 11:12:53 -06001239 ASSERT_VK_SUCCESS(err);
1240
1241 VkDescriptorImageInfo image_info = {};
1242 image_info.imageView = view;
1243 image_info.imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
1244
1245 VkWriteDescriptorSet descriptor_write;
1246 memset(&descriptor_write, 0, sizeof(descriptor_write));
1247 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
1248 descriptor_write.dstSet = descriptor_set;
1249 descriptor_write.dstBinding = 0;
1250 descriptor_write.descriptorCount = 1;
1251 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE;
1252 descriptor_write.pImageInfo = &image_info;
1253
1254 // Set pBufferInfo and pTexelBufferView to invalid values, which should
1255 // be
1256 // ignored for descriptorType == VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE.
1257 // This will most likely produce a crash if the parameter_validation
1258 // layer
1259 // does not correctly ignore pBufferInfo.
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001260 descriptor_write.pBufferInfo = reinterpret_cast<const VkDescriptorBufferInfo *>(invalid_ptr);
1261 descriptor_write.pTexelBufferView = reinterpret_cast<const VkBufferView *>(invalid_ptr);
Dustin Graves40f35822016-06-23 11:12:53 -06001262
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001263 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
Dustin Graves40f35822016-06-23 11:12:53 -06001264
1265 m_errorMonitor->VerifyNotFound();
1266
Dustin Graves40f35822016-06-23 11:12:53 -06001267 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
1268 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
1269 vkDestroyImageView(m_device->device(), view, NULL);
1270 vkDestroyImage(m_device->device(), image, NULL);
1271 vkFreeMemory(m_device->device(), image_memory, NULL);
1272 }
1273
1274 // Buffer Case
1275 {
1276 m_errorMonitor->ExpectSuccess();
1277
1278 VkBuffer buffer;
1279 uint32_t queue_family_index = 0;
1280 VkBufferCreateInfo buffer_create_info = {};
1281 buffer_create_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
1282 buffer_create_info.size = 1024;
1283 buffer_create_info.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
1284 buffer_create_info.queueFamilyIndexCount = 1;
1285 buffer_create_info.pQueueFamilyIndices = &queue_family_index;
1286
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001287 VkResult err = vkCreateBuffer(m_device->device(), &buffer_create_info, NULL, &buffer);
Dustin Graves40f35822016-06-23 11:12:53 -06001288 ASSERT_VK_SUCCESS(err);
1289
1290 VkMemoryRequirements memory_reqs;
1291 VkDeviceMemory buffer_memory;
1292 bool pass;
1293 VkMemoryAllocateInfo memory_info = {};
1294 memory_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
1295 memory_info.pNext = NULL;
1296 memory_info.allocationSize = 0;
1297 memory_info.memoryTypeIndex = 0;
1298
1299 vkGetBufferMemoryRequirements(m_device->device(), buffer, &memory_reqs);
1300 memory_info.allocationSize = memory_reqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001301 pass = m_device->phy().set_memory_type(memory_reqs.memoryTypeBits, &memory_info, 0);
Dustin Graves40f35822016-06-23 11:12:53 -06001302 ASSERT_TRUE(pass);
1303
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001304 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &buffer_memory);
Dustin Graves40f35822016-06-23 11:12:53 -06001305 ASSERT_VK_SUCCESS(err);
1306 err = vkBindBufferMemory(m_device->device(), buffer, buffer_memory, 0);
1307 ASSERT_VK_SUCCESS(err);
1308
1309 VkDescriptorPoolSize ds_type_count = {};
1310 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
1311 ds_type_count.descriptorCount = 1;
1312
1313 VkDescriptorPoolCreateInfo ds_pool_ci = {};
1314 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
1315 ds_pool_ci.pNext = NULL;
1316 ds_pool_ci.maxSets = 1;
1317 ds_pool_ci.poolSizeCount = 1;
1318 ds_pool_ci.pPoolSizes = &ds_type_count;
1319
1320 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001321 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Dustin Graves40f35822016-06-23 11:12:53 -06001322 ASSERT_VK_SUCCESS(err);
1323
1324 VkDescriptorSetLayoutBinding dsl_binding = {};
1325 dsl_binding.binding = 0;
1326 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
1327 dsl_binding.descriptorCount = 1;
1328 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
1329 dsl_binding.pImmutableSamplers = NULL;
1330
1331 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001332 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
Dustin Graves40f35822016-06-23 11:12:53 -06001333 ds_layout_ci.pNext = NULL;
1334 ds_layout_ci.bindingCount = 1;
1335 ds_layout_ci.pBindings = &dsl_binding;
1336 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001337 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Dustin Graves40f35822016-06-23 11:12:53 -06001338 ASSERT_VK_SUCCESS(err);
1339
1340 VkDescriptorSet descriptor_set;
1341 VkDescriptorSetAllocateInfo alloc_info = {};
1342 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
1343 alloc_info.descriptorSetCount = 1;
1344 alloc_info.descriptorPool = ds_pool;
1345 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001346 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
Dustin Graves40f35822016-06-23 11:12:53 -06001347 ASSERT_VK_SUCCESS(err);
1348
1349 VkDescriptorBufferInfo buffer_info = {};
1350 buffer_info.buffer = buffer;
1351 buffer_info.offset = 0;
1352 buffer_info.range = 1024;
1353
1354 VkWriteDescriptorSet descriptor_write;
1355 memset(&descriptor_write, 0, sizeof(descriptor_write));
1356 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
1357 descriptor_write.dstSet = descriptor_set;
1358 descriptor_write.dstBinding = 0;
1359 descriptor_write.descriptorCount = 1;
1360 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
1361 descriptor_write.pBufferInfo = &buffer_info;
1362
1363 // Set pImageInfo and pTexelBufferView to invalid values, which should
1364 // be
1365 // ignored for descriptorType == VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER.
1366 // This will most likely produce a crash if the parameter_validation
1367 // layer
1368 // does not correctly ignore pImageInfo.
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001369 descriptor_write.pImageInfo = reinterpret_cast<const VkDescriptorImageInfo *>(invalid_ptr);
1370 descriptor_write.pTexelBufferView = reinterpret_cast<const VkBufferView *>(invalid_ptr);
Dustin Graves40f35822016-06-23 11:12:53 -06001371
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001372 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
Dustin Graves40f35822016-06-23 11:12:53 -06001373
1374 m_errorMonitor->VerifyNotFound();
1375
1376 vkFreeDescriptorSets(m_device->device(), ds_pool, 1, &descriptor_set);
1377 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
1378 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
1379 vkDestroyBuffer(m_device->device(), buffer, NULL);
1380 vkFreeMemory(m_device->device(), buffer_memory, NULL);
1381 }
1382
1383 // Texel Buffer Case
1384 {
1385 m_errorMonitor->ExpectSuccess();
1386
1387 VkBuffer buffer;
1388 uint32_t queue_family_index = 0;
1389 VkBufferCreateInfo buffer_create_info = {};
1390 buffer_create_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
1391 buffer_create_info.size = 1024;
1392 buffer_create_info.usage = VK_BUFFER_USAGE_STORAGE_TEXEL_BUFFER_BIT;
1393 buffer_create_info.queueFamilyIndexCount = 1;
1394 buffer_create_info.pQueueFamilyIndices = &queue_family_index;
1395
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001396 VkResult err = vkCreateBuffer(m_device->device(), &buffer_create_info, NULL, &buffer);
Dustin Graves40f35822016-06-23 11:12:53 -06001397 ASSERT_VK_SUCCESS(err);
1398
1399 VkMemoryRequirements memory_reqs;
1400 VkDeviceMemory buffer_memory;
1401 bool pass;
1402 VkMemoryAllocateInfo memory_info = {};
1403 memory_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
1404 memory_info.pNext = NULL;
1405 memory_info.allocationSize = 0;
1406 memory_info.memoryTypeIndex = 0;
1407
1408 vkGetBufferMemoryRequirements(m_device->device(), buffer, &memory_reqs);
1409 memory_info.allocationSize = memory_reqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001410 pass = m_device->phy().set_memory_type(memory_reqs.memoryTypeBits, &memory_info, 0);
Dustin Graves40f35822016-06-23 11:12:53 -06001411 ASSERT_TRUE(pass);
1412
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001413 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &buffer_memory);
Dustin Graves40f35822016-06-23 11:12:53 -06001414 ASSERT_VK_SUCCESS(err);
1415 err = vkBindBufferMemory(m_device->device(), buffer, buffer_memory, 0);
1416 ASSERT_VK_SUCCESS(err);
1417
1418 VkBufferViewCreateInfo buff_view_ci = {};
1419 buff_view_ci.sType = VK_STRUCTURE_TYPE_BUFFER_VIEW_CREATE_INFO;
1420 buff_view_ci.buffer = buffer;
1421 buff_view_ci.format = VK_FORMAT_R8_UNORM;
1422 buff_view_ci.range = VK_WHOLE_SIZE;
1423 VkBufferView buffer_view;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001424 err = vkCreateBufferView(m_device->device(), &buff_view_ci, NULL, &buffer_view);
Dustin Graves40f35822016-06-23 11:12:53 -06001425
1426 VkDescriptorPoolSize ds_type_count = {};
1427 ds_type_count.type = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
1428 ds_type_count.descriptorCount = 1;
1429
1430 VkDescriptorPoolCreateInfo ds_pool_ci = {};
1431 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
1432 ds_pool_ci.pNext = NULL;
1433 ds_pool_ci.maxSets = 1;
1434 ds_pool_ci.poolSizeCount = 1;
1435 ds_pool_ci.pPoolSizes = &ds_type_count;
1436
1437 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001438 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Dustin Graves40f35822016-06-23 11:12:53 -06001439 ASSERT_VK_SUCCESS(err);
1440
1441 VkDescriptorSetLayoutBinding dsl_binding = {};
1442 dsl_binding.binding = 0;
1443 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
1444 dsl_binding.descriptorCount = 1;
1445 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
1446 dsl_binding.pImmutableSamplers = NULL;
1447
1448 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001449 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
Dustin Graves40f35822016-06-23 11:12:53 -06001450 ds_layout_ci.pNext = NULL;
1451 ds_layout_ci.bindingCount = 1;
1452 ds_layout_ci.pBindings = &dsl_binding;
1453 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001454 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Dustin Graves40f35822016-06-23 11:12:53 -06001455 ASSERT_VK_SUCCESS(err);
1456
1457 VkDescriptorSet descriptor_set;
1458 VkDescriptorSetAllocateInfo alloc_info = {};
1459 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
1460 alloc_info.descriptorSetCount = 1;
1461 alloc_info.descriptorPool = ds_pool;
1462 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001463 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
Dustin Graves40f35822016-06-23 11:12:53 -06001464 ASSERT_VK_SUCCESS(err);
1465
1466 VkWriteDescriptorSet descriptor_write;
1467 memset(&descriptor_write, 0, sizeof(descriptor_write));
1468 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
1469 descriptor_write.dstSet = descriptor_set;
1470 descriptor_write.dstBinding = 0;
1471 descriptor_write.descriptorCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001472 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
Dustin Graves40f35822016-06-23 11:12:53 -06001473 descriptor_write.pTexelBufferView = &buffer_view;
1474
1475 // Set pImageInfo and pBufferInfo to invalid values, which should be
1476 // ignored for descriptorType ==
1477 // VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER.
1478 // This will most likely produce a crash if the parameter_validation
1479 // layer
1480 // does not correctly ignore pImageInfo and pBufferInfo.
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001481 descriptor_write.pImageInfo = reinterpret_cast<const VkDescriptorImageInfo *>(invalid_ptr);
1482 descriptor_write.pBufferInfo = reinterpret_cast<const VkDescriptorBufferInfo *>(invalid_ptr);
Dustin Graves40f35822016-06-23 11:12:53 -06001483
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001484 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
Dustin Graves40f35822016-06-23 11:12:53 -06001485
1486 m_errorMonitor->VerifyNotFound();
1487
1488 vkFreeDescriptorSets(m_device->device(), ds_pool, 1, &descriptor_set);
1489 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
1490 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
1491 vkDestroyBufferView(m_device->device(), buffer_view, NULL);
1492 vkDestroyBuffer(m_device->device(), buffer, NULL);
1493 vkFreeMemory(m_device->device(), buffer_memory, NULL);
1494 }
1495}
Cortd889ff92016-07-27 09:51:27 -07001496
1497TEST_F(VkLayerTest, PSOPolygonModeInvalid) {
1498 VkResult err;
1499
1500 TEST_DESCRIPTION("Attempt to use a non-solid polygon fill mode in a "
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001501 "pipeline when this feature is not enabled.");
Cortd889ff92016-07-27 09:51:27 -07001502
1503 ASSERT_NO_FATAL_FAILURE(InitState());
1504 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
1505
1506 std::vector<const char *> device_extension_names;
1507 auto features = m_device->phy().features();
1508 // Artificially disable support for non-solid fill modes
1509 features.fillModeNonSolid = false;
1510 // The sacrificial device object
1511 VkDeviceObj test_device(0, gpu(), device_extension_names, &features);
1512
1513 VkRenderpassObj render_pass(&test_device);
1514
1515 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
1516 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
1517 pipeline_layout_ci.setLayoutCount = 0;
1518 pipeline_layout_ci.pSetLayouts = NULL;
1519
1520 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001521 err = vkCreatePipelineLayout(test_device.device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Cortd889ff92016-07-27 09:51:27 -07001522 ASSERT_VK_SUCCESS(err);
1523
1524 VkPipelineRasterizationStateCreateInfo rs_ci = {};
1525 rs_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
1526 rs_ci.pNext = nullptr;
1527 rs_ci.lineWidth = 1.0f;
1528 rs_ci.rasterizerDiscardEnable = true;
1529
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001530 VkShaderObj vs(&test_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
1531 VkShaderObj fs(&test_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Cortd889ff92016-07-27 09:51:27 -07001532
Mark Lobodzinski5e644732016-08-15 16:51:19 -06001533 // Set polygonMode to unsupported value POINT, should fail
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001534 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
1535 "polygonMode cannot be VK_POLYGON_MODE_POINT or VK_POLYGON_MODE_LINE");
Cortd889ff92016-07-27 09:51:27 -07001536 {
1537 VkPipelineObj pipe(&test_device);
1538 pipe.AddShader(&vs);
1539 pipe.AddShader(&fs);
1540 pipe.AddColorAttachment();
1541 // Introduce failure by setting unsupported polygon mode
1542 rs_ci.polygonMode = VK_POLYGON_MODE_POINT;
1543 pipe.SetRasterization(&rs_ci);
1544 pipe.CreateVKPipeline(pipeline_layout, render_pass.handle());
1545 }
1546 m_errorMonitor->VerifyFound();
1547
1548 // Try again with polygonMode=LINE, should fail
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001549 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
1550 "polygonMode cannot be VK_POLYGON_MODE_POINT or VK_POLYGON_MODE_LINE");
Cortd889ff92016-07-27 09:51:27 -07001551 {
1552 VkPipelineObj pipe(&test_device);
1553 pipe.AddShader(&vs);
1554 pipe.AddShader(&fs);
1555 pipe.AddColorAttachment();
1556 // Introduce failure by setting unsupported polygon mode
1557 rs_ci.polygonMode = VK_POLYGON_MODE_LINE;
1558 pipe.SetRasterization(&rs_ci);
1559 pipe.CreateVKPipeline(pipeline_layout, render_pass.handle());
1560 }
1561 m_errorMonitor->VerifyFound();
1562
1563 // Try again with polygonMode=FILL. No error is expected
1564 m_errorMonitor->ExpectSuccess();
1565 {
1566 VkPipelineObj pipe(&test_device);
1567 pipe.AddShader(&vs);
1568 pipe.AddShader(&fs);
1569 pipe.AddColorAttachment();
1570 // Set polygonMode to a good value
1571 rs_ci.polygonMode = VK_POLYGON_MODE_FILL;
1572 pipe.SetRasterization(&rs_ci);
1573 pipe.CreateVKPipeline(pipeline_layout, render_pass.handle());
1574 }
1575 m_errorMonitor->VerifyNotFound();
1576
1577 vkDestroyPipelineLayout(test_device.device(), pipeline_layout, NULL);
1578}
1579
Dustin Gravesffa90fa2016-05-06 11:20:38 -06001580#endif // PARAMETER_VALIDATION_TESTS
1581
Tobin Ehlis0788f522015-05-26 16:11:58 -06001582#if MEM_TRACKER_TESTS
Tobin Ehlis8fab6562015-12-01 09:57:09 -07001583#if 0
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001584TEST_F(VkLayerTest, CallResetCommandBufferBeforeCompletion)
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001585{
1586 vk_testing::Fence testFence;
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001587 VkFenceCreateInfo fenceInfo = {};
1588 fenceInfo.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
1589 fenceInfo.pNext = NULL;
1590 fenceInfo.flags = 0;
1591
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07001592 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Resetting CB");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06001593
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001594 ASSERT_NO_FATAL_FAILURE(InitState());
Tony Barbourc1eb1a52015-07-20 13:00:10 -06001595
1596 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
1597 vk_testing::Buffer buffer;
1598 buffer.init_as_dst(*m_device, (VkDeviceSize)20, reqs);
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001599
Tony Barbourfe3351b2015-07-28 10:17:20 -06001600 BeginCommandBuffer();
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001601 m_commandBuffer->FillBuffer(buffer.handle(), 0, 4, 0x11111111);
Tony Barbourfe3351b2015-07-28 10:17:20 -06001602 EndCommandBuffer();
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001603
1604 testFence.init(*m_device, fenceInfo);
1605
1606 // Bypass framework since it does the waits automatically
1607 VkResult err = VK_SUCCESS;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06001608 VkSubmitInfo submit_info;
Chia-I Wuf9be13c2015-10-26 20:37:06 +08001609 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
1610 submit_info.pNext = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08001611 submit_info.waitSemaphoreCount = 0;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06001612 submit_info.pWaitSemaphores = NULL;
Jon Ashburn7f9716c2015-12-30 16:42:50 -07001613 submit_info.pWaitDstStageMask = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08001614 submit_info.commandBufferCount = 1;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001615 submit_info.pCommandBuffers = &m_commandBuffer->handle();
Chia-I Wud50a7d72015-10-26 20:48:51 +08001616 submit_info.signalSemaphoreCount = 0;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06001617 submit_info.pSignalSemaphores = NULL;
Courtney Goeltzenleuchter646b9072015-10-20 18:04:07 -06001618
1619 err = vkQueueSubmit( m_device->m_queue, 1, &submit_info, testFence.handle());
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001620 ASSERT_VK_SUCCESS( err );
1621
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001622 // Introduce failure by calling begin again before checking fence
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001623 vkResetCommandBuffer(m_commandBuffer->handle(), 0);
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001624
Chris Forbes8f36a8a2016-04-07 13:21:07 +12001625 m_errorMonitor->VerifyFound();
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001626}
1627
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001628TEST_F(VkLayerTest, CallBeginCommandBufferBeforeCompletion)
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001629{
1630 vk_testing::Fence testFence;
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001631 VkFenceCreateInfo fenceInfo = {};
1632 fenceInfo.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
1633 fenceInfo.pNext = NULL;
1634 fenceInfo.flags = 0;
1635
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07001636 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Calling vkBeginCommandBuffer() on active CB");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06001637
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001638 ASSERT_NO_FATAL_FAILURE(InitState());
1639 ASSERT_NO_FATAL_FAILURE(InitViewport());
1640 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
1641
Tony Barbourfe3351b2015-07-28 10:17:20 -06001642 BeginCommandBuffer();
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001643 m_commandBuffer->ClearAllBuffers(m_clear_color, m_depth_clear_color, m_stencil_clear_color, NULL);
Tony Barbourfe3351b2015-07-28 10:17:20 -06001644 EndCommandBuffer();
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001645
1646 testFence.init(*m_device, fenceInfo);
1647
1648 // Bypass framework since it does the waits automatically
1649 VkResult err = VK_SUCCESS;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06001650 VkSubmitInfo submit_info;
Chia-I Wuf9be13c2015-10-26 20:37:06 +08001651 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
1652 submit_info.pNext = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08001653 submit_info.waitSemaphoreCount = 0;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06001654 submit_info.pWaitSemaphores = NULL;
Jon Ashburn7f9716c2015-12-30 16:42:50 -07001655 submit_info.pWaitDstStageMask = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08001656 submit_info.commandBufferCount = 1;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001657 submit_info.pCommandBuffers = &m_commandBuffer->handle();
Chia-I Wud50a7d72015-10-26 20:48:51 +08001658 submit_info.signalSemaphoreCount = 0;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06001659 submit_info.pSignalSemaphores = NULL;
Courtney Goeltzenleuchter646b9072015-10-20 18:04:07 -06001660
1661 err = vkQueueSubmit( m_device->m_queue, 1, &submit_info, testFence.handle());
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001662 ASSERT_VK_SUCCESS( err );
1663
Jon Ashburnf19916e2016-01-11 13:12:43 -07001664 VkCommandBufferInheritanceInfo hinfo = {};
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001665 VkCommandBufferBeginInfo info = {};
1666 info.flags = VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT;
1667 info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
Mark Lobodzinski5fcc4212015-09-14 17:43:42 -06001668 info.renderPass = VK_NULL_HANDLE;
1669 info.subpass = 0;
1670 info.framebuffer = VK_NULL_HANDLE;
Chia-I Wub8d47ae2015-11-11 10:18:12 +08001671 info.occlusionQueryEnable = VK_FALSE;
1672 info.queryFlags = 0;
1673 info.pipelineStatistics = 0;
Mark Lobodzinski5fcc4212015-09-14 17:43:42 -06001674
1675 // Introduce failure by calling BCB again before checking fence
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001676 vkBeginCommandBuffer(m_commandBuffer->handle(), &info);
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001677
Chris Forbes8f36a8a2016-04-07 13:21:07 +12001678 m_errorMonitor->VerifyFound();
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001679}
Tobin Ehlis8fab6562015-12-01 09:57:09 -07001680#endif
Chris Forbes8f36a8a2016-04-07 13:21:07 +12001681
Mark Lobodzinski152fe252016-05-03 16:49:15 -06001682// This is a positive test. No failures are expected.
1683TEST_F(VkLayerTest, TestAliasedMemoryTracking) {
1684 VkResult err;
1685 bool pass;
1686
1687 TEST_DESCRIPTION("Create a buffer, allocate memory, bind memory, destroy "
1688 "the buffer, create an image, and bind the same memory to "
1689 "it");
1690
1691 m_errorMonitor->ExpectSuccess();
1692
1693 ASSERT_NO_FATAL_FAILURE(InitState());
1694
1695 VkBuffer buffer;
1696 VkImage image;
1697 VkDeviceMemory mem;
1698 VkMemoryRequirements mem_reqs;
1699
1700 VkBufferCreateInfo buf_info = {};
1701 buf_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
1702 buf_info.pNext = NULL;
1703 buf_info.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
1704 buf_info.size = 256;
1705 buf_info.queueFamilyIndexCount = 0;
1706 buf_info.pQueueFamilyIndices = NULL;
1707 buf_info.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
1708 buf_info.flags = 0;
1709 err = vkCreateBuffer(m_device->device(), &buf_info, NULL, &buffer);
1710 ASSERT_VK_SUCCESS(err);
1711
1712 vkGetBufferMemoryRequirements(m_device->device(), buffer, &mem_reqs);
1713
1714 VkMemoryAllocateInfo alloc_info = {};
1715 alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
1716 alloc_info.pNext = NULL;
1717 alloc_info.memoryTypeIndex = 0;
1718
1719 // Ensure memory is big enough for both bindings
1720 alloc_info.allocationSize = 0x10000;
1721
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001722 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 -06001723 if (!pass) {
1724 vkDestroyBuffer(m_device->device(), buffer, NULL);
1725 return;
1726 }
1727
1728 err = vkAllocateMemory(m_device->device(), &alloc_info, NULL, &mem);
1729 ASSERT_VK_SUCCESS(err);
1730
1731 uint8_t *pData;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001732 err = vkMapMemory(m_device->device(), mem, 0, mem_reqs.size, 0, (void **)&pData);
Mark Lobodzinski152fe252016-05-03 16:49:15 -06001733 ASSERT_VK_SUCCESS(err);
1734
Mark Lobodzinski2abefa92016-05-05 11:45:57 -06001735 memset(pData, 0xCADECADE, static_cast<size_t>(mem_reqs.size));
Mark Lobodzinski152fe252016-05-03 16:49:15 -06001736
1737 vkUnmapMemory(m_device->device(), mem);
1738
1739 err = vkBindBufferMemory(m_device->device(), buffer, mem, 0);
1740 ASSERT_VK_SUCCESS(err);
1741
1742 // NOW, destroy the buffer. Obviously, the resource no longer occupies this
1743 // memory. In fact, it was never used by the GPU.
1744 // Just be be sure, wait for idle.
1745 vkDestroyBuffer(m_device->device(), buffer, NULL);
1746 vkDeviceWaitIdle(m_device->device());
1747
1748 VkImageCreateInfo image_create_info = {};
1749 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
1750 image_create_info.pNext = NULL;
1751 image_create_info.imageType = VK_IMAGE_TYPE_2D;
1752 image_create_info.format = VK_FORMAT_R8G8B8A8_UNORM;
1753 image_create_info.extent.width = 64;
1754 image_create_info.extent.height = 64;
1755 image_create_info.extent.depth = 1;
1756 image_create_info.mipLevels = 1;
1757 image_create_info.arrayLayers = 1;
1758 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
1759 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
1760 image_create_info.initialLayout = VK_IMAGE_LAYOUT_PREINITIALIZED;
1761 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
1762 image_create_info.queueFamilyIndexCount = 0;
1763 image_create_info.pQueueFamilyIndices = NULL;
1764 image_create_info.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
1765 image_create_info.flags = 0;
1766
1767 VkMemoryAllocateInfo mem_alloc = {};
1768 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
1769 mem_alloc.pNext = NULL;
1770 mem_alloc.allocationSize = 0;
1771 mem_alloc.memoryTypeIndex = 0;
1772
1773 /* Create a mappable image. It will be the texture if linear images are ok
1774 * to be textures or it will be the staging image if they are not.
1775 */
1776 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
1777 ASSERT_VK_SUCCESS(err);
1778
1779 vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs);
1780
1781 mem_alloc.allocationSize = mem_reqs.size;
1782
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001783 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 -06001784 if (!pass) {
1785 vkDestroyImage(m_device->device(), image, NULL);
1786 return;
1787 }
1788
Tobin Ehlis077ded32016-05-12 17:39:13 -06001789 // VALIDATION FAILURE:
Mark Lobodzinski152fe252016-05-03 16:49:15 -06001790 err = vkBindImageMemory(m_device->device(), image, mem, 0);
1791 ASSERT_VK_SUCCESS(err);
1792
1793 m_errorMonitor->VerifyNotFound();
1794
Tony Barbourdf4c0042016-06-01 15:55:43 -06001795 vkFreeMemory(m_device->device(), mem, NULL);
Mark Lobodzinski152fe252016-05-03 16:49:15 -06001796 vkDestroyBuffer(m_device->device(), buffer, NULL);
1797 vkDestroyImage(m_device->device(), image, NULL);
1798}
1799
Tobin Ehlisf11be982016-05-11 13:52:53 -06001800TEST_F(VkLayerTest, InvalidMemoryAliasing) {
1801 TEST_DESCRIPTION("Create a buffer and image, allocate memory, and bind the "
1802 "buffer and image to memory such that they will alias.");
1803 VkResult err;
1804 bool pass;
1805 ASSERT_NO_FATAL_FAILURE(InitState());
1806
Tobin Ehlis077ded32016-05-12 17:39:13 -06001807 VkBuffer buffer, buffer2;
Tobin Ehlisf11be982016-05-11 13:52:53 -06001808 VkImage image;
1809 VkDeviceMemory mem; // buffer will be bound first
1810 VkDeviceMemory mem_img; // image bound first
Tobin Ehlis077ded32016-05-12 17:39:13 -06001811 VkMemoryRequirements buff_mem_reqs, img_mem_reqs;
Tobin Ehlisf11be982016-05-11 13:52:53 -06001812
1813 VkBufferCreateInfo buf_info = {};
1814 buf_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
1815 buf_info.pNext = NULL;
1816 buf_info.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
1817 buf_info.size = 256;
1818 buf_info.queueFamilyIndexCount = 0;
1819 buf_info.pQueueFamilyIndices = NULL;
1820 buf_info.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
1821 buf_info.flags = 0;
1822 err = vkCreateBuffer(m_device->device(), &buf_info, NULL, &buffer);
1823 ASSERT_VK_SUCCESS(err);
1824
Tobin Ehlis077ded32016-05-12 17:39:13 -06001825 vkGetBufferMemoryRequirements(m_device->device(), buffer, &buff_mem_reqs);
Tobin Ehlisf11be982016-05-11 13:52:53 -06001826
1827 VkImageCreateInfo image_create_info = {};
1828 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
1829 image_create_info.pNext = NULL;
1830 image_create_info.imageType = VK_IMAGE_TYPE_2D;
1831 image_create_info.format = VK_FORMAT_R8G8B8A8_UNORM;
1832 image_create_info.extent.width = 64;
1833 image_create_info.extent.height = 64;
1834 image_create_info.extent.depth = 1;
1835 image_create_info.mipLevels = 1;
1836 image_create_info.arrayLayers = 1;
1837 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
Tobin Ehlis12a4b5e2016-08-08 12:33:11 -06001838 // Image tiling must be optimal to trigger error when aliasing linear buffer
1839 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
Tobin Ehlisf11be982016-05-11 13:52:53 -06001840 image_create_info.initialLayout = VK_IMAGE_LAYOUT_PREINITIALIZED;
1841 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
1842 image_create_info.queueFamilyIndexCount = 0;
1843 image_create_info.pQueueFamilyIndices = NULL;
1844 image_create_info.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
1845 image_create_info.flags = 0;
1846
Tobin Ehlisf11be982016-05-11 13:52:53 -06001847 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
1848 ASSERT_VK_SUCCESS(err);
1849
Tobin Ehlis077ded32016-05-12 17:39:13 -06001850 vkGetImageMemoryRequirements(m_device->device(), image, &img_mem_reqs);
1851
1852 VkMemoryAllocateInfo alloc_info = {};
1853 alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
1854 alloc_info.pNext = NULL;
1855 alloc_info.memoryTypeIndex = 0;
1856 // Ensure memory is big enough for both bindings
1857 alloc_info.allocationSize = buff_mem_reqs.size + img_mem_reqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001858 pass = m_device->phy().set_memory_type(buff_mem_reqs.memoryTypeBits & img_mem_reqs.memoryTypeBits, &alloc_info,
1859 VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT);
Tobin Ehlisf11be982016-05-11 13:52:53 -06001860 if (!pass) {
Tobin Ehlis077ded32016-05-12 17:39:13 -06001861 vkDestroyBuffer(m_device->device(), buffer, NULL);
Tobin Ehlisf11be982016-05-11 13:52:53 -06001862 vkDestroyImage(m_device->device(), image, NULL);
1863 return;
1864 }
Tobin Ehlis077ded32016-05-12 17:39:13 -06001865 err = vkAllocateMemory(m_device->device(), &alloc_info, NULL, &mem);
1866 ASSERT_VK_SUCCESS(err);
1867 err = vkBindBufferMemory(m_device->device(), buffer, mem, 0);
1868 ASSERT_VK_SUCCESS(err);
1869
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001870 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " is aliased with linear buffer 0x");
Tobin Ehlis077ded32016-05-12 17:39:13 -06001871 // VALIDATION FAILURE due to image mapping overlapping buffer mapping
Tobin Ehlisf11be982016-05-11 13:52:53 -06001872 err = vkBindImageMemory(m_device->device(), image, mem, 0);
1873 m_errorMonitor->VerifyFound();
1874
1875 // Now correctly bind image to second mem allocation before incorrectly
Tobin Ehlis077ded32016-05-12 17:39:13 -06001876 // aliasing buffer2
1877 err = vkCreateBuffer(m_device->device(), &buf_info, NULL, &buffer2);
1878 ASSERT_VK_SUCCESS(err);
Tobin Ehlisf11be982016-05-11 13:52:53 -06001879 err = vkAllocateMemory(m_device->device(), &alloc_info, NULL, &mem_img);
1880 ASSERT_VK_SUCCESS(err);
1881 err = vkBindImageMemory(m_device->device(), image, mem_img, 0);
1882 ASSERT_VK_SUCCESS(err);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001883 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "is aliased with non-linear image 0x");
Tobin Ehlis077ded32016-05-12 17:39:13 -06001884 err = vkBindBufferMemory(m_device->device(), buffer2, mem_img, 0);
Tobin Ehlisf11be982016-05-11 13:52:53 -06001885 m_errorMonitor->VerifyFound();
1886
1887 vkDestroyBuffer(m_device->device(), buffer, NULL);
Tobin Ehlis077ded32016-05-12 17:39:13 -06001888 vkDestroyBuffer(m_device->device(), buffer2, NULL);
Tobin Ehlisf11be982016-05-11 13:52:53 -06001889 vkDestroyImage(m_device->device(), image, NULL);
1890 vkFreeMemory(m_device->device(), mem, NULL);
1891 vkFreeMemory(m_device->device(), mem_img, NULL);
1892}
1893
Tobin Ehlis35372522016-05-12 08:32:31 -06001894TEST_F(VkLayerTest, InvalidMemoryMapping) {
1895 TEST_DESCRIPTION("Attempt to map memory in a number of incorrect ways");
1896 VkResult err;
1897 bool pass;
1898 ASSERT_NO_FATAL_FAILURE(InitState());
1899
1900 VkBuffer buffer;
1901 VkDeviceMemory mem;
1902 VkMemoryRequirements mem_reqs;
1903
1904 VkBufferCreateInfo buf_info = {};
1905 buf_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
1906 buf_info.pNext = NULL;
1907 buf_info.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
1908 buf_info.size = 256;
1909 buf_info.queueFamilyIndexCount = 0;
1910 buf_info.pQueueFamilyIndices = NULL;
1911 buf_info.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
1912 buf_info.flags = 0;
1913 err = vkCreateBuffer(m_device->device(), &buf_info, NULL, &buffer);
1914 ASSERT_VK_SUCCESS(err);
1915
1916 vkGetBufferMemoryRequirements(m_device->device(), buffer, &mem_reqs);
1917 VkMemoryAllocateInfo alloc_info = {};
1918 alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
1919 alloc_info.pNext = NULL;
1920 alloc_info.memoryTypeIndex = 0;
1921
1922 // Ensure memory is big enough for both bindings
1923 static const VkDeviceSize allocation_size = 0x10000;
1924 alloc_info.allocationSize = allocation_size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001925 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 -06001926 if (!pass) {
1927 vkDestroyBuffer(m_device->device(), buffer, NULL);
1928 return;
1929 }
1930 err = vkAllocateMemory(m_device->device(), &alloc_info, NULL, &mem);
1931 ASSERT_VK_SUCCESS(err);
1932
1933 uint8_t *pData;
1934 // Attempt to map memory size 0 is invalid
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001935 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 -06001936 err = vkMapMemory(m_device->device(), mem, 0, 0, 0, (void **)&pData);
1937 m_errorMonitor->VerifyFound();
1938 // Map memory twice
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001939 err = vkMapMemory(m_device->device(), mem, 0, mem_reqs.size, 0, (void **)&pData);
Tobin Ehlis35372522016-05-12 08:32:31 -06001940 ASSERT_VK_SUCCESS(err);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001941 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
1942 "VkMapMemory: Attempting to map memory on an already-mapped object ");
1943 err = vkMapMemory(m_device->device(), mem, 0, mem_reqs.size, 0, (void **)&pData);
Tobin Ehlis35372522016-05-12 08:32:31 -06001944 m_errorMonitor->VerifyFound();
1945
1946 // Unmap the memory to avoid re-map error
1947 vkUnmapMemory(m_device->device(), mem);
1948 // overstep allocation with VK_WHOLE_SIZE
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001949 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
1950 " with size of VK_WHOLE_SIZE oversteps total array size 0x");
1951 err = vkMapMemory(m_device->device(), mem, allocation_size + 1, VK_WHOLE_SIZE, 0, (void **)&pData);
Tobin Ehlis35372522016-05-12 08:32:31 -06001952 m_errorMonitor->VerifyFound();
1953 // overstep allocation w/o VK_WHOLE_SIZE
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001954 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " oversteps total array size 0x");
1955 err = vkMapMemory(m_device->device(), mem, 1, allocation_size, 0, (void **)&pData);
Tobin Ehlis35372522016-05-12 08:32:31 -06001956 m_errorMonitor->VerifyFound();
1957 // Now error due to unmapping memory that's not mapped
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001958 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Unmapping Memory without memory being mapped: ");
Tobin Ehlis35372522016-05-12 08:32:31 -06001959 vkUnmapMemory(m_device->device(), mem);
1960 m_errorMonitor->VerifyFound();
1961 // Now map memory and cause errors due to flushing invalid ranges
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001962 err = vkMapMemory(m_device->device(), mem, 16, VK_WHOLE_SIZE, 0, (void **)&pData);
Tobin Ehlis35372522016-05-12 08:32:31 -06001963 ASSERT_VK_SUCCESS(err);
1964 VkMappedMemoryRange mmr = {};
Chris Forbes3aec0892016-06-13 10:29:26 +12001965 mmr.sType = VK_STRUCTURE_TYPE_MAPPED_MEMORY_RANGE;
Tobin Ehlis35372522016-05-12 08:32:31 -06001966 mmr.memory = mem;
1967 mmr.offset = 15; // Error b/c offset less than offset of mapped mem
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001968 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, ") is less than Memory Object's offset (");
Tobin Ehlis35372522016-05-12 08:32:31 -06001969 vkFlushMappedMemoryRanges(m_device->device(), 1, &mmr);
1970 m_errorMonitor->VerifyFound();
1971 // Now flush range that oversteps mapped range
1972 vkUnmapMemory(m_device->device(), mem);
1973 err = vkMapMemory(m_device->device(), mem, 0, 256, 0, (void **)&pData);
1974 ASSERT_VK_SUCCESS(err);
1975 mmr.offset = 16;
1976 mmr.size = 256; // flushing bounds (272) exceed mapped bounds (256)
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001977 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, ") exceeds the Memory Object's upper-bound (");
Tobin Ehlis35372522016-05-12 08:32:31 -06001978 vkFlushMappedMemoryRanges(m_device->device(), 1, &mmr);
1979 m_errorMonitor->VerifyFound();
1980
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001981 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &alloc_info, VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT,
1982 VK_MEMORY_PROPERTY_HOST_COHERENT_BIT);
Tobin Ehlis35372522016-05-12 08:32:31 -06001983 if (!pass) {
1984 vkFreeMemory(m_device->device(), mem, NULL);
1985 vkDestroyBuffer(m_device->device(), buffer, NULL);
1986 return;
1987 }
1988 // TODO : If we can get HOST_VISIBLE w/o HOST_COHERENT we can test cases of
1989 // MEMTRACK_INVALID_MAP in validateAndCopyNoncoherentMemoryToDriver()
1990
1991 vkDestroyBuffer(m_device->device(), buffer, NULL);
1992 vkFreeMemory(m_device->device(), mem, NULL);
1993}
1994
Mark Lobodzinski1f515922016-08-16 10:03:30 -06001995TEST_F(VkLayerTest, NonCoherentMemoryMapping) {
1996
1997 TEST_DESCRIPTION("Ensure that validations handling of non-coherent memory "
1998 "mapping while using VK_WHOLE_SIZE does not cause access "
1999 "violations");
2000 VkResult err;
2001 uint8_t *pData;
2002 ASSERT_NO_FATAL_FAILURE(InitState());
2003
2004 VkDeviceMemory mem;
2005 VkMemoryRequirements mem_reqs;
2006 mem_reqs.memoryTypeBits = 0xFFFFFFFF;
2007 VkMemoryAllocateInfo alloc_info = {};
2008 alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
2009 alloc_info.pNext = NULL;
2010 alloc_info.memoryTypeIndex = 0;
2011
2012 static const VkDeviceSize allocation_size = 0x1000;
2013 alloc_info.allocationSize = allocation_size;
2014
2015 // Find a memory configurations WITHOUT a COHERENT bit, otherwise exit
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002016 bool pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &alloc_info, VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT,
2017 VK_MEMORY_PROPERTY_HOST_COHERENT_BIT);
Mark Lobodzinski1f515922016-08-16 10:03:30 -06002018 if (!pass) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002019 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &alloc_info,
2020 VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT,
2021 VK_MEMORY_PROPERTY_HOST_COHERENT_BIT);
Mark Lobodzinski1f515922016-08-16 10:03:30 -06002022 if (!pass) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002023 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &alloc_info,
2024 VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT |
2025 VK_MEMORY_PROPERTY_HOST_CACHED_BIT,
2026 VK_MEMORY_PROPERTY_HOST_COHERENT_BIT);
Mark Lobodzinski1f515922016-08-16 10:03:30 -06002027 if (!pass) {
2028 return;
2029 }
2030 }
2031 }
2032
2033 err = vkAllocateMemory(m_device->device(), &alloc_info, NULL, &mem);
2034 ASSERT_VK_SUCCESS(err);
2035
2036 // Map/Flush/Invalidate using WHOLE_SIZE and zero offsets and entire
2037 // mapped range
2038 m_errorMonitor->ExpectSuccess();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002039 err = vkMapMemory(m_device->device(), mem, 0, VK_WHOLE_SIZE, 0, (void **)&pData);
Mark Lobodzinski1f515922016-08-16 10:03:30 -06002040 ASSERT_VK_SUCCESS(err);
2041 VkMappedMemoryRange mmr = {};
2042 mmr.sType = VK_STRUCTURE_TYPE_MAPPED_MEMORY_RANGE;
2043 mmr.memory = mem;
2044 mmr.offset = 0;
2045 mmr.size = VK_WHOLE_SIZE;
2046 err = vkFlushMappedMemoryRanges(m_device->device(), 1, &mmr);
2047 ASSERT_VK_SUCCESS(err);
2048 err = vkInvalidateMappedMemoryRanges(m_device->device(), 1, &mmr);
2049 ASSERT_VK_SUCCESS(err);
2050 m_errorMonitor->VerifyNotFound();
2051 vkUnmapMemory(m_device->device(), mem);
2052
2053 // Map/Flush/Invalidate using WHOLE_SIZE and a prime offset and entire
2054 // mapped range
2055 m_errorMonitor->ExpectSuccess();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002056 err = vkMapMemory(m_device->device(), mem, 13, VK_WHOLE_SIZE, 0, (void **)&pData);
Mark Lobodzinski1f515922016-08-16 10:03:30 -06002057 ASSERT_VK_SUCCESS(err);
2058 mmr.sType = VK_STRUCTURE_TYPE_MAPPED_MEMORY_RANGE;
2059 mmr.memory = mem;
2060 mmr.offset = 13;
2061 mmr.size = VK_WHOLE_SIZE;
2062 err = vkFlushMappedMemoryRanges(m_device->device(), 1, &mmr);
2063 ASSERT_VK_SUCCESS(err);
2064 err = vkInvalidateMappedMemoryRanges(m_device->device(), 1, &mmr);
2065 ASSERT_VK_SUCCESS(err);
2066 m_errorMonitor->VerifyNotFound();
2067 vkUnmapMemory(m_device->device(), mem);
2068
2069 // Map with prime offset and size
2070 // Flush/Invalidate subrange of mapped area with prime offset and size
2071 m_errorMonitor->ExpectSuccess();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002072 err = vkMapMemory(m_device->device(), mem, allocation_size - 137, 109, 0, (void **)&pData);
Mark Lobodzinski1f515922016-08-16 10:03:30 -06002073 ASSERT_VK_SUCCESS(err);
2074 mmr.sType = VK_STRUCTURE_TYPE_MAPPED_MEMORY_RANGE;
2075 mmr.memory = mem;
2076 mmr.offset = allocation_size - 107;
2077 mmr.size = 61;
2078 err = vkFlushMappedMemoryRanges(m_device->device(), 1, &mmr);
2079 ASSERT_VK_SUCCESS(err);
2080 err = vkInvalidateMappedMemoryRanges(m_device->device(), 1, &mmr);
2081 ASSERT_VK_SUCCESS(err);
2082 m_errorMonitor->VerifyNotFound();
2083 vkUnmapMemory(m_device->device(), mem);
2084
2085 vkFreeMemory(m_device->device(), mem, NULL);
2086}
2087
Ian Elliott1c32c772016-04-28 14:47:13 -06002088TEST_F(VkLayerTest, EnableWsiBeforeUse) {
2089 VkResult err;
2090 bool pass;
2091
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002092 // FIXME: After we turn on this code for non-Linux platforms, uncomment the
2093 // following declaration (which is temporarily being moved below):
2094 // VkSurfaceKHR surface = VK_NULL_HANDLE;
Ian Elliott1c32c772016-04-28 14:47:13 -06002095 VkSwapchainKHR swapchain = VK_NULL_HANDLE;
2096 VkSwapchainCreateInfoKHR swapchain_create_info = {};
2097 uint32_t swapchain_image_count = 0;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002098 // VkImage swapchain_images[1] = {VK_NULL_HANDLE};
Ian Elliott1c32c772016-04-28 14:47:13 -06002099 uint32_t image_index = 0;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002100 // VkPresentInfoKHR present_info = {};
Ian Elliott1c32c772016-04-28 14:47:13 -06002101
2102 ASSERT_NO_FATAL_FAILURE(InitState());
2103
Ian Elliott3f06ce52016-04-29 14:46:21 -06002104#ifdef NEED_TO_TEST_THIS_ON_PLATFORM
2105#if defined(VK_USE_PLATFORM_ANDROID_KHR)
2106 // Use the functions from the VK_KHR_android_surface extension without
2107 // enabling that extension:
2108
2109 // Create a surface:
2110 VkAndroidSurfaceCreateInfoKHR android_create_info = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002111 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
2112 err = vkCreateAndroidSurfaceKHR(instance(), &android_create_info, NULL, &surface);
Ian Elliott3f06ce52016-04-29 14:46:21 -06002113 pass = (err != VK_SUCCESS);
2114 ASSERT_TRUE(pass);
2115 m_errorMonitor->VerifyFound();
2116#endif // VK_USE_PLATFORM_ANDROID_KHR
2117
Ian Elliott3f06ce52016-04-29 14:46:21 -06002118#if defined(VK_USE_PLATFORM_MIR_KHR)
2119 // Use the functions from the VK_KHR_mir_surface extension without enabling
2120 // that extension:
2121
2122 // Create a surface:
2123 VkMirSurfaceCreateInfoKHR mir_create_info = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002124 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
Ian Elliott3f06ce52016-04-29 14:46:21 -06002125 err = vkCreateMirSurfaceKHR(instance(), &mir_create_info, NULL, &surface);
2126 pass = (err != VK_SUCCESS);
2127 ASSERT_TRUE(pass);
2128 m_errorMonitor->VerifyFound();
2129
2130 // Tell whether an mir_connection supports presentation:
2131 MirConnection *mir_connection = NULL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002132 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
2133 vkGetPhysicalDeviceMirPresentationSupportKHR(gpu(), 0, mir_connection, visual_id);
Ian Elliott3f06ce52016-04-29 14:46:21 -06002134 m_errorMonitor->VerifyFound();
2135#endif // VK_USE_PLATFORM_MIR_KHR
2136
Ian Elliott3f06ce52016-04-29 14:46:21 -06002137#if defined(VK_USE_PLATFORM_WAYLAND_KHR)
2138 // Use the functions from the VK_KHR_wayland_surface extension without
2139 // enabling that extension:
2140
2141 // Create a surface:
2142 VkWaylandSurfaceCreateInfoKHR wayland_create_info = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002143 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
2144 err = vkCreateWaylandSurfaceKHR(instance(), &wayland_create_info, NULL, &surface);
Ian Elliott3f06ce52016-04-29 14:46:21 -06002145 pass = (err != VK_SUCCESS);
2146 ASSERT_TRUE(pass);
2147 m_errorMonitor->VerifyFound();
2148
2149 // Tell whether an wayland_display supports presentation:
2150 struct wl_display wayland_display = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002151 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
2152 vkGetPhysicalDeviceWaylandPresentationSupportKHR(gpu(), 0, &wayland_display);
Ian Elliott3f06ce52016-04-29 14:46:21 -06002153 m_errorMonitor->VerifyFound();
2154#endif // VK_USE_PLATFORM_WAYLAND_KHR
Ian Elliott489eec02016-05-05 14:12:44 -06002155#endif // NEED_TO_TEST_THIS_ON_PLATFORM
Ian Elliott3f06ce52016-04-29 14:46:21 -06002156
Ian Elliott3f06ce52016-04-29 14:46:21 -06002157#if defined(VK_USE_PLATFORM_WIN32_KHR)
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002158 // FIXME: REMOVE THIS HERE, AND UNCOMMENT ABOVE, WHEN THIS TEST HAS BEEN PORTED
2159 // TO NON-LINUX PLATFORMS:
2160 VkSurfaceKHR surface = VK_NULL_HANDLE;
Ian Elliott3f06ce52016-04-29 14:46:21 -06002161 // Use the functions from the VK_KHR_win32_surface extension without
2162 // enabling that extension:
2163
2164 // Create a surface:
2165 VkWin32SurfaceCreateInfoKHR win32_create_info = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002166 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
2167 err = vkCreateWin32SurfaceKHR(instance(), &win32_create_info, NULL, &surface);
Ian Elliott3f06ce52016-04-29 14:46:21 -06002168 pass = (err != VK_SUCCESS);
2169 ASSERT_TRUE(pass);
2170 m_errorMonitor->VerifyFound();
2171
2172 // Tell whether win32 supports presentation:
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002173 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
Ian Elliott489eec02016-05-05 14:12:44 -06002174 vkGetPhysicalDeviceWin32PresentationSupportKHR(gpu(), 0);
Ian Elliott3f06ce52016-04-29 14:46:21 -06002175 m_errorMonitor->VerifyFound();
Ian Elliott489eec02016-05-05 14:12:44 -06002176// Set this (for now, until all platforms are supported and tested):
2177#define NEED_TO_TEST_THIS_ON_PLATFORM
2178#endif // VK_USE_PLATFORM_WIN32_KHR
Ian Elliott3f06ce52016-04-29 14:46:21 -06002179
Ian Elliott1c32c772016-04-28 14:47:13 -06002180#if defined(VK_USE_PLATFORM_XCB_KHR)
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002181 // FIXME: REMOVE THIS HERE, AND UNCOMMENT ABOVE, WHEN THIS TEST HAS BEEN PORTED
2182 // TO NON-LINUX PLATFORMS:
2183 VkSurfaceKHR surface = VK_NULL_HANDLE;
Ian Elliott1c32c772016-04-28 14:47:13 -06002184 // Use the functions from the VK_KHR_xcb_surface extension without enabling
2185 // that extension:
2186
2187 // Create a surface:
2188 VkXcbSurfaceCreateInfoKHR xcb_create_info = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002189 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
Ian Elliott1c32c772016-04-28 14:47:13 -06002190 err = vkCreateXcbSurfaceKHR(instance(), &xcb_create_info, NULL, &surface);
2191 pass = (err != VK_SUCCESS);
2192 ASSERT_TRUE(pass);
2193 m_errorMonitor->VerifyFound();
2194
2195 // Tell whether an xcb_visualid_t supports presentation:
Ian Elliott3f06ce52016-04-29 14:46:21 -06002196 xcb_connection_t *xcb_connection = NULL;
Ian Elliott1c32c772016-04-28 14:47:13 -06002197 xcb_visualid_t visual_id = 0;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002198 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
2199 vkGetPhysicalDeviceXcbPresentationSupportKHR(gpu(), 0, xcb_connection, visual_id);
Ian Elliott1c32c772016-04-28 14:47:13 -06002200 m_errorMonitor->VerifyFound();
Ian Elliott489eec02016-05-05 14:12:44 -06002201// Set this (for now, until all platforms are supported and tested):
2202#define NEED_TO_TEST_THIS_ON_PLATFORM
Ian Elliott1c32c772016-04-28 14:47:13 -06002203#endif // VK_USE_PLATFORM_XCB_KHR
2204
Ian Elliott12630812016-04-29 14:35:43 -06002205#if defined(VK_USE_PLATFORM_XLIB_KHR)
2206 // Use the functions from the VK_KHR_xlib_surface extension without enabling
2207 // that extension:
2208
2209 // Create a surface:
2210 VkXlibSurfaceCreateInfoKHR xlib_create_info = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002211 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
Ian Elliott12630812016-04-29 14:35:43 -06002212 err = vkCreateXlibSurfaceKHR(instance(), &xlib_create_info, NULL, &surface);
2213 pass = (err != VK_SUCCESS);
2214 ASSERT_TRUE(pass);
2215 m_errorMonitor->VerifyFound();
2216
2217 // Tell whether an Xlib VisualID supports presentation:
2218 Display *dpy = NULL;
2219 VisualID visual = 0;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002220 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
Ian Elliott12630812016-04-29 14:35:43 -06002221 vkGetPhysicalDeviceXlibPresentationSupportKHR(gpu(), 0, dpy, visual);
2222 m_errorMonitor->VerifyFound();
Ian Elliott489eec02016-05-05 14:12:44 -06002223// Set this (for now, until all platforms are supported and tested):
2224#define NEED_TO_TEST_THIS_ON_PLATFORM
Ian Elliott12630812016-04-29 14:35:43 -06002225#endif // VK_USE_PLATFORM_XLIB_KHR
2226
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002227// Use the functions from the VK_KHR_surface extension without enabling
2228// that extension:
Ian Elliott1c32c772016-04-28 14:47:13 -06002229
Ian Elliott489eec02016-05-05 14:12:44 -06002230#ifdef NEED_TO_TEST_THIS_ON_PLATFORM
Ian Elliott1c32c772016-04-28 14:47:13 -06002231 // Destroy a surface:
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002232 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
Ian Elliott1c32c772016-04-28 14:47:13 -06002233 vkDestroySurfaceKHR(instance(), surface, NULL);
2234 m_errorMonitor->VerifyFound();
2235
2236 // Check if surface supports presentation:
2237 VkBool32 supported = false;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002238 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
Ian Elliott1c32c772016-04-28 14:47:13 -06002239 err = vkGetPhysicalDeviceSurfaceSupportKHR(gpu(), 0, surface, &supported);
2240 pass = (err != VK_SUCCESS);
2241 ASSERT_TRUE(pass);
2242 m_errorMonitor->VerifyFound();
2243
2244 // Check surface capabilities:
2245 VkSurfaceCapabilitiesKHR capabilities = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002246 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
2247 err = vkGetPhysicalDeviceSurfaceCapabilitiesKHR(gpu(), surface, &capabilities);
Ian Elliott1c32c772016-04-28 14:47:13 -06002248 pass = (err != VK_SUCCESS);
2249 ASSERT_TRUE(pass);
2250 m_errorMonitor->VerifyFound();
2251
2252 // Check surface formats:
2253 uint32_t format_count = 0;
2254 VkSurfaceFormatKHR *formats = NULL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002255 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
2256 err = vkGetPhysicalDeviceSurfaceFormatsKHR(gpu(), surface, &format_count, formats);
Ian Elliott1c32c772016-04-28 14:47:13 -06002257 pass = (err != VK_SUCCESS);
2258 ASSERT_TRUE(pass);
2259 m_errorMonitor->VerifyFound();
2260
2261 // Check surface present modes:
2262 uint32_t present_mode_count = 0;
2263 VkSurfaceFormatKHR *present_modes = NULL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002264 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
2265 err = vkGetPhysicalDeviceSurfaceFormatsKHR(gpu(), surface, &present_mode_count, present_modes);
Ian Elliott1c32c772016-04-28 14:47:13 -06002266 pass = (err != VK_SUCCESS);
2267 ASSERT_TRUE(pass);
2268 m_errorMonitor->VerifyFound();
Ian Elliott489eec02016-05-05 14:12:44 -06002269#endif // NEED_TO_TEST_THIS_ON_PLATFORM
Ian Elliott1c32c772016-04-28 14:47:13 -06002270
Ian Elliott1c32c772016-04-28 14:47:13 -06002271 // Use the functions from the VK_KHR_swapchain extension without enabling
2272 // that extension:
2273
2274 // Create a swapchain:
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002275 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
Ian Elliott1c32c772016-04-28 14:47:13 -06002276 swapchain_create_info.sType = VK_STRUCTURE_TYPE_SWAPCHAIN_CREATE_INFO_KHR;
2277 swapchain_create_info.pNext = NULL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002278 err = vkCreateSwapchainKHR(m_device->device(), &swapchain_create_info, NULL, &swapchain);
Ian Elliott1c32c772016-04-28 14:47:13 -06002279 pass = (err != VK_SUCCESS);
2280 ASSERT_TRUE(pass);
2281 m_errorMonitor->VerifyFound();
2282
2283 // Get the images from the swapchain:
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002284 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
2285 err = vkGetSwapchainImagesKHR(m_device->device(), swapchain, &swapchain_image_count, NULL);
Ian Elliott1c32c772016-04-28 14:47:13 -06002286 pass = (err != VK_SUCCESS);
2287 ASSERT_TRUE(pass);
2288 m_errorMonitor->VerifyFound();
2289
Chris Forbeseb7d5502016-09-13 18:19:21 +12002290 // Add a fence to avoid (justifiable) error about not providing fence OR semaphore
2291 VkFenceCreateInfo fci = { VK_STRUCTURE_TYPE_FENCE_CREATE_INFO, nullptr, 0 };
2292 VkFence fence;
2293 err = vkCreateFence(m_device->device(), &fci, nullptr, &fence);
2294
Ian Elliott1c32c772016-04-28 14:47:13 -06002295 // Try to acquire an image:
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002296 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
Chris Forbeseb7d5502016-09-13 18:19:21 +12002297 err = vkAcquireNextImageKHR(m_device->device(), swapchain, 0, VK_NULL_HANDLE, fence, &image_index);
Ian Elliott1c32c772016-04-28 14:47:13 -06002298 pass = (err != VK_SUCCESS);
2299 ASSERT_TRUE(pass);
2300 m_errorMonitor->VerifyFound();
2301
Chris Forbeseb7d5502016-09-13 18:19:21 +12002302 vkDestroyFence(m_device->device(), fence, nullptr);
2303
Ian Elliott1c32c772016-04-28 14:47:13 -06002304 // Try to present an image:
Ian Elliott2c1daf52016-05-12 09:41:46 -06002305 //
2306 // NOTE: Currently can't test this because a real swapchain is needed (as
2307 // opposed to the fake one we created) in order for the layer to lookup the
2308 // VkDevice used to enable the extension:
Ian Elliott1c32c772016-04-28 14:47:13 -06002309
2310 // Destroy the swapchain:
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002311 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
Ian Elliott1c32c772016-04-28 14:47:13 -06002312 vkDestroySwapchainKHR(m_device->device(), swapchain, NULL);
2313 m_errorMonitor->VerifyFound();
2314}
2315
Ian Elliott2c1daf52016-05-12 09:41:46 -06002316TEST_F(VkWsiEnabledLayerTest, TestEnabledWsi) {
Ian Elliott2c1daf52016-05-12 09:41:46 -06002317
Dustin Graves6c6d8982016-05-17 10:09:21 -06002318#if defined(VK_USE_PLATFORM_XCB_KHR)
Ian Elliott2c1daf52016-05-12 09:41:46 -06002319 VkSurfaceKHR surface = VK_NULL_HANDLE;
Mark Lobodzinski085d27a2016-05-17 09:34:26 -06002320
Mark Lobodzinski085d27a2016-05-17 09:34:26 -06002321 VkResult err;
2322 bool pass;
Ian Elliott2c1daf52016-05-12 09:41:46 -06002323 VkSwapchainKHR swapchain = VK_NULL_HANDLE;
2324 VkSwapchainCreateInfoKHR swapchain_create_info = {};
Mark Lobodzinski085d27a2016-05-17 09:34:26 -06002325 // uint32_t swapchain_image_count = 0;
2326 // VkImage swapchain_images[1] = {VK_NULL_HANDLE};
2327 // uint32_t image_index = 0;
2328 // VkPresentInfoKHR present_info = {};
Ian Elliott2c1daf52016-05-12 09:41:46 -06002329
2330 ASSERT_NO_FATAL_FAILURE(InitState());
2331
2332 // Use the create function from one of the VK_KHR_*_surface extension in
2333 // order to create a surface, testing all known errors in the process,
2334 // before successfully creating a surface:
2335 // First, try to create a surface without a VkXcbSurfaceCreateInfoKHR:
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002336 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "required parameter pCreateInfo specified as NULL");
Ian Elliott2c1daf52016-05-12 09:41:46 -06002337 err = vkCreateXcbSurfaceKHR(instance(), NULL, NULL, &surface);
2338 pass = (err != VK_SUCCESS);
2339 ASSERT_TRUE(pass);
2340 m_errorMonitor->VerifyFound();
2341
2342 // Next, try to create a surface with the wrong
2343 // VkXcbSurfaceCreateInfoKHR::sType:
2344 VkXcbSurfaceCreateInfoKHR xcb_create_info = {};
2345 xcb_create_info.sType = VK_STRUCTURE_TYPE_APPLICATION_INFO;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002346 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "parameter pCreateInfo->sType must be");
Ian Elliott2c1daf52016-05-12 09:41:46 -06002347 err = vkCreateXcbSurfaceKHR(instance(), &xcb_create_info, NULL, &surface);
2348 pass = (err != VK_SUCCESS);
2349 ASSERT_TRUE(pass);
2350 m_errorMonitor->VerifyFound();
2351
Ian Elliott2c1daf52016-05-12 09:41:46 -06002352 // Create a native window, and then correctly create a surface:
2353 xcb_connection_t *connection;
2354 xcb_screen_t *screen;
2355 xcb_window_t xcb_window;
2356 xcb_intern_atom_reply_t *atom_wm_delete_window;
2357
2358 const xcb_setup_t *setup;
2359 xcb_screen_iterator_t iter;
2360 int scr;
2361 uint32_t value_mask, value_list[32];
2362 int width = 1;
2363 int height = 1;
2364
2365 connection = xcb_connect(NULL, &scr);
2366 ASSERT_TRUE(connection != NULL);
2367 setup = xcb_get_setup(connection);
2368 iter = xcb_setup_roots_iterator(setup);
2369 while (scr-- > 0)
2370 xcb_screen_next(&iter);
2371 screen = iter.data;
2372
2373 xcb_window = xcb_generate_id(connection);
2374
2375 value_mask = XCB_CW_BACK_PIXEL | XCB_CW_EVENT_MASK;
2376 value_list[0] = screen->black_pixel;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002377 value_list[1] = XCB_EVENT_MASK_KEY_RELEASE | XCB_EVENT_MASK_EXPOSURE | XCB_EVENT_MASK_STRUCTURE_NOTIFY;
Ian Elliott2c1daf52016-05-12 09:41:46 -06002378
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002379 xcb_create_window(connection, XCB_COPY_FROM_PARENT, xcb_window, screen->root, 0, 0, width, height, 0,
2380 XCB_WINDOW_CLASS_INPUT_OUTPUT, screen->root_visual, value_mask, value_list);
Ian Elliott2c1daf52016-05-12 09:41:46 -06002381
2382 /* Magic code that will send notification when window is destroyed */
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002383 xcb_intern_atom_cookie_t cookie = xcb_intern_atom(connection, 1, 12, "WM_PROTOCOLS");
2384 xcb_intern_atom_reply_t *reply = xcb_intern_atom_reply(connection, cookie, 0);
Ian Elliott2c1daf52016-05-12 09:41:46 -06002385
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002386 xcb_intern_atom_cookie_t cookie2 = xcb_intern_atom(connection, 0, 16, "WM_DELETE_WINDOW");
Mark Lobodzinski085d27a2016-05-17 09:34:26 -06002387 atom_wm_delete_window = xcb_intern_atom_reply(connection, cookie2, 0);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002388 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 -06002389 free(reply);
2390
2391 xcb_map_window(connection, xcb_window);
2392
2393 // Force the x/y coordinates to 100,100 results are identical in consecutive
2394 // runs
2395 const uint32_t coords[] = {100, 100};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002396 xcb_configure_window(connection, xcb_window, XCB_CONFIG_WINDOW_X | XCB_CONFIG_WINDOW_Y, coords);
Ian Elliott2c1daf52016-05-12 09:41:46 -06002397
Ian Elliott2c1daf52016-05-12 09:41:46 -06002398 // Finally, try to correctly create a surface:
2399 xcb_create_info.sType = VK_STRUCTURE_TYPE_XCB_SURFACE_CREATE_INFO_KHR;
2400 xcb_create_info.pNext = NULL;
2401 xcb_create_info.flags = 0;
2402 xcb_create_info.connection = connection;
2403 xcb_create_info.window = xcb_window;
2404 err = vkCreateXcbSurfaceKHR(instance(), &xcb_create_info, NULL, &surface);
2405 pass = (err == VK_SUCCESS);
2406 ASSERT_TRUE(pass);
2407
Ian Elliott2c1daf52016-05-12 09:41:46 -06002408 // Check if surface supports presentation:
2409
2410 // 1st, do so without having queried the queue families:
2411 VkBool32 supported = false;
2412 // TODO: Get the following error to come out:
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002413 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
2414 "called before calling the vkGetPhysicalDeviceQueueFamilyProperties "
2415 "function");
Ian Elliott2c1daf52016-05-12 09:41:46 -06002416 err = vkGetPhysicalDeviceSurfaceSupportKHR(gpu(), 0, surface, &supported);
2417 pass = (err != VK_SUCCESS);
Mark Lobodzinski085d27a2016-05-17 09:34:26 -06002418 // ASSERT_TRUE(pass);
2419 // m_errorMonitor->VerifyFound();
Ian Elliott2c1daf52016-05-12 09:41:46 -06002420
2421 // Next, query a queue family index that's too large:
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002422 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "called with a queueFamilyIndex that is too large");
2423 err = vkGetPhysicalDeviceSurfaceSupportKHR(gpu(), 100000, surface, &supported);
Ian Elliott2c1daf52016-05-12 09:41:46 -06002424 pass = (err != VK_SUCCESS);
2425 ASSERT_TRUE(pass);
2426 m_errorMonitor->VerifyFound();
2427
2428 // Finally, do so correctly:
Mark Lobodzinski085d27a2016-05-17 09:34:26 -06002429 // FIXME: THIS ISN'T CORRECT--MUST QUERY UNTIL WE FIND A QUEUE FAMILY THAT'S
2430 // SUPPORTED
Ian Elliott2c1daf52016-05-12 09:41:46 -06002431 err = vkGetPhysicalDeviceSurfaceSupportKHR(gpu(), 0, surface, &supported);
2432 pass = (err == VK_SUCCESS);
2433 ASSERT_TRUE(pass);
2434
Ian Elliott2c1daf52016-05-12 09:41:46 -06002435 // Before proceeding, try to create a swapchain without having called
2436 // vkGetPhysicalDeviceSurfaceCapabilitiesKHR():
2437 swapchain_create_info.sType = VK_STRUCTURE_TYPE_SWAPCHAIN_CREATE_INFO_KHR;
2438 swapchain_create_info.pNext = NULL;
2439 swapchain_create_info.flags = 0;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002440 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
2441 "called before calling vkGetPhysicalDeviceSurfaceCapabilitiesKHR().");
2442 err = vkCreateSwapchainKHR(m_device->device(), &swapchain_create_info, NULL, &swapchain);
Ian Elliott2c1daf52016-05-12 09:41:46 -06002443 pass = (err != VK_SUCCESS);
2444 ASSERT_TRUE(pass);
2445 m_errorMonitor->VerifyFound();
2446
Ian Elliott2c1daf52016-05-12 09:41:46 -06002447 // Get the surface capabilities:
2448 VkSurfaceCapabilitiesKHR surface_capabilities;
2449
2450 // Do so correctly (only error logged by this entrypoint is if the
2451 // extension isn't enabled):
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002452 err = vkGetPhysicalDeviceSurfaceCapabilitiesKHR(gpu(), surface, &surface_capabilities);
Ian Elliott2c1daf52016-05-12 09:41:46 -06002453 pass = (err == VK_SUCCESS);
2454 ASSERT_TRUE(pass);
2455
Ian Elliott2c1daf52016-05-12 09:41:46 -06002456 // Get the surface formats:
2457 uint32_t surface_format_count;
2458
2459 // First, try without a pointer to surface_format_count:
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002460 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "required parameter pSurfaceFormatCount "
2461 "specified as NULL");
Ian Elliott2c1daf52016-05-12 09:41:46 -06002462 vkGetPhysicalDeviceSurfaceFormatsKHR(gpu(), surface, NULL, NULL);
2463 pass = (err == VK_SUCCESS);
2464 ASSERT_TRUE(pass);
2465 m_errorMonitor->VerifyFound();
2466
2467 // Next, call with a non-NULL pSurfaceFormats, even though we haven't
2468 // correctly done a 1st try (to get the count):
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002469 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 -06002470 surface_format_count = 0;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002471 vkGetPhysicalDeviceSurfaceFormatsKHR(gpu(), surface, &surface_format_count, (VkSurfaceFormatKHR *)&surface_format_count);
Ian Elliott2c1daf52016-05-12 09:41:46 -06002472 pass = (err == VK_SUCCESS);
2473 ASSERT_TRUE(pass);
2474 m_errorMonitor->VerifyFound();
2475
2476 // Next, correctly do a 1st try (with a NULL pointer to surface_formats):
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002477 vkGetPhysicalDeviceSurfaceFormatsKHR(gpu(), surface, &surface_format_count, NULL);
Ian Elliott2c1daf52016-05-12 09:41:46 -06002478 pass = (err == VK_SUCCESS);
2479 ASSERT_TRUE(pass);
2480
2481 // Allocate memory for the correct number of VkSurfaceFormatKHR's:
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002482 VkSurfaceFormatKHR *surface_formats = (VkSurfaceFormatKHR *)malloc(surface_format_count * sizeof(VkSurfaceFormatKHR));
Ian Elliott2c1daf52016-05-12 09:41:46 -06002483
2484 // Next, do a 2nd try with surface_format_count being set too high:
2485 surface_format_count += 5;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002486 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "that is greater than the value");
2487 vkGetPhysicalDeviceSurfaceFormatsKHR(gpu(), surface, &surface_format_count, surface_formats);
Ian Elliott2c1daf52016-05-12 09:41:46 -06002488 pass = (err == VK_SUCCESS);
2489 ASSERT_TRUE(pass);
2490 m_errorMonitor->VerifyFound();
2491
2492 // Finally, do a correct 1st and 2nd try:
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002493 vkGetPhysicalDeviceSurfaceFormatsKHR(gpu(), surface, &surface_format_count, NULL);
Ian Elliott2c1daf52016-05-12 09:41:46 -06002494 pass = (err == VK_SUCCESS);
2495 ASSERT_TRUE(pass);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002496 vkGetPhysicalDeviceSurfaceFormatsKHR(gpu(), surface, &surface_format_count, surface_formats);
Ian Elliott2c1daf52016-05-12 09:41:46 -06002497 pass = (err == VK_SUCCESS);
2498 ASSERT_TRUE(pass);
2499
Ian Elliott2c1daf52016-05-12 09:41:46 -06002500 // Get the surface present modes:
2501 uint32_t surface_present_mode_count;
2502
2503 // First, try without a pointer to surface_format_count:
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002504 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "required parameter pPresentModeCount "
2505 "specified as NULL");
Mark Lobodzinskib02ea642016-08-17 13:03:57 -06002506
Ian Elliott2c1daf52016-05-12 09:41:46 -06002507 vkGetPhysicalDeviceSurfacePresentModesKHR(gpu(), surface, NULL, NULL);
2508 pass = (err == VK_SUCCESS);
2509 ASSERT_TRUE(pass);
2510 m_errorMonitor->VerifyFound();
2511
2512 // Next, call with a non-NULL VkPresentModeKHR, even though we haven't
2513 // correctly done a 1st try (to get the count):
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002514 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 -06002515 surface_present_mode_count = 0;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002516 vkGetPhysicalDeviceSurfacePresentModesKHR(gpu(), surface, &surface_present_mode_count,
2517 (VkPresentModeKHR *)&surface_present_mode_count);
Ian Elliott2c1daf52016-05-12 09:41:46 -06002518 pass = (err == VK_SUCCESS);
2519 ASSERT_TRUE(pass);
2520 m_errorMonitor->VerifyFound();
2521
2522 // Next, correctly do a 1st try (with a NULL pointer to surface_formats):
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002523 vkGetPhysicalDeviceSurfacePresentModesKHR(gpu(), surface, &surface_present_mode_count, NULL);
Ian Elliott2c1daf52016-05-12 09:41:46 -06002524 pass = (err == VK_SUCCESS);
2525 ASSERT_TRUE(pass);
2526
2527 // Allocate memory for the correct number of VkSurfaceFormatKHR's:
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002528 VkPresentModeKHR *surface_present_modes = (VkPresentModeKHR *)malloc(surface_present_mode_count * sizeof(VkPresentModeKHR));
Ian Elliott2c1daf52016-05-12 09:41:46 -06002529
2530 // Next, do a 2nd try with surface_format_count being set too high:
2531 surface_present_mode_count += 5;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002532 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "that is greater than the value");
2533 vkGetPhysicalDeviceSurfacePresentModesKHR(gpu(), surface, &surface_present_mode_count, surface_present_modes);
Ian Elliott2c1daf52016-05-12 09:41:46 -06002534 pass = (err == VK_SUCCESS);
2535 ASSERT_TRUE(pass);
2536 m_errorMonitor->VerifyFound();
2537
2538 // Finally, do a correct 1st and 2nd try:
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002539 vkGetPhysicalDeviceSurfacePresentModesKHR(gpu(), surface, &surface_present_mode_count, NULL);
Ian Elliott2c1daf52016-05-12 09:41:46 -06002540 pass = (err == VK_SUCCESS);
2541 ASSERT_TRUE(pass);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002542 vkGetPhysicalDeviceSurfacePresentModesKHR(gpu(), surface, &surface_present_mode_count, surface_present_modes);
Ian Elliott2c1daf52016-05-12 09:41:46 -06002543 pass = (err == VK_SUCCESS);
2544 ASSERT_TRUE(pass);
2545
Ian Elliott2c1daf52016-05-12 09:41:46 -06002546 // Create a swapchain:
2547
2548 // First, try without a pointer to swapchain_create_info:
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002549 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "required parameter pCreateInfo "
2550 "specified as NULL");
Mark Lobodzinskib02ea642016-08-17 13:03:57 -06002551
Ian Elliott2c1daf52016-05-12 09:41:46 -06002552 err = vkCreateSwapchainKHR(m_device->device(), NULL, NULL, &swapchain);
2553 pass = (err != VK_SUCCESS);
2554 ASSERT_TRUE(pass);
2555 m_errorMonitor->VerifyFound();
2556
2557 // Next, call with a non-NULL swapchain_create_info, that has the wrong
2558 // sType:
2559 swapchain_create_info.sType = VK_STRUCTURE_TYPE_APPLICATION_INFO;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002560 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "parameter pCreateInfo->sType must be");
Mark Lobodzinskib02ea642016-08-17 13:03:57 -06002561
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002562 err = vkCreateSwapchainKHR(m_device->device(), &swapchain_create_info, NULL, &swapchain);
Ian Elliott2c1daf52016-05-12 09:41:46 -06002563 pass = (err != VK_SUCCESS);
2564 ASSERT_TRUE(pass);
2565 m_errorMonitor->VerifyFound();
2566
2567 // Next, call with a NULL swapchain pointer:
2568 swapchain_create_info.sType = VK_STRUCTURE_TYPE_SWAPCHAIN_CREATE_INFO_KHR;
2569 swapchain_create_info.pNext = NULL;
2570 swapchain_create_info.flags = 0;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002571 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "required parameter pSwapchain "
2572 "specified as NULL");
Mark Lobodzinskib02ea642016-08-17 13:03:57 -06002573
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002574 err = vkCreateSwapchainKHR(m_device->device(), &swapchain_create_info, NULL, NULL);
Ian Elliott2c1daf52016-05-12 09:41:46 -06002575 pass = (err != VK_SUCCESS);
2576 ASSERT_TRUE(pass);
2577 m_errorMonitor->VerifyFound();
2578
Mark Lobodzinski085d27a2016-05-17 09:34:26 -06002579 // TODO: Enhance swapchain layer so that
2580 // swapchain_create_info.queueFamilyIndexCount is checked against something?
Ian Elliott2c1daf52016-05-12 09:41:46 -06002581
2582 // Next, call with a queue family index that's too large:
2583 uint32_t queueFamilyIndex[2] = {100000, 0};
2584 swapchain_create_info.imageSharingMode = VK_SHARING_MODE_CONCURRENT;
2585 swapchain_create_info.queueFamilyIndexCount = 2;
2586 swapchain_create_info.pQueueFamilyIndices = queueFamilyIndex;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002587 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "called with a queueFamilyIndex that is too large");
2588 err = vkCreateSwapchainKHR(m_device->device(), &swapchain_create_info, NULL, &swapchain);
Ian Elliott2c1daf52016-05-12 09:41:46 -06002589 pass = (err != VK_SUCCESS);
2590 ASSERT_TRUE(pass);
2591 m_errorMonitor->VerifyFound();
2592
2593 // Next, call a queueFamilyIndexCount that's too small for CONCURRENT:
2594 swapchain_create_info.imageSharingMode = VK_SHARING_MODE_CONCURRENT;
2595 swapchain_create_info.queueFamilyIndexCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002596 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
2597 "but with a bad value(s) for pCreateInfo->queueFamilyIndexCount or "
2598 "pCreateInfo->pQueueFamilyIndices).");
2599 err = vkCreateSwapchainKHR(m_device->device(), &swapchain_create_info, NULL, &swapchain);
Ian Elliott2c1daf52016-05-12 09:41:46 -06002600 pass = (err != VK_SUCCESS);
2601 ASSERT_TRUE(pass);
2602 m_errorMonitor->VerifyFound();
2603
2604 // Next, call with an invalid imageSharingMode:
2605 swapchain_create_info.imageSharingMode = VK_SHARING_MODE_MAX_ENUM;
2606 swapchain_create_info.queueFamilyIndexCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002607 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
2608 "called with a non-supported pCreateInfo->imageSharingMode (i.e.");
2609 err = vkCreateSwapchainKHR(m_device->device(), &swapchain_create_info, NULL, &swapchain);
Ian Elliott2c1daf52016-05-12 09:41:46 -06002610 pass = (err != VK_SUCCESS);
2611 ASSERT_TRUE(pass);
2612 m_errorMonitor->VerifyFound();
2613 // Fix for the future:
Mark Lobodzinski085d27a2016-05-17 09:34:26 -06002614 // FIXME: THIS ISN'T CORRECT--MUST QUERY UNTIL WE FIND A QUEUE FAMILY THAT'S
2615 // SUPPORTED
Ian Elliott2c1daf52016-05-12 09:41:46 -06002616 swapchain_create_info.queueFamilyIndexCount = 0;
2617 queueFamilyIndex[0] = 0;
2618 swapchain_create_info.imageSharingMode = VK_SHARING_MODE_EXCLUSIVE;
2619
Mark Lobodzinski085d27a2016-05-17 09:34:26 -06002620 // TODO: CONTINUE TESTING VALIDATION OF vkCreateSwapchainKHR() ...
Ian Elliott2c1daf52016-05-12 09:41:46 -06002621 // Get the images from a swapchain:
Ian Elliott2c1daf52016-05-12 09:41:46 -06002622 // Acquire an image from a swapchain:
Ian Elliott2c1daf52016-05-12 09:41:46 -06002623 // Present an image to a swapchain:
Ian Elliott2c1daf52016-05-12 09:41:46 -06002624 // Destroy the swapchain:
2625
Mark Lobodzinski085d27a2016-05-17 09:34:26 -06002626 // TODOs:
2627 //
2628 // - Try destroying the device without first destroying the swapchain
2629 //
2630 // - Try destroying the device without first destroying the surface
2631 //
2632 // - Try destroying the surface without first destroying the swapchain
Ian Elliott2c1daf52016-05-12 09:41:46 -06002633
2634 // Destroy the surface:
2635 vkDestroySurfaceKHR(instance(), surface, NULL);
2636
Ian Elliott2c1daf52016-05-12 09:41:46 -06002637 // Tear down the window:
2638 xcb_destroy_window(connection, xcb_window);
2639 xcb_disconnect(connection);
2640
2641#else // VK_USE_PLATFORM_XCB_KHR
Mark Lobodzinski085d27a2016-05-17 09:34:26 -06002642 return;
Ian Elliott2c1daf52016-05-12 09:41:46 -06002643#endif // VK_USE_PLATFORM_XCB_KHR
2644}
2645
Karl Schultz6addd812016-02-02 17:17:23 -07002646TEST_F(VkLayerTest, MapMemWithoutHostVisibleBit) {
2647 VkResult err;
2648 bool pass;
Mark Lobodzinski3780e142015-05-14 15:08:13 -05002649
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002650 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
2651 "Mapping Memory without VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06002652
Mark Lobodzinski3780e142015-05-14 15:08:13 -05002653 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinski3780e142015-05-14 15:08:13 -05002654
2655 // Create an image, allocate memory, free it, and then try to bind it
Karl Schultz6addd812016-02-02 17:17:23 -07002656 VkImage image;
2657 VkDeviceMemory mem;
2658 VkMemoryRequirements mem_reqs;
Mark Lobodzinski3780e142015-05-14 15:08:13 -05002659
Karl Schultz6addd812016-02-02 17:17:23 -07002660 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
2661 const int32_t tex_width = 32;
2662 const int32_t tex_height = 32;
Mark Lobodzinski3780e142015-05-14 15:08:13 -05002663
Tony Barboureb254902015-07-15 12:50:33 -06002664 VkImageCreateInfo image_create_info = {};
2665 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
Karl Schultz6addd812016-02-02 17:17:23 -07002666 image_create_info.pNext = NULL;
2667 image_create_info.imageType = VK_IMAGE_TYPE_2D;
2668 image_create_info.format = tex_format;
2669 image_create_info.extent.width = tex_width;
2670 image_create_info.extent.height = tex_height;
2671 image_create_info.extent.depth = 1;
2672 image_create_info.mipLevels = 1;
2673 image_create_info.arrayLayers = 1;
2674 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
2675 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
2676 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
2677 image_create_info.flags = 0;
Chris Forbese65e4d02016-09-13 17:39:18 +12002678 image_create_info.initialLayout = VK_IMAGE_LAYOUT_PREINITIALIZED;
Mark Lobodzinski5fcc4212015-09-14 17:43:42 -06002679
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002680 VkMemoryAllocateInfo mem_alloc = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08002681 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
Karl Schultz6addd812016-02-02 17:17:23 -07002682 mem_alloc.pNext = NULL;
2683 mem_alloc.allocationSize = 0;
Mark Lobodzinski3780e142015-05-14 15:08:13 -05002684
Chia-I Wuf7458c52015-10-26 21:10:41 +08002685 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
Mark Lobodzinski3780e142015-05-14 15:08:13 -05002686 ASSERT_VK_SUCCESS(err);
2687
Karl Schultz6addd812016-02-02 17:17:23 -07002688 vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs);
Mark Lobodzinski3780e142015-05-14 15:08:13 -05002689
Mark Lobodzinski23065352015-05-29 09:32:35 -05002690 mem_alloc.allocationSize = mem_reqs.size;
Mark Lobodzinski3780e142015-05-14 15:08:13 -05002691
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002692 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 -07002693 if (!pass) { // If we can't find any unmappable memory this test doesn't
2694 // make sense
Chia-I Wuf7458c52015-10-26 21:10:41 +08002695 vkDestroyImage(m_device->device(), image, NULL);
Tony Barbour02fdc7d2015-08-04 16:13:01 -06002696 return;
Mike Stroyand1c84a52015-08-18 14:40:24 -06002697 }
Mike Stroyan713b2d72015-08-04 10:49:29 -06002698
Mark Lobodzinski3780e142015-05-14 15:08:13 -05002699 // allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002700 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem);
Mark Lobodzinski3780e142015-05-14 15:08:13 -05002701 ASSERT_VK_SUCCESS(err);
2702
2703 // Try to bind free memory that has been freed
Tony Barbour67e99152015-07-10 14:10:27 -06002704 err = vkBindImageMemory(m_device->device(), image, mem, 0);
Mark Lobodzinski3780e142015-05-14 15:08:13 -05002705 ASSERT_VK_SUCCESS(err);
2706
2707 // Map memory as if to initialize the image
2708 void *mappedAddress = NULL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002709 err = vkMapMemory(m_device->device(), mem, 0, VK_WHOLE_SIZE, 0, &mappedAddress);
Mark Lobodzinski3780e142015-05-14 15:08:13 -05002710
Chris Forbes8f36a8a2016-04-07 13:21:07 +12002711 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06002712
Chia-I Wuf7458c52015-10-26 21:10:41 +08002713 vkDestroyImage(m_device->device(), image, NULL);
Tony Barbourdf4c0042016-06-01 15:55:43 -06002714 vkFreeMemory(m_device->device(), mem, NULL);
Mark Lobodzinski3780e142015-05-14 15:08:13 -05002715}
2716
Karl Schultz6addd812016-02-02 17:17:23 -07002717TEST_F(VkLayerTest, RebindMemory) {
2718 VkResult err;
2719 bool pass;
Mark Lobodzinski944aab12015-06-05 13:59:04 -05002720
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002721 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "which has already been bound to mem object");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06002722
Mark Lobodzinski944aab12015-06-05 13:59:04 -05002723 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinski944aab12015-06-05 13:59:04 -05002724
2725 // Create an image, allocate memory, free it, and then try to bind it
Karl Schultz6addd812016-02-02 17:17:23 -07002726 VkImage image;
2727 VkDeviceMemory mem1;
2728 VkDeviceMemory mem2;
2729 VkMemoryRequirements mem_reqs;
Mark Lobodzinski944aab12015-06-05 13:59:04 -05002730
Karl Schultz6addd812016-02-02 17:17:23 -07002731 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
2732 const int32_t tex_width = 32;
2733 const int32_t tex_height = 32;
Mark Lobodzinski944aab12015-06-05 13:59:04 -05002734
Tony Barboureb254902015-07-15 12:50:33 -06002735 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -07002736 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
2737 image_create_info.pNext = NULL;
2738 image_create_info.imageType = VK_IMAGE_TYPE_2D;
2739 image_create_info.format = tex_format;
2740 image_create_info.extent.width = tex_width;
2741 image_create_info.extent.height = tex_height;
2742 image_create_info.extent.depth = 1;
2743 image_create_info.mipLevels = 1;
2744 image_create_info.arrayLayers = 1;
2745 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
2746 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
2747 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
2748 image_create_info.flags = 0;
Mark Lobodzinski944aab12015-06-05 13:59:04 -05002749
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002750 VkMemoryAllocateInfo mem_alloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -07002751 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
2752 mem_alloc.pNext = NULL;
2753 mem_alloc.allocationSize = 0;
2754 mem_alloc.memoryTypeIndex = 0;
Tony Barboureb254902015-07-15 12:50:33 -06002755
Karl Schultz6addd812016-02-02 17:17:23 -07002756 // Introduce failure, do NOT set memProps to
2757 // VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT
Tony Barboureb254902015-07-15 12:50:33 -06002758 mem_alloc.memoryTypeIndex = 1;
Chia-I Wuf7458c52015-10-26 21:10:41 +08002759 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
Mark Lobodzinski944aab12015-06-05 13:59:04 -05002760 ASSERT_VK_SUCCESS(err);
2761
Karl Schultz6addd812016-02-02 17:17:23 -07002762 vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs);
Mark Lobodzinski944aab12015-06-05 13:59:04 -05002763
2764 mem_alloc.allocationSize = mem_reqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002765 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -06002766 ASSERT_TRUE(pass);
Mark Lobodzinski944aab12015-06-05 13:59:04 -05002767
2768 // allocate 2 memory objects
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002769 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem1);
Mark Lobodzinski944aab12015-06-05 13:59:04 -05002770 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002771 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem2);
Mark Lobodzinski944aab12015-06-05 13:59:04 -05002772 ASSERT_VK_SUCCESS(err);
2773
2774 // Bind first memory object to Image object
Tony Barbour67e99152015-07-10 14:10:27 -06002775 err = vkBindImageMemory(m_device->device(), image, mem1, 0);
Mark Lobodzinski944aab12015-06-05 13:59:04 -05002776 ASSERT_VK_SUCCESS(err);
2777
Karl Schultz6addd812016-02-02 17:17:23 -07002778 // Introduce validation failure, try to bind a different memory object to
2779 // the same image object
Tony Barbour67e99152015-07-10 14:10:27 -06002780 err = vkBindImageMemory(m_device->device(), image, mem2, 0);
Mark Lobodzinski944aab12015-06-05 13:59:04 -05002781
Chris Forbes8f36a8a2016-04-07 13:21:07 +12002782 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06002783
Chia-I Wuf7458c52015-10-26 21:10:41 +08002784 vkDestroyImage(m_device->device(), image, NULL);
2785 vkFreeMemory(m_device->device(), mem1, NULL);
2786 vkFreeMemory(m_device->device(), mem2, NULL);
Mark Lobodzinski944aab12015-06-05 13:59:04 -05002787}
Mark Lobodzinski3780e142015-05-14 15:08:13 -05002788
Karl Schultz6addd812016-02-02 17:17:23 -07002789TEST_F(VkLayerTest, SubmitSignaledFence) {
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06002790 vk_testing::Fence testFence;
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06002791
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002792 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "submitted in SIGNALED state. Fences "
2793 "must be reset before being submitted");
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06002794
2795 VkFenceCreateInfo fenceInfo = {};
Tony Barbour0b4d9562015-04-09 10:48:04 -06002796 fenceInfo.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
2797 fenceInfo.pNext = NULL;
2798 fenceInfo.flags = VK_FENCE_CREATE_SIGNALED_BIT;
Tony Barbour300a6082015-04-07 13:44:53 -06002799
Tony Barbour300a6082015-04-07 13:44:53 -06002800 ASSERT_NO_FATAL_FAILURE(InitState());
2801 ASSERT_NO_FATAL_FAILURE(InitViewport());
2802 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
2803
Tony Barbourfe3351b2015-07-28 10:17:20 -06002804 BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002805 m_commandBuffer->ClearAllBuffers(m_clear_color, m_depth_clear_color, m_stencil_clear_color, NULL);
Tony Barbourfe3351b2015-07-28 10:17:20 -06002806 EndCommandBuffer();
Tony Barbour300a6082015-04-07 13:44:53 -06002807
2808 testFence.init(*m_device, fenceInfo);
Mark Lobodzinski5fcc4212015-09-14 17:43:42 -06002809
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06002810 VkSubmitInfo submit_info;
Chia-I Wuf9be13c2015-10-26 20:37:06 +08002811 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
2812 submit_info.pNext = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08002813 submit_info.waitSemaphoreCount = 0;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06002814 submit_info.pWaitSemaphores = NULL;
Jon Ashburn7f9716c2015-12-30 16:42:50 -07002815 submit_info.pWaitDstStageMask = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08002816 submit_info.commandBufferCount = 1;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002817 submit_info.pCommandBuffers = &m_commandBuffer->handle();
Chia-I Wud50a7d72015-10-26 20:48:51 +08002818 submit_info.signalSemaphoreCount = 0;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06002819 submit_info.pSignalSemaphores = NULL;
Courtney Goeltzenleuchter646b9072015-10-20 18:04:07 -06002820
2821 vkQueueSubmit(m_device->m_queue, 1, &submit_info, testFence.handle());
Karl Schultz6addd812016-02-02 17:17:23 -07002822 vkQueueWaitIdle(m_device->m_queue);
Mark Lobodzinski5fcc4212015-09-14 17:43:42 -06002823
Chris Forbes8f36a8a2016-04-07 13:21:07 +12002824 m_errorMonitor->VerifyFound();
Tony Barbour0b4d9562015-04-09 10:48:04 -06002825}
Tobin Ehlisaff7ae92016-04-18 15:45:20 -06002826// This is a positive test. We used to expect error in this case but spec now
2827// allows it
Karl Schultz6addd812016-02-02 17:17:23 -07002828TEST_F(VkLayerTest, ResetUnsignaledFence) {
Tobin Ehlisaff7ae92016-04-18 15:45:20 -06002829 m_errorMonitor->ExpectSuccess();
Tony Barbour0b4d9562015-04-09 10:48:04 -06002830 vk_testing::Fence testFence;
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06002831 VkFenceCreateInfo fenceInfo = {};
Tony Barbour0b4d9562015-04-09 10:48:04 -06002832 fenceInfo.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
2833 fenceInfo.pNext = NULL;
2834
Tony Barbour0b4d9562015-04-09 10:48:04 -06002835 ASSERT_NO_FATAL_FAILURE(InitState());
2836 testFence.init(*m_device, fenceInfo);
Chia-I Wud9e8e822015-07-03 11:45:55 +08002837 VkFence fences[1] = {testFence.handle()};
Tobin Ehlisaff7ae92016-04-18 15:45:20 -06002838 VkResult result = vkResetFences(m_device->device(), 1, fences);
2839 ASSERT_VK_SUCCESS(result);
Tony Barbour300a6082015-04-07 13:44:53 -06002840
Tobin Ehlisaff7ae92016-04-18 15:45:20 -06002841 m_errorMonitor->VerifyNotFound();
Tony Barbour300a6082015-04-07 13:44:53 -06002842}
Tobin Ehlis56ab9022016-08-17 17:59:31 -06002843#if 0 // A few devices have issues with this test so disabling for now
Chris Forbese70b7d32016-06-15 15:49:12 +12002844TEST_F(VkLayerTest, LongFenceChain)
2845{
2846 m_errorMonitor->ExpectSuccess();
2847
2848 ASSERT_NO_FATAL_FAILURE(InitState());
2849 VkResult err;
2850
2851 std::vector<VkFence> fences;
2852
2853 const int chainLength = 32768;
2854
2855 for (int i = 0; i < chainLength; i++) {
2856 VkFenceCreateInfo fci = { VK_STRUCTURE_TYPE_FENCE_CREATE_INFO, nullptr, 0 };
2857 VkFence fence;
2858 err = vkCreateFence(m_device->device(), &fci, nullptr, &fence);
2859 ASSERT_VK_SUCCESS(err);
2860
2861 fences.push_back(fence);
2862
2863 VkSubmitInfo si = { VK_STRUCTURE_TYPE_SUBMIT_INFO, nullptr, 0, nullptr, nullptr,
2864 0, nullptr, 0, nullptr };
2865 err = vkQueueSubmit(m_device->m_queue, 1, &si, fence);
2866 ASSERT_VK_SUCCESS(err);
2867
2868 }
2869
2870 // BOOM, stack overflow.
2871 vkWaitForFences(m_device->device(), 1, &fences.back(), VK_TRUE, UINT64_MAX);
2872
2873 for (auto fence : fences)
2874 vkDestroyFence(m_device->device(), fence, nullptr);
2875
2876 m_errorMonitor->VerifyNotFound();
2877}
Tobin Ehlis56ab9022016-08-17 17:59:31 -06002878#endif
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002879TEST_F(VkLayerTest, CommandBufferSimultaneousUseSync) {
Chris Forbes18127d12016-06-08 16:52:28 +12002880 m_errorMonitor->ExpectSuccess();
2881
2882 ASSERT_NO_FATAL_FAILURE(InitState());
2883 VkResult err;
2884
2885 // Record (empty!) command buffer that can be submitted multiple times
2886 // simultaneously.
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002887 VkCommandBufferBeginInfo cbbi = {VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO, nullptr,
2888 VK_COMMAND_BUFFER_USAGE_SIMULTANEOUS_USE_BIT, nullptr};
Chris Forbes18127d12016-06-08 16:52:28 +12002889 m_commandBuffer->BeginCommandBuffer(&cbbi);
2890 m_commandBuffer->EndCommandBuffer();
2891
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002892 VkFenceCreateInfo fci = {VK_STRUCTURE_TYPE_FENCE_CREATE_INFO, nullptr, 0};
Chris Forbes18127d12016-06-08 16:52:28 +12002893 VkFence fence;
2894 err = vkCreateFence(m_device->device(), &fci, nullptr, &fence);
2895 ASSERT_VK_SUCCESS(err);
2896
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002897 VkSemaphoreCreateInfo sci = {VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO, nullptr, 0};
Chris Forbes18127d12016-06-08 16:52:28 +12002898 VkSemaphore s1, s2;
2899 err = vkCreateSemaphore(m_device->device(), &sci, nullptr, &s1);
2900 ASSERT_VK_SUCCESS(err);
2901 err = vkCreateSemaphore(m_device->device(), &sci, nullptr, &s2);
2902 ASSERT_VK_SUCCESS(err);
2903
2904 // Submit CB once signaling s1, with fence so we can roll forward to its retirement.
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002905 VkSubmitInfo si = {VK_STRUCTURE_TYPE_SUBMIT_INFO, nullptr, 0, nullptr, nullptr, 1, &m_commandBuffer->handle(), 1, &s1};
Chris Forbes18127d12016-06-08 16:52:28 +12002906 err = vkQueueSubmit(m_device->m_queue, 1, &si, fence);
2907 ASSERT_VK_SUCCESS(err);
2908
2909 // Submit CB again, signaling s2.
2910 si.pSignalSemaphores = &s2;
2911 err = vkQueueSubmit(m_device->m_queue, 1, &si, VK_NULL_HANDLE);
2912 ASSERT_VK_SUCCESS(err);
2913
2914 // Wait for fence.
2915 err = vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
2916 ASSERT_VK_SUCCESS(err);
2917
2918 // CB is still in flight from second submission, but semaphore s1 is no
2919 // longer in flight. delete it.
2920 vkDestroySemaphore(m_device->device(), s1, nullptr);
2921
2922 m_errorMonitor->VerifyNotFound();
2923
2924 // Force device idle and clean up remaining objects
2925 vkDeviceWaitIdle(m_device->device());
2926 vkDestroySemaphore(m_device->device(), s2, nullptr);
2927 vkDestroyFence(m_device->device(), fence, nullptr);
2928}
2929
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002930TEST_F(VkLayerTest, FenceCreateSignaledWaitHandling) {
Chris Forbes4e44c912016-06-16 10:20:00 +12002931 m_errorMonitor->ExpectSuccess();
2932
2933 ASSERT_NO_FATAL_FAILURE(InitState());
2934 VkResult err;
2935
2936 // A fence created signaled
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002937 VkFenceCreateInfo fci1 = {VK_STRUCTURE_TYPE_FENCE_CREATE_INFO, nullptr, VK_FENCE_CREATE_SIGNALED_BIT};
Chris Forbes4e44c912016-06-16 10:20:00 +12002938 VkFence f1;
2939 err = vkCreateFence(m_device->device(), &fci1, nullptr, &f1);
2940 ASSERT_VK_SUCCESS(err);
2941
2942 // A fence created not
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002943 VkFenceCreateInfo fci2 = {VK_STRUCTURE_TYPE_FENCE_CREATE_INFO, nullptr, 0};
Chris Forbes4e44c912016-06-16 10:20:00 +12002944 VkFence f2;
2945 err = vkCreateFence(m_device->device(), &fci2, nullptr, &f2);
2946 ASSERT_VK_SUCCESS(err);
2947
2948 // Submit the unsignaled fence
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002949 VkSubmitInfo si = {VK_STRUCTURE_TYPE_SUBMIT_INFO, nullptr, 0, nullptr, nullptr, 0, nullptr, 0, nullptr};
Chris Forbes4e44c912016-06-16 10:20:00 +12002950 err = vkQueueSubmit(m_device->m_queue, 1, &si, f2);
2951
2952 // Wait on both fences, with signaled first.
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002953 VkFence fences[] = {f1, f2};
Chris Forbes4e44c912016-06-16 10:20:00 +12002954 vkWaitForFences(m_device->device(), 2, fences, VK_TRUE, UINT64_MAX);
2955
2956 // Should have both retired!
2957 vkDestroyFence(m_device->device(), f1, nullptr);
2958 vkDestroyFence(m_device->device(), f2, nullptr);
2959
2960 m_errorMonitor->VerifyNotFound();
2961}
2962
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002963TEST_F(VkLayerTest, InvalidUsageBits) {
2964 TEST_DESCRIPTION("Specify wrong usage for image then create conflicting view of image "
2965 "Initialize buffer with wrong usage then perform copy expecting errors "
2966 "from both the image and the buffer (2 calls)");
2967 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Invalid usage flag for image ");
Tobin Ehlis41376e12015-07-03 08:45:14 -06002968
2969 ASSERT_NO_FATAL_FAILURE(InitState());
Tony Barbourf92621a2016-05-02 14:28:12 -06002970 VkImageObj image(m_device);
Tony Barbour75d79f02016-08-30 09:39:07 -06002971 // Initialize image with USAGE_TRANSIENT_ATTACHMENT
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002972 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 -06002973 ASSERT_TRUE(image.initialized());
Tobin Ehlis41376e12015-07-03 08:45:14 -06002974
Tony Barbourf92621a2016-05-02 14:28:12 -06002975 VkImageView dsv;
2976 VkImageViewCreateInfo dsvci = {};
2977 dsvci.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
2978 dsvci.image = image.handle();
2979 dsvci.viewType = VK_IMAGE_VIEW_TYPE_2D;
2980 dsvci.format = VK_FORMAT_D32_SFLOAT_S8_UINT;
2981 dsvci.subresourceRange.layerCount = 1;
2982 dsvci.subresourceRange.baseMipLevel = 0;
2983 dsvci.subresourceRange.levelCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002984 dsvci.subresourceRange.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT;
Tobin Ehlis41376e12015-07-03 08:45:14 -06002985
Tony Barbourf92621a2016-05-02 14:28:12 -06002986 // Create a view with depth / stencil aspect for image with different usage
2987 vkCreateImageView(m_device->device(), &dsvci, NULL, &dsv);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06002988
Chris Forbes8f36a8a2016-04-07 13:21:07 +12002989 m_errorMonitor->VerifyFound();
Tony Barbourf92621a2016-05-02 14:28:12 -06002990
2991 // Initialize buffer with TRANSFER_DST usage
2992 vk_testing::Buffer buffer;
2993 VkMemoryPropertyFlags reqs = 0;
2994 buffer.init_as_dst(*m_device, 128 * 128, reqs);
2995 VkBufferImageCopy region = {};
2996 region.bufferRowLength = 128;
2997 region.bufferImageHeight = 128;
2998 region.imageSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
2999 region.imageSubresource.layerCount = 1;
3000 region.imageExtent.height = 16;
3001 region.imageExtent.width = 16;
3002 region.imageExtent.depth = 1;
3003
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003004 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Invalid usage flag for buffer ");
Tony Barbourf92621a2016-05-02 14:28:12 -06003005 // Buffer usage not set to TRANSFER_SRC and image usage not set to
3006 // TRANSFER_DST
3007 BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003008 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer.handle(), image.handle(),
3009 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, &region);
Tony Barbourf92621a2016-05-02 14:28:12 -06003010 m_errorMonitor->VerifyFound();
3011
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003012 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Invalid usage flag for image ");
3013 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer.handle(), image.handle(),
3014 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, &region);
Tony Barbourf92621a2016-05-02 14:28:12 -06003015 m_errorMonitor->VerifyFound();
Tobin Ehlis41376e12015-07-03 08:45:14 -06003016}
Tony Barbour75d79f02016-08-30 09:39:07 -06003017
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003018TEST_F(VkLayerTest, ValidUsage) {
3019 TEST_DESCRIPTION("Verify that creating an image view from an image with valid usage "
3020 "doesn't generate validation errors");
Tony Barbour75d79f02016-08-30 09:39:07 -06003021
3022 ASSERT_NO_FATAL_FAILURE(InitState());
3023
3024 m_errorMonitor->ExpectSuccess();
3025 // Verify that we can create a view with usage INPUT_ATTACHMENT
3026 VkImageObj image(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003027 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 -06003028 ASSERT_TRUE(image.initialized());
3029 VkImageView imageView;
3030 VkImageViewCreateInfo ivci = {};
3031 ivci.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
3032 ivci.image = image.handle();
3033 ivci.viewType = VK_IMAGE_VIEW_TYPE_2D;
3034 ivci.format = VK_FORMAT_R8G8B8A8_UNORM;
3035 ivci.subresourceRange.layerCount = 1;
3036 ivci.subresourceRange.baseMipLevel = 0;
3037 ivci.subresourceRange.levelCount = 1;
3038 ivci.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
3039
3040 vkCreateImageView(m_device->device(), &ivci, NULL, &imageView);
3041 m_errorMonitor->VerifyNotFound();
3042 vkDestroyImageView(m_device->device(), imageView, NULL);
3043}
Mark Lobodzinski209b5292015-09-17 09:44:05 -06003044#endif // MEM_TRACKER_TESTS
3045
Tobin Ehlis4bf96d12015-06-25 11:58:41 -06003046#if OBJ_TRACKER_TESTS
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06003047
3048TEST_F(VkLayerTest, LeakAnObject) {
3049 VkResult err;
3050
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003051 TEST_DESCRIPTION("Create a fence and destroy its device without first destroying the fence.");
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06003052
3053 // Note that we have to create a new device since destroying the
3054 // framework's device causes Teardown() to fail and just calling Teardown
3055 // will destroy the errorMonitor.
3056
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003057 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "has not been destroyed.");
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06003058
3059 ASSERT_NO_FATAL_FAILURE(InitState());
3060
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003061 const std::vector<VkQueueFamilyProperties> queue_props = m_device->queue_props;
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06003062 std::vector<VkDeviceQueueCreateInfo> queue_info;
3063 queue_info.reserve(queue_props.size());
3064 std::vector<std::vector<float>> queue_priorities;
3065 for (uint32_t i = 0; i < (uint32_t)queue_props.size(); i++) {
3066 VkDeviceQueueCreateInfo qi = {};
3067 qi.sType = VK_STRUCTURE_TYPE_DEVICE_QUEUE_CREATE_INFO;
3068 qi.pNext = NULL;
3069 qi.queueFamilyIndex = i;
3070 qi.queueCount = queue_props[i].queueCount;
3071 queue_priorities.emplace_back(qi.queueCount, 0.0f);
3072 qi.pQueuePriorities = queue_priorities[i].data();
3073 queue_info.push_back(qi);
3074 }
3075
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06003076 std::vector<const char *> device_extension_names;
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06003077
3078 // The sacrificial device object
3079 VkDevice testDevice;
3080 VkDeviceCreateInfo device_create_info = {};
3081 auto features = m_device->phy().features();
3082 device_create_info.sType = VK_STRUCTURE_TYPE_DEVICE_CREATE_INFO;
3083 device_create_info.pNext = NULL;
3084 device_create_info.queueCreateInfoCount = queue_info.size();
3085 device_create_info.pQueueCreateInfos = queue_info.data();
Tony Barbour4c70d102016-08-08 16:06:56 -06003086 device_create_info.enabledLayerCount = 0;
3087 device_create_info.ppEnabledLayerNames = NULL;
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06003088 device_create_info.pEnabledFeatures = &features;
3089 err = vkCreateDevice(gpu(), &device_create_info, NULL, &testDevice);
3090 ASSERT_VK_SUCCESS(err);
3091
3092 VkFence fence;
3093 VkFenceCreateInfo fence_create_info = {};
3094 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
3095 fence_create_info.pNext = NULL;
3096 fence_create_info.flags = 0;
3097 err = vkCreateFence(testDevice, &fence_create_info, NULL, &fence);
3098 ASSERT_VK_SUCCESS(err);
3099
3100 // Induce failure by not calling vkDestroyFence
3101 vkDestroyDevice(testDevice, NULL);
3102 m_errorMonitor->VerifyFound();
3103}
3104
3105TEST_F(VkLayerTest, InvalidCommandPoolConsistency) {
3106
3107 TEST_DESCRIPTION("Allocate command buffers from one command pool and "
3108 "attempt to delete them from another.");
3109
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003110 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "FreeCommandBuffers is attempting to free Command Buffer");
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06003111
Cody Northropc31a84f2016-08-22 10:41:47 -06003112 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06003113 VkCommandPool command_pool_one;
3114 VkCommandPool command_pool_two;
3115
3116 VkCommandPoolCreateInfo pool_create_info{};
3117 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
3118 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
3119 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
3120
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003121 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool_one);
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06003122
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003123 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool_two);
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06003124
3125 VkCommandBuffer command_buffer[9];
3126 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003127 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06003128 command_buffer_allocate_info.commandPool = command_pool_one;
3129 command_buffer_allocate_info.commandBufferCount = 9;
3130 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003131 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, command_buffer);
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06003132
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003133 vkFreeCommandBuffers(m_device->device(), command_pool_two, 4, &command_buffer[3]);
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06003134
3135 m_errorMonitor->VerifyFound();
3136
3137 vkDestroyCommandPool(m_device->device(), command_pool_one, NULL);
3138 vkDestroyCommandPool(m_device->device(), command_pool_two, NULL);
3139}
3140
3141TEST_F(VkLayerTest, InvalidDescriptorPoolConsistency) {
3142 VkResult err;
3143
3144 TEST_DESCRIPTION("Allocate descriptor sets from one DS pool and "
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003145 "attempt to delete them from another.");
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06003146
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003147 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "FreeDescriptorSets is attempting to free descriptorSet");
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06003148
3149 ASSERT_NO_FATAL_FAILURE(InitState());
3150 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
3151
3152 VkDescriptorPoolSize ds_type_count = {};
3153 ds_type_count.type = VK_DESCRIPTOR_TYPE_SAMPLER;
3154 ds_type_count.descriptorCount = 1;
3155
3156 VkDescriptorPoolCreateInfo ds_pool_ci = {};
3157 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
3158 ds_pool_ci.pNext = NULL;
3159 ds_pool_ci.flags = 0;
3160 ds_pool_ci.maxSets = 1;
3161 ds_pool_ci.poolSizeCount = 1;
3162 ds_pool_ci.pPoolSizes = &ds_type_count;
3163
3164 VkDescriptorPool ds_pool_one;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003165 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool_one);
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06003166 ASSERT_VK_SUCCESS(err);
3167
3168 // Create a second descriptor pool
3169 VkDescriptorPool ds_pool_two;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003170 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool_two);
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06003171 ASSERT_VK_SUCCESS(err);
3172
3173 VkDescriptorSetLayoutBinding dsl_binding = {};
3174 dsl_binding.binding = 0;
3175 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
3176 dsl_binding.descriptorCount = 1;
3177 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
3178 dsl_binding.pImmutableSamplers = NULL;
3179
3180 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
3181 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
3182 ds_layout_ci.pNext = NULL;
3183 ds_layout_ci.bindingCount = 1;
3184 ds_layout_ci.pBindings = &dsl_binding;
3185
3186 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003187 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06003188 ASSERT_VK_SUCCESS(err);
3189
3190 VkDescriptorSet descriptorSet;
3191 VkDescriptorSetAllocateInfo alloc_info = {};
3192 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
3193 alloc_info.descriptorSetCount = 1;
3194 alloc_info.descriptorPool = ds_pool_one;
3195 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003196 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06003197 ASSERT_VK_SUCCESS(err);
3198
3199 err = vkFreeDescriptorSets(m_device->device(), ds_pool_two, 1, &descriptorSet);
3200
3201 m_errorMonitor->VerifyFound();
3202
3203 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
3204 vkDestroyDescriptorPool(m_device->device(), ds_pool_one, NULL);
3205 vkDestroyDescriptorPool(m_device->device(), ds_pool_two, NULL);
3206}
3207
3208TEST_F(VkLayerTest, CreateUnknownObject) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003209 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Invalid Image Object ");
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06003210
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003211 TEST_DESCRIPTION("Pass an invalid image object handle into a Vulkan API call.");
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06003212
3213 ASSERT_NO_FATAL_FAILURE(InitState());
3214
3215 // Pass bogus handle into GetImageMemoryRequirements
3216 VkMemoryRequirements mem_reqs;
3217 uint64_t fakeImageHandle = 0xCADECADE;
3218 VkImage fauxImage = reinterpret_cast<VkImage &>(fakeImageHandle);
3219
3220 vkGetImageMemoryRequirements(m_device->device(), fauxImage, &mem_reqs);
3221
3222 m_errorMonitor->VerifyFound();
3223}
3224
Karl Schultz6addd812016-02-02 17:17:23 -07003225TEST_F(VkLayerTest, PipelineNotBound) {
3226 VkResult err;
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06003227
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003228 TEST_DESCRIPTION("Pass in an invalid pipeline object handle into a Vulkan API call.");
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06003229
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003230 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Invalid Pipeline Object ");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06003231
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06003232 ASSERT_NO_FATAL_FAILURE(InitState());
3233 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06003234
Chia-I Wu1b99bb22015-10-27 19:25:11 +08003235 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07003236 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
3237 ds_type_count.descriptorCount = 1;
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06003238
3239 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07003240 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
3241 ds_pool_ci.pNext = NULL;
3242 ds_pool_ci.maxSets = 1;
3243 ds_pool_ci.poolSizeCount = 1;
3244 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06003245
3246 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003247 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06003248 ASSERT_VK_SUCCESS(err);
3249
3250 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07003251 dsl_binding.binding = 0;
3252 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
3253 dsl_binding.descriptorCount = 1;
3254 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
3255 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06003256
3257 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07003258 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
3259 ds_layout_ci.pNext = NULL;
3260 ds_layout_ci.bindingCount = 1;
3261 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06003262
3263 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003264 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06003265 ASSERT_VK_SUCCESS(err);
3266
3267 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08003268 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08003269 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07003270 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06003271 alloc_info.descriptorPool = ds_pool;
3272 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003273 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06003274 ASSERT_VK_SUCCESS(err);
3275
3276 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07003277 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
3278 pipeline_layout_ci.pNext = NULL;
3279 pipeline_layout_ci.setLayoutCount = 1;
3280 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06003281
3282 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003283 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06003284 ASSERT_VK_SUCCESS(err);
3285
Mark Youngad779052016-01-06 14:26:04 -07003286 VkPipeline badPipeline = (VkPipeline)((size_t)0xbaadb1be);
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06003287
3288 BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003289 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, badPipeline);
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06003290
Chris Forbes8f36a8a2016-04-07 13:21:07 +12003291 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06003292
Chia-I Wuf7458c52015-10-26 21:10:41 +08003293 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
3294 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
3295 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlisec598302015-09-15 15:02:17 -06003296}
Mike Stroyan80fc6c32016-06-20 15:42:29 -06003297
Mark Lobodzinskibc185762016-06-15 16:28:53 -06003298TEST_F(VkLayerTest, BindImageInvalidMemoryType) {
3299 VkResult err;
3300
3301 TEST_DESCRIPTION("Test validation check for an invalid memory type index "
3302 "during bind[Buffer|Image]Memory time");
3303
Mark Lobodzinskibc185762016-06-15 16:28:53 -06003304 ASSERT_NO_FATAL_FAILURE(InitState());
3305
3306 // Create an image, allocate memory, set a bad typeIndex and then try to
3307 // bind it
3308 VkImage image;
3309 VkDeviceMemory mem;
3310 VkMemoryRequirements mem_reqs;
3311 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
3312 const int32_t tex_width = 32;
3313 const int32_t tex_height = 32;
3314
3315 VkImageCreateInfo image_create_info = {};
3316 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
3317 image_create_info.pNext = NULL;
3318 image_create_info.imageType = VK_IMAGE_TYPE_2D;
3319 image_create_info.format = tex_format;
3320 image_create_info.extent.width = tex_width;
3321 image_create_info.extent.height = tex_height;
3322 image_create_info.extent.depth = 1;
3323 image_create_info.mipLevels = 1;
3324 image_create_info.arrayLayers = 1;
3325 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
3326 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
3327 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
3328 image_create_info.flags = 0;
3329
3330 VkMemoryAllocateInfo mem_alloc = {};
3331 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
3332 mem_alloc.pNext = NULL;
3333 mem_alloc.allocationSize = 0;
3334 mem_alloc.memoryTypeIndex = 0;
3335
3336 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
3337 ASSERT_VK_SUCCESS(err);
3338
3339 vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs);
3340 mem_alloc.allocationSize = mem_reqs.size;
Mike Stroyan80fc6c32016-06-20 15:42:29 -06003341
3342 // Introduce Failure, select invalid TypeIndex
3343 VkPhysicalDeviceMemoryProperties memory_info;
3344
3345 vkGetPhysicalDeviceMemoryProperties(gpu(), &memory_info);
3346 unsigned int i;
3347 for (i = 0; i < memory_info.memoryTypeCount; i++) {
3348 if ((mem_reqs.memoryTypeBits & (1 << i)) == 0) {
3349 mem_alloc.memoryTypeIndex = i;
3350 break;
3351 }
3352 }
3353 if (i >= memory_info.memoryTypeCount) {
3354 printf("No invalid memory type index could be found; skipped.\n");
3355 vkDestroyImage(m_device->device(), image, NULL);
3356 return;
3357 }
3358
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003359 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 -06003360
3361 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem);
3362 ASSERT_VK_SUCCESS(err);
3363
3364 err = vkBindImageMemory(m_device->device(), image, mem, 0);
3365 (void)err;
3366
3367 m_errorMonitor->VerifyFound();
3368
3369 vkDestroyImage(m_device->device(), image, NULL);
3370 vkFreeMemory(m_device->device(), mem, NULL);
3371}
Mike Stroyan80fc6c32016-06-20 15:42:29 -06003372
Karl Schultz6addd812016-02-02 17:17:23 -07003373TEST_F(VkLayerTest, BindInvalidMemory) {
3374 VkResult err;
3375 bool pass;
Tobin Ehlisec598302015-09-15 15:02:17 -06003376
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003377 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Invalid Device Memory Object ");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06003378
Tobin Ehlisec598302015-09-15 15:02:17 -06003379 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisec598302015-09-15 15:02:17 -06003380
3381 // Create an image, allocate memory, free it, and then try to bind it
Karl Schultz6addd812016-02-02 17:17:23 -07003382 VkImage image;
3383 VkDeviceMemory mem;
3384 VkMemoryRequirements mem_reqs;
Tobin Ehlisec598302015-09-15 15:02:17 -06003385
Karl Schultz6addd812016-02-02 17:17:23 -07003386 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
3387 const int32_t tex_width = 32;
3388 const int32_t tex_height = 32;
Tobin Ehlisec598302015-09-15 15:02:17 -06003389
3390 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -07003391 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
3392 image_create_info.pNext = NULL;
3393 image_create_info.imageType = VK_IMAGE_TYPE_2D;
3394 image_create_info.format = tex_format;
3395 image_create_info.extent.width = tex_width;
3396 image_create_info.extent.height = tex_height;
3397 image_create_info.extent.depth = 1;
3398 image_create_info.mipLevels = 1;
3399 image_create_info.arrayLayers = 1;
3400 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
3401 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
3402 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
3403 image_create_info.flags = 0;
Tobin Ehlisec598302015-09-15 15:02:17 -06003404
Chia-I Wu3432a0c2015-10-27 18:04:07 +08003405 VkMemoryAllocateInfo mem_alloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -07003406 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
3407 mem_alloc.pNext = NULL;
3408 mem_alloc.allocationSize = 0;
3409 mem_alloc.memoryTypeIndex = 0;
Tobin Ehlisec598302015-09-15 15:02:17 -06003410
Chia-I Wuf7458c52015-10-26 21:10:41 +08003411 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
Tobin Ehlisec598302015-09-15 15:02:17 -06003412 ASSERT_VK_SUCCESS(err);
3413
Karl Schultz6addd812016-02-02 17:17:23 -07003414 vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs);
Tobin Ehlisec598302015-09-15 15:02:17 -06003415
3416 mem_alloc.allocationSize = mem_reqs.size;
3417
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003418 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -06003419 ASSERT_TRUE(pass);
Tobin Ehlisec598302015-09-15 15:02:17 -06003420
3421 // allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +08003422 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem);
Tobin Ehlisec598302015-09-15 15:02:17 -06003423 ASSERT_VK_SUCCESS(err);
3424
3425 // Introduce validation failure, free memory before binding
Chia-I Wuf7458c52015-10-26 21:10:41 +08003426 vkFreeMemory(m_device->device(), mem, NULL);
Tobin Ehlisec598302015-09-15 15:02:17 -06003427
3428 // Try to bind free memory that has been freed
3429 err = vkBindImageMemory(m_device->device(), image, mem, 0);
3430 // This may very well return an error.
3431 (void)err;
3432
Chris Forbes8f36a8a2016-04-07 13:21:07 +12003433 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06003434
Chia-I Wuf7458c52015-10-26 21:10:41 +08003435 vkDestroyImage(m_device->device(), image, NULL);
Tobin Ehlisec598302015-09-15 15:02:17 -06003436}
3437
Karl Schultz6addd812016-02-02 17:17:23 -07003438TEST_F(VkLayerTest, BindMemoryToDestroyedObject) {
3439 VkResult err;
3440 bool pass;
Tobin Ehlisec598302015-09-15 15:02:17 -06003441
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003442 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Invalid Image Object ");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06003443
Tobin Ehlisec598302015-09-15 15:02:17 -06003444 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisec598302015-09-15 15:02:17 -06003445
Karl Schultz6addd812016-02-02 17:17:23 -07003446 // Create an image object, allocate memory, destroy the object and then try
3447 // to bind it
3448 VkImage image;
3449 VkDeviceMemory mem;
3450 VkMemoryRequirements mem_reqs;
Tobin Ehlisec598302015-09-15 15:02:17 -06003451
Karl Schultz6addd812016-02-02 17:17:23 -07003452 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
3453 const int32_t tex_width = 32;
3454 const int32_t tex_height = 32;
Tobin Ehlisec598302015-09-15 15:02:17 -06003455
3456 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -07003457 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
3458 image_create_info.pNext = NULL;
3459 image_create_info.imageType = VK_IMAGE_TYPE_2D;
3460 image_create_info.format = tex_format;
3461 image_create_info.extent.width = tex_width;
3462 image_create_info.extent.height = tex_height;
3463 image_create_info.extent.depth = 1;
3464 image_create_info.mipLevels = 1;
3465 image_create_info.arrayLayers = 1;
3466 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
3467 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
3468 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
3469 image_create_info.flags = 0;
Tobin Ehlisec598302015-09-15 15:02:17 -06003470
Chia-I Wu3432a0c2015-10-27 18:04:07 +08003471 VkMemoryAllocateInfo mem_alloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -07003472 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
3473 mem_alloc.pNext = NULL;
3474 mem_alloc.allocationSize = 0;
3475 mem_alloc.memoryTypeIndex = 0;
Tobin Ehlisec598302015-09-15 15:02:17 -06003476
Chia-I Wuf7458c52015-10-26 21:10:41 +08003477 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
Tobin Ehlisec598302015-09-15 15:02:17 -06003478 ASSERT_VK_SUCCESS(err);
3479
Karl Schultz6addd812016-02-02 17:17:23 -07003480 vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs);
Tobin Ehlisec598302015-09-15 15:02:17 -06003481
3482 mem_alloc.allocationSize = mem_reqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003483 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -06003484 ASSERT_TRUE(pass);
Tobin Ehlisec598302015-09-15 15:02:17 -06003485
3486 // Allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +08003487 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem);
Tobin Ehlisec598302015-09-15 15:02:17 -06003488 ASSERT_VK_SUCCESS(err);
3489
3490 // Introduce validation failure, destroy Image object before binding
Chia-I Wuf7458c52015-10-26 21:10:41 +08003491 vkDestroyImage(m_device->device(), image, NULL);
Tobin Ehlisec598302015-09-15 15:02:17 -06003492 ASSERT_VK_SUCCESS(err);
3493
3494 // Now Try to bind memory to this destroyed object
3495 err = vkBindImageMemory(m_device->device(), image, mem, 0);
3496 // This may very well return an error.
Karl Schultz6addd812016-02-02 17:17:23 -07003497 (void)err;
Tobin Ehlisec598302015-09-15 15:02:17 -06003498
Chris Forbes8f36a8a2016-04-07 13:21:07 +12003499 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06003500
Chia-I Wuf7458c52015-10-26 21:10:41 +08003501 vkFreeMemory(m_device->device(), mem, NULL);
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06003502}
Tobin Ehlisa1c28562015-10-23 16:00:08 -06003503
Mark Lobodzinski209b5292015-09-17 09:44:05 -06003504#endif // OBJ_TRACKER_TESTS
3505
Tobin Ehlis0788f522015-05-26 16:11:58 -06003506#if DRAW_STATE_TESTS
Mark Lobodzinskic808d442016-04-14 10:57:23 -06003507
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06003508TEST_F(VkLayerTest, ImageSampleCounts) {
3509
3510 TEST_DESCRIPTION("Use bad sample counts in image transfer calls to trigger "
3511 "validation errors.");
3512 ASSERT_NO_FATAL_FAILURE(InitState());
3513
3514 VkMemoryPropertyFlags reqs = 0;
3515 VkImageCreateInfo image_create_info = {};
3516 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
3517 image_create_info.pNext = NULL;
3518 image_create_info.imageType = VK_IMAGE_TYPE_2D;
3519 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
3520 image_create_info.extent.width = 256;
3521 image_create_info.extent.height = 256;
3522 image_create_info.extent.depth = 1;
3523 image_create_info.mipLevels = 1;
3524 image_create_info.arrayLayers = 1;
3525 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
3526 image_create_info.flags = 0;
3527
3528 VkImageBlit blit_region = {};
3529 blit_region.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
3530 blit_region.srcSubresource.baseArrayLayer = 0;
3531 blit_region.srcSubresource.layerCount = 1;
3532 blit_region.srcSubresource.mipLevel = 0;
3533 blit_region.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
3534 blit_region.dstSubresource.baseArrayLayer = 0;
3535 blit_region.dstSubresource.layerCount = 1;
3536 blit_region.dstSubresource.mipLevel = 0;
3537
3538 // Create two images, the source with sampleCount = 2, and attempt to blit
3539 // between them
3540 {
3541 image_create_info.samples = VK_SAMPLE_COUNT_2_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003542 image_create_info.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06003543 vk_testing::Image src_image;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003544 src_image.init(*m_device, (const VkImageCreateInfo &)image_create_info, reqs);
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06003545 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003546 image_create_info.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT;
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06003547 vk_testing::Image dst_image;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003548 dst_image.init(*m_device, (const VkImageCreateInfo &)image_create_info, reqs);
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06003549 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003550 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "was created with a sample count "
3551 "of VK_SAMPLE_COUNT_2_BIT but "
3552 "must be VK_SAMPLE_COUNT_1_BIT");
3553 vkCmdBlitImage(m_commandBuffer->GetBufferHandle(), src_image.handle(), VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
3554 dst_image.handle(), VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL, 1, &blit_region, VK_FILTER_NEAREST);
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06003555 m_errorMonitor->VerifyFound();
3556 m_commandBuffer->EndCommandBuffer();
3557 }
3558
3559 // Create two images, the dest with sampleCount = 4, and attempt to blit
3560 // between them
3561 {
3562 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003563 image_create_info.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06003564 vk_testing::Image src_image;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003565 src_image.init(*m_device, (const VkImageCreateInfo &)image_create_info, reqs);
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06003566 image_create_info.samples = VK_SAMPLE_COUNT_4_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003567 image_create_info.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT;
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06003568 vk_testing::Image dst_image;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003569 dst_image.init(*m_device, (const VkImageCreateInfo &)image_create_info, reqs);
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06003570 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003571 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "was created with a sample count "
3572 "of VK_SAMPLE_COUNT_4_BIT but "
3573 "must be VK_SAMPLE_COUNT_1_BIT");
3574 vkCmdBlitImage(m_commandBuffer->GetBufferHandle(), src_image.handle(), VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
3575 dst_image.handle(), VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL, 1, &blit_region, VK_FILTER_NEAREST);
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06003576 m_errorMonitor->VerifyFound();
3577 m_commandBuffer->EndCommandBuffer();
3578 }
3579
3580 VkBufferImageCopy copy_region = {};
3581 copy_region.bufferRowLength = 128;
3582 copy_region.bufferImageHeight = 128;
3583 copy_region.imageSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
3584 copy_region.imageSubresource.layerCount = 1;
3585 copy_region.imageExtent.height = 64;
3586 copy_region.imageExtent.width = 64;
3587 copy_region.imageExtent.depth = 1;
3588
3589 // Create src buffer and dst image with sampleCount = 4 and attempt to copy
3590 // buffer to image
3591 {
3592 vk_testing::Buffer src_buffer;
3593 VkMemoryPropertyFlags reqs = 0;
3594 src_buffer.init_as_src(*m_device, 128 * 128 * 4, reqs);
3595 image_create_info.samples = VK_SAMPLE_COUNT_8_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003596 image_create_info.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT;
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06003597 vk_testing::Image dst_image;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003598 dst_image.init(*m_device, (const VkImageCreateInfo &)image_create_info, reqs);
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06003599 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003600 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "was created with a sample count "
3601 "of VK_SAMPLE_COUNT_8_BIT but "
3602 "must be VK_SAMPLE_COUNT_1_BIT");
3603 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), src_buffer.handle(), dst_image.handle(),
3604 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, &copy_region);
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06003605 m_errorMonitor->VerifyFound();
3606 m_commandBuffer->EndCommandBuffer();
3607 }
3608
3609 // Create dst buffer and src image with sampleCount = 2 and attempt to copy
3610 // image to buffer
3611 {
3612 vk_testing::Buffer dst_buffer;
3613 dst_buffer.init_as_dst(*m_device, 128 * 128 * 4, reqs);
3614 image_create_info.samples = VK_SAMPLE_COUNT_2_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003615 image_create_info.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06003616 vk_testing::Image src_image;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003617 src_image.init(*m_device, (const VkImageCreateInfo &)image_create_info, reqs);
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06003618 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003619 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "was created with a sample count "
3620 "of VK_SAMPLE_COUNT_2_BIT but "
3621 "must be VK_SAMPLE_COUNT_1_BIT");
3622 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), src_image.handle(), VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL,
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06003623 dst_buffer.handle(), 1, &copy_region);
3624 m_errorMonitor->VerifyFound();
3625 m_commandBuffer->EndCommandBuffer();
3626 }
3627}
3628
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06003629TEST_F(VkLayerTest, DSImageTransferGranularityTests) {
3630 VkResult err;
3631 bool pass;
3632
3633 TEST_DESCRIPTION("Tests for validaiton of Queue Family property minImageTransferGranularity.");
3634 ASSERT_NO_FATAL_FAILURE(InitState());
3635
3636 // If w/d/h granularity is 1, test is not meaningful
3637 // TODO: When virtual device limits are available, create a set of limits for this test that
3638 // will always have a granularity of > 1 for w, h, and d
3639 auto index = m_device->graphics_queue_node_index_;
3640 auto queue_family_properties = m_device->phy().queue_properties();
3641
3642 if ((queue_family_properties[index].minImageTransferGranularity.depth < 4) ||
3643 (queue_family_properties[index].minImageTransferGranularity.width < 4) ||
3644 (queue_family_properties[index].minImageTransferGranularity.height < 4)) {
3645 return;
3646 }
3647
3648 // Create two images of different types and try to copy between them
3649 VkImage srcImage;
3650 VkImage dstImage;
3651 VkDeviceMemory srcMem;
3652 VkDeviceMemory destMem;
3653 VkMemoryRequirements memReqs;
3654
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06003655 VkImageCreateInfo image_create_info = {};
3656 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
3657 image_create_info.pNext = NULL;
3658 image_create_info.imageType = VK_IMAGE_TYPE_2D;
3659 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
3660 image_create_info.extent.width = 32;
3661 image_create_info.extent.height = 32;
3662 image_create_info.extent.depth = 1;
3663 image_create_info.mipLevels = 1;
3664 image_create_info.arrayLayers = 4;
3665 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
3666 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
3667 image_create_info.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT;
3668 image_create_info.flags = 0;
3669
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003670 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06003671 ASSERT_VK_SUCCESS(err);
3672
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003673 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06003674 ASSERT_VK_SUCCESS(err);
3675
3676 // Allocate memory
3677 VkMemoryAllocateInfo memAlloc = {};
3678 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
3679 memAlloc.pNext = NULL;
3680 memAlloc.allocationSize = 0;
3681 memAlloc.memoryTypeIndex = 0;
3682
3683 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
3684 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003685 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06003686 ASSERT_TRUE(pass);
3687 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
3688 ASSERT_VK_SUCCESS(err);
3689
3690 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
3691 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003692 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06003693 ASSERT_VK_SUCCESS(err);
3694 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
3695 ASSERT_VK_SUCCESS(err);
3696
3697 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
3698 ASSERT_VK_SUCCESS(err);
3699 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
3700 ASSERT_VK_SUCCESS(err);
3701
3702 BeginCommandBuffer();
3703 VkImageCopy copyRegion;
3704 copyRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
3705 copyRegion.srcSubresource.mipLevel = 0;
3706 copyRegion.srcSubresource.baseArrayLayer = 0;
3707 copyRegion.srcSubresource.layerCount = 1;
3708 copyRegion.srcOffset.x = 0;
3709 copyRegion.srcOffset.y = 0;
3710 copyRegion.srcOffset.z = 0;
3711 copyRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
3712 copyRegion.dstSubresource.mipLevel = 0;
3713 copyRegion.dstSubresource.baseArrayLayer = 0;
3714 copyRegion.dstSubresource.layerCount = 1;
3715 copyRegion.dstOffset.x = 0;
3716 copyRegion.dstOffset.y = 0;
3717 copyRegion.dstOffset.z = 0;
3718 copyRegion.extent.width = 1;
3719 copyRegion.extent.height = 1;
3720 copyRegion.extent.depth = 1;
3721
3722 // Introduce failure by setting srcOffset to a bad granularity value
3723 copyRegion.srcOffset.y = 3;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003724 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "queue family image transfer granularity");
3725 m_commandBuffer->CopyImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, VK_IMAGE_LAYOUT_GENERAL, 1, &copyRegion);
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06003726 m_errorMonitor->VerifyFound();
3727
3728 // Introduce failure by setting extent to a bad granularity value
3729 copyRegion.srcOffset.y = 0;
3730 copyRegion.extent.width = 3;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003731 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "queue family image transfer granularity");
3732 m_commandBuffer->CopyImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, VK_IMAGE_LAYOUT_GENERAL, 1, &copyRegion);
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06003733 m_errorMonitor->VerifyFound();
3734
3735 // Now do some buffer/image copies
3736 vk_testing::Buffer buffer;
3737 VkMemoryPropertyFlags reqs = 0;
3738 buffer.init_as_dst(*m_device, 128 * 128, reqs);
3739 VkBufferImageCopy region = {};
3740 region.bufferOffset = 0;
3741 region.bufferRowLength = 3;
3742 region.bufferImageHeight = 128;
3743 region.imageSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
3744 region.imageSubresource.layerCount = 1;
3745 region.imageExtent.height = 16;
3746 region.imageExtent.width = 16;
3747 region.imageExtent.depth = 1;
3748 region.imageOffset.x = 0;
3749 region.imageOffset.y = 0;
3750 region.imageOffset.z = 0;
3751
3752 // Introduce failure by setting bufferRowLength to a bad granularity value
3753 region.bufferRowLength = 3;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003754 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "queue family image transfer granularity");
3755 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer.handle(), srcImage, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1,
3756 &region);
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06003757 m_errorMonitor->VerifyFound();
3758 region.bufferRowLength = 128;
3759
3760 // Introduce failure by setting bufferOffset to a bad granularity value
3761 region.bufferOffset = 3;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003762 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "queue family image transfer granularity");
3763 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), srcImage, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, buffer.handle(), 1,
3764 &region);
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06003765 m_errorMonitor->VerifyFound();
3766 region.bufferOffset = 0;
3767
3768 // Introduce failure by setting bufferImageHeight to a bad granularity value
3769 region.bufferImageHeight = 3;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003770 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "queue family image transfer granularity");
3771 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), srcImage, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, buffer.handle(), 1,
3772 &region);
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06003773 m_errorMonitor->VerifyFound();
3774 region.bufferImageHeight = 128;
3775
3776 // Introduce failure by setting imageExtent to a bad granularity value
3777 region.imageExtent.width = 3;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003778 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "queue family image transfer granularity");
3779 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), srcImage, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, buffer.handle(), 1,
3780 &region);
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06003781 m_errorMonitor->VerifyFound();
3782 region.imageExtent.width = 16;
3783
3784 // Introduce failure by setting imageOffset to a bad granularity value
3785 region.imageOffset.z = 3;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003786 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "queue family image transfer granularity");
3787 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer.handle(), srcImage, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1,
3788 &region);
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06003789 m_errorMonitor->VerifyFound();
3790
3791 EndCommandBuffer();
3792
3793 vkDestroyImage(m_device->device(), srcImage, NULL);
3794 vkDestroyImage(m_device->device(), dstImage, NULL);
3795 vkFreeMemory(m_device->device(), srcMem, NULL);
3796 vkFreeMemory(m_device->device(), destMem, NULL);
3797}
3798
Mark Lobodzinski570efc62016-08-09 16:43:19 -06003799TEST_F(VkLayerTest, MismatchedQueueFamiliesOnSubmit) {
Mark Lobodzinski570efc62016-08-09 16:43:19 -06003800 TEST_DESCRIPTION("Submit command buffer created using one queue family and "
3801 "attempt to submit them on a queue created in a different "
3802 "queue family.");
3803
Cody Northropc31a84f2016-08-22 10:41:47 -06003804 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinski570efc62016-08-09 16:43:19 -06003805 // This test is meaningless unless we have multiple queue families
3806 auto queue_family_properties = m_device->phy().queue_properties();
3807 if (queue_family_properties.size() < 2) {
3808 return;
3809 }
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003810 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " is being submitted on queue ");
Mark Lobodzinski570efc62016-08-09 16:43:19 -06003811 // Get safe index of another queue family
3812 uint32_t other_queue_family = (m_device->graphics_queue_node_index_ == 0) ? 1 : 0;
3813 ASSERT_NO_FATAL_FAILURE(InitState());
3814 // Create a second queue using a different queue family
3815 VkQueue other_queue;
3816 vkGetDeviceQueue(m_device->device(), other_queue_family, 0, &other_queue);
3817
3818 // Record an empty cmd buffer
3819 VkCommandBufferBeginInfo cmdBufBeginDesc = {};
3820 cmdBufBeginDesc.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
3821 vkBeginCommandBuffer(m_commandBuffer->handle(), &cmdBufBeginDesc);
3822 vkEndCommandBuffer(m_commandBuffer->handle());
3823
3824 // And submit on the wrong queue
3825 VkSubmitInfo submit_info = {};
3826 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
3827 submit_info.commandBufferCount = 1;
3828 submit_info.pCommandBuffers = &m_commandBuffer->handle();
Tobin Ehlisfd213ea2016-08-10 17:10:46 -06003829 vkQueueSubmit(other_queue, 1, &submit_info, VK_NULL_HANDLE);
Mark Lobodzinski570efc62016-08-09 16:43:19 -06003830
3831 m_errorMonitor->VerifyFound();
Mark Lobodzinski570efc62016-08-09 16:43:19 -06003832}
3833
Chris Forbes48a53902016-06-30 11:46:27 +12003834TEST_F(VkLayerTest, RenderPassInitialLayoutUndefined) {
3835 TEST_DESCRIPTION("Ensure that CmdBeginRenderPass with an attachment's "
3836 "initialLayout of VK_IMAGE_LAYOUT_UNDEFINED works when "
3837 "the command buffer has prior knowledge of that "
3838 "attachment's layout.");
3839
3840 m_errorMonitor->ExpectSuccess();
3841
3842 ASSERT_NO_FATAL_FAILURE(InitState());
3843
3844 // A renderpass with one color attachment.
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003845 VkAttachmentDescription attachment = {0,
3846 VK_FORMAT_R8G8B8A8_UNORM,
3847 VK_SAMPLE_COUNT_1_BIT,
3848 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
3849 VK_ATTACHMENT_STORE_OP_STORE,
3850 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
3851 VK_ATTACHMENT_STORE_OP_DONT_CARE,
3852 VK_IMAGE_LAYOUT_UNDEFINED,
3853 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL};
Chris Forbes48a53902016-06-30 11:46:27 +12003854
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003855 VkAttachmentReference att_ref = {0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL};
Chris Forbes48a53902016-06-30 11:46:27 +12003856
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003857 VkSubpassDescription subpass = {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 1, &att_ref, nullptr, nullptr, 0, nullptr};
Chris Forbes48a53902016-06-30 11:46:27 +12003858
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003859 VkRenderPassCreateInfo rpci = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 1, &attachment, 1, &subpass, 0, nullptr};
Chris Forbes48a53902016-06-30 11:46:27 +12003860
3861 VkRenderPass rp;
3862 VkResult err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
3863 ASSERT_VK_SUCCESS(err);
3864
3865 // A compatible framebuffer.
3866 VkImageObj image(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003867 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 +12003868 ASSERT_TRUE(image.initialized());
3869
3870 VkImageViewCreateInfo ivci = {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003871 VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO,
3872 nullptr,
3873 0,
3874 image.handle(),
3875 VK_IMAGE_VIEW_TYPE_2D,
3876 VK_FORMAT_R8G8B8A8_UNORM,
3877 {VK_COMPONENT_SWIZZLE_IDENTITY, VK_COMPONENT_SWIZZLE_IDENTITY, VK_COMPONENT_SWIZZLE_IDENTITY,
3878 VK_COMPONENT_SWIZZLE_IDENTITY},
3879 {VK_IMAGE_ASPECT_COLOR_BIT, 0, 1, 0, 1},
Chris Forbes48a53902016-06-30 11:46:27 +12003880 };
3881 VkImageView view;
3882 err = vkCreateImageView(m_device->device(), &ivci, nullptr, &view);
3883 ASSERT_VK_SUCCESS(err);
3884
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003885 VkFramebufferCreateInfo fci = {VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr, 0, rp, 1, &view, 32, 32, 1};
Chris Forbes48a53902016-06-30 11:46:27 +12003886 VkFramebuffer fb;
3887 err = vkCreateFramebuffer(m_device->device(), &fci, nullptr, &fb);
3888 ASSERT_VK_SUCCESS(err);
3889
3890 // Record a single command buffer which uses this renderpass twice. The
3891 // bug is triggered at the beginning of the second renderpass, when the
3892 // command buffer already has a layout recorded for the attachment.
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003893 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 +12003894 BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003895 vkCmdBeginRenderPass(m_commandBuffer->handle(), &rpbi, VK_SUBPASS_CONTENTS_INLINE);
Chris Forbes48a53902016-06-30 11:46:27 +12003896 vkCmdEndRenderPass(m_commandBuffer->handle());
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003897 vkCmdBeginRenderPass(m_commandBuffer->handle(), &rpbi, VK_SUBPASS_CONTENTS_INLINE);
Chris Forbes48a53902016-06-30 11:46:27 +12003898
3899 m_errorMonitor->VerifyNotFound();
3900
3901 vkCmdEndRenderPass(m_commandBuffer->handle());
3902 EndCommandBuffer();
3903
3904 vkDestroyFramebuffer(m_device->device(), fb, nullptr);
3905 vkDestroyRenderPass(m_device->device(), rp, nullptr);
3906 vkDestroyImageView(m_device->device(), view, nullptr);
3907}
3908
Tobin Ehlis75ac37b2016-07-29 10:55:41 -06003909TEST_F(VkLayerTest, FramebufferBindingDestroyCommandPool) {
3910 TEST_DESCRIPTION("This test should pass. Create a Framebuffer and "
3911 "command buffer, bind them together, then destroy "
3912 "command pool and framebuffer and verify there are no "
3913 "errors.");
3914
3915 m_errorMonitor->ExpectSuccess();
3916
3917 ASSERT_NO_FATAL_FAILURE(InitState());
3918
3919 // A renderpass with one color attachment.
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003920 VkAttachmentDescription attachment = {0,
3921 VK_FORMAT_R8G8B8A8_UNORM,
3922 VK_SAMPLE_COUNT_1_BIT,
3923 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
3924 VK_ATTACHMENT_STORE_OP_STORE,
3925 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
3926 VK_ATTACHMENT_STORE_OP_DONT_CARE,
3927 VK_IMAGE_LAYOUT_UNDEFINED,
3928 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL};
Tobin Ehlis75ac37b2016-07-29 10:55:41 -06003929
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003930 VkAttachmentReference att_ref = {0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL};
Tobin Ehlis75ac37b2016-07-29 10:55:41 -06003931
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003932 VkSubpassDescription subpass = {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 1, &att_ref, nullptr, nullptr, 0, nullptr};
Tobin Ehlis75ac37b2016-07-29 10:55:41 -06003933
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003934 VkRenderPassCreateInfo rpci = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 1, &attachment, 1, &subpass, 0, nullptr};
Tobin Ehlis75ac37b2016-07-29 10:55:41 -06003935
3936 VkRenderPass rp;
3937 VkResult err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
3938 ASSERT_VK_SUCCESS(err);
3939
3940 // A compatible framebuffer.
3941 VkImageObj image(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003942 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 -06003943 ASSERT_TRUE(image.initialized());
3944
3945 VkImageViewCreateInfo ivci = {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003946 VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO,
3947 nullptr,
3948 0,
3949 image.handle(),
3950 VK_IMAGE_VIEW_TYPE_2D,
3951 VK_FORMAT_R8G8B8A8_UNORM,
3952 {VK_COMPONENT_SWIZZLE_IDENTITY, VK_COMPONENT_SWIZZLE_IDENTITY, VK_COMPONENT_SWIZZLE_IDENTITY,
3953 VK_COMPONENT_SWIZZLE_IDENTITY},
3954 {VK_IMAGE_ASPECT_COLOR_BIT, 0, 1, 0, 1},
Tobin Ehlis75ac37b2016-07-29 10:55:41 -06003955 };
3956 VkImageView view;
3957 err = vkCreateImageView(m_device->device(), &ivci, nullptr, &view);
3958 ASSERT_VK_SUCCESS(err);
3959
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003960 VkFramebufferCreateInfo fci = {VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr, 0, rp, 1, &view, 32, 32, 1};
Tobin Ehlis75ac37b2016-07-29 10:55:41 -06003961 VkFramebuffer fb;
3962 err = vkCreateFramebuffer(m_device->device(), &fci, nullptr, &fb);
3963 ASSERT_VK_SUCCESS(err);
3964
3965 // Explicitly create a command buffer to bind the FB to so that we can then
3966 // destroy the command pool in order to implicitly free command buffer
3967 VkCommandPool command_pool;
3968 VkCommandPoolCreateInfo pool_create_info{};
3969 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
3970 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
3971 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003972 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
Tobin Ehlis75ac37b2016-07-29 10:55:41 -06003973
3974 VkCommandBuffer command_buffer;
3975 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003976 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
Tobin Ehlis75ac37b2016-07-29 10:55:41 -06003977 command_buffer_allocate_info.commandPool = command_pool;
3978 command_buffer_allocate_info.commandBufferCount = 1;
3979 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003980 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, &command_buffer);
Tobin Ehlis75ac37b2016-07-29 10:55:41 -06003981
3982 // Begin our cmd buffer with renderpass using our framebuffer
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003983 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 -06003984 VkCommandBufferBeginInfo begin_info{};
3985 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
3986 vkBeginCommandBuffer(command_buffer, &begin_info);
3987
3988 vkCmdBeginRenderPass(command_buffer, &rpbi, VK_SUBPASS_CONTENTS_INLINE);
3989 vkCmdEndRenderPass(command_buffer);
3990 vkEndCommandBuffer(command_buffer);
Mark Lobodzinski7d10a822016-08-03 14:08:40 -06003991 vkDestroyImageView(m_device->device(), view, nullptr);
Tobin Ehlis75ac37b2016-07-29 10:55:41 -06003992 // Destroy command pool to implicitly free command buffer
3993 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
3994 vkDestroyFramebuffer(m_device->device(), fb, nullptr);
3995 vkDestroyRenderPass(m_device->device(), rp, nullptr);
3996 m_errorMonitor->VerifyNotFound();
3997}
3998
Chris Forbes51bf7c92016-06-30 15:22:08 +12003999TEST_F(VkLayerTest, RenderPassSubpassZeroTransitionsApplied) {
4000 TEST_DESCRIPTION("Ensure that CmdBeginRenderPass applies the layout "
4001 "transitions for the first subpass");
4002
4003 m_errorMonitor->ExpectSuccess();
4004
4005 ASSERT_NO_FATAL_FAILURE(InitState());
4006
4007 // A renderpass with one color attachment.
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004008 VkAttachmentDescription attachment = {0,
4009 VK_FORMAT_R8G8B8A8_UNORM,
4010 VK_SAMPLE_COUNT_1_BIT,
4011 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
4012 VK_ATTACHMENT_STORE_OP_STORE,
4013 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
4014 VK_ATTACHMENT_STORE_OP_DONT_CARE,
4015 VK_IMAGE_LAYOUT_UNDEFINED,
4016 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL};
Chris Forbes51bf7c92016-06-30 15:22:08 +12004017
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004018 VkAttachmentReference att_ref = {0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL};
Chris Forbes51bf7c92016-06-30 15:22:08 +12004019
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004020 VkSubpassDescription subpass = {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 1, &att_ref, nullptr, nullptr, 0, nullptr};
Chris Forbes51bf7c92016-06-30 15:22:08 +12004021
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004022 VkSubpassDependency dep = {0,
4023 0,
4024 VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT,
4025 VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT,
4026 VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT,
4027 VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT,
4028 VK_DEPENDENCY_BY_REGION_BIT};
Chris Forbes51bf7c92016-06-30 15:22:08 +12004029
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004030 VkRenderPassCreateInfo rpci = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 1, &attachment, 1, &subpass, 1, &dep};
Chris Forbes51bf7c92016-06-30 15:22:08 +12004031
4032 VkResult err;
4033 VkRenderPass rp;
4034 err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
4035 ASSERT_VK_SUCCESS(err);
4036
4037 // A compatible framebuffer.
4038 VkImageObj image(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004039 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 +12004040 ASSERT_TRUE(image.initialized());
4041
4042 VkImageViewCreateInfo ivci = {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004043 VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO,
4044 nullptr,
4045 0,
4046 image.handle(),
4047 VK_IMAGE_VIEW_TYPE_2D,
4048 VK_FORMAT_R8G8B8A8_UNORM,
4049 {VK_COMPONENT_SWIZZLE_IDENTITY, VK_COMPONENT_SWIZZLE_IDENTITY, VK_COMPONENT_SWIZZLE_IDENTITY,
4050 VK_COMPONENT_SWIZZLE_IDENTITY},
4051 {VK_IMAGE_ASPECT_COLOR_BIT, 0, 1, 0, 1},
Chris Forbes51bf7c92016-06-30 15:22:08 +12004052 };
4053 VkImageView view;
4054 err = vkCreateImageView(m_device->device(), &ivci, nullptr, &view);
4055 ASSERT_VK_SUCCESS(err);
4056
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004057 VkFramebufferCreateInfo fci = {VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr, 0, rp, 1, &view, 32, 32, 1};
Chris Forbes51bf7c92016-06-30 15:22:08 +12004058 VkFramebuffer fb;
4059 err = vkCreateFramebuffer(m_device->device(), &fci, nullptr, &fb);
4060 ASSERT_VK_SUCCESS(err);
4061
4062 // Record a single command buffer which issues a pipeline barrier w/
4063 // image memory barrier for the attachment. This detects the previously
4064 // missing tracking of the subpass layout by throwing a validation error
4065 // if it doesn't occur.
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004066 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 +12004067 BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004068 vkCmdBeginRenderPass(m_commandBuffer->handle(), &rpbi, VK_SUBPASS_CONTENTS_INLINE);
Chris Forbes51bf7c92016-06-30 15:22:08 +12004069
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004070 VkImageMemoryBarrier imb = {VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER,
4071 nullptr,
4072 VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT,
4073 VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT,
4074 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
4075 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
4076 VK_QUEUE_FAMILY_IGNORED,
4077 VK_QUEUE_FAMILY_IGNORED,
4078 image.handle(),
4079 {VK_IMAGE_ASPECT_COLOR_BIT, 0, 1, 0, 1}};
4080 vkCmdPipelineBarrier(m_commandBuffer->handle(), VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT,
4081 VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT, VK_DEPENDENCY_BY_REGION_BIT, 0, nullptr, 0, nullptr, 1,
4082 &imb);
Chris Forbes51bf7c92016-06-30 15:22:08 +12004083
4084 vkCmdEndRenderPass(m_commandBuffer->handle());
4085 m_errorMonitor->VerifyNotFound();
4086 EndCommandBuffer();
4087
4088 vkDestroyFramebuffer(m_device->device(), fb, nullptr);
4089 vkDestroyRenderPass(m_device->device(), rp, nullptr);
4090 vkDestroyImageView(m_device->device(), view, nullptr);
4091}
4092
Mark Lobodzinski77a5d6f2016-08-05 09:38:18 -06004093TEST_F(VkLayerTest, DepthStencilLayoutTransitionForDepthOnlyImageview) {
4094 TEST_DESCRIPTION("Validate that when an imageView of a depth/stencil image "
4095 "is used as a depth/stencil framebuffer attachment, the "
4096 "aspectMask is ignored and both depth and stencil image "
4097 "subresources are used.");
4098
4099 VkFormatProperties format_properties;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004100 vkGetPhysicalDeviceFormatProperties(gpu(), VK_FORMAT_D32_SFLOAT_S8_UINT, &format_properties);
4101 if (!(format_properties.optimalTilingFeatures & VK_FORMAT_FEATURE_SAMPLED_IMAGE_BIT)) {
Mark Lobodzinski77a5d6f2016-08-05 09:38:18 -06004102 return;
4103 }
4104
4105 m_errorMonitor->ExpectSuccess();
4106
4107 ASSERT_NO_FATAL_FAILURE(InitState());
4108
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004109 VkAttachmentDescription attachment = {0,
4110 VK_FORMAT_D32_SFLOAT_S8_UINT,
4111 VK_SAMPLE_COUNT_1_BIT,
4112 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
4113 VK_ATTACHMENT_STORE_OP_STORE,
4114 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
4115 VK_ATTACHMENT_STORE_OP_DONT_CARE,
4116 VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL,
4117 VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL};
Mark Lobodzinski77a5d6f2016-08-05 09:38:18 -06004118
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004119 VkAttachmentReference att_ref = {0, VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL};
Mark Lobodzinski77a5d6f2016-08-05 09:38:18 -06004120
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004121 VkSubpassDescription subpass = {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 0, nullptr, nullptr, &att_ref, 0, nullptr};
Mark Lobodzinski77a5d6f2016-08-05 09:38:18 -06004122
4123 VkSubpassDependency dep = {0,
4124 0,
4125 VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT,
4126 VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT,
4127 VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT,
4128 VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT,
4129 VK_DEPENDENCY_BY_REGION_BIT};
4130
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004131 VkRenderPassCreateInfo rpci = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 1, &attachment, 1, &subpass, 1, &dep};
Mark Lobodzinski77a5d6f2016-08-05 09:38:18 -06004132
4133 VkResult err;
4134 VkRenderPass rp;
4135 err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
4136 ASSERT_VK_SUCCESS(err);
4137
4138 VkImageObj image(m_device);
4139 image.init_no_layout(32, 32, VK_FORMAT_D32_SFLOAT_S8_UINT,
4140 0x26, // usage
4141 VK_IMAGE_TILING_OPTIMAL, 0);
4142 ASSERT_TRUE(image.initialized());
4143 image.SetLayout(0x6, VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL);
4144
4145 VkImageViewCreateInfo ivci = {
4146 VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO,
4147 nullptr,
4148 0,
4149 image.handle(),
4150 VK_IMAGE_VIEW_TYPE_2D,
4151 VK_FORMAT_D32_SFLOAT_S8_UINT,
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004152 {VK_COMPONENT_SWIZZLE_R, VK_COMPONENT_SWIZZLE_G, VK_COMPONENT_SWIZZLE_B, VK_COMPONENT_SWIZZLE_A},
Mark Lobodzinski77a5d6f2016-08-05 09:38:18 -06004153 {0x2, 0, 1, 0, 1},
4154 };
4155 VkImageView view;
4156 err = vkCreateImageView(m_device->device(), &ivci, nullptr, &view);
4157 ASSERT_VK_SUCCESS(err);
4158
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004159 VkFramebufferCreateInfo fci = {VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr, 0, rp, 1, &view, 32, 32, 1};
Mark Lobodzinski77a5d6f2016-08-05 09:38:18 -06004160 VkFramebuffer fb;
4161 err = vkCreateFramebuffer(m_device->device(), &fci, nullptr, &fb);
4162 ASSERT_VK_SUCCESS(err);
4163
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004164 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 -06004165 BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004166 vkCmdBeginRenderPass(m_commandBuffer->handle(), &rpbi, VK_SUBPASS_CONTENTS_INLINE);
Mark Lobodzinski77a5d6f2016-08-05 09:38:18 -06004167
4168 VkImageMemoryBarrier imb = {};
4169 imb.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
4170 imb.pNext = nullptr;
4171 imb.srcAccessMask = VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_WRITE_BIT;
4172 imb.dstAccessMask = VK_ACCESS_SHADER_READ_BIT;
4173 imb.oldLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
4174 imb.newLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
4175 imb.srcQueueFamilyIndex = 0;
4176 imb.dstQueueFamilyIndex = 0;
4177 imb.image = image.handle();
4178 imb.subresourceRange.aspectMask = 0x6;
4179 imb.subresourceRange.baseMipLevel = 0;
4180 imb.subresourceRange.levelCount = 0x1;
4181 imb.subresourceRange.baseArrayLayer = 0;
4182 imb.subresourceRange.layerCount = 0x1;
4183
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004184 vkCmdPipelineBarrier(m_commandBuffer->handle(), VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT,
4185 VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT, VK_DEPENDENCY_BY_REGION_BIT, 0, nullptr, 0, nullptr, 1,
Mark Lobodzinski77a5d6f2016-08-05 09:38:18 -06004186 &imb);
4187
4188 vkCmdEndRenderPass(m_commandBuffer->handle());
4189 EndCommandBuffer();
4190 QueueCommandBuffer(false);
4191 m_errorMonitor->VerifyNotFound();
4192
4193 vkDestroyFramebuffer(m_device->device(), fb, nullptr);
4194 vkDestroyRenderPass(m_device->device(), rp, nullptr);
4195 vkDestroyImageView(m_device->device(), view, nullptr);
4196}
Tony Barbourd5f7b822016-08-02 15:39:33 -06004197
Tony Barbour4e919972016-08-09 13:27:40 -06004198TEST_F(VkLayerTest, RenderPassInvalidRenderArea) {
4199 TEST_DESCRIPTION("Generate INVALID_RENDER_AREA error by beginning renderpass"
4200 "with extent outside of framebuffer");
4201 ASSERT_NO_FATAL_FAILURE(InitState());
4202 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
4203
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004204 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Cannot execute a render pass with renderArea "
4205 "not within the bound of the framebuffer.");
Tony Barbour4e919972016-08-09 13:27:40 -06004206
4207 // Framebuffer for render target is 256x256, exceed that for INVALID_RENDER_AREA
4208 m_renderPassBeginInfo.renderArea.extent.width = 257;
4209 m_renderPassBeginInfo.renderArea.extent.height = 257;
4210 BeginCommandBuffer();
4211 m_errorMonitor->VerifyFound();
4212}
4213
4214TEST_F(VkLayerTest, DisabledIndependentBlend) {
4215 TEST_DESCRIPTION("Generate INDEPENDENT_BLEND by disabling independent "
4216 "blend and then specifying different blend states for two "
4217 "attachements");
Cody Northrop5703cc72016-08-19 09:57:10 -06004218 VkPhysicalDeviceFeatures features = {};
4219 features.independentBlend = VK_FALSE;
Cody Northropc31a84f2016-08-22 10:41:47 -06004220 ASSERT_NO_FATAL_FAILURE(InitState(&features));
Tony Barbour4e919972016-08-09 13:27:40 -06004221
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004222 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
4223 "Invalid Pipeline CreateInfo: If independent blend feature not "
4224 "enabled, all elements of pAttachments must be identical");
Tony Barbour4e919972016-08-09 13:27:40 -06004225
Cody Northropc31a84f2016-08-22 10:41:47 -06004226 VkDescriptorSetObj descriptorSet(m_device);
4227 descriptorSet.AppendDummy();
4228 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Tony Barbour4e919972016-08-09 13:27:40 -06004229
Cody Northropc31a84f2016-08-22 10:41:47 -06004230 VkPipelineObj pipeline(m_device);
4231 VkRenderpassObj renderpass(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004232 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
Cody Northropc31a84f2016-08-22 10:41:47 -06004233 pipeline.AddShader(&vs);
Cody Northrop5703cc72016-08-19 09:57:10 -06004234
Cody Northropc31a84f2016-08-22 10:41:47 -06004235 VkPipelineColorBlendAttachmentState att_state1 = {}, att_state2 = {};
4236 att_state1.dstAlphaBlendFactor = VK_BLEND_FACTOR_CONSTANT_COLOR;
4237 att_state1.blendEnable = VK_TRUE;
4238 att_state2.dstAlphaBlendFactor = VK_BLEND_FACTOR_CONSTANT_COLOR;
4239 att_state2.blendEnable = VK_FALSE;
4240 pipeline.AddColorAttachment(0, &att_state1);
4241 pipeline.AddColorAttachment(1, &att_state2);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004242 pipeline.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderpass.handle());
Cody Northropc31a84f2016-08-22 10:41:47 -06004243 m_errorMonitor->VerifyFound();
Tony Barbour4e919972016-08-09 13:27:40 -06004244}
4245
4246TEST_F(VkLayerTest, RenderPassDepthStencilAttachmentUnused) {
4247 TEST_DESCRIPTION("Specify no depth attachement in renderpass then specify "
4248 "depth attachments in subpass");
Cody Northropc31a84f2016-08-22 10:41:47 -06004249 ASSERT_NO_FATAL_FAILURE(InitState());
Tony Barbour4e919972016-08-09 13:27:40 -06004250
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004251 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
4252 "vkCreateRenderPass has no depth/stencil attachment, yet subpass");
Tony Barbour4e919972016-08-09 13:27:40 -06004253
4254 // Create a renderPass with a single color attachment
4255 VkAttachmentReference attach = {};
4256 attach.layout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
4257 VkSubpassDescription subpass = {};
4258 VkRenderPassCreateInfo rpci = {};
4259 rpci.subpassCount = 1;
4260 rpci.pSubpasses = &subpass;
4261 rpci.attachmentCount = 1;
4262 VkAttachmentDescription attach_desc = {};
4263 attach_desc.format = VK_FORMAT_B8G8R8A8_UNORM;
4264 attach_desc.samples = VK_SAMPLE_COUNT_1_BIT;
4265 rpci.pAttachments = &attach_desc;
4266 rpci.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
4267 VkRenderPass rp;
4268 subpass.pDepthStencilAttachment = &attach;
4269 subpass.pColorAttachments = NULL;
4270 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
4271 m_errorMonitor->VerifyFound();
4272}
4273
Chris Forbes6b3d3f42016-06-30 16:09:47 +12004274TEST_F(VkLayerTest, RenderPassTransitionsAttachmentUnused) {
4275 TEST_DESCRIPTION("Ensure that layout transitions work correctly without "
4276 "errors, when an attachment reference is "
4277 "VK_ATTACHMENT_UNUSED");
4278
4279 m_errorMonitor->ExpectSuccess();
4280
4281 ASSERT_NO_FATAL_FAILURE(InitState());
4282
4283 // A renderpass with no attachments
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004284 VkAttachmentReference att_ref = {VK_ATTACHMENT_UNUSED, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL};
Chris Forbes6b3d3f42016-06-30 16:09:47 +12004285
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004286 VkSubpassDescription subpass = {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 1, &att_ref, nullptr, nullptr, 0, nullptr};
Chris Forbes6b3d3f42016-06-30 16:09:47 +12004287
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004288 VkRenderPassCreateInfo rpci = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 0, nullptr, 1, &subpass, 0, nullptr};
Chris Forbes6b3d3f42016-06-30 16:09:47 +12004289
4290 VkRenderPass rp;
4291 VkResult err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
4292 ASSERT_VK_SUCCESS(err);
4293
4294 // A compatible framebuffer.
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004295 VkFramebufferCreateInfo fci = {VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr, 0, rp, 0, nullptr, 32, 32, 1};
Chris Forbes6b3d3f42016-06-30 16:09:47 +12004296 VkFramebuffer fb;
4297 err = vkCreateFramebuffer(m_device->device(), &fci, nullptr, &fb);
4298 ASSERT_VK_SUCCESS(err);
4299
4300 // Record a command buffer which just begins and ends the renderpass. The
4301 // bug manifests in BeginRenderPass.
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004302 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 +12004303 BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004304 vkCmdBeginRenderPass(m_commandBuffer->handle(), &rpbi, VK_SUBPASS_CONTENTS_INLINE);
Chris Forbes6b3d3f42016-06-30 16:09:47 +12004305 vkCmdEndRenderPass(m_commandBuffer->handle());
4306 m_errorMonitor->VerifyNotFound();
4307 EndCommandBuffer();
4308
4309 vkDestroyFramebuffer(m_device->device(), fb, nullptr);
4310 vkDestroyRenderPass(m_device->device(), rp, nullptr);
4311}
4312
Mark Lobodzinskice7eee72016-06-14 16:33:29 -06004313// This is a positive test. No errors are expected.
4314TEST_F(VkLayerTest, StencilLoadOp) {
4315 TEST_DESCRIPTION("Create a stencil-only attachment with a LOAD_OP set to "
4316 "CLEAR. stencil[Load|Store]Op used to be ignored.");
4317 VkResult result = VK_SUCCESS;
4318 VkImageFormatProperties formatProps;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004319 vkGetPhysicalDeviceImageFormatProperties(gpu(), VK_FORMAT_D24_UNORM_S8_UINT, VK_IMAGE_TYPE_2D, VK_IMAGE_TILING_OPTIMAL,
4320 VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_SRC_BIT, 0,
4321 &formatProps);
Mark Lobodzinskice7eee72016-06-14 16:33:29 -06004322 if (formatProps.maxExtent.width < 100 || formatProps.maxExtent.height < 100) {
4323 return;
4324 }
4325
4326 ASSERT_NO_FATAL_FAILURE(InitState());
4327 VkFormat depth_stencil_fmt = VK_FORMAT_D24_UNORM_S8_UINT;
4328 m_depthStencil->Init(m_device, 100, 100, depth_stencil_fmt,
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004329 VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_SRC_BIT);
Mark Lobodzinskice7eee72016-06-14 16:33:29 -06004330 VkAttachmentDescription att = {};
4331 VkAttachmentReference ref = {};
4332 att.format = depth_stencil_fmt;
4333 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
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006179 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Dynamic viewport state not set for this command buffer");
6180 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
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006190 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Dynamic scissor state not set for this command buffer");
6191 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
6672 VkImageObj image(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006673 image.init(128, 128, VK_FORMAT_B8G8R8A8_UNORM, VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT,
Tobin Ehlis0283c4d2016-06-28 17:57:07 -06006674 VK_IMAGE_TILING_OPTIMAL, 0);
6675 ASSERT_TRUE(image.initialized());
6676
6677 VkBuffer buffer;
6678 VkDeviceMemory mem;
6679 VkMemoryRequirements mem_reqs;
6680
6681 VkBufferCreateInfo buf_info = {};
6682 buf_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
6683 buf_info.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
6684 buf_info.size = 256;
6685 buf_info.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
6686 VkResult err = vkCreateBuffer(m_device->device(), &buf_info, NULL, &buffer);
6687 ASSERT_VK_SUCCESS(err);
6688
6689 vkGetBufferMemoryRequirements(m_device->device(), buffer, &mem_reqs);
6690
6691 VkMemoryAllocateInfo alloc_info = {};
6692 alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
6693 alloc_info.allocationSize = 256;
6694 bool pass = false;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006695 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 -06006696 if (!pass) {
6697 vkDestroyBuffer(m_device->device(), buffer, NULL);
6698 return;
6699 }
6700 err = vkAllocateMemory(m_device->device(), &alloc_info, NULL, &mem);
6701 ASSERT_VK_SUCCESS(err);
6702
6703 err = vkBindBufferMemory(m_device->device(), buffer, mem, 0);
6704 ASSERT_VK_SUCCESS(err);
6705
6706 VkBufferImageCopy region = {};
6707 region.bufferRowLength = 128;
6708 region.bufferImageHeight = 128;
6709 region.imageSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
6710
6711 region.imageSubresource.layerCount = 1;
6712 region.imageExtent.height = 4;
6713 region.imageExtent.width = 4;
6714 region.imageExtent.depth = 1;
6715 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006716 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer, image.handle(), VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1,
6717 &region);
Tobin Ehlis0283c4d2016-06-28 17:57:07 -06006718 m_commandBuffer->EndCommandBuffer();
6719
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006720 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " that is invalid because bound buffer ");
Tobin Ehlis0283c4d2016-06-28 17:57:07 -06006721 // Destroy buffer dependency prior to submit to cause ERROR
6722 vkDestroyBuffer(m_device->device(), buffer, NULL);
6723
6724 VkSubmitInfo submit_info = {};
6725 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
6726 submit_info.commandBufferCount = 1;
6727 submit_info.pCommandBuffers = &m_commandBuffer->handle();
6728 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
6729
6730 m_errorMonitor->VerifyFound();
6731 vkFreeMemory(m_device->handle(), mem, NULL);
6732}
6733
Tobin Ehlis11c8cea2016-06-28 17:44:21 -06006734TEST_F(VkLayerTest, InvalidCmdBufferImageDestroyed) {
6735 TEST_DESCRIPTION("Attempt to draw with a command buffer that is invalid "
6736 "due to an image dependency being destroyed.");
6737 ASSERT_NO_FATAL_FAILURE(InitState());
6738
6739 VkImage image;
6740 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
6741 VkImageCreateInfo image_create_info = {};
6742 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
6743 image_create_info.pNext = NULL;
6744 image_create_info.imageType = VK_IMAGE_TYPE_2D;
6745 image_create_info.format = tex_format;
6746 image_create_info.extent.width = 32;
6747 image_create_info.extent.height = 32;
6748 image_create_info.extent.depth = 1;
6749 image_create_info.mipLevels = 1;
6750 image_create_info.arrayLayers = 1;
6751 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
6752 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006753 image_create_info.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT;
Tobin Ehlis11c8cea2016-06-28 17:44:21 -06006754 image_create_info.flags = 0;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006755 VkResult err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
Tobin Ehlis11c8cea2016-06-28 17:44:21 -06006756 ASSERT_VK_SUCCESS(err);
Tobin Ehlis3d09fd52016-07-06 08:12:56 -06006757 // Have to bind memory to image before recording cmd in cmd buffer using it
6758 VkMemoryRequirements mem_reqs;
6759 VkDeviceMemory image_mem;
6760 bool pass;
6761 VkMemoryAllocateInfo mem_alloc = {};
6762 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
6763 mem_alloc.pNext = NULL;
6764 mem_alloc.memoryTypeIndex = 0;
6765 vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs);
6766 mem_alloc.allocationSize = mem_reqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006767 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0);
Tobin Ehlis3d09fd52016-07-06 08:12:56 -06006768 ASSERT_TRUE(pass);
6769 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &image_mem);
6770 ASSERT_VK_SUCCESS(err);
6771 err = vkBindImageMemory(m_device->device(), image, image_mem, 0);
6772 ASSERT_VK_SUCCESS(err);
Tobin Ehlis11c8cea2016-06-28 17:44:21 -06006773
Tobin Ehlis11c8cea2016-06-28 17:44:21 -06006774 m_commandBuffer->BeginCommandBuffer();
Tobin Ehlis764d7072016-07-01 12:54:29 -06006775 VkClearColorValue ccv;
6776 ccv.float32[0] = 1.0f;
6777 ccv.float32[1] = 1.0f;
6778 ccv.float32[2] = 1.0f;
6779 ccv.float32[3] = 1.0f;
6780 VkImageSubresourceRange isr = {};
6781 isr.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Tobin Ehlis3d09fd52016-07-06 08:12:56 -06006782 isr.baseArrayLayer = 0;
6783 isr.baseMipLevel = 0;
Tobin Ehlis764d7072016-07-01 12:54:29 -06006784 isr.layerCount = 1;
6785 isr.levelCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006786 vkCmdClearColorImage(m_commandBuffer->GetBufferHandle(), image, VK_IMAGE_LAYOUT_GENERAL, &ccv, 1, &isr);
Tobin Ehlis11c8cea2016-06-28 17:44:21 -06006787 m_commandBuffer->EndCommandBuffer();
6788
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006789 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " that is invalid because bound image ");
Tobin Ehlis11c8cea2016-06-28 17:44:21 -06006790 // Destroy image dependency prior to submit to cause ERROR
6791 vkDestroyImage(m_device->device(), image, NULL);
6792
6793 VkSubmitInfo submit_info = {};
6794 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
6795 submit_info.commandBufferCount = 1;
6796 submit_info.pCommandBuffers = &m_commandBuffer->handle();
6797 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
6798
6799 m_errorMonitor->VerifyFound();
Tobin Ehlis3d09fd52016-07-06 08:12:56 -06006800 vkFreeMemory(m_device->device(), image_mem, nullptr);
Tobin Ehlis11c8cea2016-06-28 17:44:21 -06006801}
6802
Tobin Ehlis59f68ab2016-09-06 21:59:07 -06006803TEST_F(VkLayerTest, InvalidCmdBufferFramebufferImageDestroyed) {
6804 TEST_DESCRIPTION("Attempt to draw with a command buffer that is invalid "
6805 "due to a framebuffer image dependency being destroyed.");
6806 VkFormatProperties format_properties;
6807 VkResult err = VK_SUCCESS;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006808 vkGetPhysicalDeviceFormatProperties(gpu(), VK_FORMAT_B8G8R8A8_UNORM, &format_properties);
6809 if (!(format_properties.optimalTilingFeatures & VK_FORMAT_FEATURE_SAMPLED_IMAGE_BIT)) {
Tobin Ehlis59f68ab2016-09-06 21:59:07 -06006810 return;
6811 }
6812
6813 ASSERT_NO_FATAL_FAILURE(InitState());
6814 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
6815
6816 VkImageCreateInfo image_ci = {};
6817 image_ci.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
6818 image_ci.pNext = NULL;
6819 image_ci.imageType = VK_IMAGE_TYPE_2D;
6820 image_ci.format = VK_FORMAT_B8G8R8A8_UNORM;
6821 image_ci.extent.width = 32;
6822 image_ci.extent.height = 32;
6823 image_ci.extent.depth = 1;
6824 image_ci.mipLevels = 1;
6825 image_ci.arrayLayers = 1;
6826 image_ci.samples = VK_SAMPLE_COUNT_1_BIT;
6827 image_ci.tiling = VK_IMAGE_TILING_OPTIMAL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006828 image_ci.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_SAMPLED_BIT;
Tobin Ehlis59f68ab2016-09-06 21:59:07 -06006829 image_ci.initialLayout = VK_IMAGE_LAYOUT_UNDEFINED;
6830 image_ci.flags = 0;
6831 VkImage image;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006832 ASSERT_VK_SUCCESS(vkCreateImage(m_device->handle(), &image_ci, NULL, &image));
Tobin Ehlis59f68ab2016-09-06 21:59:07 -06006833
6834 VkMemoryRequirements memory_reqs;
6835 VkDeviceMemory image_memory;
6836 bool pass;
6837 VkMemoryAllocateInfo memory_info = {};
6838 memory_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
6839 memory_info.pNext = NULL;
6840 memory_info.allocationSize = 0;
6841 memory_info.memoryTypeIndex = 0;
6842 vkGetImageMemoryRequirements(m_device->device(), image, &memory_reqs);
6843 memory_info.allocationSize = memory_reqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006844 pass = m_device->phy().set_memory_type(memory_reqs.memoryTypeBits, &memory_info, 0);
Tobin Ehlis59f68ab2016-09-06 21:59:07 -06006845 ASSERT_TRUE(pass);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006846 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &image_memory);
Tobin Ehlis59f68ab2016-09-06 21:59:07 -06006847 ASSERT_VK_SUCCESS(err);
6848 err = vkBindImageMemory(m_device->device(), image, image_memory, 0);
6849 ASSERT_VK_SUCCESS(err);
6850
6851 VkImageViewCreateInfo ivci = {
6852 VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO,
6853 nullptr,
6854 0,
6855 image,
6856 VK_IMAGE_VIEW_TYPE_2D,
6857 VK_FORMAT_B8G8R8A8_UNORM,
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006858 {VK_COMPONENT_SWIZZLE_R, VK_COMPONENT_SWIZZLE_G, VK_COMPONENT_SWIZZLE_B, VK_COMPONENT_SWIZZLE_A},
Tobin Ehlis59f68ab2016-09-06 21:59:07 -06006859 {VK_IMAGE_ASPECT_COLOR_BIT, 0, 1, 0, 1},
6860 };
6861 VkImageView view;
6862 err = vkCreateImageView(m_device->device(), &ivci, nullptr, &view);
6863 ASSERT_VK_SUCCESS(err);
6864
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006865 VkFramebufferCreateInfo fci = {VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr, 0, m_renderPass, 1, &view, 32, 32, 1};
Tobin Ehlis59f68ab2016-09-06 21:59:07 -06006866 VkFramebuffer fb;
6867 err = vkCreateFramebuffer(m_device->device(), &fci, nullptr, &fb);
6868 ASSERT_VK_SUCCESS(err);
6869
6870 // Just use default renderpass with our framebuffer
6871 m_renderPassBeginInfo.framebuffer = fb;
6872 // Create Null cmd buffer for submit
6873 BeginCommandBuffer();
6874 EndCommandBuffer();
6875 // Destroy image attached to framebuffer to invalidate cmd buffer
6876 vkDestroyImage(m_device->device(), image, NULL);
6877 // Now attempt to submit cmd buffer and verify error
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006878 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " that is invalid because bound image ");
Tobin Ehlis59f68ab2016-09-06 21:59:07 -06006879 QueueCommandBuffer(false);
6880 m_errorMonitor->VerifyFound();
6881
6882 vkDestroyFramebuffer(m_device->device(), fb, nullptr);
6883 vkDestroyImageView(m_device->device(), view, nullptr);
6884 vkFreeMemory(m_device->device(), image_memory, nullptr);
6885}
6886
Mark Lobodzinskia4df3632016-07-14 09:57:41 -06006887TEST_F(VkLayerTest, ImageMemoryNotBound) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006888 TEST_DESCRIPTION("Attempt to draw with an image which has not had memory bound to it.");
Mark Lobodzinskia4df3632016-07-14 09:57:41 -06006889 ASSERT_NO_FATAL_FAILURE(InitState());
6890
6891 VkImage image;
6892 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
6893 VkImageCreateInfo image_create_info = {};
6894 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
6895 image_create_info.pNext = NULL;
6896 image_create_info.imageType = VK_IMAGE_TYPE_2D;
6897 image_create_info.format = tex_format;
6898 image_create_info.extent.width = 32;
6899 image_create_info.extent.height = 32;
6900 image_create_info.extent.depth = 1;
6901 image_create_info.mipLevels = 1;
6902 image_create_info.arrayLayers = 1;
6903 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
6904 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006905 image_create_info.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT;
Mark Lobodzinskia4df3632016-07-14 09:57:41 -06006906 image_create_info.flags = 0;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006907 VkResult err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
Mark Lobodzinskia4df3632016-07-14 09:57:41 -06006908 ASSERT_VK_SUCCESS(err);
6909 // Have to bind memory to image before recording cmd in cmd buffer using it
6910 VkMemoryRequirements mem_reqs;
6911 VkDeviceMemory image_mem;
6912 bool pass;
6913 VkMemoryAllocateInfo mem_alloc = {};
6914 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
6915 mem_alloc.pNext = NULL;
6916 mem_alloc.memoryTypeIndex = 0;
6917 vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs);
6918 mem_alloc.allocationSize = mem_reqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006919 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0);
Mark Lobodzinskia4df3632016-07-14 09:57:41 -06006920 ASSERT_TRUE(pass);
6921 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &image_mem);
6922 ASSERT_VK_SUCCESS(err);
6923
6924 // Introduce error, do not call vkBindImageMemory(m_device->device(), image,
6925 // image_mem, 0);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006926 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "used without first calling vkBindImageMemory");
Mark Lobodzinskia4df3632016-07-14 09:57:41 -06006927
6928 m_commandBuffer->BeginCommandBuffer();
6929 VkClearColorValue ccv;
6930 ccv.float32[0] = 1.0f;
6931 ccv.float32[1] = 1.0f;
6932 ccv.float32[2] = 1.0f;
6933 ccv.float32[3] = 1.0f;
6934 VkImageSubresourceRange isr = {};
6935 isr.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
6936 isr.baseArrayLayer = 0;
6937 isr.baseMipLevel = 0;
6938 isr.layerCount = 1;
6939 isr.levelCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006940 vkCmdClearColorImage(m_commandBuffer->GetBufferHandle(), image, VK_IMAGE_LAYOUT_GENERAL, &ccv, 1, &isr);
Mark Lobodzinskia4df3632016-07-14 09:57:41 -06006941 m_commandBuffer->EndCommandBuffer();
6942
6943 m_errorMonitor->VerifyFound();
6944 vkDestroyImage(m_device->device(), image, NULL);
6945 vkFreeMemory(m_device->device(), image_mem, nullptr);
6946}
6947
6948TEST_F(VkLayerTest, BufferMemoryNotBound) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006949 TEST_DESCRIPTION("Attempt to copy from a buffer which has not had memory bound to it.");
Mark Lobodzinskia4df3632016-07-14 09:57:41 -06006950 ASSERT_NO_FATAL_FAILURE(InitState());
6951
6952 VkImageObj image(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006953 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 -06006954 VK_IMAGE_TILING_OPTIMAL, 0);
6955 ASSERT_TRUE(image.initialized());
6956
6957 VkBuffer buffer;
6958 VkDeviceMemory mem;
6959 VkMemoryRequirements mem_reqs;
6960
6961 VkBufferCreateInfo buf_info = {};
6962 buf_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
6963 buf_info.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
6964 buf_info.size = 256;
6965 buf_info.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
6966 VkResult err = vkCreateBuffer(m_device->device(), &buf_info, NULL, &buffer);
6967 ASSERT_VK_SUCCESS(err);
6968
6969 vkGetBufferMemoryRequirements(m_device->device(), buffer, &mem_reqs);
6970
6971 VkMemoryAllocateInfo alloc_info = {};
6972 alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
6973 alloc_info.allocationSize = 256;
6974 bool pass = false;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006975 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 -06006976 if (!pass) {
6977 vkDestroyBuffer(m_device->device(), buffer, NULL);
6978 return;
6979 }
6980 err = vkAllocateMemory(m_device->device(), &alloc_info, NULL, &mem);
6981 ASSERT_VK_SUCCESS(err);
6982
6983 // Introduce failure by not calling vkBindBufferMemory(m_device->device(),
6984 // buffer, mem, 0);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006985 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "used without first calling vkBindBufferMemory");
Mark Lobodzinskia4df3632016-07-14 09:57:41 -06006986 VkBufferImageCopy region = {};
6987 region.bufferRowLength = 128;
6988 region.bufferImageHeight = 128;
6989 region.imageSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
6990
6991 region.imageSubresource.layerCount = 1;
6992 region.imageExtent.height = 4;
6993 region.imageExtent.width = 4;
6994 region.imageExtent.depth = 1;
6995 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006996 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer, image.handle(), VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1,
6997 &region);
Mark Lobodzinskia4df3632016-07-14 09:57:41 -06006998 m_commandBuffer->EndCommandBuffer();
6999
7000 m_errorMonitor->VerifyFound();
7001
7002 vkDestroyBuffer(m_device->device(), buffer, NULL);
7003 vkFreeMemory(m_device->handle(), mem, NULL);
7004}
7005
Tobin Ehlis85940f52016-07-07 16:57:21 -06007006TEST_F(VkLayerTest, InvalidCmdBufferEventDestroyed) {
7007 TEST_DESCRIPTION("Attempt to draw with a command buffer that is invalid "
7008 "due to an event dependency being destroyed.");
7009 ASSERT_NO_FATAL_FAILURE(InitState());
7010
7011 VkEvent event;
7012 VkEventCreateInfo evci = {};
7013 evci.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO;
7014 VkResult result = vkCreateEvent(m_device->device(), &evci, NULL, &event);
7015 ASSERT_VK_SUCCESS(result);
7016
7017 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007018 vkCmdSetEvent(m_commandBuffer->GetBufferHandle(), event, VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT);
Tobin Ehlis85940f52016-07-07 16:57:21 -06007019 m_commandBuffer->EndCommandBuffer();
7020
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007021 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " that is invalid because bound event ");
Tobin Ehlis85940f52016-07-07 16:57:21 -06007022 // Destroy event dependency prior to submit to cause ERROR
7023 vkDestroyEvent(m_device->device(), event, NULL);
7024
7025 VkSubmitInfo submit_info = {};
7026 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
7027 submit_info.commandBufferCount = 1;
7028 submit_info.pCommandBuffers = &m_commandBuffer->handle();
7029 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
7030
7031 m_errorMonitor->VerifyFound();
7032}
7033
Tobin Ehlisdbea7552016-07-08 14:33:31 -06007034TEST_F(VkLayerTest, InvalidCmdBufferQueryPoolDestroyed) {
7035 TEST_DESCRIPTION("Attempt to draw with a command buffer that is invalid "
7036 "due to a query pool dependency being destroyed.");
7037 ASSERT_NO_FATAL_FAILURE(InitState());
7038
7039 VkQueryPool query_pool;
7040 VkQueryPoolCreateInfo qpci{};
7041 qpci.sType = VK_STRUCTURE_TYPE_QUERY_POOL_CREATE_INFO;
7042 qpci.queryType = VK_QUERY_TYPE_TIMESTAMP;
7043 qpci.queryCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007044 VkResult result = vkCreateQueryPool(m_device->device(), &qpci, nullptr, &query_pool);
Tobin Ehlisdbea7552016-07-08 14:33:31 -06007045 ASSERT_VK_SUCCESS(result);
7046
7047 m_commandBuffer->BeginCommandBuffer();
7048 vkCmdResetQueryPool(m_commandBuffer->GetBufferHandle(), query_pool, 0, 1);
7049 m_commandBuffer->EndCommandBuffer();
7050
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007051 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " that is invalid because bound query pool ");
Tobin Ehlisdbea7552016-07-08 14:33:31 -06007052 // Destroy query pool dependency prior to submit to cause ERROR
7053 vkDestroyQueryPool(m_device->device(), query_pool, NULL);
7054
7055 VkSubmitInfo submit_info = {};
7056 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
7057 submit_info.commandBufferCount = 1;
7058 submit_info.pCommandBuffers = &m_commandBuffer->handle();
7059 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
7060
7061 m_errorMonitor->VerifyFound();
7062}
7063
Tobin Ehlis24130d92016-07-08 15:50:53 -06007064TEST_F(VkLayerTest, InvalidCmdBufferPipelineDestroyed) {
7065 TEST_DESCRIPTION("Attempt to draw with a command buffer that is invalid "
7066 "due to a pipeline dependency being destroyed.");
7067 ASSERT_NO_FATAL_FAILURE(InitState());
7068 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
7069
7070 VkResult err;
7071
7072 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
7073 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
7074
7075 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007076 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis24130d92016-07-08 15:50:53 -06007077 ASSERT_VK_SUCCESS(err);
7078
7079 VkPipelineViewportStateCreateInfo vp_state_ci = {};
7080 vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
7081 vp_state_ci.viewportCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007082 VkViewport vp = {}; // Just need dummy vp to point to
Tobin Ehlis52b504f2016-07-19 13:25:12 -06007083 vp_state_ci.pViewports = &vp;
Tobin Ehlis24130d92016-07-08 15:50:53 -06007084 vp_state_ci.scissorCount = 1;
7085 VkRect2D scissors = {}; // Dummy scissors to point to
7086 vp_state_ci.pScissors = &scissors;
7087 // No dynamic state
7088 VkPipelineDynamicStateCreateInfo dyn_state_ci = {};
7089 dyn_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_DYNAMIC_STATE_CREATE_INFO;
7090
7091 VkPipelineShaderStageCreateInfo shaderStages[2];
7092 memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo));
7093
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007094 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
7095 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this); // We shouldn't need a fragment shader
7096 // but add it to be able to run on more devices
Tobin Ehlis24130d92016-07-08 15:50:53 -06007097 shaderStages[0] = vs.GetStageCreateInfo();
7098 shaderStages[1] = fs.GetStageCreateInfo();
7099
7100 VkPipelineVertexInputStateCreateInfo vi_ci = {};
7101 vi_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
7102
7103 VkPipelineInputAssemblyStateCreateInfo ia_ci = {};
7104 ia_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
7105 ia_ci.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP;
7106
7107 VkPipelineRasterizationStateCreateInfo rs_ci = {};
7108 rs_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
7109
7110 VkPipelineColorBlendAttachmentState att = {};
7111 att.blendEnable = VK_FALSE;
7112 att.colorWriteMask = 0xf;
7113
7114 VkPipelineColorBlendStateCreateInfo cb_ci = {};
7115 cb_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO;
7116 cb_ci.attachmentCount = 1;
7117 cb_ci.pAttachments = &att;
7118
7119 VkGraphicsPipelineCreateInfo gp_ci = {};
7120 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
7121 gp_ci.stageCount = 2;
7122 gp_ci.pStages = shaderStages;
7123 gp_ci.pVertexInputState = &vi_ci;
7124 gp_ci.pInputAssemblyState = &ia_ci;
7125 gp_ci.pViewportState = &vp_state_ci;
7126 gp_ci.pRasterizationState = &rs_ci;
7127 gp_ci.pColorBlendState = &cb_ci;
7128 gp_ci.pDynamicState = &dyn_state_ci;
7129 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
7130 gp_ci.layout = pipeline_layout;
7131 gp_ci.renderPass = renderPass();
7132
7133 VkPipelineCacheCreateInfo pc_ci = {};
7134 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
7135
7136 VkPipeline pipeline;
7137 VkPipelineCache pipelineCache;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007138 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Tobin Ehlis24130d92016-07-08 15:50:53 -06007139 ASSERT_VK_SUCCESS(err);
7140
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007141 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Tobin Ehlis24130d92016-07-08 15:50:53 -06007142 ASSERT_VK_SUCCESS(err);
7143
7144 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007145 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline);
Tobin Ehlis24130d92016-07-08 15:50:53 -06007146 m_commandBuffer->EndCommandBuffer();
7147 // Now destroy pipeline in order to cause error when submitting
7148 vkDestroyPipeline(m_device->device(), pipeline, nullptr);
7149
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007150 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " that is invalid because bound pipeline ");
Tobin Ehlis24130d92016-07-08 15:50:53 -06007151
7152 VkSubmitInfo submit_info = {};
7153 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
7154 submit_info.commandBufferCount = 1;
7155 submit_info.pCommandBuffers = &m_commandBuffer->handle();
7156 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
7157
7158 m_errorMonitor->VerifyFound();
7159 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
7160 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
7161}
7162
Tobin Ehlis31289162016-08-17 14:57:58 -06007163TEST_F(VkLayerTest, InvalidCmdBufferDescriptorSetBufferDestroyed) {
7164 TEST_DESCRIPTION("Attempt to draw with a command buffer that is invalid "
7165 "due to a bound descriptor set with a buffer dependency "
7166 "being destroyed.");
7167 ASSERT_NO_FATAL_FAILURE(InitState());
7168 ASSERT_NO_FATAL_FAILURE(InitViewport());
7169 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
7170
7171 VkDescriptorPoolSize ds_type_count = {};
7172 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
7173 ds_type_count.descriptorCount = 1;
7174
7175 VkDescriptorPoolCreateInfo ds_pool_ci = {};
7176 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
7177 ds_pool_ci.pNext = NULL;
7178 ds_pool_ci.maxSets = 1;
7179 ds_pool_ci.poolSizeCount = 1;
7180 ds_pool_ci.pPoolSizes = &ds_type_count;
7181
7182 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007183 VkResult err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis31289162016-08-17 14:57:58 -06007184 ASSERT_VK_SUCCESS(err);
7185
7186 VkDescriptorSetLayoutBinding dsl_binding = {};
7187 dsl_binding.binding = 0;
7188 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
7189 dsl_binding.descriptorCount = 1;
7190 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
7191 dsl_binding.pImmutableSamplers = NULL;
7192
7193 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
7194 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
7195 ds_layout_ci.pNext = NULL;
7196 ds_layout_ci.bindingCount = 1;
7197 ds_layout_ci.pBindings = &dsl_binding;
7198 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007199 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis31289162016-08-17 14:57:58 -06007200 ASSERT_VK_SUCCESS(err);
7201
7202 VkDescriptorSet descriptorSet;
7203 VkDescriptorSetAllocateInfo alloc_info = {};
7204 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
7205 alloc_info.descriptorSetCount = 1;
7206 alloc_info.descriptorPool = ds_pool;
7207 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007208 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis31289162016-08-17 14:57:58 -06007209 ASSERT_VK_SUCCESS(err);
7210
7211 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
7212 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
7213 pipeline_layout_ci.pNext = NULL;
7214 pipeline_layout_ci.setLayoutCount = 1;
7215 pipeline_layout_ci.pSetLayouts = &ds_layout;
7216
7217 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007218 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis31289162016-08-17 14:57:58 -06007219 ASSERT_VK_SUCCESS(err);
7220
7221 // Create a buffer to update the descriptor with
7222 uint32_t qfi = 0;
7223 VkBufferCreateInfo buffCI = {};
7224 buffCI.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
7225 buffCI.size = 1024;
7226 buffCI.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
7227 buffCI.queueFamilyIndexCount = 1;
7228 buffCI.pQueueFamilyIndices = &qfi;
7229
7230 VkBuffer buffer;
7231 err = vkCreateBuffer(m_device->device(), &buffCI, NULL, &buffer);
7232 ASSERT_VK_SUCCESS(err);
7233 // Allocate memory and bind to buffer so we can make it to the appropriate
7234 // error
7235 VkMemoryAllocateInfo mem_alloc = {};
7236 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
7237 mem_alloc.pNext = NULL;
7238 mem_alloc.allocationSize = 1024;
7239 mem_alloc.memoryTypeIndex = 0;
7240
7241 VkMemoryRequirements memReqs;
7242 vkGetBufferMemoryRequirements(m_device->device(), buffer, &memReqs);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007243 bool pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &mem_alloc, 0);
Tobin Ehlis31289162016-08-17 14:57:58 -06007244 if (!pass) {
7245 vkDestroyBuffer(m_device->device(), buffer, NULL);
7246 return;
7247 }
7248
7249 VkDeviceMemory mem;
7250 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem);
7251 ASSERT_VK_SUCCESS(err);
7252 err = vkBindBufferMemory(m_device->device(), buffer, mem, 0);
7253 ASSERT_VK_SUCCESS(err);
7254 // Correctly update descriptor to avoid "NOT_UPDATED" error
7255 VkDescriptorBufferInfo buffInfo = {};
7256 buffInfo.buffer = buffer;
7257 buffInfo.offset = 0;
7258 buffInfo.range = 1024;
7259
7260 VkWriteDescriptorSet descriptor_write;
7261 memset(&descriptor_write, 0, sizeof(descriptor_write));
7262 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
7263 descriptor_write.dstSet = descriptorSet;
7264 descriptor_write.dstBinding = 0;
7265 descriptor_write.descriptorCount = 1;
7266 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
7267 descriptor_write.pBufferInfo = &buffInfo;
7268
7269 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
7270
7271 // Create PSO to be used for draw-time errors below
7272 char const *vsSource = "#version 450\n"
7273 "\n"
7274 "out gl_PerVertex { \n"
7275 " vec4 gl_Position;\n"
7276 "};\n"
7277 "void main(){\n"
7278 " gl_Position = vec4(1);\n"
7279 "}\n";
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007280 char const *fsSource = "#version 450\n"
7281 "\n"
7282 "layout(location=0) out vec4 x;\n"
7283 "layout(set=0) layout(binding=0) uniform foo { int x; int y; } bar;\n"
7284 "void main(){\n"
7285 " x = vec4(bar.y);\n"
7286 "}\n";
Tobin Ehlis31289162016-08-17 14:57:58 -06007287 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
7288 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
7289 VkPipelineObj pipe(m_device);
7290 pipe.AddShader(&vs);
7291 pipe.AddShader(&fs);
7292 pipe.AddColorAttachment();
7293 pipe.CreateVKPipeline(pipeline_layout, renderPass());
7294
7295 BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007296 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
7297 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
7298 &descriptorSet, 0, NULL);
Tobin Ehlis31289162016-08-17 14:57:58 -06007299 Draw(1, 0, 0, 0);
7300 EndCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007301 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " that is invalid because bound buffer ");
Tobin Ehlis31289162016-08-17 14:57:58 -06007302 // Destroy buffer should invalidate the cmd buffer, causing error on submit
7303 vkDestroyBuffer(m_device->device(), buffer, NULL);
7304 // Attempt to submit cmd buffer
7305 VkSubmitInfo submit_info = {};
7306 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
7307 submit_info.commandBufferCount = 1;
7308 submit_info.pCommandBuffers = &m_commandBuffer->handle();
7309 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
7310 m_errorMonitor->VerifyFound();
7311 // Cleanup
7312 vkFreeMemory(m_device->device(), mem, NULL);
7313
7314 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
7315 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
7316 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
7317}
7318
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06007319TEST_F(VkLayerTest, InvalidCmdBufferDescriptorSetImageSamplerDestroyed) {
7320 TEST_DESCRIPTION("Attempt to draw with a command buffer that is invalid "
7321 "due to a bound descriptor sets with a combined image "
7322 "sampler having their image, sampler, and descriptor set "
7323 "each respectively destroyed and then attempting to "
Mark Mueller917f6bc2016-08-30 10:57:19 -06007324 "submit associated cmd buffers. Attempt to destroy a "
7325 "DescriptorSet that is in use.");
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06007326 ASSERT_NO_FATAL_FAILURE(InitState());
7327 ASSERT_NO_FATAL_FAILURE(InitViewport());
7328 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
7329
7330 VkDescriptorPoolSize ds_type_count = {};
7331 ds_type_count.type = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
7332 ds_type_count.descriptorCount = 1;
7333
7334 VkDescriptorPoolCreateInfo ds_pool_ci = {};
7335 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
7336 ds_pool_ci.pNext = NULL;
7337 ds_pool_ci.maxSets = 1;
7338 ds_pool_ci.poolSizeCount = 1;
7339 ds_pool_ci.pPoolSizes = &ds_type_count;
7340
7341 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007342 VkResult err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06007343 ASSERT_VK_SUCCESS(err);
7344
7345 VkDescriptorSetLayoutBinding dsl_binding = {};
7346 dsl_binding.binding = 0;
7347 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
7348 dsl_binding.descriptorCount = 1;
7349 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
7350 dsl_binding.pImmutableSamplers = NULL;
7351
7352 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
7353 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
7354 ds_layout_ci.pNext = NULL;
7355 ds_layout_ci.bindingCount = 1;
7356 ds_layout_ci.pBindings = &dsl_binding;
7357 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007358 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06007359 ASSERT_VK_SUCCESS(err);
7360
7361 VkDescriptorSet descriptorSet;
7362 VkDescriptorSetAllocateInfo alloc_info = {};
7363 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
7364 alloc_info.descriptorSetCount = 1;
7365 alloc_info.descriptorPool = ds_pool;
7366 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007367 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06007368 ASSERT_VK_SUCCESS(err);
7369
7370 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
7371 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
7372 pipeline_layout_ci.pNext = NULL;
7373 pipeline_layout_ci.setLayoutCount = 1;
7374 pipeline_layout_ci.pSetLayouts = &ds_layout;
7375
7376 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007377 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06007378 ASSERT_VK_SUCCESS(err);
7379
7380 // Create images to update the descriptor with
7381 VkImage image;
7382 VkImage image2;
7383 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
7384 const int32_t tex_width = 32;
7385 const int32_t tex_height = 32;
7386 VkImageCreateInfo image_create_info = {};
7387 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
7388 image_create_info.pNext = NULL;
7389 image_create_info.imageType = VK_IMAGE_TYPE_2D;
7390 image_create_info.format = tex_format;
7391 image_create_info.extent.width = tex_width;
7392 image_create_info.extent.height = tex_height;
7393 image_create_info.extent.depth = 1;
7394 image_create_info.mipLevels = 1;
7395 image_create_info.arrayLayers = 1;
7396 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
7397 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
7398 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
7399 image_create_info.flags = 0;
7400 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
7401 ASSERT_VK_SUCCESS(err);
7402 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image2);
7403 ASSERT_VK_SUCCESS(err);
7404
7405 VkMemoryRequirements memory_reqs;
7406 VkDeviceMemory image_memory;
7407 bool pass;
7408 VkMemoryAllocateInfo memory_info = {};
7409 memory_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
7410 memory_info.pNext = NULL;
7411 memory_info.allocationSize = 0;
7412 memory_info.memoryTypeIndex = 0;
7413 vkGetImageMemoryRequirements(m_device->device(), image, &memory_reqs);
7414 // Allocate enough memory for both images
7415 memory_info.allocationSize = memory_reqs.size * 2;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007416 pass = m_device->phy().set_memory_type(memory_reqs.memoryTypeBits, &memory_info, 0);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06007417 ASSERT_TRUE(pass);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007418 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &image_memory);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06007419 ASSERT_VK_SUCCESS(err);
7420 err = vkBindImageMemory(m_device->device(), image, image_memory, 0);
7421 ASSERT_VK_SUCCESS(err);
7422 // Bind second image to memory right after first image
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007423 err = vkBindImageMemory(m_device->device(), image2, image_memory, memory_reqs.size);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06007424 ASSERT_VK_SUCCESS(err);
7425
7426 VkImageViewCreateInfo image_view_create_info = {};
7427 image_view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
7428 image_view_create_info.image = image;
7429 image_view_create_info.viewType = VK_IMAGE_VIEW_TYPE_2D;
7430 image_view_create_info.format = tex_format;
7431 image_view_create_info.subresourceRange.layerCount = 1;
7432 image_view_create_info.subresourceRange.baseMipLevel = 0;
7433 image_view_create_info.subresourceRange.levelCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007434 image_view_create_info.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06007435
7436 VkImageView view;
7437 VkImageView view2;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007438 err = vkCreateImageView(m_device->device(), &image_view_create_info, NULL, &view);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06007439 ASSERT_VK_SUCCESS(err);
7440 image_view_create_info.image = image2;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007441 err = vkCreateImageView(m_device->device(), &image_view_create_info, NULL, &view2);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06007442 ASSERT_VK_SUCCESS(err);
7443 // Create Samplers
7444 VkSamplerCreateInfo sampler_ci = {};
7445 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
7446 sampler_ci.pNext = NULL;
7447 sampler_ci.magFilter = VK_FILTER_NEAREST;
7448 sampler_ci.minFilter = VK_FILTER_NEAREST;
7449 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
7450 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
7451 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
7452 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
7453 sampler_ci.mipLodBias = 1.0;
7454 sampler_ci.anisotropyEnable = VK_FALSE;
7455 sampler_ci.maxAnisotropy = 1;
7456 sampler_ci.compareEnable = VK_FALSE;
7457 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
7458 sampler_ci.minLod = 1.0;
7459 sampler_ci.maxLod = 1.0;
7460 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
7461 sampler_ci.unnormalizedCoordinates = VK_FALSE;
7462 VkSampler sampler;
7463 VkSampler sampler2;
7464 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
7465 ASSERT_VK_SUCCESS(err);
7466 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler2);
7467 ASSERT_VK_SUCCESS(err);
7468 // Update descriptor with image and sampler
7469 VkDescriptorImageInfo img_info = {};
7470 img_info.sampler = sampler;
7471 img_info.imageView = view;
7472 img_info.imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
7473
7474 VkWriteDescriptorSet descriptor_write;
7475 memset(&descriptor_write, 0, sizeof(descriptor_write));
7476 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
7477 descriptor_write.dstSet = descriptorSet;
7478 descriptor_write.dstBinding = 0;
7479 descriptor_write.descriptorCount = 1;
7480 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
7481 descriptor_write.pImageInfo = &img_info;
7482
7483 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
7484
7485 // Create PSO to be used for draw-time errors below
7486 char const *vsSource = "#version 450\n"
7487 "\n"
7488 "out gl_PerVertex { \n"
7489 " vec4 gl_Position;\n"
7490 "};\n"
7491 "void main(){\n"
7492 " gl_Position = vec4(1);\n"
7493 "}\n";
7494 char const *fsSource = "#version 450\n"
7495 "\n"
7496 "layout(set=0, binding=0) uniform sampler2D s;\n"
7497 "layout(location=0) out vec4 x;\n"
7498 "void main(){\n"
7499 " x = texture(s, vec2(1));\n"
7500 "}\n";
7501 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
7502 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
7503 VkPipelineObj pipe(m_device);
7504 pipe.AddShader(&vs);
7505 pipe.AddShader(&fs);
7506 pipe.AddColorAttachment();
7507 pipe.CreateVKPipeline(pipeline_layout, renderPass());
7508
7509 // First error case is destroying sampler prior to cmd buffer submission
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007510 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Cannot submit cmd buffer using deleted sampler ");
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06007511 BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007512 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
7513 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
7514 &descriptorSet, 0, NULL);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06007515 Draw(1, 0, 0, 0);
7516 EndCommandBuffer();
7517 // Destroy sampler invalidates the cmd buffer, causing error on submit
7518 vkDestroySampler(m_device->device(), sampler, NULL);
7519 // Attempt to submit cmd buffer
7520 VkSubmitInfo submit_info = {};
7521 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
7522 submit_info.commandBufferCount = 1;
7523 submit_info.pCommandBuffers = &m_commandBuffer->handle();
7524 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
7525 m_errorMonitor->VerifyFound();
7526 // Now re-update descriptor with valid sampler and delete image
7527 img_info.sampler = sampler2;
7528 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007529 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " that is invalid because bound image ");
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06007530 BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007531 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
7532 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
7533 &descriptorSet, 0, NULL);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06007534 Draw(1, 0, 0, 0);
7535 EndCommandBuffer();
7536 // Destroy image invalidates the cmd buffer, causing error on submit
7537 vkDestroyImage(m_device->device(), image, NULL);
7538 // Attempt to submit cmd buffer
7539 submit_info = {};
7540 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
7541 submit_info.commandBufferCount = 1;
7542 submit_info.pCommandBuffers = &m_commandBuffer->handle();
7543 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
7544 m_errorMonitor->VerifyFound();
7545 // Now update descriptor to be valid, but then free descriptor
7546 img_info.imageView = view2;
7547 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007548 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " that is invalid because bound descriptor set ");
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06007549 BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007550 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
7551 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
7552 &descriptorSet, 0, NULL);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06007553 Draw(1, 0, 0, 0);
7554 EndCommandBuffer();
7555 // Destroy descriptor set invalidates the cb, causing error on submit
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007556 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Cannot call vkFreeDescriptorSets() on descriptor set 0x");
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06007557 vkFreeDescriptorSets(m_device->device(), ds_pool, 1, &descriptorSet);
Mark Mueller917f6bc2016-08-30 10:57:19 -06007558 m_errorMonitor->VerifyFound();
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06007559 // Attempt to submit cmd buffer
7560 submit_info = {};
7561 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
7562 submit_info.commandBufferCount = 1;
7563 submit_info.pCommandBuffers = &m_commandBuffer->handle();
7564 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
7565 m_errorMonitor->VerifyFound();
7566 // Cleanup
7567 vkFreeMemory(m_device->device(), image_memory, NULL);
7568 vkDestroySampler(m_device->device(), sampler2, NULL);
7569 vkDestroyImage(m_device->device(), image2, NULL);
7570 vkDestroyImageView(m_device->device(), view, NULL);
7571 vkDestroyImageView(m_device->device(), view2, NULL);
7572 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
7573 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
7574 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
7575}
7576
Karl Schultz6addd812016-02-02 17:17:23 -07007577TEST_F(VkLayerTest, InvalidPipeline) {
Karl Schultzbdb75952016-04-19 11:36:49 -06007578 // Attempt to bind an invalid Pipeline to a valid Command Buffer
7579 // ObjectTracker should catch this.
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06007580 // Create a valid cmd buffer
7581 // call vkCmdBindPipeline w/ false Pipeline
Mark Lobodzinski02bf89d2016-05-10 14:45:13 -06007582 uint64_t fake_pipeline_handle = 0xbaad6001;
7583 VkPipeline bad_pipeline = reinterpret_cast<VkPipeline &>(fake_pipeline_handle);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007584 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Invalid Pipeline Object 0xbaad6001");
Karl Schultzbdb75952016-04-19 11:36:49 -06007585 ASSERT_NO_FATAL_FAILURE(InitState());
7586 BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007587 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, bad_pipeline);
Karl Schultzbdb75952016-04-19 11:36:49 -06007588 m_errorMonitor->VerifyFound();
Tobin Ehlisb8b6b272016-05-02 13:26:06 -06007589 // Now issue a draw call with no pipeline bound
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007590 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 -06007591
Tobin Ehlisb8b6b272016-05-02 13:26:06 -06007592 BeginCommandBuffer();
7593 Draw(1, 0, 0, 0);
7594 m_errorMonitor->VerifyFound();
7595 // Finally same check once more but with Dispatch/Compute
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007596 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 -06007597 BeginCommandBuffer();
7598 vkCmdDispatch(m_commandBuffer->GetBufferHandle(), 0, 0, 0);
7599 m_errorMonitor->VerifyFound();
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06007600}
7601
Karl Schultz6addd812016-02-02 17:17:23 -07007602TEST_F(VkLayerTest, DescriptorSetNotUpdated) {
Tobin Ehlis5a5f5ef2016-08-17 13:56:55 -06007603 TEST_DESCRIPTION("Bind a descriptor set that hasn't been updated.");
Karl Schultz6addd812016-02-02 17:17:23 -07007604 VkResult err;
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06007605
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007606 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT, " bound but it was never updated. ");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06007607
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06007608 ASSERT_NO_FATAL_FAILURE(InitState());
Mike Stroyan713b2d72015-08-04 10:49:29 -06007609 ASSERT_NO_FATAL_FAILURE(InitViewport());
7610 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chia-I Wu1b99bb22015-10-27 19:25:11 +08007611 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007612 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
7613 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -06007614
7615 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007616 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
7617 ds_pool_ci.pNext = NULL;
7618 ds_pool_ci.maxSets = 1;
7619 ds_pool_ci.poolSizeCount = 1;
7620 ds_pool_ci.pPoolSizes = &ds_type_count;
Mike Stroyan713b2d72015-08-04 10:49:29 -06007621
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06007622 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007623 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06007624 ASSERT_VK_SUCCESS(err);
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06007625
Tony Barboureb254902015-07-15 12:50:33 -06007626 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007627 dsl_binding.binding = 0;
7628 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
7629 dsl_binding.descriptorCount = 1;
7630 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
7631 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06007632
Tony Barboureb254902015-07-15 12:50:33 -06007633 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007634 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
7635 ds_layout_ci.pNext = NULL;
7636 ds_layout_ci.bindingCount = 1;
7637 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06007638 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007639 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06007640 ASSERT_VK_SUCCESS(err);
7641
7642 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08007643 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08007644 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07007645 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06007646 alloc_info.descriptorPool = ds_pool;
7647 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007648 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06007649 ASSERT_VK_SUCCESS(err);
7650
Tony Barboureb254902015-07-15 12:50:33 -06007651 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007652 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
7653 pipeline_layout_ci.pNext = NULL;
7654 pipeline_layout_ci.setLayoutCount = 1;
7655 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06007656
7657 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007658 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06007659 ASSERT_VK_SUCCESS(err);
7660
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007661 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
Karl Schultzbdb75952016-04-19 11:36:49 -06007662 // We shouldn't need a fragment shader but add it to be able to run
Karl Schultz6addd812016-02-02 17:17:23 -07007663 // on more devices
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007664 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06007665
Tony Barbourc95e4ac2015-08-04 17:05:26 -06007666 VkPipelineObj pipe(m_device);
7667 pipe.AddShader(&vs);
Tony Barbour1c94d372015-08-06 11:21:08 -06007668 pipe.AddShader(&fs);
Mark Youngc89c6312016-03-31 16:03:20 -06007669 pipe.AddColorAttachment();
Tony Barbourc95e4ac2015-08-04 17:05:26 -06007670 pipe.CreateVKPipeline(pipeline_layout, renderPass());
Tony Barbourfe3351b2015-07-28 10:17:20 -06007671
7672 BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007673 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
7674 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
7675 &descriptorSet, 0, NULL);
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06007676
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007677 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06007678
Chia-I Wuf7458c52015-10-26 21:10:41 +08007679 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
7680 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
7681 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06007682}
7683
Karl Schultz6addd812016-02-02 17:17:23 -07007684TEST_F(VkLayerTest, InvalidBufferViewObject) {
Tobin Ehlisba31cab2015-11-02 15:24:32 -07007685 // Create a single TEXEL_BUFFER descriptor and send it an invalid bufferView
Karl Schultz6addd812016-02-02 17:17:23 -07007686 VkResult err;
Tobin Ehlisba31cab2015-11-02 15:24:32 -07007687
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007688 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Attempted write update to texel buffer "
7689 "descriptor with invalid buffer view");
Tobin Ehlisba31cab2015-11-02 15:24:32 -07007690
7691 ASSERT_NO_FATAL_FAILURE(InitState());
7692 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007693 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER;
7694 ds_type_count.descriptorCount = 1;
Tobin Ehlisba31cab2015-11-02 15:24:32 -07007695
7696 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007697 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
7698 ds_pool_ci.pNext = NULL;
7699 ds_pool_ci.maxSets = 1;
7700 ds_pool_ci.poolSizeCount = 1;
7701 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlisba31cab2015-11-02 15:24:32 -07007702
7703 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007704 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlisba31cab2015-11-02 15:24:32 -07007705 ASSERT_VK_SUCCESS(err);
7706
7707 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007708 dsl_binding.binding = 0;
7709 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER;
7710 dsl_binding.descriptorCount = 1;
7711 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
7712 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlisba31cab2015-11-02 15:24:32 -07007713
7714 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007715 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
7716 ds_layout_ci.pNext = NULL;
7717 ds_layout_ci.bindingCount = 1;
7718 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlisba31cab2015-11-02 15:24:32 -07007719 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007720 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlisba31cab2015-11-02 15:24:32 -07007721 ASSERT_VK_SUCCESS(err);
7722
7723 VkDescriptorSet descriptorSet;
7724 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08007725 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07007726 alloc_info.descriptorSetCount = 1;
Tobin Ehlisba31cab2015-11-02 15:24:32 -07007727 alloc_info.descriptorPool = ds_pool;
7728 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007729 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlisba31cab2015-11-02 15:24:32 -07007730 ASSERT_VK_SUCCESS(err);
7731
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007732 VkBufferView view = (VkBufferView)((size_t)0xbaadbeef); // invalid bufferView object
Tobin Ehlisba31cab2015-11-02 15:24:32 -07007733 VkWriteDescriptorSet descriptor_write;
7734 memset(&descriptor_write, 0, sizeof(descriptor_write));
7735 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
7736 descriptor_write.dstSet = descriptorSet;
7737 descriptor_write.dstBinding = 0;
7738 descriptor_write.descriptorCount = 1;
7739 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER;
7740 descriptor_write.pTexelBufferView = &view;
7741
7742 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
7743
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007744 m_errorMonitor->VerifyFound();
Tobin Ehlisba31cab2015-11-02 15:24:32 -07007745
7746 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
7747 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
7748}
7749
Mark Youngd339ba32016-05-30 13:28:35 -06007750TEST_F(VkLayerTest, CreateBufferViewNoMemoryBoundToBuffer) {
7751 TEST_DESCRIPTION("Attempt to create a buffer view with a buffer that has"
7752 " no memory bound to it.");
7753
7754 VkResult err;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007755 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "used without first calling vkBindBufferMemory");
Mark Youngd339ba32016-05-30 13:28:35 -06007756
7757 ASSERT_NO_FATAL_FAILURE(InitState());
7758
7759 // Create a buffer with no bound memory and then attempt to create
7760 // a buffer view.
7761 VkBufferCreateInfo buff_ci = {};
7762 buff_ci.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
Chris Forbes4538d242016-09-13 18:13:58 +12007763 buff_ci.usage = VK_BUFFER_USAGE_UNIFORM_TEXEL_BUFFER_BIT;
Mark Youngd339ba32016-05-30 13:28:35 -06007764 buff_ci.size = 256;
7765 buff_ci.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
7766 VkBuffer buffer;
7767 err = vkCreateBuffer(m_device->device(), &buff_ci, NULL, &buffer);
7768 ASSERT_VK_SUCCESS(err);
7769
7770 VkBufferViewCreateInfo buff_view_ci = {};
7771 buff_view_ci.sType = VK_STRUCTURE_TYPE_BUFFER_VIEW_CREATE_INFO;
7772 buff_view_ci.buffer = buffer;
7773 buff_view_ci.format = VK_FORMAT_R8_UNORM;
7774 buff_view_ci.range = VK_WHOLE_SIZE;
7775 VkBufferView buff_view;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007776 err = vkCreateBufferView(m_device->device(), &buff_view_ci, NULL, &buff_view);
Mark Youngd339ba32016-05-30 13:28:35 -06007777
7778 m_errorMonitor->VerifyFound();
7779 vkDestroyBuffer(m_device->device(), buffer, NULL);
7780 // If last error is success, it still created the view, so delete it.
7781 if (err == VK_SUCCESS) {
7782 vkDestroyBufferView(m_device->device(), buff_view, NULL);
7783 }
7784}
7785
Karl Schultz6addd812016-02-02 17:17:23 -07007786TEST_F(VkLayerTest, InvalidDynamicOffsetCases) {
7787 // Create a descriptorSet w/ dynamic descriptor and then hit 3 offset error
7788 // cases:
Tobin Ehlisf6585052015-12-17 11:48:42 -07007789 // 1. No dynamicOffset supplied
7790 // 2. Too many dynamicOffsets supplied
7791 // 3. Dynamic offset oversteps buffer being updated
Karl Schultz6addd812016-02-02 17:17:23 -07007792 VkResult err;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007793 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " requires 1 dynamicOffsets, but only "
7794 "0 dynamicOffsets are left in "
7795 "pDynamicOffsets ");
Tobin Ehlis49f903e2015-11-04 13:30:34 -07007796
7797 ASSERT_NO_FATAL_FAILURE(InitState());
7798 ASSERT_NO_FATAL_FAILURE(InitViewport());
7799 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
7800
7801 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007802 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
7803 ds_type_count.descriptorCount = 1;
Tobin Ehlis49f903e2015-11-04 13:30:34 -07007804
7805 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007806 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
7807 ds_pool_ci.pNext = NULL;
7808 ds_pool_ci.maxSets = 1;
7809 ds_pool_ci.poolSizeCount = 1;
7810 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlis49f903e2015-11-04 13:30:34 -07007811
7812 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007813 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis49f903e2015-11-04 13:30:34 -07007814 ASSERT_VK_SUCCESS(err);
7815
7816 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007817 dsl_binding.binding = 0;
7818 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
7819 dsl_binding.descriptorCount = 1;
7820 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
7821 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis49f903e2015-11-04 13:30:34 -07007822
7823 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007824 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
7825 ds_layout_ci.pNext = NULL;
7826 ds_layout_ci.bindingCount = 1;
7827 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlis49f903e2015-11-04 13:30:34 -07007828 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007829 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis49f903e2015-11-04 13:30:34 -07007830 ASSERT_VK_SUCCESS(err);
7831
7832 VkDescriptorSet descriptorSet;
7833 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08007834 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07007835 alloc_info.descriptorSetCount = 1;
Tobin Ehlis49f903e2015-11-04 13:30:34 -07007836 alloc_info.descriptorPool = ds_pool;
7837 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007838 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis49f903e2015-11-04 13:30:34 -07007839 ASSERT_VK_SUCCESS(err);
7840
7841 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007842 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
7843 pipeline_layout_ci.pNext = NULL;
7844 pipeline_layout_ci.setLayoutCount = 1;
7845 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlis49f903e2015-11-04 13:30:34 -07007846
7847 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007848 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis49f903e2015-11-04 13:30:34 -07007849 ASSERT_VK_SUCCESS(err);
7850
7851 // Create a buffer to update the descriptor with
7852 uint32_t qfi = 0;
7853 VkBufferCreateInfo buffCI = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007854 buffCI.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
7855 buffCI.size = 1024;
7856 buffCI.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
7857 buffCI.queueFamilyIndexCount = 1;
7858 buffCI.pQueueFamilyIndices = &qfi;
Tobin Ehlis49f903e2015-11-04 13:30:34 -07007859
7860 VkBuffer dyub;
7861 err = vkCreateBuffer(m_device->device(), &buffCI, NULL, &dyub);
7862 ASSERT_VK_SUCCESS(err);
Tobin Ehlis0a43bde2016-05-03 08:31:08 -06007863 // Allocate memory and bind to buffer so we can make it to the appropriate
7864 // error
7865 VkMemoryAllocateInfo mem_alloc = {};
7866 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
7867 mem_alloc.pNext = NULL;
7868 mem_alloc.allocationSize = 1024;
Chris Forbesb6116cc2016-05-08 11:39:59 +12007869 mem_alloc.memoryTypeIndex = 0;
7870
7871 VkMemoryRequirements memReqs;
7872 vkGetBufferMemoryRequirements(m_device->device(), dyub, &memReqs);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007873 bool pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &mem_alloc, 0);
Chris Forbesb6116cc2016-05-08 11:39:59 +12007874 if (!pass) {
7875 vkDestroyBuffer(m_device->device(), dyub, NULL);
7876 return;
7877 }
7878
Tobin Ehlis0a43bde2016-05-03 08:31:08 -06007879 VkDeviceMemory mem;
7880 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem);
7881 ASSERT_VK_SUCCESS(err);
7882 err = vkBindBufferMemory(m_device->device(), dyub, mem, 0);
7883 ASSERT_VK_SUCCESS(err);
Tobin Ehlis49f903e2015-11-04 13:30:34 -07007884 // Correctly update descriptor to avoid "NOT_UPDATED" error
7885 VkDescriptorBufferInfo buffInfo = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007886 buffInfo.buffer = dyub;
7887 buffInfo.offset = 0;
7888 buffInfo.range = 1024;
Tobin Ehlis49f903e2015-11-04 13:30:34 -07007889
7890 VkWriteDescriptorSet descriptor_write;
7891 memset(&descriptor_write, 0, sizeof(descriptor_write));
7892 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
7893 descriptor_write.dstSet = descriptorSet;
7894 descriptor_write.dstBinding = 0;
7895 descriptor_write.descriptorCount = 1;
7896 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
7897 descriptor_write.pBufferInfo = &buffInfo;
7898
7899 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
7900
7901 BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007902 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
7903 &descriptorSet, 0, NULL);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007904 m_errorMonitor->VerifyFound();
Tobin Ehlisf6585052015-12-17 11:48:42 -07007905 uint32_t pDynOff[2] = {512, 756};
7906 // Now cause error b/c too many dynOffsets in array for # of dyn descriptors
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007907 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
7908 "Attempting to bind 1 descriptorSets with 1 dynamic descriptors, but ");
7909 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
7910 &descriptorSet, 2, pDynOff);
Chris Forbes7b342802016-04-07 13:20:10 +12007911 m_errorMonitor->VerifyFound();
Tobin Ehlisf6585052015-12-17 11:48:42 -07007912 // Finally cause error due to dynamicOffset being too big
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007913 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " dynamic offset 512 combined with "
7914 "offset 0 and range 1024 that "
7915 "oversteps the buffer size of 1024");
Tobin Ehlisf6585052015-12-17 11:48:42 -07007916 // Create PSO to be used for draw-time errors below
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007917 char const *vsSource = "#version 450\n"
7918 "\n"
7919 "out gl_PerVertex { \n"
7920 " vec4 gl_Position;\n"
7921 "};\n"
7922 "void main(){\n"
7923 " gl_Position = vec4(1);\n"
7924 "}\n";
7925 char const *fsSource = "#version 450\n"
7926 "\n"
7927 "layout(location=0) out vec4 x;\n"
7928 "layout(set=0) layout(binding=0) uniform foo { int x; int y; } bar;\n"
7929 "void main(){\n"
7930 " x = vec4(bar.y);\n"
7931 "}\n";
Tobin Ehlisf6585052015-12-17 11:48:42 -07007932 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
7933 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
7934 VkPipelineObj pipe(m_device);
7935 pipe.AddShader(&vs);
7936 pipe.AddShader(&fs);
7937 pipe.AddColorAttachment();
7938 pipe.CreateVKPipeline(pipeline_layout, renderPass());
7939
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007940 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Karl Schultz6addd812016-02-02 17:17:23 -07007941 // This update should succeed, but offset size of 512 will overstep buffer
7942 // /w range 1024 & size 1024
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007943 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
7944 &descriptorSet, 1, pDynOff);
Tobin Ehlisf6585052015-12-17 11:48:42 -07007945 Draw(1, 0, 0, 0);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007946 m_errorMonitor->VerifyFound();
Tobin Ehlis49f903e2015-11-04 13:30:34 -07007947
Tobin Ehlis0a43bde2016-05-03 08:31:08 -06007948 vkDestroyBuffer(m_device->device(), dyub, NULL);
Tobin Ehlis512098e2016-05-05 09:06:12 -06007949 vkFreeMemory(m_device->device(), mem, NULL);
Tobin Ehlis0a43bde2016-05-03 08:31:08 -06007950
Tobin Ehlis49f903e2015-11-04 13:30:34 -07007951 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
Tony Barbourdf4c0042016-06-01 15:55:43 -06007952 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
Tobin Ehlis49f903e2015-11-04 13:30:34 -07007953 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
7954}
7955
Tobin Ehlis8ef479c2016-07-20 16:14:49 -06007956TEST_F(VkLayerTest, DescriptorBufferUpdateNoMemoryBound) {
7957 TEST_DESCRIPTION("Attempt to update a descriptor with a non-sparse buffer "
7958 "that doesn't have memory bound");
7959 VkResult err;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007960 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " used without first calling vkBindBufferMemory.");
Tobin Ehlis8ef479c2016-07-20 16:14:49 -06007961
7962 ASSERT_NO_FATAL_FAILURE(InitState());
7963 ASSERT_NO_FATAL_FAILURE(InitViewport());
7964 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
7965
7966 VkDescriptorPoolSize ds_type_count = {};
7967 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
7968 ds_type_count.descriptorCount = 1;
7969
7970 VkDescriptorPoolCreateInfo ds_pool_ci = {};
7971 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
7972 ds_pool_ci.pNext = NULL;
7973 ds_pool_ci.maxSets = 1;
7974 ds_pool_ci.poolSizeCount = 1;
7975 ds_pool_ci.pPoolSizes = &ds_type_count;
7976
7977 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007978 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis8ef479c2016-07-20 16:14:49 -06007979 ASSERT_VK_SUCCESS(err);
7980
7981 VkDescriptorSetLayoutBinding dsl_binding = {};
7982 dsl_binding.binding = 0;
7983 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
7984 dsl_binding.descriptorCount = 1;
7985 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
7986 dsl_binding.pImmutableSamplers = NULL;
7987
7988 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
7989 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
7990 ds_layout_ci.pNext = NULL;
7991 ds_layout_ci.bindingCount = 1;
7992 ds_layout_ci.pBindings = &dsl_binding;
7993 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007994 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis8ef479c2016-07-20 16:14:49 -06007995 ASSERT_VK_SUCCESS(err);
7996
7997 VkDescriptorSet descriptorSet;
7998 VkDescriptorSetAllocateInfo alloc_info = {};
7999 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
8000 alloc_info.descriptorSetCount = 1;
8001 alloc_info.descriptorPool = ds_pool;
8002 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008003 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis8ef479c2016-07-20 16:14:49 -06008004 ASSERT_VK_SUCCESS(err);
8005
8006 // Create a buffer to update the descriptor with
8007 uint32_t qfi = 0;
8008 VkBufferCreateInfo buffCI = {};
8009 buffCI.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
8010 buffCI.size = 1024;
8011 buffCI.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
8012 buffCI.queueFamilyIndexCount = 1;
8013 buffCI.pQueueFamilyIndices = &qfi;
8014
8015 VkBuffer dyub;
8016 err = vkCreateBuffer(m_device->device(), &buffCI, NULL, &dyub);
8017 ASSERT_VK_SUCCESS(err);
8018
8019 // Attempt to update descriptor without binding memory to it
8020 VkDescriptorBufferInfo buffInfo = {};
8021 buffInfo.buffer = dyub;
8022 buffInfo.offset = 0;
8023 buffInfo.range = 1024;
8024
8025 VkWriteDescriptorSet descriptor_write;
8026 memset(&descriptor_write, 0, sizeof(descriptor_write));
8027 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
8028 descriptor_write.dstSet = descriptorSet;
8029 descriptor_write.dstBinding = 0;
8030 descriptor_write.descriptorCount = 1;
8031 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
8032 descriptor_write.pBufferInfo = &buffInfo;
8033
8034 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
8035 m_errorMonitor->VerifyFound();
8036
8037 vkDestroyBuffer(m_device->device(), dyub, NULL);
8038 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
8039 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
8040}
8041
Tobin Ehlis3a23b6a2016-02-17 10:35:18 -07008042TEST_F(VkLayerTest, InvalidPushConstants) {
Tobin Ehlis3a23b6a2016-02-17 10:35:18 -07008043 VkResult err;
Tobin Ehlis3a23b6a2016-02-17 10:35:18 -07008044 ASSERT_NO_FATAL_FAILURE(InitState());
8045 ASSERT_NO_FATAL_FAILURE(InitViewport());
8046 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
8047
Karl Schultzfc8eaf12016-05-06 13:56:42 -06008048 VkPipelineLayout pipeline_layout;
Tobin Ehlis3a23b6a2016-02-17 10:35:18 -07008049 VkPushConstantRange pc_range = {};
Tobin Ehlis3a23b6a2016-02-17 10:35:18 -07008050 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
8051 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
8052 pipeline_layout_ci.pushConstantRangeCount = 1;
8053 pipeline_layout_ci.pPushConstantRanges = &pc_range;
8054
Karl Schultzfc8eaf12016-05-06 13:56:42 -06008055 //
8056 // Check for invalid push constant ranges in pipeline layouts.
8057 //
8058 struct PipelineLayoutTestCase {
Karl Schultzc81037d2016-05-12 08:11:23 -06008059 VkPushConstantRange const range;
Karl Schultzfc8eaf12016-05-06 13:56:42 -06008060 char const *msg;
8061 };
Tobin Ehlis3a23b6a2016-02-17 10:35:18 -07008062
Karl Schultzc81037d2016-05-12 08:11:23 -06008063 const uint32_t too_big = m_device->props.limits.maxPushConstantsSize + 0x4;
8064 const std::array<PipelineLayoutTestCase, 10> range_tests = {{
8065 {{VK_SHADER_STAGE_VERTEX_BIT, 0, 0},
8066 "vkCreatePipelineLayout() call has push constants index 0 with "
8067 "size 0."},
8068 {{VK_SHADER_STAGE_VERTEX_BIT, 0, 1},
8069 "vkCreatePipelineLayout() call has push constants index 0 with "
8070 "size 1."},
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06008071 {{VK_SHADER_STAGE_VERTEX_BIT, 4, 1},
Karl Schultzc81037d2016-05-12 08:11:23 -06008072 "vkCreatePipelineLayout() call has push constants index 0 with "
8073 "size 1."},
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06008074 {{VK_SHADER_STAGE_VERTEX_BIT, 4, 0},
Karl Schultzc81037d2016-05-12 08:11:23 -06008075 "vkCreatePipelineLayout() call has push constants index 0 with "
8076 "size 0."},
8077 {{VK_SHADER_STAGE_VERTEX_BIT, 1, 4},
8078 "vkCreatePipelineLayout() call has push constants index 0 with "
8079 "offset 1. Offset must"},
8080 {{VK_SHADER_STAGE_VERTEX_BIT, 0, too_big},
8081 "vkCreatePipelineLayout() call has push constants index 0 "
8082 "with offset "},
8083 {{VK_SHADER_STAGE_VERTEX_BIT, too_big, too_big},
8084 "vkCreatePipelineLayout() call has push constants "
8085 "index 0 with offset "},
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06008086 {{VK_SHADER_STAGE_VERTEX_BIT, too_big, 4},
Karl Schultzc81037d2016-05-12 08:11:23 -06008087 "vkCreatePipelineLayout() call has push constants index 0 "
8088 "with offset "},
8089 {{VK_SHADER_STAGE_VERTEX_BIT, 0xFFFFFFF0, 0x00000020},
8090 "vkCreatePipelineLayout() call has push "
8091 "constants index 0 with offset "},
8092 {{VK_SHADER_STAGE_VERTEX_BIT, 0x00000020, 0xFFFFFFF0},
8093 "vkCreatePipelineLayout() call has push "
8094 "constants index 0 with offset "},
Karl Schultzfc8eaf12016-05-06 13:56:42 -06008095 }};
8096
8097 // Check for invalid offset and size
Karl Schultzc81037d2016-05-12 08:11:23 -06008098 for (const auto &iter : range_tests) {
8099 pc_range = iter.range;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008100 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, iter.msg);
8101 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Karl Schultzfc8eaf12016-05-06 13:56:42 -06008102 m_errorMonitor->VerifyFound();
8103 if (VK_SUCCESS == err) {
8104 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
8105 }
8106 }
8107
8108 // Check for invalid stage flag
8109 pc_range.offset = 0;
8110 pc_range.size = 16;
8111 pc_range.stageFlags = 0;
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06008112 m_errorMonitor->SetDesiredFailureMsg(
8113 VK_DEBUG_REPORT_ERROR_BIT_EXT,
8114 "vkCreatePipelineLayout: value of pCreateInfo->pPushConstantRanges[0].stageFlags must not be 0");
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008115 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008116 m_errorMonitor->VerifyFound();
Karl Schultzfc8eaf12016-05-06 13:56:42 -06008117 if (VK_SUCCESS == err) {
8118 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
8119 }
8120
8121 // Check for overlapping ranges
Karl Schultzc81037d2016-05-12 08:11:23 -06008122 const uint32_t ranges_per_test = 5;
Karl Schultzfc8eaf12016-05-06 13:56:42 -06008123 struct OverlappingRangeTestCase {
Karl Schultzc81037d2016-05-12 08:11:23 -06008124 VkPushConstantRange const ranges[ranges_per_test];
Karl Schultzfc8eaf12016-05-06 13:56:42 -06008125 char const *msg;
8126 };
8127
Karl Schultzc81037d2016-05-12 08:11:23 -06008128 const std::array<OverlappingRangeTestCase, 5> overlapping_range_tests = {
Karl Schultzfc8eaf12016-05-06 13:56:42 -06008129 {{{{VK_SHADER_STAGE_VERTEX_BIT, 0, 4},
8130 {VK_SHADER_STAGE_VERTEX_BIT, 0, 4},
8131 {VK_SHADER_STAGE_VERTEX_BIT, 0, 4},
8132 {VK_SHADER_STAGE_VERTEX_BIT, 0, 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:"},
Karl Schultzfc8eaf12016-05-06 13:56:42 -06008135 {
8136 {{VK_SHADER_STAGE_VERTEX_BIT, 0, 4},
8137 {VK_SHADER_STAGE_VERTEX_BIT, 4, 4},
8138 {VK_SHADER_STAGE_VERTEX_BIT, 8, 4},
8139 {VK_SHADER_STAGE_VERTEX_BIT, 12, 8},
8140 {VK_SHADER_STAGE_VERTEX_BIT, 16, 4}},
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06008141 "vkCreatePipelineLayout() call has push constants with overlapping ranges: 3:[12, 20), 4:[16, 20)",
Karl Schultzfc8eaf12016-05-06 13:56:42 -06008142 },
8143 {
8144 {{VK_SHADER_STAGE_VERTEX_BIT, 16, 4},
8145 {VK_SHADER_STAGE_VERTEX_BIT, 12, 8},
8146 {VK_SHADER_STAGE_VERTEX_BIT, 8, 4},
8147 {VK_SHADER_STAGE_VERTEX_BIT, 4, 4},
8148 {VK_SHADER_STAGE_VERTEX_BIT, 0, 4}},
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06008149 "vkCreatePipelineLayout() call has push constants with overlapping ranges: 0:[16, 20), 1:[12, 20)",
Karl Schultzfc8eaf12016-05-06 13:56:42 -06008150 },
8151 {
8152 {{VK_SHADER_STAGE_VERTEX_BIT, 16, 4},
8153 {VK_SHADER_STAGE_VERTEX_BIT, 8, 4},
8154 {VK_SHADER_STAGE_VERTEX_BIT, 4, 4},
8155 {VK_SHADER_STAGE_VERTEX_BIT, 12, 8},
8156 {VK_SHADER_STAGE_VERTEX_BIT, 0, 4}},
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06008157 "vkCreatePipelineLayout() call has push constants with overlapping ranges: 0:[16, 20), 3:[12, 20)",
Karl Schultzfc8eaf12016-05-06 13:56:42 -06008158 },
8159 {
8160 {{VK_SHADER_STAGE_VERTEX_BIT, 16, 4},
8161 {VK_SHADER_STAGE_VERTEX_BIT, 32, 4},
8162 {VK_SHADER_STAGE_VERTEX_BIT, 4, 96},
8163 {VK_SHADER_STAGE_VERTEX_BIT, 40, 8},
8164 {VK_SHADER_STAGE_VERTEX_BIT, 52, 4}},
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06008165 "vkCreatePipelineLayout() call has push constants with overlapping ranges:",
Karl Schultzfc8eaf12016-05-06 13:56:42 -06008166 }}};
Karl Schultzfc8eaf12016-05-06 13:56:42 -06008167
Karl Schultzc81037d2016-05-12 08:11:23 -06008168 for (const auto &iter : overlapping_range_tests) {
Karl Schultzfc8eaf12016-05-06 13:56:42 -06008169 pipeline_layout_ci.pPushConstantRanges = iter.ranges;
Karl Schultzc81037d2016-05-12 08:11:23 -06008170 pipeline_layout_ci.pushConstantRangeCount = ranges_per_test;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008171 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT, iter.msg);
8172 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Karl Schultzfc8eaf12016-05-06 13:56:42 -06008173 m_errorMonitor->VerifyFound();
8174 if (VK_SUCCESS == err) {
8175 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
8176 }
8177 }
8178
8179 // Run some positive tests to make sure overlap checking in the layer is OK
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008180 const std::array<OverlappingRangeTestCase, 2> overlapping_range_tests_pos = {{{{{VK_SHADER_STAGE_VERTEX_BIT, 0, 4},
8181 {VK_SHADER_STAGE_VERTEX_BIT, 4, 4},
8182 {VK_SHADER_STAGE_VERTEX_BIT, 8, 4},
8183 {VK_SHADER_STAGE_VERTEX_BIT, 12, 4},
8184 {VK_SHADER_STAGE_VERTEX_BIT, 16, 4}},
8185 ""},
8186 {{{VK_SHADER_STAGE_VERTEX_BIT, 92, 24},
8187 {VK_SHADER_STAGE_VERTEX_BIT, 80, 4},
8188 {VK_SHADER_STAGE_VERTEX_BIT, 64, 8},
8189 {VK_SHADER_STAGE_VERTEX_BIT, 4, 16},
8190 {VK_SHADER_STAGE_VERTEX_BIT, 0, 4}},
8191 ""}}};
Karl Schultzc81037d2016-05-12 08:11:23 -06008192 for (const auto &iter : overlapping_range_tests_pos) {
Karl Schultzfc8eaf12016-05-06 13:56:42 -06008193 pipeline_layout_ci.pPushConstantRanges = iter.ranges;
8194 m_errorMonitor->ExpectSuccess();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008195 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Karl Schultzfc8eaf12016-05-06 13:56:42 -06008196 m_errorMonitor->VerifyNotFound();
8197 if (VK_SUCCESS == err) {
8198 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
8199 }
8200 }
8201
8202 //
8203 // CmdPushConstants tests
8204 //
Karl Schultzc81037d2016-05-12 08:11:23 -06008205 const uint8_t dummy_values[100] = {};
Karl Schultzfc8eaf12016-05-06 13:56:42 -06008206
8207 // Check for invalid offset and size and if range is within layout range(s)
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06008208 const std::array<PipelineLayoutTestCase, 11> cmd_range_tests = {{
8209 {{VK_SHADER_STAGE_VERTEX_BIT, 0, 0}, "vkCmdPushConstants: parameter size must be greater than 0"},
Karl Schultzc81037d2016-05-12 08:11:23 -06008210 {{VK_SHADER_STAGE_VERTEX_BIT, 0, 1},
8211 "vkCmdPushConstants() call has push constants with size 1. Size "
8212 "must be greater than zero and a multiple of 4."},
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06008213 {{VK_SHADER_STAGE_VERTEX_BIT, 4, 1},
Karl Schultzc81037d2016-05-12 08:11:23 -06008214 "vkCmdPushConstants() call has push constants with size 1. Size "
8215 "must be greater than zero and a multiple of 4."},
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06008216 {{VK_SHADER_STAGE_VERTEX_BIT, 1, 4},
Karl Schultzc81037d2016-05-12 08:11:23 -06008217 "vkCmdPushConstants() call has push constants with offset 1. "
8218 "Offset must be a multiple of 4."},
8219 {{VK_SHADER_STAGE_VERTEX_BIT, 1, 4},
8220 "vkCmdPushConstants() call has push constants with offset 1. "
8221 "Offset must be a multiple of 4."},
8222 {{VK_SHADER_STAGE_VERTEX_BIT, 0, 20},
8223 "vkCmdPushConstants() Push constant range [0, 20) with stageFlags = "
8224 "0x1 not within flag-matching ranges in pipeline layout"},
8225 {{VK_SHADER_STAGE_VERTEX_BIT, 60, 8},
8226 "vkCmdPushConstants() Push constant range [60, 68) with stageFlags = "
8227 "0x1 not within flag-matching ranges in pipeline layout"},
8228 {{VK_SHADER_STAGE_VERTEX_BIT, 76, 8},
8229 "vkCmdPushConstants() Push constant range [76, 84) with stageFlags = "
8230 "0x1 not within flag-matching ranges in pipeline layout"},
8231 {{VK_SHADER_STAGE_VERTEX_BIT, 0, 80},
8232 "vkCmdPushConstants() Push constant range [0, 80) with stageFlags = "
8233 "0x1 not within flag-matching ranges in pipeline layout"},
8234 {{VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT, 0, 4},
8235 "vkCmdPushConstants() stageFlags = 0x2 do not match the stageFlags in "
8236 "any of the ranges in pipeline layout"},
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008237 {{VK_SHADER_STAGE_VERTEX_BIT | VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT, 0, 16},
Karl Schultzc81037d2016-05-12 08:11:23 -06008238 "vkCmdPushConstants() stageFlags = 0x3 do not match the stageFlags in "
8239 "any of the ranges in pipeline layout"},
Karl Schultzfc8eaf12016-05-06 13:56:42 -06008240 }};
8241
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06008242 BeginCommandBuffer();
8243
8244 // Setup ranges: [0,16) [64,80)
Karl Schultzc81037d2016-05-12 08:11:23 -06008245 const VkPushConstantRange pc_range2[] = {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008246 {VK_SHADER_STAGE_VERTEX_BIT, 64, 16}, {VK_SHADER_STAGE_VERTEX_BIT, 0, 16},
Karl Schultzfc8eaf12016-05-06 13:56:42 -06008247 };
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008248 pipeline_layout_ci.pushConstantRangeCount = sizeof(pc_range2) / sizeof(VkPushConstantRange);
Karl Schultzfc8eaf12016-05-06 13:56:42 -06008249 pipeline_layout_ci.pPushConstantRanges = pc_range2;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008250 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis3a23b6a2016-02-17 10:35:18 -07008251 ASSERT_VK_SUCCESS(err);
Karl Schultzc81037d2016-05-12 08:11:23 -06008252 for (const auto &iter : cmd_range_tests) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008253 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, iter.msg);
8254 vkCmdPushConstants(m_commandBuffer->GetBufferHandle(), pipeline_layout, iter.range.stageFlags, iter.range.offset,
Karl Schultzc81037d2016-05-12 08:11:23 -06008255 iter.range.size, dummy_values);
Karl Schultzfc8eaf12016-05-06 13:56:42 -06008256 m_errorMonitor->VerifyFound();
8257 }
8258
8259 // Check for invalid stage flag
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06008260 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "vkCmdPushConstants: value of stageFlags must not be 0");
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008261 vkCmdPushConstants(m_commandBuffer->GetBufferHandle(), pipeline_layout, 0, 0, 16, dummy_values);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008262 m_errorMonitor->VerifyFound();
Karl Schultzc81037d2016-05-12 08:11:23 -06008263 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
Karl Schultzfc8eaf12016-05-06 13:56:42 -06008264
Karl Schultzc81037d2016-05-12 08:11:23 -06008265 // overlapping range tests with cmd
8266 const std::array<PipelineLayoutTestCase, 3> cmd_overlap_tests = {{
8267 {{VK_SHADER_STAGE_VERTEX_BIT, 0, 20},
8268 "vkCmdPushConstants() Push constant range [0, 20) with stageFlags = "
8269 "0x1 not within flag-matching ranges in pipeline layout"},
8270 {{VK_SHADER_STAGE_VERTEX_BIT, 16, 4},
8271 "vkCmdPushConstants() Push constant range [16, 20) with stageFlags = "
8272 "0x1 not within flag-matching ranges in pipeline layout"},
8273 {{VK_SHADER_STAGE_VERTEX_BIT, 40, 16},
8274 "vkCmdPushConstants() Push constant range [40, 56) with stageFlags = "
8275 "0x1 not within flag-matching ranges in pipeline layout"},
8276 }};
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06008277 // Setup ranges: [0,16), [20,36), [36,44), [44,52), [80,92)
Karl Schultzc81037d2016-05-12 08:11:23 -06008278 const VkPushConstantRange pc_range3[] = {
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06008279 {VK_SHADER_STAGE_VERTEX_BIT, 20, 16}, {VK_SHADER_STAGE_VERTEX_BIT, 0, 16}, {VK_SHADER_STAGE_VERTEX_BIT, 44, 8},
8280 {VK_SHADER_STAGE_VERTEX_BIT, 80, 12}, {VK_SHADER_STAGE_VERTEX_BIT, 36, 8},
Karl Schultzc81037d2016-05-12 08:11:23 -06008281 };
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008282 pipeline_layout_ci.pushConstantRangeCount = sizeof(pc_range3) / sizeof(VkPushConstantRange);
Karl Schultzc81037d2016-05-12 08:11:23 -06008283 pipeline_layout_ci.pPushConstantRanges = pc_range3;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008284 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Karl Schultzc81037d2016-05-12 08:11:23 -06008285 ASSERT_VK_SUCCESS(err);
Karl Schultzc81037d2016-05-12 08:11:23 -06008286 for (const auto &iter : cmd_overlap_tests) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008287 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, iter.msg);
8288 vkCmdPushConstants(m_commandBuffer->GetBufferHandle(), pipeline_layout, iter.range.stageFlags, iter.range.offset,
Karl Schultzc81037d2016-05-12 08:11:23 -06008289 iter.range.size, dummy_values);
8290 m_errorMonitor->VerifyFound();
8291 }
Karl Schultzc81037d2016-05-12 08:11:23 -06008292 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
8293
8294 // positive overlapping range tests with cmd
8295 const std::array<PipelineLayoutTestCase, 4> cmd_overlap_tests_pos = {{
8296 {{VK_SHADER_STAGE_VERTEX_BIT, 0, 16}, ""},
8297 {{VK_SHADER_STAGE_VERTEX_BIT, 0, 4}, ""},
8298 {{VK_SHADER_STAGE_VERTEX_BIT, 20, 12}, ""},
8299 {{VK_SHADER_STAGE_VERTEX_BIT, 56, 36}, ""},
8300 }};
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06008301 // Setup ranges: [0,16) [20,36) [36,44) [44,52) [56,80) [80,92)
Karl Schultzc81037d2016-05-12 08:11:23 -06008302 const VkPushConstantRange pc_range4[] = {
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06008303 {VK_SHADER_STAGE_VERTEX_BIT, 20, 16}, {VK_SHADER_STAGE_VERTEX_BIT, 0, 16}, {VK_SHADER_STAGE_VERTEX_BIT, 44, 8},
8304 {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 -06008305 };
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008306 pipeline_layout_ci.pushConstantRangeCount = sizeof(pc_range4) / sizeof(VkPushConstantRange);
Karl Schultzc81037d2016-05-12 08:11:23 -06008307 pipeline_layout_ci.pPushConstantRanges = pc_range4;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008308 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Karl Schultzc81037d2016-05-12 08:11:23 -06008309 ASSERT_VK_SUCCESS(err);
Karl Schultzc81037d2016-05-12 08:11:23 -06008310 for (const auto &iter : cmd_overlap_tests_pos) {
8311 m_errorMonitor->ExpectSuccess();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008312 vkCmdPushConstants(m_commandBuffer->GetBufferHandle(), pipeline_layout, iter.range.stageFlags, iter.range.offset,
Karl Schultzc81037d2016-05-12 08:11:23 -06008313 iter.range.size, dummy_values);
8314 m_errorMonitor->VerifyNotFound();
8315 }
Tobin Ehlis3a23b6a2016-02-17 10:35:18 -07008316 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06008317
8318 EndCommandBuffer();
Tobin Ehlis3a23b6a2016-02-17 10:35:18 -07008319}
8320
Karl Schultz6addd812016-02-02 17:17:23 -07008321TEST_F(VkLayerTest, DescriptorSetCompatibility) {
Tobin Ehlis559c6382015-11-05 09:52:49 -07008322 // Test various desriptorSet errors with bad binding combinations
Karl Schultz6addd812016-02-02 17:17:23 -07008323 VkResult err;
Tobin Ehlis559c6382015-11-05 09:52:49 -07008324
8325 ASSERT_NO_FATAL_FAILURE(InitState());
8326 ASSERT_NO_FATAL_FAILURE(InitViewport());
8327 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
8328
Mike Stroyanb8a61002016-06-20 16:00:28 -06008329 const VkFormat tex_format = VK_FORMAT_R8G8B8A8_UNORM;
8330 VkImageTiling tiling;
8331 VkFormatProperties format_properties;
8332 vkGetPhysicalDeviceFormatProperties(gpu(), tex_format, &format_properties);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008333 if (format_properties.linearTilingFeatures & VK_FORMAT_FEATURE_STORAGE_IMAGE_BIT) {
Mike Stroyanb8a61002016-06-20 16:00:28 -06008334 tiling = VK_IMAGE_TILING_LINEAR;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008335 } else if (format_properties.optimalTilingFeatures & VK_FORMAT_FEATURE_STORAGE_IMAGE_BIT) {
Mike Stroyanb8a61002016-06-20 16:00:28 -06008336 tiling = VK_IMAGE_TILING_OPTIMAL;
8337 } else {
8338 printf("Device does not support VK_FORMAT_FEATURE_STORAGE_IMAGE_BIT; "
8339 "skipped.\n");
8340 return;
8341 }
8342
Tobin Ehlis559c6382015-11-05 09:52:49 -07008343 static const uint32_t NUM_DESCRIPTOR_TYPES = 5;
8344 VkDescriptorPoolSize ds_type_count[NUM_DESCRIPTOR_TYPES] = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008345 ds_type_count[0].type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
8346 ds_type_count[0].descriptorCount = 10;
8347 ds_type_count[1].type = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE;
8348 ds_type_count[1].descriptorCount = 2;
8349 ds_type_count[2].type = VK_DESCRIPTOR_TYPE_STORAGE_IMAGE;
8350 ds_type_count[2].descriptorCount = 2;
8351 ds_type_count[3].type = VK_DESCRIPTOR_TYPE_SAMPLER;
8352 ds_type_count[3].descriptorCount = 5;
8353 // TODO : LunarG ILO driver currently asserts in desc.c w/ INPUT_ATTACHMENT
8354 // type
8355 // ds_type_count[4].type = VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT;
8356 ds_type_count[4].type = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
8357 ds_type_count[4].descriptorCount = 2;
Tobin Ehlis559c6382015-11-05 09:52:49 -07008358
8359 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008360 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
8361 ds_pool_ci.pNext = NULL;
8362 ds_pool_ci.maxSets = 5;
8363 ds_pool_ci.poolSizeCount = NUM_DESCRIPTOR_TYPES;
8364 ds_pool_ci.pPoolSizes = ds_type_count;
Tobin Ehlis559c6382015-11-05 09:52:49 -07008365
8366 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008367 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis559c6382015-11-05 09:52:49 -07008368 ASSERT_VK_SUCCESS(err);
8369
8370 static const uint32_t MAX_DS_TYPES_IN_LAYOUT = 2;
8371 VkDescriptorSetLayoutBinding dsl_binding[MAX_DS_TYPES_IN_LAYOUT] = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008372 dsl_binding[0].binding = 0;
8373 dsl_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
8374 dsl_binding[0].descriptorCount = 5;
8375 dsl_binding[0].stageFlags = VK_SHADER_STAGE_ALL;
8376 dsl_binding[0].pImmutableSamplers = NULL;
Tobin Ehlis559c6382015-11-05 09:52:49 -07008377
Tobin Ehlis8fab6562015-12-01 09:57:09 -07008378 // Create layout identical to set0 layout but w/ different stageFlags
8379 VkDescriptorSetLayoutBinding dsl_fs_stage_only = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008380 dsl_fs_stage_only.binding = 0;
8381 dsl_fs_stage_only.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
8382 dsl_fs_stage_only.descriptorCount = 5;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008383 dsl_fs_stage_only.stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT; // Different stageFlags to cause error at
8384 // bind time
Karl Schultz6addd812016-02-02 17:17:23 -07008385 dsl_fs_stage_only.pImmutableSamplers = NULL;
Tobin Ehlis559c6382015-11-05 09:52:49 -07008386 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008387 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
8388 ds_layout_ci.pNext = NULL;
8389 ds_layout_ci.bindingCount = 1;
8390 ds_layout_ci.pBindings = dsl_binding;
Tobin Ehlis559c6382015-11-05 09:52:49 -07008391 static const uint32_t NUM_LAYOUTS = 4;
8392 VkDescriptorSetLayout ds_layout[NUM_LAYOUTS] = {};
Tobin Ehlis8fab6562015-12-01 09:57:09 -07008393 VkDescriptorSetLayout ds_layout_fs_only = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008394 // Create 4 unique layouts for full pipelineLayout, and 1 special fs-only
8395 // layout for error case
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008396 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout[0]);
Tobin Ehlis559c6382015-11-05 09:52:49 -07008397 ASSERT_VK_SUCCESS(err);
Jon Ashburn6e23c1f2015-12-30 18:01:16 -07008398 ds_layout_ci.pBindings = &dsl_fs_stage_only;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008399 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout_fs_only);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07008400 ASSERT_VK_SUCCESS(err);
Tobin Ehlis559c6382015-11-05 09:52:49 -07008401 dsl_binding[0].binding = 0;
8402 dsl_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE;
Tobin Ehlis8fab6562015-12-01 09:57:09 -07008403 dsl_binding[0].descriptorCount = 2;
Mike Stroyan9c70cdb2016-01-06 14:14:17 -07008404 dsl_binding[1].binding = 1;
8405 dsl_binding[1].descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_IMAGE;
8406 dsl_binding[1].descriptorCount = 2;
8407 dsl_binding[1].stageFlags = VK_SHADER_STAGE_ALL;
8408 dsl_binding[1].pImmutableSamplers = NULL;
Jon Ashburn6e23c1f2015-12-30 18:01:16 -07008409 ds_layout_ci.pBindings = dsl_binding;
Tobin Ehlis559c6382015-11-05 09:52:49 -07008410 ds_layout_ci.bindingCount = 2;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008411 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout[1]);
Tobin Ehlis559c6382015-11-05 09:52:49 -07008412 ASSERT_VK_SUCCESS(err);
8413 dsl_binding[0].binding = 0;
8414 dsl_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
Tobin Ehlis8fab6562015-12-01 09:57:09 -07008415 dsl_binding[0].descriptorCount = 5;
Tobin Ehlis559c6382015-11-05 09:52:49 -07008416 ds_layout_ci.bindingCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008417 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout[2]);
Tobin Ehlis559c6382015-11-05 09:52:49 -07008418 ASSERT_VK_SUCCESS(err);
8419 dsl_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
Tobin Ehlis8fab6562015-12-01 09:57:09 -07008420 dsl_binding[0].descriptorCount = 2;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008421 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout[3]);
Tobin Ehlis559c6382015-11-05 09:52:49 -07008422 ASSERT_VK_SUCCESS(err);
8423
8424 static const uint32_t NUM_SETS = 4;
8425 VkDescriptorSet descriptorSet[NUM_SETS] = {};
8426 VkDescriptorSetAllocateInfo alloc_info = {};
Tobin Ehlis8fab6562015-12-01 09:57:09 -07008427 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07008428 alloc_info.descriptorSetCount = NUM_LAYOUTS;
Tobin Ehlis559c6382015-11-05 09:52:49 -07008429 alloc_info.descriptorPool = ds_pool;
8430 alloc_info.pSetLayouts = ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008431 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, descriptorSet);
Tobin Ehlis559c6382015-11-05 09:52:49 -07008432 ASSERT_VK_SUCCESS(err);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07008433 VkDescriptorSet ds0_fs_only = {};
Jon Ashburnf19916e2016-01-11 13:12:43 -07008434 alloc_info.descriptorSetCount = 1;
Tobin Ehlis8fab6562015-12-01 09:57:09 -07008435 alloc_info.pSetLayouts = &ds_layout_fs_only;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008436 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &ds0_fs_only);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07008437 ASSERT_VK_SUCCESS(err);
Tobin Ehlis559c6382015-11-05 09:52:49 -07008438
8439 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008440 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
8441 pipeline_layout_ci.pNext = NULL;
8442 pipeline_layout_ci.setLayoutCount = NUM_LAYOUTS;
8443 pipeline_layout_ci.pSetLayouts = ds_layout;
Tobin Ehlis559c6382015-11-05 09:52:49 -07008444
8445 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008446 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis559c6382015-11-05 09:52:49 -07008447 ASSERT_VK_SUCCESS(err);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07008448 // Create pipelineLayout with only one setLayout
8449 pipeline_layout_ci.setLayoutCount = 1;
8450 VkPipelineLayout single_pipe_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008451 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &single_pipe_layout);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07008452 ASSERT_VK_SUCCESS(err);
8453 // Create pipelineLayout with 2 descriptor setLayout at index 0
8454 pipeline_layout_ci.pSetLayouts = &ds_layout[3];
8455 VkPipelineLayout pipe_layout_one_desc;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008456 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipe_layout_one_desc);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07008457 ASSERT_VK_SUCCESS(err);
8458 // Create pipelineLayout with 5 SAMPLER descriptor setLayout at index 0
8459 pipeline_layout_ci.pSetLayouts = &ds_layout[2];
8460 VkPipelineLayout pipe_layout_five_samp;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008461 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipe_layout_five_samp);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07008462 ASSERT_VK_SUCCESS(err);
8463 // Create pipelineLayout with UB type, but stageFlags for FS only
8464 pipeline_layout_ci.pSetLayouts = &ds_layout_fs_only;
8465 VkPipelineLayout pipe_layout_fs_only;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008466 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipe_layout_fs_only);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07008467 ASSERT_VK_SUCCESS(err);
8468 // Create pipelineLayout w/ incompatible set0 layout, but set1 is fine
8469 VkDescriptorSetLayout pl_bad_s0[2] = {};
8470 pl_bad_s0[0] = ds_layout_fs_only;
8471 pl_bad_s0[1] = ds_layout[1];
8472 pipeline_layout_ci.setLayoutCount = 2;
8473 pipeline_layout_ci.pSetLayouts = pl_bad_s0;
8474 VkPipelineLayout pipe_layout_bad_set0;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008475 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipe_layout_bad_set0);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07008476 ASSERT_VK_SUCCESS(err);
Tobin Ehlis559c6382015-11-05 09:52:49 -07008477
8478 // Create a buffer to update the descriptor with
8479 uint32_t qfi = 0;
8480 VkBufferCreateInfo buffCI = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008481 buffCI.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
8482 buffCI.size = 1024;
8483 buffCI.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
8484 buffCI.queueFamilyIndexCount = 1;
8485 buffCI.pQueueFamilyIndices = &qfi;
Tobin Ehlis559c6382015-11-05 09:52:49 -07008486
8487 VkBuffer dyub;
8488 err = vkCreateBuffer(m_device->device(), &buffCI, NULL, &dyub);
8489 ASSERT_VK_SUCCESS(err);
8490 // Correctly update descriptor to avoid "NOT_UPDATED" error
8491 static const uint32_t NUM_BUFFS = 5;
8492 VkDescriptorBufferInfo buffInfo[NUM_BUFFS] = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008493 for (uint32_t i = 0; i < NUM_BUFFS; ++i) {
Tobin Ehlis559c6382015-11-05 09:52:49 -07008494 buffInfo[i].buffer = dyub;
8495 buffInfo[i].offset = 0;
8496 buffInfo[i].range = 1024;
8497 }
Karl Schultz6addd812016-02-02 17:17:23 -07008498 VkImage image;
Karl Schultz6addd812016-02-02 17:17:23 -07008499 const int32_t tex_width = 32;
8500 const int32_t tex_height = 32;
Tobin Ehlis8fab6562015-12-01 09:57:09 -07008501 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008502 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
8503 image_create_info.pNext = NULL;
8504 image_create_info.imageType = VK_IMAGE_TYPE_2D;
8505 image_create_info.format = tex_format;
8506 image_create_info.extent.width = tex_width;
8507 image_create_info.extent.height = tex_height;
8508 image_create_info.extent.depth = 1;
8509 image_create_info.mipLevels = 1;
8510 image_create_info.arrayLayers = 1;
8511 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
Mike Stroyanb8a61002016-06-20 16:00:28 -06008512 image_create_info.tiling = tiling;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008513 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT | VK_IMAGE_USAGE_STORAGE_BIT;
Karl Schultz6addd812016-02-02 17:17:23 -07008514 image_create_info.flags = 0;
Tobin Ehlis8fab6562015-12-01 09:57:09 -07008515 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
8516 ASSERT_VK_SUCCESS(err);
Tobin Ehlis559c6382015-11-05 09:52:49 -07008517
Karl Schultz6addd812016-02-02 17:17:23 -07008518 VkMemoryRequirements memReqs;
8519 VkDeviceMemory imageMem;
8520 bool pass;
Mike Stroyan9c70cdb2016-01-06 14:14:17 -07008521 VkMemoryAllocateInfo memAlloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008522 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
8523 memAlloc.pNext = NULL;
8524 memAlloc.allocationSize = 0;
8525 memAlloc.memoryTypeIndex = 0;
Mike Stroyan9c70cdb2016-01-06 14:14:17 -07008526 vkGetImageMemoryRequirements(m_device->device(), image, &memReqs);
8527 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008528 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Mike Stroyan9c70cdb2016-01-06 14:14:17 -07008529 ASSERT_TRUE(pass);
8530 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &imageMem);
8531 ASSERT_VK_SUCCESS(err);
8532 err = vkBindImageMemory(m_device->device(), image, imageMem, 0);
8533 ASSERT_VK_SUCCESS(err);
8534
Tobin Ehlis8fab6562015-12-01 09:57:09 -07008535 VkImageViewCreateInfo image_view_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008536 image_view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
8537 image_view_create_info.image = image;
8538 image_view_create_info.viewType = VK_IMAGE_VIEW_TYPE_2D;
8539 image_view_create_info.format = tex_format;
8540 image_view_create_info.subresourceRange.layerCount = 1;
8541 image_view_create_info.subresourceRange.baseMipLevel = 0;
8542 image_view_create_info.subresourceRange.levelCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008543 image_view_create_info.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Tobin Ehlis559c6382015-11-05 09:52:49 -07008544
Tobin Ehlis8fab6562015-12-01 09:57:09 -07008545 VkImageView view;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008546 err = vkCreateImageView(m_device->device(), &image_view_create_info, NULL, &view);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07008547 ASSERT_VK_SUCCESS(err);
Tobin Ehlis991d45a2016-01-06 08:48:41 -07008548 VkDescriptorImageInfo imageInfo[4] = {};
Tobin Ehlis8fab6562015-12-01 09:57:09 -07008549 imageInfo[0].imageView = view;
8550 imageInfo[0].imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
8551 imageInfo[1].imageView = view;
8552 imageInfo[1].imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
Tobin Ehlis991d45a2016-01-06 08:48:41 -07008553 imageInfo[2].imageView = view;
8554 imageInfo[2].imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
8555 imageInfo[3].imageView = view;
8556 imageInfo[3].imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
Tobin Ehlis8fab6562015-12-01 09:57:09 -07008557
8558 static const uint32_t NUM_SET_UPDATES = 3;
8559 VkWriteDescriptorSet descriptor_write[NUM_SET_UPDATES] = {};
8560 descriptor_write[0].sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
8561 descriptor_write[0].dstSet = descriptorSet[0];
8562 descriptor_write[0].dstBinding = 0;
8563 descriptor_write[0].descriptorCount = 5;
8564 descriptor_write[0].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
8565 descriptor_write[0].pBufferInfo = buffInfo;
8566 descriptor_write[1].sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
8567 descriptor_write[1].dstSet = descriptorSet[1];
8568 descriptor_write[1].dstBinding = 0;
8569 descriptor_write[1].descriptorCount = 2;
8570 descriptor_write[1].descriptorType = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE;
8571 descriptor_write[1].pImageInfo = imageInfo;
8572 descriptor_write[2].sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
8573 descriptor_write[2].dstSet = descriptorSet[1];
8574 descriptor_write[2].dstBinding = 1;
8575 descriptor_write[2].descriptorCount = 2;
8576 descriptor_write[2].descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_IMAGE;
Tobin Ehlis991d45a2016-01-06 08:48:41 -07008577 descriptor_write[2].pImageInfo = &imageInfo[2];
Tobin Ehlis8fab6562015-12-01 09:57:09 -07008578
8579 vkUpdateDescriptorSets(m_device->device(), 3, descriptor_write, 0, NULL);
Tobin Ehlis559c6382015-11-05 09:52:49 -07008580
Tobin Ehlis88452832015-12-03 09:40:56 -07008581 // Create PSO to be used for draw-time errors below
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008582 char const *vsSource = "#version 450\n"
8583 "\n"
8584 "out gl_PerVertex {\n"
8585 " vec4 gl_Position;\n"
8586 "};\n"
8587 "void main(){\n"
8588 " gl_Position = vec4(1);\n"
8589 "}\n";
8590 char const *fsSource = "#version 450\n"
8591 "\n"
8592 "layout(location=0) out vec4 x;\n"
8593 "layout(set=0) layout(binding=0) uniform foo { int x; int y; } bar;\n"
8594 "void main(){\n"
8595 " x = vec4(bar.y);\n"
8596 "}\n";
Tobin Ehlis88452832015-12-03 09:40:56 -07008597 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
8598 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Tobin Ehlis559c6382015-11-05 09:52:49 -07008599 VkPipelineObj pipe(m_device);
8600 pipe.AddShader(&vs);
8601 pipe.AddShader(&fs);
Tobin Ehlis88452832015-12-03 09:40:56 -07008602 pipe.AddColorAttachment();
8603 pipe.CreateVKPipeline(pipe_layout_fs_only, renderPass());
Tobin Ehlis559c6382015-11-05 09:52:49 -07008604
8605 BeginCommandBuffer();
Tobin Ehlis88452832015-12-03 09:40:56 -07008606
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008607 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Karl Schultz6addd812016-02-02 17:17:23 -07008608 // NOTE : I believe LunarG ilo driver has bug (LX#189) that requires binding
8609 // of PSO
8610 // here before binding DSs. Otherwise we assert in cmd_copy_dset_data() of
8611 // cmd_pipeline.c
8612 // due to the fact that cmd_alloc_dset_data() has not been called in
8613 // cmd_bind_graphics_pipeline()
8614 // TODO : Want to cause various binding incompatibility issues here to test
8615 // DrawState
Tobin Ehlis559c6382015-11-05 09:52:49 -07008616 // First cause various verify_layout_compatibility() fails
8617 // Second disturb early and late sets and verify INFO msgs
Tobin Ehlis8fab6562015-12-01 09:57:09 -07008618 // verify_set_layout_compatibility fail cases:
8619 // 1. invalid VkPipelineLayout (layout) passed into vkCmdBindDescriptorSets
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008620 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Invalid Pipeline Layout Object ");
8621 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS,
8622 (VkPipelineLayout)((size_t)0xbaadb1be), 0, 1, &descriptorSet[0], 0, NULL);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008623 m_errorMonitor->VerifyFound();
8624
Tobin Ehlis8fab6562015-12-01 09:57:09 -07008625 // 2. layoutIndex exceeds # of layouts in layout
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008626 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " attempting to bind set to index 1");
8627 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, single_pipe_layout, 0, 2,
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(), single_pipe_layout, NULL);
Karl Schultz6addd812016-02-02 17:17:23 -07008632 // 3. Pipeline setLayout[0] has 2 descriptors, but set being bound has 5
8633 // descriptors
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008634 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " has 2 descriptors, but DescriptorSetLayout ");
8635 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe_layout_one_desc, 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 vkDestroyPipelineLayout(m_device->device(), pipe_layout_one_desc, NULL);
8640 // 4. same # of descriptors but mismatch in type
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008641 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " is type 'VK_DESCRIPTOR_TYPE_SAMPLER' but binding ");
8642 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe_layout_five_samp, 0, 1,
8643 &descriptorSet[0], 0, NULL);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008644 m_errorMonitor->VerifyFound();
8645
Tobin Ehlis8fab6562015-12-01 09:57:09 -07008646 vkDestroyPipelineLayout(m_device->device(), pipe_layout_five_samp, NULL);
8647 // 5. same # of descriptors but mismatch in stageFlags
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008648 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
8649 " has stageFlags 16 but binding 0 for DescriptorSetLayout ");
8650 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe_layout_fs_only, 0, 1,
8651 &descriptorSet[0], 0, NULL);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008652 m_errorMonitor->VerifyFound();
8653
Tobin Ehlis8fab6562015-12-01 09:57:09 -07008654 // Cause INFO messages due to disturbing previously bound Sets
8655 // First bind sets 0 & 1
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008656 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 2,
8657 &descriptorSet[0], 0, NULL);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07008658 // 1. Disturb bound set0 by re-binding set1 w/ updated pipelineLayout
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008659 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT, " previously bound as set #0 was disturbed ");
8660 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe_layout_bad_set0, 1, 1,
8661 &descriptorSet[1], 0, NULL);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008662 m_errorMonitor->VerifyFound();
8663
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008664 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 2,
8665 &descriptorSet[0], 0, NULL);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07008666 // 2. Disturb set after last bound set
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008667 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT, " newly bound as set #0 so set #1 and "
8668 "any subsequent sets were disturbed ");
8669 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe_layout_fs_only, 0, 1,
8670 &ds0_fs_only, 0, NULL);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008671 m_errorMonitor->VerifyFound();
8672
Tobin Ehlis10fad692016-07-07 12:00:36 -06008673 // Now that we're done actively using the pipelineLayout that gfx pipeline
8674 // was created with, we should be able to delete it. Do that now to verify
8675 // that validation obeys pipelineLayout lifetime
8676 vkDestroyPipelineLayout(m_device->device(), pipe_layout_fs_only, NULL);
8677
Tobin Ehlis88452832015-12-03 09:40:56 -07008678 // Cause draw-time errors due to PSO incompatibilities
Karl Schultz6addd812016-02-02 17:17:23 -07008679 // 1. Error due to not binding required set (we actually use same code as
8680 // above to disturb set0)
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008681 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 2,
8682 &descriptorSet[0], 0, NULL);
8683 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe_layout_bad_set0, 1, 1,
8684 &descriptorSet[1], 0, NULL);
8685 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 -07008686 Draw(1, 0, 0, 0);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008687 m_errorMonitor->VerifyFound();
8688
Tobin Ehlis991d45a2016-01-06 08:48:41 -07008689 vkDestroyPipelineLayout(m_device->device(), pipe_layout_bad_set0, NULL);
Karl Schultz6addd812016-02-02 17:17:23 -07008690 // 2. Error due to bound set not being compatible with PSO's
8691 // VkPipelineLayout (diff stageFlags in this case)
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008692 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 2,
8693 &descriptorSet[0], 0, NULL);
8694 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " bound as set #0 is not compatible with ");
Tobin Ehlis88452832015-12-03 09:40:56 -07008695 Draw(1, 0, 0, 0);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008696 m_errorMonitor->VerifyFound();
8697
Tobin Ehlis8fab6562015-12-01 09:57:09 -07008698 // Remaining clean-up
Karl Schultz6addd812016-02-02 17:17:23 -07008699 for (uint32_t i = 0; i < NUM_LAYOUTS; ++i) {
Tobin Ehlis8fab6562015-12-01 09:57:09 -07008700 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout[i], NULL);
8701 }
8702 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout_fs_only, NULL);
Tobin Ehlis9bfd4492016-05-05 15:09:11 -06008703 vkFreeDescriptorSets(m_device->device(), ds_pool, 1, &ds0_fs_only);
8704 vkFreeDescriptorSets(m_device->device(), ds_pool, NUM_SETS, descriptorSet);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07008705 vkDestroyBuffer(m_device->device(), dyub, NULL);
Tobin Ehlis559c6382015-11-05 09:52:49 -07008706 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
8707 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tony Barbourdf4c0042016-06-01 15:55:43 -06008708 vkFreeMemory(m_device->device(), imageMem, NULL);
8709 vkDestroyImage(m_device->device(), image, NULL);
8710 vkDestroyImageView(m_device->device(), view, NULL);
Tobin Ehlis559c6382015-11-05 09:52:49 -07008711}
Tobin Ehlis559c6382015-11-05 09:52:49 -07008712
Karl Schultz6addd812016-02-02 17:17:23 -07008713TEST_F(VkLayerTest, NoBeginCommandBuffer) {
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,
8716 "You must call vkBeginCommandBuffer() before this call to ");
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06008717
8718 ASSERT_NO_FATAL_FAILURE(InitState());
Chia-I Wu3432a0c2015-10-27 18:04:07 +08008719 VkCommandBufferObj commandBuffer(m_device, m_commandPool);
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06008720 // Call EndCommandBuffer() w/o calling BeginCommandBuffer()
Chia-I Wu3432a0c2015-10-27 18:04:07 +08008721 vkEndCommandBuffer(commandBuffer.GetBufferHandle());
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06008722
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008723 m_errorMonitor->VerifyFound();
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06008724}
8725
Karl Schultz6addd812016-02-02 17:17:23 -07008726TEST_F(VkLayerTest, SecondaryCommandBufferNullRenderpass) {
8727 VkResult err;
8728 VkCommandBuffer draw_cmd;
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06008729
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008730 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " must specify a valid renderpass parameter.");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06008731
Mark Lobodzinskid9139a62015-08-04 16:24:20 -06008732 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinskid9139a62015-08-04 16:24:20 -06008733
Chia-I Wu3432a0c2015-10-27 18:04:07 +08008734 VkCommandBufferAllocateInfo cmd = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08008735 cmd.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
Cody Northropb4569702015-08-04 17:35:57 -06008736 cmd.pNext = NULL;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08008737 cmd.commandPool = m_commandPool;
8738 cmd.level = VK_COMMAND_BUFFER_LEVEL_SECONDARY;
Jon Ashburnf19916e2016-01-11 13:12:43 -07008739 cmd.commandBufferCount = 1;
Cody Northropb4569702015-08-04 17:35:57 -06008740
Chia-I Wu3432a0c2015-10-27 18:04:07 +08008741 err = vkAllocateCommandBuffers(m_device->device(), &cmd, &draw_cmd);
Mike Stroyand1c84a52015-08-18 14:40:24 -06008742 ASSERT_VK_SUCCESS(err);
Mark Lobodzinskid9139a62015-08-04 16:24:20 -06008743
8744 // Force the failure by not setting the Renderpass and Framebuffer fields
Chia-I Wu3432a0c2015-10-27 18:04:07 +08008745 VkCommandBufferBeginInfo cmd_buf_info = {};
Jon Ashburnf19916e2016-01-11 13:12:43 -07008746 VkCommandBufferInheritanceInfo cmd_buf_hinfo = {};
Chia-I Wu3432a0c2015-10-27 18:04:07 +08008747 cmd_buf_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
Cody Northropb4569702015-08-04 17:35:57 -06008748 cmd_buf_info.pNext = NULL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008749 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 -07008750 cmd_buf_info.pInheritanceInfo = &cmd_buf_hinfo;
Mark Lobodzinskid9139a62015-08-04 16:24:20 -06008751
8752 // The error should be caught by validation of the BeginCommandBuffer call
8753 vkBeginCommandBuffer(draw_cmd, &cmd_buf_info);
8754
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008755 m_errorMonitor->VerifyFound();
Chia-I Wu3432a0c2015-10-27 18:04:07 +08008756 vkFreeCommandBuffers(m_device->device(), m_commandPool, 1, &draw_cmd);
Mark Lobodzinskid9139a62015-08-04 16:24:20 -06008757}
8758
Karl Schultz6addd812016-02-02 17:17:23 -07008759TEST_F(VkLayerTest, CommandBufferResetErrors) {
Tobin Ehlisac0ef842015-12-14 13:46:38 -07008760 // Cause error due to Begin while recording CB
8761 // Then cause 2 errors for attempting to reset CB w/o having
8762 // VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT set for the pool from
8763 // which CBs were allocated. Note that this bit is off by default.
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008764 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Cannot call Begin on CB");
Tobin Ehlisac0ef842015-12-14 13:46:38 -07008765
8766 ASSERT_NO_FATAL_FAILURE(InitState());
8767
8768 // Calls AllocateCommandBuffers
8769 VkCommandBufferObj commandBuffer(m_device, m_commandPool);
8770
Karl Schultz6addd812016-02-02 17:17:23 -07008771 // Force the failure by setting the Renderpass and Framebuffer fields with
8772 // (fake) data
Tobin Ehlisac0ef842015-12-14 13:46:38 -07008773 VkCommandBufferBeginInfo cmd_buf_info = {};
Jon Ashburnf19916e2016-01-11 13:12:43 -07008774 VkCommandBufferInheritanceInfo cmd_buf_hinfo = {};
Tobin Ehlisac0ef842015-12-14 13:46:38 -07008775 cmd_buf_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
8776 cmd_buf_info.pNext = NULL;
8777 cmd_buf_info.flags = VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT;
Jon Ashburnf19916e2016-01-11 13:12:43 -07008778 cmd_buf_info.pInheritanceInfo = &cmd_buf_hinfo;
Tobin Ehlisac0ef842015-12-14 13:46:38 -07008779
8780 // Begin CB to transition to recording state
8781 vkBeginCommandBuffer(commandBuffer.GetBufferHandle(), &cmd_buf_info);
8782 // Can't re-begin. This should trigger error
8783 vkBeginCommandBuffer(commandBuffer.GetBufferHandle(), &cmd_buf_info);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008784 m_errorMonitor->VerifyFound();
8785
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008786 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Attempt to reset command buffer ");
Tobin Ehlisac0ef842015-12-14 13:46:38 -07008787 VkCommandBufferResetFlags flags = 0; // Don't care about flags for this test
8788 // Reset attempt will trigger error due to incorrect CommandPool state
8789 vkResetCommandBuffer(commandBuffer.GetBufferHandle(), flags);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008790 m_errorMonitor->VerifyFound();
8791
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008792 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " attempts to implicitly reset cmdBuffer created from ");
Tobin Ehlisac0ef842015-12-14 13:46:38 -07008793 // Transition CB to RECORDED state
8794 vkEndCommandBuffer(commandBuffer.GetBufferHandle());
8795 // Now attempting to Begin will implicitly reset, which triggers error
8796 vkBeginCommandBuffer(commandBuffer.GetBufferHandle(), &cmd_buf_info);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008797 m_errorMonitor->VerifyFound();
Tobin Ehlisac0ef842015-12-14 13:46:38 -07008798}
8799
Karl Schultz6addd812016-02-02 17:17:23 -07008800TEST_F(VkLayerTest, InvalidPipelineCreateState) {
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06008801 // Attempt to Create Gfx Pipeline w/o a VS
Karl Schultz6addd812016-02-02 17:17:23 -07008802 VkResult err;
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06008803
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008804 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Invalid Pipeline CreateInfo State: Vtx Shader required");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06008805
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06008806 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06008807 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Mark Lobodzinski209b5292015-09-17 09:44:05 -06008808
Chia-I Wu1b99bb22015-10-27 19:25:11 +08008809 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008810 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
8811 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -06008812
8813 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008814 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
8815 ds_pool_ci.pNext = NULL;
8816 ds_pool_ci.maxSets = 1;
8817 ds_pool_ci.poolSizeCount = 1;
8818 ds_pool_ci.pPoolSizes = &ds_type_count;
Mark Lobodzinski209b5292015-09-17 09:44:05 -06008819
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06008820 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008821 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06008822 ASSERT_VK_SUCCESS(err);
8823
Tony Barboureb254902015-07-15 12:50:33 -06008824 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008825 dsl_binding.binding = 0;
8826 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
8827 dsl_binding.descriptorCount = 1;
8828 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
8829 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06008830
Tony Barboureb254902015-07-15 12:50:33 -06008831 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008832 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
8833 ds_layout_ci.pNext = NULL;
8834 ds_layout_ci.bindingCount = 1;
8835 ds_layout_ci.pBindings = &dsl_binding;
Tony Barboureb254902015-07-15 12:50:33 -06008836
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06008837 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008838 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06008839 ASSERT_VK_SUCCESS(err);
8840
8841 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08008842 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08008843 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07008844 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06008845 alloc_info.descriptorPool = ds_pool;
8846 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008847 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06008848 ASSERT_VK_SUCCESS(err);
8849
Tony Barboureb254902015-07-15 12:50:33 -06008850 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008851 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
8852 pipeline_layout_ci.setLayoutCount = 1;
8853 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06008854
8855 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008856 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06008857 ASSERT_VK_SUCCESS(err);
8858
Tobin Ehlise68360f2015-10-01 11:15:13 -06008859 VkViewport vp = {}; // Just need dummy vp to point to
Karl Schultz6addd812016-02-02 17:17:23 -07008860 VkRect2D sc = {}; // dummy scissor to point to
Tobin Ehlise68360f2015-10-01 11:15:13 -06008861
8862 VkPipelineViewportStateCreateInfo vp_state_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008863 vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
8864 vp_state_ci.scissorCount = 1;
8865 vp_state_ci.pScissors = &sc;
8866 vp_state_ci.viewportCount = 1;
8867 vp_state_ci.pViewports = &vp;
Tobin Ehlise68360f2015-10-01 11:15:13 -06008868
Karl Schultzdfdb8d42016-03-08 10:30:21 -07008869 VkPipelineRasterizationStateCreateInfo rs_state_ci = {};
8870 rs_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
8871 rs_state_ci.polygonMode = VK_POLYGON_MODE_FILL;
8872 rs_state_ci.cullMode = VK_CULL_MODE_BACK_BIT;
8873 rs_state_ci.frontFace = VK_FRONT_FACE_COUNTER_CLOCKWISE;
8874 rs_state_ci.depthClampEnable = VK_FALSE;
8875 rs_state_ci.rasterizerDiscardEnable = VK_FALSE;
8876 rs_state_ci.depthBiasEnable = VK_FALSE;
8877
Tony Barboureb254902015-07-15 12:50:33 -06008878 VkGraphicsPipelineCreateInfo gp_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008879 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
8880 gp_ci.pViewportState = &vp_state_ci;
Karl Schultzdfdb8d42016-03-08 10:30:21 -07008881 gp_ci.pRasterizationState = &rs_state_ci;
Karl Schultz6addd812016-02-02 17:17:23 -07008882 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
8883 gp_ci.layout = pipeline_layout;
8884 gp_ci.renderPass = renderPass();
Tony Barboureb254902015-07-15 12:50:33 -06008885
8886 VkPipelineCacheCreateInfo pc_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008887 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
8888 pc_ci.initialDataSize = 0;
8889 pc_ci.pInitialData = 0;
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06008890
8891 VkPipeline pipeline;
Jon Ashburnc669cc62015-07-09 15:02:25 -06008892 VkPipelineCache pipelineCache;
8893
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008894 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Jon Ashburnc669cc62015-07-09 15:02:25 -06008895 ASSERT_VK_SUCCESS(err);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008896 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06008897
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008898 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06008899
Chia-I Wuf7458c52015-10-26 21:10:41 +08008900 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
8901 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
8902 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
8903 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06008904}
Tobin Ehlis912df022015-09-17 08:46:18 -06008905/*// TODO : This test should be good, but needs Tess support in compiler to run
8906TEST_F(VkLayerTest, InvalidPatchControlPoints)
8907{
8908 // Attempt to Create Gfx Pipeline w/o a VS
Tobin Ehlis912df022015-09-17 08:46:18 -06008909 VkResult err;
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06008910
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07008911 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Karl Schultz6addd812016-02-02 17:17:23 -07008912 "Invalid Pipeline CreateInfo State: VK_PRIMITIVE_TOPOLOGY_PATCH
8913primitive ");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06008914
Tobin Ehlis912df022015-09-17 08:46:18 -06008915 ASSERT_NO_FATAL_FAILURE(InitState());
8916 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlis912df022015-09-17 08:46:18 -06008917
Chia-I Wu1b99bb22015-10-27 19:25:11 +08008918 VkDescriptorPoolSize ds_type_count = {};
Tobin Ehlis912df022015-09-17 08:46:18 -06008919 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Chia-I Wud50a7d72015-10-26 20:48:51 +08008920 ds_type_count.descriptorCount = 1;
Tobin Ehlis912df022015-09-17 08:46:18 -06008921
8922 VkDescriptorPoolCreateInfo ds_pool_ci = {};
8923 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
8924 ds_pool_ci.pNext = NULL;
Chia-I Wu1b99bb22015-10-27 19:25:11 +08008925 ds_pool_ci.poolSizeCount = 1;
8926 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlis912df022015-09-17 08:46:18 -06008927
8928 VkDescriptorPool ds_pool;
Karl Schultz6addd812016-02-02 17:17:23 -07008929 err = vkCreateDescriptorPool(m_device->device(),
8930VK_DESCRIPTOR_POOL_USAGE_NON_FREE, 1, &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis912df022015-09-17 08:46:18 -06008931 ASSERT_VK_SUCCESS(err);
8932
8933 VkDescriptorSetLayoutBinding dsl_binding = {};
Chia-I Wud46e6ae2015-10-31 00:31:16 +08008934 dsl_binding.binding = 0;
Tobin Ehlis912df022015-09-17 08:46:18 -06008935 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Chia-I Wu02124482015-11-06 06:42:02 +08008936 dsl_binding.descriptorCount = 1;
Tobin Ehlis912df022015-09-17 08:46:18 -06008937 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
8938 dsl_binding.pImmutableSamplers = NULL;
8939
8940 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008941 ds_layout_ci.sType =
8942VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
Tobin Ehlis912df022015-09-17 08:46:18 -06008943 ds_layout_ci.pNext = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08008944 ds_layout_ci.bindingCount = 1;
Jon Ashburn6e23c1f2015-12-30 18:01:16 -07008945 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlis912df022015-09-17 08:46:18 -06008946
8947 VkDescriptorSetLayout ds_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07008948 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL,
8949&ds_layout);
Tobin Ehlis912df022015-09-17 08:46:18 -06008950 ASSERT_VK_SUCCESS(err);
8951
8952 VkDescriptorSet descriptorSet;
Karl Schultz6addd812016-02-02 17:17:23 -07008953 err = vkAllocateDescriptorSets(m_device->device(), ds_pool,
8954VK_DESCRIPTOR_SET_USAGE_NON_FREE, 1, &ds_layout, &descriptorSet);
Tobin Ehlis912df022015-09-17 08:46:18 -06008955 ASSERT_VK_SUCCESS(err);
8956
8957 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008958 pipeline_layout_ci.sType =
8959VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
Tobin Ehlis912df022015-09-17 08:46:18 -06008960 pipeline_layout_ci.pNext = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08008961 pipeline_layout_ci.setLayoutCount = 1;
Tobin Ehlis912df022015-09-17 08:46:18 -06008962 pipeline_layout_ci.pSetLayouts = &ds_layout;
8963
8964 VkPipelineLayout pipeline_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07008965 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL,
8966&pipeline_layout);
Tobin Ehlis912df022015-09-17 08:46:18 -06008967 ASSERT_VK_SUCCESS(err);
8968
8969 VkPipelineShaderStageCreateInfo shaderStages[3];
8970 memset(&shaderStages, 0, 3 * sizeof(VkPipelineShaderStageCreateInfo));
8971
Karl Schultz6addd812016-02-02 17:17:23 -07008972 VkShaderObj vs(m_device,bindStateVertShaderText,VK_SHADER_STAGE_VERTEX_BIT,
8973this);
Tobin Ehlis912df022015-09-17 08:46:18 -06008974 // Just using VS txt for Tess shaders as we don't care about functionality
Karl Schultz6addd812016-02-02 17:17:23 -07008975 VkShaderObj
8976tc(m_device,bindStateVertShaderText,VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT,
8977this);
8978 VkShaderObj
8979te(m_device,bindStateVertShaderText,VK_SHADER_STAGE_TESSELLATION_EVALUATION_BIT,
8980this);
Tobin Ehlis912df022015-09-17 08:46:18 -06008981
Karl Schultz6addd812016-02-02 17:17:23 -07008982 shaderStages[0].sType =
8983VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO;
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -06008984 shaderStages[0].stage = VK_SHADER_STAGE_VERTEX_BIT;
Tobin Ehlis912df022015-09-17 08:46:18 -06008985 shaderStages[0].shader = vs.handle();
Karl Schultz6addd812016-02-02 17:17:23 -07008986 shaderStages[1].sType =
8987VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO;
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -06008988 shaderStages[1].stage = VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT;
Tobin Ehlis912df022015-09-17 08:46:18 -06008989 shaderStages[1].shader = tc.handle();
Karl Schultz6addd812016-02-02 17:17:23 -07008990 shaderStages[2].sType =
8991VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO;
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -06008992 shaderStages[2].stage = VK_SHADER_STAGE_TESSELLATION_EVALUATION_BIT;
Tobin Ehlis912df022015-09-17 08:46:18 -06008993 shaderStages[2].shader = te.handle();
8994
8995 VkPipelineInputAssemblyStateCreateInfo iaCI = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008996 iaCI.sType =
8997VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
Chia-I Wu515eb8f2015-10-31 00:31:16 +08008998 iaCI.topology = VK_PRIMITIVE_TOPOLOGY_PATCH_LIST;
Tobin Ehlis912df022015-09-17 08:46:18 -06008999
9000 VkPipelineTessellationStateCreateInfo tsCI = {};
9001 tsCI.sType = VK_STRUCTURE_TYPE_PIPELINE_TESSELLATION_STATE_CREATE_INFO;
9002 tsCI.patchControlPoints = 0; // This will cause an error
9003
9004 VkGraphicsPipelineCreateInfo gp_ci = {};
9005 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
9006 gp_ci.pNext = NULL;
9007 gp_ci.stageCount = 3;
9008 gp_ci.pStages = shaderStages;
9009 gp_ci.pVertexInputState = NULL;
9010 gp_ci.pInputAssemblyState = &iaCI;
9011 gp_ci.pTessellationState = &tsCI;
9012 gp_ci.pViewportState = NULL;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009013 gp_ci.pRasterizationState = NULL;
Tobin Ehlis912df022015-09-17 08:46:18 -06009014 gp_ci.pMultisampleState = NULL;
9015 gp_ci.pDepthStencilState = NULL;
9016 gp_ci.pColorBlendState = NULL;
9017 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
9018 gp_ci.layout = pipeline_layout;
9019 gp_ci.renderPass = renderPass();
9020
9021 VkPipelineCacheCreateInfo pc_ci = {};
9022 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
9023 pc_ci.pNext = NULL;
9024 pc_ci.initialSize = 0;
9025 pc_ci.initialData = 0;
9026 pc_ci.maxSize = 0;
9027
9028 VkPipeline pipeline;
9029 VkPipelineCache pipelineCache;
9030
Karl Schultz6addd812016-02-02 17:17:23 -07009031 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL,
9032&pipelineCache);
Tobin Ehlis912df022015-09-17 08:46:18 -06009033 ASSERT_VK_SUCCESS(err);
Karl Schultz6addd812016-02-02 17:17:23 -07009034 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1,
9035&gp_ci, NULL, &pipeline);
Tobin Ehlis912df022015-09-17 08:46:18 -06009036
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009037 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06009038
Chia-I Wuf7458c52015-10-26 21:10:41 +08009039 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
9040 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
9041 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
9042 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis912df022015-09-17 08:46:18 -06009043}
9044*/
Tobin Ehlise68360f2015-10-01 11:15:13 -06009045// Set scissor and viewport counts to different numbers
Karl Schultz6addd812016-02-02 17:17:23 -07009046TEST_F(VkLayerTest, PSOViewportScissorCountMismatch) {
Karl Schultz6addd812016-02-02 17:17:23 -07009047 VkResult err;
Tobin Ehlise68360f2015-10-01 11:15:13 -06009048
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009049 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
9050 "Gfx Pipeline viewport count (1) must match scissor count (0).");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06009051
Tobin Ehlise68360f2015-10-01 11:15:13 -06009052 ASSERT_NO_FATAL_FAILURE(InitState());
9053 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlise68360f2015-10-01 11:15:13 -06009054
Chia-I Wu1b99bb22015-10-27 19:25:11 +08009055 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009056 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
9057 ds_type_count.descriptorCount = 1;
Tobin Ehlise68360f2015-10-01 11:15:13 -06009058
9059 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009060 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
9061 ds_pool_ci.maxSets = 1;
9062 ds_pool_ci.poolSizeCount = 1;
9063 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlise68360f2015-10-01 11:15:13 -06009064
9065 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009066 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlise68360f2015-10-01 11:15:13 -06009067 ASSERT_VK_SUCCESS(err);
9068
9069 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009070 dsl_binding.binding = 0;
9071 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
9072 dsl_binding.descriptorCount = 1;
9073 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
Tobin Ehlise68360f2015-10-01 11:15:13 -06009074
9075 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009076 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
9077 ds_layout_ci.bindingCount = 1;
9078 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlise68360f2015-10-01 11:15:13 -06009079
9080 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009081 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlise68360f2015-10-01 11:15:13 -06009082 ASSERT_VK_SUCCESS(err);
9083
9084 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009085 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08009086 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07009087 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06009088 alloc_info.descriptorPool = ds_pool;
9089 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009090 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlise68360f2015-10-01 11:15:13 -06009091 ASSERT_VK_SUCCESS(err);
9092
9093 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009094 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
9095 pipeline_layout_ci.setLayoutCount = 1;
9096 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlise68360f2015-10-01 11:15:13 -06009097
9098 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009099 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlise68360f2015-10-01 11:15:13 -06009100 ASSERT_VK_SUCCESS(err);
9101
9102 VkViewport vp = {}; // Just need dummy vp to point to
9103
9104 VkPipelineViewportStateCreateInfo vp_state_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009105 vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
9106 vp_state_ci.scissorCount = 0;
9107 vp_state_ci.viewportCount = 1; // Count mismatch should cause error
9108 vp_state_ci.pViewports = &vp;
Tobin Ehlise68360f2015-10-01 11:15:13 -06009109
Karl Schultzdfdb8d42016-03-08 10:30:21 -07009110 VkPipelineRasterizationStateCreateInfo rs_state_ci = {};
9111 rs_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
9112 rs_state_ci.polygonMode = VK_POLYGON_MODE_FILL;
9113 rs_state_ci.cullMode = VK_CULL_MODE_BACK_BIT;
9114 rs_state_ci.frontFace = VK_FRONT_FACE_COUNTER_CLOCKWISE;
9115 rs_state_ci.depthClampEnable = VK_FALSE;
9116 rs_state_ci.rasterizerDiscardEnable = VK_FALSE;
9117 rs_state_ci.depthBiasEnable = VK_FALSE;
9118
Cody Northropeb3a6c12015-10-05 14:44:45 -06009119 VkPipelineShaderStageCreateInfo shaderStages[2];
Karl Schultz6addd812016-02-02 17:17:23 -07009120 memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo));
Tobin Ehlise68360f2015-10-01 11:15:13 -06009121
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009122 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
9123 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this); // We shouldn't need a fragment shader
9124 // but add it to be able to run on more devices
Chia-I Wu28e06912015-10-31 00:31:16 +08009125 shaderStages[0] = vs.GetStageCreateInfo();
9126 shaderStages[1] = fs.GetStageCreateInfo();
Tobin Ehlise68360f2015-10-01 11:15:13 -06009127
9128 VkGraphicsPipelineCreateInfo gp_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009129 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
9130 gp_ci.stageCount = 2;
9131 gp_ci.pStages = shaderStages;
9132 gp_ci.pViewportState = &vp_state_ci;
Karl Schultzdfdb8d42016-03-08 10:30:21 -07009133 gp_ci.pRasterizationState = &rs_state_ci;
Karl Schultz6addd812016-02-02 17:17:23 -07009134 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
9135 gp_ci.layout = pipeline_layout;
9136 gp_ci.renderPass = renderPass();
Tobin Ehlise68360f2015-10-01 11:15:13 -06009137
9138 VkPipelineCacheCreateInfo pc_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009139 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
Tobin Ehlise68360f2015-10-01 11:15:13 -06009140
9141 VkPipeline pipeline;
9142 VkPipelineCache pipelineCache;
9143
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009144 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Tobin Ehlise68360f2015-10-01 11:15:13 -06009145 ASSERT_VK_SUCCESS(err);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009146 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Tobin Ehlise68360f2015-10-01 11:15:13 -06009147
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009148 m_errorMonitor->VerifyFound();
Tobin Ehlise68360f2015-10-01 11:15:13 -06009149
Chia-I Wuf7458c52015-10-26 21:10:41 +08009150 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
9151 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
9152 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
9153 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlise68360f2015-10-01 11:15:13 -06009154}
Karl Schultz6addd812016-02-02 17:17:23 -07009155// Don't set viewport state in PSO. This is an error b/c we always need this
9156// state
Tobin Ehlisd332f282015-10-02 11:00:56 -06009157// for the counts even if the data is going to be set dynamically.
Karl Schultz6addd812016-02-02 17:17:23 -07009158TEST_F(VkLayerTest, PSOViewportStateNotSet) {
Tobin Ehlise68360f2015-10-01 11:15:13 -06009159 // Attempt to Create Gfx Pipeline w/o a VS
Karl Schultz6addd812016-02-02 17:17:23 -07009160 VkResult err;
Tobin Ehlise68360f2015-10-01 11:15:13 -06009161
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009162 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Gfx Pipeline pViewportState is null. Even if ");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06009163
Tobin Ehlise68360f2015-10-01 11:15:13 -06009164 ASSERT_NO_FATAL_FAILURE(InitState());
9165 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlise68360f2015-10-01 11:15:13 -06009166
Chia-I Wu1b99bb22015-10-27 19:25:11 +08009167 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009168 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
9169 ds_type_count.descriptorCount = 1;
Tobin Ehlise68360f2015-10-01 11:15:13 -06009170
9171 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009172 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
9173 ds_pool_ci.maxSets = 1;
9174 ds_pool_ci.poolSizeCount = 1;
9175 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlise68360f2015-10-01 11:15:13 -06009176
9177 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009178 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlise68360f2015-10-01 11:15:13 -06009179 ASSERT_VK_SUCCESS(err);
9180
9181 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009182 dsl_binding.binding = 0;
9183 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
9184 dsl_binding.descriptorCount = 1;
9185 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
Tobin Ehlise68360f2015-10-01 11:15:13 -06009186
9187 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009188 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
9189 ds_layout_ci.bindingCount = 1;
9190 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlise68360f2015-10-01 11:15:13 -06009191
9192 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009193 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlise68360f2015-10-01 11:15:13 -06009194 ASSERT_VK_SUCCESS(err);
9195
9196 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009197 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08009198 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07009199 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06009200 alloc_info.descriptorPool = ds_pool;
9201 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009202 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlise68360f2015-10-01 11:15:13 -06009203 ASSERT_VK_SUCCESS(err);
9204
9205 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009206 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
9207 pipeline_layout_ci.setLayoutCount = 1;
9208 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlise68360f2015-10-01 11:15:13 -06009209
9210 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009211 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlise68360f2015-10-01 11:15:13 -06009212 ASSERT_VK_SUCCESS(err);
9213
9214 VkDynamicState sc_state = VK_DYNAMIC_STATE_SCISSOR;
9215 // Set scissor as dynamic to avoid second error
9216 VkPipelineDynamicStateCreateInfo dyn_state_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009217 dyn_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_DYNAMIC_STATE_CREATE_INFO;
9218 dyn_state_ci.dynamicStateCount = 1;
9219 dyn_state_ci.pDynamicStates = &sc_state;
Tobin Ehlise68360f2015-10-01 11:15:13 -06009220
Cody Northropeb3a6c12015-10-05 14:44:45 -06009221 VkPipelineShaderStageCreateInfo shaderStages[2];
Karl Schultz6addd812016-02-02 17:17:23 -07009222 memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo));
Tobin Ehlise68360f2015-10-01 11:15:13 -06009223
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009224 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
9225 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this); // We shouldn't need a fragment shader
9226 // but add it to be able to run on more devices
Chia-I Wu28e06912015-10-31 00:31:16 +08009227 shaderStages[0] = vs.GetStageCreateInfo();
9228 shaderStages[1] = fs.GetStageCreateInfo();
Tobin Ehlise68360f2015-10-01 11:15:13 -06009229
Karl Schultzdfdb8d42016-03-08 10:30:21 -07009230 VkPipelineRasterizationStateCreateInfo rs_state_ci = {};
9231 rs_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
9232 rs_state_ci.polygonMode = VK_POLYGON_MODE_FILL;
9233 rs_state_ci.cullMode = VK_CULL_MODE_BACK_BIT;
9234 rs_state_ci.frontFace = VK_FRONT_FACE_COUNTER_CLOCKWISE;
9235 rs_state_ci.depthClampEnable = VK_FALSE;
9236 rs_state_ci.rasterizerDiscardEnable = VK_FALSE;
9237 rs_state_ci.depthBiasEnable = VK_FALSE;
9238
Tobin Ehlise68360f2015-10-01 11:15:13 -06009239 VkGraphicsPipelineCreateInfo gp_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009240 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
9241 gp_ci.stageCount = 2;
9242 gp_ci.pStages = shaderStages;
Karl Schultzdfdb8d42016-03-08 10:30:21 -07009243 gp_ci.pRasterizationState = &rs_state_ci;
Karl Schultz6addd812016-02-02 17:17:23 -07009244 gp_ci.pViewportState = NULL; // Not setting VP state w/o dynamic vp state
9245 // should cause validation error
9246 gp_ci.pDynamicState = &dyn_state_ci;
9247 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
9248 gp_ci.layout = pipeline_layout;
9249 gp_ci.renderPass = renderPass();
Tobin Ehlise68360f2015-10-01 11:15:13 -06009250
9251 VkPipelineCacheCreateInfo pc_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009252 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
Tobin Ehlise68360f2015-10-01 11:15:13 -06009253
9254 VkPipeline pipeline;
9255 VkPipelineCache pipelineCache;
9256
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009257 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Tobin Ehlise68360f2015-10-01 11:15:13 -06009258 ASSERT_VK_SUCCESS(err);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009259 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Tobin Ehlise68360f2015-10-01 11:15:13 -06009260
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009261 m_errorMonitor->VerifyFound();
Tobin Ehlise68360f2015-10-01 11:15:13 -06009262
Chia-I Wuf7458c52015-10-26 21:10:41 +08009263 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
9264 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
9265 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
9266 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlise68360f2015-10-01 11:15:13 -06009267}
9268// Create PSO w/o non-zero viewportCount but no viewport data
Karl Schultz6addd812016-02-02 17:17:23 -07009269// Then run second test where dynamic scissor count doesn't match PSO scissor
9270// count
9271TEST_F(VkLayerTest, PSOViewportCountWithoutDataAndDynScissorMismatch) {
9272 VkResult err;
Tobin Ehlise68360f2015-10-01 11:15:13 -06009273
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009274 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
9275 "Gfx Pipeline viewportCount is 1, but pViewports is NULL. ");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06009276
Tobin Ehlise68360f2015-10-01 11:15:13 -06009277 ASSERT_NO_FATAL_FAILURE(InitState());
Chris Forbesc08a6ca2016-07-28 14:14:07 +12009278
9279 if (!m_device->phy().features().multiViewport) {
9280 printf("Device does not support multiple viewports/scissors; skipped.\n");
9281 return;
9282 }
9283
Tobin Ehlise68360f2015-10-01 11:15:13 -06009284 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlise68360f2015-10-01 11:15:13 -06009285
Chia-I Wu1b99bb22015-10-27 19:25:11 +08009286 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009287 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
9288 ds_type_count.descriptorCount = 1;
Tobin Ehlise68360f2015-10-01 11:15:13 -06009289
9290 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009291 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
9292 ds_pool_ci.maxSets = 1;
9293 ds_pool_ci.poolSizeCount = 1;
9294 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlise68360f2015-10-01 11:15:13 -06009295
9296 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009297 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlise68360f2015-10-01 11:15:13 -06009298 ASSERT_VK_SUCCESS(err);
9299
9300 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009301 dsl_binding.binding = 0;
9302 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
9303 dsl_binding.descriptorCount = 1;
9304 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
Tobin Ehlise68360f2015-10-01 11:15:13 -06009305
9306 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009307 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
9308 ds_layout_ci.bindingCount = 1;
9309 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlise68360f2015-10-01 11:15:13 -06009310
9311 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009312 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlise68360f2015-10-01 11:15:13 -06009313 ASSERT_VK_SUCCESS(err);
9314
9315 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009316 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08009317 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07009318 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06009319 alloc_info.descriptorPool = ds_pool;
9320 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009321 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlise68360f2015-10-01 11:15:13 -06009322 ASSERT_VK_SUCCESS(err);
9323
9324 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009325 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
9326 pipeline_layout_ci.setLayoutCount = 1;
9327 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlise68360f2015-10-01 11:15:13 -06009328
9329 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009330 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlise68360f2015-10-01 11:15:13 -06009331 ASSERT_VK_SUCCESS(err);
9332
9333 VkPipelineViewportStateCreateInfo vp_state_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009334 vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
9335 vp_state_ci.viewportCount = 1;
9336 vp_state_ci.pViewports = NULL; // Null vp w/ count of 1 should cause error
9337 vp_state_ci.scissorCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009338 vp_state_ci.pScissors = NULL; // Scissor is dynamic (below) so this won't cause error
Tobin Ehlise68360f2015-10-01 11:15:13 -06009339
9340 VkDynamicState sc_state = VK_DYNAMIC_STATE_SCISSOR;
9341 // Set scissor as dynamic to avoid that error
9342 VkPipelineDynamicStateCreateInfo dyn_state_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009343 dyn_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_DYNAMIC_STATE_CREATE_INFO;
9344 dyn_state_ci.dynamicStateCount = 1;
9345 dyn_state_ci.pDynamicStates = &sc_state;
Tobin Ehlise68360f2015-10-01 11:15:13 -06009346
Cody Northropeb3a6c12015-10-05 14:44:45 -06009347 VkPipelineShaderStageCreateInfo shaderStages[2];
Karl Schultz6addd812016-02-02 17:17:23 -07009348 memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo));
Tobin Ehlise68360f2015-10-01 11:15:13 -06009349
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009350 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
9351 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this); // We shouldn't need a fragment shader
9352 // but add it to be able to run on more devices
Chia-I Wu28e06912015-10-31 00:31:16 +08009353 shaderStages[0] = vs.GetStageCreateInfo();
9354 shaderStages[1] = fs.GetStageCreateInfo();
Tobin Ehlise68360f2015-10-01 11:15:13 -06009355
Cody Northropf6622dc2015-10-06 10:33:21 -06009356 VkPipelineVertexInputStateCreateInfo vi_ci = {};
9357 vi_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
9358 vi_ci.pNext = nullptr;
Chia-I Wud50a7d72015-10-26 20:48:51 +08009359 vi_ci.vertexBindingDescriptionCount = 0;
Cody Northropf6622dc2015-10-06 10:33:21 -06009360 vi_ci.pVertexBindingDescriptions = nullptr;
Chia-I Wud50a7d72015-10-26 20:48:51 +08009361 vi_ci.vertexAttributeDescriptionCount = 0;
Cody Northropf6622dc2015-10-06 10:33:21 -06009362 vi_ci.pVertexAttributeDescriptions = nullptr;
9363
9364 VkPipelineInputAssemblyStateCreateInfo ia_ci = {};
9365 ia_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
9366 ia_ci.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP;
9367
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009368 VkPipelineRasterizationStateCreateInfo rs_ci = {};
Chia-I Wu1b99bb22015-10-27 19:25:11 +08009369 rs_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
Cody Northropf6622dc2015-10-06 10:33:21 -06009370 rs_ci.pNext = nullptr;
9371
Mark Youngc89c6312016-03-31 16:03:20 -06009372 VkPipelineColorBlendAttachmentState att = {};
9373 att.blendEnable = VK_FALSE;
9374 att.colorWriteMask = 0xf;
9375
Cody Northropf6622dc2015-10-06 10:33:21 -06009376 VkPipelineColorBlendStateCreateInfo cb_ci = {};
9377 cb_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO;
9378 cb_ci.pNext = nullptr;
Mark Youngc89c6312016-03-31 16:03:20 -06009379 cb_ci.attachmentCount = 1;
9380 cb_ci.pAttachments = &att;
Cody Northropf6622dc2015-10-06 10:33:21 -06009381
Tobin Ehlise68360f2015-10-01 11:15:13 -06009382 VkGraphicsPipelineCreateInfo gp_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009383 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
9384 gp_ci.stageCount = 2;
9385 gp_ci.pStages = shaderStages;
9386 gp_ci.pVertexInputState = &vi_ci;
9387 gp_ci.pInputAssemblyState = &ia_ci;
9388 gp_ci.pViewportState = &vp_state_ci;
9389 gp_ci.pRasterizationState = &rs_ci;
9390 gp_ci.pColorBlendState = &cb_ci;
9391 gp_ci.pDynamicState = &dyn_state_ci;
9392 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
9393 gp_ci.layout = pipeline_layout;
9394 gp_ci.renderPass = renderPass();
Tobin Ehlise68360f2015-10-01 11:15:13 -06009395
9396 VkPipelineCacheCreateInfo pc_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009397 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
Tobin Ehlise68360f2015-10-01 11:15:13 -06009398
9399 VkPipeline pipeline;
9400 VkPipelineCache pipelineCache;
9401
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009402 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Tobin Ehlise68360f2015-10-01 11:15:13 -06009403 ASSERT_VK_SUCCESS(err);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009404 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Tobin Ehlise68360f2015-10-01 11:15:13 -06009405
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009406 m_errorMonitor->VerifyFound();
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06009407
Tobin Ehlisd332f282015-10-02 11:00:56 -06009408 // Now hit second fail case where we set scissor w/ different count than PSO
Karl Schultz6addd812016-02-02 17:17:23 -07009409 // First need to successfully create the PSO from above by setting
9410 // pViewports
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009411 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Dynamic scissor(s) 0 are used by PSO, ");
Karl Schultz6addd812016-02-02 17:17:23 -07009412
9413 VkViewport vp = {}; // Just need dummy vp to point to
9414 vp_state_ci.pViewports = &vp;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009415 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Karl Schultz6addd812016-02-02 17:17:23 -07009416 ASSERT_VK_SUCCESS(err);
9417 BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009418 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline);
Chris Forbesc08a6ca2016-07-28 14:14:07 +12009419 VkRect2D scissors[1] = {}; // don't care about data
Karl Schultz6addd812016-02-02 17:17:23 -07009420 // Count of 2 doesn't match PSO count of 1
Chris Forbesc08a6ca2016-07-28 14:14:07 +12009421 vkCmdSetScissor(m_commandBuffer->GetBufferHandle(), 1, 1, scissors);
Karl Schultz6addd812016-02-02 17:17:23 -07009422 Draw(1, 0, 0, 0);
9423
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009424 m_errorMonitor->VerifyFound();
Karl Schultz6addd812016-02-02 17:17:23 -07009425
9426 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
9427 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
9428 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
9429 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tony Barbourdf4c0042016-06-01 15:55:43 -06009430 vkDestroyPipeline(m_device->device(), pipeline, NULL);
Karl Schultz6addd812016-02-02 17:17:23 -07009431}
9432// Create PSO w/o non-zero scissorCount but no scissor data
9433// Then run second test where dynamic viewportCount doesn't match PSO
9434// viewportCount
9435TEST_F(VkLayerTest, PSOScissorCountWithoutDataAndDynViewportMismatch) {
9436 VkResult err;
9437
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009438 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 -07009439
9440 ASSERT_NO_FATAL_FAILURE(InitState());
Chris Forbesc08a6ca2016-07-28 14:14:07 +12009441
9442 if (!m_device->phy().features().multiViewport) {
9443 printf("Device does not support multiple viewports/scissors; skipped.\n");
9444 return;
9445 }
9446
Karl Schultz6addd812016-02-02 17:17:23 -07009447 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
9448
9449 VkDescriptorPoolSize ds_type_count = {};
9450 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
9451 ds_type_count.descriptorCount = 1;
9452
9453 VkDescriptorPoolCreateInfo ds_pool_ci = {};
9454 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
9455 ds_pool_ci.maxSets = 1;
9456 ds_pool_ci.poolSizeCount = 1;
9457 ds_pool_ci.pPoolSizes = &ds_type_count;
9458
9459 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009460 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Karl Schultz6addd812016-02-02 17:17:23 -07009461 ASSERT_VK_SUCCESS(err);
9462
9463 VkDescriptorSetLayoutBinding dsl_binding = {};
9464 dsl_binding.binding = 0;
9465 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
9466 dsl_binding.descriptorCount = 1;
9467 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
9468
9469 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
9470 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
9471 ds_layout_ci.bindingCount = 1;
9472 ds_layout_ci.pBindings = &dsl_binding;
9473
9474 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009475 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Karl Schultz6addd812016-02-02 17:17:23 -07009476 ASSERT_VK_SUCCESS(err);
9477
9478 VkDescriptorSet descriptorSet;
9479 VkDescriptorSetAllocateInfo alloc_info = {};
9480 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
9481 alloc_info.descriptorSetCount = 1;
9482 alloc_info.descriptorPool = ds_pool;
9483 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009484 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Karl Schultz6addd812016-02-02 17:17:23 -07009485 ASSERT_VK_SUCCESS(err);
9486
9487 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
9488 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
9489 pipeline_layout_ci.setLayoutCount = 1;
9490 pipeline_layout_ci.pSetLayouts = &ds_layout;
9491
9492 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009493 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Karl Schultz6addd812016-02-02 17:17:23 -07009494 ASSERT_VK_SUCCESS(err);
9495
9496 VkPipelineViewportStateCreateInfo vp_state_ci = {};
9497 vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
9498 vp_state_ci.scissorCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009499 vp_state_ci.pScissors = NULL; // Null scissor w/ count of 1 should cause error
Karl Schultz6addd812016-02-02 17:17:23 -07009500 vp_state_ci.viewportCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009501 vp_state_ci.pViewports = NULL; // vp is dynamic (below) so this won't cause error
Karl Schultz6addd812016-02-02 17:17:23 -07009502
9503 VkDynamicState vp_state = VK_DYNAMIC_STATE_VIEWPORT;
9504 // Set scissor as dynamic to avoid that error
9505 VkPipelineDynamicStateCreateInfo dyn_state_ci = {};
9506 dyn_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_DYNAMIC_STATE_CREATE_INFO;
9507 dyn_state_ci.dynamicStateCount = 1;
9508 dyn_state_ci.pDynamicStates = &vp_state;
9509
9510 VkPipelineShaderStageCreateInfo shaderStages[2];
9511 memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo));
9512
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009513 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
9514 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this); // We shouldn't need a fragment shader
9515 // but add it to be able to run on more devices
Karl Schultz6addd812016-02-02 17:17:23 -07009516 shaderStages[0] = vs.GetStageCreateInfo();
9517 shaderStages[1] = fs.GetStageCreateInfo();
9518
9519 VkPipelineVertexInputStateCreateInfo vi_ci = {};
9520 vi_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
9521 vi_ci.pNext = nullptr;
9522 vi_ci.vertexBindingDescriptionCount = 0;
9523 vi_ci.pVertexBindingDescriptions = nullptr;
9524 vi_ci.vertexAttributeDescriptionCount = 0;
9525 vi_ci.pVertexAttributeDescriptions = nullptr;
9526
9527 VkPipelineInputAssemblyStateCreateInfo ia_ci = {};
9528 ia_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
9529 ia_ci.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP;
9530
9531 VkPipelineRasterizationStateCreateInfo rs_ci = {};
9532 rs_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
9533 rs_ci.pNext = nullptr;
9534
Mark Youngc89c6312016-03-31 16:03:20 -06009535 VkPipelineColorBlendAttachmentState att = {};
9536 att.blendEnable = VK_FALSE;
9537 att.colorWriteMask = 0xf;
9538
Karl Schultz6addd812016-02-02 17:17:23 -07009539 VkPipelineColorBlendStateCreateInfo cb_ci = {};
9540 cb_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO;
9541 cb_ci.pNext = nullptr;
Mark Youngc89c6312016-03-31 16:03:20 -06009542 cb_ci.attachmentCount = 1;
9543 cb_ci.pAttachments = &att;
Karl Schultz6addd812016-02-02 17:17:23 -07009544
9545 VkGraphicsPipelineCreateInfo gp_ci = {};
9546 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
9547 gp_ci.stageCount = 2;
9548 gp_ci.pStages = shaderStages;
9549 gp_ci.pVertexInputState = &vi_ci;
9550 gp_ci.pInputAssemblyState = &ia_ci;
9551 gp_ci.pViewportState = &vp_state_ci;
9552 gp_ci.pRasterizationState = &rs_ci;
9553 gp_ci.pColorBlendState = &cb_ci;
9554 gp_ci.pDynamicState = &dyn_state_ci;
9555 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
9556 gp_ci.layout = pipeline_layout;
9557 gp_ci.renderPass = renderPass();
9558
9559 VkPipelineCacheCreateInfo pc_ci = {};
9560 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
9561
9562 VkPipeline pipeline;
9563 VkPipelineCache pipelineCache;
9564
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009565 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Karl Schultz6addd812016-02-02 17:17:23 -07009566 ASSERT_VK_SUCCESS(err);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009567 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Karl Schultz6addd812016-02-02 17:17:23 -07009568
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009569 m_errorMonitor->VerifyFound();
Karl Schultz6addd812016-02-02 17:17:23 -07009570
9571 // Now hit second fail case where we set scissor w/ different count than PSO
9572 // First need to successfully create the PSO from above by setting
9573 // pViewports
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009574 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Dynamic viewport(s) 0 are used by PSO, ");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06009575
Tobin Ehlisd332f282015-10-02 11:00:56 -06009576 VkRect2D sc = {}; // Just need dummy vp to point to
9577 vp_state_ci.pScissors = &sc;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009578 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Tobin Ehlisd332f282015-10-02 11:00:56 -06009579 ASSERT_VK_SUCCESS(err);
9580 BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009581 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline);
Chris Forbesc08a6ca2016-07-28 14:14:07 +12009582 VkViewport viewports[1] = {}; // don't care about data
Tobin Ehlisd332f282015-10-02 11:00:56 -06009583 // Count of 2 doesn't match PSO count of 1
Chris Forbesc08a6ca2016-07-28 14:14:07 +12009584 vkCmdSetViewport(m_commandBuffer->GetBufferHandle(), 1, 1, viewports);
Tobin Ehlisd332f282015-10-02 11:00:56 -06009585 Draw(1, 0, 0, 0);
9586
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009587 m_errorMonitor->VerifyFound();
Tobin Ehlise68360f2015-10-01 11:15:13 -06009588
Chia-I Wuf7458c52015-10-26 21:10:41 +08009589 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
9590 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
9591 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
9592 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tony Barbourdf4c0042016-06-01 15:55:43 -06009593 vkDestroyPipeline(m_device->device(), pipeline, NULL);
Tobin Ehlise68360f2015-10-01 11:15:13 -06009594}
9595
Mark Young7394fdd2016-03-31 14:56:43 -06009596TEST_F(VkLayerTest, PSOLineWidthInvalid) {
9597 VkResult err;
9598
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009599 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Attempt to set lineWidth to -1");
Mark Young7394fdd2016-03-31 14:56:43 -06009600
9601 ASSERT_NO_FATAL_FAILURE(InitState());
9602 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
9603
9604 VkDescriptorPoolSize ds_type_count = {};
9605 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
9606 ds_type_count.descriptorCount = 1;
9607
9608 VkDescriptorPoolCreateInfo ds_pool_ci = {};
9609 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
9610 ds_pool_ci.maxSets = 1;
9611 ds_pool_ci.poolSizeCount = 1;
9612 ds_pool_ci.pPoolSizes = &ds_type_count;
9613
9614 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009615 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Mark Young7394fdd2016-03-31 14:56:43 -06009616 ASSERT_VK_SUCCESS(err);
9617
9618 VkDescriptorSetLayoutBinding dsl_binding = {};
9619 dsl_binding.binding = 0;
9620 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
9621 dsl_binding.descriptorCount = 1;
9622 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
9623
9624 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
9625 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
9626 ds_layout_ci.bindingCount = 1;
9627 ds_layout_ci.pBindings = &dsl_binding;
9628
9629 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009630 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Mark Young7394fdd2016-03-31 14:56:43 -06009631 ASSERT_VK_SUCCESS(err);
9632
9633 VkDescriptorSet descriptorSet;
9634 VkDescriptorSetAllocateInfo alloc_info = {};
9635 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
9636 alloc_info.descriptorSetCount = 1;
9637 alloc_info.descriptorPool = ds_pool;
9638 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009639 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Mark Young7394fdd2016-03-31 14:56:43 -06009640 ASSERT_VK_SUCCESS(err);
9641
9642 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
9643 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
9644 pipeline_layout_ci.setLayoutCount = 1;
9645 pipeline_layout_ci.pSetLayouts = &ds_layout;
9646
9647 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009648 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Mark Young7394fdd2016-03-31 14:56:43 -06009649 ASSERT_VK_SUCCESS(err);
9650
9651 VkPipelineViewportStateCreateInfo vp_state_ci = {};
9652 vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
9653 vp_state_ci.scissorCount = 1;
9654 vp_state_ci.pScissors = NULL;
9655 vp_state_ci.viewportCount = 1;
9656 vp_state_ci.pViewports = NULL;
9657
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009658 VkDynamicState dynamic_states[3] = {VK_DYNAMIC_STATE_VIEWPORT, VK_DYNAMIC_STATE_SCISSOR, VK_DYNAMIC_STATE_LINE_WIDTH};
Mark Young7394fdd2016-03-31 14:56:43 -06009659 // Set scissor as dynamic to avoid that error
9660 VkPipelineDynamicStateCreateInfo dyn_state_ci = {};
9661 dyn_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_DYNAMIC_STATE_CREATE_INFO;
9662 dyn_state_ci.dynamicStateCount = 2;
9663 dyn_state_ci.pDynamicStates = dynamic_states;
9664
9665 VkPipelineShaderStageCreateInfo shaderStages[2];
9666 memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo));
9667
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009668 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
9669 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT,
Mark Young7394fdd2016-03-31 14:56:43 -06009670 this); // TODO - We shouldn't need a fragment shader
9671 // but add it to be able to run on more devices
9672 shaderStages[0] = vs.GetStageCreateInfo();
9673 shaderStages[1] = fs.GetStageCreateInfo();
9674
9675 VkPipelineVertexInputStateCreateInfo vi_ci = {};
9676 vi_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
9677 vi_ci.pNext = nullptr;
9678 vi_ci.vertexBindingDescriptionCount = 0;
9679 vi_ci.pVertexBindingDescriptions = nullptr;
9680 vi_ci.vertexAttributeDescriptionCount = 0;
9681 vi_ci.pVertexAttributeDescriptions = nullptr;
9682
9683 VkPipelineInputAssemblyStateCreateInfo ia_ci = {};
9684 ia_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
9685 ia_ci.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP;
9686
9687 VkPipelineRasterizationStateCreateInfo rs_ci = {};
9688 rs_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
9689 rs_ci.pNext = nullptr;
9690
Mark Young47107952016-05-02 15:59:55 -06009691 // Check too low (line width of -1.0f).
9692 rs_ci.lineWidth = -1.0f;
Mark Young7394fdd2016-03-31 14:56:43 -06009693
9694 VkPipelineColorBlendAttachmentState att = {};
9695 att.blendEnable = VK_FALSE;
9696 att.colorWriteMask = 0xf;
9697
9698 VkPipelineColorBlendStateCreateInfo cb_ci = {};
9699 cb_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO;
9700 cb_ci.pNext = nullptr;
9701 cb_ci.attachmentCount = 1;
9702 cb_ci.pAttachments = &att;
9703
9704 VkGraphicsPipelineCreateInfo gp_ci = {};
9705 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
9706 gp_ci.stageCount = 2;
9707 gp_ci.pStages = shaderStages;
9708 gp_ci.pVertexInputState = &vi_ci;
9709 gp_ci.pInputAssemblyState = &ia_ci;
9710 gp_ci.pViewportState = &vp_state_ci;
9711 gp_ci.pRasterizationState = &rs_ci;
9712 gp_ci.pColorBlendState = &cb_ci;
9713 gp_ci.pDynamicState = &dyn_state_ci;
9714 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
9715 gp_ci.layout = pipeline_layout;
9716 gp_ci.renderPass = renderPass();
9717
9718 VkPipelineCacheCreateInfo pc_ci = {};
9719 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
9720
9721 VkPipeline pipeline;
9722 VkPipelineCache pipelineCache;
9723
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009724 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Mark Young7394fdd2016-03-31 14:56:43 -06009725 ASSERT_VK_SUCCESS(err);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009726 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Mark Young7394fdd2016-03-31 14:56:43 -06009727
9728 m_errorMonitor->VerifyFound();
Tony Barbourdf4c0042016-06-01 15:55:43 -06009729 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
Mark Young7394fdd2016-03-31 14:56:43 -06009730
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009731 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Attempt to set lineWidth to 65536");
Mark Young7394fdd2016-03-31 14:56:43 -06009732
9733 // Check too high (line width of 65536.0f).
9734 rs_ci.lineWidth = 65536.0f;
9735
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009736 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Mark Young7394fdd2016-03-31 14:56:43 -06009737 ASSERT_VK_SUCCESS(err);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009738 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Mark Young7394fdd2016-03-31 14:56:43 -06009739
9740 m_errorMonitor->VerifyFound();
Tony Barbourdf4c0042016-06-01 15:55:43 -06009741 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
Mark Young7394fdd2016-03-31 14:56:43 -06009742
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009743 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Attempt to set lineWidth to -1");
Mark Young7394fdd2016-03-31 14:56:43 -06009744
9745 dyn_state_ci.dynamicStateCount = 3;
9746
9747 rs_ci.lineWidth = 1.0f;
9748
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009749 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Mark Young7394fdd2016-03-31 14:56:43 -06009750 ASSERT_VK_SUCCESS(err);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009751 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Mark Young7394fdd2016-03-31 14:56:43 -06009752 BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009753 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline);
Mark Young7394fdd2016-03-31 14:56:43 -06009754
9755 // Check too low with dynamic setting.
Mark Young47107952016-05-02 15:59:55 -06009756 vkCmdSetLineWidth(m_commandBuffer->GetBufferHandle(), -1.0f);
Mark Young7394fdd2016-03-31 14:56:43 -06009757 m_errorMonitor->VerifyFound();
9758
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009759 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Attempt to set lineWidth to 65536");
Mark Young7394fdd2016-03-31 14:56:43 -06009760
9761 // Check too high with dynamic setting.
9762 vkCmdSetLineWidth(m_commandBuffer->GetBufferHandle(), 65536.0f);
9763 m_errorMonitor->VerifyFound();
9764 EndCommandBuffer();
9765
9766 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
9767 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
9768 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
9769 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tony Barbourdf4c0042016-06-01 15:55:43 -06009770 vkDestroyPipeline(m_device->device(), pipeline, NULL);
Mark Young7394fdd2016-03-31 14:56:43 -06009771}
9772
Karl Schultz6addd812016-02-02 17:17:23 -07009773TEST_F(VkLayerTest, NullRenderPass) {
Tobin Ehlis98aa0ed2015-06-25 16:27:19 -06009774 // Bind a NULL RenderPass
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009775 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
9776 "You cannot use a NULL RenderPass object in vkCmdBeginRenderPass()");
Tobin Ehlis98aa0ed2015-06-25 16:27:19 -06009777
9778 ASSERT_NO_FATAL_FAILURE(InitState());
9779 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlis98aa0ed2015-06-25 16:27:19 -06009780
Tony Barbourfe3351b2015-07-28 10:17:20 -06009781 BeginCommandBuffer();
Karl Schultz6addd812016-02-02 17:17:23 -07009782 // Don't care about RenderPass handle b/c error should be flagged before
9783 // that
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009784 vkCmdBeginRenderPass(m_commandBuffer->GetBufferHandle(), NULL, VK_SUBPASS_CONTENTS_INLINE);
Tobin Ehlis98aa0ed2015-06-25 16:27:19 -06009785
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009786 m_errorMonitor->VerifyFound();
Tobin Ehlis98aa0ed2015-06-25 16:27:19 -06009787}
9788
Karl Schultz6addd812016-02-02 17:17:23 -07009789TEST_F(VkLayerTest, RenderPassWithinRenderPass) {
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06009790 // Bind a BeginRenderPass within an active RenderPass
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009791 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
9792 "It is invalid to issue this call inside an active render pass");
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06009793
9794 ASSERT_NO_FATAL_FAILURE(InitState());
9795 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06009796
Tony Barbourfe3351b2015-07-28 10:17:20 -06009797 BeginCommandBuffer();
Karl Schultz6addd812016-02-02 17:17:23 -07009798 // Just create a dummy Renderpass that's non-NULL so we can get to the
9799 // proper error
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009800 vkCmdBeginRenderPass(m_commandBuffer->GetBufferHandle(), &m_renderPassBeginInfo, VK_SUBPASS_CONTENTS_INLINE);
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06009801
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009802 m_errorMonitor->VerifyFound();
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06009803}
9804
Chris Forbes2eeabe32016-06-21 20:52:34 +12009805TEST_F(VkLayerTest, RenderPassSecondaryCommandBuffersMultipleTimes) {
9806 m_errorMonitor->ExpectSuccess();
9807
9808 ASSERT_NO_FATAL_FAILURE(InitState());
9809 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
9810
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009811 BeginCommandBuffer(); // framework implicitly begins the renderpass.
Chris Forbes2eeabe32016-06-21 20:52:34 +12009812 vkCmdEndRenderPass(m_commandBuffer->GetBufferHandle()); // end implicit.
9813
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009814 vkCmdBeginRenderPass(m_commandBuffer->GetBufferHandle(), &m_renderPassBeginInfo, VK_SUBPASS_CONTENTS_SECONDARY_COMMAND_BUFFERS);
Chris Forbes2eeabe32016-06-21 20:52:34 +12009815 vkCmdEndRenderPass(m_commandBuffer->GetBufferHandle());
9816 m_errorMonitor->VerifyNotFound();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009817 vkCmdBeginRenderPass(m_commandBuffer->GetBufferHandle(), &m_renderPassBeginInfo, VK_SUBPASS_CONTENTS_INLINE);
Chris Forbes2eeabe32016-06-21 20:52:34 +12009818 m_errorMonitor->VerifyNotFound();
9819 vkCmdEndRenderPass(m_commandBuffer->GetBufferHandle());
9820 m_errorMonitor->VerifyNotFound();
9821
9822 m_commandBuffer->EndCommandBuffer();
9823 m_errorMonitor->VerifyNotFound();
9824}
9825
Tobin Ehlis5a1c0332016-05-31 13:59:26 -06009826TEST_F(VkLayerTest, RenderPassClearOpMismatch) {
9827 TEST_DESCRIPTION("Begin a renderPass where clearValueCount is less than"
9828 "the number of renderPass attachments that use loadOp"
9829 "VK_ATTACHMENT_LOAD_OP_CLEAR.");
9830
9831 ASSERT_NO_FATAL_FAILURE(InitState());
9832 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
9833
9834 // Create a renderPass with a single attachment that uses loadOp CLEAR
9835 VkAttachmentReference attach = {};
9836 attach.layout = VK_IMAGE_LAYOUT_GENERAL;
9837 VkSubpassDescription subpass = {};
9838 subpass.inputAttachmentCount = 1;
9839 subpass.pInputAttachments = &attach;
9840 VkRenderPassCreateInfo rpci = {};
9841 rpci.subpassCount = 1;
9842 rpci.pSubpasses = &subpass;
9843 rpci.attachmentCount = 1;
9844 VkAttachmentDescription attach_desc = {};
9845 attach_desc.format = VK_FORMAT_UNDEFINED;
9846 // Set loadOp to CLEAR
9847 attach_desc.loadOp = VK_ATTACHMENT_LOAD_OP_CLEAR;
9848 rpci.pAttachments = &attach_desc;
9849 rpci.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
9850 VkRenderPass rp;
9851 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
9852
9853 VkCommandBufferInheritanceInfo hinfo = {};
9854 hinfo.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_INHERITANCE_INFO;
9855 hinfo.renderPass = VK_NULL_HANDLE;
9856 hinfo.subpass = 0;
9857 hinfo.framebuffer = VK_NULL_HANDLE;
9858 hinfo.occlusionQueryEnable = VK_FALSE;
9859 hinfo.queryFlags = 0;
9860 hinfo.pipelineStatistics = 0;
9861 VkCommandBufferBeginInfo info = {};
9862 info.flags = VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT;
9863 info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
9864 info.pInheritanceInfo = &hinfo;
9865
9866 vkBeginCommandBuffer(m_commandBuffer->handle(), &info);
9867 VkRenderPassBeginInfo rp_begin = {};
9868 rp_begin.sType = VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO;
9869 rp_begin.pNext = NULL;
9870 rp_begin.renderPass = renderPass();
9871 rp_begin.framebuffer = framebuffer();
9872 rp_begin.clearValueCount = 0; // Should be 1
9873
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009874 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " has a clearValueCount of 0 but "
9875 "there must be at least 1 entries in "
9876 "pClearValues array to account for ");
Tobin Ehlis5a1c0332016-05-31 13:59:26 -06009877
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009878 vkCmdBeginRenderPass(m_commandBuffer->GetBufferHandle(), &rp_begin, VK_SUBPASS_CONTENTS_INLINE);
Tobin Ehlis5a1c0332016-05-31 13:59:26 -06009879
9880 m_errorMonitor->VerifyFound();
Mark Lobodzinski5c70ebd2016-06-09 13:45:00 -06009881
9882 vkDestroyRenderPass(m_device->device(), rp, NULL);
Tobin Ehlis5a1c0332016-05-31 13:59:26 -06009883}
9884
Cody Northrop3bb4d962016-05-09 16:15:57 -06009885TEST_F(VkLayerTest, EndCommandBufferWithinRenderPass) {
9886
9887 TEST_DESCRIPTION("End a command buffer with an active render pass");
9888
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009889 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
9890 "It is invalid to issue this call inside an active render pass");
Cody Northrop3bb4d962016-05-09 16:15:57 -06009891
9892 ASSERT_NO_FATAL_FAILURE(InitState());
9893 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
9894
9895 // The framework's BeginCommandBuffer calls CreateRenderPass
9896 BeginCommandBuffer();
9897
9898 // Call directly into vkEndCommandBuffer instead of the
9899 // the framework's EndCommandBuffer, which inserts a
9900 // vkEndRenderPass
9901 vkEndCommandBuffer(m_commandBuffer->GetBufferHandle());
9902
9903 m_errorMonitor->VerifyFound();
9904
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009905 // TODO: Add test for VK_COMMAND_BUFFER_LEVEL_SECONDARY
9906 // TODO: Add test for VK_COMMAND_BUFFER_USAGE_RENDER_PASS_CONTINUE_BIT
Cody Northrop3bb4d962016-05-09 16:15:57 -06009907}
9908
Karl Schultz6addd812016-02-02 17:17:23 -07009909TEST_F(VkLayerTest, FillBufferWithinRenderPass) {
Mark Lobodzinskid5639502015-09-24 09:51:47 -06009910 // Call CmdFillBuffer within an active renderpass
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009911 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
9912 "It is invalid to issue this call inside an active render pass");
Mark Lobodzinskid5639502015-09-24 09:51:47 -06009913
9914 ASSERT_NO_FATAL_FAILURE(InitState());
9915 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Mark Lobodzinskid5639502015-09-24 09:51:47 -06009916
9917 // Renderpass is started here
9918 BeginCommandBuffer();
9919
9920 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009921 vk_testing::Buffer dstBuffer;
9922 dstBuffer.init_as_dst(*m_device, (VkDeviceSize)1024, reqs);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06009923
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009924 m_commandBuffer->FillBuffer(dstBuffer.handle(), 0, 4, 0x11111111);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06009925
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009926 m_errorMonitor->VerifyFound();
Mark Lobodzinskid5639502015-09-24 09:51:47 -06009927}
9928
Karl Schultz6addd812016-02-02 17:17:23 -07009929TEST_F(VkLayerTest, UpdateBufferWithinRenderPass) {
Mark Lobodzinskid5639502015-09-24 09:51:47 -06009930 // Call CmdUpdateBuffer within an active renderpass
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009931 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
9932 "It is invalid to issue this call inside an active render pass");
Mark Lobodzinskid5639502015-09-24 09:51:47 -06009933
9934 ASSERT_NO_FATAL_FAILURE(InitState());
9935 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Mark Lobodzinskid5639502015-09-24 09:51:47 -06009936
9937 // Renderpass is started here
9938 BeginCommandBuffer();
9939
9940 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009941 vk_testing::Buffer dstBuffer;
9942 dstBuffer.init_as_dst(*m_device, (VkDeviceSize)1024, reqs);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06009943
Karl Schultz6addd812016-02-02 17:17:23 -07009944 VkDeviceSize dstOffset = 0;
9945 VkDeviceSize dataSize = 1024;
Karl Schultzee344492016-07-11 15:09:57 -06009946 const void *pData = NULL;
Mark Lobodzinskid5639502015-09-24 09:51:47 -06009947
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009948 vkCmdUpdateBuffer(m_commandBuffer->GetBufferHandle(), dstBuffer.handle(), dstOffset, dataSize, pData);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06009949
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009950 m_errorMonitor->VerifyFound();
Mark Lobodzinskid5639502015-09-24 09:51:47 -06009951}
9952
Karl Schultz6addd812016-02-02 17:17:23 -07009953TEST_F(VkLayerTest, ClearColorImageWithinRenderPass) {
Mark Lobodzinskid5639502015-09-24 09:51:47 -06009954 // Call CmdClearColorImage within an active RenderPass
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009955 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
9956 "It is invalid to issue this call inside an active render pass");
Mark Lobodzinskid5639502015-09-24 09:51:47 -06009957
9958 ASSERT_NO_FATAL_FAILURE(InitState());
9959 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Mark Lobodzinskid5639502015-09-24 09:51:47 -06009960
9961 // Renderpass is started here
9962 BeginCommandBuffer();
9963
Michael Lentine0a369f62016-02-03 16:51:46 -06009964 VkClearColorValue clear_color;
9965 memset(clear_color.uint32, 0, sizeof(uint32_t) * 4);
Karl Schultz6addd812016-02-02 17:17:23 -07009966 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
9967 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
9968 const int32_t tex_width = 32;
9969 const int32_t tex_height = 32;
9970 VkImageCreateInfo image_create_info = {};
9971 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
9972 image_create_info.pNext = NULL;
9973 image_create_info.imageType = VK_IMAGE_TYPE_2D;
9974 image_create_info.format = tex_format;
9975 image_create_info.extent.width = tex_width;
9976 image_create_info.extent.height = tex_height;
9977 image_create_info.extent.depth = 1;
9978 image_create_info.mipLevels = 1;
9979 image_create_info.arrayLayers = 1;
9980 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
9981 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
9982 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
Mark Lobodzinskid5639502015-09-24 09:51:47 -06009983
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009984 vk_testing::Image dstImage;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009985 dstImage.init(*m_device, (const VkImageCreateInfo &)image_create_info, reqs);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06009986
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009987 const VkImageSubresourceRange range = vk_testing::Image::subresource_range(image_create_info, VK_IMAGE_ASPECT_COLOR_BIT);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06009988
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009989 vkCmdClearColorImage(m_commandBuffer->GetBufferHandle(), dstImage.handle(), VK_IMAGE_LAYOUT_GENERAL, &clear_color, 1, &range);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06009990
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009991 m_errorMonitor->VerifyFound();
Mark Lobodzinskid5639502015-09-24 09:51:47 -06009992}
9993
Karl Schultz6addd812016-02-02 17:17:23 -07009994TEST_F(VkLayerTest, ClearDepthStencilImageWithinRenderPass) {
Mark Lobodzinskid5639502015-09-24 09:51:47 -06009995 // Call CmdClearDepthStencilImage within an active RenderPass
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009996 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
9997 "It is invalid to issue this call inside an active render pass");
Mark Lobodzinskid5639502015-09-24 09:51:47 -06009998
9999 ASSERT_NO_FATAL_FAILURE(InitState());
10000 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Mark Lobodzinskid5639502015-09-24 09:51:47 -060010001
10002 // Renderpass is started here
10003 BeginCommandBuffer();
10004
10005 VkClearDepthStencilValue clear_value = {0};
Dustin Gravesa2e5c942016-02-11 18:28:06 -070010006 VkMemoryPropertyFlags reqs = 0;
Karl Schultz6addd812016-02-02 17:17:23 -070010007 VkImageCreateInfo image_create_info = vk_testing::Image::create_info();
10008 image_create_info.imageType = VK_IMAGE_TYPE_2D;
10009 image_create_info.format = VK_FORMAT_D24_UNORM_S8_UINT;
10010 image_create_info.extent.width = 64;
10011 image_create_info.extent.height = 64;
10012 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
10013 image_create_info.usage = VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT;
Mark Lobodzinskid5639502015-09-24 09:51:47 -060010014
Chia-I Wu3432a0c2015-10-27 18:04:07 +080010015 vk_testing::Image dstImage;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010016 dstImage.init(*m_device, (const VkImageCreateInfo &)image_create_info, reqs);
Mark Lobodzinskid5639502015-09-24 09:51:47 -060010017
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010018 const VkImageSubresourceRange range = vk_testing::Image::subresource_range(image_create_info, VK_IMAGE_ASPECT_DEPTH_BIT);
Mark Lobodzinskid5639502015-09-24 09:51:47 -060010019
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010020 vkCmdClearDepthStencilImage(m_commandBuffer->GetBufferHandle(), dstImage.handle(),
10021 VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL, &clear_value, 1, &range);
Mark Lobodzinskid5639502015-09-24 09:51:47 -060010022
Chris Forbes8f36a8a2016-04-07 13:21:07 +120010023 m_errorMonitor->VerifyFound();
Mark Lobodzinskid5639502015-09-24 09:51:47 -060010024}
10025
Karl Schultz6addd812016-02-02 17:17:23 -070010026TEST_F(VkLayerTest, ClearColorAttachmentsOutsideRenderPass) {
Courtney Goeltzenleuchterc9323e02015-10-15 16:51:05 -060010027 // Call CmdClearAttachmentss outside of an active RenderPass
Karl Schultz6addd812016-02-02 17:17:23 -070010028 VkResult err;
Mark Lobodzinskid5639502015-09-24 09:51:47 -060010029
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010030 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "vkCmdClearAttachments(): This call "
10031 "must be issued inside an active "
10032 "render pass");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060010033
Mark Lobodzinskid5639502015-09-24 09:51:47 -060010034 ASSERT_NO_FATAL_FAILURE(InitState());
10035 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Mark Lobodzinskid5639502015-09-24 09:51:47 -060010036
10037 // Start no RenderPass
Chia-I Wu3432a0c2015-10-27 18:04:07 +080010038 err = m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskid5639502015-09-24 09:51:47 -060010039 ASSERT_VK_SUCCESS(err);
10040
Courtney Goeltzenleuchterc9323e02015-10-15 16:51:05 -060010041 VkClearAttachment color_attachment;
10042 color_attachment.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
10043 color_attachment.clearValue.color.float32[0] = 0;
10044 color_attachment.clearValue.color.float32[1] = 0;
10045 color_attachment.clearValue.color.float32[2] = 0;
10046 color_attachment.clearValue.color.float32[3] = 0;
10047 color_attachment.colorAttachment = 0;
Karl Schultz6addd812016-02-02 17:17:23 -070010048 VkClearRect clear_rect = {{{0, 0}, {32, 32}}};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010049 vkCmdClearAttachments(m_commandBuffer->GetBufferHandle(), 1, &color_attachment, 1, &clear_rect);
Mark Lobodzinskid5639502015-09-24 09:51:47 -060010050
Chris Forbes8f36a8a2016-04-07 13:21:07 +120010051 m_errorMonitor->VerifyFound();
Mark Lobodzinskid5639502015-09-24 09:51:47 -060010052}
10053
Chris Forbes3b97e932016-09-07 11:29:24 +120010054TEST_F(VkLayerTest, RenderPassExcessiveNextSubpass) {
10055 TEST_DESCRIPTION("Test that an error is produced when CmdNextSubpass is "
10056 "called too many times in a renderpass instance");
10057
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010058 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "vkCmdNextSubpass(): Attempted to advance "
10059 "beyond final subpass");
Chris Forbes3b97e932016-09-07 11:29:24 +120010060
10061 ASSERT_NO_FATAL_FAILURE(InitState());
10062 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
10063
10064 BeginCommandBuffer();
10065
10066 // error here.
10067 vkCmdNextSubpass(m_commandBuffer->GetBufferHandle(), VK_SUBPASS_CONTENTS_INLINE);
10068 m_errorMonitor->VerifyFound();
10069
10070 EndCommandBuffer();
10071}
10072
Chris Forbes6d624702016-09-07 13:57:05 +120010073TEST_F(VkLayerTest, RenderPassEndedBeforeFinalSubpass) {
10074 TEST_DESCRIPTION("Test that an error is produced when CmdEndRenderPass is "
10075 "called before the final subpass has been reached");
10076
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010077 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "vkCmdEndRenderPass(): Called before reaching "
10078 "final subpass");
Chris Forbes6d624702016-09-07 13:57:05 +120010079
10080 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010081 VkSubpassDescription sd[2] = {{0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 0, nullptr, nullptr, nullptr, 0, nullptr},
10082 {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 0, nullptr, nullptr, nullptr, 0, nullptr}};
Chris Forbes6d624702016-09-07 13:57:05 +120010083
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010084 VkRenderPassCreateInfo rcpi = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 0, nullptr, 2, sd, 0, nullptr};
Chris Forbes6d624702016-09-07 13:57:05 +120010085
10086 VkRenderPass rp;
10087 VkResult err = vkCreateRenderPass(m_device->device(), &rcpi, nullptr, &rp);
10088 ASSERT_VK_SUCCESS(err);
10089
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010090 VkFramebufferCreateInfo fbci = {VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr, 0, rp, 0, nullptr, 16, 16, 1};
Chris Forbes6d624702016-09-07 13:57:05 +120010091
10092 VkFramebuffer fb;
10093 err = vkCreateFramebuffer(m_device->device(), &fbci, nullptr, &fb);
10094 ASSERT_VK_SUCCESS(err);
10095
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010096 m_commandBuffer->BeginCommandBuffer(); // no implicit RP begin
Chris Forbes6d624702016-09-07 13:57:05 +120010097
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010098 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 +120010099
10100 vkCmdBeginRenderPass(m_commandBuffer->GetBufferHandle(), &rpbi, VK_SUBPASS_CONTENTS_INLINE);
10101
10102 // Error here.
10103 vkCmdEndRenderPass(m_commandBuffer->GetBufferHandle());
10104 m_errorMonitor->VerifyFound();
10105
10106 // Clean up.
10107 vkDestroyFramebuffer(m_device->device(), fb, nullptr);
10108 vkDestroyRenderPass(m_device->device(), rp, nullptr);
10109}
10110
Karl Schultz9e66a292016-04-21 15:57:51 -060010111TEST_F(VkLayerTest, BufferMemoryBarrierNoBuffer) {
10112 // Try to add a buffer memory barrier with no buffer.
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010113 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
10114 "required parameter pBufferMemoryBarriers[0].buffer specified as VK_NULL_HANDLE");
Karl Schultz9e66a292016-04-21 15:57:51 -060010115
10116 ASSERT_NO_FATAL_FAILURE(InitState());
10117 BeginCommandBuffer();
10118
10119 VkBufferMemoryBarrier buf_barrier = {};
10120 buf_barrier.sType = VK_STRUCTURE_TYPE_BUFFER_MEMORY_BARRIER;
10121 buf_barrier.srcAccessMask = VK_ACCESS_HOST_WRITE_BIT;
10122 buf_barrier.dstAccessMask = VK_ACCESS_SHADER_READ_BIT;
10123 buf_barrier.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
10124 buf_barrier.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
10125 buf_barrier.buffer = VK_NULL_HANDLE;
10126 buf_barrier.offset = 0;
10127 buf_barrier.size = VK_WHOLE_SIZE;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010128 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
10129 nullptr, 1, &buf_barrier, 0, nullptr);
Karl Schultz9e66a292016-04-21 15:57:51 -060010130
10131 m_errorMonitor->VerifyFound();
10132}
10133
Tony Barbour7fd5c0f2016-05-03 16:11:53 -060010134TEST_F(VkLayerTest, InvalidBarriers) {
10135 TEST_DESCRIPTION("A variety of ways to get VK_INVALID_BARRIER ");
10136
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010137 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Barriers cannot be set during subpass");
Tony Barbour7fd5c0f2016-05-03 16:11:53 -060010138
10139 ASSERT_NO_FATAL_FAILURE(InitState());
10140 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
10141
10142 VkMemoryBarrier mem_barrier = {};
10143 mem_barrier.sType = VK_STRUCTURE_TYPE_MEMORY_BARRIER;
10144 mem_barrier.pNext = NULL;
10145 mem_barrier.srcAccessMask = VK_ACCESS_HOST_WRITE_BIT;
10146 mem_barrier.dstAccessMask = VK_ACCESS_SHADER_READ_BIT;
10147 BeginCommandBuffer();
10148 // BeginCommandBuffer() starts a render pass
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010149 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 1,
Tony Barbour7fd5c0f2016-05-03 16:11:53 -060010150 &mem_barrier, 0, nullptr, 0, nullptr);
10151 m_errorMonitor->VerifyFound();
10152
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010153 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Image Layout cannot be transitioned to UNDEFINED");
Tony Barbour7fd5c0f2016-05-03 16:11:53 -060010154 VkImageObj image(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010155 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 -060010156 ASSERT_TRUE(image.initialized());
10157 VkImageMemoryBarrier img_barrier = {};
10158 img_barrier.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
10159 img_barrier.pNext = NULL;
10160 img_barrier.srcAccessMask = VK_ACCESS_HOST_WRITE_BIT;
10161 img_barrier.dstAccessMask = VK_ACCESS_SHADER_READ_BIT;
10162 img_barrier.oldLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
10163 // New layout can't be UNDEFINED
10164 img_barrier.newLayout = VK_IMAGE_LAYOUT_UNDEFINED;
10165 img_barrier.image = image.handle();
10166 img_barrier.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
10167 img_barrier.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
10168 img_barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
10169 img_barrier.subresourceRange.baseArrayLayer = 0;
10170 img_barrier.subresourceRange.baseMipLevel = 0;
10171 img_barrier.subresourceRange.layerCount = 1;
10172 img_barrier.subresourceRange.levelCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010173 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
10174 nullptr, 0, nullptr, 1, &img_barrier);
Tony Barbour7fd5c0f2016-05-03 16:11:53 -060010175 m_errorMonitor->VerifyFound();
10176 img_barrier.newLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
10177
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010178 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Subresource must have the sum of the "
10179 "baseArrayLayer");
Tony Barbour7fd5c0f2016-05-03 16:11:53 -060010180 // baseArrayLayer + layerCount must be <= image's arrayLayers
10181 img_barrier.subresourceRange.baseArrayLayer = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010182 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
10183 nullptr, 0, nullptr, 1, &img_barrier);
Tony Barbour7fd5c0f2016-05-03 16:11:53 -060010184 m_errorMonitor->VerifyFound();
10185 img_barrier.subresourceRange.baseArrayLayer = 0;
10186
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010187 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Subresource must have the sum of the baseMipLevel");
Tony Barbour7fd5c0f2016-05-03 16:11:53 -060010188 // baseMipLevel + levelCount must be <= image's mipLevels
10189 img_barrier.subresourceRange.baseMipLevel = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010190 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
10191 nullptr, 0, nullptr, 1, &img_barrier);
Tony Barbour7fd5c0f2016-05-03 16:11:53 -060010192 m_errorMonitor->VerifyFound();
10193 img_barrier.subresourceRange.baseMipLevel = 0;
10194
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010195 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 -060010196 vk_testing::Buffer buffer;
10197 buffer.init(*m_device, 256);
10198 VkBufferMemoryBarrier buf_barrier = {};
10199 buf_barrier.sType = VK_STRUCTURE_TYPE_BUFFER_MEMORY_BARRIER;
10200 buf_barrier.pNext = NULL;
10201 buf_barrier.srcAccessMask = VK_ACCESS_HOST_WRITE_BIT;
10202 buf_barrier.dstAccessMask = VK_ACCESS_SHADER_READ_BIT;
10203 buf_barrier.buffer = buffer.handle();
10204 buf_barrier.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
10205 buf_barrier.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
10206 buf_barrier.offset = 0;
10207 buf_barrier.size = VK_WHOLE_SIZE;
10208 // Can't send buffer barrier during a render pass
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010209 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
10210 nullptr, 1, &buf_barrier, 0, nullptr);
Tony Barbour7fd5c0f2016-05-03 16:11:53 -060010211 m_errorMonitor->VerifyFound();
10212 vkCmdEndRenderPass(m_commandBuffer->GetBufferHandle());
10213
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010214 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "which is not less than total size");
Tony Barbour7fd5c0f2016-05-03 16:11:53 -060010215 buf_barrier.offset = 257;
10216 // Offset greater than total size
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010217 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
10218 nullptr, 1, &buf_barrier, 0, nullptr);
Tony Barbour7fd5c0f2016-05-03 16:11:53 -060010219 m_errorMonitor->VerifyFound();
10220 buf_barrier.offset = 0;
10221
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010222 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "whose sum is greater than total size");
Tony Barbour7fd5c0f2016-05-03 16:11:53 -060010223 buf_barrier.size = 257;
10224 // Size greater than total size
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010225 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
10226 nullptr, 1, &buf_barrier, 0, nullptr);
Tony Barbour7fd5c0f2016-05-03 16:11:53 -060010227 m_errorMonitor->VerifyFound();
Tony Barbour7fd5c0f2016-05-03 16:11:53 -060010228
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -060010229 // Now exercise barrier aspect bit errors, first DS
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010230 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Image is a depth and stencil format and thus must "
10231 "have either one or both of VK_IMAGE_ASPECT_DEPTH_BIT and "
10232 "VK_IMAGE_ASPECT_STENCIL_BIT set.");
Tony Barbour7fd5c0f2016-05-03 16:11:53 -060010233 VkDepthStencilObj ds_image(m_device);
10234 ds_image.Init(m_device, 128, 128, VK_FORMAT_D24_UNORM_S8_UINT);
10235 ASSERT_TRUE(ds_image.initialized());
Tobin Ehlis15684a02016-07-21 14:55:26 -060010236 img_barrier.oldLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
10237 img_barrier.newLayout = VK_IMAGE_LAYOUT_GENERAL;
Tony Barbour7fd5c0f2016-05-03 16:11:53 -060010238 img_barrier.image = ds_image.handle();
Tobin Ehlis15684a02016-07-21 14:55:26 -060010239 // Use of COLOR aspect on DS image is error
10240 img_barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010241 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
10242 nullptr, 0, nullptr, 1, &img_barrier);
Tony Barbour7fd5c0f2016-05-03 16:11:53 -060010243 m_errorMonitor->VerifyFound();
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -060010244 // Now test depth-only
10245 VkFormatProperties format_props;
10246
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010247 vkGetPhysicalDeviceFormatProperties(m_device->phy().handle(), VK_FORMAT_D16_UNORM, &format_props);
10248 if (format_props.optimalTilingFeatures & VK_FORMAT_FEATURE_DEPTH_STENCIL_ATTACHMENT_BIT) {
10249 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Image is a depth-only format and thus must "
10250 "have VK_IMAGE_ASPECT_DEPTH_BIT set.");
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -060010251 VkDepthStencilObj d_image(m_device);
10252 d_image.Init(m_device, 128, 128, VK_FORMAT_D16_UNORM);
10253 ASSERT_TRUE(d_image.initialized());
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010254 img_barrier.oldLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
Tobin Ehlis15684a02016-07-21 14:55:26 -060010255 img_barrier.newLayout = VK_IMAGE_LAYOUT_GENERAL;
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -060010256 img_barrier.image = d_image.handle();
Tobin Ehlis15684a02016-07-21 14:55:26 -060010257 // Use of COLOR aspect on depth image is error
10258 img_barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010259 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0,
10260 0, nullptr, 0, nullptr, 1, &img_barrier);
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -060010261 m_errorMonitor->VerifyFound();
10262 }
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010263 vkGetPhysicalDeviceFormatProperties(m_device->phy().handle(), VK_FORMAT_S8_UINT, &format_props);
10264 if (format_props.optimalTilingFeatures & VK_FORMAT_FEATURE_DEPTH_STENCIL_ATTACHMENT_BIT) {
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -060010265 // Now test stencil-only
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010266 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Image is a stencil-only format and thus must "
10267 "have VK_IMAGE_ASPECT_STENCIL_BIT set.");
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -060010268 VkDepthStencilObj s_image(m_device);
10269 s_image.Init(m_device, 128, 128, VK_FORMAT_S8_UINT);
10270 ASSERT_TRUE(s_image.initialized());
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010271 img_barrier.oldLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
Tobin Ehlis15684a02016-07-21 14:55:26 -060010272 img_barrier.newLayout = VK_IMAGE_LAYOUT_GENERAL;
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -060010273 img_barrier.image = s_image.handle();
Tobin Ehlis15684a02016-07-21 14:55:26 -060010274 // Use of COLOR aspect on depth image is error
10275 img_barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_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,
10277 0, nullptr, 0, nullptr, 1, &img_barrier);
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -060010278 m_errorMonitor->VerifyFound();
10279 }
10280 // Finally test color
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010281 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Image is a color format and thus must "
10282 "have VK_IMAGE_ASPECT_COLOR_BIT set.");
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -060010283 VkImageObj c_image(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010284 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 -060010285 ASSERT_TRUE(c_image.initialized());
10286 img_barrier.oldLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
10287 img_barrier.newLayout = VK_IMAGE_LAYOUT_GENERAL;
10288 img_barrier.image = c_image.handle();
10289 // Set aspect to depth (non-color)
10290 img_barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010291 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
10292 nullptr, 0, nullptr, 1, &img_barrier);
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -060010293 m_errorMonitor->VerifyFound();
Tony Barbour7fd5c0f2016-05-03 16:11:53 -060010294}
10295
Karl Schultz6addd812016-02-02 17:17:23 -070010296TEST_F(VkLayerTest, IdxBufferAlignmentError) {
Tobin Ehlisc4c23182015-09-17 12:24:13 -060010297 // Bind a BeginRenderPass within an active RenderPass
Karl Schultz6addd812016-02-02 17:17:23 -070010298 VkResult err;
Tobin Ehlisc4c23182015-09-17 12:24:13 -060010299
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010300 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "vkCmdBindIndexBuffer() offset (0x7) does not fall on ");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060010301
Tobin Ehlisc4c23182015-09-17 12:24:13 -060010302 ASSERT_NO_FATAL_FAILURE(InitState());
10303 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlisc4c23182015-09-17 12:24:13 -060010304 uint32_t qfi = 0;
10305 VkBufferCreateInfo buffCI = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010306 buffCI.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
10307 buffCI.size = 1024;
10308 buffCI.usage = VK_BUFFER_USAGE_INDEX_BUFFER_BIT;
10309 buffCI.queueFamilyIndexCount = 1;
10310 buffCI.pQueueFamilyIndices = &qfi;
Tobin Ehlisc4c23182015-09-17 12:24:13 -060010311
10312 VkBuffer ib;
Chia-I Wuf7458c52015-10-26 21:10:41 +080010313 err = vkCreateBuffer(m_device->device(), &buffCI, NULL, &ib);
Tobin Ehlisc4c23182015-09-17 12:24:13 -060010314 ASSERT_VK_SUCCESS(err);
10315
10316 BeginCommandBuffer();
10317 ASSERT_VK_SUCCESS(err);
Karl Schultz6addd812016-02-02 17:17:23 -070010318 // vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(),
10319 // VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Tobin Ehlisc4c23182015-09-17 12:24:13 -060010320 // Should error before calling to driver so don't care about actual data
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010321 vkCmdBindIndexBuffer(m_commandBuffer->GetBufferHandle(), ib, 7, VK_INDEX_TYPE_UINT16);
Tobin Ehlisc4c23182015-09-17 12:24:13 -060010322
Chris Forbes8f36a8a2016-04-07 13:21:07 +120010323 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -060010324
Chia-I Wuf7458c52015-10-26 21:10:41 +080010325 vkDestroyBuffer(m_device->device(), ib, NULL);
Tobin Ehlisc4c23182015-09-17 12:24:13 -060010326}
10327
Mark Lobodzinski52a6e7d2016-02-25 15:09:52 -070010328TEST_F(VkLayerTest, InvalidQueueFamilyIndex) {
10329 // Create an out-of-range queueFamilyIndex
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010330 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
10331 "vkCreateBuffer: pCreateInfo->pQueueFamilyIndices[0] (777) must be one "
10332 "of the indices specified when the device was created, via the "
10333 "VkDeviceQueueCreateInfo structure.");
Mark Lobodzinski52a6e7d2016-02-25 15:09:52 -070010334
10335 ASSERT_NO_FATAL_FAILURE(InitState());
10336 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
10337 VkBufferCreateInfo buffCI = {};
10338 buffCI.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
10339 buffCI.size = 1024;
10340 buffCI.usage = VK_BUFFER_USAGE_INDEX_BUFFER_BIT;
10341 buffCI.queueFamilyIndexCount = 1;
10342 // Introduce failure by specifying invalid queue_family_index
10343 uint32_t qfi = 777;
10344 buffCI.pQueueFamilyIndices = &qfi;
Tobin Ehlis24aab042016-03-24 10:54:18 -060010345 buffCI.sharingMode = VK_SHARING_MODE_CONCURRENT; // qfi only matters in CONCURRENT mode
Mark Lobodzinski52a6e7d2016-02-25 15:09:52 -070010346
10347 VkBuffer ib;
10348 vkCreateBuffer(m_device->device(), &buffCI, NULL, &ib);
10349
Chris Forbes8f36a8a2016-04-07 13:21:07 +120010350 m_errorMonitor->VerifyFound();
Tony Barbourdf4c0042016-06-01 15:55:43 -060010351 vkDestroyBuffer(m_device->device(), ib, NULL);
Mark Lobodzinski52a6e7d2016-02-25 15:09:52 -070010352}
10353
Karl Schultz6addd812016-02-02 17:17:23 -070010354TEST_F(VkLayerTest, ExecuteCommandsPrimaryCB) {
Tobin Ehlis0c94db02016-07-19 10:49:32 -060010355 TEST_DESCRIPTION("Attempt vkCmdExecuteCommands w/ a primary cmd buffer"
10356 " (should only be secondary)");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060010357
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010358 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "vkCmdExecuteCommands() called w/ Primary Cmd Buffer ");
Tobin Ehlis4b34ddc2015-09-17 14:18:16 -060010359
10360 ASSERT_NO_FATAL_FAILURE(InitState());
10361 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlis4b34ddc2015-09-17 14:18:16 -060010362
10363 BeginCommandBuffer();
Tobin Ehlis0c94db02016-07-19 10:49:32 -060010364
Chia-I Wu3432a0c2015-10-27 18:04:07 +080010365 VkCommandBuffer primCB = m_commandBuffer->GetBufferHandle();
10366 vkCmdExecuteCommands(m_commandBuffer->GetBufferHandle(), 1, &primCB);
Tobin Ehlis4b34ddc2015-09-17 14:18:16 -060010367
Chris Forbes8f36a8a2016-04-07 13:21:07 +120010368 m_errorMonitor->VerifyFound();
Tobin Ehlis4b34ddc2015-09-17 14:18:16 -060010369}
10370
Tobin Ehlis17826bd2016-05-25 11:12:50 -060010371TEST_F(VkLayerTest, DSUsageBitsErrors) {
10372 TEST_DESCRIPTION("Attempt to update descriptor sets for images and buffers "
10373 "that do not have correct usage bits sets.");
10374 VkResult err;
10375
10376 ASSERT_NO_FATAL_FAILURE(InitState());
10377 VkDescriptorPoolSize ds_type_count[VK_DESCRIPTOR_TYPE_RANGE_SIZE] = {};
10378 for (uint32_t i = 0; i < VK_DESCRIPTOR_TYPE_RANGE_SIZE; ++i) {
10379 ds_type_count[i].type = VkDescriptorType(i);
10380 ds_type_count[i].descriptorCount = 1;
10381 }
10382 VkDescriptorPoolCreateInfo ds_pool_ci = {};
10383 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
10384 ds_pool_ci.pNext = NULL;
10385 ds_pool_ci.maxSets = VK_DESCRIPTOR_TYPE_RANGE_SIZE;
10386 ds_pool_ci.poolSizeCount = VK_DESCRIPTOR_TYPE_RANGE_SIZE;
10387 ds_pool_ci.pPoolSizes = ds_type_count;
10388
10389 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010390 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis17826bd2016-05-25 11:12:50 -060010391 ASSERT_VK_SUCCESS(err);
10392
10393 // Create 10 layouts where each has a single descriptor of different type
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010394 VkDescriptorSetLayoutBinding dsl_binding[VK_DESCRIPTOR_TYPE_RANGE_SIZE] = {};
Tobin Ehlis17826bd2016-05-25 11:12:50 -060010395 for (uint32_t i = 0; i < VK_DESCRIPTOR_TYPE_RANGE_SIZE; ++i) {
10396 dsl_binding[i].binding = 0;
10397 dsl_binding[i].descriptorType = VkDescriptorType(i);
10398 dsl_binding[i].descriptorCount = 1;
10399 dsl_binding[i].stageFlags = VK_SHADER_STAGE_ALL;
10400 dsl_binding[i].pImmutableSamplers = NULL;
10401 }
10402
10403 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
10404 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
10405 ds_layout_ci.pNext = NULL;
10406 ds_layout_ci.bindingCount = 1;
10407 VkDescriptorSetLayout ds_layouts[VK_DESCRIPTOR_TYPE_RANGE_SIZE];
10408 for (uint32_t i = 0; i < VK_DESCRIPTOR_TYPE_RANGE_SIZE; ++i) {
10409 ds_layout_ci.pBindings = dsl_binding + i;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010410 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, ds_layouts + i);
Tobin Ehlis17826bd2016-05-25 11:12:50 -060010411 ASSERT_VK_SUCCESS(err);
10412 }
10413 VkDescriptorSet descriptor_sets[VK_DESCRIPTOR_TYPE_RANGE_SIZE] = {};
10414 VkDescriptorSetAllocateInfo alloc_info = {};
10415 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
10416 alloc_info.descriptorSetCount = VK_DESCRIPTOR_TYPE_RANGE_SIZE;
10417 alloc_info.descriptorPool = ds_pool;
10418 alloc_info.pSetLayouts = ds_layouts;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010419 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, descriptor_sets);
Tobin Ehlis17826bd2016-05-25 11:12:50 -060010420 ASSERT_VK_SUCCESS(err);
10421
10422 // Create a buffer & bufferView to be used for invalid updates
10423 VkBufferCreateInfo buff_ci = {};
10424 buff_ci.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
10425 // This usage is not valid for any descriptor type
10426 buff_ci.usage = VK_BUFFER_USAGE_TRANSFER_SRC_BIT;
10427 buff_ci.size = 256;
10428 buff_ci.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
10429 VkBuffer buffer;
10430 err = vkCreateBuffer(m_device->device(), &buff_ci, NULL, &buffer);
10431 ASSERT_VK_SUCCESS(err);
10432
10433 VkBufferViewCreateInfo buff_view_ci = {};
10434 buff_view_ci.sType = VK_STRUCTURE_TYPE_BUFFER_VIEW_CREATE_INFO;
10435 buff_view_ci.buffer = buffer;
10436 buff_view_ci.format = VK_FORMAT_R8_UNORM;
10437 buff_view_ci.range = VK_WHOLE_SIZE;
10438 VkBufferView buff_view;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010439 err = vkCreateBufferView(m_device->device(), &buff_view_ci, NULL, &buff_view);
Tobin Ehlis17826bd2016-05-25 11:12:50 -060010440 ASSERT_VK_SUCCESS(err);
10441
10442 // Create an image to be used for invalid updates
10443 VkImageCreateInfo image_ci = {};
10444 image_ci.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
10445 image_ci.imageType = VK_IMAGE_TYPE_2D;
10446 image_ci.format = VK_FORMAT_R8G8B8A8_UNORM;
10447 image_ci.extent.width = 64;
10448 image_ci.extent.height = 64;
10449 image_ci.extent.depth = 1;
10450 image_ci.mipLevels = 1;
10451 image_ci.arrayLayers = 1;
10452 image_ci.samples = VK_SAMPLE_COUNT_1_BIT;
10453 image_ci.tiling = VK_IMAGE_TILING_LINEAR;
10454 image_ci.initialLayout = VK_IMAGE_LAYOUT_PREINITIALIZED;
10455 // This usage is not valid for any descriptor type
10456 image_ci.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
10457 image_ci.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
10458 VkImage image;
10459 err = vkCreateImage(m_device->device(), &image_ci, NULL, &image);
10460 ASSERT_VK_SUCCESS(err);
10461 // Bind memory to image
10462 VkMemoryRequirements mem_reqs;
10463 VkDeviceMemory image_mem;
10464 bool pass;
10465 VkMemoryAllocateInfo mem_alloc = {};
10466 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
10467 mem_alloc.pNext = NULL;
10468 mem_alloc.allocationSize = 0;
10469 mem_alloc.memoryTypeIndex = 0;
10470 vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs);
10471 mem_alloc.allocationSize = mem_reqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010472 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0);
Tobin Ehlis17826bd2016-05-25 11:12:50 -060010473 ASSERT_TRUE(pass);
10474 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &image_mem);
10475 ASSERT_VK_SUCCESS(err);
10476 err = vkBindImageMemory(m_device->device(), image, image_mem, 0);
10477 ASSERT_VK_SUCCESS(err);
10478 // Now create view for image
10479 VkImageViewCreateInfo image_view_ci = {};
10480 image_view_ci.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
10481 image_view_ci.image = image;
10482 image_view_ci.format = VK_FORMAT_R8G8B8A8_UNORM;
10483 image_view_ci.viewType = VK_IMAGE_VIEW_TYPE_2D;
10484 image_view_ci.subresourceRange.layerCount = 1;
10485 image_view_ci.subresourceRange.baseArrayLayer = 0;
10486 image_view_ci.subresourceRange.levelCount = 1;
10487 image_view_ci.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
10488 VkImageView image_view;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010489 err = vkCreateImageView(m_device->device(), &image_view_ci, NULL, &image_view);
Tobin Ehlis17826bd2016-05-25 11:12:50 -060010490 ASSERT_VK_SUCCESS(err);
10491
10492 VkDescriptorBufferInfo buff_info = {};
10493 buff_info.buffer = buffer;
10494 VkDescriptorImageInfo img_info = {};
10495 img_info.imageView = image_view;
10496 VkWriteDescriptorSet descriptor_write = {};
10497 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
10498 descriptor_write.dstBinding = 0;
10499 descriptor_write.descriptorCount = 1;
10500 descriptor_write.pTexelBufferView = &buff_view;
10501 descriptor_write.pBufferInfo = &buff_info;
10502 descriptor_write.pImageInfo = &img_info;
10503
10504 // These error messages align with VkDescriptorType struct
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010505 const char *error_msgs[] = {"", // placeholder, no error for SAMPLER descriptor
10506 " does not have VK_IMAGE_USAGE_SAMPLED_BIT set.",
10507 " does not have VK_IMAGE_USAGE_SAMPLED_BIT set.",
10508 " does not have VK_IMAGE_USAGE_STORAGE_BIT set.",
10509 " does not have VK_BUFFER_USAGE_UNIFORM_TEXEL_BUFFER_BIT set.",
10510 " does not have VK_BUFFER_USAGE_STORAGE_TEXEL_BUFFER_BIT set.",
10511 " does not have VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT set.",
10512 " does not have VK_BUFFER_USAGE_STORAGE_BUFFER_BIT set.",
10513 " does not have VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT set.",
10514 " does not have VK_BUFFER_USAGE_STORAGE_BUFFER_BIT set.",
10515 " does not have VK_IMAGE_USAGE_INPUT_ATTACHMENT_BIT set."};
Tobin Ehlis17826bd2016-05-25 11:12:50 -060010516 // Start loop at 1 as SAMPLER desc type has no usage bit error
10517 for (uint32_t i = 1; i < VK_DESCRIPTOR_TYPE_RANGE_SIZE; ++i) {
10518 descriptor_write.descriptorType = VkDescriptorType(i);
10519 descriptor_write.dstSet = descriptor_sets[i];
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010520 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, error_msgs[i]);
Tobin Ehlis17826bd2016-05-25 11:12:50 -060010521
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010522 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
Tobin Ehlis17826bd2016-05-25 11:12:50 -060010523
10524 m_errorMonitor->VerifyFound();
10525 vkDestroyDescriptorSetLayout(m_device->device(), ds_layouts[i], NULL);
10526 }
10527 vkDestroyDescriptorSetLayout(m_device->device(), ds_layouts[0], NULL);
10528 vkDestroyImage(m_device->device(), image, NULL);
Tony Barbourdf4c0042016-06-01 15:55:43 -060010529 vkFreeMemory(m_device->device(), image_mem, NULL);
Tobin Ehlis17826bd2016-05-25 11:12:50 -060010530 vkDestroyImageView(m_device->device(), image_view, NULL);
10531 vkDestroyBuffer(m_device->device(), buffer, NULL);
10532 vkDestroyBufferView(m_device->device(), buff_view, NULL);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010533 vkFreeDescriptorSets(m_device->device(), ds_pool, VK_DESCRIPTOR_TYPE_RANGE_SIZE, descriptor_sets);
Tobin Ehlis17826bd2016-05-25 11:12:50 -060010534 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
10535}
10536
Tobin Ehlis585f66d2016-07-01 18:23:58 -060010537TEST_F(VkLayerTest, DSBufferInfoErrors) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010538 TEST_DESCRIPTION("Attempt to update buffer descriptor set that has incorrect "
10539 "parameters in VkDescriptorBufferInfo struct. This includes:\n"
10540 "1. offset value greater than buffer size\n"
10541 "2. range value of 0\n"
10542 "3. range value greater than buffer (size - offset)");
Tobin Ehlis585f66d2016-07-01 18:23:58 -060010543 VkResult err;
10544
10545 ASSERT_NO_FATAL_FAILURE(InitState());
10546 VkDescriptorPoolSize ds_type_count = {};
10547 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
10548 ds_type_count.descriptorCount = 1;
10549
10550 VkDescriptorPoolCreateInfo ds_pool_ci = {};
10551 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
10552 ds_pool_ci.pNext = NULL;
10553 ds_pool_ci.maxSets = 1;
10554 ds_pool_ci.poolSizeCount = 1;
10555 ds_pool_ci.pPoolSizes = &ds_type_count;
10556
10557 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010558 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis585f66d2016-07-01 18:23:58 -060010559 ASSERT_VK_SUCCESS(err);
10560
10561 // Create layout with single uniform buffer descriptor
10562 VkDescriptorSetLayoutBinding dsl_binding = {};
10563 dsl_binding.binding = 0;
10564 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
10565 dsl_binding.descriptorCount = 1;
10566 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
10567 dsl_binding.pImmutableSamplers = NULL;
10568
10569 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
10570 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
10571 ds_layout_ci.pNext = NULL;
10572 ds_layout_ci.bindingCount = 1;
10573 ds_layout_ci.pBindings = &dsl_binding;
10574 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010575 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis585f66d2016-07-01 18:23:58 -060010576 ASSERT_VK_SUCCESS(err);
10577
10578 VkDescriptorSet descriptor_set = {};
10579 VkDescriptorSetAllocateInfo alloc_info = {};
10580 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
10581 alloc_info.descriptorSetCount = 1;
10582 alloc_info.descriptorPool = ds_pool;
10583 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010584 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
Tobin Ehlis585f66d2016-07-01 18:23:58 -060010585 ASSERT_VK_SUCCESS(err);
10586
10587 // Create a buffer to be used for invalid updates
10588 VkBufferCreateInfo buff_ci = {};
10589 buff_ci.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
10590 buff_ci.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
10591 buff_ci.size = 256;
10592 buff_ci.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
10593 VkBuffer buffer;
10594 err = vkCreateBuffer(m_device->device(), &buff_ci, NULL, &buffer);
10595 ASSERT_VK_SUCCESS(err);
10596 // Have to bind memory to buffer before descriptor update
10597 VkMemoryAllocateInfo mem_alloc = {};
10598 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
10599 mem_alloc.pNext = NULL;
10600 mem_alloc.allocationSize = 256;
10601 mem_alloc.memoryTypeIndex = 0;
10602
10603 VkMemoryRequirements mem_reqs;
10604 vkGetBufferMemoryRequirements(m_device->device(), buffer, &mem_reqs);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010605 bool pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0);
Tobin Ehlis585f66d2016-07-01 18:23:58 -060010606 if (!pass) {
10607 vkDestroyBuffer(m_device->device(), buffer, NULL);
10608 return;
10609 }
10610
10611 VkDeviceMemory mem;
10612 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem);
10613 ASSERT_VK_SUCCESS(err);
10614 err = vkBindBufferMemory(m_device->device(), buffer, mem, 0);
10615 ASSERT_VK_SUCCESS(err);
10616
10617 VkDescriptorBufferInfo buff_info = {};
10618 buff_info.buffer = buffer;
10619 // First make offset 1 larger than buffer size
10620 buff_info.offset = 257;
10621 buff_info.range = VK_WHOLE_SIZE;
10622 VkWriteDescriptorSet descriptor_write = {};
10623 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
10624 descriptor_write.dstBinding = 0;
10625 descriptor_write.descriptorCount = 1;
10626 descriptor_write.pTexelBufferView = nullptr;
10627 descriptor_write.pBufferInfo = &buff_info;
10628 descriptor_write.pImageInfo = nullptr;
10629
10630 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
10631 descriptor_write.dstSet = descriptor_set;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010632 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " offset of 257 is greater than buffer ");
Tobin Ehlis585f66d2016-07-01 18:23:58 -060010633
10634 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
10635
10636 m_errorMonitor->VerifyFound();
10637 // Now cause error due to range of 0
10638 buff_info.offset = 0;
10639 buff_info.range = 0;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010640 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
10641 " range is not VK_WHOLE_SIZE and is zero, which is not allowed.");
Tobin Ehlis585f66d2016-07-01 18:23:58 -060010642
10643 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
10644
10645 m_errorMonitor->VerifyFound();
10646 // Now cause error due to range exceeding buffer size - offset
10647 buff_info.offset = 128;
10648 buff_info.range = 200;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010649 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 -060010650
10651 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
10652
10653 m_errorMonitor->VerifyFound();
Mark Lobodzinski4bb54092016-07-06 14:27:19 -060010654 vkFreeMemory(m_device->device(), mem, NULL);
Tobin Ehlis585f66d2016-07-01 18:23:58 -060010655 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
10656 vkDestroyBuffer(m_device->device(), buffer, NULL);
10657 vkFreeDescriptorSets(m_device->device(), ds_pool, 1, &descriptor_set);
10658 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
10659}
10660
Tobin Ehlis2fc296b2016-06-15 14:05:27 -060010661TEST_F(VkLayerTest, DSAspectBitsErrors) {
10662 // TODO : Initially only catching case where DEPTH & STENCIL aspect bits
10663 // are set, but could expand this test to hit more cases.
10664 TEST_DESCRIPTION("Attempt to update descriptor sets for images "
10665 "that do not have correct aspect bits sets.");
10666 VkResult err;
10667
10668 ASSERT_NO_FATAL_FAILURE(InitState());
10669 VkDescriptorPoolSize ds_type_count = {};
10670 ds_type_count.type = VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT;
10671 ds_type_count.descriptorCount = 1;
10672
10673 VkDescriptorPoolCreateInfo ds_pool_ci = {};
10674 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
10675 ds_pool_ci.pNext = NULL;
10676 ds_pool_ci.maxSets = 5;
10677 ds_pool_ci.poolSizeCount = 1;
10678 ds_pool_ci.pPoolSizes = &ds_type_count;
10679
10680 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010681 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis2fc296b2016-06-15 14:05:27 -060010682 ASSERT_VK_SUCCESS(err);
10683
10684 VkDescriptorSetLayoutBinding dsl_binding = {};
10685 dsl_binding.binding = 0;
10686 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT;
10687 dsl_binding.descriptorCount = 1;
10688 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
10689 dsl_binding.pImmutableSamplers = NULL;
10690
10691 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
10692 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
10693 ds_layout_ci.pNext = NULL;
10694 ds_layout_ci.bindingCount = 1;
10695 ds_layout_ci.pBindings = &dsl_binding;
10696 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010697 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis2fc296b2016-06-15 14:05:27 -060010698 ASSERT_VK_SUCCESS(err);
10699
10700 VkDescriptorSet descriptor_set = {};
10701 VkDescriptorSetAllocateInfo alloc_info = {};
10702 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
10703 alloc_info.descriptorSetCount = 1;
10704 alloc_info.descriptorPool = ds_pool;
10705 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010706 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
Tobin Ehlis2fc296b2016-06-15 14:05:27 -060010707 ASSERT_VK_SUCCESS(err);
10708
10709 // Create an image to be used for invalid updates
10710 VkImageCreateInfo image_ci = {};
10711 image_ci.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
10712 image_ci.imageType = VK_IMAGE_TYPE_2D;
10713 image_ci.format = VK_FORMAT_D24_UNORM_S8_UINT;
10714 image_ci.extent.width = 64;
10715 image_ci.extent.height = 64;
10716 image_ci.extent.depth = 1;
10717 image_ci.mipLevels = 1;
10718 image_ci.arrayLayers = 1;
10719 image_ci.samples = VK_SAMPLE_COUNT_1_BIT;
10720 image_ci.tiling = VK_IMAGE_TILING_LINEAR;
10721 image_ci.initialLayout = VK_IMAGE_LAYOUT_PREINITIALIZED;
10722 image_ci.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
10723 image_ci.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
10724 VkImage image;
10725 err = vkCreateImage(m_device->device(), &image_ci, NULL, &image);
10726 ASSERT_VK_SUCCESS(err);
10727 // Bind memory to image
10728 VkMemoryRequirements mem_reqs;
10729 VkDeviceMemory image_mem;
10730 bool pass;
10731 VkMemoryAllocateInfo mem_alloc = {};
10732 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
10733 mem_alloc.pNext = NULL;
10734 mem_alloc.allocationSize = 0;
10735 mem_alloc.memoryTypeIndex = 0;
10736 vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs);
10737 mem_alloc.allocationSize = mem_reqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010738 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0);
Tobin Ehlis2fc296b2016-06-15 14:05:27 -060010739 ASSERT_TRUE(pass);
10740 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &image_mem);
10741 ASSERT_VK_SUCCESS(err);
10742 err = vkBindImageMemory(m_device->device(), image, image_mem, 0);
10743 ASSERT_VK_SUCCESS(err);
10744 // Now create view for image
10745 VkImageViewCreateInfo image_view_ci = {};
10746 image_view_ci.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
10747 image_view_ci.image = image;
10748 image_view_ci.format = VK_FORMAT_D24_UNORM_S8_UINT;
10749 image_view_ci.viewType = VK_IMAGE_VIEW_TYPE_2D;
10750 image_view_ci.subresourceRange.layerCount = 1;
10751 image_view_ci.subresourceRange.baseArrayLayer = 0;
10752 image_view_ci.subresourceRange.levelCount = 1;
10753 // Setting both depth & stencil aspect bits is illegal for descriptor
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010754 image_view_ci.subresourceRange.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT;
Tobin Ehlis2fc296b2016-06-15 14:05:27 -060010755
10756 VkImageView image_view;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010757 err = vkCreateImageView(m_device->device(), &image_view_ci, NULL, &image_view);
Tobin Ehlis2fc296b2016-06-15 14:05:27 -060010758 ASSERT_VK_SUCCESS(err);
10759
10760 VkDescriptorImageInfo img_info = {};
10761 img_info.imageView = image_view;
10762 VkWriteDescriptorSet descriptor_write = {};
10763 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
10764 descriptor_write.dstBinding = 0;
10765 descriptor_write.descriptorCount = 1;
10766 descriptor_write.pTexelBufferView = NULL;
10767 descriptor_write.pBufferInfo = NULL;
10768 descriptor_write.pImageInfo = &img_info;
10769 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT;
10770 descriptor_write.dstSet = descriptor_set;
10771 const char *error_msg = " please only set either VK_IMAGE_ASPECT_DEPTH_BIT "
10772 "or VK_IMAGE_ASPECT_STENCIL_BIT ";
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010773 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, error_msg);
Tobin Ehlis2fc296b2016-06-15 14:05:27 -060010774
10775 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
10776
10777 m_errorMonitor->VerifyFound();
10778 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
10779 vkDestroyImage(m_device->device(), image, NULL);
10780 vkFreeMemory(m_device->device(), image_mem, NULL);
10781 vkDestroyImageView(m_device->device(), image_view, NULL);
10782 vkFreeDescriptorSets(m_device->device(), ds_pool, 1, &descriptor_set);
10783 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
10784}
10785
Karl Schultz6addd812016-02-02 17:17:23 -070010786TEST_F(VkLayerTest, DSTypeMismatch) {
Tobin Ehlis49eb23d2015-05-22 12:38:55 -060010787 // Create DS w/ layout of one type and attempt Update w/ mis-matched type
Karl Schultz6addd812016-02-02 17:17:23 -070010788 VkResult err;
Tobin Ehlis3b780662015-05-28 12:11:26 -060010789
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010790 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
10791 " binding #0 with type VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER but update "
10792 "type is VK_DESCRIPTOR_TYPE_SAMPLER");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060010793
Tobin Ehlis3b780662015-05-28 12:11:26 -060010794 ASSERT_NO_FATAL_FAILURE(InitState());
Karl Schultz6addd812016-02-02 17:17:23 -070010795 // VkDescriptorSetObj descriptorSet(m_device);
Chia-I Wu1b99bb22015-10-27 19:25:11 +080010796 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010797 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
10798 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -060010799
10800 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010801 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
10802 ds_pool_ci.pNext = NULL;
10803 ds_pool_ci.maxSets = 1;
10804 ds_pool_ci.poolSizeCount = 1;
10805 ds_pool_ci.pPoolSizes = &ds_type_count;
Tony Barboureb254902015-07-15 12:50:33 -060010806
Tobin Ehlis3b780662015-05-28 12:11:26 -060010807 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010808 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis3b780662015-05-28 12:11:26 -060010809 ASSERT_VK_SUCCESS(err);
Tony Barboureb254902015-07-15 12:50:33 -060010810 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010811 dsl_binding.binding = 0;
10812 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
10813 dsl_binding.descriptorCount = 1;
10814 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
10815 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis3b780662015-05-28 12:11:26 -060010816
Tony Barboureb254902015-07-15 12:50:33 -060010817 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010818 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
10819 ds_layout_ci.pNext = NULL;
10820 ds_layout_ci.bindingCount = 1;
10821 ds_layout_ci.pBindings = &dsl_binding;
Tony Barboureb254902015-07-15 12:50:33 -060010822
Tobin Ehlis3b780662015-05-28 12:11:26 -060010823 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010824 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis3b780662015-05-28 12:11:26 -060010825 ASSERT_VK_SUCCESS(err);
10826
10827 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080010828 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +080010829 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -070010830 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -060010831 alloc_info.descriptorPool = ds_pool;
10832 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010833 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis3b780662015-05-28 12:11:26 -060010834 ASSERT_VK_SUCCESS(err);
Tobin Ehlis3b780662015-05-28 12:11:26 -060010835
Tobin Ehlis30db8f82016-05-05 08:19:48 -060010836 VkSamplerCreateInfo sampler_ci = {};
10837 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
10838 sampler_ci.pNext = NULL;
10839 sampler_ci.magFilter = VK_FILTER_NEAREST;
10840 sampler_ci.minFilter = VK_FILTER_NEAREST;
10841 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
10842 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
10843 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
10844 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
10845 sampler_ci.mipLodBias = 1.0;
10846 sampler_ci.anisotropyEnable = VK_FALSE;
10847 sampler_ci.maxAnisotropy = 1;
10848 sampler_ci.compareEnable = VK_FALSE;
10849 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
10850 sampler_ci.minLod = 1.0;
10851 sampler_ci.maxLod = 1.0;
10852 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
10853 sampler_ci.unnormalizedCoordinates = VK_FALSE;
10854 VkSampler sampler;
10855 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
10856 ASSERT_VK_SUCCESS(err);
10857
10858 VkDescriptorImageInfo info = {};
10859 info.sampler = sampler;
Chia-I Wu9d00ed72015-05-25 16:27:55 +080010860
10861 VkWriteDescriptorSet descriptor_write;
10862 memset(&descriptor_write, 0, sizeof(descriptor_write));
10863 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080010864 descriptor_write.dstSet = descriptorSet;
Chia-I Wud50a7d72015-10-26 20:48:51 +080010865 descriptor_write.descriptorCount = 1;
Tobin Ehlis3b780662015-05-28 12:11:26 -060010866 // This is a mismatched type for the layout which expects BUFFER
Chia-I Wu9d00ed72015-05-25 16:27:55 +080010867 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
Courtney Goeltzenleuchter4cb6d922015-10-23 13:38:14 -060010868 descriptor_write.pImageInfo = &info;
Chia-I Wu9d00ed72015-05-25 16:27:55 +080010869
10870 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
10871
Chris Forbes8f36a8a2016-04-07 13:21:07 +120010872 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -060010873
Chia-I Wuf7458c52015-10-26 21:10:41 +080010874 vkDestroySampler(m_device->device(), sampler, NULL);
10875 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
10876 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis49eb23d2015-05-22 12:38:55 -060010877}
10878
Karl Schultz6addd812016-02-02 17:17:23 -070010879TEST_F(VkLayerTest, DSUpdateOutOfBounds) {
Tobin Ehlis49eb23d2015-05-22 12:38:55 -060010880 // For overlapping Update, have arrayIndex exceed that of layout
Karl Schultz6addd812016-02-02 17:17:23 -070010881 VkResult err;
Tobin Ehlis3b780662015-05-28 12:11:26 -060010882
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010883 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
10884 " binding #0 with 1 total descriptors but update of 1 descriptors "
10885 "starting at binding offset of 0 combined with update array element "
10886 "offset of 1 oversteps the size of this descriptor set.");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060010887
Tobin Ehlis3b780662015-05-28 12:11:26 -060010888 ASSERT_NO_FATAL_FAILURE(InitState());
Karl Schultz6addd812016-02-02 17:17:23 -070010889 // VkDescriptorSetObj descriptorSet(m_device);
Chia-I Wu1b99bb22015-10-27 19:25:11 +080010890 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010891 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
10892 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -060010893
10894 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010895 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
10896 ds_pool_ci.pNext = NULL;
10897 ds_pool_ci.maxSets = 1;
10898 ds_pool_ci.poolSizeCount = 1;
10899 ds_pool_ci.pPoolSizes = &ds_type_count;
Tony Barboureb254902015-07-15 12:50:33 -060010900
Tobin Ehlis3b780662015-05-28 12:11:26 -060010901 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010902 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis3b780662015-05-28 12:11:26 -060010903 ASSERT_VK_SUCCESS(err);
Tobin Ehlis3b780662015-05-28 12:11:26 -060010904
Tony Barboureb254902015-07-15 12:50:33 -060010905 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010906 dsl_binding.binding = 0;
10907 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
10908 dsl_binding.descriptorCount = 1;
10909 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
10910 dsl_binding.pImmutableSamplers = NULL;
Tony Barboureb254902015-07-15 12:50:33 -060010911
10912 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010913 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
10914 ds_layout_ci.pNext = NULL;
10915 ds_layout_ci.bindingCount = 1;
10916 ds_layout_ci.pBindings = &dsl_binding;
Tony Barboureb254902015-07-15 12:50:33 -060010917
Tobin Ehlis3b780662015-05-28 12:11:26 -060010918 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010919 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis3b780662015-05-28 12:11:26 -060010920 ASSERT_VK_SUCCESS(err);
10921
10922 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080010923 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +080010924 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -070010925 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -060010926 alloc_info.descriptorPool = ds_pool;
10927 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010928 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis3b780662015-05-28 12:11:26 -060010929 ASSERT_VK_SUCCESS(err);
Tobin Ehlis3b780662015-05-28 12:11:26 -060010930
Tobin Ehlis30db8f82016-05-05 08:19:48 -060010931 // Correctly update descriptor to avoid "NOT_UPDATED" error
10932 VkDescriptorBufferInfo buff_info = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010933 buff_info.buffer = VkBuffer(0); // Don't care about buffer handle for this test
Tobin Ehlis30db8f82016-05-05 08:19:48 -060010934 buff_info.offset = 0;
10935 buff_info.range = 1024;
Chia-I Wu9d00ed72015-05-25 16:27:55 +080010936
10937 VkWriteDescriptorSet descriptor_write;
10938 memset(&descriptor_write, 0, sizeof(descriptor_write));
10939 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080010940 descriptor_write.dstSet = descriptorSet;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010941 descriptor_write.dstArrayElement = 1; /* This index out of bounds for the update */
Chia-I Wud50a7d72015-10-26 20:48:51 +080010942 descriptor_write.descriptorCount = 1;
Tobin Ehlis0a43bde2016-05-03 08:31:08 -060010943 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
10944 descriptor_write.pBufferInfo = &buff_info;
Chia-I Wu9d00ed72015-05-25 16:27:55 +080010945
10946 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
10947
Chris Forbes8f36a8a2016-04-07 13:21:07 +120010948 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -060010949
Chia-I Wuf7458c52015-10-26 21:10:41 +080010950 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
10951 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis49eb23d2015-05-22 12:38:55 -060010952}
10953
Karl Schultz6addd812016-02-02 17:17:23 -070010954TEST_F(VkLayerTest, InvalidDSUpdateIndex) {
10955 // Create layout w/ count of 1 and attempt update to that layout w/ binding
10956 // index 2
10957 VkResult err;
Tobin Ehlis3b780662015-05-28 12:11:26 -060010958
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010959 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " does not have binding 2.");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060010960
Tobin Ehlis3b780662015-05-28 12:11:26 -060010961 ASSERT_NO_FATAL_FAILURE(InitState());
Karl Schultz6addd812016-02-02 17:17:23 -070010962 // VkDescriptorSetObj descriptorSet(m_device);
Chia-I Wu1b99bb22015-10-27 19:25:11 +080010963 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010964 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
10965 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -060010966
10967 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010968 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
10969 ds_pool_ci.pNext = NULL;
10970 ds_pool_ci.maxSets = 1;
10971 ds_pool_ci.poolSizeCount = 1;
10972 ds_pool_ci.pPoolSizes = &ds_type_count;
Courtney Goeltzenleuchterfe908d32015-09-16 16:12:45 -060010973
Tobin Ehlis3b780662015-05-28 12:11:26 -060010974 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010975 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis3b780662015-05-28 12:11:26 -060010976 ASSERT_VK_SUCCESS(err);
Tobin Ehlis3b780662015-05-28 12:11:26 -060010977
Tony Barboureb254902015-07-15 12:50:33 -060010978 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010979 dsl_binding.binding = 0;
10980 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
10981 dsl_binding.descriptorCount = 1;
10982 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
10983 dsl_binding.pImmutableSamplers = NULL;
Tony Barboureb254902015-07-15 12:50:33 -060010984
10985 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010986 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
10987 ds_layout_ci.pNext = NULL;
10988 ds_layout_ci.bindingCount = 1;
10989 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlis3b780662015-05-28 12:11:26 -060010990 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010991 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis3b780662015-05-28 12:11:26 -060010992 ASSERT_VK_SUCCESS(err);
10993
10994 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080010995 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +080010996 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -070010997 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -060010998 alloc_info.descriptorPool = ds_pool;
10999 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011000 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis3b780662015-05-28 12:11:26 -060011001 ASSERT_VK_SUCCESS(err);
Tobin Ehlis3b780662015-05-28 12:11:26 -060011002
Tony Barboureb254902015-07-15 12:50:33 -060011003 VkSamplerCreateInfo sampler_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011004 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
11005 sampler_ci.pNext = NULL;
11006 sampler_ci.magFilter = VK_FILTER_NEAREST;
11007 sampler_ci.minFilter = VK_FILTER_NEAREST;
11008 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
11009 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
11010 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
11011 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
11012 sampler_ci.mipLodBias = 1.0;
11013 sampler_ci.anisotropyEnable = VK_FALSE;
11014 sampler_ci.maxAnisotropy = 1;
11015 sampler_ci.compareEnable = VK_FALSE;
11016 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
11017 sampler_ci.minLod = 1.0;
11018 sampler_ci.maxLod = 1.0;
11019 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
11020 sampler_ci.unnormalizedCoordinates = VK_FALSE;
Tony Barboureb254902015-07-15 12:50:33 -060011021
Tobin Ehlis3b780662015-05-28 12:11:26 -060011022 VkSampler sampler;
Chia-I Wuf7458c52015-10-26 21:10:41 +080011023 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
Tobin Ehlis3b780662015-05-28 12:11:26 -060011024 ASSERT_VK_SUCCESS(err);
Chia-I Wu9d00ed72015-05-25 16:27:55 +080011025
Courtney Goeltzenleuchter4cb6d922015-10-23 13:38:14 -060011026 VkDescriptorImageInfo info = {};
11027 info.sampler = sampler;
Chia-I Wu9d00ed72015-05-25 16:27:55 +080011028
11029 VkWriteDescriptorSet descriptor_write;
11030 memset(&descriptor_write, 0, sizeof(descriptor_write));
11031 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080011032 descriptor_write.dstSet = descriptorSet;
11033 descriptor_write.dstBinding = 2;
Chia-I Wud50a7d72015-10-26 20:48:51 +080011034 descriptor_write.descriptorCount = 1;
Tobin Ehlis3b780662015-05-28 12:11:26 -060011035 // This is the wrong type, but out of bounds will be flagged first
Chia-I Wu9d00ed72015-05-25 16:27:55 +080011036 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
Courtney Goeltzenleuchter4cb6d922015-10-23 13:38:14 -060011037 descriptor_write.pImageInfo = &info;
Chia-I Wu9d00ed72015-05-25 16:27:55 +080011038
11039 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
11040
Chris Forbes8f36a8a2016-04-07 13:21:07 +120011041 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -060011042
Chia-I Wuf7458c52015-10-26 21:10:41 +080011043 vkDestroySampler(m_device->device(), sampler, NULL);
11044 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
11045 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis49eb23d2015-05-22 12:38:55 -060011046}
11047
Karl Schultz6addd812016-02-02 17:17:23 -070011048TEST_F(VkLayerTest, InvalidDSUpdateStruct) {
11049 // Call UpdateDS w/ struct type other than valid VK_STRUCTUR_TYPE_UPDATE_*
11050 // types
11051 VkResult err;
Tobin Ehlis3b780662015-05-28 12:11:26 -060011052
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011053 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 -060011054
Tobin Ehlis3b780662015-05-28 12:11:26 -060011055 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinski209b5292015-09-17 09:44:05 -060011056
Chia-I Wu1b99bb22015-10-27 19:25:11 +080011057 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011058 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
11059 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -060011060
11061 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011062 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
11063 ds_pool_ci.pNext = NULL;
11064 ds_pool_ci.maxSets = 1;
11065 ds_pool_ci.poolSizeCount = 1;
11066 ds_pool_ci.pPoolSizes = &ds_type_count;
Courtney Goeltzenleuchterfe908d32015-09-16 16:12:45 -060011067
Tobin Ehlis3b780662015-05-28 12:11:26 -060011068 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011069 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis3b780662015-05-28 12:11:26 -060011070 ASSERT_VK_SUCCESS(err);
Tony Barboureb254902015-07-15 12:50:33 -060011071 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011072 dsl_binding.binding = 0;
11073 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
11074 dsl_binding.descriptorCount = 1;
11075 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
11076 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis3b780662015-05-28 12:11:26 -060011077
Tony Barboureb254902015-07-15 12:50:33 -060011078 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011079 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
11080 ds_layout_ci.pNext = NULL;
11081 ds_layout_ci.bindingCount = 1;
11082 ds_layout_ci.pBindings = &dsl_binding;
Tony Barboureb254902015-07-15 12:50:33 -060011083
Tobin Ehlis3b780662015-05-28 12:11:26 -060011084 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011085 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis3b780662015-05-28 12:11:26 -060011086 ASSERT_VK_SUCCESS(err);
11087
11088 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080011089 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +080011090 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -070011091 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -060011092 alloc_info.descriptorPool = ds_pool;
11093 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011094 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis3b780662015-05-28 12:11:26 -060011095 ASSERT_VK_SUCCESS(err);
Tobin Ehlis3b780662015-05-28 12:11:26 -060011096
Tony Barboureb254902015-07-15 12:50:33 -060011097 VkSamplerCreateInfo sampler_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011098 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
11099 sampler_ci.pNext = NULL;
11100 sampler_ci.magFilter = VK_FILTER_NEAREST;
11101 sampler_ci.minFilter = VK_FILTER_NEAREST;
11102 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
11103 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
11104 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
11105 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
11106 sampler_ci.mipLodBias = 1.0;
11107 sampler_ci.anisotropyEnable = VK_FALSE;
11108 sampler_ci.maxAnisotropy = 1;
11109 sampler_ci.compareEnable = VK_FALSE;
11110 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
11111 sampler_ci.minLod = 1.0;
11112 sampler_ci.maxLod = 1.0;
11113 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
11114 sampler_ci.unnormalizedCoordinates = VK_FALSE;
Tobin Ehlis3b780662015-05-28 12:11:26 -060011115 VkSampler sampler;
Chia-I Wuf7458c52015-10-26 21:10:41 +080011116 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
Tobin Ehlis3b780662015-05-28 12:11:26 -060011117 ASSERT_VK_SUCCESS(err);
Chia-I Wu9d00ed72015-05-25 16:27:55 +080011118
Courtney Goeltzenleuchter4cb6d922015-10-23 13:38:14 -060011119 VkDescriptorImageInfo info = {};
11120 info.sampler = sampler;
Chia-I Wu9d00ed72015-05-25 16:27:55 +080011121
11122 VkWriteDescriptorSet descriptor_write;
11123 memset(&descriptor_write, 0, sizeof(descriptor_write));
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011124 descriptor_write.sType = (VkStructureType)0x99999999; /* Intentionally broken struct type */
Chia-I Wu3432a0c2015-10-27 18:04:07 +080011125 descriptor_write.dstSet = descriptorSet;
Chia-I Wud50a7d72015-10-26 20:48:51 +080011126 descriptor_write.descriptorCount = 1;
Tobin Ehlis3b780662015-05-28 12:11:26 -060011127 // This is the wrong type, but out of bounds will be flagged first
Chia-I Wu9d00ed72015-05-25 16:27:55 +080011128 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
Courtney Goeltzenleuchter4cb6d922015-10-23 13:38:14 -060011129 descriptor_write.pImageInfo = &info;
Chia-I Wu9d00ed72015-05-25 16:27:55 +080011130
11131 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
11132
Chris Forbes8f36a8a2016-04-07 13:21:07 +120011133 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -060011134
Chia-I Wuf7458c52015-10-26 21:10:41 +080011135 vkDestroySampler(m_device->device(), sampler, NULL);
11136 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
11137 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis49eb23d2015-05-22 12:38:55 -060011138}
11139
Karl Schultz6addd812016-02-02 17:17:23 -070011140TEST_F(VkLayerTest, SampleDescriptorUpdateError) {
Tobin Ehlisa1c28562015-10-23 16:00:08 -060011141 // Create a single Sampler descriptor and send it an invalid Sampler
Karl Schultz6addd812016-02-02 17:17:23 -070011142 VkResult err;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060011143
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011144 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
11145 "Attempted write update to sampler descriptor with invalid sampler");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060011146
Tobin Ehlisa1c28562015-10-23 16:00:08 -060011147 ASSERT_NO_FATAL_FAILURE(InitState());
Karl Schultz6addd812016-02-02 17:17:23 -070011148 // TODO : Farm Descriptor setup code to helper function(s) to reduce copied
11149 // code
Chia-I Wu1b99bb22015-10-27 19:25:11 +080011150 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011151 ds_type_count.type = VK_DESCRIPTOR_TYPE_SAMPLER;
11152 ds_type_count.descriptorCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060011153
11154 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011155 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
11156 ds_pool_ci.pNext = NULL;
11157 ds_pool_ci.maxSets = 1;
11158 ds_pool_ci.poolSizeCount = 1;
11159 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060011160
11161 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011162 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060011163 ASSERT_VK_SUCCESS(err);
11164
11165 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011166 dsl_binding.binding = 0;
11167 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
11168 dsl_binding.descriptorCount = 1;
11169 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
11170 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060011171
11172 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011173 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
11174 ds_layout_ci.pNext = NULL;
11175 ds_layout_ci.bindingCount = 1;
11176 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060011177 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011178 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060011179 ASSERT_VK_SUCCESS(err);
11180
11181 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080011182 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +080011183 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -070011184 alloc_info.descriptorSetCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060011185 alloc_info.descriptorPool = ds_pool;
11186 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011187 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060011188 ASSERT_VK_SUCCESS(err);
11189
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011190 VkSampler sampler = (VkSampler)((size_t)0xbaadbeef); // Sampler with invalid handle
Tobin Ehlisa1c28562015-10-23 16:00:08 -060011191
11192 VkDescriptorImageInfo descriptor_info;
11193 memset(&descriptor_info, 0, sizeof(VkDescriptorImageInfo));
11194 descriptor_info.sampler = sampler;
11195
11196 VkWriteDescriptorSet descriptor_write;
11197 memset(&descriptor_write, 0, sizeof(descriptor_write));
11198 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080011199 descriptor_write.dstSet = descriptorSet;
11200 descriptor_write.dstBinding = 0;
Chia-I Wud50a7d72015-10-26 20:48:51 +080011201 descriptor_write.descriptorCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060011202 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
11203 descriptor_write.pImageInfo = &descriptor_info;
11204
11205 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
11206
Chris Forbes8f36a8a2016-04-07 13:21:07 +120011207 m_errorMonitor->VerifyFound();
Tobin Ehlisa1c28562015-10-23 16:00:08 -060011208
Chia-I Wuf7458c52015-10-26 21:10:41 +080011209 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
11210 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060011211}
11212
Karl Schultz6addd812016-02-02 17:17:23 -070011213TEST_F(VkLayerTest, ImageViewDescriptorUpdateError) {
11214 // Create a single combined Image/Sampler descriptor and send it an invalid
11215 // imageView
11216 VkResult err;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060011217
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011218 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Attempted write update to combined "
11219 "image sampler descriptor failed due "
11220 "to: Invalid VkImageView:");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060011221
Tobin Ehlisa1c28562015-10-23 16:00:08 -060011222 ASSERT_NO_FATAL_FAILURE(InitState());
Chia-I Wu1b99bb22015-10-27 19:25:11 +080011223 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011224 ds_type_count.type = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
11225 ds_type_count.descriptorCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060011226
11227 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011228 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
11229 ds_pool_ci.pNext = NULL;
11230 ds_pool_ci.maxSets = 1;
11231 ds_pool_ci.poolSizeCount = 1;
11232 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060011233
11234 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011235 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060011236 ASSERT_VK_SUCCESS(err);
11237
11238 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011239 dsl_binding.binding = 0;
11240 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
11241 dsl_binding.descriptorCount = 1;
11242 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
11243 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060011244
11245 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011246 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
11247 ds_layout_ci.pNext = NULL;
11248 ds_layout_ci.bindingCount = 1;
11249 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060011250 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011251 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060011252 ASSERT_VK_SUCCESS(err);
11253
11254 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080011255 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +080011256 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -070011257 alloc_info.descriptorSetCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060011258 alloc_info.descriptorPool = ds_pool;
11259 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011260 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060011261 ASSERT_VK_SUCCESS(err);
11262
11263 VkSamplerCreateInfo sampler_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011264 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
11265 sampler_ci.pNext = NULL;
11266 sampler_ci.magFilter = VK_FILTER_NEAREST;
11267 sampler_ci.minFilter = VK_FILTER_NEAREST;
11268 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
11269 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
11270 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
11271 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
11272 sampler_ci.mipLodBias = 1.0;
11273 sampler_ci.anisotropyEnable = VK_FALSE;
11274 sampler_ci.maxAnisotropy = 1;
11275 sampler_ci.compareEnable = VK_FALSE;
11276 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
11277 sampler_ci.minLod = 1.0;
11278 sampler_ci.maxLod = 1.0;
11279 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
11280 sampler_ci.unnormalizedCoordinates = VK_FALSE;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060011281
11282 VkSampler sampler;
Chia-I Wuf7458c52015-10-26 21:10:41 +080011283 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060011284 ASSERT_VK_SUCCESS(err);
11285
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011286 VkImageView view = (VkImageView)((size_t)0xbaadbeef); // invalid imageView object
Tobin Ehlisa1c28562015-10-23 16:00:08 -060011287
11288 VkDescriptorImageInfo descriptor_info;
11289 memset(&descriptor_info, 0, sizeof(VkDescriptorImageInfo));
11290 descriptor_info.sampler = sampler;
11291 descriptor_info.imageView = view;
11292
11293 VkWriteDescriptorSet descriptor_write;
11294 memset(&descriptor_write, 0, sizeof(descriptor_write));
11295 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080011296 descriptor_write.dstSet = descriptorSet;
11297 descriptor_write.dstBinding = 0;
Chia-I Wud50a7d72015-10-26 20:48:51 +080011298 descriptor_write.descriptorCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060011299 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
11300 descriptor_write.pImageInfo = &descriptor_info;
11301
11302 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
11303
Chris Forbes8f36a8a2016-04-07 13:21:07 +120011304 m_errorMonitor->VerifyFound();
Tobin Ehlisa1c28562015-10-23 16:00:08 -060011305
Chia-I Wuf7458c52015-10-26 21:10:41 +080011306 vkDestroySampler(m_device->device(), sampler, NULL);
11307 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
11308 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060011309}
11310
Karl Schultz6addd812016-02-02 17:17:23 -070011311TEST_F(VkLayerTest, CopyDescriptorUpdateErrors) {
11312 // Create DS w/ layout of 2 types, write update 1 and attempt to copy-update
11313 // into the other
11314 VkResult err;
Tobin Ehlis04356f92015-10-27 16:35:27 -060011315
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011316 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " binding #1 with type "
11317 "VK_DESCRIPTOR_TYPE_SAMPLER. Types do "
11318 "not match.");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060011319
Tobin Ehlis04356f92015-10-27 16:35:27 -060011320 ASSERT_NO_FATAL_FAILURE(InitState());
Karl Schultz6addd812016-02-02 17:17:23 -070011321 // VkDescriptorSetObj descriptorSet(m_device);
Chia-I Wu1b99bb22015-10-27 19:25:11 +080011322 VkDescriptorPoolSize ds_type_count[2] = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011323 ds_type_count[0].type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
11324 ds_type_count[0].descriptorCount = 1;
11325 ds_type_count[1].type = VK_DESCRIPTOR_TYPE_SAMPLER;
11326 ds_type_count[1].descriptorCount = 1;
Tobin Ehlis04356f92015-10-27 16:35:27 -060011327
11328 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011329 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
11330 ds_pool_ci.pNext = NULL;
11331 ds_pool_ci.maxSets = 1;
11332 ds_pool_ci.poolSizeCount = 2;
11333 ds_pool_ci.pPoolSizes = ds_type_count;
Tobin Ehlis04356f92015-10-27 16:35:27 -060011334
11335 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011336 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis04356f92015-10-27 16:35:27 -060011337 ASSERT_VK_SUCCESS(err);
11338 VkDescriptorSetLayoutBinding dsl_binding[2] = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011339 dsl_binding[0].binding = 0;
11340 dsl_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
11341 dsl_binding[0].descriptorCount = 1;
11342 dsl_binding[0].stageFlags = VK_SHADER_STAGE_ALL;
11343 dsl_binding[0].pImmutableSamplers = NULL;
11344 dsl_binding[1].binding = 1;
11345 dsl_binding[1].descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
11346 dsl_binding[1].descriptorCount = 1;
11347 dsl_binding[1].stageFlags = VK_SHADER_STAGE_ALL;
11348 dsl_binding[1].pImmutableSamplers = NULL;
Tobin Ehlis04356f92015-10-27 16:35:27 -060011349
11350 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011351 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
11352 ds_layout_ci.pNext = NULL;
11353 ds_layout_ci.bindingCount = 2;
11354 ds_layout_ci.pBindings = dsl_binding;
Tobin Ehlis04356f92015-10-27 16:35:27 -060011355
11356 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011357 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis04356f92015-10-27 16:35:27 -060011358 ASSERT_VK_SUCCESS(err);
11359
11360 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080011361 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +080011362 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -070011363 alloc_info.descriptorSetCount = 1;
Tobin Ehlis04356f92015-10-27 16:35:27 -060011364 alloc_info.descriptorPool = ds_pool;
11365 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011366 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis04356f92015-10-27 16:35:27 -060011367 ASSERT_VK_SUCCESS(err);
11368
11369 VkSamplerCreateInfo sampler_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011370 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
11371 sampler_ci.pNext = NULL;
11372 sampler_ci.magFilter = VK_FILTER_NEAREST;
11373 sampler_ci.minFilter = VK_FILTER_NEAREST;
11374 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
11375 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
11376 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
11377 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
11378 sampler_ci.mipLodBias = 1.0;
11379 sampler_ci.anisotropyEnable = VK_FALSE;
11380 sampler_ci.maxAnisotropy = 1;
11381 sampler_ci.compareEnable = VK_FALSE;
11382 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
11383 sampler_ci.minLod = 1.0;
11384 sampler_ci.maxLod = 1.0;
11385 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
11386 sampler_ci.unnormalizedCoordinates = VK_FALSE;
Tobin Ehlis04356f92015-10-27 16:35:27 -060011387
11388 VkSampler sampler;
Chia-I Wuf7458c52015-10-26 21:10:41 +080011389 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
Tobin Ehlis04356f92015-10-27 16:35:27 -060011390 ASSERT_VK_SUCCESS(err);
11391
11392 VkDescriptorImageInfo info = {};
11393 info.sampler = sampler;
11394
11395 VkWriteDescriptorSet descriptor_write;
11396 memset(&descriptor_write, 0, sizeof(VkWriteDescriptorSet));
11397 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080011398 descriptor_write.dstSet = descriptorSet;
11399 descriptor_write.dstBinding = 1; // SAMPLER binding from layout above
Chia-I Wud50a7d72015-10-26 20:48:51 +080011400 descriptor_write.descriptorCount = 1;
Tobin Ehlis04356f92015-10-27 16:35:27 -060011401 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
11402 descriptor_write.pImageInfo = &info;
11403 // This write update should succeed
11404 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
11405 // Now perform a copy update that fails due to type mismatch
11406 VkCopyDescriptorSet copy_ds_update;
11407 memset(&copy_ds_update, 0, sizeof(VkCopyDescriptorSet));
11408 copy_ds_update.sType = VK_STRUCTURE_TYPE_COPY_DESCRIPTOR_SET;
11409 copy_ds_update.srcSet = descriptorSet;
Mark Young29927482016-05-04 14:38:51 -060011410 copy_ds_update.srcBinding = 1; // Copy from SAMPLER binding
Chia-I Wu3432a0c2015-10-27 18:04:07 +080011411 copy_ds_update.dstSet = descriptorSet;
Karl Schultz6addd812016-02-02 17:17:23 -070011412 copy_ds_update.dstBinding = 0; // ERROR : copy to UNIFORM binding
Chia-I Wud50a7d72015-10-26 20:48:51 +080011413 copy_ds_update.descriptorCount = 1; // copy 1 descriptor
Tobin Ehlis04356f92015-10-27 16:35:27 -060011414 vkUpdateDescriptorSets(m_device->device(), 0, NULL, 1, &copy_ds_update);
11415
Chris Forbes8f36a8a2016-04-07 13:21:07 +120011416 m_errorMonitor->VerifyFound();
Tobin Ehlis04356f92015-10-27 16:35:27 -060011417 // Now perform a copy update that fails due to binding out of bounds
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011418 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 -060011419 memset(&copy_ds_update, 0, sizeof(VkCopyDescriptorSet));
11420 copy_ds_update.sType = VK_STRUCTURE_TYPE_COPY_DESCRIPTOR_SET;
11421 copy_ds_update.srcSet = descriptorSet;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011422 copy_ds_update.srcBinding = 3; // ERROR : Invalid binding for matching layout
Chia-I Wu3432a0c2015-10-27 18:04:07 +080011423 copy_ds_update.dstSet = descriptorSet;
11424 copy_ds_update.dstBinding = 0;
Mark Young29927482016-05-04 14:38:51 -060011425 copy_ds_update.descriptorCount = 1; // Copy 1 descriptor
Tobin Ehlis04356f92015-10-27 16:35:27 -060011426 vkUpdateDescriptorSets(m_device->device(), 0, NULL, 1, &copy_ds_update);
11427
Chris Forbes8f36a8a2016-04-07 13:21:07 +120011428 m_errorMonitor->VerifyFound();
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060011429
Tobin Ehlis04356f92015-10-27 16:35:27 -060011430 // Now perform a copy update that fails due to binding out of bounds
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011431 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " binding#1 with offset index of 1 plus "
11432 "update array offset of 0 and update of "
11433 "5 descriptors oversteps total number "
11434 "of descriptors in set: 2.");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060011435
Tobin Ehlis04356f92015-10-27 16:35:27 -060011436 memset(&copy_ds_update, 0, sizeof(VkCopyDescriptorSet));
11437 copy_ds_update.sType = VK_STRUCTURE_TYPE_COPY_DESCRIPTOR_SET;
11438 copy_ds_update.srcSet = descriptorSet;
11439 copy_ds_update.srcBinding = 1;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080011440 copy_ds_update.dstSet = descriptorSet;
11441 copy_ds_update.dstBinding = 0;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011442 copy_ds_update.descriptorCount = 5; // ERROR copy 5 descriptors (out of bounds for layout)
Tobin Ehlis04356f92015-10-27 16:35:27 -060011443 vkUpdateDescriptorSets(m_device->device(), 0, NULL, 1, &copy_ds_update);
11444
Chris Forbes8f36a8a2016-04-07 13:21:07 +120011445 m_errorMonitor->VerifyFound();
Tobin Ehlis04356f92015-10-27 16:35:27 -060011446
Chia-I Wuf7458c52015-10-26 21:10:41 +080011447 vkDestroySampler(m_device->device(), sampler, NULL);
11448 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
11449 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis04356f92015-10-27 16:35:27 -060011450}
11451
Karl Schultz6addd812016-02-02 17:17:23 -070011452TEST_F(VkLayerTest, NumSamplesMismatch) {
11453 // Create CommandBuffer where MSAA samples doesn't match RenderPass
11454 // sampleCount
11455 VkResult err;
Tobin Ehlis3b780662015-05-28 12:11:26 -060011456
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011457 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Num samples mismatch! ");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060011458
Tobin Ehlis3b780662015-05-28 12:11:26 -060011459 ASSERT_NO_FATAL_FAILURE(InitState());
11460 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chia-I Wu1b99bb22015-10-27 19:25:11 +080011461 VkDescriptorPoolSize ds_type_count = {};
Tony Barboureb254902015-07-15 12:50:33 -060011462 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Chia-I Wud50a7d72015-10-26 20:48:51 +080011463 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -060011464
11465 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011466 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
11467 ds_pool_ci.pNext = NULL;
11468 ds_pool_ci.maxSets = 1;
11469 ds_pool_ci.poolSizeCount = 1;
11470 ds_pool_ci.pPoolSizes = &ds_type_count;
Courtney Goeltzenleuchterfe908d32015-09-16 16:12:45 -060011471
Tobin Ehlis3b780662015-05-28 12:11:26 -060011472 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011473 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis3b780662015-05-28 12:11:26 -060011474 ASSERT_VK_SUCCESS(err);
Tobin Ehlis3b780662015-05-28 12:11:26 -060011475
Tony Barboureb254902015-07-15 12:50:33 -060011476 VkDescriptorSetLayoutBinding dsl_binding = {};
Chia-I Wud46e6ae2015-10-31 00:31:16 +080011477 dsl_binding.binding = 0;
Tony Barboureb254902015-07-15 12:50:33 -060011478 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Chia-I Wu02124482015-11-06 06:42:02 +080011479 dsl_binding.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -060011480 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
11481 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis3b780662015-05-28 12:11:26 -060011482
Tony Barboureb254902015-07-15 12:50:33 -060011483 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
11484 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
11485 ds_layout_ci.pNext = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +080011486 ds_layout_ci.bindingCount = 1;
Jon Ashburn6e23c1f2015-12-30 18:01:16 -070011487 ds_layout_ci.pBindings = &dsl_binding;
Tony Barboureb254902015-07-15 12:50:33 -060011488
Tobin Ehlis3b780662015-05-28 12:11:26 -060011489 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011490 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis3b780662015-05-28 12:11:26 -060011491 ASSERT_VK_SUCCESS(err);
11492
11493 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080011494 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +080011495 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -070011496 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -060011497 alloc_info.descriptorPool = ds_pool;
11498 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011499 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis3b780662015-05-28 12:11:26 -060011500 ASSERT_VK_SUCCESS(err);
11501
Tony Barboureb254902015-07-15 12:50:33 -060011502 VkPipelineMultisampleStateCreateInfo pipe_ms_state_ci = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011503 pipe_ms_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
Karl Schultz6addd812016-02-02 17:17:23 -070011504 pipe_ms_state_ci.pNext = NULL;
11505 pipe_ms_state_ci.rasterizationSamples = VK_SAMPLE_COUNT_4_BIT;
11506 pipe_ms_state_ci.sampleShadingEnable = 0;
11507 pipe_ms_state_ci.minSampleShading = 1.0;
11508 pipe_ms_state_ci.pSampleMask = NULL;
Tobin Ehlis3b780662015-05-28 12:11:26 -060011509
Tony Barboureb254902015-07-15 12:50:33 -060011510 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011511 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
11512 pipeline_layout_ci.pNext = NULL;
11513 pipeline_layout_ci.setLayoutCount = 1;
11514 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlis3b780662015-05-28 12:11:26 -060011515
11516 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011517 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis3b780662015-05-28 12:11:26 -060011518 ASSERT_VK_SUCCESS(err);
11519
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011520 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
11521 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this); // We shouldn't need a fragment shader
11522 // but add it to be able to run on more devices
Tony Barbour62e1a5b2015-08-06 10:16:07 -060011523 VkPipelineObj pipe(m_device);
11524 pipe.AddShader(&vs);
Tony Barbour1c94d372015-08-06 11:21:08 -060011525 pipe.AddShader(&fs);
Mark Youngc89c6312016-03-31 16:03:20 -060011526 pipe.AddColorAttachment();
Tony Barbour62e1a5b2015-08-06 10:16:07 -060011527 pipe.SetMSAA(&pipe_ms_state_ci);
11528 pipe.CreateVKPipeline(pipeline_layout, renderPass());
Tobin Ehlis3b780662015-05-28 12:11:26 -060011529
Tony Barbourfe3351b2015-07-28 10:17:20 -060011530 BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011531 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Tobin Ehlis3b780662015-05-28 12:11:26 -060011532
Mark Young29927482016-05-04 14:38:51 -060011533 // Render triangle (the error should trigger on the attempt to draw).
11534 Draw(3, 1, 0, 0);
11535
11536 // Finalize recording of the command buffer
11537 EndCommandBuffer();
11538
Chris Forbes8f36a8a2016-04-07 13:21:07 +120011539 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -060011540
Chia-I Wuf7458c52015-10-26 21:10:41 +080011541 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
11542 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
11543 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis49eb23d2015-05-22 12:38:55 -060011544}
Mark Young29927482016-05-04 14:38:51 -060011545
Tobin Ehlis85aa15a2016-06-15 10:52:37 -060011546TEST_F(VkLayerTest, RenderPassIncompatible) {
11547 TEST_DESCRIPTION("Hit RenderPass incompatible cases. "
11548 "Initial case is drawing with an active renderpass that's "
11549 "not compatible with the bound PSO's creation renderpass");
11550 VkResult err;
11551
11552 ASSERT_NO_FATAL_FAILURE(InitState());
11553 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
11554
11555 VkDescriptorSetLayoutBinding dsl_binding = {};
11556 dsl_binding.binding = 0;
11557 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
11558 dsl_binding.descriptorCount = 1;
11559 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
11560 dsl_binding.pImmutableSamplers = NULL;
11561
11562 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
11563 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
11564 ds_layout_ci.pNext = NULL;
11565 ds_layout_ci.bindingCount = 1;
11566 ds_layout_ci.pBindings = &dsl_binding;
11567
11568 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011569 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis85aa15a2016-06-15 10:52:37 -060011570 ASSERT_VK_SUCCESS(err);
11571
11572 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
11573 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
11574 pipeline_layout_ci.pNext = NULL;
11575 pipeline_layout_ci.setLayoutCount = 1;
11576 pipeline_layout_ci.pSetLayouts = &ds_layout;
11577
11578 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011579 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis85aa15a2016-06-15 10:52:37 -060011580 ASSERT_VK_SUCCESS(err);
11581
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011582 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
11583 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this); // We shouldn't need a fragment shader
11584 // but add it to be able to run on more devices
Tobin Ehlis85aa15a2016-06-15 10:52:37 -060011585 // Create a renderpass that will be incompatible with default renderpass
11586 VkAttachmentReference attach = {};
11587 attach.layout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
11588 VkAttachmentReference color_att = {};
11589 color_att.layout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
11590 VkSubpassDescription subpass = {};
11591 subpass.inputAttachmentCount = 1;
11592 subpass.pInputAttachments = &attach;
11593 subpass.colorAttachmentCount = 1;
11594 subpass.pColorAttachments = &color_att;
11595 VkRenderPassCreateInfo rpci = {};
11596 rpci.subpassCount = 1;
11597 rpci.pSubpasses = &subpass;
11598 rpci.attachmentCount = 1;
11599 VkAttachmentDescription attach_desc = {};
11600 attach_desc.samples = VK_SAMPLE_COUNT_1_BIT;
Cody Northropbd16af12016-06-21 09:25:48 -060011601 // Format incompatible with PSO RP color attach format B8G8R8A8_UNORM
11602 attach_desc.format = VK_FORMAT_R8G8B8A8_UNORM;
Tobin Ehlis85aa15a2016-06-15 10:52:37 -060011603 rpci.pAttachments = &attach_desc;
11604 rpci.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
11605 VkRenderPass rp;
11606 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
11607 VkPipelineObj pipe(m_device);
11608 pipe.AddShader(&vs);
11609 pipe.AddShader(&fs);
11610 pipe.AddColorAttachment();
11611 VkViewport view_port = {};
11612 m_viewports.push_back(view_port);
11613 pipe.SetViewport(m_viewports);
11614 VkRect2D rect = {};
11615 m_scissors.push_back(rect);
11616 pipe.SetScissor(m_scissors);
11617 pipe.CreateVKPipeline(pipeline_layout, renderPass());
11618
11619 VkCommandBufferInheritanceInfo cbii = {};
11620 cbii.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_INHERITANCE_INFO;
11621 cbii.renderPass = rp;
11622 cbii.subpass = 0;
11623 VkCommandBufferBeginInfo cbbi = {};
11624 cbbi.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
11625 cbbi.pInheritanceInfo = &cbii;
11626 vkBeginCommandBuffer(m_commandBuffer->handle(), &cbbi);
11627 VkRenderPassBeginInfo rpbi = {};
11628 rpbi.sType = VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO;
11629 rpbi.framebuffer = m_framebuffer;
11630 rpbi.renderPass = rp;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011631 vkCmdBeginRenderPass(m_commandBuffer->GetBufferHandle(), &rpbi, VK_SUBPASS_CONTENTS_INLINE);
11632 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Tobin Ehlis85aa15a2016-06-15 10:52:37 -060011633
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011634 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " is incompatible w/ gfx pipeline ");
Tobin Ehlis85aa15a2016-06-15 10:52:37 -060011635 // Render triangle (the error should trigger on the attempt to draw).
11636 Draw(3, 1, 0, 0);
11637
11638 // Finalize recording of the command buffer
11639 EndCommandBuffer();
11640
11641 m_errorMonitor->VerifyFound();
11642
11643 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
11644 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
11645 vkDestroyRenderPass(m_device->device(), rp, NULL);
11646}
11647
Mark Youngc89c6312016-03-31 16:03:20 -060011648TEST_F(VkLayerTest, NumBlendAttachMismatch) {
11649 // Create Pipeline where the number of blend attachments doesn't match the
11650 // number of color attachments. In this case, we don't add any color
11651 // blend attachments even though we have a color attachment.
11652 VkResult err;
11653
11654 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011655 "Render pass subpass 0 mismatch with blending state defined and blend state attachment");
Mark Youngc89c6312016-03-31 16:03:20 -060011656
11657 ASSERT_NO_FATAL_FAILURE(InitState());
11658 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
11659 VkDescriptorPoolSize ds_type_count = {};
11660 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
11661 ds_type_count.descriptorCount = 1;
11662
11663 VkDescriptorPoolCreateInfo ds_pool_ci = {};
11664 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
11665 ds_pool_ci.pNext = NULL;
11666 ds_pool_ci.maxSets = 1;
11667 ds_pool_ci.poolSizeCount = 1;
11668 ds_pool_ci.pPoolSizes = &ds_type_count;
11669
11670 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011671 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Mark Youngc89c6312016-03-31 16:03:20 -060011672 ASSERT_VK_SUCCESS(err);
11673
11674 VkDescriptorSetLayoutBinding dsl_binding = {};
11675 dsl_binding.binding = 0;
11676 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
11677 dsl_binding.descriptorCount = 1;
11678 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
11679 dsl_binding.pImmutableSamplers = NULL;
11680
11681 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
11682 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
11683 ds_layout_ci.pNext = NULL;
11684 ds_layout_ci.bindingCount = 1;
11685 ds_layout_ci.pBindings = &dsl_binding;
11686
11687 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011688 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Mark Youngc89c6312016-03-31 16:03:20 -060011689 ASSERT_VK_SUCCESS(err);
11690
11691 VkDescriptorSet descriptorSet;
11692 VkDescriptorSetAllocateInfo alloc_info = {};
11693 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
11694 alloc_info.descriptorSetCount = 1;
11695 alloc_info.descriptorPool = ds_pool;
11696 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011697 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Mark Youngc89c6312016-03-31 16:03:20 -060011698 ASSERT_VK_SUCCESS(err);
11699
11700 VkPipelineMultisampleStateCreateInfo pipe_ms_state_ci = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011701 pipe_ms_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
Mark Youngc89c6312016-03-31 16:03:20 -060011702 pipe_ms_state_ci.pNext = NULL;
11703 pipe_ms_state_ci.rasterizationSamples = VK_SAMPLE_COUNT_1_BIT;
11704 pipe_ms_state_ci.sampleShadingEnable = 0;
11705 pipe_ms_state_ci.minSampleShading = 1.0;
11706 pipe_ms_state_ci.pSampleMask = NULL;
11707
11708 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
11709 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
11710 pipeline_layout_ci.pNext = NULL;
11711 pipeline_layout_ci.setLayoutCount = 1;
11712 pipeline_layout_ci.pSetLayouts = &ds_layout;
11713
11714 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011715 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Mark Youngc89c6312016-03-31 16:03:20 -060011716 ASSERT_VK_SUCCESS(err);
11717
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011718 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
11719 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this); // We shouldn't need a fragment shader
11720 // but add it to be able to run on more devices
Mark Youngc89c6312016-03-31 16:03:20 -060011721 VkPipelineObj pipe(m_device);
11722 pipe.AddShader(&vs);
11723 pipe.AddShader(&fs);
11724 pipe.SetMSAA(&pipe_ms_state_ci);
11725 pipe.CreateVKPipeline(pipeline_layout, renderPass());
11726
11727 BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011728 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Mark Youngc89c6312016-03-31 16:03:20 -060011729
Mark Young29927482016-05-04 14:38:51 -060011730 // Render triangle (the error should trigger on the attempt to draw).
11731 Draw(3, 1, 0, 0);
11732
11733 // Finalize recording of the command buffer
11734 EndCommandBuffer();
11735
Chris Forbes8f36a8a2016-04-07 13:21:07 +120011736 m_errorMonitor->VerifyFound();
Mark Youngc89c6312016-03-31 16:03:20 -060011737
11738 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
11739 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
11740 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
11741}
Mark Young29927482016-05-04 14:38:51 -060011742
Mark Muellerd4914412016-06-13 17:52:06 -060011743TEST_F(VkLayerTest, MissingClearAttachment) {
11744 TEST_DESCRIPTION("Points to a wrong colorAttachment index in a VkClearAttachment "
11745 "structure passed to vkCmdClearAttachments");
Cody Northropc31a84f2016-08-22 10:41:47 -060011746 ASSERT_NO_FATAL_FAILURE(InitState());
Chris Forbesda6ae6f2016-09-09 14:36:33 +120011747 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Chris Forbesef5e2842016-09-08 15:25:24 +120011748 "vkCmdClearAttachments() color attachment index 1 out of range for active subpass 0; ignored");
Mark Muellerd4914412016-06-13 17:52:06 -060011749
11750 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailCmdClearAttachments);
11751 m_errorMonitor->VerifyFound();
11752}
11753
Karl Schultz6addd812016-02-02 17:17:23 -070011754TEST_F(VkLayerTest, ClearCmdNoDraw) {
11755 // Create CommandBuffer where we add ClearCmd for FB Color attachment prior
11756 // to issuing a Draw
11757 VkResult err;
Tobin Ehlis53eddda2015-07-01 16:46:13 -060011758
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011759 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
11760 "vkCmdClearAttachments() issued on CB object ");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060011761
Tobin Ehlis53eddda2015-07-01 16:46:13 -060011762 ASSERT_NO_FATAL_FAILURE(InitState());
11763 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barboureb254902015-07-15 12:50:33 -060011764
Chia-I Wu1b99bb22015-10-27 19:25:11 +080011765 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011766 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
11767 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -060011768
11769 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011770 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
11771 ds_pool_ci.pNext = NULL;
11772 ds_pool_ci.maxSets = 1;
11773 ds_pool_ci.poolSizeCount = 1;
11774 ds_pool_ci.pPoolSizes = &ds_type_count;
Tony Barboureb254902015-07-15 12:50:33 -060011775
Tobin Ehlis53eddda2015-07-01 16:46:13 -060011776 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011777 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis53eddda2015-07-01 16:46:13 -060011778 ASSERT_VK_SUCCESS(err);
11779
Tony Barboureb254902015-07-15 12:50:33 -060011780 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011781 dsl_binding.binding = 0;
11782 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
11783 dsl_binding.descriptorCount = 1;
11784 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
11785 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis53eddda2015-07-01 16:46:13 -060011786
Tony Barboureb254902015-07-15 12:50:33 -060011787 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011788 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
11789 ds_layout_ci.pNext = NULL;
11790 ds_layout_ci.bindingCount = 1;
11791 ds_layout_ci.pBindings = &dsl_binding;
Mark Lobodzinski209b5292015-09-17 09:44:05 -060011792
Tobin Ehlis53eddda2015-07-01 16:46:13 -060011793 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011794 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis53eddda2015-07-01 16:46:13 -060011795 ASSERT_VK_SUCCESS(err);
11796
11797 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080011798 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +080011799 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -070011800 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -060011801 alloc_info.descriptorPool = ds_pool;
11802 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011803 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis53eddda2015-07-01 16:46:13 -060011804 ASSERT_VK_SUCCESS(err);
11805
Tony Barboureb254902015-07-15 12:50:33 -060011806 VkPipelineMultisampleStateCreateInfo pipe_ms_state_ci = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011807 pipe_ms_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
Karl Schultz6addd812016-02-02 17:17:23 -070011808 pipe_ms_state_ci.pNext = NULL;
11809 pipe_ms_state_ci.rasterizationSamples = VK_SAMPLE_COUNT_4_BIT;
11810 pipe_ms_state_ci.sampleShadingEnable = 0;
11811 pipe_ms_state_ci.minSampleShading = 1.0;
11812 pipe_ms_state_ci.pSampleMask = NULL;
Tobin Ehlis53eddda2015-07-01 16:46:13 -060011813
Tony Barboureb254902015-07-15 12:50:33 -060011814 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011815 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
11816 pipeline_layout_ci.pNext = NULL;
11817 pipeline_layout_ci.setLayoutCount = 1;
11818 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlis53eddda2015-07-01 16:46:13 -060011819
11820 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011821 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis53eddda2015-07-01 16:46:13 -060011822 ASSERT_VK_SUCCESS(err);
Mark Lobodzinski209b5292015-09-17 09:44:05 -060011823
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011824 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
Karl Schultzbdb75952016-04-19 11:36:49 -060011825 // We shouldn't need a fragment shader but add it to be able to run
Karl Schultz6addd812016-02-02 17:17:23 -070011826 // on more devices
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011827 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060011828
Tony Barbour62e1a5b2015-08-06 10:16:07 -060011829 VkPipelineObj pipe(m_device);
11830 pipe.AddShader(&vs);
Tony Barbour1c94d372015-08-06 11:21:08 -060011831 pipe.AddShader(&fs);
Tony Barbour62e1a5b2015-08-06 10:16:07 -060011832 pipe.SetMSAA(&pipe_ms_state_ci);
11833 pipe.CreateVKPipeline(pipeline_layout, renderPass());
Tony Barbourfe3351b2015-07-28 10:17:20 -060011834
11835 BeginCommandBuffer();
Tobin Ehlis53eddda2015-07-01 16:46:13 -060011836
Karl Schultz6addd812016-02-02 17:17:23 -070011837 // Main thing we care about for this test is that the VkImage obj we're
11838 // clearing matches Color Attachment of FB
Tobin Ehlis53eddda2015-07-01 16:46:13 -060011839 // Also pass down other dummy params to keep driver and paramchecker happy
Courtney Goeltzenleuchterc9323e02015-10-15 16:51:05 -060011840 VkClearAttachment color_attachment;
11841 color_attachment.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
11842 color_attachment.clearValue.color.float32[0] = 1.0;
11843 color_attachment.clearValue.color.float32[1] = 1.0;
11844 color_attachment.clearValue.color.float32[2] = 1.0;
11845 color_attachment.clearValue.color.float32[3] = 1.0;
11846 color_attachment.colorAttachment = 0;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011847 VkClearRect clear_rect = {{{0, 0}, {(uint32_t)m_width, (uint32_t)m_height}}};
Tobin Ehlis53eddda2015-07-01 16:46:13 -060011848
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011849 vkCmdClearAttachments(m_commandBuffer->GetBufferHandle(), 1, &color_attachment, 1, &clear_rect);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060011850
Chris Forbes8f36a8a2016-04-07 13:21:07 +120011851 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -060011852
Chia-I Wuf7458c52015-10-26 21:10:41 +080011853 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
11854 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
11855 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis53eddda2015-07-01 16:46:13 -060011856}
11857
Karl Schultz6addd812016-02-02 17:17:23 -070011858TEST_F(VkLayerTest, VtxBufferBadIndex) {
11859 VkResult err;
Tobin Ehlis502480b2015-06-24 15:53:07 -060011860
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011861 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
11862 "but no vertex buffers are attached to this Pipeline State Object");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060011863
Tobin Ehlis502480b2015-06-24 15:53:07 -060011864 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisd332f282015-10-02 11:00:56 -060011865 ASSERT_NO_FATAL_FAILURE(InitViewport());
Tobin Ehlis502480b2015-06-24 15:53:07 -060011866 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barboureb254902015-07-15 12:50:33 -060011867
Chia-I Wu1b99bb22015-10-27 19:25:11 +080011868 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011869 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
11870 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -060011871
11872 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011873 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
11874 ds_pool_ci.pNext = NULL;
11875 ds_pool_ci.maxSets = 1;
11876 ds_pool_ci.poolSizeCount = 1;
11877 ds_pool_ci.pPoolSizes = &ds_type_count;
Tony Barboureb254902015-07-15 12:50:33 -060011878
Courtney Goeltzenleuchterfe908d32015-09-16 16:12:45 -060011879 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011880 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis502480b2015-06-24 15:53:07 -060011881 ASSERT_VK_SUCCESS(err);
11882
Tony Barboureb254902015-07-15 12:50:33 -060011883 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011884 dsl_binding.binding = 0;
11885 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
11886 dsl_binding.descriptorCount = 1;
11887 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
11888 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis502480b2015-06-24 15:53:07 -060011889
Tony Barboureb254902015-07-15 12:50:33 -060011890 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011891 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
11892 ds_layout_ci.pNext = NULL;
11893 ds_layout_ci.bindingCount = 1;
11894 ds_layout_ci.pBindings = &dsl_binding;
Tony Barboureb254902015-07-15 12:50:33 -060011895
Tobin Ehlis502480b2015-06-24 15:53:07 -060011896 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011897 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis502480b2015-06-24 15:53:07 -060011898 ASSERT_VK_SUCCESS(err);
11899
11900 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080011901 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +080011902 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -070011903 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -060011904 alloc_info.descriptorPool = ds_pool;
11905 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011906 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis502480b2015-06-24 15:53:07 -060011907 ASSERT_VK_SUCCESS(err);
11908
Tony Barboureb254902015-07-15 12:50:33 -060011909 VkPipelineMultisampleStateCreateInfo pipe_ms_state_ci = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011910 pipe_ms_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
Karl Schultz6addd812016-02-02 17:17:23 -070011911 pipe_ms_state_ci.pNext = NULL;
11912 pipe_ms_state_ci.rasterizationSamples = VK_SAMPLE_COUNT_1_BIT;
11913 pipe_ms_state_ci.sampleShadingEnable = 0;
11914 pipe_ms_state_ci.minSampleShading = 1.0;
11915 pipe_ms_state_ci.pSampleMask = NULL;
Tobin Ehlis502480b2015-06-24 15:53:07 -060011916
Tony Barboureb254902015-07-15 12:50:33 -060011917 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011918 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
11919 pipeline_layout_ci.pNext = NULL;
11920 pipeline_layout_ci.setLayoutCount = 1;
11921 pipeline_layout_ci.pSetLayouts = &ds_layout;
11922 VkPipelineLayout pipeline_layout;
Tobin Ehlis502480b2015-06-24 15:53:07 -060011923
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011924 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis502480b2015-06-24 15:53:07 -060011925 ASSERT_VK_SUCCESS(err);
11926
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011927 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
11928 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this); // We shouldn't need a fragment shader
11929 // but add it to be able to run on more devices
Tony Barbour62e1a5b2015-08-06 10:16:07 -060011930 VkPipelineObj pipe(m_device);
11931 pipe.AddShader(&vs);
Tony Barbour1c94d372015-08-06 11:21:08 -060011932 pipe.AddShader(&fs);
Mark Youngc89c6312016-03-31 16:03:20 -060011933 pipe.AddColorAttachment();
Tony Barbour62e1a5b2015-08-06 10:16:07 -060011934 pipe.SetMSAA(&pipe_ms_state_ci);
Tobin Ehlisd332f282015-10-02 11:00:56 -060011935 pipe.SetViewport(m_viewports);
11936 pipe.SetScissor(m_scissors);
Tony Barbour62e1a5b2015-08-06 10:16:07 -060011937 pipe.CreateVKPipeline(pipeline_layout, renderPass());
Tony Barbourfe3351b2015-07-28 10:17:20 -060011938
11939 BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011940 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Tobin Ehlisf7bf4502015-09-09 15:12:35 -060011941 // Don't care about actual data, just need to get to draw to flag error
11942 static const float vbo_data[3] = {1.f, 0.f, 1.f};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011943 VkConstantBufferObj vbo(m_device, sizeof(vbo_data), sizeof(float), (const void *)&vbo_data);
Tobin Ehlisf7bf4502015-09-09 15:12:35 -060011944 BindVertexBuffer(&vbo, (VkDeviceSize)0, 1); // VBO idx 1, but no VBO in PSO
Courtney Goeltzenleuchter08c26372015-09-23 12:31:50 -060011945 Draw(1, 0, 0, 0);
Tobin Ehlis502480b2015-06-24 15:53:07 -060011946
Chris Forbes8f36a8a2016-04-07 13:21:07 +120011947 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -060011948
Chia-I Wuf7458c52015-10-26 21:10:41 +080011949 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
11950 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
11951 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis502480b2015-06-24 15:53:07 -060011952}
Mark Muellerdfe37552016-07-07 14:47:42 -060011953
Mark Mueller2ee294f2016-08-04 12:59:48 -060011954TEST_F(VkLayerTest, MismatchCountQueueCreateRequestedFeature) {
11955 TEST_DESCRIPTION("Use an invalid count in a vkEnumeratePhysicalDevices call."
11956 "Use invalid Queue Family Index in vkCreateDevice");
Cody Northropc31a84f2016-08-22 10:41:47 -060011957 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Mueller2ee294f2016-08-04 12:59:48 -060011958
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011959 const char *mismatch_count_message = "Call to vkEnumeratePhysicalDevices() "
11960 "w/ pPhysicalDeviceCount value ";
Mark Mueller2ee294f2016-08-04 12:59:48 -060011961
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011962 const char *invalid_queueFamilyIndex_message = "Invalid queue create request in vkCreateDevice(). Invalid "
11963 "queueFamilyIndex ";
Mark Mueller2ee294f2016-08-04 12:59:48 -060011964
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011965 const char *unavailable_feature_message = "While calling vkCreateDevice(), requesting feature #";
Mark Mueller2ee294f2016-08-04 12:59:48 -060011966
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011967 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT, mismatch_count_message);
Mark Mueller880fce52016-08-17 15:23:23 -060011968 // The following test fails with recent NVidia drivers.
11969 // By the time core_validation is reached, the NVidia
11970 // driver has sanitized the invalid condition and core_validation
11971 // is not introduced to the failure condition. This is not the case
11972 // with AMD and Mesa drivers. Futher investigation is required
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011973 // uint32_t count = static_cast<uint32_t>(~0);
11974 // VkPhysicalDevice physical_device;
11975 // vkEnumeratePhysicalDevices(instance(), &count, &physical_device);
11976 // m_errorMonitor->VerifyFound();
Mark Mueller2ee294f2016-08-04 12:59:48 -060011977
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011978 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, invalid_queueFamilyIndex_message);
Mark Mueller2ee294f2016-08-04 12:59:48 -060011979 float queue_priority = 0.0;
11980
11981 VkDeviceQueueCreateInfo queue_create_info = {};
11982 queue_create_info.sType = VK_STRUCTURE_TYPE_DEVICE_QUEUE_CREATE_INFO;
11983 queue_create_info.queueCount = 1;
11984 queue_create_info.pQueuePriorities = &queue_priority;
11985 queue_create_info.queueFamilyIndex = static_cast<uint32_t>(~0);
11986
11987 VkPhysicalDeviceFeatures features = m_device->phy().features();
11988 VkDevice testDevice;
11989 VkDeviceCreateInfo device_create_info = {};
11990 device_create_info.sType = VK_STRUCTURE_TYPE_DEVICE_CREATE_INFO;
11991 device_create_info.queueCreateInfoCount = 1;
11992 device_create_info.pQueueCreateInfos = &queue_create_info;
11993 device_create_info.pEnabledFeatures = &features;
11994 vkCreateDevice(gpu(), &device_create_info, nullptr, &testDevice);
11995 m_errorMonitor->VerifyFound();
11996
11997 queue_create_info.queueFamilyIndex = 1;
11998
11999 unsigned feature_count = sizeof(VkPhysicalDeviceFeatures) / sizeof(VkBool32);
12000 VkBool32 *feature_array = reinterpret_cast<VkBool32 *>(&features);
12001 for (unsigned i = 0; i < feature_count; i++) {
12002 if (VK_FALSE == feature_array[i]) {
12003 feature_array[i] = VK_TRUE;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012004 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, unavailable_feature_message);
Mark Mueller2ee294f2016-08-04 12:59:48 -060012005 device_create_info.pEnabledFeatures = &features;
12006 vkCreateDevice(gpu(), &device_create_info, nullptr, &testDevice);
12007 m_errorMonitor->VerifyFound();
12008 break;
12009 }
12010 }
12011}
12012
12013TEST_F(VkLayerTest, InvalidQueueIndexInvalidQuery) {
12014 TEST_DESCRIPTION("Use an invalid queue index in a vkCmdWaitEvents call."
12015 "End a command buffer with a query still in progress.");
12016
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012017 const char *invalid_queue_index = "was created with sharingMode of VK_SHARING_MODE_EXCLUSIVE. If one "
12018 "of src- or dstQueueFamilyIndex is VK_QUEUE_FAMILY_IGNORED, both "
12019 "must be.";
Mark Mueller2ee294f2016-08-04 12:59:48 -060012020
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012021 const char *invalid_query = "Ending command buffer with in progress query: queryPool 0x";
Mark Mueller2ee294f2016-08-04 12:59:48 -060012022
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012023 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, invalid_queue_index);
Mark Mueller2ee294f2016-08-04 12:59:48 -060012024
12025 ASSERT_NO_FATAL_FAILURE(InitState());
12026
12027 VkEvent event;
12028 VkEventCreateInfo event_create_info{};
12029 event_create_info.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO;
12030 vkCreateEvent(m_device->device(), &event_create_info, nullptr, &event);
12031
Mark Mueller2ee294f2016-08-04 12:59:48 -060012032 VkQueue queue = VK_NULL_HANDLE;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012033 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 0, &queue);
Mark Mueller2ee294f2016-08-04 12:59:48 -060012034
12035 BeginCommandBuffer();
12036
12037 VkImageObj image(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012038 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 -060012039 ASSERT_TRUE(image.initialized());
12040 VkImageMemoryBarrier img_barrier = {};
12041 img_barrier.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
12042 img_barrier.pNext = NULL;
12043 img_barrier.srcAccessMask = VK_ACCESS_HOST_WRITE_BIT;
12044 img_barrier.dstAccessMask = VK_ACCESS_SHADER_READ_BIT;
12045 img_barrier.oldLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
12046 img_barrier.newLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
12047 img_barrier.image = image.handle();
12048 img_barrier.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
Mark Lobodzinski2a74c5c2016-08-17 13:26:28 -060012049
12050 // QueueFamilyIndex must be VK_QUEUE_FAMILY_IGNORED, this verifies
12051 // that layer validation catches the case when it is not.
12052 img_barrier.dstQueueFamilyIndex = 0;
Mark Mueller2ee294f2016-08-04 12:59:48 -060012053 img_barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
12054 img_barrier.subresourceRange.baseArrayLayer = 0;
12055 img_barrier.subresourceRange.baseMipLevel = 0;
12056 img_barrier.subresourceRange.layerCount = 1;
12057 img_barrier.subresourceRange.levelCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012058 vkCmdWaitEvents(m_commandBuffer->handle(), 1, &event, VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0,
12059 nullptr, 0, nullptr, 1, &img_barrier);
Mark Mueller2ee294f2016-08-04 12:59:48 -060012060 m_errorMonitor->VerifyFound();
12061
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012062 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, invalid_query);
Mark Mueller2ee294f2016-08-04 12:59:48 -060012063
12064 VkQueryPool query_pool;
12065 VkQueryPoolCreateInfo query_pool_create_info = {};
12066 query_pool_create_info.sType = VK_STRUCTURE_TYPE_QUERY_POOL_CREATE_INFO;
12067 query_pool_create_info.queryType = VK_QUERY_TYPE_OCCLUSION;
12068 query_pool_create_info.queryCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012069 vkCreateQueryPool(m_device->device(), &query_pool_create_info, nullptr, &query_pool);
Mark Mueller2ee294f2016-08-04 12:59:48 -060012070
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012071 vkCmdResetQueryPool(m_commandBuffer->handle(), query_pool, 0 /*startQuery*/, 1 /*queryCount*/);
Mark Mueller2ee294f2016-08-04 12:59:48 -060012072 vkCmdBeginQuery(m_commandBuffer->handle(), query_pool, 0, 0);
12073
12074 vkEndCommandBuffer(m_commandBuffer->handle());
12075 m_errorMonitor->VerifyFound();
12076
12077 vkDestroyQueryPool(m_device->device(), query_pool, nullptr);
12078 vkDestroyEvent(m_device->device(), event, nullptr);
12079}
12080
Mark Muellerdfe37552016-07-07 14:47:42 -060012081TEST_F(VkLayerTest, VertexBufferInvalid) {
12082 TEST_DESCRIPTION("Submit a command buffer using deleted vertex buffer, "
12083 "delete a buffer twice, use an invalid offset for each "
12084 "buffer type, and attempt to bind a null buffer");
12085
12086 const char *deleted_buffer_in_command_buffer = "Cannot submit cmd buffer "
12087 "using deleted buffer ";
12088 const char *double_destroy_message = "Cannot free buffer 0x";
12089 const char *invalid_offset_message = "vkBindBufferMemory(): "
12090 "memoryOffset is 0x";
12091 const char *invalid_storage_buffer_offset_message = "vkBindBufferMemory(): "
12092 "storage memoryOffset "
12093 "is 0x";
12094 const char *invalid_texel_buffer_offset_message = "vkBindBufferMemory(): "
12095 "texel memoryOffset "
12096 "is 0x";
12097 const char *invalid_uniform_buffer_offset_message = "vkBindBufferMemory(): "
12098 "uniform memoryOffset "
12099 "is 0x";
12100 const char *bind_null_buffer_message = "In vkBindBufferMemory, attempting"
12101 " to Bind Obj(0x";
12102 const char *free_invalid_buffer_message = "Request to delete memory "
12103 "object 0x";
12104
12105 ASSERT_NO_FATAL_FAILURE(InitState());
12106 ASSERT_NO_FATAL_FAILURE(InitViewport());
12107 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12108
12109 VkPipelineMultisampleStateCreateInfo pipe_ms_state_ci = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012110 pipe_ms_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
Mark Muellerdfe37552016-07-07 14:47:42 -060012111 pipe_ms_state_ci.pNext = NULL;
12112 pipe_ms_state_ci.rasterizationSamples = VK_SAMPLE_COUNT_1_BIT;
12113 pipe_ms_state_ci.sampleShadingEnable = 0;
12114 pipe_ms_state_ci.minSampleShading = 1.0;
12115 pipe_ms_state_ci.pSampleMask = nullptr;
12116
12117 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
12118 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
12119 VkPipelineLayout pipeline_layout;
12120
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012121 VkResult err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, nullptr, &pipeline_layout);
Mark Muellerdfe37552016-07-07 14:47:42 -060012122 ASSERT_VK_SUCCESS(err);
12123
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012124 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
12125 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Mark Muellerdfe37552016-07-07 14:47:42 -060012126 VkPipelineObj pipe(m_device);
12127 pipe.AddShader(&vs);
12128 pipe.AddShader(&fs);
12129 pipe.AddColorAttachment();
12130 pipe.SetMSAA(&pipe_ms_state_ci);
12131 pipe.SetViewport(m_viewports);
12132 pipe.SetScissor(m_scissors);
12133 pipe.CreateVKPipeline(pipeline_layout, renderPass());
12134
12135 BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012136 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Mark Muellerdfe37552016-07-07 14:47:42 -060012137
12138 {
12139 // Create and bind a vertex buffer in a reduced scope, which will cause
12140 // it to be deleted upon leaving this scope
12141 const float vbo_data[3] = {1.f, 0.f, 1.f};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012142 VkVerticesObj draw_verticies(m_device, 1, 1, sizeof(vbo_data), 3, vbo_data);
Mark Muellerdfe37552016-07-07 14:47:42 -060012143 draw_verticies.BindVertexBuffers(m_commandBuffer->handle());
12144 draw_verticies.AddVertexInputToPipe(pipe);
12145 }
12146
12147 Draw(1, 0, 0, 0);
12148
12149 EndCommandBuffer();
12150
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012151 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, deleted_buffer_in_command_buffer);
Mark Muellerdfe37552016-07-07 14:47:42 -060012152 QueueCommandBuffer(false);
12153 m_errorMonitor->VerifyFound();
12154
12155 {
12156 // Create and bind a vertex buffer in a reduced scope, and delete it
12157 // twice, the second through the destructor
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012158 VkBufferTest buffer_test(m_device, VK_BUFFER_USAGE_STORAGE_BUFFER_BIT, VkBufferTest::eDoubleDelete);
12159 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, double_destroy_message);
Mark Muellerdfe37552016-07-07 14:47:42 -060012160 buffer_test.TestDoubleDestroy();
12161 }
12162 m_errorMonitor->VerifyFound();
12163
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012164 if (VkBufferTest::GetTestConditionValid(m_device, VkBufferTest::eInvalidMemoryOffset)) {
Mark Muellerdfe37552016-07-07 14:47:42 -060012165 // Create and bind a memory buffer with an invalid offset.
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012166 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, invalid_offset_message);
12167 VkBufferTest buffer_test(m_device, VK_BUFFER_USAGE_UNIFORM_TEXEL_BUFFER_BIT, VkBufferTest::eInvalidMemoryOffset);
12168 (void)buffer_test;
Mark Muellerdfe37552016-07-07 14:47:42 -060012169 m_errorMonitor->VerifyFound();
12170 }
12171
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012172 if (VkBufferTest::GetTestConditionValid(m_device, VkBufferTest::eInvalidDeviceOffset,
12173 VK_BUFFER_USAGE_UNIFORM_TEXEL_BUFFER_BIT)) {
Mark Muellerdfe37552016-07-07 14:47:42 -060012174 // Create and bind a memory buffer with an invalid offset again,
12175 // but look for a texel buffer message.
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012176 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, invalid_texel_buffer_offset_message);
12177 VkBufferTest buffer_test(m_device, VK_BUFFER_USAGE_UNIFORM_TEXEL_BUFFER_BIT, VkBufferTest::eInvalidDeviceOffset);
12178 (void)buffer_test;
Mark Muellerdfe37552016-07-07 14:47:42 -060012179 m_errorMonitor->VerifyFound();
12180 }
12181
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012182 if (VkBufferTest::GetTestConditionValid(m_device, VkBufferTest::eInvalidDeviceOffset, VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT)) {
Mark Muellerdfe37552016-07-07 14:47:42 -060012183 // Create and bind a memory buffer with an invalid offset again, but
12184 // look for a uniform buffer message.
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012185 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, invalid_uniform_buffer_offset_message);
12186 VkBufferTest buffer_test(m_device, VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT, VkBufferTest::eInvalidDeviceOffset);
12187 (void)buffer_test;
Mark Muellerdfe37552016-07-07 14:47:42 -060012188 m_errorMonitor->VerifyFound();
12189 }
12190
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012191 if (VkBufferTest::GetTestConditionValid(m_device, VkBufferTest::eInvalidDeviceOffset, VK_BUFFER_USAGE_STORAGE_BUFFER_BIT)) {
Mark Muellerdfe37552016-07-07 14:47:42 -060012192 // Create and bind a memory buffer with an invalid offset again, but
12193 // look for a storage buffer message.
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012194 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, invalid_storage_buffer_offset_message);
12195 VkBufferTest buffer_test(m_device, VK_BUFFER_USAGE_STORAGE_BUFFER_BIT, VkBufferTest::eInvalidDeviceOffset);
12196 (void)buffer_test;
Mark Muellerdfe37552016-07-07 14:47:42 -060012197 m_errorMonitor->VerifyFound();
12198 }
12199
12200 {
12201 // Attempt to bind a null buffer.
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012202 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, bind_null_buffer_message);
12203 VkBufferTest buffer_test(m_device, VK_BUFFER_USAGE_STORAGE_BUFFER_BIT, VkBufferTest::eBindNullBuffer);
12204 (void)buffer_test;
Mark Muellerdfe37552016-07-07 14:47:42 -060012205 m_errorMonitor->VerifyFound();
12206 }
12207
12208 {
12209 // Attempt to use an invalid handle to delete a buffer.
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012210 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, free_invalid_buffer_message);
12211 VkBufferTest buffer_test(m_device, VK_BUFFER_USAGE_STORAGE_BUFFER_BIT, VkBufferTest::eFreeInvalidHandle);
12212 (void)buffer_test;
Mark Muellerdfe37552016-07-07 14:47:42 -060012213 }
12214 m_errorMonitor->VerifyFound();
12215
12216 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
12217}
12218
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060012219// INVALID_IMAGE_LAYOUT tests (one other case is hit by MapMemWithoutHostVisibleBit and not here)
12220TEST_F(VkLayerTest, InvalidImageLayout) {
12221 TEST_DESCRIPTION("Hit all possible validation checks associated with the "
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012222 "DRAWSTATE_INVALID_IMAGE_LAYOUT enum. Generally these involve having"
12223 "images in the wrong layout when they're copied or transitioned.");
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060012224 // 3 in ValidateCmdBufImageLayouts
12225 // * -1 Attempt to submit cmd buf w/ deleted image
12226 // * -2 Cmd buf submit of image w/ layout not matching first use w/ subresource
12227 // * -3 Cmd buf submit of image w/ layout not matching first use w/o subresource
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012228 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
12229 "Layout for input image should be TRANSFER_SRC_OPTIMAL instead of GENERAL.");
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060012230
12231 ASSERT_NO_FATAL_FAILURE(InitState());
12232 // Create src & dst images to use for copy operations
12233 VkImage src_image;
12234 VkImage dst_image;
12235
12236 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
12237 const int32_t tex_width = 32;
12238 const int32_t tex_height = 32;
12239
12240 VkImageCreateInfo image_create_info = {};
12241 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
12242 image_create_info.pNext = NULL;
12243 image_create_info.imageType = VK_IMAGE_TYPE_2D;
12244 image_create_info.format = tex_format;
12245 image_create_info.extent.width = tex_width;
12246 image_create_info.extent.height = tex_height;
12247 image_create_info.extent.depth = 1;
12248 image_create_info.mipLevels = 1;
12249 image_create_info.arrayLayers = 4;
12250 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
12251 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
12252 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
12253 image_create_info.flags = 0;
12254
12255 VkResult err = vkCreateImage(m_device->device(), &image_create_info, NULL, &src_image);
12256 ASSERT_VK_SUCCESS(err);
12257 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &dst_image);
12258 ASSERT_VK_SUCCESS(err);
12259
12260 BeginCommandBuffer();
12261 VkImageCopy copyRegion;
12262 copyRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
12263 copyRegion.srcSubresource.mipLevel = 0;
12264 copyRegion.srcSubresource.baseArrayLayer = 0;
12265 copyRegion.srcSubresource.layerCount = 1;
12266 copyRegion.srcOffset.x = 0;
12267 copyRegion.srcOffset.y = 0;
12268 copyRegion.srcOffset.z = 0;
12269 copyRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
12270 copyRegion.dstSubresource.mipLevel = 0;
12271 copyRegion.dstSubresource.baseArrayLayer = 0;
12272 copyRegion.dstSubresource.layerCount = 1;
12273 copyRegion.dstOffset.x = 0;
12274 copyRegion.dstOffset.y = 0;
12275 copyRegion.dstOffset.z = 0;
12276 copyRegion.extent.width = 1;
12277 copyRegion.extent.height = 1;
12278 copyRegion.extent.depth = 1;
12279 m_commandBuffer->CopyImage(src_image, VK_IMAGE_LAYOUT_GENERAL, dst_image, VK_IMAGE_LAYOUT_GENERAL, 1, &copyRegion);
12280 m_errorMonitor->VerifyFound();
12281 // Now cause error due to src image layout changing
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012282 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Cannot copy from an image whose source layout is "
12283 "VK_IMAGE_LAYOUT_UNDEFINED and doesn't match the current "
12284 "layout VK_IMAGE_LAYOUT_GENERAL.");
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060012285 m_commandBuffer->CopyImage(src_image, VK_IMAGE_LAYOUT_UNDEFINED, dst_image, VK_IMAGE_LAYOUT_GENERAL, 1, &copyRegion);
12286 m_errorMonitor->VerifyFound();
12287 // Final src error is due to bad layout type
12288 m_errorMonitor->SetDesiredFailureMsg(
12289 VK_DEBUG_REPORT_ERROR_BIT_EXT,
12290 "Layout for input image is VK_IMAGE_LAYOUT_UNDEFINED but can only be TRANSFER_SRC_OPTIMAL or GENERAL.");
12291 m_commandBuffer->CopyImage(src_image, VK_IMAGE_LAYOUT_UNDEFINED, dst_image, VK_IMAGE_LAYOUT_GENERAL, 1, &copyRegion);
12292 m_errorMonitor->VerifyFound();
12293 // Now verify same checks for dst
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012294 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
12295 "Layout for output image should be TRANSFER_DST_OPTIMAL instead of GENERAL.");
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060012296 m_commandBuffer->CopyImage(src_image, VK_IMAGE_LAYOUT_GENERAL, dst_image, VK_IMAGE_LAYOUT_GENERAL, 1, &copyRegion);
12297 m_errorMonitor->VerifyFound();
12298 // Now cause error due to src image layout changing
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012299 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Cannot copy from an image whose dest layout is "
12300 "VK_IMAGE_LAYOUT_UNDEFINED and doesn't match the current "
12301 "layout VK_IMAGE_LAYOUT_GENERAL.");
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060012302 m_commandBuffer->CopyImage(src_image, VK_IMAGE_LAYOUT_GENERAL, dst_image, VK_IMAGE_LAYOUT_UNDEFINED, 1, &copyRegion);
12303 m_errorMonitor->VerifyFound();
12304 m_errorMonitor->SetDesiredFailureMsg(
12305 VK_DEBUG_REPORT_ERROR_BIT_EXT,
12306 "Layout for output image is VK_IMAGE_LAYOUT_UNDEFINED but can only be TRANSFER_DST_OPTIMAL or GENERAL.");
12307 m_commandBuffer->CopyImage(src_image, VK_IMAGE_LAYOUT_GENERAL, dst_image, VK_IMAGE_LAYOUT_UNDEFINED, 1, &copyRegion);
12308 m_errorMonitor->VerifyFound();
12309 // Now cause error due to bad image layout transition in PipelineBarrier
12310 VkImageMemoryBarrier image_barrier[1] = {};
12311 image_barrier[0].oldLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL;
12312 image_barrier[0].image = src_image;
12313 image_barrier[0].subresourceRange.layerCount = 2;
12314 image_barrier[0].subresourceRange.levelCount = 2;
12315 image_barrier[0].subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012316 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "You cannot transition the layout from "
12317 "VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL when "
12318 "current layout is VK_IMAGE_LAYOUT_GENERAL.");
12319 vkCmdPipelineBarrier(m_commandBuffer->handle(), VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0,
12320 NULL, 0, NULL, 1, image_barrier);
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060012321 m_errorMonitor->VerifyFound();
12322
12323 // Finally some layout errors at RenderPass create time
12324 // Just hacking in specific state to get to the errors we want so don't copy this unless you know what you're doing.
12325 VkAttachmentReference attach = {};
12326 // perf warning for GENERAL layout w/ non-DS input attachment
12327 attach.layout = VK_IMAGE_LAYOUT_GENERAL;
12328 VkSubpassDescription subpass = {};
12329 subpass.inputAttachmentCount = 1;
12330 subpass.pInputAttachments = &attach;
12331 VkRenderPassCreateInfo rpci = {};
12332 rpci.subpassCount = 1;
12333 rpci.pSubpasses = &subpass;
12334 rpci.attachmentCount = 1;
12335 VkAttachmentDescription attach_desc = {};
12336 attach_desc.format = VK_FORMAT_UNDEFINED;
12337 rpci.pAttachments = &attach_desc;
Tobin Ehlis1efce022016-05-11 10:40:34 -060012338 rpci.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060012339 VkRenderPass rp;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012340 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
12341 "Layout for input attachment is GENERAL but should be READ_ONLY_OPTIMAL.");
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060012342 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
12343 m_errorMonitor->VerifyFound();
12344 // error w/ non-general layout
12345 attach.layout = VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL;
12346
12347 m_errorMonitor->SetDesiredFailureMsg(
12348 VK_DEBUG_REPORT_ERROR_BIT_EXT,
12349 "Layout for input attachment is VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL but can only be READ_ONLY_OPTIMAL or GENERAL.");
12350 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
12351 m_errorMonitor->VerifyFound();
12352 subpass.inputAttachmentCount = 0;
12353 subpass.colorAttachmentCount = 1;
12354 subpass.pColorAttachments = &attach;
12355 attach.layout = VK_IMAGE_LAYOUT_GENERAL;
12356 // perf warning for GENERAL layout on color attachment
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012357 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
12358 "Layout for color attachment is GENERAL but should be COLOR_ATTACHMENT_OPTIMAL.");
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060012359 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
12360 m_errorMonitor->VerifyFound();
12361 // error w/ non-color opt or GENERAL layout for color attachment
12362 attach.layout = VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL;
12363 m_errorMonitor->SetDesiredFailureMsg(
12364 VK_DEBUG_REPORT_ERROR_BIT_EXT,
12365 "Layout for color attachment is VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL but can only be COLOR_ATTACHMENT_OPTIMAL or GENERAL.");
12366 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
12367 m_errorMonitor->VerifyFound();
12368 subpass.colorAttachmentCount = 0;
12369 subpass.pDepthStencilAttachment = &attach;
12370 attach.layout = VK_IMAGE_LAYOUT_GENERAL;
12371 // perf warning for GENERAL layout on DS attachment
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012372 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
12373 "GENERAL layout for depth attachment may not give optimal performance.");
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060012374 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
12375 m_errorMonitor->VerifyFound();
12376 // error w/ non-ds opt or GENERAL layout for color attachment
12377 attach.layout = VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012378 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
12379 "Layout for depth attachment is VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL but can only be "
12380 "DEPTH_STENCIL_ATTACHMENT_OPTIMAL, DEPTH_STENCIL_READ_ONLY_OPTIMAL or GENERAL.");
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060012381 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
12382 m_errorMonitor->VerifyFound();
Tobin Ehlis1efce022016-05-11 10:40:34 -060012383 // For this error we need a valid renderpass so create default one
12384 attach.layout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL;
12385 attach.attachment = 0;
12386 attach_desc.format = VK_FORMAT_D24_UNORM_S8_UINT;
12387 attach_desc.samples = VK_SAMPLE_COUNT_1_BIT;
12388 attach_desc.storeOp = VK_ATTACHMENT_STORE_OP_STORE;
12389 attach_desc.stencilLoadOp = VK_ATTACHMENT_LOAD_OP_DONT_CARE;
12390 attach_desc.stencilStoreOp = VK_ATTACHMENT_STORE_OP_DONT_CARE;
12391 // Can't do a CLEAR load on READ_ONLY initialLayout
12392 attach_desc.loadOp = VK_ATTACHMENT_LOAD_OP_CLEAR;
12393 attach_desc.initialLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL;
12394 attach_desc.finalLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012395 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " with invalid first layout "
12396 "VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_"
12397 "ONLY_OPTIMAL");
Tobin Ehlis1efce022016-05-11 10:40:34 -060012398 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
12399 m_errorMonitor->VerifyFound();
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060012400
12401 vkDestroyImage(m_device->device(), src_image, NULL);
12402 vkDestroyImage(m_device->device(), dst_image, NULL);
12403}
Tobin Ehlisd8d89182016-07-18 20:13:11 -060012404
12405TEST_F(VkLayerTest, ValidRenderPassAttachmentLayoutWithLoadOp) {
12406 TEST_DESCRIPTION("Positive test where we create a renderpass with an "
12407 "attachment that uses LOAD_OP_CLEAR, the first subpass "
12408 "has a valid layout, and a second subpass then uses a "
12409 "valid *READ_ONLY* layout.");
12410 m_errorMonitor->ExpectSuccess();
12411 ASSERT_NO_FATAL_FAILURE(InitState());
12412
12413 VkAttachmentReference attach[2] = {};
12414 attach[0].attachment = 0;
12415 attach[0].layout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
12416 attach[1].attachment = 0;
12417 attach[1].layout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL;
12418 VkSubpassDescription subpasses[2] = {};
12419 // First subpass clears DS attach on load
12420 subpasses[0].pDepthStencilAttachment = &attach[0];
12421 // 2nd subpass reads in DS as input attachment
12422 subpasses[1].inputAttachmentCount = 1;
12423 subpasses[1].pInputAttachments = &attach[1];
12424 VkAttachmentDescription attach_desc = {};
12425 attach_desc.format = VK_FORMAT_D24_UNORM_S8_UINT;
12426 attach_desc.samples = VK_SAMPLE_COUNT_1_BIT;
12427 attach_desc.storeOp = VK_ATTACHMENT_STORE_OP_STORE;
12428 attach_desc.stencilStoreOp = VK_ATTACHMENT_STORE_OP_DONT_CARE;
12429 attach_desc.loadOp = VK_ATTACHMENT_LOAD_OP_CLEAR;
12430 attach_desc.stencilLoadOp = VK_ATTACHMENT_LOAD_OP_CLEAR;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012431 attach_desc.initialLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
Tobin Ehlisd8d89182016-07-18 20:13:11 -060012432 attach_desc.finalLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL;
12433 VkRenderPassCreateInfo rpci = {};
12434 rpci.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
12435 rpci.attachmentCount = 1;
12436 rpci.pAttachments = &attach_desc;
12437 rpci.subpassCount = 2;
12438 rpci.pSubpasses = subpasses;
12439
12440 // Now create RenderPass and verify no errors
12441 VkRenderPass rp;
12442 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
12443 m_errorMonitor->VerifyNotFound();
12444
12445 vkDestroyRenderPass(m_device->device(), rp, NULL);
12446}
Tobin Ehlis4af23302016-07-19 10:50:30 -060012447
Mark Mueller93b938f2016-08-18 10:27:40 -060012448TEST_F(VkLayerTest, SimultaneousUse) {
12449 TEST_DESCRIPTION("Use vkCmdExecuteCommands with invalid state "
12450 "in primary and secondary command buffers.");
12451
12452 ASSERT_NO_FATAL_FAILURE(InitState());
12453 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12454
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012455 const char *simultaneous_use_message1 = "w/o VK_COMMAND_BUFFER_USAGE_SIMULTANEOUS_USE_BIT set!";
12456 const char *simultaneous_use_message2 = "does not have VK_COMMAND_BUFFER_USAGE_SIMULTANEOUS_USE_BIT set and "
12457 "will cause primary command buffer";
Mark Mueller93b938f2016-08-18 10:27:40 -060012458
12459 VkCommandBufferAllocateInfo command_buffer_allocate_info = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012460 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
Mark Mueller93b938f2016-08-18 10:27:40 -060012461 command_buffer_allocate_info.commandPool = m_commandPool;
12462 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_SECONDARY;
12463 command_buffer_allocate_info.commandBufferCount = 1;
12464
12465 VkCommandBuffer secondary_command_buffer;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012466 ASSERT_VK_SUCCESS(vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, &secondary_command_buffer));
Mark Mueller93b938f2016-08-18 10:27:40 -060012467 VkCommandBufferBeginInfo command_buffer_begin_info = {};
12468 VkCommandBufferInheritanceInfo command_buffer_inheritance_info = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012469 command_buffer_inheritance_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_INHERITANCE_INFO;
Mark Mueller93b938f2016-08-18 10:27:40 -060012470 command_buffer_inheritance_info.renderPass = m_renderPass;
12471 command_buffer_inheritance_info.framebuffer = m_framebuffer;
12472 command_buffer_begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012473 command_buffer_begin_info.flags =
12474 VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT | VK_COMMAND_BUFFER_USAGE_RENDER_PASS_CONTINUE_BIT;
Mark Mueller93b938f2016-08-18 10:27:40 -060012475 command_buffer_begin_info.pInheritanceInfo = &command_buffer_inheritance_info;
12476
12477 vkBeginCommandBuffer(secondary_command_buffer, &command_buffer_begin_info);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012478 vkCmdBeginRenderPass(m_commandBuffer->handle(), &renderPassBeginInfo(), VK_SUBPASS_CONTENTS_SECONDARY_COMMAND_BUFFERS);
12479 vkCmdExecuteCommands(m_commandBuffer->handle(), 1, &secondary_command_buffer);
Mark Mueller4042b652016-09-05 22:52:21 -060012480 vkCmdEndRenderPass(m_commandBuffer->GetBufferHandle());
Mark Mueller93b938f2016-08-18 10:27:40 -060012481 vkEndCommandBuffer(secondary_command_buffer);
12482
Mark Mueller93b938f2016-08-18 10:27:40 -060012483 VkSubmitInfo submit_info = {};
12484 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
12485 submit_info.commandBufferCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012486 submit_info.pCommandBuffers = &m_commandBuffer->handle();
Mark Mueller4042b652016-09-05 22:52:21 -060012487 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
Mark Mueller93b938f2016-08-18 10:27:40 -060012488
Mark Mueller4042b652016-09-05 22:52:21 -060012489 vkBeginCommandBuffer(m_commandBuffer->handle(), &command_buffer_begin_info);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012490 vkCmdBeginRenderPass(m_commandBuffer->handle(), &renderPassBeginInfo(), VK_SUBPASS_CONTENTS_SECONDARY_COMMAND_BUFFERS);
12491 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, simultaneous_use_message1);
12492 vkCmdExecuteCommands(m_commandBuffer->handle(), 1, &secondary_command_buffer);
Mark Mueller93b938f2016-08-18 10:27:40 -060012493 m_errorMonitor->VerifyFound();
Mark Mueller4042b652016-09-05 22:52:21 -060012494 vkCmdEndRenderPass(m_commandBuffer->GetBufferHandle());
12495 vkEndCommandBuffer(m_commandBuffer->handle());
Mark Mueller93b938f2016-08-18 10:27:40 -060012496
12497 m_errorMonitor->SetDesiredFailureMsg(0, "");
Mark Mueller93b938f2016-08-18 10:27:40 -060012498 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
12499
Mark Mueller4042b652016-09-05 22:52:21 -060012500 command_buffer_begin_info.flags = VK_COMMAND_BUFFER_USAGE_SIMULTANEOUS_USE_BIT;
Mark Mueller93b938f2016-08-18 10:27:40 -060012501 vkBeginCommandBuffer(m_commandBuffer->handle(), &command_buffer_begin_info);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012502 vkCmdBeginRenderPass(m_commandBuffer->handle(), &renderPassBeginInfo(), VK_SUBPASS_CONTENTS_SECONDARY_COMMAND_BUFFERS);
Mark Mueller4042b652016-09-05 22:52:21 -060012503
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012504 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT, simultaneous_use_message2);
12505 vkCmdExecuteCommands(m_commandBuffer->handle(), 1, &secondary_command_buffer);
Mark Mueller93b938f2016-08-18 10:27:40 -060012506 m_errorMonitor->VerifyFound();
Mark Mueller4042b652016-09-05 22:52:21 -060012507 vkCmdEndRenderPass(m_commandBuffer->GetBufferHandle());
12508 vkEndCommandBuffer(m_commandBuffer->handle());
Mark Mueller93b938f2016-08-18 10:27:40 -060012509}
12510
Mark Mueller917f6bc2016-08-30 10:57:19 -060012511TEST_F(VkLayerTest, InUseDestroyedSignaled) {
12512 TEST_DESCRIPTION("Use vkCmdExecuteCommands with invalid state "
12513 "in primary and secondary command buffers. "
Mark Muellerc8d441e2016-08-23 17:36:00 -060012514 "Delete objects that are inuse. Call VkQueueSubmit "
12515 "with an event that has been deleted.");
Mark Mueller917f6bc2016-08-30 10:57:19 -060012516
12517 ASSERT_NO_FATAL_FAILURE(InitState());
12518 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12519
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012520 const char *submit_with_deleted_event_message = "Cannot submit cmd buffer using deleted event 0x";
12521 const char *cannot_delete_event_message = "Cannot delete event 0x";
12522 const char *cannot_delete_semaphore_message = "Cannot delete semaphore 0x";
12523 const char *cannot_destroy_fence_message = "Fence 0x";
Mark Mueller917f6bc2016-08-30 10:57:19 -060012524
12525 BeginCommandBuffer();
12526
12527 VkEvent event;
12528 VkEventCreateInfo event_create_info = {};
12529 event_create_info.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO;
12530 vkCreateEvent(m_device->device(), &event_create_info, nullptr, &event);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012531 vkCmdSetEvent(m_commandBuffer->handle(), event, VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT);
Mark Mueller917f6bc2016-08-30 10:57:19 -060012532
Mark Muellerc8d441e2016-08-23 17:36:00 -060012533 EndCommandBuffer();
12534 vkDestroyEvent(m_device->device(), event, nullptr);
12535
12536 VkSubmitInfo submit_info = {};
12537 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
12538 submit_info.commandBufferCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012539 submit_info.pCommandBuffers = &m_commandBuffer->handle();
12540 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, submit_with_deleted_event_message);
Mark Muellerc8d441e2016-08-23 17:36:00 -060012541 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
12542 m_errorMonitor->VerifyFound();
12543
12544 m_errorMonitor->SetDesiredFailureMsg(0, "");
12545 vkResetCommandBuffer(m_commandBuffer->handle(), 0);
12546
12547 vkCreateEvent(m_device->device(), &event_create_info, nullptr, &event);
12548
Mark Mueller917f6bc2016-08-30 10:57:19 -060012549 VkSemaphoreCreateInfo semaphore_create_info = {};
12550 semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
12551 VkSemaphore semaphore;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012552 ASSERT_VK_SUCCESS(vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr, &semaphore));
Mark Mueller917f6bc2016-08-30 10:57:19 -060012553 VkFenceCreateInfo fence_create_info = {};
12554 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
12555 VkFence fence;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012556 ASSERT_VK_SUCCESS(vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence));
Mark Mueller917f6bc2016-08-30 10:57:19 -060012557
12558 VkDescriptorPoolSize descriptor_pool_type_count = {};
Mark Mueller4042b652016-09-05 22:52:21 -060012559 descriptor_pool_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Mark Mueller917f6bc2016-08-30 10:57:19 -060012560 descriptor_pool_type_count.descriptorCount = 1;
12561
12562 VkDescriptorPoolCreateInfo descriptor_pool_create_info = {};
12563 descriptor_pool_create_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
12564 descriptor_pool_create_info.maxSets = 1;
12565 descriptor_pool_create_info.poolSizeCount = 1;
12566 descriptor_pool_create_info.pPoolSizes = &descriptor_pool_type_count;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012567 descriptor_pool_create_info.flags = VK_DESCRIPTOR_POOL_CREATE_FREE_DESCRIPTOR_SET_BIT;
Mark Mueller917f6bc2016-08-30 10:57:19 -060012568
12569 VkDescriptorPool descriptorset_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012570 ASSERT_VK_SUCCESS(vkCreateDescriptorPool(m_device->device(), &descriptor_pool_create_info, nullptr, &descriptorset_pool));
Mark Mueller917f6bc2016-08-30 10:57:19 -060012571
12572 VkDescriptorSetLayoutBinding descriptorset_layout_binding = {};
Mark Mueller4042b652016-09-05 22:52:21 -060012573 descriptorset_layout_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Mark Mueller917f6bc2016-08-30 10:57:19 -060012574 descriptorset_layout_binding.descriptorCount = 1;
12575 descriptorset_layout_binding.stageFlags = VK_SHADER_STAGE_ALL;
12576
12577 VkDescriptorSetLayoutCreateInfo descriptorset_layout_create_info = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012578 descriptorset_layout_create_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
Mark Mueller917f6bc2016-08-30 10:57:19 -060012579 descriptorset_layout_create_info.bindingCount = 1;
12580 descriptorset_layout_create_info.pBindings = &descriptorset_layout_binding;
12581
12582 VkDescriptorSetLayout descriptorset_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012583 ASSERT_VK_SUCCESS(
12584 vkCreateDescriptorSetLayout(m_device->device(), &descriptorset_layout_create_info, nullptr, &descriptorset_layout));
Mark Mueller917f6bc2016-08-30 10:57:19 -060012585
12586 VkDescriptorSet descriptorset;
12587 VkDescriptorSetAllocateInfo descriptorset_allocate_info = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012588 descriptorset_allocate_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Mark Mueller917f6bc2016-08-30 10:57:19 -060012589 descriptorset_allocate_info.descriptorSetCount = 1;
12590 descriptorset_allocate_info.descriptorPool = descriptorset_pool;
12591 descriptorset_allocate_info.pSetLayouts = &descriptorset_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012592 ASSERT_VK_SUCCESS(vkAllocateDescriptorSets(m_device->device(), &descriptorset_allocate_info, &descriptorset));
Mark Mueller917f6bc2016-08-30 10:57:19 -060012593
Mark Mueller4042b652016-09-05 22:52:21 -060012594 VkBufferTest buffer_test(m_device, VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT);
12595
12596 VkDescriptorBufferInfo buffer_info = {};
12597 buffer_info.buffer = buffer_test.GetBuffer();
12598 buffer_info.offset = 0;
12599 buffer_info.range = 1024;
12600
12601 VkWriteDescriptorSet write_descriptor_set = {};
12602 write_descriptor_set.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
12603 write_descriptor_set.dstSet = descriptorset;
12604 write_descriptor_set.descriptorCount = 1;
12605 write_descriptor_set.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
12606 write_descriptor_set.pBufferInfo = &buffer_info;
12607
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012608 vkUpdateDescriptorSets(m_device->device(), 1, &write_descriptor_set, 0, nullptr);
Mark Mueller4042b652016-09-05 22:52:21 -060012609
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012610 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
12611 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Mark Mueller917f6bc2016-08-30 10:57:19 -060012612
12613 VkPipelineObj pipe(m_device);
12614 pipe.AddColorAttachment();
12615 pipe.AddShader(&vs);
12616 pipe.AddShader(&fs);
12617
12618 VkPipelineLayoutCreateInfo pipeline_layout_create_info = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012619 pipeline_layout_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
Mark Mueller917f6bc2016-08-30 10:57:19 -060012620 pipeline_layout_create_info.setLayoutCount = 1;
12621 pipeline_layout_create_info.pSetLayouts = &descriptorset_layout;
12622
12623 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012624 ASSERT_VK_SUCCESS(vkCreatePipelineLayout(m_device->device(), &pipeline_layout_create_info, nullptr, &pipeline_layout));
Mark Mueller917f6bc2016-08-30 10:57:19 -060012625
12626 pipe.CreateVKPipeline(pipeline_layout, m_renderPass);
12627
Mark Muellerc8d441e2016-08-23 17:36:00 -060012628 BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012629 vkCmdSetEvent(m_commandBuffer->handle(), event, VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT);
Mark Muellerc8d441e2016-08-23 17:36:00 -060012630
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012631 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
12632 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
12633 &descriptorset, 0, NULL);
Mark Mueller917f6bc2016-08-30 10:57:19 -060012634
Mark Muellerc8d441e2016-08-23 17:36:00 -060012635 EndCommandBuffer();
Mark Mueller917f6bc2016-08-30 10:57:19 -060012636
Mark Mueller917f6bc2016-08-30 10:57:19 -060012637 submit_info.signalSemaphoreCount = 1;
12638 submit_info.pSignalSemaphores = &semaphore;
12639 vkQueueSubmit(m_device->m_queue, 1, &submit_info, fence);
Mark Muellerc8d441e2016-08-23 17:36:00 -060012640
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012641 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, cannot_delete_event_message);
Mark Mueller917f6bc2016-08-30 10:57:19 -060012642 vkDestroyEvent(m_device->device(), event, nullptr);
12643 m_errorMonitor->VerifyFound();
12644
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012645 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, cannot_delete_semaphore_message);
Mark Mueller917f6bc2016-08-30 10:57:19 -060012646 vkDestroySemaphore(m_device->device(), semaphore, nullptr);
12647 m_errorMonitor->VerifyFound();
12648
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012649 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, cannot_destroy_fence_message);
Mark Mueller917f6bc2016-08-30 10:57:19 -060012650 vkDestroyFence(m_device->device(), fence, nullptr);
12651 m_errorMonitor->VerifyFound();
12652
Tobin Ehlis122207b2016-09-01 08:50:06 -070012653 vkQueueWaitIdle(m_device->m_queue);
Mark Mueller917f6bc2016-08-30 10:57:19 -060012654 vkDestroySemaphore(m_device->device(), semaphore, nullptr);
12655 vkDestroyFence(m_device->device(), fence, nullptr);
12656 vkDestroyEvent(m_device->device(), event, nullptr);
12657 vkDestroyDescriptorPool(m_device->device(), descriptorset_pool, nullptr);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012658 vkDestroyDescriptorSetLayout(m_device->device(), descriptorset_layout, nullptr);
Mark Mueller917f6bc2016-08-30 10:57:19 -060012659 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, nullptr);
12660}
12661
Tobin Ehlis2adda372016-09-01 08:51:06 -070012662TEST_F(VkLayerTest, QueryPoolInUseDestroyedSignaled) {
12663 TEST_DESCRIPTION("Delete in-use query pool.");
12664
12665 ASSERT_NO_FATAL_FAILURE(InitState());
12666 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12667
12668 VkQueryPool query_pool;
12669 VkQueryPoolCreateInfo query_pool_ci{};
12670 query_pool_ci.sType = VK_STRUCTURE_TYPE_QUERY_POOL_CREATE_INFO;
12671 query_pool_ci.queryType = VK_QUERY_TYPE_TIMESTAMP;
12672 query_pool_ci.queryCount = 1;
12673 vkCreateQueryPool(m_device->device(), &query_pool_ci, nullptr, &query_pool);
12674 BeginCommandBuffer();
12675 // Reset query pool to create binding with cmd buffer
12676 vkCmdResetQueryPool(m_commandBuffer->handle(), query_pool, 0, 1);
12677
12678 EndCommandBuffer();
12679
12680 VkSubmitInfo submit_info = {};
12681 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
12682 submit_info.commandBufferCount = 1;
12683 submit_info.pCommandBuffers = &m_commandBuffer->handle();
12684 // Submit cmd buffer and then destroy query pool while in-flight
12685 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
12686
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012687 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Cannot delete query pool 0x");
Tobin Ehlis2adda372016-09-01 08:51:06 -070012688 vkDestroyQueryPool(m_device->handle(), query_pool, NULL);
12689 m_errorMonitor->VerifyFound();
12690
12691 vkQueueWaitIdle(m_device->m_queue);
12692 // Now that cmd buffer done we can safely destroy query_pool
12693 vkDestroyQueryPool(m_device->handle(), query_pool, NULL);
12694}
12695
Tobin Ehlisfafab2d2016-09-07 13:51:24 -060012696TEST_F(VkLayerTest, PipelineInUseDestroyedSignaled) {
12697 TEST_DESCRIPTION("Delete in-use pipeline.");
12698
12699 ASSERT_NO_FATAL_FAILURE(InitState());
12700 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12701
12702 // Empty pipeline layout used for binding PSO
12703 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
12704 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
12705 pipeline_layout_ci.setLayoutCount = 0;
12706 pipeline_layout_ci.pSetLayouts = NULL;
12707
12708 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012709 VkResult err = vkCreatePipelineLayout(m_device->handle(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlisfafab2d2016-09-07 13:51:24 -060012710 ASSERT_VK_SUCCESS(err);
12711
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012712 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Cannot delete pipeline 0x");
Tobin Ehlisfafab2d2016-09-07 13:51:24 -060012713 // Create PSO to be used for draw-time errors below
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012714 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
12715 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Tobin Ehlisfafab2d2016-09-07 13:51:24 -060012716 // Store pipeline handle so we can actually delete it before test finishes
12717 VkPipeline delete_this_pipeline;
12718 { // Scope pipeline so it will be auto-deleted
12719 VkPipelineObj pipe(m_device);
12720 pipe.AddShader(&vs);
12721 pipe.AddShader(&fs);
12722 pipe.AddColorAttachment();
12723 pipe.CreateVKPipeline(pipeline_layout, renderPass());
12724 delete_this_pipeline = pipe.handle();
12725
12726 BeginCommandBuffer();
12727 // Bind pipeline to cmd buffer
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012728 vkCmdBindPipeline(m_commandBuffer->handle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Tobin Ehlisfafab2d2016-09-07 13:51:24 -060012729
12730 EndCommandBuffer();
12731
12732 VkSubmitInfo submit_info = {};
12733 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
12734 submit_info.commandBufferCount = 1;
12735 submit_info.pCommandBuffers = &m_commandBuffer->handle();
12736 // Submit cmd buffer and then pipeline destroyed while in-flight
12737 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
12738 } // Pipeline deletion triggered here
12739 m_errorMonitor->VerifyFound();
12740 // Make sure queue finished and then actually delete pipeline
12741 vkQueueWaitIdle(m_device->m_queue);
12742 vkDestroyPipeline(m_device->handle(), delete_this_pipeline, nullptr);
12743 vkDestroyPipelineLayout(m_device->handle(), pipeline_layout, nullptr);
12744}
12745
Tobin Ehlis209532e2016-09-07 13:52:18 -060012746TEST_F(VkLayerTest, SamplerInUseDestroyedSignaled) {
12747 TEST_DESCRIPTION("Delete in-use sampler.");
12748
12749 ASSERT_NO_FATAL_FAILURE(InitState());
12750 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12751
12752 VkDescriptorPoolSize ds_type_count;
12753 ds_type_count.type = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
12754 ds_type_count.descriptorCount = 1;
12755
12756 VkDescriptorPoolCreateInfo ds_pool_ci = {};
12757 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
12758 ds_pool_ci.maxSets = 1;
12759 ds_pool_ci.poolSizeCount = 1;
12760 ds_pool_ci.pPoolSizes = &ds_type_count;
12761
12762 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012763 VkResult err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis209532e2016-09-07 13:52:18 -060012764 ASSERT_VK_SUCCESS(err);
12765
12766 VkSamplerCreateInfo sampler_ci = {};
12767 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
12768 sampler_ci.pNext = NULL;
12769 sampler_ci.magFilter = VK_FILTER_NEAREST;
12770 sampler_ci.minFilter = VK_FILTER_NEAREST;
12771 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
12772 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
12773 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
12774 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
12775 sampler_ci.mipLodBias = 1.0;
12776 sampler_ci.anisotropyEnable = VK_FALSE;
12777 sampler_ci.maxAnisotropy = 1;
12778 sampler_ci.compareEnable = VK_FALSE;
12779 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
12780 sampler_ci.minLod = 1.0;
12781 sampler_ci.maxLod = 1.0;
12782 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
12783 sampler_ci.unnormalizedCoordinates = VK_FALSE;
12784 VkSampler sampler;
12785
12786 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
12787 ASSERT_VK_SUCCESS(err);
12788
12789 VkDescriptorSetLayoutBinding layout_binding;
12790 layout_binding.binding = 0;
12791 layout_binding.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
12792 layout_binding.descriptorCount = 1;
12793 layout_binding.stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
12794 layout_binding.pImmutableSamplers = NULL;
12795
12796 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
12797 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
12798 ds_layout_ci.bindingCount = 1;
12799 ds_layout_ci.pBindings = &layout_binding;
12800 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012801 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis209532e2016-09-07 13:52:18 -060012802 ASSERT_VK_SUCCESS(err);
12803
12804 VkDescriptorSetAllocateInfo alloc_info = {};
12805 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
12806 alloc_info.descriptorSetCount = 1;
12807 alloc_info.descriptorPool = ds_pool;
12808 alloc_info.pSetLayouts = &ds_layout;
12809 VkDescriptorSet descriptor_set;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012810 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
Tobin Ehlis209532e2016-09-07 13:52:18 -060012811 ASSERT_VK_SUCCESS(err);
12812
12813 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
12814 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
12815 pipeline_layout_ci.pNext = NULL;
12816 pipeline_layout_ci.setLayoutCount = 1;
12817 pipeline_layout_ci.pSetLayouts = &ds_layout;
12818
12819 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012820 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis209532e2016-09-07 13:52:18 -060012821 ASSERT_VK_SUCCESS(err);
12822
12823 VkImageObj image(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012824 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 -060012825 ASSERT_TRUE(image.initialized());
12826
12827 VkImageView view;
12828 VkImageViewCreateInfo ivci = {};
12829 ivci.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
12830 ivci.image = image.handle();
12831 ivci.viewType = VK_IMAGE_VIEW_TYPE_2D;
12832 ivci.format = VK_FORMAT_R8G8B8A8_UNORM;
12833 ivci.subresourceRange.layerCount = 1;
12834 ivci.subresourceRange.baseMipLevel = 0;
12835 ivci.subresourceRange.levelCount = 1;
12836 ivci.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
12837
12838 err = vkCreateImageView(m_device->device(), &ivci, NULL, &view);
12839 ASSERT_VK_SUCCESS(err);
12840
12841 VkDescriptorImageInfo image_info{};
12842 image_info.imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
12843 image_info.imageView = view;
12844 image_info.sampler = sampler;
12845
12846 VkWriteDescriptorSet descriptor_write = {};
12847 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
12848 descriptor_write.dstSet = descriptor_set;
12849 descriptor_write.dstBinding = 0;
12850 descriptor_write.descriptorCount = 1;
12851 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
12852 descriptor_write.pImageInfo = &image_info;
12853
12854 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
12855
12856 // Create PSO to use the sampler
12857 char const *vsSource = "#version 450\n"
12858 "\n"
12859 "out gl_PerVertex { \n"
12860 " vec4 gl_Position;\n"
12861 "};\n"
12862 "void main(){\n"
12863 " gl_Position = vec4(1);\n"
12864 "}\n";
12865 char const *fsSource = "#version 450\n"
12866 "\n"
12867 "layout(set=0, binding=0) uniform sampler2D s;\n"
12868 "layout(location=0) out vec4 x;\n"
12869 "void main(){\n"
12870 " x = texture(s, vec2(1));\n"
12871 "}\n";
12872 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
12873 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
12874 VkPipelineObj pipe(m_device);
12875 pipe.AddShader(&vs);
12876 pipe.AddShader(&fs);
12877 pipe.AddColorAttachment();
12878 pipe.CreateVKPipeline(pipeline_layout, renderPass());
12879
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012880 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Cannot delete sampler 0x");
Tobin Ehlis209532e2016-09-07 13:52:18 -060012881
12882 BeginCommandBuffer();
12883 // Bind pipeline to cmd buffer
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012884 vkCmdBindPipeline(m_commandBuffer->handle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
12885 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
12886 &descriptor_set, 0, nullptr);
Tobin Ehlis209532e2016-09-07 13:52:18 -060012887 Draw(1, 0, 0, 0);
12888 EndCommandBuffer();
12889 // Submit cmd buffer then destroy sampler
12890 VkSubmitInfo submit_info = {};
12891 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
12892 submit_info.commandBufferCount = 1;
12893 submit_info.pCommandBuffers = &m_commandBuffer->handle();
12894 // Submit cmd buffer and then destroy sampler while in-flight
12895 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
12896
12897 vkDestroySampler(m_device->device(), sampler, nullptr);
12898 m_errorMonitor->VerifyFound();
12899 vkQueueWaitIdle(m_device->m_queue);
12900 // Now we can actually destroy sampler
12901 vkDestroySampler(m_device->device(), sampler, nullptr);
12902 vkDestroyImageView(m_device->device(), view, NULL);
12903 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
12904 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
12905 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
12906}
12907
Mark Mueller1cd9f412016-08-25 13:23:52 -060012908TEST_F(VkLayerTest, QueueForwardProgressFenceWait) {
Mark Mueller96a56d52016-08-24 10:28:05 -060012909 TEST_DESCRIPTION("Call VkQueueSubmit with a semaphore that is already "
Mark Mueller1cd9f412016-08-25 13:23:52 -060012910 "signaled but not waited on by the queue. Wait on a "
12911 "fence that has not yet been submitted to a queue.");
Mark Mueller96a56d52016-08-24 10:28:05 -060012912
12913 ASSERT_NO_FATAL_FAILURE(InitState());
12914 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12915
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012916 const char *queue_forward_progress_message = " that has already been signaled but not waited on by queue 0x";
12917 const char *invalid_fence_wait_message = " which has not been submitted on a Queue or during "
12918 "acquire next image.";
Mark Mueller96a56d52016-08-24 10:28:05 -060012919
12920 BeginCommandBuffer();
12921 EndCommandBuffer();
12922
12923 VkSemaphoreCreateInfo semaphore_create_info = {};
12924 semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
12925 VkSemaphore semaphore;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012926 ASSERT_VK_SUCCESS(vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr, &semaphore));
Mark Mueller96a56d52016-08-24 10:28:05 -060012927 VkSubmitInfo submit_info = {};
12928 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
12929 submit_info.commandBufferCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012930 submit_info.pCommandBuffers = &m_commandBuffer->handle();
Mark Mueller96a56d52016-08-24 10:28:05 -060012931 submit_info.signalSemaphoreCount = 1;
12932 submit_info.pSignalSemaphores = &semaphore;
12933 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
12934 m_errorMonitor->SetDesiredFailureMsg(0, "");
12935 vkResetCommandBuffer(m_commandBuffer->handle(), 0);
12936 BeginCommandBuffer();
12937 EndCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012938 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, queue_forward_progress_message);
Mark Mueller96a56d52016-08-24 10:28:05 -060012939 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
12940 m_errorMonitor->VerifyFound();
12941
Mark Mueller1cd9f412016-08-25 13:23:52 -060012942 VkFenceCreateInfo fence_create_info = {};
12943 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
12944 VkFence fence;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012945 ASSERT_VK_SUCCESS(vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence));
Mark Mueller1cd9f412016-08-25 13:23:52 -060012946
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012947 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT, invalid_fence_wait_message);
Mark Mueller1cd9f412016-08-25 13:23:52 -060012948 vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
12949 m_errorMonitor->VerifyFound();
12950
Mark Mueller4042b652016-09-05 22:52:21 -060012951 vkDeviceWaitIdle(m_device->device());
Mark Mueller1cd9f412016-08-25 13:23:52 -060012952 vkDestroyFence(m_device->device(), fence, nullptr);
Mark Mueller96a56d52016-08-24 10:28:05 -060012953 vkDestroySemaphore(m_device->device(), semaphore, nullptr);
12954}
12955
Tobin Ehlis4af23302016-07-19 10:50:30 -060012956TEST_F(VkLayerTest, FramebufferIncompatible) {
12957 TEST_DESCRIPTION("Bind a secondary command buffer with with a framebuffer "
12958 "that does not match the framebuffer for the active "
12959 "renderpass.");
12960 ASSERT_NO_FATAL_FAILURE(InitState());
12961 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12962
12963 // A renderpass with one color attachment.
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012964 VkAttachmentDescription attachment = {0,
12965 VK_FORMAT_B8G8R8A8_UNORM,
12966 VK_SAMPLE_COUNT_1_BIT,
12967 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
12968 VK_ATTACHMENT_STORE_OP_STORE,
12969 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
12970 VK_ATTACHMENT_STORE_OP_DONT_CARE,
12971 VK_IMAGE_LAYOUT_UNDEFINED,
12972 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL};
Tobin Ehlis4af23302016-07-19 10:50:30 -060012973
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012974 VkAttachmentReference att_ref = {0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL};
Tobin Ehlis4af23302016-07-19 10:50:30 -060012975
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012976 VkSubpassDescription subpass = {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 1, &att_ref, nullptr, nullptr, 0, nullptr};
Tobin Ehlis4af23302016-07-19 10:50:30 -060012977
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012978 VkRenderPassCreateInfo rpci = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 1, &attachment, 1, &subpass, 0, nullptr};
Tobin Ehlis4af23302016-07-19 10:50:30 -060012979
12980 VkRenderPass rp;
12981 VkResult err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
12982 ASSERT_VK_SUCCESS(err);
12983
12984 // A compatible framebuffer.
12985 VkImageObj image(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012986 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 -060012987 ASSERT_TRUE(image.initialized());
12988
12989 VkImageViewCreateInfo ivci = {
12990 VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO,
12991 nullptr,
12992 0,
12993 image.handle(),
12994 VK_IMAGE_VIEW_TYPE_2D,
12995 VK_FORMAT_B8G8R8A8_UNORM,
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012996 {VK_COMPONENT_SWIZZLE_IDENTITY, VK_COMPONENT_SWIZZLE_IDENTITY, VK_COMPONENT_SWIZZLE_IDENTITY,
12997 VK_COMPONENT_SWIZZLE_IDENTITY},
Tobin Ehlis4af23302016-07-19 10:50:30 -060012998 {VK_IMAGE_ASPECT_COLOR_BIT, 0, 1, 0, 1},
12999 };
13000 VkImageView view;
13001 err = vkCreateImageView(m_device->device(), &ivci, nullptr, &view);
13002 ASSERT_VK_SUCCESS(err);
13003
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013004 VkFramebufferCreateInfo fci = {VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr, 0, rp, 1, &view, 32, 32, 1};
Tobin Ehlis4af23302016-07-19 10:50:30 -060013005 VkFramebuffer fb;
13006 err = vkCreateFramebuffer(m_device->device(), &fci, nullptr, &fb);
13007 ASSERT_VK_SUCCESS(err);
13008
13009 VkCommandBufferAllocateInfo cbai = {};
13010 cbai.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
13011 cbai.commandPool = m_commandPool;
13012 cbai.level = VK_COMMAND_BUFFER_LEVEL_SECONDARY;
13013 cbai.commandBufferCount = 1;
13014
13015 VkCommandBuffer sec_cb;
13016 err = vkAllocateCommandBuffers(m_device->device(), &cbai, &sec_cb);
13017 ASSERT_VK_SUCCESS(err);
13018 VkCommandBufferBeginInfo cbbi = {};
13019 VkCommandBufferInheritanceInfo cbii = {};
13020 cbii.renderPass = renderPass();
13021 cbii.framebuffer = fb;
13022 cbbi.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
13023 cbbi.pNext = NULL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013024 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 -060013025 cbbi.pInheritanceInfo = &cbii;
13026 vkBeginCommandBuffer(sec_cb, &cbbi);
13027 vkEndCommandBuffer(sec_cb);
13028
Chris Forbes3400bc52016-09-13 18:10:34 +120013029 VkCommandBufferBeginInfo cbbi2 = {
13030 VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO, nullptr,
13031 0, nullptr
13032 };
13033 vkBeginCommandBuffer(m_commandBuffer->GetBufferHandle(), &cbbi2);
13034 vkCmdBeginRenderPass(m_commandBuffer->GetBufferHandle(), &m_renderPassBeginInfo, VK_SUBPASS_CONTENTS_SECONDARY_COMMAND_BUFFERS);
Tobin Ehlis4af23302016-07-19 10:50:30 -060013035
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013036 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
13037 " that is not the same as the primaryCB's current active framebuffer ");
Tobin Ehlis4af23302016-07-19 10:50:30 -060013038 vkCmdExecuteCommands(m_commandBuffer->GetBufferHandle(), 1, &sec_cb);
13039 m_errorMonitor->VerifyFound();
13040 // Cleanup
13041 vkDestroyImageView(m_device->device(), view, NULL);
13042 vkDestroyRenderPass(m_device->device(), rp, NULL);
13043 vkDestroyFramebuffer(m_device->device(), fb, NULL);
13044}
Tobin Ehlis52b504f2016-07-19 13:25:12 -060013045
13046TEST_F(VkLayerTest, ColorBlendLogicOpTests) {
13047 TEST_DESCRIPTION("If logicOp is available on the device, set it to an "
13048 "invalid value. If logicOp is not available, attempt to "
13049 "use it and verify that we see the correct error.");
13050 ASSERT_NO_FATAL_FAILURE(InitState());
13051 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13052
13053 auto features = m_device->phy().features();
13054 // Set the expected error depending on whether or not logicOp available
13055 if (VK_FALSE == features.logicOp) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013056 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "If logic operations feature not "
13057 "enabled, logicOpEnable must be "
13058 "VK_FALSE");
Tobin Ehlis52b504f2016-07-19 13:25:12 -060013059 } else {
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013060 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, ", logicOp must be a valid VkLogicOp value");
Tobin Ehlis52b504f2016-07-19 13:25:12 -060013061 }
13062 // Create a pipeline using logicOp
13063 VkResult err;
13064
13065 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
13066 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
13067
13068 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013069 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis52b504f2016-07-19 13:25:12 -060013070 ASSERT_VK_SUCCESS(err);
13071
13072 VkPipelineViewportStateCreateInfo vp_state_ci = {};
13073 vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
13074 vp_state_ci.viewportCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013075 VkViewport vp = {}; // Just need dummy vp to point to
Tobin Ehlis52b504f2016-07-19 13:25:12 -060013076 vp_state_ci.pViewports = &vp;
13077 vp_state_ci.scissorCount = 1;
13078 VkRect2D scissors = {}; // Dummy scissors to point to
13079 vp_state_ci.pScissors = &scissors;
13080 // No dynamic state
13081 VkPipelineDynamicStateCreateInfo dyn_state_ci = {};
13082 dyn_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_DYNAMIC_STATE_CREATE_INFO;
13083
13084 VkPipelineShaderStageCreateInfo shaderStages[2];
13085 memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo));
13086
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013087 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
13088 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Tobin Ehlis52b504f2016-07-19 13:25:12 -060013089 shaderStages[0] = vs.GetStageCreateInfo();
13090 shaderStages[1] = fs.GetStageCreateInfo();
13091
13092 VkPipelineVertexInputStateCreateInfo vi_ci = {};
13093 vi_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
13094
13095 VkPipelineInputAssemblyStateCreateInfo ia_ci = {};
13096 ia_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
13097 ia_ci.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP;
13098
13099 VkPipelineRasterizationStateCreateInfo rs_ci = {};
13100 rs_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
13101
13102 VkPipelineColorBlendAttachmentState att = {};
13103 att.blendEnable = VK_FALSE;
13104 att.colorWriteMask = 0xf;
13105
13106 VkPipelineColorBlendStateCreateInfo cb_ci = {};
13107 cb_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO;
13108 // Enable logicOp & set logicOp to value 1 beyond allowed entries
13109 cb_ci.logicOpEnable = VK_TRUE;
13110 cb_ci.logicOp = VK_LOGIC_OP_RANGE_SIZE; // This should cause an error
13111 cb_ci.attachmentCount = 1;
13112 cb_ci.pAttachments = &att;
13113
13114 VkGraphicsPipelineCreateInfo gp_ci = {};
13115 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
13116 gp_ci.stageCount = 2;
13117 gp_ci.pStages = shaderStages;
13118 gp_ci.pVertexInputState = &vi_ci;
13119 gp_ci.pInputAssemblyState = &ia_ci;
13120 gp_ci.pViewportState = &vp_state_ci;
13121 gp_ci.pRasterizationState = &rs_ci;
13122 gp_ci.pColorBlendState = &cb_ci;
13123 gp_ci.pDynamicState = &dyn_state_ci;
13124 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
13125 gp_ci.layout = pipeline_layout;
13126 gp_ci.renderPass = renderPass();
13127
13128 VkPipelineCacheCreateInfo pc_ci = {};
13129 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
13130
13131 VkPipeline pipeline;
13132 VkPipelineCache pipelineCache;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013133 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Tobin Ehlis52b504f2016-07-19 13:25:12 -060013134 ASSERT_VK_SUCCESS(err);
13135
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013136 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Tobin Ehlis52b504f2016-07-19 13:25:12 -060013137 m_errorMonitor->VerifyFound();
13138 if (VK_SUCCESS == err) {
13139 vkDestroyPipeline(m_device->device(), pipeline, NULL);
13140 }
13141 m_errorMonitor->VerifyFound();
13142 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
13143 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
13144}
Mark Lobodzinski209b5292015-09-17 09:44:05 -060013145#endif // DRAW_STATE_TESTS
13146
Tobin Ehlis0788f522015-05-26 16:11:58 -060013147#if THREADING_TESTS
Mike Stroyanaccf7692015-05-12 16:00:45 -060013148#if GTEST_IS_THREADSAFE
13149struct thread_data_struct {
Chia-I Wu3432a0c2015-10-27 18:04:07 +080013150 VkCommandBuffer commandBuffer;
Mike Stroyanaccf7692015-05-12 16:00:45 -060013151 VkEvent event;
13152 bool bailout;
13153};
13154
Karl Schultz6addd812016-02-02 17:17:23 -070013155extern "C" void *AddToCommandBuffer(void *arg) {
13156 struct thread_data_struct *data = (struct thread_data_struct *)arg;
Mike Stroyanaccf7692015-05-12 16:00:45 -060013157
Mike Stroyana6d14942016-07-13 15:10:05 -060013158 for (int i = 0; i < 80000; i++) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013159 vkCmdSetEvent(data->commandBuffer, data->event, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT);
Mike Stroyanaccf7692015-05-12 16:00:45 -060013160 if (data->bailout) {
13161 break;
13162 }
13163 }
13164 return NULL;
13165}
13166
Karl Schultz6addd812016-02-02 17:17:23 -070013167TEST_F(VkLayerTest, ThreadCommandBufferCollision) {
Mike Stroyan4268d1f2015-07-13 14:45:35 -060013168 test_platform_thread thread;
Mike Stroyanaccf7692015-05-12 16:00:45 -060013169
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013170 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "THREADING ERROR");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060013171
Mike Stroyanaccf7692015-05-12 16:00:45 -060013172 ASSERT_NO_FATAL_FAILURE(InitState());
13173 ASSERT_NO_FATAL_FAILURE(InitViewport());
13174 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13175
Chia-I Wu3432a0c2015-10-27 18:04:07 +080013176 // Calls AllocateCommandBuffers
13177 VkCommandBufferObj commandBuffer(m_device, m_commandPool);
Mark Lobodzinski5495d132015-09-30 16:19:16 -060013178
13179 // Avoid creating RenderPass
Chia-I Wu3432a0c2015-10-27 18:04:07 +080013180 commandBuffer.BeginCommandBuffer();
Mike Stroyanaccf7692015-05-12 16:00:45 -060013181
13182 VkEventCreateInfo event_info;
13183 VkEvent event;
Mike Stroyanaccf7692015-05-12 16:00:45 -060013184 VkResult err;
13185
13186 memset(&event_info, 0, sizeof(event_info));
13187 event_info.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO;
13188
Chia-I Wuf7458c52015-10-26 21:10:41 +080013189 err = vkCreateEvent(device(), &event_info, NULL, &event);
Mike Stroyanaccf7692015-05-12 16:00:45 -060013190 ASSERT_VK_SUCCESS(err);
13191
Mike Stroyanaccf7692015-05-12 16:00:45 -060013192 err = vkResetEvent(device(), event);
13193 ASSERT_VK_SUCCESS(err);
13194
13195 struct thread_data_struct data;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080013196 data.commandBuffer = commandBuffer.GetBufferHandle();
Mike Stroyanaccf7692015-05-12 16:00:45 -060013197 data.event = event;
13198 data.bailout = false;
13199 m_errorMonitor->SetBailout(&data.bailout);
Mike Stroyana6d14942016-07-13 15:10:05 -060013200
13201 // First do some correct operations using multiple threads.
13202 // Add many entries to command buffer from another thread.
13203 test_platform_thread_create(&thread, AddToCommandBuffer, (void *)&data);
13204 // Make non-conflicting calls from this thread at the same time.
13205 for (int i = 0; i < 80000; i++) {
Mike Stroyand6343902016-07-14 08:56:16 -060013206 uint32_t count;
13207 vkEnumeratePhysicalDevices(instance(), &count, NULL);
Mike Stroyana6d14942016-07-13 15:10:05 -060013208 }
13209 test_platform_thread_join(thread, NULL);
13210
13211 // Then do some incorrect operations using multiple threads.
Mike Stroyanaccf7692015-05-12 16:00:45 -060013212 // Add many entries to command buffer from another thread.
Mike Stroyan4268d1f2015-07-13 14:45:35 -060013213 test_platform_thread_create(&thread, AddToCommandBuffer, (void *)&data);
Mike Stroyanaccf7692015-05-12 16:00:45 -060013214 // Add many entries to command buffer from this thread at the same time.
13215 AddToCommandBuffer(&data);
Mark Lobodzinski5495d132015-09-30 16:19:16 -060013216
Mike Stroyan4268d1f2015-07-13 14:45:35 -060013217 test_platform_thread_join(thread, NULL);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080013218 commandBuffer.EndCommandBuffer();
Mike Stroyanaccf7692015-05-12 16:00:45 -060013219
Mike Stroyan10b8cb72016-01-22 15:22:03 -070013220 m_errorMonitor->SetBailout(NULL);
13221
Chris Forbes8f36a8a2016-04-07 13:21:07 +120013222 m_errorMonitor->VerifyFound();
Mike Stroyanaccf7692015-05-12 16:00:45 -060013223
Chia-I Wuf7458c52015-10-26 21:10:41 +080013224 vkDestroyEvent(device(), event, NULL);
Mike Stroyanaccf7692015-05-12 16:00:45 -060013225}
Mark Lobodzinski209b5292015-09-17 09:44:05 -060013226#endif // GTEST_IS_THREADSAFE
13227#endif // THREADING_TESTS
13228
Chris Forbes9f7ff632015-05-25 11:13:08 +120013229#if SHADER_CHECKER_TESTS
Karl Schultz6addd812016-02-02 17:17:23 -070013230TEST_F(VkLayerTest, InvalidSPIRVCodeSize) {
Chris Forbes1cc79542016-07-20 11:13:44 +120013231 TEST_DESCRIPTION("Test that an error is produced for a spirv module "
13232 "with an impossible code size");
13233
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013234 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Invalid SPIR-V header");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060013235
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060013236 ASSERT_NO_FATAL_FAILURE(InitState());
13237 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13238
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060013239 VkShaderModule module;
13240 VkShaderModuleCreateInfo moduleCreateInfo;
13241 struct icd_spv_header spv;
13242
13243 spv.magic = ICD_SPV_MAGIC;
13244 spv.version = ICD_SPV_VERSION;
13245 spv.gen_magic = 0;
13246
13247 moduleCreateInfo.sType = VK_STRUCTURE_TYPE_SHADER_MODULE_CREATE_INFO;
13248 moduleCreateInfo.pNext = NULL;
Karl Schultz6addd812016-02-02 17:17:23 -070013249 moduleCreateInfo.pCode = (const uint32_t *)&spv;
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060013250 moduleCreateInfo.codeSize = 4;
13251 moduleCreateInfo.flags = 0;
Chia-I Wuf7458c52015-10-26 21:10:41 +080013252 vkCreateShaderModule(m_device->device(), &moduleCreateInfo, NULL, &module);
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060013253
Chris Forbes8f36a8a2016-04-07 13:21:07 +120013254 m_errorMonitor->VerifyFound();
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060013255}
13256
Karl Schultz6addd812016-02-02 17:17:23 -070013257TEST_F(VkLayerTest, InvalidSPIRVMagic) {
Chris Forbes1cc79542016-07-20 11:13:44 +120013258 TEST_DESCRIPTION("Test that an error is produced for a spirv module "
13259 "with a bad magic number");
13260
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013261 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Invalid SPIR-V magic number");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060013262
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060013263 ASSERT_NO_FATAL_FAILURE(InitState());
13264 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13265
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060013266 VkShaderModule module;
13267 VkShaderModuleCreateInfo moduleCreateInfo;
13268 struct icd_spv_header spv;
13269
13270 spv.magic = ~ICD_SPV_MAGIC;
13271 spv.version = ICD_SPV_VERSION;
13272 spv.gen_magic = 0;
13273
13274 moduleCreateInfo.sType = VK_STRUCTURE_TYPE_SHADER_MODULE_CREATE_INFO;
13275 moduleCreateInfo.pNext = NULL;
Karl Schultz6addd812016-02-02 17:17:23 -070013276 moduleCreateInfo.pCode = (const uint32_t *)&spv;
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060013277 moduleCreateInfo.codeSize = sizeof(spv) + 10;
13278 moduleCreateInfo.flags = 0;
Chia-I Wuf7458c52015-10-26 21:10:41 +080013279 vkCreateShaderModule(m_device->device(), &moduleCreateInfo, NULL, &module);
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060013280
Chris Forbes8f36a8a2016-04-07 13:21:07 +120013281 m_errorMonitor->VerifyFound();
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060013282}
13283
Chris Forbesb4afd0f2016-04-04 10:48:35 +120013284#if 0
13285// Not currently covered by SPIRV-Tools validator
Karl Schultz6addd812016-02-02 17:17:23 -070013286TEST_F(VkLayerTest, InvalidSPIRVVersion) {
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -070013287 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Chris Forbesb4afd0f2016-04-04 10:48:35 +120013288 "Invalid SPIR-V header");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060013289
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060013290 ASSERT_NO_FATAL_FAILURE(InitState());
13291 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13292
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060013293 VkShaderModule module;
13294 VkShaderModuleCreateInfo moduleCreateInfo;
13295 struct icd_spv_header spv;
13296
13297 spv.magic = ICD_SPV_MAGIC;
13298 spv.version = ~ICD_SPV_VERSION;
13299 spv.gen_magic = 0;
13300
13301 moduleCreateInfo.sType = VK_STRUCTURE_TYPE_SHADER_MODULE_CREATE_INFO;
13302 moduleCreateInfo.pNext = NULL;
13303
Karl Schultz6addd812016-02-02 17:17:23 -070013304 moduleCreateInfo.pCode = (const uint32_t *)&spv;
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060013305 moduleCreateInfo.codeSize = sizeof(spv) + 10;
13306 moduleCreateInfo.flags = 0;
Chia-I Wuf7458c52015-10-26 21:10:41 +080013307 vkCreateShaderModule(m_device->device(), &moduleCreateInfo, NULL, &module);
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060013308
Chris Forbes8f36a8a2016-04-07 13:21:07 +120013309 m_errorMonitor->VerifyFound();
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060013310}
Chris Forbesb4afd0f2016-04-04 10:48:35 +120013311#endif
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060013312
Karl Schultz6addd812016-02-02 17:17:23 -070013313TEST_F(VkLayerTest, CreatePipelineVertexOutputNotConsumed) {
Chris Forbes1cc79542016-07-20 11:13:44 +120013314 TEST_DESCRIPTION("Test that a warning is produced for a vertex output that "
13315 "is not consumed by the fragment stage");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013316 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT, "not consumed by fragment shader");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060013317
Chris Forbes9f7ff632015-05-25 11:13:08 +120013318 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -060013319 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbes9f7ff632015-05-25 11:13:08 +120013320
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013321 char const *vsSource = "#version 450\n"
13322 "\n"
13323 "layout(location=0) out float x;\n"
13324 "out gl_PerVertex {\n"
13325 " vec4 gl_Position;\n"
13326 "};\n"
13327 "void main(){\n"
13328 " gl_Position = vec4(1);\n"
13329 " x = 0;\n"
13330 "}\n";
13331 char const *fsSource = "#version 450\n"
13332 "\n"
13333 "layout(location=0) out vec4 color;\n"
13334 "void main(){\n"
13335 " color = vec4(1);\n"
13336 "}\n";
Chris Forbes9f7ff632015-05-25 11:13:08 +120013337
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060013338 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13339 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbes9f7ff632015-05-25 11:13:08 +120013340
13341 VkPipelineObj pipe(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +080013342 pipe.AddColorAttachment();
Chris Forbes9f7ff632015-05-25 11:13:08 +120013343 pipe.AddShader(&vs);
13344 pipe.AddShader(&fs);
13345
Chris Forbes9f7ff632015-05-25 11:13:08 +120013346 VkDescriptorSetObj descriptorSet(m_device);
13347 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080013348 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbes9f7ff632015-05-25 11:13:08 +120013349
Tony Barbour5781e8f2015-08-04 16:23:11 -060013350 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbes9f7ff632015-05-25 11:13:08 +120013351
Chris Forbes8f36a8a2016-04-07 13:21:07 +120013352 m_errorMonitor->VerifyFound();
Chris Forbes9f7ff632015-05-25 11:13:08 +120013353}
Chris Forbes9f7ff632015-05-25 11:13:08 +120013354
Karl Schultz6addd812016-02-02 17:17:23 -070013355TEST_F(VkLayerTest, CreatePipelineFragmentInputNotProvided) {
Chris Forbes1cc79542016-07-20 11:13:44 +120013356 TEST_DESCRIPTION("Test that an error is produced for a fragment shader input "
13357 "which is not present in the outputs of the previous stage");
13358
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013359 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "not written by vertex shader");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060013360
Chris Forbes59cb88d2015-05-25 11:13:13 +120013361 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -060013362 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbes59cb88d2015-05-25 11:13:13 +120013363
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013364 char const *vsSource = "#version 450\n"
13365 "\n"
13366 "out gl_PerVertex {\n"
13367 " vec4 gl_Position;\n"
13368 "};\n"
13369 "void main(){\n"
13370 " gl_Position = vec4(1);\n"
13371 "}\n";
13372 char const *fsSource = "#version 450\n"
13373 "\n"
13374 "layout(location=0) in float x;\n"
13375 "layout(location=0) out vec4 color;\n"
13376 "void main(){\n"
13377 " color = vec4(x);\n"
13378 "}\n";
Chris Forbes59cb88d2015-05-25 11:13:13 +120013379
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060013380 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13381 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbes59cb88d2015-05-25 11:13:13 +120013382
13383 VkPipelineObj pipe(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +080013384 pipe.AddColorAttachment();
Chris Forbes59cb88d2015-05-25 11:13:13 +120013385 pipe.AddShader(&vs);
13386 pipe.AddShader(&fs);
13387
Chris Forbes59cb88d2015-05-25 11:13:13 +120013388 VkDescriptorSetObj descriptorSet(m_device);
13389 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080013390 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbes59cb88d2015-05-25 11:13:13 +120013391
Tony Barbour5781e8f2015-08-04 16:23:11 -060013392 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbes59cb88d2015-05-25 11:13:13 +120013393
Chris Forbes8f36a8a2016-04-07 13:21:07 +120013394 m_errorMonitor->VerifyFound();
Chris Forbes59cb88d2015-05-25 11:13:13 +120013395}
13396
Karl Schultz6addd812016-02-02 17:17:23 -070013397TEST_F(VkLayerTest, CreatePipelineFragmentInputNotProvidedInBlock) {
Chris Forbes1cc79542016-07-20 11:13:44 +120013398 TEST_DESCRIPTION("Test that an error is produced for a fragment shader input "
13399 "within an interace block, which is not present in the outputs "
13400 "of the previous stage.");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013401 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "not written by vertex shader");
Chris Forbesa3e85f62016-01-15 14:53:11 +130013402
13403 ASSERT_NO_FATAL_FAILURE(InitState());
13404 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13405
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013406 char const *vsSource = "#version 450\n"
13407 "\n"
13408 "out gl_PerVertex {\n"
13409 " vec4 gl_Position;\n"
13410 "};\n"
13411 "void main(){\n"
13412 " gl_Position = vec4(1);\n"
13413 "}\n";
13414 char const *fsSource = "#version 450\n"
13415 "\n"
13416 "in block { layout(location=0) float x; } ins;\n"
13417 "layout(location=0) out vec4 color;\n"
13418 "void main(){\n"
13419 " color = vec4(ins.x);\n"
13420 "}\n";
Chris Forbesa3e85f62016-01-15 14:53:11 +130013421
13422 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13423 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
13424
13425 VkPipelineObj pipe(m_device);
13426 pipe.AddColorAttachment();
13427 pipe.AddShader(&vs);
13428 pipe.AddShader(&fs);
13429
13430 VkDescriptorSetObj descriptorSet(m_device);
13431 descriptorSet.AppendDummy();
13432 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
13433
13434 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
13435
Chris Forbes8f36a8a2016-04-07 13:21:07 +120013436 m_errorMonitor->VerifyFound();
Chris Forbesa3e85f62016-01-15 14:53:11 +130013437}
13438
Karl Schultz6addd812016-02-02 17:17:23 -070013439TEST_F(VkLayerTest, CreatePipelineVsFsTypeMismatchArraySize) {
Chris Forbes1cc79542016-07-20 11:13:44 +120013440 TEST_DESCRIPTION("Test that an error is produced for mismatched array sizes "
13441 "across the VS->FS interface");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013442 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Type mismatch on location 0.0: 'ptr to "
13443 "output arr[2] of float32' vs 'ptr to "
13444 "input arr[3] of float32'");
Chris Forbes0036fd12016-01-26 14:19:49 +130013445
13446 ASSERT_NO_FATAL_FAILURE(InitState());
13447 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13448
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013449 char const *vsSource = "#version 450\n"
13450 "\n"
13451 "layout(location=0) out float x[2];\n"
13452 "out gl_PerVertex {\n"
13453 " vec4 gl_Position;\n"
13454 "};\n"
13455 "void main(){\n"
13456 " x[0] = 0; x[1] = 0;\n"
13457 " gl_Position = vec4(1);\n"
13458 "}\n";
13459 char const *fsSource = "#version 450\n"
13460 "\n"
13461 "layout(location=0) in float x[3];\n"
13462 "layout(location=0) out vec4 color;\n"
13463 "void main(){\n"
13464 " color = vec4(x[0] + x[1] + x[2]);\n"
13465 "}\n";
Chris Forbes0036fd12016-01-26 14:19:49 +130013466
13467 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13468 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
13469
13470 VkPipelineObj pipe(m_device);
13471 pipe.AddColorAttachment();
13472 pipe.AddShader(&vs);
13473 pipe.AddShader(&fs);
13474
13475 VkDescriptorSetObj descriptorSet(m_device);
13476 descriptorSet.AppendDummy();
13477 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
13478
13479 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
13480
Chris Forbes8f36a8a2016-04-07 13:21:07 +120013481 m_errorMonitor->VerifyFound();
Chris Forbes0036fd12016-01-26 14:19:49 +130013482}
13483
Karl Schultz6addd812016-02-02 17:17:23 -070013484TEST_F(VkLayerTest, CreatePipelineVsFsTypeMismatch) {
Chris Forbes1cc79542016-07-20 11:13:44 +120013485 TEST_DESCRIPTION("Test that an error is produced for mismatched types across "
13486 "the VS->FS interface");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013487 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Type mismatch on location 0");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060013488
Chris Forbesb56af562015-05-25 11:13:17 +120013489 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -060013490 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbesb56af562015-05-25 11:13:17 +120013491
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013492 char const *vsSource = "#version 450\n"
13493 "\n"
13494 "layout(location=0) out int x;\n"
13495 "out gl_PerVertex {\n"
13496 " vec4 gl_Position;\n"
13497 "};\n"
13498 "void main(){\n"
13499 " x = 0;\n"
13500 " gl_Position = vec4(1);\n"
13501 "}\n";
13502 char const *fsSource = "#version 450\n"
13503 "\n"
13504 "layout(location=0) in float x;\n" /* VS writes int */
13505 "layout(location=0) out vec4 color;\n"
13506 "void main(){\n"
13507 " color = vec4(x);\n"
13508 "}\n";
Chris Forbesb56af562015-05-25 11:13:17 +120013509
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060013510 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13511 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbesb56af562015-05-25 11:13:17 +120013512
13513 VkPipelineObj pipe(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +080013514 pipe.AddColorAttachment();
Chris Forbesb56af562015-05-25 11:13:17 +120013515 pipe.AddShader(&vs);
13516 pipe.AddShader(&fs);
13517
Chris Forbesb56af562015-05-25 11:13:17 +120013518 VkDescriptorSetObj descriptorSet(m_device);
13519 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080013520 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbesb56af562015-05-25 11:13:17 +120013521
Tony Barbour5781e8f2015-08-04 16:23:11 -060013522 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbesb56af562015-05-25 11:13:17 +120013523
Chris Forbes8f36a8a2016-04-07 13:21:07 +120013524 m_errorMonitor->VerifyFound();
Chris Forbesb56af562015-05-25 11:13:17 +120013525}
13526
Karl Schultz6addd812016-02-02 17:17:23 -070013527TEST_F(VkLayerTest, CreatePipelineVsFsTypeMismatchInBlock) {
Chris Forbes1cc79542016-07-20 11:13:44 +120013528 TEST_DESCRIPTION("Test that an error is produced for mismatched types across "
13529 "the VS->FS interface, when the variable is contained within "
13530 "an interface block");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013531 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Type mismatch on location 0");
Chris Forbesa3e85f62016-01-15 14:53:11 +130013532
13533 ASSERT_NO_FATAL_FAILURE(InitState());
13534 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13535
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013536 char const *vsSource = "#version 450\n"
13537 "\n"
13538 "out block { layout(location=0) int x; } outs;\n"
13539 "out gl_PerVertex {\n"
13540 " vec4 gl_Position;\n"
13541 "};\n"
13542 "void main(){\n"
13543 " outs.x = 0;\n"
13544 " gl_Position = vec4(1);\n"
13545 "}\n";
13546 char const *fsSource = "#version 450\n"
13547 "\n"
13548 "in block { layout(location=0) float x; } ins;\n" /* VS writes int */
13549 "layout(location=0) out vec4 color;\n"
13550 "void main(){\n"
13551 " color = vec4(ins.x);\n"
13552 "}\n";
Chris Forbesa3e85f62016-01-15 14:53:11 +130013553
13554 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13555 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
13556
13557 VkPipelineObj pipe(m_device);
13558 pipe.AddColorAttachment();
13559 pipe.AddShader(&vs);
13560 pipe.AddShader(&fs);
13561
13562 VkDescriptorSetObj descriptorSet(m_device);
13563 descriptorSet.AppendDummy();
13564 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
13565
13566 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
13567
Chris Forbes8f36a8a2016-04-07 13:21:07 +120013568 m_errorMonitor->VerifyFound();
Chris Forbese9928822016-02-17 14:44:52 +130013569}
13570
13571TEST_F(VkLayerTest, CreatePipelineVsFsMismatchByLocation) {
Chris Forbes1cc79542016-07-20 11:13:44 +120013572 TEST_DESCRIPTION("Test that an error is produced for location mismatches across "
13573 "the VS->FS interface; This should manifest as a not-written/not-consumed "
13574 "pair, but flushes out broken walking of the interfaces");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013575 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 +130013576
13577 ASSERT_NO_FATAL_FAILURE(InitState());
13578 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13579
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013580 char const *vsSource = "#version 450\n"
13581 "\n"
13582 "out block { layout(location=1) float x; } outs;\n"
13583 "out gl_PerVertex {\n"
13584 " vec4 gl_Position;\n"
13585 "};\n"
13586 "void main(){\n"
13587 " outs.x = 0;\n"
13588 " gl_Position = vec4(1);\n"
13589 "}\n";
13590 char const *fsSource = "#version 450\n"
13591 "\n"
13592 "in block { layout(location=0) float x; } ins;\n"
13593 "layout(location=0) out vec4 color;\n"
13594 "void main(){\n"
13595 " color = vec4(ins.x);\n"
13596 "}\n";
Chris Forbese9928822016-02-17 14:44:52 +130013597
13598 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13599 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
13600
13601 VkPipelineObj pipe(m_device);
13602 pipe.AddColorAttachment();
13603 pipe.AddShader(&vs);
13604 pipe.AddShader(&fs);
13605
13606 VkDescriptorSetObj descriptorSet(m_device);
13607 descriptorSet.AppendDummy();
13608 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
13609
13610 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
13611
Chris Forbes8f36a8a2016-04-07 13:21:07 +120013612 m_errorMonitor->VerifyFound();
Chris Forbese9928822016-02-17 14:44:52 +130013613}
13614
13615TEST_F(VkLayerTest, CreatePipelineVsFsMismatchByComponent) {
Chris Forbes1cc79542016-07-20 11:13:44 +120013616 TEST_DESCRIPTION("Test that an error is produced for component mismatches across the "
13617 "VS->FS interface. It's not enough to have the same set of locations in "
13618 "use; matching is defined in terms of spirv variables.");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013619 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 +130013620
13621 ASSERT_NO_FATAL_FAILURE(InitState());
13622 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13623
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013624 char const *vsSource = "#version 450\n"
13625 "\n"
13626 "out block { layout(location=0, component=0) float x; } outs;\n"
13627 "out gl_PerVertex {\n"
13628 " vec4 gl_Position;\n"
13629 "};\n"
13630 "void main(){\n"
13631 " outs.x = 0;\n"
13632 " gl_Position = vec4(1);\n"
13633 "}\n";
13634 char const *fsSource = "#version 450\n"
13635 "\n"
13636 "in block { layout(location=0, component=1) float x; } ins;\n"
13637 "layout(location=0) out vec4 color;\n"
13638 "void main(){\n"
13639 " color = vec4(ins.x);\n"
13640 "}\n";
Chris Forbese9928822016-02-17 14:44:52 +130013641
13642 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13643 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
13644
13645 VkPipelineObj pipe(m_device);
13646 pipe.AddColorAttachment();
13647 pipe.AddShader(&vs);
13648 pipe.AddShader(&fs);
13649
13650 VkDescriptorSetObj descriptorSet(m_device);
13651 descriptorSet.AppendDummy();
13652 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
13653
13654 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
13655
Chris Forbes8f36a8a2016-04-07 13:21:07 +120013656 m_errorMonitor->VerifyFound();
Chris Forbesa3e85f62016-01-15 14:53:11 +130013657}
13658
Karl Schultz6addd812016-02-02 17:17:23 -070013659TEST_F(VkLayerTest, CreatePipelineAttribNotConsumed) {
Chris Forbes1cc79542016-07-20 11:13:44 +120013660 TEST_DESCRIPTION("Test that a warning is produced for a vertex attribute which is "
13661 "not consumed by the vertex shader");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013662 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT, "location 0 not consumed by VS");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060013663
Chris Forbesde136e02015-05-25 11:13:28 +120013664 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -060013665 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbesde136e02015-05-25 11:13:28 +120013666
13667 VkVertexInputBindingDescription input_binding;
13668 memset(&input_binding, 0, sizeof(input_binding));
13669
13670 VkVertexInputAttributeDescription input_attrib;
13671 memset(&input_attrib, 0, sizeof(input_attrib));
13672 input_attrib.format = VK_FORMAT_R32_SFLOAT;
13673
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013674 char const *vsSource = "#version 450\n"
13675 "\n"
13676 "out gl_PerVertex {\n"
13677 " vec4 gl_Position;\n"
13678 "};\n"
13679 "void main(){\n"
13680 " gl_Position = vec4(1);\n"
13681 "}\n";
13682 char const *fsSource = "#version 450\n"
13683 "\n"
13684 "layout(location=0) out vec4 color;\n"
13685 "void main(){\n"
13686 " color = vec4(1);\n"
13687 "}\n";
Chris Forbesde136e02015-05-25 11:13:28 +120013688
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060013689 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13690 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbesde136e02015-05-25 11:13:28 +120013691
13692 VkPipelineObj pipe(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +080013693 pipe.AddColorAttachment();
Chris Forbesde136e02015-05-25 11:13:28 +120013694 pipe.AddShader(&vs);
13695 pipe.AddShader(&fs);
13696
13697 pipe.AddVertexInputBindings(&input_binding, 1);
13698 pipe.AddVertexInputAttribs(&input_attrib, 1);
13699
Chris Forbesde136e02015-05-25 11:13:28 +120013700 VkDescriptorSetObj descriptorSet(m_device);
13701 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080013702 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbesde136e02015-05-25 11:13:28 +120013703
Tony Barbour5781e8f2015-08-04 16:23:11 -060013704 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbesde136e02015-05-25 11:13:28 +120013705
Chris Forbes8f36a8a2016-04-07 13:21:07 +120013706 m_errorMonitor->VerifyFound();
Chris Forbesde136e02015-05-25 11:13:28 +120013707}
13708
Karl Schultz6addd812016-02-02 17:17:23 -070013709TEST_F(VkLayerTest, CreatePipelineAttribLocationMismatch) {
Chris Forbes1cc79542016-07-20 11:13:44 +120013710 TEST_DESCRIPTION("Test that a warning is produced for a location mismatch on "
13711 "vertex attributes. This flushes out bad behavior in the interface walker");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013712 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT, "location 0 not consumed by VS");
Chris Forbes7d83cd52016-01-15 11:32:03 +130013713
13714 ASSERT_NO_FATAL_FAILURE(InitState());
13715 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13716
13717 VkVertexInputBindingDescription input_binding;
13718 memset(&input_binding, 0, sizeof(input_binding));
13719
13720 VkVertexInputAttributeDescription input_attrib;
13721 memset(&input_attrib, 0, sizeof(input_attrib));
13722 input_attrib.format = VK_FORMAT_R32_SFLOAT;
13723
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013724 char const *vsSource = "#version 450\n"
13725 "\n"
13726 "layout(location=1) in float x;\n"
13727 "out gl_PerVertex {\n"
13728 " vec4 gl_Position;\n"
13729 "};\n"
13730 "void main(){\n"
13731 " gl_Position = vec4(x);\n"
13732 "}\n";
13733 char const *fsSource = "#version 450\n"
13734 "\n"
13735 "layout(location=0) out vec4 color;\n"
13736 "void main(){\n"
13737 " color = vec4(1);\n"
13738 "}\n";
Chris Forbes7d83cd52016-01-15 11:32:03 +130013739
13740 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13741 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
13742
13743 VkPipelineObj pipe(m_device);
13744 pipe.AddColorAttachment();
13745 pipe.AddShader(&vs);
13746 pipe.AddShader(&fs);
13747
13748 pipe.AddVertexInputBindings(&input_binding, 1);
13749 pipe.AddVertexInputAttribs(&input_attrib, 1);
13750
13751 VkDescriptorSetObj descriptorSet(m_device);
13752 descriptorSet.AppendDummy();
13753 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
13754
13755 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
13756
Chris Forbes8f36a8a2016-04-07 13:21:07 +120013757 m_errorMonitor->VerifyFound();
Chris Forbes7d83cd52016-01-15 11:32:03 +130013758}
13759
Karl Schultz6addd812016-02-02 17:17:23 -070013760TEST_F(VkLayerTest, CreatePipelineAttribNotProvided) {
Chris Forbes1cc79542016-07-20 11:13:44 +120013761 TEST_DESCRIPTION("Test that an error is produced for a VS input which is not "
13762 "provided by a vertex attribute");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013763 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 -060013764
Chris Forbes62e8e502015-05-25 11:13:29 +120013765 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -060013766 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbes62e8e502015-05-25 11:13:29 +120013767
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013768 char const *vsSource = "#version 450\n"
13769 "\n"
13770 "layout(location=0) in vec4 x;\n" /* not provided */
13771 "out gl_PerVertex {\n"
13772 " vec4 gl_Position;\n"
13773 "};\n"
13774 "void main(){\n"
13775 " gl_Position = x;\n"
13776 "}\n";
13777 char const *fsSource = "#version 450\n"
13778 "\n"
13779 "layout(location=0) out vec4 color;\n"
13780 "void main(){\n"
13781 " color = vec4(1);\n"
13782 "}\n";
Chris Forbes62e8e502015-05-25 11:13:29 +120013783
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060013784 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13785 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbes62e8e502015-05-25 11:13:29 +120013786
13787 VkPipelineObj pipe(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +080013788 pipe.AddColorAttachment();
Chris Forbes62e8e502015-05-25 11:13:29 +120013789 pipe.AddShader(&vs);
13790 pipe.AddShader(&fs);
13791
Chris Forbes62e8e502015-05-25 11:13:29 +120013792 VkDescriptorSetObj descriptorSet(m_device);
13793 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080013794 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbes62e8e502015-05-25 11:13:29 +120013795
Tony Barbour5781e8f2015-08-04 16:23:11 -060013796 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbes62e8e502015-05-25 11:13:29 +120013797
Chris Forbes8f36a8a2016-04-07 13:21:07 +120013798 m_errorMonitor->VerifyFound();
Chris Forbes62e8e502015-05-25 11:13:29 +120013799}
13800
Karl Schultz6addd812016-02-02 17:17:23 -070013801TEST_F(VkLayerTest, CreatePipelineAttribTypeMismatch) {
Chris Forbes1cc79542016-07-20 11:13:44 +120013802 TEST_DESCRIPTION("Test that an error is produced for a mismatch between the "
13803 "fundamental type (float/int/uint) of an attribute and the "
13804 "VS input that consumes it");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013805 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "location 0 does not match VS input type");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060013806
Chris Forbesc97d98e2015-05-25 11:13:31 +120013807 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -060013808 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbesc97d98e2015-05-25 11:13:31 +120013809
13810 VkVertexInputBindingDescription input_binding;
13811 memset(&input_binding, 0, sizeof(input_binding));
13812
13813 VkVertexInputAttributeDescription input_attrib;
13814 memset(&input_attrib, 0, sizeof(input_attrib));
13815 input_attrib.format = VK_FORMAT_R32_SFLOAT;
13816
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013817 char const *vsSource = "#version 450\n"
13818 "\n"
13819 "layout(location=0) in int x;\n" /* attrib provided float */
13820 "out gl_PerVertex {\n"
13821 " vec4 gl_Position;\n"
13822 "};\n"
13823 "void main(){\n"
13824 " gl_Position = vec4(x);\n"
13825 "}\n";
13826 char const *fsSource = "#version 450\n"
13827 "\n"
13828 "layout(location=0) out vec4 color;\n"
13829 "void main(){\n"
13830 " color = vec4(1);\n"
13831 "}\n";
Chris Forbesc97d98e2015-05-25 11:13:31 +120013832
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060013833 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13834 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbesc97d98e2015-05-25 11:13:31 +120013835
13836 VkPipelineObj pipe(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +080013837 pipe.AddColorAttachment();
Chris Forbesc97d98e2015-05-25 11:13:31 +120013838 pipe.AddShader(&vs);
13839 pipe.AddShader(&fs);
13840
13841 pipe.AddVertexInputBindings(&input_binding, 1);
13842 pipe.AddVertexInputAttribs(&input_attrib, 1);
13843
Chris Forbesc97d98e2015-05-25 11:13:31 +120013844 VkDescriptorSetObj descriptorSet(m_device);
13845 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080013846 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbesc97d98e2015-05-25 11:13:31 +120013847
Tony Barbour5781e8f2015-08-04 16:23:11 -060013848 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbesc97d98e2015-05-25 11:13:31 +120013849
Chris Forbes8f36a8a2016-04-07 13:21:07 +120013850 m_errorMonitor->VerifyFound();
Chris Forbesc97d98e2015-05-25 11:13:31 +120013851}
13852
Chris Forbesc68b43c2016-04-06 11:18:47 +120013853TEST_F(VkLayerTest, CreatePipelineDuplicateStage) {
Chris Forbes1cc79542016-07-20 11:13:44 +120013854 TEST_DESCRIPTION("Test that an error is produced for a pipeline containing multiple "
13855 "shaders for the same stage");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013856 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
13857 "Multiple shaders provided for stage VK_SHADER_STAGE_VERTEX_BIT");
Chris Forbesc68b43c2016-04-06 11:18:47 +120013858
13859 ASSERT_NO_FATAL_FAILURE(InitState());
13860 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13861
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013862 char const *vsSource = "#version 450\n"
13863 "\n"
13864 "out gl_PerVertex {\n"
13865 " vec4 gl_Position;\n"
13866 "};\n"
13867 "void main(){\n"
13868 " gl_Position = vec4(1);\n"
13869 "}\n";
13870 char const *fsSource = "#version 450\n"
13871 "\n"
13872 "layout(location=0) out vec4 color;\n"
13873 "void main(){\n"
13874 " color = vec4(1);\n"
13875 "}\n";
Chris Forbesc68b43c2016-04-06 11:18:47 +120013876
13877 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13878 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
13879
13880 VkPipelineObj pipe(m_device);
13881 pipe.AddColorAttachment();
13882 pipe.AddShader(&vs);
13883 pipe.AddShader(&vs);
13884 pipe.AddShader(&fs);
13885
13886 VkDescriptorSetObj descriptorSet(m_device);
13887 descriptorSet.AppendDummy();
13888 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
13889
13890 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
13891
Chris Forbes8f36a8a2016-04-07 13:21:07 +120013892 m_errorMonitor->VerifyFound();
Chris Forbesc68b43c2016-04-06 11:18:47 +120013893}
13894
Karl Schultz6addd812016-02-02 17:17:23 -070013895TEST_F(VkLayerTest, CreatePipelineAttribMatrixType) {
Chris Forbes1cc79542016-07-20 11:13:44 +120013896 TEST_DESCRIPTION("Test that pipeline validation accepts matrices passed "
13897 "as vertex attributes");
Chris Forbes8f36a8a2016-04-07 13:21:07 +120013898 m_errorMonitor->ExpectSuccess();
Chris Forbes2682b242015-11-24 11:13:14 +130013899
13900 ASSERT_NO_FATAL_FAILURE(InitState());
13901 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13902
13903 VkVertexInputBindingDescription input_binding;
13904 memset(&input_binding, 0, sizeof(input_binding));
13905
13906 VkVertexInputAttributeDescription input_attribs[2];
13907 memset(input_attribs, 0, sizeof(input_attribs));
13908
13909 for (int i = 0; i < 2; i++) {
13910 input_attribs[i].format = VK_FORMAT_R32G32B32A32_SFLOAT;
13911 input_attribs[i].location = i;
13912 }
13913
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013914 char const *vsSource = "#version 450\n"
13915 "\n"
13916 "layout(location=0) in mat2x4 x;\n"
13917 "out gl_PerVertex {\n"
13918 " vec4 gl_Position;\n"
13919 "};\n"
13920 "void main(){\n"
13921 " gl_Position = x[0] + x[1];\n"
13922 "}\n";
13923 char const *fsSource = "#version 450\n"
13924 "\n"
13925 "layout(location=0) out vec4 color;\n"
13926 "void main(){\n"
13927 " color = vec4(1);\n"
13928 "}\n";
Chris Forbes2682b242015-11-24 11:13:14 +130013929
13930 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13931 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
13932
13933 VkPipelineObj pipe(m_device);
13934 pipe.AddColorAttachment();
13935 pipe.AddShader(&vs);
13936 pipe.AddShader(&fs);
13937
13938 pipe.AddVertexInputBindings(&input_binding, 1);
13939 pipe.AddVertexInputAttribs(input_attribs, 2);
13940
13941 VkDescriptorSetObj descriptorSet(m_device);
13942 descriptorSet.AppendDummy();
13943 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
13944
13945 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
13946
13947 /* expect success */
Chris Forbes8f36a8a2016-04-07 13:21:07 +120013948 m_errorMonitor->VerifyNotFound();
Chris Forbes2682b242015-11-24 11:13:14 +130013949}
13950
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013951TEST_F(VkLayerTest, CreatePipelineAttribArrayType) {
Chris Forbes8f36a8a2016-04-07 13:21:07 +120013952 m_errorMonitor->ExpectSuccess();
Chris Forbes2682b242015-11-24 11:13:14 +130013953
13954 ASSERT_NO_FATAL_FAILURE(InitState());
13955 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13956
13957 VkVertexInputBindingDescription input_binding;
13958 memset(&input_binding, 0, sizeof(input_binding));
13959
13960 VkVertexInputAttributeDescription input_attribs[2];
13961 memset(input_attribs, 0, sizeof(input_attribs));
13962
13963 for (int i = 0; i < 2; i++) {
13964 input_attribs[i].format = VK_FORMAT_R32G32B32A32_SFLOAT;
13965 input_attribs[i].location = i;
13966 }
13967
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013968 char const *vsSource = "#version 450\n"
13969 "\n"
13970 "layout(location=0) in vec4 x[2];\n"
13971 "out gl_PerVertex {\n"
13972 " vec4 gl_Position;\n"
13973 "};\n"
13974 "void main(){\n"
13975 " gl_Position = x[0] + x[1];\n"
13976 "}\n";
13977 char const *fsSource = "#version 450\n"
13978 "\n"
13979 "layout(location=0) out vec4 color;\n"
13980 "void main(){\n"
13981 " color = vec4(1);\n"
13982 "}\n";
Chris Forbes2682b242015-11-24 11:13:14 +130013983
13984 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13985 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
13986
13987 VkPipelineObj pipe(m_device);
13988 pipe.AddColorAttachment();
13989 pipe.AddShader(&vs);
13990 pipe.AddShader(&fs);
13991
13992 pipe.AddVertexInputBindings(&input_binding, 1);
13993 pipe.AddVertexInputAttribs(input_attribs, 2);
13994
13995 VkDescriptorSetObj descriptorSet(m_device);
13996 descriptorSet.AppendDummy();
13997 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
13998
13999 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
14000
Chris Forbes8f36a8a2016-04-07 13:21:07 +120014001 m_errorMonitor->VerifyNotFound();
Chris Forbes2682b242015-11-24 11:13:14 +130014002}
Chris Forbes2682b242015-11-24 11:13:14 +130014003
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014004TEST_F(VkLayerTest, CreatePipelineAttribComponents) {
Chris Forbes1cc79542016-07-20 11:13:44 +120014005 TEST_DESCRIPTION("Test that pipeline validation accepts consuming a vertex attribute "
14006 "through multiple VS inputs, each consuming a different subset of the "
14007 "components.");
Chris Forbesbc290ce2016-07-06 12:01:49 +120014008 m_errorMonitor->ExpectSuccess();
14009
14010 ASSERT_NO_FATAL_FAILURE(InitState());
14011 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
14012
14013 VkVertexInputBindingDescription input_binding;
14014 memset(&input_binding, 0, sizeof(input_binding));
14015
14016 VkVertexInputAttributeDescription input_attribs[3];
14017 memset(input_attribs, 0, sizeof(input_attribs));
14018
14019 for (int i = 0; i < 3; i++) {
14020 input_attribs[i].format = VK_FORMAT_R32G32B32A32_SFLOAT;
14021 input_attribs[i].location = i;
14022 }
14023
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014024 char const *vsSource = "#version 450\n"
14025 "\n"
14026 "layout(location=0) in vec4 x;\n"
14027 "layout(location=1) in vec3 y1;\n"
14028 "layout(location=1, component=3) in float y2;\n"
14029 "layout(location=2) in vec4 z;\n"
14030 "out gl_PerVertex {\n"
14031 " vec4 gl_Position;\n"
14032 "};\n"
14033 "void main(){\n"
14034 " gl_Position = x + vec4(y1, y2) + z;\n"
14035 "}\n";
14036 char const *fsSource = "#version 450\n"
14037 "\n"
14038 "layout(location=0) out vec4 color;\n"
14039 "void main(){\n"
14040 " color = vec4(1);\n"
14041 "}\n";
Chris Forbesbc290ce2016-07-06 12:01:49 +120014042
14043 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
14044 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
14045
14046 VkPipelineObj pipe(m_device);
14047 pipe.AddColorAttachment();
14048 pipe.AddShader(&vs);
14049 pipe.AddShader(&fs);
14050
14051 pipe.AddVertexInputBindings(&input_binding, 1);
14052 pipe.AddVertexInputAttribs(input_attribs, 3);
14053
14054 VkDescriptorSetObj descriptorSet(m_device);
14055 descriptorSet.AppendDummy();
14056 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
14057
14058 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
14059
14060 m_errorMonitor->VerifyNotFound();
14061}
14062
Chris Forbes82ff92a2016-09-09 10:50:24 +120014063TEST_F(VkLayerTest, CreatePipelineMissingEntrypoint) {
14064 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
14065 "No entrypoint found named `foo`");
14066
14067 ASSERT_NO_FATAL_FAILURE(InitState());
14068 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
14069
14070 char const *vsSource = "#version 450\n"
14071 "out gl_PerVertex {\n"
14072 " vec4 gl_Position;\n"
14073 "};\n"
14074 "void main(){\n"
14075 " gl_Position = vec4(0);\n"
14076 "}\n";
14077 char const *fsSource = "#version 450\n"
14078 "\n"
14079 "layout(location=0) out vec4 color;\n"
14080 "void main(){\n"
14081 " color = vec4(1);\n"
14082 "}\n";
14083
14084 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
14085 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this, "foo");
14086
14087 VkPipelineObj pipe(m_device);
14088 pipe.AddColorAttachment();
14089 pipe.AddShader(&vs);
14090 pipe.AddShader(&fs);
14091
14092 VkDescriptorSetObj descriptorSet(m_device);
14093 descriptorSet.AppendDummy();
14094 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
14095
14096 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
14097
14098 m_errorMonitor->VerifyFound();
14099}
14100
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014101TEST_F(VkLayerTest, CreatePipelineSimplePositive) {
Chris Forbes8f36a8a2016-04-07 13:21:07 +120014102 m_errorMonitor->ExpectSuccess();
Chris Forbes4ea14fc2016-04-04 18:52:54 +120014103
14104 ASSERT_NO_FATAL_FAILURE(InitState());
14105 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
14106
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014107 char const *vsSource = "#version 450\n"
14108 "out gl_PerVertex {\n"
14109 " vec4 gl_Position;\n"
14110 "};\n"
14111 "void main(){\n"
14112 " gl_Position = vec4(0);\n"
14113 "}\n";
14114 char const *fsSource = "#version 450\n"
14115 "\n"
14116 "layout(location=0) out vec4 color;\n"
14117 "void main(){\n"
14118 " color = vec4(1);\n"
14119 "}\n";
Chris Forbes4ea14fc2016-04-04 18:52:54 +120014120
14121 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
14122 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
14123
14124 VkPipelineObj pipe(m_device);
14125 pipe.AddColorAttachment();
14126 pipe.AddShader(&vs);
14127 pipe.AddShader(&fs);
14128
14129 VkDescriptorSetObj descriptorSet(m_device);
14130 descriptorSet.AppendDummy();
14131 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
14132
14133 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
14134
Chris Forbes8f36a8a2016-04-07 13:21:07 +120014135 m_errorMonitor->VerifyNotFound();
Chris Forbes4ea14fc2016-04-04 18:52:54 +120014136}
14137
Chris Forbesae9d8cd2016-09-13 16:32:57 +120014138TEST_F(VkLayerTest, CreatePipelineDepthStencilRequired) {
14139 m_errorMonitor->SetDesiredFailureMsg(
14140 VK_DEBUG_REPORT_ERROR_BIT_EXT,
14141 "pDepthStencilState is NULL when rasterization is enabled and subpass "
14142 "uses a depth/stencil attachment");
14143
14144 ASSERT_NO_FATAL_FAILURE(InitState());
14145 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
14146
14147 char const *vsSource = "#version 450\n"
14148 "void main(){ gl_Position = vec4(0); }\n";
14149 char const *fsSource = "#version 450\n"
14150 "\n"
14151 "layout(location=0) out vec4 color;\n"
14152 "void main(){\n"
14153 " color = vec4(1);\n"
14154 "}\n";
14155
14156 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
14157 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
14158
14159 VkPipelineObj pipe(m_device);
14160 pipe.AddColorAttachment();
14161 pipe.AddShader(&vs);
14162 pipe.AddShader(&fs);
14163
14164 VkDescriptorSetObj descriptorSet(m_device);
14165 descriptorSet.AppendDummy();
14166 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
14167
14168 VkAttachmentDescription attachments[] = {
14169 { 0, VK_FORMAT_B8G8R8A8_UNORM, VK_SAMPLE_COUNT_1_BIT,
14170 VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE,
14171 VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE,
14172 VK_IMAGE_LAYOUT_UNDEFINED, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
14173 },
14174 { 0, VK_FORMAT_D16_UNORM, VK_SAMPLE_COUNT_1_BIT,
14175 VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE,
14176 VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE,
14177 VK_IMAGE_LAYOUT_UNDEFINED, VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL,
14178 },
14179 };
14180 VkAttachmentReference refs[] = {
14181 { 0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL },
14182 { 1, VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL },
14183 };
14184 VkSubpassDescription subpass = {
14185 0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr,
14186 1, &refs[0], nullptr, &refs[1],
14187 0, nullptr
14188 };
14189 VkRenderPassCreateInfo rpci = {
14190 VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr,
14191 0, 2, attachments, 1, &subpass, 0, nullptr
14192 };
14193 VkRenderPass rp;
14194 VkResult err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
14195 ASSERT_VK_SUCCESS(err);
14196
14197 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), rp);
14198
14199 m_errorMonitor->VerifyFound();
14200
14201 vkDestroyRenderPass(m_device->device(), rp, nullptr);
14202}
14203
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014204TEST_F(VkLayerTest, CreatePipelineRelaxedTypeMatch) {
Chris Forbes1cc79542016-07-20 11:13:44 +120014205 TEST_DESCRIPTION("Test that pipeline validation accepts the relaxed type matching rules "
14206 "set out in 14.1.3: fundamental type must match, and producer side must "
14207 "have at least as many components");
Chris Forbes8f36a8a2016-04-07 13:21:07 +120014208 m_errorMonitor->ExpectSuccess();
Chris Forbes912c9192016-04-05 17:50:35 +120014209
14210 // VK 1.0.8 Specification, 14.1.3 "Additionally,..." block
14211
14212 ASSERT_NO_FATAL_FAILURE(InitState());
14213 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
14214
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014215 char const *vsSource = "#version 450\n"
14216 "out gl_PerVertex {\n"
14217 " vec4 gl_Position;\n"
14218 "};\n"
14219 "layout(location=0) out vec3 x;\n"
14220 "layout(location=1) out ivec3 y;\n"
14221 "layout(location=2) out vec3 z;\n"
14222 "void main(){\n"
14223 " gl_Position = vec4(0);\n"
14224 " x = vec3(0); y = ivec3(0); z = vec3(0);\n"
14225 "}\n";
14226 char const *fsSource = "#version 450\n"
14227 "\n"
14228 "layout(location=0) out vec4 color;\n"
14229 "layout(location=0) in float x;\n"
14230 "layout(location=1) flat in int y;\n"
14231 "layout(location=2) in vec2 z;\n"
14232 "void main(){\n"
14233 " color = vec4(1 + x + y + z.x);\n"
14234 "}\n";
Chris Forbes912c9192016-04-05 17:50:35 +120014235
14236 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
14237 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
14238
14239 VkPipelineObj pipe(m_device);
14240 pipe.AddColorAttachment();
14241 pipe.AddShader(&vs);
14242 pipe.AddShader(&fs);
14243
14244 VkDescriptorSetObj descriptorSet(m_device);
14245 descriptorSet.AppendDummy();
14246 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
14247
Mike Stroyan255e9582016-06-24 09:49:32 -060014248 VkResult err = VK_SUCCESS;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014249 err = pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Mike Stroyan255e9582016-06-24 09:49:32 -060014250 ASSERT_VK_SUCCESS(err);
14251
Chris Forbes8f36a8a2016-04-07 13:21:07 +120014252 m_errorMonitor->VerifyNotFound();
Chris Forbes912c9192016-04-05 17:50:35 +120014253}
14254
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014255TEST_F(VkLayerTest, CreatePipelineTessPerVertex) {
Chris Forbes1cc79542016-07-20 11:13:44 +120014256 TEST_DESCRIPTION("Test that pipeline validation accepts per-vertex variables "
14257 "passed between the TCS and TES stages");
Chris Forbes8f36a8a2016-04-07 13:21:07 +120014258 m_errorMonitor->ExpectSuccess();
Chris Forbes4ea14fc2016-04-04 18:52:54 +120014259
14260 ASSERT_NO_FATAL_FAILURE(InitState());
14261 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
14262
Chris Forbesc1e852d2016-04-04 19:26:42 +120014263 if (!m_device->phy().features().tessellationShader) {
14264 printf("Device does not support tessellation shaders; skipped.\n");
14265 return;
14266 }
14267
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014268 char const *vsSource = "#version 450\n"
14269 "void main(){}\n";
14270 char const *tcsSource = "#version 450\n"
14271 "layout(location=0) out int x[];\n"
14272 "layout(vertices=3) out;\n"
14273 "void main(){\n"
14274 " gl_TessLevelOuter[0] = gl_TessLevelOuter[1] = gl_TessLevelOuter[2] = 1;\n"
14275 " gl_TessLevelInner[0] = 1;\n"
14276 " x[gl_InvocationID] = gl_InvocationID;\n"
14277 "}\n";
14278 char const *tesSource = "#version 450\n"
14279 "layout(triangles, equal_spacing, cw) in;\n"
14280 "layout(location=0) in int x[];\n"
14281 "out gl_PerVertex { vec4 gl_Position; };\n"
14282 "void main(){\n"
14283 " gl_Position.xyz = gl_TessCoord;\n"
14284 " gl_Position.w = x[0] + x[1] + x[2];\n"
14285 "}\n";
14286 char const *fsSource = "#version 450\n"
14287 "layout(location=0) out vec4 color;\n"
14288 "void main(){\n"
14289 " color = vec4(1);\n"
14290 "}\n";
Chris Forbes4ea14fc2016-04-04 18:52:54 +120014291
14292 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
14293 VkShaderObj tcs(m_device, tcsSource, VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT, this);
14294 VkShaderObj tes(m_device, tesSource, VK_SHADER_STAGE_TESSELLATION_EVALUATION_BIT, this);
14295 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
14296
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014297 VkPipelineInputAssemblyStateCreateInfo iasci{VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO, nullptr, 0,
14298 VK_PRIMITIVE_TOPOLOGY_PATCH_LIST, VK_FALSE};
Chris Forbes4ea14fc2016-04-04 18:52:54 +120014299
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014300 VkPipelineTessellationStateCreateInfo tsci{VK_STRUCTURE_TYPE_PIPELINE_TESSELLATION_STATE_CREATE_INFO, nullptr, 0, 3};
Chris Forbesb4cacb62016-04-04 19:15:00 +120014301
Chris Forbes4ea14fc2016-04-04 18:52:54 +120014302 VkPipelineObj pipe(m_device);
14303 pipe.SetInputAssembly(&iasci);
Chris Forbesb4cacb62016-04-04 19:15:00 +120014304 pipe.SetTessellation(&tsci);
Chris Forbes4ea14fc2016-04-04 18:52:54 +120014305 pipe.AddColorAttachment();
14306 pipe.AddShader(&vs);
14307 pipe.AddShader(&tcs);
14308 pipe.AddShader(&tes);
14309 pipe.AddShader(&fs);
14310
14311 VkDescriptorSetObj descriptorSet(m_device);
14312 descriptorSet.AppendDummy();
14313 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
14314
14315 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
14316
Chris Forbes8f36a8a2016-04-07 13:21:07 +120014317 m_errorMonitor->VerifyNotFound();
Chris Forbes4ea14fc2016-04-04 18:52:54 +120014318}
14319
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014320TEST_F(VkLayerTest, CreatePipelineGeometryInputBlockPositive) {
Chris Forbes1cc79542016-07-20 11:13:44 +120014321 TEST_DESCRIPTION("Test that pipeline validation accepts a user-defined "
14322 "interface block passed into the geometry shader. This "
14323 "is interesting because the 'extra' array level is not "
14324 "present on the member type, but on the block instance.");
Chris Forbesa0ab8152016-04-20 13:34:27 +120014325 m_errorMonitor->ExpectSuccess();
14326
14327 ASSERT_NO_FATAL_FAILURE(InitState());
14328 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
14329
14330 if (!m_device->phy().features().geometryShader) {
14331 printf("Device does not support geometry shaders; skipped.\n");
14332 return;
14333 }
14334
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014335 char const *vsSource = "#version 450\n"
14336 "layout(location=0) out VertexData { vec4 x; } vs_out;\n"
14337 "void main(){\n"
14338 " vs_out.x = vec4(1);\n"
14339 "}\n";
14340 char const *gsSource = "#version 450\n"
14341 "layout(triangles) in;\n"
14342 "layout(triangle_strip, max_vertices=3) out;\n"
14343 "layout(location=0) in VertexData { vec4 x; } gs_in[];\n"
14344 "out gl_PerVertex { vec4 gl_Position; };\n"
14345 "void main() {\n"
14346 " gl_Position = gs_in[0].x;\n"
14347 " EmitVertex();\n"
14348 "}\n";
14349 char const *fsSource = "#version 450\n"
14350 "layout(location=0) out vec4 color;\n"
14351 "void main(){\n"
14352 " color = vec4(1);\n"
14353 "}\n";
Chris Forbesa0ab8152016-04-20 13:34:27 +120014354
14355 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
14356 VkShaderObj gs(m_device, gsSource, VK_SHADER_STAGE_GEOMETRY_BIT, this);
14357 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
14358
14359 VkPipelineObj pipe(m_device);
14360 pipe.AddColorAttachment();
14361 pipe.AddShader(&vs);
14362 pipe.AddShader(&gs);
14363 pipe.AddShader(&fs);
14364
14365 VkDescriptorSetObj descriptorSet(m_device);
14366 descriptorSet.AppendDummy();
14367 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
14368
14369 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
14370
14371 m_errorMonitor->VerifyNotFound();
14372}
14373
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014374TEST_F(VkLayerTest, CreatePipelineTessPatchDecorationMismatch) {
Chris Forbes1cc79542016-07-20 11:13:44 +120014375 TEST_DESCRIPTION("Test that an error is produced for a variable output from "
14376 "the TCS without the patch decoration, but consumed in the TES "
14377 "with the decoration.");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014378 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "is per-vertex in tessellation control shader stage "
14379 "but per-patch in tessellation evaluation shader stage");
Chris Forbesa0193bc2016-04-04 19:19:47 +120014380
14381 ASSERT_NO_FATAL_FAILURE(InitState());
14382 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
14383
Chris Forbesc1e852d2016-04-04 19:26:42 +120014384 if (!m_device->phy().features().tessellationShader) {
14385 printf("Device does not support tessellation shaders; skipped.\n");
14386 return;
14387 }
14388
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014389 char const *vsSource = "#version 450\n"
14390 "void main(){}\n";
14391 char const *tcsSource = "#version 450\n"
14392 "layout(location=0) out int x[];\n"
14393 "layout(vertices=3) out;\n"
14394 "void main(){\n"
14395 " gl_TessLevelOuter[0] = gl_TessLevelOuter[1] = gl_TessLevelOuter[2] = 1;\n"
14396 " gl_TessLevelInner[0] = 1;\n"
14397 " x[gl_InvocationID] = gl_InvocationID;\n"
14398 "}\n";
14399 char const *tesSource = "#version 450\n"
14400 "layout(triangles, equal_spacing, cw) in;\n"
14401 "layout(location=0) patch in int x;\n"
14402 "out gl_PerVertex { vec4 gl_Position; };\n"
14403 "void main(){\n"
14404 " gl_Position.xyz = gl_TessCoord;\n"
14405 " gl_Position.w = x;\n"
14406 "}\n";
14407 char const *fsSource = "#version 450\n"
14408 "layout(location=0) out vec4 color;\n"
14409 "void main(){\n"
14410 " color = vec4(1);\n"
14411 "}\n";
Chris Forbesa0193bc2016-04-04 19:19:47 +120014412
14413 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
14414 VkShaderObj tcs(m_device, tcsSource, VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT, this);
14415 VkShaderObj tes(m_device, tesSource, VK_SHADER_STAGE_TESSELLATION_EVALUATION_BIT, this);
14416 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
14417
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014418 VkPipelineInputAssemblyStateCreateInfo iasci{VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO, nullptr, 0,
14419 VK_PRIMITIVE_TOPOLOGY_PATCH_LIST, VK_FALSE};
Chris Forbesa0193bc2016-04-04 19:19:47 +120014420
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014421 VkPipelineTessellationStateCreateInfo tsci{VK_STRUCTURE_TYPE_PIPELINE_TESSELLATION_STATE_CREATE_INFO, nullptr, 0, 3};
Chris Forbesa0193bc2016-04-04 19:19:47 +120014422
14423 VkPipelineObj pipe(m_device);
14424 pipe.SetInputAssembly(&iasci);
14425 pipe.SetTessellation(&tsci);
14426 pipe.AddColorAttachment();
14427 pipe.AddShader(&vs);
14428 pipe.AddShader(&tcs);
14429 pipe.AddShader(&tes);
14430 pipe.AddShader(&fs);
14431
14432 VkDescriptorSetObj descriptorSet(m_device);
14433 descriptorSet.AppendDummy();
14434 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
14435
14436 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
14437
Chris Forbes8f36a8a2016-04-07 13:21:07 +120014438 m_errorMonitor->VerifyFound();
Chris Forbesa0193bc2016-04-04 19:19:47 +120014439}
14440
Karl Schultz6addd812016-02-02 17:17:23 -070014441TEST_F(VkLayerTest, CreatePipelineAttribBindingConflict) {
Chris Forbes1cc79542016-07-20 11:13:44 +120014442 TEST_DESCRIPTION("Test that an error is produced for a vertex attribute setup where multiple "
14443 "bindings provide the same location");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014444 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
14445 "Duplicate vertex input binding descriptions for binding 0");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060014446
Chris Forbes280ba2c2015-06-12 11:16:41 +120014447 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -060014448 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbes280ba2c2015-06-12 11:16:41 +120014449
14450 /* Two binding descriptions for binding 0 */
14451 VkVertexInputBindingDescription input_bindings[2];
14452 memset(input_bindings, 0, sizeof(input_bindings));
14453
14454 VkVertexInputAttributeDescription input_attrib;
14455 memset(&input_attrib, 0, sizeof(input_attrib));
14456 input_attrib.format = VK_FORMAT_R32_SFLOAT;
14457
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014458 char const *vsSource = "#version 450\n"
14459 "\n"
14460 "layout(location=0) in float x;\n" /* attrib provided float */
14461 "out gl_PerVertex {\n"
14462 " vec4 gl_Position;\n"
14463 "};\n"
14464 "void main(){\n"
14465 " gl_Position = vec4(x);\n"
14466 "}\n";
14467 char const *fsSource = "#version 450\n"
14468 "\n"
14469 "layout(location=0) out vec4 color;\n"
14470 "void main(){\n"
14471 " color = vec4(1);\n"
14472 "}\n";
Chris Forbes280ba2c2015-06-12 11:16:41 +120014473
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060014474 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
14475 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbes280ba2c2015-06-12 11:16:41 +120014476
14477 VkPipelineObj pipe(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +080014478 pipe.AddColorAttachment();
Chris Forbes280ba2c2015-06-12 11:16:41 +120014479 pipe.AddShader(&vs);
14480 pipe.AddShader(&fs);
14481
14482 pipe.AddVertexInputBindings(input_bindings, 2);
14483 pipe.AddVertexInputAttribs(&input_attrib, 1);
14484
Chris Forbes280ba2c2015-06-12 11:16:41 +120014485 VkDescriptorSetObj descriptorSet(m_device);
14486 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014487 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbes280ba2c2015-06-12 11:16:41 +120014488
Tony Barbour5781e8f2015-08-04 16:23:11 -060014489 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbes280ba2c2015-06-12 11:16:41 +120014490
Chris Forbes8f36a8a2016-04-07 13:21:07 +120014491 m_errorMonitor->VerifyFound();
Chris Forbes280ba2c2015-06-12 11:16:41 +120014492}
Chris Forbes8f68b562015-05-25 11:13:32 +120014493
Chris Forbes35efec72016-04-21 14:32:08 +120014494TEST_F(VkLayerTest, CreatePipeline64BitAttributesPositive) {
Chris Forbes1cc79542016-07-20 11:13:44 +120014495 TEST_DESCRIPTION("Test that pipeline validation accepts basic use of 64bit vertex "
14496 "attributes. This is interesting because they consume multiple "
14497 "locations.");
Chris Forbes35efec72016-04-21 14:32:08 +120014498 m_errorMonitor->ExpectSuccess();
14499
14500 ASSERT_NO_FATAL_FAILURE(InitState());
14501 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
14502
Chris Forbes91cf3a82016-06-28 17:51:35 +120014503 if (!m_device->phy().features().shaderFloat64) {
Chris Forbes35efec72016-04-21 14:32:08 +120014504 printf("Device does not support 64bit vertex attributes; skipped.\n");
14505 return;
14506 }
14507
14508 VkVertexInputBindingDescription input_bindings[1];
14509 memset(input_bindings, 0, sizeof(input_bindings));
14510
14511 VkVertexInputAttributeDescription input_attribs[4];
14512 memset(input_attribs, 0, sizeof(input_attribs));
14513 input_attribs[0].location = 0;
14514 input_attribs[0].offset = 0;
14515 input_attribs[0].format = VK_FORMAT_R64G64B64A64_SFLOAT;
14516 input_attribs[1].location = 2;
14517 input_attribs[1].offset = 32;
14518 input_attribs[1].format = VK_FORMAT_R64G64B64A64_SFLOAT;
14519 input_attribs[2].location = 4;
14520 input_attribs[2].offset = 64;
14521 input_attribs[2].format = VK_FORMAT_R64G64B64A64_SFLOAT;
14522 input_attribs[3].location = 6;
14523 input_attribs[3].offset = 96;
14524 input_attribs[3].format = VK_FORMAT_R64G64B64A64_SFLOAT;
14525
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014526 char const *vsSource = "#version 450\n"
14527 "\n"
14528 "layout(location=0) in dmat4 x;\n"
14529 "out gl_PerVertex {\n"
14530 " vec4 gl_Position;\n"
14531 "};\n"
14532 "void main(){\n"
14533 " gl_Position = vec4(x[0][0]);\n"
14534 "}\n";
14535 char const *fsSource = "#version 450\n"
14536 "\n"
14537 "layout(location=0) out vec4 color;\n"
14538 "void main(){\n"
14539 " color = vec4(1);\n"
14540 "}\n";
Chris Forbes35efec72016-04-21 14:32:08 +120014541
14542 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
14543 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
14544
14545 VkPipelineObj pipe(m_device);
14546 pipe.AddColorAttachment();
14547 pipe.AddShader(&vs);
14548 pipe.AddShader(&fs);
14549
14550 pipe.AddVertexInputBindings(input_bindings, 1);
14551 pipe.AddVertexInputAttribs(input_attribs, 4);
14552
14553 VkDescriptorSetObj descriptorSet(m_device);
14554 descriptorSet.AppendDummy();
14555 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
14556
14557 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
14558
14559 m_errorMonitor->VerifyNotFound();
14560}
14561
Karl Schultz6addd812016-02-02 17:17:23 -070014562TEST_F(VkLayerTest, CreatePipelineFragmentOutputNotWritten) {
Chris Forbes1cc79542016-07-20 11:13:44 +120014563 TEST_DESCRIPTION("Test that an error is produced for a FS which does not "
14564 "provide an output for one of the pipeline's color attachments");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014565 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Attachment 0 not written by FS");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060014566
Chris Forbes4d6d1e52015-05-25 11:13:40 +120014567 ASSERT_NO_FATAL_FAILURE(InitState());
Chris Forbes4d6d1e52015-05-25 11:13:40 +120014568
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014569 char const *vsSource = "#version 450\n"
14570 "\n"
14571 "out gl_PerVertex {\n"
14572 " vec4 gl_Position;\n"
14573 "};\n"
14574 "void main(){\n"
14575 " gl_Position = vec4(1);\n"
14576 "}\n";
14577 char const *fsSource = "#version 450\n"
14578 "\n"
14579 "void main(){\n"
14580 "}\n";
Chris Forbes4d6d1e52015-05-25 11:13:40 +120014581
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060014582 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
14583 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbes4d6d1e52015-05-25 11:13:40 +120014584
14585 VkPipelineObj pipe(m_device);
14586 pipe.AddShader(&vs);
14587 pipe.AddShader(&fs);
14588
Chia-I Wu08accc62015-07-07 11:50:03 +080014589 /* set up CB 0, not written */
14590 pipe.AddColorAttachment();
14591 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbes4d6d1e52015-05-25 11:13:40 +120014592
Chris Forbes4d6d1e52015-05-25 11:13:40 +120014593 VkDescriptorSetObj descriptorSet(m_device);
14594 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014595 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbes4d6d1e52015-05-25 11:13:40 +120014596
Tony Barbour5781e8f2015-08-04 16:23:11 -060014597 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbes4d6d1e52015-05-25 11:13:40 +120014598
Chris Forbes8f36a8a2016-04-07 13:21:07 +120014599 m_errorMonitor->VerifyFound();
Chris Forbes4d6d1e52015-05-25 11:13:40 +120014600}
14601
Karl Schultz6addd812016-02-02 17:17:23 -070014602TEST_F(VkLayerTest, CreatePipelineFragmentOutputNotConsumed) {
Chris Forbes1cc79542016-07-20 11:13:44 +120014603 TEST_DESCRIPTION("Test that a warning is produced for a FS which provides a spurious "
14604 "output with no matching attachment");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014605 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT,
14606 "FS writes to output location 1 with no matching attachment");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060014607
Chris Forbesf3fffaa2015-05-25 11:13:43 +120014608 ASSERT_NO_FATAL_FAILURE(InitState());
Chris Forbesf3fffaa2015-05-25 11:13:43 +120014609
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014610 char const *vsSource = "#version 450\n"
14611 "\n"
14612 "out gl_PerVertex {\n"
14613 " vec4 gl_Position;\n"
14614 "};\n"
14615 "void main(){\n"
14616 " gl_Position = vec4(1);\n"
14617 "}\n";
14618 char const *fsSource = "#version 450\n"
14619 "\n"
14620 "layout(location=0) out vec4 x;\n"
14621 "layout(location=1) out vec4 y;\n" /* no matching attachment for this */
14622 "void main(){\n"
14623 " x = vec4(1);\n"
14624 " y = vec4(1);\n"
14625 "}\n";
Chris Forbesf3fffaa2015-05-25 11:13:43 +120014626
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060014627 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
14628 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbesf3fffaa2015-05-25 11:13:43 +120014629
14630 VkPipelineObj pipe(m_device);
14631 pipe.AddShader(&vs);
14632 pipe.AddShader(&fs);
14633
Chia-I Wu08accc62015-07-07 11:50:03 +080014634 /* set up CB 0, not written */
14635 pipe.AddColorAttachment();
14636 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbesf3fffaa2015-05-25 11:13:43 +120014637 /* FS writes CB 1, but we don't configure it */
14638
Chris Forbesf3fffaa2015-05-25 11:13:43 +120014639 VkDescriptorSetObj descriptorSet(m_device);
14640 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014641 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbesf3fffaa2015-05-25 11:13:43 +120014642
Tony Barbour5781e8f2015-08-04 16:23:11 -060014643 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbesf3fffaa2015-05-25 11:13:43 +120014644
Chris Forbes8f36a8a2016-04-07 13:21:07 +120014645 m_errorMonitor->VerifyFound();
Chris Forbesf3fffaa2015-05-25 11:13:43 +120014646}
14647
Karl Schultz6addd812016-02-02 17:17:23 -070014648TEST_F(VkLayerTest, CreatePipelineFragmentOutputTypeMismatch) {
Chris Forbes1cc79542016-07-20 11:13:44 +120014649 TEST_DESCRIPTION("Test that an error is produced for a mismatch between the fundamental "
14650 "type of an FS output variable, and the format of the corresponding attachment");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014651 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "does not match FS output type");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060014652
Chris Forbesa36d69e2015-05-25 11:13:44 +120014653 ASSERT_NO_FATAL_FAILURE(InitState());
Chris Forbesa36d69e2015-05-25 11:13:44 +120014654
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014655 char const *vsSource = "#version 450\n"
14656 "\n"
14657 "out gl_PerVertex {\n"
14658 " vec4 gl_Position;\n"
14659 "};\n"
14660 "void main(){\n"
14661 " gl_Position = vec4(1);\n"
14662 "}\n";
14663 char const *fsSource = "#version 450\n"
14664 "\n"
14665 "layout(location=0) out ivec4 x;\n" /* not UNORM */
14666 "void main(){\n"
14667 " x = ivec4(1);\n"
14668 "}\n";
Chris Forbesa36d69e2015-05-25 11:13:44 +120014669
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060014670 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
14671 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbesa36d69e2015-05-25 11:13:44 +120014672
14673 VkPipelineObj pipe(m_device);
14674 pipe.AddShader(&vs);
14675 pipe.AddShader(&fs);
14676
Chia-I Wu08accc62015-07-07 11:50:03 +080014677 /* set up CB 0; type is UNORM by default */
14678 pipe.AddColorAttachment();
14679 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbesa36d69e2015-05-25 11:13:44 +120014680
Chris Forbesa36d69e2015-05-25 11:13:44 +120014681 VkDescriptorSetObj descriptorSet(m_device);
14682 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014683 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbesa36d69e2015-05-25 11:13:44 +120014684
Tony Barbour5781e8f2015-08-04 16:23:11 -060014685 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbesa36d69e2015-05-25 11:13:44 +120014686
Chris Forbes8f36a8a2016-04-07 13:21:07 +120014687 m_errorMonitor->VerifyFound();
Chris Forbesa36d69e2015-05-25 11:13:44 +120014688}
Chris Forbes7b1b8932015-06-05 14:43:36 +120014689
Karl Schultz6addd812016-02-02 17:17:23 -070014690TEST_F(VkLayerTest, CreatePipelineUniformBlockNotProvided) {
Chris Forbes1cc79542016-07-20 11:13:44 +120014691 TEST_DESCRIPTION("Test that an error is produced for a shader consuming a uniform "
14692 "block which has no corresponding binding in the pipeline layout");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014693 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "not declared in pipeline layout");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060014694
Chris Forbes556c76c2015-08-14 12:04:59 +120014695 ASSERT_NO_FATAL_FAILURE(InitState());
Chris Forbes556c76c2015-08-14 12:04:59 +120014696
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014697 char const *vsSource = "#version 450\n"
14698 "\n"
14699 "out gl_PerVertex {\n"
14700 " vec4 gl_Position;\n"
14701 "};\n"
14702 "void main(){\n"
14703 " gl_Position = vec4(1);\n"
14704 "}\n";
14705 char const *fsSource = "#version 450\n"
14706 "\n"
14707 "layout(location=0) out vec4 x;\n"
14708 "layout(set=0) layout(binding=0) uniform foo { int x; int y; } bar;\n"
14709 "void main(){\n"
14710 " x = vec4(bar.y);\n"
14711 "}\n";
Chris Forbes556c76c2015-08-14 12:04:59 +120014712
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060014713 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
14714 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbes556c76c2015-08-14 12:04:59 +120014715
Chris Forbes556c76c2015-08-14 12:04:59 +120014716 VkPipelineObj pipe(m_device);
14717 pipe.AddShader(&vs);
14718 pipe.AddShader(&fs);
14719
14720 /* set up CB 0; type is UNORM by default */
14721 pipe.AddColorAttachment();
14722 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
14723
14724 VkDescriptorSetObj descriptorSet(m_device);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014725 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbes556c76c2015-08-14 12:04:59 +120014726
14727 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
14728
Chris Forbes8f36a8a2016-04-07 13:21:07 +120014729 m_errorMonitor->VerifyFound();
Chris Forbes556c76c2015-08-14 12:04:59 +120014730}
14731
Chris Forbes5c59e902016-02-26 16:56:09 +130014732TEST_F(VkLayerTest, CreatePipelinePushConstantsNotInLayout) {
Chris Forbes1cc79542016-07-20 11:13:44 +120014733 TEST_DESCRIPTION("Test that an error is produced for a shader consuming push constants "
14734 "which are not provided in the pipeline layout");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014735 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "not declared in layout");
Chris Forbes5c59e902016-02-26 16:56:09 +130014736
14737 ASSERT_NO_FATAL_FAILURE(InitState());
14738
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014739 char const *vsSource = "#version 450\n"
14740 "\n"
14741 "layout(push_constant, std430) uniform foo { float x; } consts;\n"
14742 "out gl_PerVertex {\n"
14743 " vec4 gl_Position;\n"
14744 "};\n"
14745 "void main(){\n"
14746 " gl_Position = vec4(consts.x);\n"
14747 "}\n";
14748 char const *fsSource = "#version 450\n"
14749 "\n"
14750 "layout(location=0) out vec4 x;\n"
14751 "void main(){\n"
14752 " x = vec4(1);\n"
14753 "}\n";
Chris Forbes5c59e902016-02-26 16:56:09 +130014754
14755 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
14756 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
14757
14758 VkPipelineObj pipe(m_device);
14759 pipe.AddShader(&vs);
14760 pipe.AddShader(&fs);
14761
14762 /* set up CB 0; type is UNORM by default */
14763 pipe.AddColorAttachment();
14764 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
14765
14766 VkDescriptorSetObj descriptorSet(m_device);
14767 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
14768
14769 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
14770
14771 /* should have generated an error -- no push constant ranges provided! */
Chris Forbes8f36a8a2016-04-07 13:21:07 +120014772 m_errorMonitor->VerifyFound();
Chris Forbes5c59e902016-02-26 16:56:09 +130014773}
14774
Chris Forbes3fb17902016-08-22 14:57:55 +120014775TEST_F(VkLayerTest, CreatePipelineInputAttachmentMissing) {
14776 TEST_DESCRIPTION("Test that an error is produced for a shader consuming an input attachment "
14777 "which is not included in the subpass description");
14778 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
14779 "consumes input attachment index 0 but not provided in subpass");
14780
14781 ASSERT_NO_FATAL_FAILURE(InitState());
14782
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014783 char const *vsSource = "#version 450\n"
14784 "\n"
14785 "out gl_PerVertex {\n"
14786 " vec4 gl_Position;\n"
14787 "};\n"
14788 "void main(){\n"
14789 " gl_Position = vec4(1);\n"
14790 "}\n";
14791 char const *fsSource = "#version 450\n"
14792 "\n"
14793 "layout(input_attachment_index=0, set=0, binding=0) uniform subpassInput x;\n"
14794 "layout(location=0) out vec4 color;\n"
14795 "void main() {\n"
14796 " color = subpassLoad(x);\n"
14797 "}\n";
Chris Forbes3fb17902016-08-22 14:57:55 +120014798
14799 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
14800 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
14801
14802 VkPipelineObj pipe(m_device);
14803 pipe.AddShader(&vs);
14804 pipe.AddShader(&fs);
14805 pipe.AddColorAttachment();
14806 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
14807
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014808 VkDescriptorSetLayoutBinding dslb = {0, VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT, 1, VK_SHADER_STAGE_FRAGMENT_BIT, nullptr};
14809 VkDescriptorSetLayoutCreateInfo dslci = {VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dslb};
Chris Forbes3fb17902016-08-22 14:57:55 +120014810 VkDescriptorSetLayout dsl;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014811 VkResult err = vkCreateDescriptorSetLayout(m_device->device(), &dslci, nullptr, &dsl);
Chris Forbes3fb17902016-08-22 14:57:55 +120014812 ASSERT_VK_SUCCESS(err);
14813
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014814 VkPipelineLayoutCreateInfo plci = {VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dsl, 0, nullptr};
Chris Forbes3fb17902016-08-22 14:57:55 +120014815 VkPipelineLayout pl;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014816 err = vkCreatePipelineLayout(m_device->device(), &plci, nullptr, &pl);
Chris Forbes3fb17902016-08-22 14:57:55 +120014817 ASSERT_VK_SUCCESS(err);
14818
14819 // error here.
14820 pipe.CreateVKPipeline(pl, renderPass());
14821
14822 m_errorMonitor->VerifyFound();
14823
14824 vkDestroyPipelineLayout(m_device->device(), pl, nullptr);
14825 vkDestroyDescriptorSetLayout(m_device->device(), dsl, nullptr);
14826}
14827
Chris Forbes663b5a82016-08-22 16:14:06 +120014828TEST_F(VkLayerTest, CreatePipelineInputAttachmentPositive) {
14829 TEST_DESCRIPTION("Positive test for a correctly matched input attachment");
14830 m_errorMonitor->ExpectSuccess();
14831
14832 ASSERT_NO_FATAL_FAILURE(InitState());
14833
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014834 char const *vsSource = "#version 450\n"
14835 "\n"
14836 "out gl_PerVertex {\n"
14837 " vec4 gl_Position;\n"
14838 "};\n"
14839 "void main(){\n"
14840 " gl_Position = vec4(1);\n"
14841 "}\n";
14842 char const *fsSource = "#version 450\n"
14843 "\n"
14844 "layout(input_attachment_index=0, set=0, binding=0) uniform subpassInput x;\n"
14845 "layout(location=0) out vec4 color;\n"
14846 "void main() {\n"
14847 " color = subpassLoad(x);\n"
14848 "}\n";
Chris Forbes663b5a82016-08-22 16:14:06 +120014849
14850 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
14851 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
14852
14853 VkPipelineObj pipe(m_device);
14854 pipe.AddShader(&vs);
14855 pipe.AddShader(&fs);
14856 pipe.AddColorAttachment();
14857 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
14858
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014859 VkDescriptorSetLayoutBinding dslb = {0, VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT, 1, VK_SHADER_STAGE_FRAGMENT_BIT, nullptr};
14860 VkDescriptorSetLayoutCreateInfo dslci = {VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dslb};
Chris Forbes663b5a82016-08-22 16:14:06 +120014861 VkDescriptorSetLayout dsl;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014862 VkResult err = vkCreateDescriptorSetLayout(m_device->device(), &dslci, nullptr, &dsl);
Chris Forbes663b5a82016-08-22 16:14:06 +120014863 ASSERT_VK_SUCCESS(err);
14864
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014865 VkPipelineLayoutCreateInfo plci = {VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dsl, 0, nullptr};
Chris Forbes663b5a82016-08-22 16:14:06 +120014866 VkPipelineLayout pl;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014867 err = vkCreatePipelineLayout(m_device->device(), &plci, nullptr, &pl);
Chris Forbes663b5a82016-08-22 16:14:06 +120014868 ASSERT_VK_SUCCESS(err);
14869
14870 VkAttachmentDescription descs[2] = {
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014871 {0, VK_FORMAT_R8G8B8A8_UNORM, VK_SAMPLE_COUNT_1_BIT, VK_ATTACHMENT_LOAD_OP_LOAD, VK_ATTACHMENT_STORE_OP_STORE,
14872 VK_ATTACHMENT_LOAD_OP_LOAD, VK_ATTACHMENT_STORE_OP_STORE, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
14873 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL},
14874 {0, VK_FORMAT_R8G8B8A8_UNORM, VK_SAMPLE_COUNT_1_BIT, VK_ATTACHMENT_LOAD_OP_LOAD, VK_ATTACHMENT_STORE_OP_STORE,
14875 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 +120014876 };
14877 VkAttachmentReference color = {
14878 0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
14879 };
14880 VkAttachmentReference input = {
14881 1, VK_IMAGE_LAYOUT_GENERAL,
14882 };
14883
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014884 VkSubpassDescription sd = {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 1, &input, 1, &color, nullptr, nullptr, 0, nullptr};
Chris Forbes663b5a82016-08-22 16:14:06 +120014885
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014886 VkRenderPassCreateInfo rpci = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 2, descs, 1, &sd, 0, nullptr};
Chris Forbes663b5a82016-08-22 16:14:06 +120014887 VkRenderPass rp;
14888 err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
14889 ASSERT_VK_SUCCESS(err);
14890
14891 // should be OK. would go wrong here if it's going to...
14892 pipe.CreateVKPipeline(pl, rp);
14893
14894 m_errorMonitor->VerifyNotFound();
14895
14896 vkDestroyRenderPass(m_device->device(), rp, nullptr);
14897 vkDestroyPipelineLayout(m_device->device(), pl, nullptr);
14898 vkDestroyDescriptorSetLayout(m_device->device(), dsl, nullptr);
14899}
14900
Chris Forbes5a9a0472016-08-22 16:02:09 +120014901TEST_F(VkLayerTest, CreatePipelineInputAttachmentTypeMismatch) {
14902 TEST_DESCRIPTION("Test that an error is produced for a shader consuming an input attachment "
14903 "with a format having a different fundamental type");
14904 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
14905 "input attachment 0 format of VK_FORMAT_R8G8B8A8_UINT does not match");
14906
14907 ASSERT_NO_FATAL_FAILURE(InitState());
14908
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014909 char const *vsSource = "#version 450\n"
14910 "\n"
14911 "out gl_PerVertex {\n"
14912 " vec4 gl_Position;\n"
14913 "};\n"
14914 "void main(){\n"
14915 " gl_Position = vec4(1);\n"
14916 "}\n";
14917 char const *fsSource = "#version 450\n"
14918 "\n"
14919 "layout(input_attachment_index=0, set=0, binding=0) uniform subpassInput x;\n"
14920 "layout(location=0) out vec4 color;\n"
14921 "void main() {\n"
14922 " color = subpassLoad(x);\n"
14923 "}\n";
Chris Forbes5a9a0472016-08-22 16:02:09 +120014924
14925 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
14926 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
14927
14928 VkPipelineObj pipe(m_device);
14929 pipe.AddShader(&vs);
14930 pipe.AddShader(&fs);
14931 pipe.AddColorAttachment();
14932 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
14933
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014934 VkDescriptorSetLayoutBinding dslb = {0, VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT, 1, VK_SHADER_STAGE_FRAGMENT_BIT, nullptr};
14935 VkDescriptorSetLayoutCreateInfo dslci = {VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dslb};
Chris Forbes5a9a0472016-08-22 16:02:09 +120014936 VkDescriptorSetLayout dsl;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014937 VkResult err = vkCreateDescriptorSetLayout(m_device->device(), &dslci, nullptr, &dsl);
Chris Forbes5a9a0472016-08-22 16:02:09 +120014938 ASSERT_VK_SUCCESS(err);
14939
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014940 VkPipelineLayoutCreateInfo plci = {VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dsl, 0, nullptr};
Chris Forbes5a9a0472016-08-22 16:02:09 +120014941 VkPipelineLayout pl;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014942 err = vkCreatePipelineLayout(m_device->device(), &plci, nullptr, &pl);
Chris Forbes5a9a0472016-08-22 16:02:09 +120014943 ASSERT_VK_SUCCESS(err);
14944
14945 VkAttachmentDescription descs[2] = {
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014946 {0, VK_FORMAT_R8G8B8A8_UNORM, VK_SAMPLE_COUNT_1_BIT, VK_ATTACHMENT_LOAD_OP_LOAD, VK_ATTACHMENT_STORE_OP_STORE,
14947 VK_ATTACHMENT_LOAD_OP_LOAD, VK_ATTACHMENT_STORE_OP_STORE, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
14948 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL},
14949 {0, VK_FORMAT_R8G8B8A8_UINT, VK_SAMPLE_COUNT_1_BIT, VK_ATTACHMENT_LOAD_OP_LOAD, VK_ATTACHMENT_STORE_OP_STORE,
14950 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 +120014951 };
14952 VkAttachmentReference color = {
14953 0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
14954 };
14955 VkAttachmentReference input = {
14956 1, VK_IMAGE_LAYOUT_GENERAL,
14957 };
14958
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014959 VkSubpassDescription sd = {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 1, &input, 1, &color, nullptr, nullptr, 0, nullptr};
Chris Forbes5a9a0472016-08-22 16:02:09 +120014960
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014961 VkRenderPassCreateInfo rpci = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 2, descs, 1, &sd, 0, nullptr};
Chris Forbes5a9a0472016-08-22 16:02:09 +120014962 VkRenderPass rp;
14963 err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
14964 ASSERT_VK_SUCCESS(err);
14965
14966 // error here.
14967 pipe.CreateVKPipeline(pl, rp);
14968
14969 m_errorMonitor->VerifyFound();
14970
14971 vkDestroyRenderPass(m_device->device(), rp, nullptr);
14972 vkDestroyPipelineLayout(m_device->device(), pl, nullptr);
14973 vkDestroyDescriptorSetLayout(m_device->device(), dsl, nullptr);
14974}
14975
Chris Forbes541f7b02016-08-22 15:30:27 +120014976TEST_F(VkLayerTest, CreatePipelineInputAttachmentMissingArray) {
14977 TEST_DESCRIPTION("Test that an error is produced for a shader consuming an input attachment "
14978 "which is not included in the subpass description -- array case");
14979 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
14980 "consumes input attachment index 1 but not provided in subpass");
14981
14982 ASSERT_NO_FATAL_FAILURE(InitState());
14983
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014984 char const *vsSource = "#version 450\n"
14985 "\n"
14986 "out gl_PerVertex {\n"
14987 " vec4 gl_Position;\n"
14988 "};\n"
14989 "void main(){\n"
14990 " gl_Position = vec4(1);\n"
14991 "}\n";
14992 char const *fsSource = "#version 450\n"
14993 "\n"
14994 "layout(input_attachment_index=0, set=0, binding=0) uniform subpassInput xs[2];\n"
14995 "layout(location=0) out vec4 color;\n"
14996 "void main() {\n"
14997 " color = subpassLoad(xs[1]);\n"
14998 "}\n";
Chris Forbes541f7b02016-08-22 15:30:27 +120014999
15000 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
15001 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
15002
15003 VkPipelineObj pipe(m_device);
15004 pipe.AddShader(&vs);
15005 pipe.AddShader(&fs);
15006 pipe.AddColorAttachment();
15007 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
15008
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015009 VkDescriptorSetLayoutBinding dslb = {0, VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT, 2, VK_SHADER_STAGE_FRAGMENT_BIT, nullptr};
15010 VkDescriptorSetLayoutCreateInfo dslci = {VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dslb};
Chris Forbes541f7b02016-08-22 15:30:27 +120015011 VkDescriptorSetLayout dsl;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015012 VkResult err = vkCreateDescriptorSetLayout(m_device->device(), &dslci, nullptr, &dsl);
Chris Forbes541f7b02016-08-22 15:30:27 +120015013 ASSERT_VK_SUCCESS(err);
15014
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015015 VkPipelineLayoutCreateInfo plci = {VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dsl, 0, nullptr};
Chris Forbes541f7b02016-08-22 15:30:27 +120015016 VkPipelineLayout pl;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015017 err = vkCreatePipelineLayout(m_device->device(), &plci, nullptr, &pl);
Chris Forbes541f7b02016-08-22 15:30:27 +120015018 ASSERT_VK_SUCCESS(err);
15019
15020 // error here.
15021 pipe.CreateVKPipeline(pl, renderPass());
15022
15023 m_errorMonitor->VerifyFound();
15024
15025 vkDestroyPipelineLayout(m_device->device(), pl, nullptr);
15026 vkDestroyDescriptorSetLayout(m_device->device(), dsl, nullptr);
15027}
15028
Chris Forbes10eb9ae2016-05-31 16:09:42 +120015029TEST_F(VkLayerTest, CreateComputePipelineMissingDescriptor) {
Chris Forbes1cc79542016-07-20 11:13:44 +120015030 TEST_DESCRIPTION("Test that an error is produced for a compute pipeline consuming a "
15031 "descriptor which is not provided in the pipeline layout");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015032 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Shader uses descriptor slot 0.0");
Chris Forbes10eb9ae2016-05-31 16:09:42 +120015033
15034 ASSERT_NO_FATAL_FAILURE(InitState());
15035
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015036 char const *csSource = "#version 450\n"
15037 "\n"
15038 "layout(local_size_x=1) in;\n"
15039 "layout(set=0, binding=0) buffer block { vec4 x; };\n"
15040 "void main(){\n"
15041 " x = vec4(1);\n"
15042 "}\n";
Chris Forbes10eb9ae2016-05-31 16:09:42 +120015043
15044 VkShaderObj cs(m_device, csSource, VK_SHADER_STAGE_COMPUTE_BIT, this);
15045
15046 VkDescriptorSetObj descriptorSet(m_device);
15047 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
15048
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015049 VkComputePipelineCreateInfo cpci = {VK_STRUCTURE_TYPE_COMPUTE_PIPELINE_CREATE_INFO,
15050 nullptr,
15051 0,
15052 {VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO, nullptr, 0,
15053 VK_SHADER_STAGE_COMPUTE_BIT, cs.handle(), "main", nullptr},
15054 descriptorSet.GetPipelineLayout(),
15055 VK_NULL_HANDLE,
15056 -1};
Chris Forbes10eb9ae2016-05-31 16:09:42 +120015057
15058 VkPipeline pipe;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015059 VkResult err = vkCreateComputePipelines(m_device->device(), VK_NULL_HANDLE, 1, &cpci, nullptr, &pipe);
Chris Forbes10eb9ae2016-05-31 16:09:42 +120015060
15061 m_errorMonitor->VerifyFound();
15062
15063 if (err == VK_SUCCESS) {
15064 vkDestroyPipeline(m_device->device(), pipe, nullptr);
15065 }
15066}
15067
15068TEST_F(VkLayerTest, CreateComputePipelineMissingDescriptorUnusedPositive) {
Chris Forbes1cc79542016-07-20 11:13:44 +120015069 TEST_DESCRIPTION("Test that pipeline validation accepts a compute pipeline which declares a "
15070 "descriptor-backed resource which is not provided, but the shader does not "
15071 "statically use it. This is interesting because it requires compute pipelines "
15072 "to have a proper descriptor use walk, which they didn't for some time.");
Chris Forbes10eb9ae2016-05-31 16:09:42 +120015073 m_errorMonitor->ExpectSuccess();
15074
15075 ASSERT_NO_FATAL_FAILURE(InitState());
15076
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015077 char const *csSource = "#version 450\n"
15078 "\n"
15079 "layout(local_size_x=1) in;\n"
15080 "layout(set=0, binding=0) buffer block { vec4 x; };\n"
15081 "void main(){\n"
15082 " // x is not used.\n"
15083 "}\n";
Chris Forbes10eb9ae2016-05-31 16:09:42 +120015084
15085 VkShaderObj cs(m_device, csSource, VK_SHADER_STAGE_COMPUTE_BIT, this);
15086
15087 VkDescriptorSetObj descriptorSet(m_device);
15088 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
15089
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015090 VkComputePipelineCreateInfo cpci = {VK_STRUCTURE_TYPE_COMPUTE_PIPELINE_CREATE_INFO,
15091 nullptr,
15092 0,
15093 {VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO, nullptr, 0,
15094 VK_SHADER_STAGE_COMPUTE_BIT, cs.handle(), "main", nullptr},
15095 descriptorSet.GetPipelineLayout(),
15096 VK_NULL_HANDLE,
15097 -1};
Chris Forbes10eb9ae2016-05-31 16:09:42 +120015098
15099 VkPipeline pipe;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015100 VkResult err = vkCreateComputePipelines(m_device->device(), VK_NULL_HANDLE, 1, &cpci, nullptr, &pipe);
Chris Forbes10eb9ae2016-05-31 16:09:42 +120015101
15102 m_errorMonitor->VerifyNotFound();
15103
15104 if (err == VK_SUCCESS) {
15105 vkDestroyPipeline(m_device->device(), pipe, nullptr);
15106 }
15107}
15108
Chris Forbes22a9b092016-07-19 14:34:05 +120015109TEST_F(VkLayerTest, CreateComputePipelineDescriptorTypeMismatch) {
Chris Forbes1cc79542016-07-20 11:13:44 +120015110 TEST_DESCRIPTION("Test that an error is produced for a pipeline consuming a "
15111 "descriptor-backed resource of a mismatched type");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015112 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
15113 "but descriptor of type VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER");
Chris Forbes22a9b092016-07-19 14:34:05 +120015114
15115 ASSERT_NO_FATAL_FAILURE(InitState());
15116
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015117 VkDescriptorSetLayoutBinding binding = {0, VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, 1, VK_SHADER_STAGE_COMPUTE_BIT, nullptr};
15118 VkDescriptorSetLayoutCreateInfo dslci = {VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO, nullptr, 0, 1, &binding};
Chris Forbes22a9b092016-07-19 14:34:05 +120015119 VkDescriptorSetLayout dsl;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015120 VkResult err = vkCreateDescriptorSetLayout(m_device->device(), &dslci, nullptr, &dsl);
Chris Forbes22a9b092016-07-19 14:34:05 +120015121 ASSERT_VK_SUCCESS(err);
15122
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015123 VkPipelineLayoutCreateInfo plci = {VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dsl, 0, nullptr};
Chris Forbes22a9b092016-07-19 14:34:05 +120015124 VkPipelineLayout pl;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015125 err = vkCreatePipelineLayout(m_device->device(), &plci, nullptr, &pl);
Chris Forbes22a9b092016-07-19 14:34:05 +120015126 ASSERT_VK_SUCCESS(err);
15127
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015128 char const *csSource = "#version 450\n"
15129 "\n"
15130 "layout(local_size_x=1) in;\n"
15131 "layout(set=0, binding=0) buffer block { vec4 x; };\n"
15132 "void main() {\n"
15133 " x.x = 1.0f;\n"
15134 "}\n";
Chris Forbes22a9b092016-07-19 14:34:05 +120015135 VkShaderObj cs(m_device, csSource, VK_SHADER_STAGE_COMPUTE_BIT, this);
15136
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015137 VkComputePipelineCreateInfo cpci = {VK_STRUCTURE_TYPE_COMPUTE_PIPELINE_CREATE_INFO,
15138 nullptr,
15139 0,
15140 {VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO, nullptr, 0,
15141 VK_SHADER_STAGE_COMPUTE_BIT, cs.handle(), "main", nullptr},
15142 pl,
15143 VK_NULL_HANDLE,
15144 -1};
Chris Forbes22a9b092016-07-19 14:34:05 +120015145
15146 VkPipeline pipe;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015147 err = vkCreateComputePipelines(m_device->device(), VK_NULL_HANDLE, 1, &cpci, nullptr, &pipe);
Chris Forbes22a9b092016-07-19 14:34:05 +120015148
15149 m_errorMonitor->VerifyFound();
15150
15151 if (err == VK_SUCCESS) {
15152 vkDestroyPipeline(m_device->device(), pipe, nullptr);
15153 }
15154
15155 vkDestroyPipelineLayout(m_device->device(), pl, nullptr);
15156 vkDestroyDescriptorSetLayout(m_device->device(), dsl, nullptr);
15157}
15158
Chris Forbese10a51f2016-07-19 14:42:51 +120015159TEST_F(VkLayerTest, CreateComputePipelineCombinedImageSamplerConsumedAsSampler) {
Chris Forbes1cc79542016-07-20 11:13:44 +120015160 TEST_DESCRIPTION("Test that pipeline validation accepts a shader consuming only the "
15161 "sampler portion of a combined image + sampler");
Chris Forbese10a51f2016-07-19 14:42:51 +120015162 m_errorMonitor->ExpectSuccess();
15163
15164 ASSERT_NO_FATAL_FAILURE(InitState());
15165
15166 VkDescriptorSetLayoutBinding bindings[] = {
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015167 {0, VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, 1, VK_SHADER_STAGE_COMPUTE_BIT, nullptr},
15168 {1, VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE, 1, VK_SHADER_STAGE_COMPUTE_BIT, nullptr},
15169 {2, VK_DESCRIPTOR_TYPE_STORAGE_BUFFER, 1, VK_SHADER_STAGE_COMPUTE_BIT, nullptr},
Chris Forbese10a51f2016-07-19 14:42:51 +120015170 };
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015171 VkDescriptorSetLayoutCreateInfo dslci = {VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO, nullptr, 0, 3, bindings};
Chris Forbese10a51f2016-07-19 14:42:51 +120015172 VkDescriptorSetLayout dsl;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015173 VkResult err = vkCreateDescriptorSetLayout(m_device->device(), &dslci, nullptr, &dsl);
Chris Forbese10a51f2016-07-19 14:42:51 +120015174 ASSERT_VK_SUCCESS(err);
15175
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015176 VkPipelineLayoutCreateInfo plci = {VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dsl, 0, nullptr};
Chris Forbese10a51f2016-07-19 14:42:51 +120015177 VkPipelineLayout pl;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015178 err = vkCreatePipelineLayout(m_device->device(), &plci, nullptr, &pl);
Chris Forbese10a51f2016-07-19 14:42:51 +120015179 ASSERT_VK_SUCCESS(err);
15180
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015181 char const *csSource = "#version 450\n"
15182 "\n"
15183 "layout(local_size_x=1) in;\n"
15184 "layout(set=0, binding=0) uniform sampler s;\n"
15185 "layout(set=0, binding=1) uniform texture2D t;\n"
15186 "layout(set=0, binding=2) buffer block { vec4 x; };\n"
15187 "void main() {\n"
15188 " x = texture(sampler2D(t, s), vec2(0));\n"
15189 "}\n";
Chris Forbese10a51f2016-07-19 14:42:51 +120015190 VkShaderObj cs(m_device, csSource, VK_SHADER_STAGE_COMPUTE_BIT, this);
15191
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015192 VkComputePipelineCreateInfo cpci = {VK_STRUCTURE_TYPE_COMPUTE_PIPELINE_CREATE_INFO,
15193 nullptr,
15194 0,
15195 {VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO, nullptr, 0,
15196 VK_SHADER_STAGE_COMPUTE_BIT, cs.handle(), "main", nullptr},
15197 pl,
15198 VK_NULL_HANDLE,
15199 -1};
Chris Forbese10a51f2016-07-19 14:42:51 +120015200
15201 VkPipeline pipe;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015202 err = vkCreateComputePipelines(m_device->device(), VK_NULL_HANDLE, 1, &cpci, nullptr, &pipe);
Chris Forbese10a51f2016-07-19 14:42:51 +120015203
15204 m_errorMonitor->VerifyNotFound();
15205
15206 if (err == VK_SUCCESS) {
15207 vkDestroyPipeline(m_device->device(), pipe, nullptr);
15208 }
15209
15210 vkDestroyPipelineLayout(m_device->device(), pl, nullptr);
15211 vkDestroyDescriptorSetLayout(m_device->device(), dsl, nullptr);
15212}
15213
Chris Forbes91c3b2a2016-07-19 14:46:38 +120015214TEST_F(VkLayerTest, CreateComputePipelineCombinedImageSamplerConsumedAsImage) {
Chris Forbes1cc79542016-07-20 11:13:44 +120015215 TEST_DESCRIPTION("Test that pipeline validation accepts a shader consuming only the "
15216 "image portion of a combined image + sampler");
Chris Forbes91c3b2a2016-07-19 14:46:38 +120015217 m_errorMonitor->ExpectSuccess();
15218
15219 ASSERT_NO_FATAL_FAILURE(InitState());
15220
15221 VkDescriptorSetLayoutBinding bindings[] = {
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015222 {0, VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, 1, VK_SHADER_STAGE_COMPUTE_BIT, nullptr},
15223 {1, VK_DESCRIPTOR_TYPE_SAMPLER, 1, VK_SHADER_STAGE_COMPUTE_BIT, nullptr},
15224 {2, VK_DESCRIPTOR_TYPE_STORAGE_BUFFER, 1, VK_SHADER_STAGE_COMPUTE_BIT, nullptr},
Chris Forbes91c3b2a2016-07-19 14:46:38 +120015225 };
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015226 VkDescriptorSetLayoutCreateInfo dslci = {VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO, nullptr, 0, 3, bindings};
Chris Forbes91c3b2a2016-07-19 14:46:38 +120015227 VkDescriptorSetLayout dsl;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015228 VkResult err = vkCreateDescriptorSetLayout(m_device->device(), &dslci, nullptr, &dsl);
Chris Forbes91c3b2a2016-07-19 14:46:38 +120015229 ASSERT_VK_SUCCESS(err);
15230
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015231 VkPipelineLayoutCreateInfo plci = {VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dsl, 0, nullptr};
Chris Forbes91c3b2a2016-07-19 14:46:38 +120015232 VkPipelineLayout pl;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015233 err = vkCreatePipelineLayout(m_device->device(), &plci, nullptr, &pl);
Chris Forbes91c3b2a2016-07-19 14:46:38 +120015234 ASSERT_VK_SUCCESS(err);
15235
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015236 char const *csSource = "#version 450\n"
15237 "\n"
15238 "layout(local_size_x=1) in;\n"
15239 "layout(set=0, binding=0) uniform texture2D t;\n"
15240 "layout(set=0, binding=1) uniform sampler s;\n"
15241 "layout(set=0, binding=2) buffer block { vec4 x; };\n"
15242 "void main() {\n"
15243 " x = texture(sampler2D(t, s), vec2(0));\n"
15244 "}\n";
Chris Forbes91c3b2a2016-07-19 14:46:38 +120015245 VkShaderObj cs(m_device, csSource, VK_SHADER_STAGE_COMPUTE_BIT, this);
15246
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015247 VkComputePipelineCreateInfo cpci = {VK_STRUCTURE_TYPE_COMPUTE_PIPELINE_CREATE_INFO,
15248 nullptr,
15249 0,
15250 {VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO, nullptr, 0,
15251 VK_SHADER_STAGE_COMPUTE_BIT, cs.handle(), "main", nullptr},
15252 pl,
15253 VK_NULL_HANDLE,
15254 -1};
Chris Forbes91c3b2a2016-07-19 14:46:38 +120015255
15256 VkPipeline pipe;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015257 err = vkCreateComputePipelines(m_device->device(), VK_NULL_HANDLE, 1, &cpci, nullptr, &pipe);
Chris Forbes91c3b2a2016-07-19 14:46:38 +120015258
15259 m_errorMonitor->VerifyNotFound();
15260
15261 if (err == VK_SUCCESS) {
15262 vkDestroyPipeline(m_device->device(), pipe, nullptr);
15263 }
15264
15265 vkDestroyPipelineLayout(m_device->device(), pl, nullptr);
15266 vkDestroyDescriptorSetLayout(m_device->device(), dsl, nullptr);
15267}
15268
Chris Forbes6a4991a2016-07-19 15:07:32 +120015269TEST_F(VkLayerTest, CreateComputePipelineCombinedImageSamplerConsumedAsBoth) {
Chris Forbes1cc79542016-07-20 11:13:44 +120015270 TEST_DESCRIPTION("Test that pipeline validation accepts a shader consuming "
15271 "both the sampler and the image of a combined image+sampler "
15272 "but via separate variables");
Chris Forbes6a4991a2016-07-19 15:07:32 +120015273 m_errorMonitor->ExpectSuccess();
15274
15275 ASSERT_NO_FATAL_FAILURE(InitState());
15276
15277 VkDescriptorSetLayoutBinding bindings[] = {
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015278 {0, VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, 1, VK_SHADER_STAGE_COMPUTE_BIT, nullptr},
15279 {1, VK_DESCRIPTOR_TYPE_STORAGE_BUFFER, 1, VK_SHADER_STAGE_COMPUTE_BIT, nullptr},
Chris Forbes6a4991a2016-07-19 15:07:32 +120015280 };
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015281 VkDescriptorSetLayoutCreateInfo dslci = {VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO, nullptr, 0, 2, bindings};
Chris Forbes6a4991a2016-07-19 15:07:32 +120015282 VkDescriptorSetLayout dsl;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015283 VkResult err = vkCreateDescriptorSetLayout(m_device->device(), &dslci, nullptr, &dsl);
Chris Forbes6a4991a2016-07-19 15:07:32 +120015284 ASSERT_VK_SUCCESS(err);
15285
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015286 VkPipelineLayoutCreateInfo plci = {VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dsl, 0, nullptr};
Chris Forbes6a4991a2016-07-19 15:07:32 +120015287 VkPipelineLayout pl;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015288 err = vkCreatePipelineLayout(m_device->device(), &plci, nullptr, &pl);
Chris Forbes6a4991a2016-07-19 15:07:32 +120015289 ASSERT_VK_SUCCESS(err);
15290
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015291 char const *csSource = "#version 450\n"
15292 "\n"
15293 "layout(local_size_x=1) in;\n"
15294 "layout(set=0, binding=0) uniform texture2D t;\n"
15295 "layout(set=0, binding=0) uniform sampler s; // both binding 0!\n"
15296 "layout(set=0, binding=1) buffer block { vec4 x; };\n"
15297 "void main() {\n"
15298 " x = texture(sampler2D(t, s), vec2(0));\n"
15299 "}\n";
Chris Forbes6a4991a2016-07-19 15:07:32 +120015300 VkShaderObj cs(m_device, csSource, VK_SHADER_STAGE_COMPUTE_BIT, this);
15301
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015302 VkComputePipelineCreateInfo cpci = {VK_STRUCTURE_TYPE_COMPUTE_PIPELINE_CREATE_INFO,
15303 nullptr,
15304 0,
15305 {VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO, nullptr, 0,
15306 VK_SHADER_STAGE_COMPUTE_BIT, cs.handle(), "main", nullptr},
15307 pl,
15308 VK_NULL_HANDLE,
15309 -1};
Chris Forbes6a4991a2016-07-19 15:07:32 +120015310
15311 VkPipeline pipe;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015312 err = vkCreateComputePipelines(m_device->device(), VK_NULL_HANDLE, 1, &cpci, nullptr, &pipe);
Chris Forbes6a4991a2016-07-19 15:07:32 +120015313
15314 m_errorMonitor->VerifyNotFound();
15315
15316 if (err == VK_SUCCESS) {
15317 vkDestroyPipeline(m_device->device(), pipe, nullptr);
15318 }
15319
15320 vkDestroyPipelineLayout(m_device->device(), pl, nullptr);
15321 vkDestroyDescriptorSetLayout(m_device->device(), dsl, nullptr);
15322}
15323
Chris Forbes50020592016-07-27 13:52:41 +120015324TEST_F(VkLayerTest, DrawTimeImageViewTypeMismatchWithPipeline) {
15325 TEST_DESCRIPTION("Test that an error is produced when an image view type "
15326 "does not match the dimensionality declared in the shader");
15327
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015328 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 +120015329
15330 ASSERT_NO_FATAL_FAILURE(InitState());
15331 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
15332
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015333 char const *vsSource = "#version 450\n"
15334 "\n"
15335 "out gl_PerVertex { vec4 gl_Position; };\n"
15336 "void main() { gl_Position = vec4(0); }\n";
15337 char const *fsSource = "#version 450\n"
15338 "\n"
15339 "layout(set=0, binding=0) uniform sampler3D s;\n"
15340 "layout(location=0) out vec4 color;\n"
15341 "void main() {\n"
15342 " color = texture(s, vec3(0));\n"
15343 "}\n";
Chris Forbes50020592016-07-27 13:52:41 +120015344 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
15345 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
15346
15347 VkPipelineObj pipe(m_device);
15348 pipe.AddShader(&vs);
15349 pipe.AddShader(&fs);
15350 pipe.AddColorAttachment();
15351
15352 VkTextureObj texture(m_device, nullptr);
15353 VkSamplerObj sampler(m_device);
15354
15355 VkDescriptorSetObj descriptorSet(m_device);
15356 descriptorSet.AppendSamplerTexture(&sampler, &texture);
15357 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
15358
15359 VkResult err = pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
15360 ASSERT_VK_SUCCESS(err);
15361
15362 BeginCommandBuffer();
15363
15364 m_commandBuffer->BindPipeline(pipe);
15365 m_commandBuffer->BindDescriptorSet(descriptorSet);
15366
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015367 VkViewport viewport = {0, 0, 16, 16, 0, 1};
Chris Forbes50020592016-07-27 13:52:41 +120015368 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015369 VkRect2D scissor = {{0, 0}, {16, 16}};
Chris Forbes50020592016-07-27 13:52:41 +120015370 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
15371
15372 // error produced here.
15373 vkCmdDraw(m_commandBuffer->handle(), 3, 1, 0, 0);
15374
15375 m_errorMonitor->VerifyFound();
15376
15377 EndCommandBuffer();
15378}
15379
Chris Forbes5533bfc2016-07-27 14:12:34 +120015380TEST_F(VkLayerTest, DrawTimeImageMultisampleMismatchWithPipeline) {
15381 TEST_DESCRIPTION("Test that an error is produced when a multisampled images "
15382 "are consumed via singlesample images types in the shader, or vice versa.");
15383
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015384 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "requires bound image to have multiple samples");
Chris Forbes5533bfc2016-07-27 14:12:34 +120015385
15386 ASSERT_NO_FATAL_FAILURE(InitState());
15387 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
15388
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015389 char const *vsSource = "#version 450\n"
15390 "\n"
15391 "out gl_PerVertex { vec4 gl_Position; };\n"
15392 "void main() { gl_Position = vec4(0); }\n";
15393 char const *fsSource = "#version 450\n"
15394 "\n"
15395 "layout(set=0, binding=0) uniform sampler2DMS s;\n"
15396 "layout(location=0) out vec4 color;\n"
15397 "void main() {\n"
15398 " color = texelFetch(s, ivec2(0), 0);\n"
15399 "}\n";
Chris Forbes5533bfc2016-07-27 14:12:34 +120015400 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
15401 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
15402
15403 VkPipelineObj pipe(m_device);
15404 pipe.AddShader(&vs);
15405 pipe.AddShader(&fs);
15406 pipe.AddColorAttachment();
15407
15408 VkTextureObj texture(m_device, nullptr);
15409 VkSamplerObj sampler(m_device);
15410
15411 VkDescriptorSetObj descriptorSet(m_device);
15412 descriptorSet.AppendSamplerTexture(&sampler, &texture);
15413 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
15414
15415 VkResult err = pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
15416 ASSERT_VK_SUCCESS(err);
15417
15418 BeginCommandBuffer();
15419
15420 m_commandBuffer->BindPipeline(pipe);
15421 m_commandBuffer->BindDescriptorSet(descriptorSet);
15422
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015423 VkViewport viewport = {0, 0, 16, 16, 0, 1};
Chris Forbes5533bfc2016-07-27 14:12:34 +120015424 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015425 VkRect2D scissor = {{0, 0}, {16, 16}};
Chris Forbes5533bfc2016-07-27 14:12:34 +120015426 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
15427
15428 // error produced here.
15429 vkCmdDraw(m_commandBuffer->handle(), 3, 1, 0, 0);
15430
15431 m_errorMonitor->VerifyFound();
15432
15433 EndCommandBuffer();
15434}
15435
Mark Lobodzinski209b5292015-09-17 09:44:05 -060015436#endif // SHADER_CHECKER_TESTS
15437
15438#if DEVICE_LIMITS_TESTS
Mark Youngc48c4c12016-04-11 14:26:49 -060015439TEST_F(VkLayerTest, CreateImageLimitsViolationMaxWidth) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015440 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "CreateImage extents exceed allowable limits for format");
Mark Lobodzinski6f2274e2015-09-22 09:33:21 -060015441
15442 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinski6f2274e2015-09-22 09:33:21 -060015443
15444 // Create an image
15445 VkImage image;
15446
Karl Schultz6addd812016-02-02 17:17:23 -070015447 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
15448 const int32_t tex_width = 32;
15449 const int32_t tex_height = 32;
Mark Lobodzinski6f2274e2015-09-22 09:33:21 -060015450
15451 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070015452 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
15453 image_create_info.pNext = NULL;
15454 image_create_info.imageType = VK_IMAGE_TYPE_2D;
15455 image_create_info.format = tex_format;
15456 image_create_info.extent.width = tex_width;
Mark Lobodzinski6f2274e2015-09-22 09:33:21 -060015457 image_create_info.extent.height = tex_height;
Karl Schultz6addd812016-02-02 17:17:23 -070015458 image_create_info.extent.depth = 1;
15459 image_create_info.mipLevels = 1;
15460 image_create_info.arrayLayers = 1;
15461 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
15462 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
15463 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
15464 image_create_info.flags = 0;
Mark Lobodzinski6f2274e2015-09-22 09:33:21 -060015465
15466 // Introduce error by sending down a bogus width extent
15467 image_create_info.extent.width = 65536;
Chia-I Wuf7458c52015-10-26 21:10:41 +080015468 vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
Mark Lobodzinski6f2274e2015-09-22 09:33:21 -060015469
Chris Forbes8f36a8a2016-04-07 13:21:07 +120015470 m_errorMonitor->VerifyFound();
Mark Lobodzinski6f2274e2015-09-22 09:33:21 -060015471}
15472
Mark Youngc48c4c12016-04-11 14:26:49 -060015473TEST_F(VkLayerTest, CreateImageLimitsViolationMinWidth) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015474 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
15475 "CreateImage extents is 0 for at least one required dimension");
Mark Youngc48c4c12016-04-11 14:26:49 -060015476
15477 ASSERT_NO_FATAL_FAILURE(InitState());
15478
15479 // Create an image
15480 VkImage image;
15481
15482 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
15483 const int32_t tex_width = 32;
15484 const int32_t tex_height = 32;
15485
15486 VkImageCreateInfo image_create_info = {};
15487 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
15488 image_create_info.pNext = NULL;
15489 image_create_info.imageType = VK_IMAGE_TYPE_2D;
15490 image_create_info.format = tex_format;
15491 image_create_info.extent.width = tex_width;
15492 image_create_info.extent.height = tex_height;
15493 image_create_info.extent.depth = 1;
15494 image_create_info.mipLevels = 1;
15495 image_create_info.arrayLayers = 1;
15496 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
15497 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
15498 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
15499 image_create_info.flags = 0;
15500
15501 // Introduce error by sending down a bogus width extent
15502 image_create_info.extent.width = 0;
15503 vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
15504
15505 m_errorMonitor->VerifyFound();
15506}
Mark Lobodzinski209b5292015-09-17 09:44:05 -060015507#endif // DEVICE_LIMITS_TESTS
Chris Forbesa36d69e2015-05-25 11:13:44 +120015508
Tobin Ehliscde08892015-09-22 10:11:37 -060015509#if IMAGE_TESTS
Mark Lobodzinskidf4c57d2016-08-05 11:47:16 -060015510TEST_F(VkLayerTest, AttachmentDescriptionUndefinedFormat) {
15511 TEST_DESCRIPTION("Create a render pass with an attachment description "
15512 "format set to VK_FORMAT_UNDEFINED");
15513
15514 ASSERT_NO_FATAL_FAILURE(InitState());
15515 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
15516
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015517 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "format is VK_FORMAT_UNDEFINED");
Mark Lobodzinskidf4c57d2016-08-05 11:47:16 -060015518
15519 VkAttachmentReference color_attach = {};
15520 color_attach.layout = VK_IMAGE_LAYOUT_GENERAL;
15521 color_attach.attachment = 0;
15522 VkSubpassDescription subpass = {};
15523 subpass.colorAttachmentCount = 1;
15524 subpass.pColorAttachments = &color_attach;
15525
15526 VkRenderPassCreateInfo rpci = {};
15527 rpci.subpassCount = 1;
15528 rpci.pSubpasses = &subpass;
15529 rpci.attachmentCount = 1;
15530 VkAttachmentDescription attach_desc = {};
15531 attach_desc.format = VK_FORMAT_UNDEFINED;
15532 rpci.pAttachments = &attach_desc;
15533 rpci.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
15534 VkRenderPass rp;
15535 VkResult result = vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
15536
15537 m_errorMonitor->VerifyFound();
15538
15539 if (result == VK_SUCCESS) {
15540 vkDestroyRenderPass(m_device->device(), rp, NULL);
15541 }
15542}
15543
Karl Schultz6addd812016-02-02 17:17:23 -070015544TEST_F(VkLayerTest, InvalidImageView) {
15545 VkResult err;
Tobin Ehliscde08892015-09-22 10:11:37 -060015546
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015547 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "vkCreateImageView called with baseMipLevel 10 ");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060015548
Tobin Ehliscde08892015-09-22 10:11:37 -060015549 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehliscde08892015-09-22 10:11:37 -060015550
Mike Stroyana3082432015-09-25 13:39:21 -060015551 // Create an image and try to create a view with bad baseMipLevel
Karl Schultz6addd812016-02-02 17:17:23 -070015552 VkImage image;
Tobin Ehliscde08892015-09-22 10:11:37 -060015553
Karl Schultz6addd812016-02-02 17:17:23 -070015554 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
15555 const int32_t tex_width = 32;
15556 const int32_t tex_height = 32;
Tobin Ehliscde08892015-09-22 10:11:37 -060015557
15558 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070015559 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
15560 image_create_info.pNext = NULL;
15561 image_create_info.imageType = VK_IMAGE_TYPE_2D;
15562 image_create_info.format = tex_format;
15563 image_create_info.extent.width = tex_width;
15564 image_create_info.extent.height = tex_height;
15565 image_create_info.extent.depth = 1;
15566 image_create_info.mipLevels = 1;
15567 image_create_info.arrayLayers = 1;
15568 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
15569 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
15570 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
15571 image_create_info.flags = 0;
Tobin Ehliscde08892015-09-22 10:11:37 -060015572
Chia-I Wuf7458c52015-10-26 21:10:41 +080015573 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
Tobin Ehliscde08892015-09-22 10:11:37 -060015574 ASSERT_VK_SUCCESS(err);
15575
15576 VkImageViewCreateInfo image_view_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070015577 image_view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
15578 image_view_create_info.image = image;
15579 image_view_create_info.viewType = VK_IMAGE_VIEW_TYPE_2D;
15580 image_view_create_info.format = tex_format;
15581 image_view_create_info.subresourceRange.layerCount = 1;
15582 image_view_create_info.subresourceRange.baseMipLevel = 10; // cause an error
15583 image_view_create_info.subresourceRange.levelCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015584 image_view_create_info.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Tobin Ehliscde08892015-09-22 10:11:37 -060015585
15586 VkImageView view;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015587 err = vkCreateImageView(m_device->device(), &image_view_create_info, NULL, &view);
Tobin Ehliscde08892015-09-22 10:11:37 -060015588
Chris Forbes8f36a8a2016-04-07 13:21:07 +120015589 m_errorMonitor->VerifyFound();
Tony Barbourdf4c0042016-06-01 15:55:43 -060015590 vkDestroyImage(m_device->device(), image, NULL);
Tobin Ehliscde08892015-09-22 10:11:37 -060015591}
Mike Stroyana3082432015-09-25 13:39:21 -060015592
Mark Youngd339ba32016-05-30 13:28:35 -060015593TEST_F(VkLayerTest, CreateImageViewNoMemoryBoundToImage) {
15594 VkResult err;
15595
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015596 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "used without first calling vkBindImageMemory");
Mark Youngd339ba32016-05-30 13:28:35 -060015597
15598 ASSERT_NO_FATAL_FAILURE(InitState());
15599
15600 // Create an image and try to create a view with no memory backing the image
15601 VkImage image;
15602
15603 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
15604 const int32_t tex_width = 32;
15605 const int32_t tex_height = 32;
15606
15607 VkImageCreateInfo image_create_info = {};
15608 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
15609 image_create_info.pNext = NULL;
15610 image_create_info.imageType = VK_IMAGE_TYPE_2D;
15611 image_create_info.format = tex_format;
15612 image_create_info.extent.width = tex_width;
15613 image_create_info.extent.height = tex_height;
15614 image_create_info.extent.depth = 1;
15615 image_create_info.mipLevels = 1;
15616 image_create_info.arrayLayers = 1;
15617 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
15618 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
15619 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
15620 image_create_info.flags = 0;
15621
15622 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
15623 ASSERT_VK_SUCCESS(err);
15624
15625 VkImageViewCreateInfo image_view_create_info = {};
15626 image_view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
15627 image_view_create_info.image = image;
15628 image_view_create_info.viewType = VK_IMAGE_VIEW_TYPE_2D;
15629 image_view_create_info.format = tex_format;
15630 image_view_create_info.subresourceRange.layerCount = 1;
15631 image_view_create_info.subresourceRange.baseMipLevel = 0;
15632 image_view_create_info.subresourceRange.levelCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015633 image_view_create_info.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mark Youngd339ba32016-05-30 13:28:35 -060015634
15635 VkImageView view;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015636 err = vkCreateImageView(m_device->device(), &image_view_create_info, NULL, &view);
Mark Youngd339ba32016-05-30 13:28:35 -060015637
15638 m_errorMonitor->VerifyFound();
15639 vkDestroyImage(m_device->device(), image, NULL);
15640 // If last error is success, it still created the view, so delete it.
15641 if (err == VK_SUCCESS) {
15642 vkDestroyImageView(m_device->device(), view, NULL);
15643 }
Mark Youngd339ba32016-05-30 13:28:35 -060015644}
15645
Karl Schultz6addd812016-02-02 17:17:23 -070015646TEST_F(VkLayerTest, InvalidImageViewAspect) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015647 TEST_DESCRIPTION("Create an image and try to create a view with an invalid aspectMask");
15648 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "vkCreateImageView: Color image "
15649 "formats must have ONLY the "
15650 "VK_IMAGE_ASPECT_COLOR_BIT set");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060015651
Mark Lobodzinskidc86b852015-10-23 14:20:31 -060015652 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinskidc86b852015-10-23 14:20:31 -060015653
Karl Schultz6addd812016-02-02 17:17:23 -070015654 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
Tobin Ehlis1f567a22016-05-25 16:15:18 -060015655 VkImageObj image(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015656 image.init(32, 32, tex_format, VK_IMAGE_USAGE_SAMPLED_BIT, VK_IMAGE_TILING_LINEAR, 0);
Tobin Ehlis1f567a22016-05-25 16:15:18 -060015657 ASSERT_TRUE(image.initialized());
Mark Lobodzinskidc86b852015-10-23 14:20:31 -060015658
15659 VkImageViewCreateInfo image_view_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070015660 image_view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
Tobin Ehlis1f567a22016-05-25 16:15:18 -060015661 image_view_create_info.image = image.handle();
Karl Schultz6addd812016-02-02 17:17:23 -070015662 image_view_create_info.viewType = VK_IMAGE_VIEW_TYPE_2D;
15663 image_view_create_info.format = tex_format;
15664 image_view_create_info.subresourceRange.baseMipLevel = 0;
15665 image_view_create_info.subresourceRange.levelCount = 1;
15666 // Cause an error by setting an invalid image aspect
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015667 image_view_create_info.subresourceRange.aspectMask = VK_IMAGE_ASPECT_METADATA_BIT;
Mark Lobodzinskidc86b852015-10-23 14:20:31 -060015668
15669 VkImageView view;
Tobin Ehlis1f567a22016-05-25 16:15:18 -060015670 vkCreateImageView(m_device->device(), &image_view_create_info, NULL, &view);
Mark Lobodzinskidc86b852015-10-23 14:20:31 -060015671
Chris Forbes8f36a8a2016-04-07 13:21:07 +120015672 m_errorMonitor->VerifyFound();
Mark Lobodzinskidc86b852015-10-23 14:20:31 -060015673}
15674
Mark Lobodzinskidb117632016-03-31 10:45:56 -060015675TEST_F(VkLayerTest, CopyImageLayerCountMismatch) {
Karl Schultz6addd812016-02-02 17:17:23 -070015676 VkResult err;
15677 bool pass;
Mike Stroyana3082432015-09-25 13:39:21 -060015678
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015679 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
15680 "vkCmdCopyImage: number of layers in source and destination subresources for pRegions");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060015681
Mike Stroyana3082432015-09-25 13:39:21 -060015682 ASSERT_NO_FATAL_FAILURE(InitState());
Mike Stroyana3082432015-09-25 13:39:21 -060015683
15684 // Create two images of different types and try to copy between them
Karl Schultz6addd812016-02-02 17:17:23 -070015685 VkImage srcImage;
15686 VkImage dstImage;
15687 VkDeviceMemory srcMem;
15688 VkDeviceMemory destMem;
15689 VkMemoryRequirements memReqs;
Mike Stroyana3082432015-09-25 13:39:21 -060015690
15691 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070015692 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
15693 image_create_info.pNext = NULL;
15694 image_create_info.imageType = VK_IMAGE_TYPE_2D;
15695 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
15696 image_create_info.extent.width = 32;
15697 image_create_info.extent.height = 32;
15698 image_create_info.extent.depth = 1;
15699 image_create_info.mipLevels = 1;
Mark Lobodzinskidb117632016-03-31 10:45:56 -060015700 image_create_info.arrayLayers = 4;
Karl Schultz6addd812016-02-02 17:17:23 -070015701 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
15702 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
15703 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
15704 image_create_info.flags = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060015705
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015706 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
Mike Stroyana3082432015-09-25 13:39:21 -060015707 ASSERT_VK_SUCCESS(err);
15708
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015709 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
Mike Stroyana3082432015-09-25 13:39:21 -060015710 ASSERT_VK_SUCCESS(err);
15711
15712 // Allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015713 VkMemoryAllocateInfo memAlloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -070015714 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
15715 memAlloc.pNext = NULL;
15716 memAlloc.allocationSize = 0;
15717 memAlloc.memoryTypeIndex = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060015718
Courtney Goeltzenleuchter06d89472015-10-20 16:40:38 -060015719 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060015720 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015721 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060015722 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015723 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
Mike Stroyana3082432015-09-25 13:39:21 -060015724 ASSERT_VK_SUCCESS(err);
15725
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015726 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060015727 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015728 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Mike Stroyana3082432015-09-25 13:39:21 -060015729 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015730 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
Mike Stroyana3082432015-09-25 13:39:21 -060015731 ASSERT_VK_SUCCESS(err);
15732
15733 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
15734 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015735 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
Mike Stroyana3082432015-09-25 13:39:21 -060015736 ASSERT_VK_SUCCESS(err);
15737
15738 BeginCommandBuffer();
15739 VkImageCopy copyRegion;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080015740 copyRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060015741 copyRegion.srcSubresource.mipLevel = 0;
Courtney Goeltzenleuchter8367ce02015-10-16 09:46:00 -060015742 copyRegion.srcSubresource.baseArrayLayer = 0;
Mark Lobodzinskidb117632016-03-31 10:45:56 -060015743 copyRegion.srcSubresource.layerCount = 1;
Mike Stroyana3082432015-09-25 13:39:21 -060015744 copyRegion.srcOffset.x = 0;
15745 copyRegion.srcOffset.y = 0;
15746 copyRegion.srcOffset.z = 0;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080015747 copyRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015748 copyRegion.dstSubresource.mipLevel = 0;
15749 copyRegion.dstSubresource.baseArrayLayer = 0;
Mark Lobodzinskidb117632016-03-31 10:45:56 -060015750 // Introduce failure by forcing the dst layerCount to differ from src
15751 copyRegion.dstSubresource.layerCount = 3;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015752 copyRegion.dstOffset.x = 0;
15753 copyRegion.dstOffset.y = 0;
15754 copyRegion.dstOffset.z = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060015755 copyRegion.extent.width = 1;
15756 copyRegion.extent.height = 1;
15757 copyRegion.extent.depth = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015758 m_commandBuffer->CopyImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, VK_IMAGE_LAYOUT_GENERAL, 1, &copyRegion);
Mike Stroyana3082432015-09-25 13:39:21 -060015759 EndCommandBuffer();
15760
Chris Forbes8f36a8a2016-04-07 13:21:07 +120015761 m_errorMonitor->VerifyFound();
Mike Stroyana3082432015-09-25 13:39:21 -060015762
Chia-I Wuf7458c52015-10-26 21:10:41 +080015763 vkDestroyImage(m_device->device(), srcImage, NULL);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015764 vkDestroyImage(m_device->device(), dstImage, NULL);
Chia-I Wuf7458c52015-10-26 21:10:41 +080015765 vkFreeMemory(m_device->device(), srcMem, NULL);
15766 vkFreeMemory(m_device->device(), destMem, NULL);
Mike Stroyana3082432015-09-25 13:39:21 -060015767}
15768
Tony Barbourd6673642016-05-05 14:46:39 -060015769TEST_F(VkLayerTest, ImageLayerUnsupportedFormat) {
15770
15771 TEST_DESCRIPTION("Creating images with unsuported formats ");
15772
15773 ASSERT_NO_FATAL_FAILURE(InitState());
15774 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
15775 VkImageObj image(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015776 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 -060015777 VK_IMAGE_TILING_OPTIMAL, 0);
15778 ASSERT_TRUE(image.initialized());
15779
Mark Lobodzinskiba5c6862016-05-17 08:14:00 -060015780 // Create image with unsupported format - Expect FORMAT_UNSUPPORTED
15781 VkImageCreateInfo image_create_info;
15782 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
15783 image_create_info.pNext = NULL;
15784 image_create_info.imageType = VK_IMAGE_TYPE_2D;
15785 image_create_info.format = VK_FORMAT_UNDEFINED;
15786 image_create_info.extent.width = 32;
15787 image_create_info.extent.height = 32;
15788 image_create_info.extent.depth = 1;
15789 image_create_info.mipLevels = 1;
15790 image_create_info.arrayLayers = 1;
15791 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
15792 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
15793 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
15794 image_create_info.flags = 0;
15795
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015796 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
15797 "vkCreateImage: VkFormat for image must not be VK_FORMAT_UNDEFINED");
Mark Lobodzinskiba5c6862016-05-17 08:14:00 -060015798
15799 VkImage localImage;
15800 vkCreateImage(m_device->handle(), &image_create_info, NULL, &localImage);
15801 m_errorMonitor->VerifyFound();
15802
Tony Barbourd6673642016-05-05 14:46:39 -060015803 VkFormat unsupported = VK_FORMAT_UNDEFINED;
Mark Lobodzinskiba5c6862016-05-17 08:14:00 -060015804 // Look for a format that is COMPLETELY unsupported with this hardware
Tony Barbourd6673642016-05-05 14:46:39 -060015805 for (int f = VK_FORMAT_BEGIN_RANGE; f <= VK_FORMAT_END_RANGE; f++) {
15806 VkFormat format = static_cast<VkFormat>(f);
15807 VkFormatProperties fProps = m_device->format_properties(format);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015808 if (format != VK_FORMAT_UNDEFINED && fProps.linearTilingFeatures == 0 && fProps.optimalTilingFeatures == 0) {
Tony Barbourd6673642016-05-05 14:46:39 -060015809 unsupported = format;
15810 break;
15811 }
15812 }
Mark Lobodzinskiba5c6862016-05-17 08:14:00 -060015813
Tony Barbourd6673642016-05-05 14:46:39 -060015814 if (unsupported != VK_FORMAT_UNDEFINED) {
Tony Barbourd6673642016-05-05 14:46:39 -060015815 image_create_info.format = unsupported;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015816 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "is an unsupported format");
Tony Barbourd6673642016-05-05 14:46:39 -060015817
Mark Lobodzinskiba5c6862016-05-17 08:14:00 -060015818 vkCreateImage(m_device->handle(), &image_create_info, NULL, &localImage);
Tony Barbourd6673642016-05-05 14:46:39 -060015819 m_errorMonitor->VerifyFound();
15820 }
15821}
15822
15823TEST_F(VkLayerTest, ImageLayerViewTests) {
15824 VkResult ret;
15825 TEST_DESCRIPTION("Passing bad parameters to CreateImageView");
15826
15827 ASSERT_NO_FATAL_FAILURE(InitState());
15828
15829 VkImageObj image(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015830 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 -060015831 VK_IMAGE_TILING_OPTIMAL, 0);
15832 ASSERT_TRUE(image.initialized());
15833
15834 VkImageView imgView;
15835 VkImageViewCreateInfo imgViewInfo = {};
15836 imgViewInfo.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
15837 imgViewInfo.image = image.handle();
15838 imgViewInfo.viewType = VK_IMAGE_VIEW_TYPE_2D;
15839 imgViewInfo.format = VK_FORMAT_B8G8R8A8_UNORM;
15840 imgViewInfo.subresourceRange.layerCount = 1;
15841 imgViewInfo.subresourceRange.baseMipLevel = 0;
15842 imgViewInfo.subresourceRange.levelCount = 1;
15843 imgViewInfo.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
15844
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015845 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "vkCreateImageView called with baseMipLevel");
Tony Barbourd6673642016-05-05 14:46:39 -060015846 // View can't have baseMipLevel >= image's mipLevels - Expect
15847 // VIEW_CREATE_ERROR
15848 imgViewInfo.subresourceRange.baseMipLevel = 1;
15849 vkCreateImageView(m_device->handle(), &imgViewInfo, NULL, &imgView);
15850 m_errorMonitor->VerifyFound();
15851 imgViewInfo.subresourceRange.baseMipLevel = 0;
15852
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015853 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "vkCreateImageView called with baseArrayLayer");
Tony Barbourd6673642016-05-05 14:46:39 -060015854 // View can't have baseArrayLayer >= image's arraySize - Expect
15855 // VIEW_CREATE_ERROR
15856 imgViewInfo.subresourceRange.baseArrayLayer = 1;
15857 vkCreateImageView(m_device->handle(), &imgViewInfo, NULL, &imgView);
15858 m_errorMonitor->VerifyFound();
15859 imgViewInfo.subresourceRange.baseArrayLayer = 0;
15860
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015861 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "vkCreateImageView called with 0 in "
15862 "pCreateInfo->subresourceRange."
15863 "levelCount");
Tony Barbourd6673642016-05-05 14:46:39 -060015864 // View's levelCount can't be 0 - Expect VIEW_CREATE_ERROR
15865 imgViewInfo.subresourceRange.levelCount = 0;
15866 vkCreateImageView(m_device->handle(), &imgViewInfo, NULL, &imgView);
15867 m_errorMonitor->VerifyFound();
15868 imgViewInfo.subresourceRange.levelCount = 1;
15869
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015870 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "vkCreateImageView called with 0 in "
15871 "pCreateInfo->subresourceRange."
15872 "layerCount");
Tony Barbourd6673642016-05-05 14:46:39 -060015873 // View's layerCount can't be 0 - Expect VIEW_CREATE_ERROR
15874 imgViewInfo.subresourceRange.layerCount = 0;
15875 vkCreateImageView(m_device->handle(), &imgViewInfo, NULL, &imgView);
15876 m_errorMonitor->VerifyFound();
15877 imgViewInfo.subresourceRange.layerCount = 1;
15878
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015879 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "but both must be color formats");
Tony Barbourd6673642016-05-05 14:46:39 -060015880 // Can't use depth format for view into color image - Expect INVALID_FORMAT
15881 imgViewInfo.format = VK_FORMAT_D24_UNORM_S8_UINT;
15882 vkCreateImageView(m_device->handle(), &imgViewInfo, NULL, &imgView);
15883 m_errorMonitor->VerifyFound();
15884 imgViewInfo.format = VK_FORMAT_B8G8R8A8_UNORM;
15885
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015886 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Formats MUST be IDENTICAL unless "
15887 "VK_IMAGE_CREATE_MUTABLE_FORMAT BIT "
15888 "was set on image creation.");
Tony Barbourd6673642016-05-05 14:46:39 -060015889 // Same compatibility class but no MUTABLE_FORMAT bit - Expect
15890 // VIEW_CREATE_ERROR
15891 imgViewInfo.format = VK_FORMAT_B8G8R8A8_UINT;
15892 vkCreateImageView(m_device->handle(), &imgViewInfo, NULL, &imgView);
15893 m_errorMonitor->VerifyFound();
15894 imgViewInfo.format = VK_FORMAT_B8G8R8A8_UNORM;
15895
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015896 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "can support ImageViews with "
15897 "differing formats but they must be "
15898 "in the same compatibility class.");
Tony Barbourd6673642016-05-05 14:46:39 -060015899 // Have MUTABLE_FORMAT bit but not in same compatibility class - Expect
15900 // VIEW_CREATE_ERROR
15901 VkImageCreateInfo mutImgInfo = image.create_info();
15902 VkImage mutImage;
15903 mutImgInfo.format = VK_FORMAT_R8_UINT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015904 assert(m_device->format_properties(VK_FORMAT_R8_UINT).optimalTilingFeatures & VK_FORMAT_FEATURE_COLOR_ATTACHMENT_BIT);
Tony Barbourd6673642016-05-05 14:46:39 -060015905 mutImgInfo.flags = VK_IMAGE_CREATE_MUTABLE_FORMAT_BIT;
15906 mutImgInfo.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
15907 ret = vkCreateImage(m_device->handle(), &mutImgInfo, NULL, &mutImage);
15908 ASSERT_VK_SUCCESS(ret);
15909 imgViewInfo.image = mutImage;
15910 vkCreateImageView(m_device->handle(), &imgViewInfo, NULL, &imgView);
15911 m_errorMonitor->VerifyFound();
15912 imgViewInfo.image = image.handle();
15913 vkDestroyImage(m_device->handle(), mutImage, NULL);
15914}
15915
15916TEST_F(VkLayerTest, MiscImageLayerTests) {
15917
15918 TEST_DESCRIPTION("Image layer tests that don't belong elsewhare");
15919
15920 ASSERT_NO_FATAL_FAILURE(InitState());
15921
15922 VkImageObj image(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015923 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 -060015924 VK_IMAGE_TILING_OPTIMAL, 0);
15925 ASSERT_TRUE(image.initialized());
15926
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015927 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "number of layers in image subresource is zero");
Tony Barbourd6673642016-05-05 14:46:39 -060015928 vk_testing::Buffer buffer;
15929 VkMemoryPropertyFlags reqs = 0;
15930 buffer.init_as_src(*m_device, 128 * 128 * 4, reqs);
15931 VkBufferImageCopy region = {};
15932 region.bufferRowLength = 128;
15933 region.bufferImageHeight = 128;
15934 region.imageSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
15935 // layerCount can't be 0 - Expect MISMATCHED_IMAGE_ASPECT
15936 region.imageSubresource.layerCount = 0;
15937 region.imageExtent.height = 4;
15938 region.imageExtent.width = 4;
15939 region.imageExtent.depth = 1;
15940 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015941 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer.handle(), image.handle(),
15942 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, &region);
Tony Barbourd6673642016-05-05 14:46:39 -060015943 m_errorMonitor->VerifyFound();
15944 region.imageSubresource.layerCount = 1;
15945
Mark Lobodzinski7d8cf142016-08-19 10:53:26 -060015946 // BufferOffset must be a multiple of the calling command's VkImage parameter's texel size
15947 // Introduce failure by setting bufferOffset to 1 and 1/2 texels
15948 region.bufferOffset = 6;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015949 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "must be a multiple of this format's texel size");
15950 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer.handle(), image.handle(),
15951 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, &region);
Mark Lobodzinski7d8cf142016-08-19 10:53:26 -060015952 m_errorMonitor->VerifyFound();
15953
15954 // BufferOffset must be a multiple of 4
15955 // Introduce failure by setting bufferOffset to a value not divisible by 4
15956 region.bufferOffset = 6;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015957 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "must be a multiple of 4");
15958 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer.handle(), image.handle(),
15959 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, &region);
Mark Lobodzinski7d8cf142016-08-19 10:53:26 -060015960 m_errorMonitor->VerifyFound();
15961
15962 // BufferRowLength must be 0, or greater than or equal to the width member of imageExtent
15963 region.bufferOffset = 0;
15964 region.imageExtent.height = 128;
15965 region.imageExtent.width = 128;
15966 // Introduce failure by setting bufferRowLength > 0 but less than width
15967 region.bufferRowLength = 64;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015968 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
15969 "must be zero or greater-than-or-equal-to imageExtent.width");
15970 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer.handle(), image.handle(),
15971 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, &region);
Mark Lobodzinski7d8cf142016-08-19 10:53:26 -060015972 m_errorMonitor->VerifyFound();
15973
15974 // BufferImageHeight must be 0, or greater than or equal to the height member of imageExtent
15975 region.bufferRowLength = 128;
15976 // Introduce failure by setting bufferRowHeight > 0 but less than height
15977 region.bufferImageHeight = 64;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015978 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
15979 "must be zero or greater-than-or-equal-to imageExtent.height");
15980 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer.handle(), image.handle(),
15981 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, &region);
Mark Lobodzinski7d8cf142016-08-19 10:53:26 -060015982 m_errorMonitor->VerifyFound();
15983
15984 region.bufferImageHeight = 128;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015985 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "aspectMasks for each region must "
15986 "specify only COLOR or DEPTH or "
15987 "STENCIL");
Tony Barbourd6673642016-05-05 14:46:39 -060015988 // Expect MISMATCHED_IMAGE_ASPECT
15989 region.imageSubresource.aspectMask = VK_IMAGE_ASPECT_METADATA_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015990 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer.handle(), image.handle(),
15991 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, &region);
Tony Barbourd6673642016-05-05 14:46:39 -060015992 m_errorMonitor->VerifyFound();
15993 region.imageSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
15994
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015995 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
15996 "If the format of srcImage is a depth, stencil, depth stencil or "
15997 "integer-based format then filter must be VK_FILTER_NEAREST");
Tony Barbourd6673642016-05-05 14:46:39 -060015998 // Expect INVALID_FILTER
15999 VkImageObj intImage1(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016000 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 -060016001 VkImageObj intImage2(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016002 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 -060016003 VkImageBlit blitRegion = {};
16004 blitRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
16005 blitRegion.srcSubresource.baseArrayLayer = 0;
16006 blitRegion.srcSubresource.layerCount = 1;
16007 blitRegion.srcSubresource.mipLevel = 0;
16008 blitRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
16009 blitRegion.dstSubresource.baseArrayLayer = 0;
16010 blitRegion.dstSubresource.layerCount = 1;
16011 blitRegion.dstSubresource.mipLevel = 0;
16012
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016013 vkCmdBlitImage(m_commandBuffer->GetBufferHandle(), intImage1.handle(), intImage1.layout(), intImage2.handle(),
16014 intImage2.layout(), 16, &blitRegion, VK_FILTER_LINEAR);
Tony Barbourd6673642016-05-05 14:46:39 -060016015 m_errorMonitor->VerifyFound();
16016
Mark Lobodzinskib02ea642016-08-17 13:03:57 -060016017 // Look for NULL-blit warning
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016018 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT, "Offsets specify a zero-volume area.");
16019 vkCmdBlitImage(m_commandBuffer->GetBufferHandle(), intImage1.handle(), intImage1.layout(), intImage2.handle(),
16020 intImage2.layout(), 1, &blitRegion, VK_FILTER_LINEAR);
Mark Lobodzinskib02ea642016-08-17 13:03:57 -060016021 m_errorMonitor->VerifyFound();
16022
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016023 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "called with 0 in ppMemoryBarriers");
Tony Barbourd6673642016-05-05 14:46:39 -060016024 VkImageMemoryBarrier img_barrier;
16025 img_barrier.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
16026 img_barrier.pNext = NULL;
16027 img_barrier.srcAccessMask = VK_ACCESS_HOST_WRITE_BIT;
16028 img_barrier.dstAccessMask = VK_ACCESS_SHADER_READ_BIT;
16029 img_barrier.oldLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
16030 img_barrier.newLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
16031 img_barrier.image = image.handle();
16032 img_barrier.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
16033 img_barrier.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
16034 img_barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
16035 img_barrier.subresourceRange.baseArrayLayer = 0;
16036 img_barrier.subresourceRange.baseMipLevel = 0;
16037 // layerCount should not be 0 - Expect INVALID_IMAGE_RESOURCE
16038 img_barrier.subresourceRange.layerCount = 0;
16039 img_barrier.subresourceRange.levelCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016040 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
16041 nullptr, 0, nullptr, 1, &img_barrier);
Tony Barbourd6673642016-05-05 14:46:39 -060016042 m_errorMonitor->VerifyFound();
16043 img_barrier.subresourceRange.layerCount = 1;
16044}
16045
16046TEST_F(VkLayerTest, ImageFormatLimits) {
16047
16048 TEST_DESCRIPTION("Exceed the limits of image format ");
16049
Cody Northropc31a84f2016-08-22 10:41:47 -060016050 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016051 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "CreateImage extents exceed allowable limits for format");
Tony Barbourd6673642016-05-05 14:46:39 -060016052 VkImageCreateInfo image_create_info = {};
16053 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
16054 image_create_info.pNext = NULL;
16055 image_create_info.imageType = VK_IMAGE_TYPE_2D;
16056 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
16057 image_create_info.extent.width = 32;
16058 image_create_info.extent.height = 32;
16059 image_create_info.extent.depth = 1;
16060 image_create_info.mipLevels = 1;
16061 image_create_info.arrayLayers = 1;
16062 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
16063 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
16064 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
16065 image_create_info.initialLayout = VK_IMAGE_LAYOUT_UNDEFINED;
16066 image_create_info.flags = 0;
16067
16068 VkImage nullImg;
16069 VkImageFormatProperties imgFmtProps;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016070 vkGetPhysicalDeviceImageFormatProperties(gpu(), image_create_info.format, image_create_info.imageType, image_create_info.tiling,
16071 image_create_info.usage, image_create_info.flags, &imgFmtProps);
Tony Barbourd6673642016-05-05 14:46:39 -060016072 image_create_info.extent.depth = imgFmtProps.maxExtent.depth + 1;
16073 // Expect INVALID_FORMAT_LIMITS_VIOLATION
16074 vkCreateImage(m_device->handle(), &image_create_info, NULL, &nullImg);
16075 m_errorMonitor->VerifyFound();
16076 image_create_info.extent.depth = 1;
16077
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016078 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "exceeds allowable maximum supported by format of");
Tony Barbourd6673642016-05-05 14:46:39 -060016079 image_create_info.mipLevels = imgFmtProps.maxMipLevels + 1;
16080 // Expect INVALID_FORMAT_LIMITS_VIOLATION
16081 vkCreateImage(m_device->handle(), &image_create_info, NULL, &nullImg);
16082 m_errorMonitor->VerifyFound();
16083 image_create_info.mipLevels = 1;
16084
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016085 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "exceeds allowable maximum supported by format of");
Tony Barbourd6673642016-05-05 14:46:39 -060016086 image_create_info.arrayLayers = imgFmtProps.maxArrayLayers + 1;
16087 // Expect INVALID_FORMAT_LIMITS_VIOLATION
16088 vkCreateImage(m_device->handle(), &image_create_info, NULL, &nullImg);
16089 m_errorMonitor->VerifyFound();
16090 image_create_info.arrayLayers = 1;
16091
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016092 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "is not supported by format");
Tony Barbourd6673642016-05-05 14:46:39 -060016093 int samples = imgFmtProps.sampleCounts >> 1;
16094 image_create_info.samples = (VkSampleCountFlagBits)samples;
16095 // Expect INVALID_FORMAT_LIMITS_VIOLATION
16096 vkCreateImage(m_device->handle(), &image_create_info, NULL, &nullImg);
16097 m_errorMonitor->VerifyFound();
16098 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
16099
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016100 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "pCreateInfo->initialLayout, must be "
16101 "VK_IMAGE_LAYOUT_UNDEFINED or "
16102 "VK_IMAGE_LAYOUT_PREINITIALIZED");
Tony Barbourd6673642016-05-05 14:46:39 -060016103 image_create_info.initialLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
16104 // Expect INVALID_LAYOUT
16105 vkCreateImage(m_device->handle(), &image_create_info, NULL, &nullImg);
16106 m_errorMonitor->VerifyFound();
16107 image_create_info.initialLayout = VK_IMAGE_LAYOUT_UNDEFINED;
16108}
16109
Karl Schultz6addd812016-02-02 17:17:23 -070016110TEST_F(VkLayerTest, CopyImageFormatSizeMismatch) {
Karl Schultzbdb75952016-04-19 11:36:49 -060016111 VkResult err;
16112 bool pass;
16113
16114 // Create color images with different format sizes and try to copy between them
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016115 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
16116 "vkCmdCopyImage called with unmatched source and dest image format sizes");
Karl Schultzbdb75952016-04-19 11:36:49 -060016117
16118 ASSERT_NO_FATAL_FAILURE(InitState());
16119
16120 // Create two images of different types and try to copy between them
16121 VkImage srcImage;
16122 VkImage dstImage;
16123 VkDeviceMemory srcMem;
16124 VkDeviceMemory destMem;
16125 VkMemoryRequirements memReqs;
16126
16127 VkImageCreateInfo image_create_info = {};
16128 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
16129 image_create_info.pNext = NULL;
16130 image_create_info.imageType = VK_IMAGE_TYPE_2D;
16131 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
16132 image_create_info.extent.width = 32;
16133 image_create_info.extent.height = 32;
16134 image_create_info.extent.depth = 1;
16135 image_create_info.mipLevels = 1;
16136 image_create_info.arrayLayers = 1;
16137 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
16138 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
16139 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
16140 image_create_info.flags = 0;
16141
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016142 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
Karl Schultzbdb75952016-04-19 11:36:49 -060016143 ASSERT_VK_SUCCESS(err);
16144
16145 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT;
16146 // Introduce failure by creating second image with a different-sized format.
16147 image_create_info.format = VK_FORMAT_R5G5B5A1_UNORM_PACK16;
16148
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016149 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
Karl Schultzbdb75952016-04-19 11:36:49 -060016150 ASSERT_VK_SUCCESS(err);
16151
16152 // Allocate memory
16153 VkMemoryAllocateInfo memAlloc = {};
16154 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
16155 memAlloc.pNext = NULL;
16156 memAlloc.allocationSize = 0;
16157 memAlloc.memoryTypeIndex = 0;
16158
16159 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
16160 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016161 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Karl Schultzbdb75952016-04-19 11:36:49 -060016162 ASSERT_TRUE(pass);
16163 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
16164 ASSERT_VK_SUCCESS(err);
16165
16166 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
16167 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016168 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Karl Schultzbdb75952016-04-19 11:36:49 -060016169 ASSERT_TRUE(pass);
16170 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
16171 ASSERT_VK_SUCCESS(err);
16172
16173 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
16174 ASSERT_VK_SUCCESS(err);
16175 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
16176 ASSERT_VK_SUCCESS(err);
16177
16178 BeginCommandBuffer();
16179 VkImageCopy copyRegion;
16180 copyRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
16181 copyRegion.srcSubresource.mipLevel = 0;
16182 copyRegion.srcSubresource.baseArrayLayer = 0;
16183 copyRegion.srcSubresource.layerCount = 0;
16184 copyRegion.srcOffset.x = 0;
16185 copyRegion.srcOffset.y = 0;
16186 copyRegion.srcOffset.z = 0;
16187 copyRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
16188 copyRegion.dstSubresource.mipLevel = 0;
16189 copyRegion.dstSubresource.baseArrayLayer = 0;
16190 copyRegion.dstSubresource.layerCount = 0;
16191 copyRegion.dstOffset.x = 0;
16192 copyRegion.dstOffset.y = 0;
16193 copyRegion.dstOffset.z = 0;
16194 copyRegion.extent.width = 1;
16195 copyRegion.extent.height = 1;
16196 copyRegion.extent.depth = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016197 m_commandBuffer->CopyImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, VK_IMAGE_LAYOUT_GENERAL, 1, &copyRegion);
Karl Schultzbdb75952016-04-19 11:36:49 -060016198 EndCommandBuffer();
16199
16200 m_errorMonitor->VerifyFound();
16201
16202 vkDestroyImage(m_device->device(), srcImage, NULL);
16203 vkDestroyImage(m_device->device(), dstImage, NULL);
16204 vkFreeMemory(m_device->device(), srcMem, NULL);
16205 vkFreeMemory(m_device->device(), destMem, NULL);
Mike Stroyana3082432015-09-25 13:39:21 -060016206}
16207
Karl Schultz6addd812016-02-02 17:17:23 -070016208TEST_F(VkLayerTest, CopyImageDepthStencilFormatMismatch) {
16209 VkResult err;
16210 bool pass;
Mike Stroyana3082432015-09-25 13:39:21 -060016211
Mark Lobodzinskidb117632016-03-31 10:45:56 -060016212 // Create a color image and a depth/stencil image and try to copy between them
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016213 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
16214 "vkCmdCopyImage called with unmatched source and dest image depth");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060016215
Mike Stroyana3082432015-09-25 13:39:21 -060016216 ASSERT_NO_FATAL_FAILURE(InitState());
Mike Stroyana3082432015-09-25 13:39:21 -060016217
16218 // Create two images of different types and try to copy between them
Karl Schultz6addd812016-02-02 17:17:23 -070016219 VkImage srcImage;
16220 VkImage dstImage;
16221 VkDeviceMemory srcMem;
16222 VkDeviceMemory destMem;
16223 VkMemoryRequirements memReqs;
Mike Stroyana3082432015-09-25 13:39:21 -060016224
16225 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070016226 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
16227 image_create_info.pNext = NULL;
16228 image_create_info.imageType = VK_IMAGE_TYPE_2D;
16229 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
16230 image_create_info.extent.width = 32;
16231 image_create_info.extent.height = 32;
16232 image_create_info.extent.depth = 1;
16233 image_create_info.mipLevels = 1;
16234 image_create_info.arrayLayers = 1;
16235 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
16236 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
16237 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
16238 image_create_info.flags = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060016239
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016240 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
Mike Stroyana3082432015-09-25 13:39:21 -060016241 ASSERT_VK_SUCCESS(err);
16242
Karl Schultzbdb75952016-04-19 11:36:49 -060016243 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT;
16244
Mark Lobodzinskidb117632016-03-31 10:45:56 -060016245 // Introduce failure by creating second image with a depth/stencil format
Karl Schultz6addd812016-02-02 17:17:23 -070016246 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
Mark Lobodzinskidb117632016-03-31 10:45:56 -060016247 image_create_info.format = VK_FORMAT_D24_UNORM_S8_UINT;
16248 image_create_info.usage = VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060016249
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016250 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
Mike Stroyana3082432015-09-25 13:39:21 -060016251 ASSERT_VK_SUCCESS(err);
16252
16253 // Allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016254 VkMemoryAllocateInfo memAlloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -070016255 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
16256 memAlloc.pNext = NULL;
16257 memAlloc.allocationSize = 0;
16258 memAlloc.memoryTypeIndex = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060016259
Courtney Goeltzenleuchter06d89472015-10-20 16:40:38 -060016260 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060016261 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016262 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060016263 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016264 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
Mike Stroyana3082432015-09-25 13:39:21 -060016265 ASSERT_VK_SUCCESS(err);
16266
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016267 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060016268 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016269 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060016270 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016271 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
Mike Stroyana3082432015-09-25 13:39:21 -060016272 ASSERT_VK_SUCCESS(err);
16273
16274 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
16275 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016276 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
Mike Stroyana3082432015-09-25 13:39:21 -060016277 ASSERT_VK_SUCCESS(err);
16278
16279 BeginCommandBuffer();
16280 VkImageCopy copyRegion;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080016281 copyRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060016282 copyRegion.srcSubresource.mipLevel = 0;
Courtney Goeltzenleuchter8367ce02015-10-16 09:46:00 -060016283 copyRegion.srcSubresource.baseArrayLayer = 0;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016284 copyRegion.srcSubresource.layerCount = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060016285 copyRegion.srcOffset.x = 0;
16286 copyRegion.srcOffset.y = 0;
16287 copyRegion.srcOffset.z = 0;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080016288 copyRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016289 copyRegion.dstSubresource.mipLevel = 0;
16290 copyRegion.dstSubresource.baseArrayLayer = 0;
16291 copyRegion.dstSubresource.layerCount = 0;
16292 copyRegion.dstOffset.x = 0;
16293 copyRegion.dstOffset.y = 0;
16294 copyRegion.dstOffset.z = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060016295 copyRegion.extent.width = 1;
16296 copyRegion.extent.height = 1;
16297 copyRegion.extent.depth = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016298 m_commandBuffer->CopyImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, VK_IMAGE_LAYOUT_GENERAL, 1, &copyRegion);
Mike Stroyana3082432015-09-25 13:39:21 -060016299 EndCommandBuffer();
16300
Chris Forbes8f36a8a2016-04-07 13:21:07 +120016301 m_errorMonitor->VerifyFound();
Mike Stroyana3082432015-09-25 13:39:21 -060016302
Chia-I Wuf7458c52015-10-26 21:10:41 +080016303 vkDestroyImage(m_device->device(), srcImage, NULL);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016304 vkDestroyImage(m_device->device(), dstImage, NULL);
Chia-I Wuf7458c52015-10-26 21:10:41 +080016305 vkFreeMemory(m_device->device(), srcMem, NULL);
16306 vkFreeMemory(m_device->device(), destMem, NULL);
Mike Stroyana3082432015-09-25 13:39:21 -060016307}
16308
Karl Schultz6addd812016-02-02 17:17:23 -070016309TEST_F(VkLayerTest, ResolveImageLowSampleCount) {
16310 VkResult err;
16311 bool pass;
Mike Stroyana3082432015-09-25 13:39:21 -060016312
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016313 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
16314 "vkCmdResolveImage called with source sample count less than 2.");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060016315
Mike Stroyana3082432015-09-25 13:39:21 -060016316 ASSERT_NO_FATAL_FAILURE(InitState());
Mike Stroyana3082432015-09-25 13:39:21 -060016317
16318 // Create two images of sample count 1 and try to Resolve between them
Karl Schultz6addd812016-02-02 17:17:23 -070016319 VkImage srcImage;
16320 VkImage dstImage;
16321 VkDeviceMemory srcMem;
16322 VkDeviceMemory destMem;
16323 VkMemoryRequirements memReqs;
Mike Stroyana3082432015-09-25 13:39:21 -060016324
16325 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070016326 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
16327 image_create_info.pNext = NULL;
16328 image_create_info.imageType = VK_IMAGE_TYPE_2D;
16329 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
16330 image_create_info.extent.width = 32;
16331 image_create_info.extent.height = 1;
16332 image_create_info.extent.depth = 1;
16333 image_create_info.mipLevels = 1;
16334 image_create_info.arrayLayers = 1;
16335 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
16336 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
16337 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
16338 image_create_info.flags = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060016339
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016340 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
Mike Stroyana3082432015-09-25 13:39:21 -060016341 ASSERT_VK_SUCCESS(err);
16342
Karl Schultz6addd812016-02-02 17:17:23 -070016343 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060016344
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016345 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
Mike Stroyana3082432015-09-25 13:39:21 -060016346 ASSERT_VK_SUCCESS(err);
16347
16348 // Allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016349 VkMemoryAllocateInfo memAlloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -070016350 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
16351 memAlloc.pNext = NULL;
16352 memAlloc.allocationSize = 0;
16353 memAlloc.memoryTypeIndex = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060016354
Courtney Goeltzenleuchter06d89472015-10-20 16:40:38 -060016355 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060016356 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016357 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060016358 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016359 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
Mike Stroyana3082432015-09-25 13:39:21 -060016360 ASSERT_VK_SUCCESS(err);
16361
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016362 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060016363 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016364 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060016365 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016366 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
Mike Stroyana3082432015-09-25 13:39:21 -060016367 ASSERT_VK_SUCCESS(err);
16368
16369 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
16370 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016371 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
Mike Stroyana3082432015-09-25 13:39:21 -060016372 ASSERT_VK_SUCCESS(err);
16373
16374 BeginCommandBuffer();
16375 // Need memory barrier to VK_IMAGE_LAYOUT_GENERAL for source and dest?
Karl Schultz6addd812016-02-02 17:17:23 -070016376 // VK_IMAGE_LAYOUT_UNDEFINED = 0,
16377 // VK_IMAGE_LAYOUT_GENERAL = 1,
Mike Stroyana3082432015-09-25 13:39:21 -060016378 VkImageResolve resolveRegion;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080016379 resolveRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060016380 resolveRegion.srcSubresource.mipLevel = 0;
Courtney Goeltzenleuchter8367ce02015-10-16 09:46:00 -060016381 resolveRegion.srcSubresource.baseArrayLayer = 0;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016382 resolveRegion.srcSubresource.layerCount = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060016383 resolveRegion.srcOffset.x = 0;
16384 resolveRegion.srcOffset.y = 0;
16385 resolveRegion.srcOffset.z = 0;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080016386 resolveRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016387 resolveRegion.dstSubresource.mipLevel = 0;
16388 resolveRegion.dstSubresource.baseArrayLayer = 0;
16389 resolveRegion.dstSubresource.layerCount = 0;
16390 resolveRegion.dstOffset.x = 0;
16391 resolveRegion.dstOffset.y = 0;
16392 resolveRegion.dstOffset.z = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060016393 resolveRegion.extent.width = 1;
16394 resolveRegion.extent.height = 1;
16395 resolveRegion.extent.depth = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016396 m_commandBuffer->ResolveImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, VK_IMAGE_LAYOUT_GENERAL, 1, &resolveRegion);
Mike Stroyana3082432015-09-25 13:39:21 -060016397 EndCommandBuffer();
16398
Chris Forbes8f36a8a2016-04-07 13:21:07 +120016399 m_errorMonitor->VerifyFound();
Mike Stroyana3082432015-09-25 13:39:21 -060016400
Chia-I Wuf7458c52015-10-26 21:10:41 +080016401 vkDestroyImage(m_device->device(), srcImage, NULL);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016402 vkDestroyImage(m_device->device(), dstImage, NULL);
Chia-I Wuf7458c52015-10-26 21:10:41 +080016403 vkFreeMemory(m_device->device(), srcMem, NULL);
16404 vkFreeMemory(m_device->device(), destMem, NULL);
Mike Stroyana3082432015-09-25 13:39:21 -060016405}
16406
Karl Schultz6addd812016-02-02 17:17:23 -070016407TEST_F(VkLayerTest, ResolveImageHighSampleCount) {
16408 VkResult err;
16409 bool pass;
Mike Stroyana3082432015-09-25 13:39:21 -060016410
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016411 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
16412 "vkCmdResolveImage called with dest sample count greater than 1.");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060016413
Mike Stroyana3082432015-09-25 13:39:21 -060016414 ASSERT_NO_FATAL_FAILURE(InitState());
Mike Stroyana3082432015-09-25 13:39:21 -060016415
Chris Forbesa7530692016-05-08 12:35:39 +120016416 // Create two images of sample count 4 and try to Resolve between them
Karl Schultz6addd812016-02-02 17:17:23 -070016417 VkImage srcImage;
16418 VkImage dstImage;
16419 VkDeviceMemory srcMem;
16420 VkDeviceMemory destMem;
16421 VkMemoryRequirements memReqs;
Mike Stroyana3082432015-09-25 13:39:21 -060016422
16423 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070016424 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
16425 image_create_info.pNext = NULL;
16426 image_create_info.imageType = VK_IMAGE_TYPE_2D;
16427 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
16428 image_create_info.extent.width = 32;
16429 image_create_info.extent.height = 1;
16430 image_create_info.extent.depth = 1;
16431 image_create_info.mipLevels = 1;
16432 image_create_info.arrayLayers = 1;
Chris Forbesa7530692016-05-08 12:35:39 +120016433 image_create_info.samples = VK_SAMPLE_COUNT_4_BIT;
Karl Schultz6addd812016-02-02 17:17:23 -070016434 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
16435 // Note: Some implementations expect color attachment usage for any
16436 // multisample surface
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016437 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
Karl Schultz6addd812016-02-02 17:17:23 -070016438 image_create_info.flags = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060016439
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016440 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
Mike Stroyana3082432015-09-25 13:39:21 -060016441 ASSERT_VK_SUCCESS(err);
16442
Karl Schultz6addd812016-02-02 17:17:23 -070016443 // Note: Some implementations expect color attachment usage for any
16444 // multisample surface
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016445 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060016446
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016447 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
Mike Stroyana3082432015-09-25 13:39:21 -060016448 ASSERT_VK_SUCCESS(err);
16449
16450 // Allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016451 VkMemoryAllocateInfo memAlloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -070016452 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
16453 memAlloc.pNext = NULL;
16454 memAlloc.allocationSize = 0;
16455 memAlloc.memoryTypeIndex = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060016456
Courtney Goeltzenleuchter06d89472015-10-20 16:40:38 -060016457 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060016458 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016459 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060016460 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016461 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
Mike Stroyana3082432015-09-25 13:39:21 -060016462 ASSERT_VK_SUCCESS(err);
16463
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016464 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060016465 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016466 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060016467 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016468 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
Mike Stroyana3082432015-09-25 13:39:21 -060016469 ASSERT_VK_SUCCESS(err);
16470
16471 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
16472 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016473 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
Mike Stroyana3082432015-09-25 13:39:21 -060016474 ASSERT_VK_SUCCESS(err);
16475
16476 BeginCommandBuffer();
16477 // Need memory barrier to VK_IMAGE_LAYOUT_GENERAL for source and dest?
Karl Schultz6addd812016-02-02 17:17:23 -070016478 // VK_IMAGE_LAYOUT_UNDEFINED = 0,
16479 // VK_IMAGE_LAYOUT_GENERAL = 1,
Mike Stroyana3082432015-09-25 13:39:21 -060016480 VkImageResolve resolveRegion;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080016481 resolveRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060016482 resolveRegion.srcSubresource.mipLevel = 0;
Courtney Goeltzenleuchter8367ce02015-10-16 09:46:00 -060016483 resolveRegion.srcSubresource.baseArrayLayer = 0;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016484 resolveRegion.srcSubresource.layerCount = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060016485 resolveRegion.srcOffset.x = 0;
16486 resolveRegion.srcOffset.y = 0;
16487 resolveRegion.srcOffset.z = 0;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080016488 resolveRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016489 resolveRegion.dstSubresource.mipLevel = 0;
16490 resolveRegion.dstSubresource.baseArrayLayer = 0;
16491 resolveRegion.dstSubresource.layerCount = 0;
16492 resolveRegion.dstOffset.x = 0;
16493 resolveRegion.dstOffset.y = 0;
16494 resolveRegion.dstOffset.z = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060016495 resolveRegion.extent.width = 1;
16496 resolveRegion.extent.height = 1;
16497 resolveRegion.extent.depth = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016498 m_commandBuffer->ResolveImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, VK_IMAGE_LAYOUT_GENERAL, 1, &resolveRegion);
Mike Stroyana3082432015-09-25 13:39:21 -060016499 EndCommandBuffer();
16500
Chris Forbes8f36a8a2016-04-07 13:21:07 +120016501 m_errorMonitor->VerifyFound();
Mike Stroyana3082432015-09-25 13:39:21 -060016502
Chia-I Wuf7458c52015-10-26 21:10:41 +080016503 vkDestroyImage(m_device->device(), srcImage, NULL);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016504 vkDestroyImage(m_device->device(), dstImage, NULL);
Chia-I Wuf7458c52015-10-26 21:10:41 +080016505 vkFreeMemory(m_device->device(), srcMem, NULL);
16506 vkFreeMemory(m_device->device(), destMem, NULL);
Mike Stroyana3082432015-09-25 13:39:21 -060016507}
16508
Karl Schultz6addd812016-02-02 17:17:23 -070016509TEST_F(VkLayerTest, ResolveImageFormatMismatch) {
16510 VkResult err;
16511 bool pass;
Mike Stroyana3082432015-09-25 13:39:21 -060016512
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016513 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
16514 "vkCmdResolveImage called with unmatched source and dest formats.");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060016515
Mike Stroyana3082432015-09-25 13:39:21 -060016516 ASSERT_NO_FATAL_FAILURE(InitState());
Mike Stroyana3082432015-09-25 13:39:21 -060016517
16518 // Create two images of different types and try to copy between them
Karl Schultz6addd812016-02-02 17:17:23 -070016519 VkImage srcImage;
16520 VkImage dstImage;
16521 VkDeviceMemory srcMem;
16522 VkDeviceMemory destMem;
16523 VkMemoryRequirements memReqs;
Mike Stroyana3082432015-09-25 13:39:21 -060016524
16525 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070016526 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
16527 image_create_info.pNext = NULL;
16528 image_create_info.imageType = VK_IMAGE_TYPE_2D;
16529 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
16530 image_create_info.extent.width = 32;
16531 image_create_info.extent.height = 1;
16532 image_create_info.extent.depth = 1;
16533 image_create_info.mipLevels = 1;
16534 image_create_info.arrayLayers = 1;
16535 image_create_info.samples = VK_SAMPLE_COUNT_2_BIT;
16536 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
16537 // Note: Some implementations expect color attachment usage for any
16538 // multisample surface
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016539 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
Karl Schultz6addd812016-02-02 17:17:23 -070016540 image_create_info.flags = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060016541
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016542 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
Mike Stroyana3082432015-09-25 13:39:21 -060016543 ASSERT_VK_SUCCESS(err);
16544
Karl Schultz6addd812016-02-02 17:17:23 -070016545 // Set format to something other than source image
16546 image_create_info.format = VK_FORMAT_R32_SFLOAT;
16547 // Note: Some implementations expect color attachment usage for any
16548 // multisample surface
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016549 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
Karl Schultz6addd812016-02-02 17:17:23 -070016550 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060016551
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016552 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
Mike Stroyana3082432015-09-25 13:39:21 -060016553 ASSERT_VK_SUCCESS(err);
16554
16555 // Allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016556 VkMemoryAllocateInfo memAlloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -070016557 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
16558 memAlloc.pNext = NULL;
16559 memAlloc.allocationSize = 0;
16560 memAlloc.memoryTypeIndex = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060016561
Courtney Goeltzenleuchter06d89472015-10-20 16:40:38 -060016562 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060016563 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016564 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060016565 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016566 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
Mike Stroyana3082432015-09-25 13:39:21 -060016567 ASSERT_VK_SUCCESS(err);
16568
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016569 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060016570 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016571 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060016572 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016573 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
Mike Stroyana3082432015-09-25 13:39:21 -060016574 ASSERT_VK_SUCCESS(err);
16575
16576 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
16577 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016578 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
Mike Stroyana3082432015-09-25 13:39:21 -060016579 ASSERT_VK_SUCCESS(err);
16580
16581 BeginCommandBuffer();
16582 // Need memory barrier to VK_IMAGE_LAYOUT_GENERAL for source and dest?
Karl Schultz6addd812016-02-02 17:17:23 -070016583 // VK_IMAGE_LAYOUT_UNDEFINED = 0,
16584 // VK_IMAGE_LAYOUT_GENERAL = 1,
Mike Stroyana3082432015-09-25 13:39:21 -060016585 VkImageResolve resolveRegion;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080016586 resolveRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060016587 resolveRegion.srcSubresource.mipLevel = 0;
Courtney Goeltzenleuchter8367ce02015-10-16 09:46:00 -060016588 resolveRegion.srcSubresource.baseArrayLayer = 0;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016589 resolveRegion.srcSubresource.layerCount = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060016590 resolveRegion.srcOffset.x = 0;
16591 resolveRegion.srcOffset.y = 0;
16592 resolveRegion.srcOffset.z = 0;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080016593 resolveRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016594 resolveRegion.dstSubresource.mipLevel = 0;
16595 resolveRegion.dstSubresource.baseArrayLayer = 0;
16596 resolveRegion.dstSubresource.layerCount = 0;
16597 resolveRegion.dstOffset.x = 0;
16598 resolveRegion.dstOffset.y = 0;
16599 resolveRegion.dstOffset.z = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060016600 resolveRegion.extent.width = 1;
16601 resolveRegion.extent.height = 1;
16602 resolveRegion.extent.depth = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016603 m_commandBuffer->ResolveImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, VK_IMAGE_LAYOUT_GENERAL, 1, &resolveRegion);
Mike Stroyana3082432015-09-25 13:39:21 -060016604 EndCommandBuffer();
16605
Chris Forbes8f36a8a2016-04-07 13:21:07 +120016606 m_errorMonitor->VerifyFound();
Mike Stroyana3082432015-09-25 13:39:21 -060016607
Chia-I Wuf7458c52015-10-26 21:10:41 +080016608 vkDestroyImage(m_device->device(), srcImage, NULL);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016609 vkDestroyImage(m_device->device(), dstImage, NULL);
Chia-I Wuf7458c52015-10-26 21:10:41 +080016610 vkFreeMemory(m_device->device(), srcMem, NULL);
16611 vkFreeMemory(m_device->device(), destMem, NULL);
Mike Stroyana3082432015-09-25 13:39:21 -060016612}
16613
Karl Schultz6addd812016-02-02 17:17:23 -070016614TEST_F(VkLayerTest, ResolveImageTypeMismatch) {
16615 VkResult err;
16616 bool pass;
Mike Stroyana3082432015-09-25 13:39:21 -060016617
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016618 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
16619 "vkCmdResolveImage called with unmatched source and dest image types.");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060016620
Mike Stroyana3082432015-09-25 13:39:21 -060016621 ASSERT_NO_FATAL_FAILURE(InitState());
Mike Stroyana3082432015-09-25 13:39:21 -060016622
16623 // Create two images of different types and try to copy between them
Karl Schultz6addd812016-02-02 17:17:23 -070016624 VkImage srcImage;
16625 VkImage dstImage;
16626 VkDeviceMemory srcMem;
16627 VkDeviceMemory destMem;
16628 VkMemoryRequirements memReqs;
Mike Stroyana3082432015-09-25 13:39:21 -060016629
16630 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070016631 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
16632 image_create_info.pNext = NULL;
16633 image_create_info.imageType = VK_IMAGE_TYPE_2D;
16634 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
16635 image_create_info.extent.width = 32;
16636 image_create_info.extent.height = 1;
16637 image_create_info.extent.depth = 1;
16638 image_create_info.mipLevels = 1;
16639 image_create_info.arrayLayers = 1;
16640 image_create_info.samples = VK_SAMPLE_COUNT_2_BIT;
16641 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
16642 // Note: Some implementations expect color attachment usage for any
16643 // multisample surface
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016644 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
Karl Schultz6addd812016-02-02 17:17:23 -070016645 image_create_info.flags = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060016646
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016647 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
Mike Stroyana3082432015-09-25 13:39:21 -060016648 ASSERT_VK_SUCCESS(err);
16649
Karl Schultz6addd812016-02-02 17:17:23 -070016650 image_create_info.imageType = VK_IMAGE_TYPE_1D;
16651 // Note: Some implementations expect color attachment usage for any
16652 // multisample surface
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016653 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
Karl Schultz6addd812016-02-02 17:17:23 -070016654 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060016655
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016656 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
Mike Stroyana3082432015-09-25 13:39:21 -060016657 ASSERT_VK_SUCCESS(err);
16658
16659 // Allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016660 VkMemoryAllocateInfo memAlloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -070016661 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
16662 memAlloc.pNext = NULL;
16663 memAlloc.allocationSize = 0;
16664 memAlloc.memoryTypeIndex = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060016665
Courtney Goeltzenleuchter06d89472015-10-20 16:40:38 -060016666 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060016667 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016668 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060016669 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016670 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
Mike Stroyana3082432015-09-25 13:39:21 -060016671 ASSERT_VK_SUCCESS(err);
16672
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016673 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060016674 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016675 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060016676 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016677 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
Mike Stroyana3082432015-09-25 13:39:21 -060016678 ASSERT_VK_SUCCESS(err);
16679
16680 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
16681 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016682 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
Mike Stroyana3082432015-09-25 13:39:21 -060016683 ASSERT_VK_SUCCESS(err);
16684
16685 BeginCommandBuffer();
16686 // Need memory barrier to VK_IMAGE_LAYOUT_GENERAL for source and dest?
Karl Schultz6addd812016-02-02 17:17:23 -070016687 // VK_IMAGE_LAYOUT_UNDEFINED = 0,
16688 // VK_IMAGE_LAYOUT_GENERAL = 1,
Mike Stroyana3082432015-09-25 13:39:21 -060016689 VkImageResolve resolveRegion;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080016690 resolveRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060016691 resolveRegion.srcSubresource.mipLevel = 0;
Courtney Goeltzenleuchter8367ce02015-10-16 09:46:00 -060016692 resolveRegion.srcSubresource.baseArrayLayer = 0;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016693 resolveRegion.srcSubresource.layerCount = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060016694 resolveRegion.srcOffset.x = 0;
16695 resolveRegion.srcOffset.y = 0;
16696 resolveRegion.srcOffset.z = 0;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080016697 resolveRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016698 resolveRegion.dstSubresource.mipLevel = 0;
16699 resolveRegion.dstSubresource.baseArrayLayer = 0;
16700 resolveRegion.dstSubresource.layerCount = 0;
16701 resolveRegion.dstOffset.x = 0;
16702 resolveRegion.dstOffset.y = 0;
16703 resolveRegion.dstOffset.z = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060016704 resolveRegion.extent.width = 1;
16705 resolveRegion.extent.height = 1;
16706 resolveRegion.extent.depth = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016707 m_commandBuffer->ResolveImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, VK_IMAGE_LAYOUT_GENERAL, 1, &resolveRegion);
Mike Stroyana3082432015-09-25 13:39:21 -060016708 EndCommandBuffer();
16709
Chris Forbes8f36a8a2016-04-07 13:21:07 +120016710 m_errorMonitor->VerifyFound();
Mike Stroyana3082432015-09-25 13:39:21 -060016711
Chia-I Wuf7458c52015-10-26 21:10:41 +080016712 vkDestroyImage(m_device->device(), srcImage, NULL);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016713 vkDestroyImage(m_device->device(), dstImage, NULL);
Chia-I Wuf7458c52015-10-26 21:10:41 +080016714 vkFreeMemory(m_device->device(), srcMem, NULL);
16715 vkFreeMemory(m_device->device(), destMem, NULL);
Mike Stroyana3082432015-09-25 13:39:21 -060016716}
Tobin Ehlisa1c28562015-10-23 16:00:08 -060016717
Karl Schultz6addd812016-02-02 17:17:23 -070016718TEST_F(VkLayerTest, DepthStencilImageViewWithColorAspectBitError) {
Tobin Ehlisa1c28562015-10-23 16:00:08 -060016719 // Create a single Image descriptor and cause it to first hit an error due
Karl Schultz6addd812016-02-02 17:17:23 -070016720 // to using a DS format, then cause it to hit error due to COLOR_BIT not
16721 // set in aspect
Tobin Ehlisa1c28562015-10-23 16:00:08 -060016722 // The image format check comes 2nd in validation so we trigger it first,
16723 // then when we cause aspect fail next, bad format check will be preempted
Karl Schultz6addd812016-02-02 17:17:23 -070016724 VkResult err;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060016725
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016726 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
16727 "Combination depth/stencil image formats can have only the ");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060016728
Tobin Ehlisa1c28562015-10-23 16:00:08 -060016729 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060016730
Chia-I Wu1b99bb22015-10-27 19:25:11 +080016731 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -070016732 ds_type_count.type = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE;
16733 ds_type_count.descriptorCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060016734
16735 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070016736 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
16737 ds_pool_ci.pNext = NULL;
16738 ds_pool_ci.maxSets = 1;
16739 ds_pool_ci.poolSizeCount = 1;
16740 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060016741
16742 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016743 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060016744 ASSERT_VK_SUCCESS(err);
16745
16746 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -070016747 dsl_binding.binding = 0;
16748 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE;
16749 dsl_binding.descriptorCount = 1;
16750 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
16751 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060016752
16753 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070016754 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
16755 ds_layout_ci.pNext = NULL;
16756 ds_layout_ci.bindingCount = 1;
16757 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060016758 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016759 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060016760 ASSERT_VK_SUCCESS(err);
16761
16762 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016763 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +080016764 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -070016765 alloc_info.descriptorSetCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060016766 alloc_info.descriptorPool = ds_pool;
16767 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016768 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060016769 ASSERT_VK_SUCCESS(err);
16770
Karl Schultz6addd812016-02-02 17:17:23 -070016771 VkImage image_bad;
16772 VkImage image_good;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060016773 // One bad format and one good format for Color attachment
Tobin Ehlis269f0322016-05-25 16:24:21 -060016774 const VkFormat tex_format_bad = VK_FORMAT_D24_UNORM_S8_UINT;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060016775 const VkFormat tex_format_good = VK_FORMAT_B8G8R8A8_UNORM;
Karl Schultz6addd812016-02-02 17:17:23 -070016776 const int32_t tex_width = 32;
16777 const int32_t tex_height = 32;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060016778
16779 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070016780 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
16781 image_create_info.pNext = NULL;
16782 image_create_info.imageType = VK_IMAGE_TYPE_2D;
16783 image_create_info.format = tex_format_bad;
16784 image_create_info.extent.width = tex_width;
16785 image_create_info.extent.height = tex_height;
16786 image_create_info.extent.depth = 1;
16787 image_create_info.mipLevels = 1;
16788 image_create_info.arrayLayers = 1;
16789 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
16790 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016791 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT | VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT;
Karl Schultz6addd812016-02-02 17:17:23 -070016792 image_create_info.flags = 0;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060016793
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016794 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image_bad);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060016795 ASSERT_VK_SUCCESS(err);
16796 image_create_info.format = tex_format_good;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016797 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
16798 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image_good);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060016799 ASSERT_VK_SUCCESS(err);
16800
16801 VkImageViewCreateInfo image_view_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070016802 image_view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
16803 image_view_create_info.image = image_bad;
16804 image_view_create_info.viewType = VK_IMAGE_VIEW_TYPE_2D;
16805 image_view_create_info.format = tex_format_bad;
16806 image_view_create_info.subresourceRange.baseArrayLayer = 0;
16807 image_view_create_info.subresourceRange.baseMipLevel = 0;
16808 image_view_create_info.subresourceRange.layerCount = 1;
16809 image_view_create_info.subresourceRange.levelCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016810 image_view_create_info.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060016811
16812 VkImageView view;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016813 err = vkCreateImageView(m_device->device(), &image_view_create_info, NULL, &view);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060016814
Chris Forbes8f36a8a2016-04-07 13:21:07 +120016815 m_errorMonitor->VerifyFound();
Tobin Ehlisa1c28562015-10-23 16:00:08 -060016816
Chia-I Wuf7458c52015-10-26 21:10:41 +080016817 vkDestroyImage(m_device->device(), image_bad, NULL);
16818 vkDestroyImage(m_device->device(), image_good, NULL);
Chia-I Wuf7458c52015-10-26 21:10:41 +080016819 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
16820 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060016821}
Tobin Ehlis6e23d772016-05-19 11:08:34 -060016822
16823TEST_F(VkLayerTest, ClearImageErrors) {
16824 TEST_DESCRIPTION("Call ClearColorImage w/ a depth|stencil image and "
16825 "ClearDepthStencilImage with a color image.");
16826
16827 ASSERT_NO_FATAL_FAILURE(InitState());
16828 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
16829
16830 // Renderpass is started here so end it as Clear cmds can't be in renderpass
16831 BeginCommandBuffer();
16832 m_commandBuffer->EndRenderPass();
16833
16834 // Color image
16835 VkClearColorValue clear_color;
16836 memset(clear_color.uint32, 0, sizeof(uint32_t) * 4);
16837 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
16838 const VkFormat color_format = VK_FORMAT_B8G8R8A8_UNORM;
16839 const int32_t img_width = 32;
16840 const int32_t img_height = 32;
16841 VkImageCreateInfo image_create_info = {};
16842 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
16843 image_create_info.pNext = NULL;
16844 image_create_info.imageType = VK_IMAGE_TYPE_2D;
16845 image_create_info.format = color_format;
16846 image_create_info.extent.width = img_width;
16847 image_create_info.extent.height = img_height;
16848 image_create_info.extent.depth = 1;
16849 image_create_info.mipLevels = 1;
16850 image_create_info.arrayLayers = 1;
16851 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
16852 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
16853 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
16854
16855 vk_testing::Image color_image;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016856 color_image.init(*m_device, (const VkImageCreateInfo &)image_create_info, reqs);
Tobin Ehlis6e23d772016-05-19 11:08:34 -060016857
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016858 const VkImageSubresourceRange color_range = vk_testing::Image::subresource_range(image_create_info, VK_IMAGE_ASPECT_COLOR_BIT);
Tobin Ehlis6e23d772016-05-19 11:08:34 -060016859
16860 // Depth/Stencil image
16861 VkClearDepthStencilValue clear_value = {0};
16862 reqs = 0; // don't need HOST_VISIBLE DS image
16863 VkImageCreateInfo ds_image_create_info = vk_testing::Image::create_info();
16864 ds_image_create_info.imageType = VK_IMAGE_TYPE_2D;
16865 ds_image_create_info.format = VK_FORMAT_D24_UNORM_S8_UINT;
16866 ds_image_create_info.extent.width = 64;
16867 ds_image_create_info.extent.height = 64;
16868 ds_image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
16869 ds_image_create_info.usage = VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT;
16870
16871 vk_testing::Image ds_image;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016872 ds_image.init(*m_device, (const VkImageCreateInfo &)ds_image_create_info, reqs);
Tobin Ehlis6e23d772016-05-19 11:08:34 -060016873
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016874 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 -060016875
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016876 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "vkCmdClearColorImage called with depth/stencil image.");
Tobin Ehlis6e23d772016-05-19 11:08:34 -060016877
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016878 vkCmdClearColorImage(m_commandBuffer->GetBufferHandle(), ds_image.handle(), VK_IMAGE_LAYOUT_GENERAL, &clear_color, 1,
Tobin Ehlis6e23d772016-05-19 11:08:34 -060016879 &color_range);
16880
16881 m_errorMonitor->VerifyFound();
16882
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016883 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "vkCmdClearColorImage called with "
16884 "image created without "
16885 "VK_IMAGE_USAGE_TRANSFER_DST_BIT");
Tony Barbour26434b92016-06-02 09:43:50 -060016886
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016887 vkCmdClearColorImage(m_commandBuffer->GetBufferHandle(), ds_image.handle(), VK_IMAGE_LAYOUT_GENERAL, &clear_color, 1,
Tony Barbour26434b92016-06-02 09:43:50 -060016888 &color_range);
16889
16890 m_errorMonitor->VerifyFound();
16891
Tobin Ehlis6e23d772016-05-19 11:08:34 -060016892 // Call CmdClearDepthStencilImage with color image
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016893 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
16894 "vkCmdClearDepthStencilImage called without a depth/stencil image.");
Tobin Ehlis6e23d772016-05-19 11:08:34 -060016895
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016896 vkCmdClearDepthStencilImage(m_commandBuffer->GetBufferHandle(), color_image.handle(),
16897 VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL, &clear_value, 1, &ds_range);
Tobin Ehlis6e23d772016-05-19 11:08:34 -060016898
16899 m_errorMonitor->VerifyFound();
16900}
Tobin Ehliscde08892015-09-22 10:11:37 -060016901#endif // IMAGE_TESTS
16902
Cody Northrop1242dfd2016-07-13 17:24:59 -060016903#if defined(ANDROID) && defined(VALIDATION_APK)
16904static bool initialized = false;
16905static bool active = false;
16906
16907// Convert Intents to argv
16908// Ported from Hologram sample, only difference is flexible key
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016909std::vector<std::string> get_args(android_app &app, const char *intent_extra_data_key) {
Cody Northrop1242dfd2016-07-13 17:24:59 -060016910 std::vector<std::string> args;
16911 JavaVM &vm = *app.activity->vm;
16912 JNIEnv *p_env;
16913 if (vm.AttachCurrentThread(&p_env, nullptr) != JNI_OK)
16914 return args;
16915
16916 JNIEnv &env = *p_env;
16917 jobject activity = app.activity->clazz;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016918 jmethodID get_intent_method = env.GetMethodID(env.GetObjectClass(activity), "getIntent", "()Landroid/content/Intent;");
Cody Northrop1242dfd2016-07-13 17:24:59 -060016919 jobject intent = env.CallObjectMethod(activity, get_intent_method);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016920 jmethodID get_string_extra_method =
16921 env.GetMethodID(env.GetObjectClass(intent), "getStringExtra", "(Ljava/lang/String;)Ljava/lang/String;");
Cody Northrop1242dfd2016-07-13 17:24:59 -060016922 jvalue get_string_extra_args;
16923 get_string_extra_args.l = env.NewStringUTF(intent_extra_data_key);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016924 jstring extra_str = static_cast<jstring>(env.CallObjectMethodA(intent, get_string_extra_method, &get_string_extra_args));
Cody Northrop1242dfd2016-07-13 17:24:59 -060016925
16926 std::string args_str;
16927 if (extra_str) {
16928 const char *extra_utf = env.GetStringUTFChars(extra_str, nullptr);
16929 args_str = extra_utf;
16930 env.ReleaseStringUTFChars(extra_str, extra_utf);
16931 env.DeleteLocalRef(extra_str);
16932 }
16933
16934 env.DeleteLocalRef(get_string_extra_args.l);
16935 env.DeleteLocalRef(intent);
16936 vm.DetachCurrentThread();
16937
16938 // split args_str
16939 std::stringstream ss(args_str);
16940 std::string arg;
16941 while (std::getline(ss, arg, ' ')) {
16942 if (!arg.empty())
16943 args.push_back(arg);
16944 }
16945
16946 return args;
16947}
16948
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016949static int32_t processInput(struct android_app *app, AInputEvent *event) { return 0; }
Cody Northrop1242dfd2016-07-13 17:24:59 -060016950
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016951static void processCommand(struct android_app *app, int32_t cmd) {
16952 switch (cmd) {
16953 case APP_CMD_INIT_WINDOW: {
16954 if (app->window) {
16955 initialized = true;
Cody Northrop1242dfd2016-07-13 17:24:59 -060016956 }
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016957 break;
16958 }
16959 case APP_CMD_GAINED_FOCUS: {
16960 active = true;
16961 break;
16962 }
16963 case APP_CMD_LOST_FOCUS: {
16964 active = false;
16965 break;
16966 }
Cody Northrop1242dfd2016-07-13 17:24:59 -060016967 }
16968}
16969
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016970void android_main(struct android_app *app) {
Cody Northrop1242dfd2016-07-13 17:24:59 -060016971 app_dummy();
16972
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016973 const char *appTag = "VulkanLayerValidationTests";
Cody Northrop1242dfd2016-07-13 17:24:59 -060016974
16975 int vulkanSupport = InitVulkan();
16976 if (vulkanSupport == 0) {
16977 __android_log_print(ANDROID_LOG_INFO, appTag, "==== FAILED ==== No Vulkan support found");
16978 return;
16979 }
16980
16981 app->onAppCmd = processCommand;
16982 app->onInputEvent = processInput;
16983
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016984 while (1) {
Cody Northrop1242dfd2016-07-13 17:24:59 -060016985 int events;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016986 struct android_poll_source *source;
16987 while (ALooper_pollAll(active ? 0 : -1, NULL, &events, (void **)&source) >= 0) {
Cody Northrop1242dfd2016-07-13 17:24:59 -060016988 if (source) {
16989 source->process(app, source);
16990 }
16991
16992 if (app->destroyRequested != 0) {
16993 VkTestFramework::Finish();
16994 return;
16995 }
16996 }
16997
16998 if (initialized && active) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016999 // Use the following key to send arguments to gtest, i.e.
17000 // --es args "--gtest_filter=-VkLayerTest.foo"
17001 const char key[] = "args";
17002 std::vector<std::string> args = get_args(*app, key);
Cody Northrop1242dfd2016-07-13 17:24:59 -060017003
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017004 std::string filter = "";
17005 if (args.size() > 0) {
17006 __android_log_print(ANDROID_LOG_INFO, appTag, "Intent args = %s", args[0].c_str());
17007 filter += args[0];
17008 } else {
17009 __android_log_print(ANDROID_LOG_INFO, appTag, "No Intent args detected");
17010 }
Cody Northrop1242dfd2016-07-13 17:24:59 -060017011
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017012 int argc = 2;
17013 char *argv[] = {(char *)"foo", (char *)filter.c_str()};
17014 __android_log_print(ANDROID_LOG_DEBUG, appTag, "filter = %s", argv[1]);
Cody Northrop1242dfd2016-07-13 17:24:59 -060017015
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017016 // Route output to files until we can override the gtest output
17017 freopen("/sdcard/Android/data/com.example.VulkanLayerValidationTests/files/out.txt", "w", stdout);
17018 freopen("/sdcard/Android/data/com.example.VulkanLayerValidationTests/files/err.txt", "w", stderr);
Cody Northrop1242dfd2016-07-13 17:24:59 -060017019
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017020 ::testing::InitGoogleTest(&argc, argv);
17021 VkTestFramework::InitArgs(&argc, argv);
17022 ::testing::AddGlobalTestEnvironment(new TestEnvironment);
Cody Northrop1242dfd2016-07-13 17:24:59 -060017023
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017024 int result = RUN_ALL_TESTS();
Cody Northrop1242dfd2016-07-13 17:24:59 -060017025
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017026 if (result != 0) {
17027 __android_log_print(ANDROID_LOG_INFO, appTag, "==== Tests FAILED ====");
17028 } else {
17029 __android_log_print(ANDROID_LOG_INFO, appTag, "==== Tests PASSED ====");
17030 }
Cody Northrop1242dfd2016-07-13 17:24:59 -060017031
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017032 VkTestFramework::Finish();
Cody Northrop1242dfd2016-07-13 17:24:59 -060017033
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017034 fclose(stdout);
17035 fclose(stderr);
Cody Northrop1242dfd2016-07-13 17:24:59 -060017036
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017037 ANativeActivity_finish(app->activity);
Cody Northrop1242dfd2016-07-13 17:24:59 -060017038
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017039 return;
Cody Northrop1242dfd2016-07-13 17:24:59 -060017040 }
17041 }
17042}
17043#endif
17044
Tony Barbour300a6082015-04-07 13:44:53 -060017045int main(int argc, char **argv) {
17046 int result;
17047
Cody Northrop8e54a402016-03-08 22:25:52 -070017048#ifdef ANDROID
17049 int vulkanSupport = InitVulkan();
17050 if (vulkanSupport == 0)
17051 return 1;
17052#endif
17053
Tony Barbour300a6082015-04-07 13:44:53 -060017054 ::testing::InitGoogleTest(&argc, argv);
Tony Barbour6918cd52015-04-09 12:58:51 -060017055 VkTestFramework::InitArgs(&argc, argv);
Tony Barbour300a6082015-04-07 13:44:53 -060017056
17057 ::testing::AddGlobalTestEnvironment(new TestEnvironment);
17058
17059 result = RUN_ALL_TESTS();
17060
Tony Barbour6918cd52015-04-09 12:58:51 -060017061 VkTestFramework::Finish();
Tony Barbour300a6082015-04-07 13:44:53 -060017062 return result;
17063}