blob: 49fef96c85c08a24e52ee16bfe7261cfc3c2ea57 [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
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600386 VkConstantBufferObj constantBuffer(m_device, bufSize * 2, sizeof(float), (const void *)&data);
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500387
Karl Schultz6addd812016-02-02 17:17:23 -0700388 VkShaderObj vs(m_device, vertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600389 VkShaderObj ps(m_device, fragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500390
391 VkPipelineObj pipelineobj(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +0800392 pipelineobj.AddColorAttachment();
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500393 pipelineobj.AddShader(&vs);
394 pipelineobj.AddShader(&ps);
Courtney Goeltzenleuchter507ba972015-09-30 16:16:57 -0600395 if (failMask & BsoFailLineWidth) {
396 pipelineobj.MakeDynamic(VK_DYNAMIC_STATE_LINE_WIDTH);
Tobin Ehlis7a1d2352016-03-28 11:18:19 -0600397 VkPipelineInputAssemblyStateCreateInfo ia_state = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600398 ia_state.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
Tobin Ehlis7a1d2352016-03-28 11:18:19 -0600399 ia_state.topology = VK_PRIMITIVE_TOPOLOGY_LINE_LIST;
400 pipelineobj.SetInputAssembly(&ia_state);
Courtney Goeltzenleuchter507ba972015-09-30 16:16:57 -0600401 }
402 if (failMask & BsoFailDepthBias) {
403 pipelineobj.MakeDynamic(VK_DYNAMIC_STATE_DEPTH_BIAS);
Tobin Ehlis7a1d2352016-03-28 11:18:19 -0600404 VkPipelineRasterizationStateCreateInfo rs_state = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600405 rs_state.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
Tobin Ehlis7a1d2352016-03-28 11:18:19 -0600406 rs_state.depthBiasEnable = VK_TRUE;
Mark Young7394fdd2016-03-31 14:56:43 -0600407 rs_state.lineWidth = 1.0f;
Tobin Ehlis7a1d2352016-03-28 11:18:19 -0600408 pipelineobj.SetRasterization(&rs_state);
Courtney Goeltzenleuchter507ba972015-09-30 16:16:57 -0600409 }
Karl Schultz6addd812016-02-02 17:17:23 -0700410 // Viewport and scissors must stay in synch or other errors will occur than
411 // the ones we want
Courtney Goeltzenleuchter507ba972015-09-30 16:16:57 -0600412 if (failMask & BsoFailViewport) {
413 pipelineobj.MakeDynamic(VK_DYNAMIC_STATE_VIEWPORT);
Tobin Ehlisd332f282015-10-02 11:00:56 -0600414 m_viewports.clear();
415 m_scissors.clear();
Courtney Goeltzenleuchter507ba972015-09-30 16:16:57 -0600416 }
417 if (failMask & BsoFailScissor) {
418 pipelineobj.MakeDynamic(VK_DYNAMIC_STATE_SCISSOR);
Tobin Ehlisd332f282015-10-02 11:00:56 -0600419 m_scissors.clear();
420 m_viewports.clear();
Courtney Goeltzenleuchter507ba972015-09-30 16:16:57 -0600421 }
422 if (failMask & BsoFailBlend) {
423 pipelineobj.MakeDynamic(VK_DYNAMIC_STATE_BLEND_CONSTANTS);
Tobin Ehlis7a1d2352016-03-28 11:18:19 -0600424 VkPipelineColorBlendAttachmentState att_state = {};
425 att_state.dstAlphaBlendFactor = VK_BLEND_FACTOR_CONSTANT_COLOR;
426 att_state.blendEnable = VK_TRUE;
427 pipelineobj.AddColorAttachment(0, &att_state);
Courtney Goeltzenleuchter507ba972015-09-30 16:16:57 -0600428 }
429 if (failMask & BsoFailDepthBounds) {
430 pipelineobj.MakeDynamic(VK_DYNAMIC_STATE_DEPTH_BOUNDS);
431 }
432 if (failMask & BsoFailStencilReadMask) {
433 pipelineobj.MakeDynamic(VK_DYNAMIC_STATE_STENCIL_COMPARE_MASK);
434 }
435 if (failMask & BsoFailStencilWriteMask) {
436 pipelineobj.MakeDynamic(VK_DYNAMIC_STATE_STENCIL_WRITE_MASK);
437 }
438 if (failMask & BsoFailStencilReference) {
439 pipelineobj.MakeDynamic(VK_DYNAMIC_STATE_STENCIL_REFERENCE);
440 }
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500441
442 VkDescriptorSetObj descriptorSet(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600443 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, constantBuffer);
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500444
445 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barbourfe3351b2015-07-28 10:17:20 -0600446 ASSERT_VK_SUCCESS(BeginCommandBuffer());
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500447
Tony Barbourfe3351b2015-07-28 10:17:20 -0600448 GenericDrawPreparation(pipelineobj, descriptorSet, failMask);
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500449
450 // render triangle
Tobin Ehlis379ba3b2016-07-19 11:22:29 -0600451 if (failMask & BsoFailIndexBuffer) {
452 // Use DrawIndexed w/o an index buffer bound
453 DrawIndexed(3, 1, 0, 0, 0);
454 } else {
455 Draw(3, 1, 0, 0);
456 }
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500457
Mark Muellerd4914412016-06-13 17:52:06 -0600458 if (failMask & BsoFailCmdClearAttachments) {
459 VkClearAttachment color_attachment = {};
460 color_attachment.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
461 color_attachment.colorAttachment = 1; // Someone who knew what they were doing would use 0 for the index;
462 VkClearRect clear_rect = {{{0, 0}, {static_cast<uint32_t>(m_width), static_cast<uint32_t>(m_height)}}, 0, 0};
463
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600464 vkCmdClearAttachments(m_commandBuffer->GetBufferHandle(), 1, &color_attachment, 1, &clear_rect);
Mark Muellerd4914412016-06-13 17:52:06 -0600465 }
466
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500467 // finalize recording of the command buffer
Tony Barbourfe3351b2015-07-28 10:17:20 -0600468 EndCommandBuffer();
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500469
Tony Barbourfe3351b2015-07-28 10:17:20 -0600470 QueueCommandBuffer();
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500471}
472
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600473void VkLayerTest::GenericDrawPreparation(VkCommandBufferObj *commandBuffer, VkPipelineObj &pipelineobj,
474 VkDescriptorSetObj &descriptorSet, BsoFailSelect failMask) {
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500475 if (m_depthStencil->Initialized()) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600476 commandBuffer->ClearAllBuffers(m_clear_color, m_depth_clear_color, m_stencil_clear_color, m_depthStencil);
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500477 } else {
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600478 commandBuffer->ClearAllBuffers(m_clear_color, m_depth_clear_color, m_stencil_clear_color, NULL);
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500479 }
480
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800481 commandBuffer->PrepareAttachments();
Karl Schultz6addd812016-02-02 17:17:23 -0700482 // Make sure depthWriteEnable is set so that Depth fail test will work
483 // correctly
484 // Make sure stencilTestEnable is set so that Stencil fail test will work
485 // correctly
Tony Barboureb254902015-07-15 12:50:33 -0600486 VkStencilOpState stencil = {};
Chia-I Wu1b99bb22015-10-27 19:25:11 +0800487 stencil.failOp = VK_STENCIL_OP_KEEP;
488 stencil.passOp = VK_STENCIL_OP_KEEP;
489 stencil.depthFailOp = VK_STENCIL_OP_KEEP;
490 stencil.compareOp = VK_COMPARE_OP_NEVER;
Tony Barboureb254902015-07-15 12:50:33 -0600491
492 VkPipelineDepthStencilStateCreateInfo ds_ci = {};
493 ds_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_DEPTH_STENCIL_STATE_CREATE_INFO;
Courtney Goeltzenleuchter507ba972015-09-30 16:16:57 -0600494 ds_ci.pNext = NULL;
495 ds_ci.depthTestEnable = VK_FALSE;
496 ds_ci.depthWriteEnable = VK_TRUE;
497 ds_ci.depthCompareOp = VK_COMPARE_OP_NEVER;
498 ds_ci.depthBoundsTestEnable = VK_FALSE;
Tobin Ehlis7a1d2352016-03-28 11:18:19 -0600499 if (failMask & BsoFailDepthBounds) {
500 ds_ci.depthBoundsTestEnable = VK_TRUE;
Tobin Ehlis21c88352016-05-26 06:15:45 -0600501 ds_ci.maxDepthBounds = 0.0f;
502 ds_ci.minDepthBounds = 0.0f;
Tobin Ehlis7a1d2352016-03-28 11:18:19 -0600503 }
Courtney Goeltzenleuchter507ba972015-09-30 16:16:57 -0600504 ds_ci.stencilTestEnable = VK_TRUE;
505 ds_ci.front = stencil;
506 ds_ci.back = stencil;
Tony Barboureb254902015-07-15 12:50:33 -0600507
Tobin Ehlis4bf96d12015-06-25 11:58:41 -0600508 pipelineobj.SetDepthStencil(&ds_ci);
Tobin Ehlisd332f282015-10-02 11:00:56 -0600509 pipelineobj.SetViewport(m_viewports);
510 pipelineobj.SetScissor(m_scissors);
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800511 descriptorSet.CreateVKDescriptorSet(commandBuffer);
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600512 VkResult err = pipelineobj.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Cody Northrop29a08f22015-08-27 10:20:35 -0600513 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800514 commandBuffer->BindPipeline(pipelineobj);
515 commandBuffer->BindDescriptorSet(descriptorSet);
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500516}
517
Ian Elliott2c1daf52016-05-12 09:41:46 -0600518class VkWsiEnabledLayerTest : public VkLayerTest {
519 public:
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600520 protected:
521 VkWsiEnabledLayerTest() { m_enableWSI = true; }
Ian Elliott2c1daf52016-05-12 09:41:46 -0600522};
523
Mark Muellerdfe37552016-07-07 14:47:42 -0600524class VkBufferTest {
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600525 public:
Mark Muellerdfe37552016-07-07 14:47:42 -0600526 enum eTestEnFlags {
527 eDoubleDelete,
528 eInvalidDeviceOffset,
529 eInvalidMemoryOffset,
530 eBindNullBuffer,
531 eFreeInvalidHandle,
Mark Mueller4042b652016-09-05 22:52:21 -0600532 eNone,
Mark Muellerdfe37552016-07-07 14:47:42 -0600533 };
534
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600535 enum eTestConditions { eOffsetAlignment = 1 };
Mark Muellerdfe37552016-07-07 14:47:42 -0600536
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600537 static bool GetTestConditionValid(VkDeviceObj *aVulkanDevice, eTestEnFlags aTestFlag, VkBufferUsageFlags aBufferUsage = 0) {
538 if (eInvalidDeviceOffset != aTestFlag && eInvalidMemoryOffset != aTestFlag) {
Mark Muellerdfe37552016-07-07 14:47:42 -0600539 return true;
540 }
541 VkDeviceSize offset_limit = 0;
542 if (eInvalidMemoryOffset == aTestFlag) {
543 VkBuffer vulkanBuffer;
544 VkBufferCreateInfo buffer_create_info = {};
545 buffer_create_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
546 buffer_create_info.size = 32;
547 buffer_create_info.usage = aBufferUsage;
548
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600549 vkCreateBuffer(aVulkanDevice->device(), &buffer_create_info, nullptr, &vulkanBuffer);
Mark Mueller4042b652016-09-05 22:52:21 -0600550 VkMemoryRequirements memory_reqs = {};
Mark Muellerdfe37552016-07-07 14:47:42 -0600551
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600552 vkGetBufferMemoryRequirements(aVulkanDevice->device(), vulkanBuffer, &memory_reqs);
Mark Muellerdfe37552016-07-07 14:47:42 -0600553 vkDestroyBuffer(aVulkanDevice->device(), vulkanBuffer, nullptr);
554 offset_limit = memory_reqs.alignment;
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600555 } else if ((VK_BUFFER_USAGE_UNIFORM_TEXEL_BUFFER_BIT | VK_BUFFER_USAGE_STORAGE_TEXEL_BUFFER_BIT) & aBufferUsage) {
556 offset_limit = aVulkanDevice->props.limits.minTexelBufferOffsetAlignment;
Mark Muellerdfe37552016-07-07 14:47:42 -0600557 } else if (VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT & aBufferUsage) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600558 offset_limit = aVulkanDevice->props.limits.minUniformBufferOffsetAlignment;
Mark Muellerdfe37552016-07-07 14:47:42 -0600559 } else if (VK_BUFFER_USAGE_STORAGE_BUFFER_BIT & aBufferUsage) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600560 offset_limit = aVulkanDevice->props.limits.minStorageBufferOffsetAlignment;
Mark Muellerdfe37552016-07-07 14:47:42 -0600561 }
562 if (eOffsetAlignment < offset_limit) {
563 return true;
564 }
565 return false;
566 }
567
568 // A constructor which performs validation tests within construction.
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600569 VkBufferTest(VkDeviceObj *aVulkanDevice, VkBufferUsageFlags aBufferUsage, eTestEnFlags aTestFlag = eNone)
570 : AllocateCurrent(false), BoundCurrent(false), CreateCurrent(false), VulkanDevice(aVulkanDevice->device()) {
Mark Muellerdfe37552016-07-07 14:47:42 -0600571
572 if (eBindNullBuffer == aTestFlag) {
573 VulkanMemory = 0;
574 vkBindBufferMemory(VulkanDevice, VulkanBuffer, VulkanMemory, 0);
575 } else {
576 VkBufferCreateInfo buffer_create_info = {};
577 buffer_create_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
578 buffer_create_info.size = 32;
579 buffer_create_info.usage = aBufferUsage;
580
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600581 vkCreateBuffer(VulkanDevice, &buffer_create_info, nullptr, &VulkanBuffer);
Mark Muellerdfe37552016-07-07 14:47:42 -0600582
583 CreateCurrent = true;
584
585 VkMemoryRequirements memory_requirements;
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600586 vkGetBufferMemoryRequirements(VulkanDevice, VulkanBuffer, &memory_requirements);
Mark Muellerdfe37552016-07-07 14:47:42 -0600587
588 VkMemoryAllocateInfo memory_allocate_info = {};
589 memory_allocate_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
590 memory_allocate_info.allocationSize = memory_requirements.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600591 bool pass = aVulkanDevice->phy().set_memory_type(memory_requirements.memoryTypeBits, &memory_allocate_info,
592 VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT);
Mark Muellerdfe37552016-07-07 14:47:42 -0600593 if (!pass) {
594 vkDestroyBuffer(VulkanDevice, VulkanBuffer, nullptr);
595 return;
596 }
597
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600598 vkAllocateMemory(VulkanDevice, &memory_allocate_info, NULL, &VulkanMemory);
Mark Muellerdfe37552016-07-07 14:47:42 -0600599 AllocateCurrent = true;
600 // NB: 1 is intentionally an invalid offset value
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600601 const bool offset_en = eInvalidDeviceOffset == aTestFlag || eInvalidMemoryOffset == aTestFlag;
602 vkBindBufferMemory(VulkanDevice, VulkanBuffer, VulkanMemory, offset_en ? eOffsetAlignment : 0);
Mark Muellerdfe37552016-07-07 14:47:42 -0600603 BoundCurrent = true;
604
605 InvalidDeleteEn = (eFreeInvalidHandle == aTestFlag);
606 }
607 }
608
609 ~VkBufferTest() {
610 if (CreateCurrent) {
611 vkDestroyBuffer(VulkanDevice, VulkanBuffer, nullptr);
612 }
613 if (AllocateCurrent) {
614 if (InvalidDeleteEn) {
615 union {
616 VkDeviceMemory device_memory;
617 unsigned long long index_access;
618 } bad_index;
619
620 bad_index.device_memory = VulkanMemory;
621 bad_index.index_access++;
622
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600623 vkFreeMemory(VulkanDevice, bad_index.device_memory, nullptr);
Mark Muellerdfe37552016-07-07 14:47:42 -0600624 }
625 vkFreeMemory(VulkanDevice, VulkanMemory, nullptr);
626 }
627 }
628
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600629 bool GetBufferCurrent() { return AllocateCurrent && BoundCurrent && CreateCurrent; }
Mark Muellerdfe37552016-07-07 14:47:42 -0600630
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600631 const VkBuffer &GetBuffer() { return VulkanBuffer; }
Mark Muellerdfe37552016-07-07 14:47:42 -0600632
633 void TestDoubleDestroy() {
634 // Destroy the buffer but leave the flag set, which will cause
635 // the buffer to be destroyed again in the destructor.
636 vkDestroyBuffer(VulkanDevice, VulkanBuffer, nullptr);
637 }
638
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600639 protected:
Mark Muellerdfe37552016-07-07 14:47:42 -0600640 bool AllocateCurrent;
641 bool BoundCurrent;
642 bool CreateCurrent;
643 bool InvalidDeleteEn;
644
645 VkBuffer VulkanBuffer;
646 VkDevice VulkanDevice;
647 VkDeviceMemory VulkanMemory;
Mark Muellerdfe37552016-07-07 14:47:42 -0600648};
649
650class VkVerticesObj {
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600651 public:
652 VkVerticesObj(VkDeviceObj *aVulkanDevice, unsigned aAttributeCount, unsigned aBindingCount, unsigned aByteStride,
Mark Muellerdfe37552016-07-07 14:47:42 -0600653 VkDeviceSize aVertexCount, const float *aVerticies)
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600654 : BoundCurrent(false), AttributeCount(aAttributeCount), BindingCount(aBindingCount), BindId(BindIdGenerator),
Mark Muellerdfe37552016-07-07 14:47:42 -0600655 PipelineVertexInputStateCreateInfo(),
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600656 VulkanMemoryBuffer(aVulkanDevice, 1, static_cast<int>(aByteStride * aVertexCount),
657 reinterpret_cast<const void *>(aVerticies), VK_BUFFER_USAGE_VERTEX_BUFFER_BIT) {
Mark Muellerdfe37552016-07-07 14:47:42 -0600658 BindIdGenerator++; // NB: This can wrap w/misuse
659
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600660 VertexInputAttributeDescription = new VkVertexInputAttributeDescription[AttributeCount];
661 VertexInputBindingDescription = new VkVertexInputBindingDescription[BindingCount];
Mark Muellerdfe37552016-07-07 14:47:42 -0600662
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600663 PipelineVertexInputStateCreateInfo.pVertexAttributeDescriptions = VertexInputAttributeDescription;
664 PipelineVertexInputStateCreateInfo.vertexAttributeDescriptionCount = AttributeCount;
665 PipelineVertexInputStateCreateInfo.pVertexBindingDescriptions = VertexInputBindingDescription;
666 PipelineVertexInputStateCreateInfo.vertexBindingDescriptionCount = BindingCount;
667 PipelineVertexInputStateCreateInfo.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
Mark Muellerdfe37552016-07-07 14:47:42 -0600668
669 unsigned i = 0;
670 do {
671 VertexInputAttributeDescription[i].binding = BindId;
672 VertexInputAttributeDescription[i].location = i;
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600673 VertexInputAttributeDescription[i].format = VK_FORMAT_R32G32B32_SFLOAT;
674 VertexInputAttributeDescription[i].offset = sizeof(float) * aByteStride;
Mark Muellerdfe37552016-07-07 14:47:42 -0600675 i++;
676 } while (AttributeCount < i);
677
678 i = 0;
679 do {
680 VertexInputBindingDescription[i].binding = BindId;
681 VertexInputBindingDescription[i].stride = aByteStride;
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600682 VertexInputBindingDescription[i].inputRate = VK_VERTEX_INPUT_RATE_VERTEX;
Mark Muellerdfe37552016-07-07 14:47:42 -0600683 i++;
684 } while (BindingCount < i);
685 }
686
687 ~VkVerticesObj() {
688 if (VertexInputAttributeDescription) {
689 delete[] VertexInputAttributeDescription;
690 }
691 if (VertexInputBindingDescription) {
692 delete[] VertexInputBindingDescription;
693 }
694 }
695
696 bool AddVertexInputToPipe(VkPipelineObj &aPipelineObj) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600697 aPipelineObj.AddVertexInputAttribs(VertexInputAttributeDescription, AttributeCount);
698 aPipelineObj.AddVertexInputBindings(VertexInputBindingDescription, BindingCount);
Mark Muellerdfe37552016-07-07 14:47:42 -0600699 return true;
700 }
701
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600702 void BindVertexBuffers(VkCommandBuffer aCommandBuffer, unsigned aOffsetCount = 0, VkDeviceSize *aOffsetList = nullptr) {
Mark Muellerdfe37552016-07-07 14:47:42 -0600703 VkDeviceSize *offsetList;
704 unsigned offsetCount;
705
706 if (aOffsetCount) {
707 offsetList = aOffsetList;
708 offsetCount = aOffsetCount;
709 } else {
710 offsetList = new VkDeviceSize[1]();
711 offsetCount = 1;
712 }
713
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600714 vkCmdBindVertexBuffers(aCommandBuffer, BindId, offsetCount, &VulkanMemoryBuffer.handle(), offsetList);
Mark Muellerdfe37552016-07-07 14:47:42 -0600715 BoundCurrent = true;
716
717 if (!aOffsetCount) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600718 delete[] offsetList;
Mark Muellerdfe37552016-07-07 14:47:42 -0600719 }
720 }
721
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600722 protected:
Mark Muellerdfe37552016-07-07 14:47:42 -0600723 static uint32_t BindIdGenerator;
724
725 bool BoundCurrent;
726 unsigned AttributeCount;
727 unsigned BindingCount;
728 uint32_t BindId;
729
730 VkPipelineVertexInputStateCreateInfo PipelineVertexInputStateCreateInfo;
731 VkVertexInputAttributeDescription *VertexInputAttributeDescription;
732 VkVertexInputBindingDescription *VertexInputBindingDescription;
733 VkConstantBufferObj VulkanMemoryBuffer;
734};
735
736uint32_t VkVerticesObj::BindIdGenerator;
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500737// ********************************************************************************************************************
738// ********************************************************************************************************************
739// ********************************************************************************************************************
740// ********************************************************************************************************************
Dustin Gravesffa90fa2016-05-06 11:20:38 -0600741#if PARAMETER_VALIDATION_TESTS
742TEST_F(VkLayerTest, RequiredParameter) {
743 TEST_DESCRIPTION("Specify VK_NULL_HANDLE, NULL, and 0 for required handle, "
744 "pointer, array, and array count parameters");
745
746 ASSERT_NO_FATAL_FAILURE(InitState());
747
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600748 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "required parameter pFeatures specified as NULL");
Dustin Gravesffa90fa2016-05-06 11:20:38 -0600749 // Specify NULL for a pointer to a handle
750 // Expected to trigger an error with
751 // parameter_validation::validate_required_pointer
752 vkGetPhysicalDeviceFeatures(gpu(), NULL);
753 m_errorMonitor->VerifyFound();
754
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600755 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
756 "required parameter pQueueFamilyPropertyCount specified as NULL");
Dustin Gravesffa90fa2016-05-06 11:20:38 -0600757 // Specify NULL for pointer to array count
758 // Expected to trigger an error with parameter_validation::validate_array
Dustin Gravesa4bb8c12016-05-16 17:22:51 -0600759 vkGetPhysicalDeviceQueueFamilyProperties(gpu(), NULL, NULL);
Dustin Gravesffa90fa2016-05-06 11:20:38 -0600760 m_errorMonitor->VerifyFound();
761
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600762 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "parameter viewportCount must be greater than 0");
Dustin Gravesffa90fa2016-05-06 11:20:38 -0600763 // Specify 0 for a required array count
764 // Expected to trigger an error with parameter_validation::validate_array
765 VkViewport view_port = {};
766 m_commandBuffer->SetViewport(0, 0, &view_port);
767 m_errorMonitor->VerifyFound();
768
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600769 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "required parameter pViewports specified as NULL");
Dustin Gravesffa90fa2016-05-06 11:20:38 -0600770 // Specify NULL for a required array
771 // Expected to trigger an error with parameter_validation::validate_array
772 m_commandBuffer->SetViewport(0, 1, NULL);
773 m_errorMonitor->VerifyFound();
774
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600775 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "required parameter memory specified as VK_NULL_HANDLE");
Dustin Gravesffa90fa2016-05-06 11:20:38 -0600776 // Specify VK_NULL_HANDLE for a required handle
777 // Expected to trigger an error with
778 // parameter_validation::validate_required_handle
779 vkUnmapMemory(device(), VK_NULL_HANDLE);
780 m_errorMonitor->VerifyFound();
781
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600782 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
783 "required parameter pFences[0] specified as VK_NULL_HANDLE");
Dustin Gravesffa90fa2016-05-06 11:20:38 -0600784 // Specify VK_NULL_HANDLE for a required handle array entry
785 // Expected to trigger an error with
786 // parameter_validation::validate_required_handle_array
787 VkFence fence = VK_NULL_HANDLE;
788 vkResetFences(device(), 1, &fence);
789 m_errorMonitor->VerifyFound();
790
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600791 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "required parameter pAllocateInfo specified as NULL");
Dustin Gravesffa90fa2016-05-06 11:20:38 -0600792 // Specify NULL for a required struct pointer
793 // Expected to trigger an error with
794 // parameter_validation::validate_struct_type
795 VkDeviceMemory memory = VK_NULL_HANDLE;
796 vkAllocateMemory(device(), NULL, NULL, &memory);
797 m_errorMonitor->VerifyFound();
798
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600799 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "value of faceMask must not be 0");
Dustin Gravesffa90fa2016-05-06 11:20:38 -0600800 // Specify 0 for a required VkFlags parameter
801 // Expected to trigger an error with parameter_validation::validate_flags
802 m_commandBuffer->SetStencilReference(0, 0);
803 m_errorMonitor->VerifyFound();
804
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600805 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "value of pSubmits[0].pWaitDstStageMask[0] must not be 0");
Dustin Gravesffa90fa2016-05-06 11:20:38 -0600806 // Specify 0 for a required VkFlags array entry
807 // Expected to trigger an error with
808 // parameter_validation::validate_flags_array
809 VkSemaphore semaphore = VK_NULL_HANDLE;
810 VkPipelineStageFlags stageFlags = 0;
811 VkSubmitInfo submitInfo = {};
812 submitInfo.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
813 submitInfo.waitSemaphoreCount = 1;
814 submitInfo.pWaitSemaphores = &semaphore;
815 submitInfo.pWaitDstStageMask = &stageFlags;
816 vkQueueSubmit(m_device->m_queue, 1, &submitInfo, VK_NULL_HANDLE);
817 m_errorMonitor->VerifyFound();
818}
Dustin Gravesc99cf5a2016-05-09 14:40:29 -0600819
Dustin Gravesfce74c02016-05-10 11:42:58 -0600820TEST_F(VkLayerTest, ReservedParameter) {
821 TEST_DESCRIPTION("Specify a non-zero value for a reserved parameter");
822
823 ASSERT_NO_FATAL_FAILURE(InitState());
824
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600825 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " must be 0");
Dustin Gravesfce74c02016-05-10 11:42:58 -0600826 // Specify 0 for a reserved VkFlags parameter
827 // Expected to trigger an error with
828 // parameter_validation::validate_reserved_flags
829 VkEvent event_handle = VK_NULL_HANDLE;
830 VkEventCreateInfo event_info = {};
831 event_info.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO;
832 event_info.flags = 1;
833 vkCreateEvent(device(), &event_info, NULL, &event_handle);
834 m_errorMonitor->VerifyFound();
835}
836
Dustin Gravesc99cf5a2016-05-09 14:40:29 -0600837TEST_F(VkLayerTest, InvalidStructSType) {
838 TEST_DESCRIPTION("Specify an invalid VkStructureType for a Vulkan "
839 "structure's sType field");
840
841 ASSERT_NO_FATAL_FAILURE(InitState());
842
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600843 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "parameter pAllocateInfo->sType must be");
Dustin Gravesc99cf5a2016-05-09 14:40:29 -0600844 // Zero struct memory, effectively setting sType to
845 // VK_STRUCTURE_TYPE_APPLICATION_INFO
846 // Expected to trigger an error with
847 // parameter_validation::validate_struct_type
848 VkMemoryAllocateInfo alloc_info = {};
849 VkDeviceMemory memory = VK_NULL_HANDLE;
850 vkAllocateMemory(device(), &alloc_info, NULL, &memory);
851 m_errorMonitor->VerifyFound();
852
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600853 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "parameter pSubmits[0].sType must be");
Dustin Gravesc99cf5a2016-05-09 14:40:29 -0600854 // Zero struct memory, effectively setting sType to
855 // VK_STRUCTURE_TYPE_APPLICATION_INFO
856 // Expected to trigger an error with
857 // parameter_validation::validate_struct_type_array
858 VkSubmitInfo submit_info = {};
859 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
860 m_errorMonitor->VerifyFound();
861}
862
863TEST_F(VkLayerTest, InvalidStructPNext) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600864 TEST_DESCRIPTION("Specify an invalid value for a Vulkan structure's pNext field");
Dustin Gravesc99cf5a2016-05-09 14:40:29 -0600865
866 ASSERT_NO_FATAL_FAILURE(InitState());
867
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600868 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT, "value of pCreateInfo->pNext must be NULL");
Dustin Gravesc99cf5a2016-05-09 14:40:29 -0600869 // Set VkMemoryAllocateInfo::pNext to a non-NULL value, when pNext must be
Karl Schultz38b50992016-07-11 16:09:09 -0600870 // NULL.
871 // Need to pick a function that has no allowed pNext structure types.
872 // Expected to trigger an error with
873 // parameter_validation::validate_struct_pnext
874 VkEvent event = VK_NULL_HANDLE;
Karl Schultz70db3902016-07-11 16:22:10 -0600875 VkEventCreateInfo event_alloc_info = {};
Karl Schultz38b50992016-07-11 16:09:09 -0600876 // Zero-initialization will provide the correct sType
877 VkApplicationInfo app_info = {};
878 event_alloc_info.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO;
879 event_alloc_info.pNext = &app_info;
880 vkCreateEvent(device(), &event_alloc_info, NULL, &event);
881 m_errorMonitor->VerifyFound();
882
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600883 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT,
884 " chain includes a structure with unexpected VkStructureType ");
Karl Schultz38b50992016-07-11 16:09:09 -0600885 // Set VkMemoryAllocateInfo::pNext to a non-NULL value, but use
886 // a function that has allowed pNext structure types and specify
887 // a structure type that is not allowed.
Dustin Gravesc99cf5a2016-05-09 14:40:29 -0600888 // Expected to trigger an error with
889 // parameter_validation::validate_struct_pnext
890 VkDeviceMemory memory = VK_NULL_HANDLE;
Dustin Graves47b6cba2016-05-10 17:34:38 -0600891 VkMemoryAllocateInfo memory_alloc_info = {};
892 memory_alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
893 memory_alloc_info.pNext = &app_info;
894 vkAllocateMemory(device(), &memory_alloc_info, NULL, &memory);
Dustin Gravesc99cf5a2016-05-09 14:40:29 -0600895 m_errorMonitor->VerifyFound();
896
Dustin Gravesfd1c8fe2016-07-15 11:40:20 -0600897 // Positive test to check parameter_validation and unique_objects support
898 // for NV_dedicated_allocation
899 uint32_t extension_count = 0;
900 bool supports_nv_dedicated_allocation = false;
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600901 VkResult err = vkEnumerateDeviceExtensionProperties(gpu(), nullptr, &extension_count, nullptr);
Dustin Gravesfd1c8fe2016-07-15 11:40:20 -0600902 ASSERT_VK_SUCCESS(err);
903
904 if (extension_count > 0) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600905 std::vector<VkExtensionProperties> available_extensions(extension_count);
Dustin Gravesfd1c8fe2016-07-15 11:40:20 -0600906
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600907 err = vkEnumerateDeviceExtensionProperties(gpu(), nullptr, &extension_count, &available_extensions[0]);
Dustin Gravesfd1c8fe2016-07-15 11:40:20 -0600908 ASSERT_VK_SUCCESS(err);
909
910 for (const auto &extension_props : available_extensions) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600911 if (strcmp(extension_props.extensionName, VK_NV_DEDICATED_ALLOCATION_EXTENSION_NAME) == 0) {
Dustin Gravesfd1c8fe2016-07-15 11:40:20 -0600912 supports_nv_dedicated_allocation = true;
913 }
914 }
915 }
916
917 if (supports_nv_dedicated_allocation) {
918 m_errorMonitor->ExpectSuccess();
919
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600920 VkDedicatedAllocationBufferCreateInfoNV dedicated_buffer_create_info = {};
921 dedicated_buffer_create_info.sType = VK_STRUCTURE_TYPE_DEDICATED_ALLOCATION_BUFFER_CREATE_INFO_NV;
Dustin Gravesfd1c8fe2016-07-15 11:40:20 -0600922 dedicated_buffer_create_info.pNext = nullptr;
923 dedicated_buffer_create_info.dedicatedAllocation = VK_TRUE;
924
925 uint32_t queue_family_index = 0;
926 VkBufferCreateInfo buffer_create_info = {};
927 buffer_create_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
928 buffer_create_info.pNext = &dedicated_buffer_create_info;
929 buffer_create_info.size = 1024;
930 buffer_create_info.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
931 buffer_create_info.queueFamilyIndexCount = 1;
932 buffer_create_info.pQueueFamilyIndices = &queue_family_index;
933
934 VkBuffer buffer;
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600935 VkResult err = vkCreateBuffer(m_device->device(), &buffer_create_info, NULL, &buffer);
Dustin Gravesfd1c8fe2016-07-15 11:40:20 -0600936 ASSERT_VK_SUCCESS(err);
937
938 VkMemoryRequirements memory_reqs;
939 vkGetBufferMemoryRequirements(m_device->device(), buffer, &memory_reqs);
940
941 VkDedicatedAllocationMemoryAllocateInfoNV dedicated_memory_info = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600942 dedicated_memory_info.sType = VK_STRUCTURE_TYPE_DEDICATED_ALLOCATION_MEMORY_ALLOCATE_INFO_NV;
Dustin Gravesfd1c8fe2016-07-15 11:40:20 -0600943 dedicated_memory_info.pNext = nullptr;
944 dedicated_memory_info.buffer = buffer;
945 dedicated_memory_info.image = VK_NULL_HANDLE;
946
947 VkMemoryAllocateInfo memory_info = {};
948 memory_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
949 memory_info.pNext = &dedicated_memory_info;
950 memory_info.allocationSize = memory_reqs.size;
951
952 bool pass;
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600953 pass = m_device->phy().set_memory_type(memory_reqs.memoryTypeBits, &memory_info, 0);
Dustin Gravesfd1c8fe2016-07-15 11:40:20 -0600954 ASSERT_TRUE(pass);
955
956 VkDeviceMemory buffer_memory;
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600957 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &buffer_memory);
Dustin Gravesfd1c8fe2016-07-15 11:40:20 -0600958 ASSERT_VK_SUCCESS(err);
959
960 err = vkBindBufferMemory(m_device->device(), buffer, buffer_memory, 0);
961 ASSERT_VK_SUCCESS(err);
962
963 vkDestroyBuffer(m_device->device(), buffer, NULL);
964 vkFreeMemory(m_device->device(), buffer_memory, NULL);
965
966 m_errorMonitor->VerifyNotFound();
967 }
Dustin Gravesc99cf5a2016-05-09 14:40:29 -0600968}
Dustin Graves5d33d532016-05-09 16:21:12 -0600969
970TEST_F(VkLayerTest, UnrecognizedValue) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600971 TEST_DESCRIPTION("Specify unrecognized Vulkan enumeration, flags, and VkBool32 values");
Dustin Graves5d33d532016-05-09 16:21:12 -0600972
973 ASSERT_NO_FATAL_FAILURE(InitState());
974
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600975 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "does not fall within the begin..end "
976 "range of the core VkFormat "
977 "enumeration tokens");
Dustin Graves5d33d532016-05-09 16:21:12 -0600978 // Specify an invalid VkFormat value
979 // Expected to trigger an error with
980 // parameter_validation::validate_ranged_enum
981 VkFormatProperties format_properties;
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600982 vkGetPhysicalDeviceFormatProperties(gpu(), static_cast<VkFormat>(8000), &format_properties);
Dustin Graves5d33d532016-05-09 16:21:12 -0600983 m_errorMonitor->VerifyFound();
984
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600985 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "contains flag bits that are not recognized members of");
Dustin Graves5d33d532016-05-09 16:21:12 -0600986 // Specify an invalid VkFlags bitmask value
987 // Expected to trigger an error with parameter_validation::validate_flags
988 VkImageFormatProperties image_format_properties;
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600989 vkGetPhysicalDeviceImageFormatProperties(gpu(), VK_FORMAT_R8G8B8A8_UNORM, VK_IMAGE_TYPE_2D, VK_IMAGE_TILING_OPTIMAL,
990 static_cast<VkImageUsageFlags>(1 << 25), 0, &image_format_properties);
Dustin Graves5d33d532016-05-09 16:21:12 -0600991 m_errorMonitor->VerifyFound();
992
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600993 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "contains flag bits that are not recognized members of");
Dustin Graves5d33d532016-05-09 16:21:12 -0600994 // Specify an invalid VkFlags array entry
995 // Expected to trigger an error with
996 // parameter_validation::validate_flags_array
997 VkSemaphore semaphore = VK_NULL_HANDLE;
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600998 VkPipelineStageFlags stage_flags = static_cast<VkPipelineStageFlags>(1 << 25);
Dustin Graves5d33d532016-05-09 16:21:12 -0600999 VkSubmitInfo submit_info = {};
1000 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
1001 submit_info.waitSemaphoreCount = 1;
1002 submit_info.pWaitSemaphores = &semaphore;
1003 submit_info.pWaitDstStageMask = &stage_flags;
1004 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
1005 m_errorMonitor->VerifyFound();
1006
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001007 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT, "is neither VK_TRUE nor VK_FALSE");
Dustin Graves5d33d532016-05-09 16:21:12 -06001008 // Specify an invalid VkBool32 value
1009 // Expected to trigger a warning with
1010 // parameter_validation::validate_bool32
1011 VkSampler sampler = VK_NULL_HANDLE;
1012 VkSamplerCreateInfo sampler_info = {};
1013 sampler_info.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
1014 sampler_info.pNext = NULL;
1015 sampler_info.magFilter = VK_FILTER_NEAREST;
1016 sampler_info.minFilter = VK_FILTER_NEAREST;
1017 sampler_info.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
1018 sampler_info.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
1019 sampler_info.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
1020 sampler_info.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
1021 sampler_info.mipLodBias = 1.0;
1022 sampler_info.maxAnisotropy = 1;
1023 sampler_info.compareEnable = VK_FALSE;
1024 sampler_info.compareOp = VK_COMPARE_OP_NEVER;
1025 sampler_info.minLod = 1.0;
1026 sampler_info.maxLod = 1.0;
1027 sampler_info.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
1028 sampler_info.unnormalizedCoordinates = VK_FALSE;
1029 // Not VK_TRUE or VK_FALSE
1030 sampler_info.anisotropyEnable = 3;
1031 vkCreateSampler(m_device->device(), &sampler_info, NULL, &sampler);
1032 m_errorMonitor->VerifyFound();
1033}
Dustin Gravesfce74c02016-05-10 11:42:58 -06001034
1035TEST_F(VkLayerTest, FailedReturnValue) {
1036 TEST_DESCRIPTION("Check for a message describing a VkResult failure code");
1037
1038 ASSERT_NO_FATAL_FAILURE(InitState());
1039
Dustin Graves13c1e2b2016-05-16 15:31:02 -06001040 // Find an unsupported image format
1041 VkFormat unsupported = VK_FORMAT_UNDEFINED;
1042 for (int f = VK_FORMAT_BEGIN_RANGE; f <= VK_FORMAT_END_RANGE; f++) {
1043 VkFormat format = static_cast<VkFormat>(f);
1044 VkFormatProperties fProps = m_device->format_properties(format);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001045 if (format != VK_FORMAT_UNDEFINED && fProps.linearTilingFeatures == 0 && fProps.optimalTilingFeatures == 0) {
Dustin Graves13c1e2b2016-05-16 15:31:02 -06001046 unsupported = format;
1047 break;
1048 }
1049 }
1050
1051 if (unsupported != VK_FORMAT_UNDEFINED) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001052 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT,
1053 "the requested format is not supported on this device");
Dustin Graves13c1e2b2016-05-16 15:31:02 -06001054 // Specify an unsupported VkFormat value to generate a
1055 // VK_ERROR_FORMAT_NOT_SUPPORTED return code
1056 // Expected to trigger a warning from
1057 // parameter_validation::validate_result
1058 VkImageFormatProperties image_format_properties;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001059 VkResult err = vkGetPhysicalDeviceImageFormatProperties(gpu(), unsupported, VK_IMAGE_TYPE_2D, VK_IMAGE_TILING_OPTIMAL,
1060 VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT, 0, &image_format_properties);
Dustin Graves13c1e2b2016-05-16 15:31:02 -06001061 ASSERT_TRUE(err == VK_ERROR_FORMAT_NOT_SUPPORTED);
1062 m_errorMonitor->VerifyFound();
1063 }
Dustin Gravesfce74c02016-05-10 11:42:58 -06001064}
Mark Lobodzinskie090fef2016-06-09 17:04:56 -06001065
1066TEST_F(VkLayerTest, UpdateBufferAlignment) {
1067 TEST_DESCRIPTION("Check alignment parameters for vkCmdUpdateBuffer");
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001068 uint32_t updateData[] = {1, 2, 3, 4, 5, 6, 7, 8};
Mark Lobodzinskie090fef2016-06-09 17:04:56 -06001069
1070 ASSERT_NO_FATAL_FAILURE(InitState());
1071
1072 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
1073 vk_testing::Buffer buffer;
1074 buffer.init_as_dst(*m_device, (VkDeviceSize)20, reqs);
1075
1076 BeginCommandBuffer();
1077 // Introduce failure by using dstOffset that is not multiple of 4
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001078 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " is not a multiple of 4");
Mark Lobodzinskie090fef2016-06-09 17:04:56 -06001079 m_commandBuffer->UpdateBuffer(buffer.handle(), 1, 4, updateData);
1080 m_errorMonitor->VerifyFound();
1081
1082 // Introduce failure by using dataSize that is not multiple of 4
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001083 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " is not a multiple of 4");
Mark Lobodzinskie090fef2016-06-09 17:04:56 -06001084 m_commandBuffer->UpdateBuffer(buffer.handle(), 0, 6, updateData);
1085 m_errorMonitor->VerifyFound();
1086
1087 // Introduce failure by using dataSize that is < 0
1088 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001089 "must be greater than zero and less than or equal to 65536");
Mark Lobodzinskie090fef2016-06-09 17:04:56 -06001090 m_commandBuffer->UpdateBuffer(buffer.handle(), 0, -44, updateData);
1091 m_errorMonitor->VerifyFound();
1092
1093 // Introduce failure by using dataSize that is > 65536
1094 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001095 "must be greater than zero and less than or equal to 65536");
Mark Lobodzinskie090fef2016-06-09 17:04:56 -06001096 m_commandBuffer->UpdateBuffer(buffer.handle(), 0, 80000, updateData);
1097 m_errorMonitor->VerifyFound();
1098
1099 EndCommandBuffer();
1100}
1101
1102TEST_F(VkLayerTest, FillBufferAlignment) {
1103 TEST_DESCRIPTION("Check alignment parameters for vkCmdFillBuffer");
1104
1105 ASSERT_NO_FATAL_FAILURE(InitState());
1106
1107 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
1108 vk_testing::Buffer buffer;
1109 buffer.init_as_dst(*m_device, (VkDeviceSize)20, reqs);
1110
1111 BeginCommandBuffer();
1112
1113 // Introduce failure by using dstOffset that is not multiple of 4
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001114 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " is not a multiple of 4");
Mark Lobodzinskie090fef2016-06-09 17:04:56 -06001115 m_commandBuffer->FillBuffer(buffer.handle(), 1, 4, 0x11111111);
1116 m_errorMonitor->VerifyFound();
1117
1118 // Introduce failure by using size that is not multiple of 4
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001119 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " is not a multiple of 4");
Mark Lobodzinskie090fef2016-06-09 17:04:56 -06001120 m_commandBuffer->FillBuffer(buffer.handle(), 0, 6, 0x11111111);
1121 m_errorMonitor->VerifyFound();
1122
1123 // Introduce failure by using size that is zero
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001124 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "must be greater than zero");
Mark Lobodzinskie090fef2016-06-09 17:04:56 -06001125 m_commandBuffer->FillBuffer(buffer.handle(), 0, 0, 0x11111111);
1126 m_errorMonitor->VerifyFound();
1127
1128 EndCommandBuffer();
1129}
Dustin Graves40f35822016-06-23 11:12:53 -06001130
1131// This is a positive test. No failures are expected.
1132TEST_F(VkLayerTest, IgnoreUnrelatedDescriptor) {
1133 TEST_DESCRIPTION("Ensure that the vkUpdateDescriptorSet validation code "
1134 "is ignoring VkWriteDescriptorSet members that are not "
1135 "related to the descriptor type specified by "
1136 "VkWriteDescriptorSet::descriptorType. Correct "
1137 "validation behavior will result in the test running to "
1138 "completion without validation errors.");
1139
Dustin Graves5e2d8fc2016-07-07 16:18:49 -06001140 const uintptr_t invalid_ptr = 0xcdcdcdcd;
1141
Dustin Graves40f35822016-06-23 11:12:53 -06001142 ASSERT_NO_FATAL_FAILURE(InitState());
1143
1144 // Image Case
1145 {
1146 m_errorMonitor->ExpectSuccess();
1147
1148 VkImage image;
1149 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
1150 const int32_t tex_width = 32;
1151 const int32_t tex_height = 32;
1152 VkImageCreateInfo image_create_info = {};
1153 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
1154 image_create_info.pNext = NULL;
1155 image_create_info.imageType = VK_IMAGE_TYPE_2D;
1156 image_create_info.format = tex_format;
1157 image_create_info.extent.width = tex_width;
1158 image_create_info.extent.height = tex_height;
1159 image_create_info.extent.depth = 1;
1160 image_create_info.mipLevels = 1;
1161 image_create_info.arrayLayers = 1;
1162 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
Tobin Ehlis51cde412016-07-11 16:08:30 -06001163 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
Dustin Graves40f35822016-06-23 11:12:53 -06001164 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
1165 image_create_info.flags = 0;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001166 VkResult err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
Dustin Graves40f35822016-06-23 11:12:53 -06001167 ASSERT_VK_SUCCESS(err);
1168
1169 VkMemoryRequirements memory_reqs;
1170 VkDeviceMemory image_memory;
1171 bool pass;
1172 VkMemoryAllocateInfo memory_info = {};
1173 memory_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
1174 memory_info.pNext = NULL;
1175 memory_info.allocationSize = 0;
1176 memory_info.memoryTypeIndex = 0;
1177 vkGetImageMemoryRequirements(m_device->device(), image, &memory_reqs);
1178 memory_info.allocationSize = memory_reqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001179 pass = m_device->phy().set_memory_type(memory_reqs.memoryTypeBits, &memory_info, 0);
Dustin Graves40f35822016-06-23 11:12:53 -06001180 ASSERT_TRUE(pass);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001181 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &image_memory);
Dustin Graves40f35822016-06-23 11:12:53 -06001182 ASSERT_VK_SUCCESS(err);
1183 err = vkBindImageMemory(m_device->device(), image, image_memory, 0);
1184 ASSERT_VK_SUCCESS(err);
1185
1186 VkImageViewCreateInfo image_view_create_info = {};
1187 image_view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
1188 image_view_create_info.image = image;
1189 image_view_create_info.viewType = VK_IMAGE_VIEW_TYPE_2D;
1190 image_view_create_info.format = tex_format;
1191 image_view_create_info.subresourceRange.layerCount = 1;
1192 image_view_create_info.subresourceRange.baseMipLevel = 0;
1193 image_view_create_info.subresourceRange.levelCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001194 image_view_create_info.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Dustin Graves40f35822016-06-23 11:12:53 -06001195
1196 VkImageView view;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001197 err = vkCreateImageView(m_device->device(), &image_view_create_info, NULL, &view);
Dustin Graves40f35822016-06-23 11:12:53 -06001198 ASSERT_VK_SUCCESS(err);
1199
1200 VkDescriptorPoolSize ds_type_count = {};
1201 ds_type_count.type = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE;
1202 ds_type_count.descriptorCount = 1;
1203
1204 VkDescriptorPoolCreateInfo ds_pool_ci = {};
1205 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
1206 ds_pool_ci.pNext = NULL;
1207 ds_pool_ci.maxSets = 1;
1208 ds_pool_ci.poolSizeCount = 1;
1209 ds_pool_ci.pPoolSizes = &ds_type_count;
1210
1211 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001212 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Dustin Graves40f35822016-06-23 11:12:53 -06001213 ASSERT_VK_SUCCESS(err);
1214
1215 VkDescriptorSetLayoutBinding dsl_binding = {};
1216 dsl_binding.binding = 0;
1217 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE;
1218 dsl_binding.descriptorCount = 1;
1219 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
1220 dsl_binding.pImmutableSamplers = NULL;
1221
1222 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001223 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
Dustin Graves40f35822016-06-23 11:12:53 -06001224 ds_layout_ci.pNext = NULL;
1225 ds_layout_ci.bindingCount = 1;
1226 ds_layout_ci.pBindings = &dsl_binding;
1227 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001228 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Dustin Graves40f35822016-06-23 11:12:53 -06001229 ASSERT_VK_SUCCESS(err);
1230
1231 VkDescriptorSet descriptor_set;
1232 VkDescriptorSetAllocateInfo alloc_info = {};
1233 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
1234 alloc_info.descriptorSetCount = 1;
1235 alloc_info.descriptorPool = ds_pool;
1236 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001237 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
Dustin Graves40f35822016-06-23 11:12:53 -06001238 ASSERT_VK_SUCCESS(err);
1239
1240 VkDescriptorImageInfo image_info = {};
1241 image_info.imageView = view;
1242 image_info.imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
1243
1244 VkWriteDescriptorSet descriptor_write;
1245 memset(&descriptor_write, 0, sizeof(descriptor_write));
1246 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
1247 descriptor_write.dstSet = descriptor_set;
1248 descriptor_write.dstBinding = 0;
1249 descriptor_write.descriptorCount = 1;
1250 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE;
1251 descriptor_write.pImageInfo = &image_info;
1252
1253 // Set pBufferInfo and pTexelBufferView to invalid values, which should
1254 // be
1255 // ignored for descriptorType == VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE.
1256 // This will most likely produce a crash if the parameter_validation
1257 // layer
1258 // does not correctly ignore pBufferInfo.
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001259 descriptor_write.pBufferInfo = reinterpret_cast<const VkDescriptorBufferInfo *>(invalid_ptr);
1260 descriptor_write.pTexelBufferView = reinterpret_cast<const VkBufferView *>(invalid_ptr);
Dustin Graves40f35822016-06-23 11:12:53 -06001261
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001262 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
Dustin Graves40f35822016-06-23 11:12:53 -06001263
1264 m_errorMonitor->VerifyNotFound();
1265
Dustin Graves40f35822016-06-23 11:12:53 -06001266 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
1267 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
1268 vkDestroyImageView(m_device->device(), view, NULL);
1269 vkDestroyImage(m_device->device(), image, NULL);
1270 vkFreeMemory(m_device->device(), image_memory, NULL);
1271 }
1272
1273 // Buffer Case
1274 {
1275 m_errorMonitor->ExpectSuccess();
1276
1277 VkBuffer buffer;
1278 uint32_t queue_family_index = 0;
1279 VkBufferCreateInfo buffer_create_info = {};
1280 buffer_create_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
1281 buffer_create_info.size = 1024;
1282 buffer_create_info.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
1283 buffer_create_info.queueFamilyIndexCount = 1;
1284 buffer_create_info.pQueueFamilyIndices = &queue_family_index;
1285
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001286 VkResult err = vkCreateBuffer(m_device->device(), &buffer_create_info, NULL, &buffer);
Dustin Graves40f35822016-06-23 11:12:53 -06001287 ASSERT_VK_SUCCESS(err);
1288
1289 VkMemoryRequirements memory_reqs;
1290 VkDeviceMemory buffer_memory;
1291 bool pass;
1292 VkMemoryAllocateInfo memory_info = {};
1293 memory_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
1294 memory_info.pNext = NULL;
1295 memory_info.allocationSize = 0;
1296 memory_info.memoryTypeIndex = 0;
1297
1298 vkGetBufferMemoryRequirements(m_device->device(), buffer, &memory_reqs);
1299 memory_info.allocationSize = memory_reqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001300 pass = m_device->phy().set_memory_type(memory_reqs.memoryTypeBits, &memory_info, 0);
Dustin Graves40f35822016-06-23 11:12:53 -06001301 ASSERT_TRUE(pass);
1302
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001303 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &buffer_memory);
Dustin Graves40f35822016-06-23 11:12:53 -06001304 ASSERT_VK_SUCCESS(err);
1305 err = vkBindBufferMemory(m_device->device(), buffer, buffer_memory, 0);
1306 ASSERT_VK_SUCCESS(err);
1307
1308 VkDescriptorPoolSize ds_type_count = {};
1309 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
1310 ds_type_count.descriptorCount = 1;
1311
1312 VkDescriptorPoolCreateInfo ds_pool_ci = {};
1313 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
1314 ds_pool_ci.pNext = NULL;
1315 ds_pool_ci.maxSets = 1;
1316 ds_pool_ci.poolSizeCount = 1;
1317 ds_pool_ci.pPoolSizes = &ds_type_count;
1318
1319 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001320 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Dustin Graves40f35822016-06-23 11:12:53 -06001321 ASSERT_VK_SUCCESS(err);
1322
1323 VkDescriptorSetLayoutBinding dsl_binding = {};
1324 dsl_binding.binding = 0;
1325 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
1326 dsl_binding.descriptorCount = 1;
1327 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
1328 dsl_binding.pImmutableSamplers = NULL;
1329
1330 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001331 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
Dustin Graves40f35822016-06-23 11:12:53 -06001332 ds_layout_ci.pNext = NULL;
1333 ds_layout_ci.bindingCount = 1;
1334 ds_layout_ci.pBindings = &dsl_binding;
1335 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001336 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Dustin Graves40f35822016-06-23 11:12:53 -06001337 ASSERT_VK_SUCCESS(err);
1338
1339 VkDescriptorSet descriptor_set;
1340 VkDescriptorSetAllocateInfo alloc_info = {};
1341 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
1342 alloc_info.descriptorSetCount = 1;
1343 alloc_info.descriptorPool = ds_pool;
1344 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001345 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
Dustin Graves40f35822016-06-23 11:12:53 -06001346 ASSERT_VK_SUCCESS(err);
1347
1348 VkDescriptorBufferInfo buffer_info = {};
1349 buffer_info.buffer = buffer;
1350 buffer_info.offset = 0;
1351 buffer_info.range = 1024;
1352
1353 VkWriteDescriptorSet descriptor_write;
1354 memset(&descriptor_write, 0, sizeof(descriptor_write));
1355 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
1356 descriptor_write.dstSet = descriptor_set;
1357 descriptor_write.dstBinding = 0;
1358 descriptor_write.descriptorCount = 1;
1359 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
1360 descriptor_write.pBufferInfo = &buffer_info;
1361
1362 // Set pImageInfo and pTexelBufferView to invalid values, which should
1363 // be
1364 // ignored for descriptorType == VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER.
1365 // This will most likely produce a crash if the parameter_validation
1366 // layer
1367 // does not correctly ignore pImageInfo.
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001368 descriptor_write.pImageInfo = reinterpret_cast<const VkDescriptorImageInfo *>(invalid_ptr);
1369 descriptor_write.pTexelBufferView = reinterpret_cast<const VkBufferView *>(invalid_ptr);
Dustin Graves40f35822016-06-23 11:12:53 -06001370
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001371 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
Dustin Graves40f35822016-06-23 11:12:53 -06001372
1373 m_errorMonitor->VerifyNotFound();
1374
1375 vkFreeDescriptorSets(m_device->device(), ds_pool, 1, &descriptor_set);
1376 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
1377 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
1378 vkDestroyBuffer(m_device->device(), buffer, NULL);
1379 vkFreeMemory(m_device->device(), buffer_memory, NULL);
1380 }
1381
1382 // Texel Buffer Case
1383 {
1384 m_errorMonitor->ExpectSuccess();
1385
1386 VkBuffer buffer;
1387 uint32_t queue_family_index = 0;
1388 VkBufferCreateInfo buffer_create_info = {};
1389 buffer_create_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
1390 buffer_create_info.size = 1024;
1391 buffer_create_info.usage = VK_BUFFER_USAGE_STORAGE_TEXEL_BUFFER_BIT;
1392 buffer_create_info.queueFamilyIndexCount = 1;
1393 buffer_create_info.pQueueFamilyIndices = &queue_family_index;
1394
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001395 VkResult err = vkCreateBuffer(m_device->device(), &buffer_create_info, NULL, &buffer);
Dustin Graves40f35822016-06-23 11:12:53 -06001396 ASSERT_VK_SUCCESS(err);
1397
1398 VkMemoryRequirements memory_reqs;
1399 VkDeviceMemory buffer_memory;
1400 bool pass;
1401 VkMemoryAllocateInfo memory_info = {};
1402 memory_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
1403 memory_info.pNext = NULL;
1404 memory_info.allocationSize = 0;
1405 memory_info.memoryTypeIndex = 0;
1406
1407 vkGetBufferMemoryRequirements(m_device->device(), buffer, &memory_reqs);
1408 memory_info.allocationSize = memory_reqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001409 pass = m_device->phy().set_memory_type(memory_reqs.memoryTypeBits, &memory_info, 0);
Dustin Graves40f35822016-06-23 11:12:53 -06001410 ASSERT_TRUE(pass);
1411
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001412 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &buffer_memory);
Dustin Graves40f35822016-06-23 11:12:53 -06001413 ASSERT_VK_SUCCESS(err);
1414 err = vkBindBufferMemory(m_device->device(), buffer, buffer_memory, 0);
1415 ASSERT_VK_SUCCESS(err);
1416
1417 VkBufferViewCreateInfo buff_view_ci = {};
1418 buff_view_ci.sType = VK_STRUCTURE_TYPE_BUFFER_VIEW_CREATE_INFO;
1419 buff_view_ci.buffer = buffer;
1420 buff_view_ci.format = VK_FORMAT_R8_UNORM;
1421 buff_view_ci.range = VK_WHOLE_SIZE;
1422 VkBufferView buffer_view;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001423 err = vkCreateBufferView(m_device->device(), &buff_view_ci, NULL, &buffer_view);
Dustin Graves40f35822016-06-23 11:12:53 -06001424
1425 VkDescriptorPoolSize ds_type_count = {};
1426 ds_type_count.type = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
1427 ds_type_count.descriptorCount = 1;
1428
1429 VkDescriptorPoolCreateInfo ds_pool_ci = {};
1430 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
1431 ds_pool_ci.pNext = NULL;
1432 ds_pool_ci.maxSets = 1;
1433 ds_pool_ci.poolSizeCount = 1;
1434 ds_pool_ci.pPoolSizes = &ds_type_count;
1435
1436 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001437 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Dustin Graves40f35822016-06-23 11:12:53 -06001438 ASSERT_VK_SUCCESS(err);
1439
1440 VkDescriptorSetLayoutBinding dsl_binding = {};
1441 dsl_binding.binding = 0;
1442 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
1443 dsl_binding.descriptorCount = 1;
1444 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
1445 dsl_binding.pImmutableSamplers = NULL;
1446
1447 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001448 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
Dustin Graves40f35822016-06-23 11:12:53 -06001449 ds_layout_ci.pNext = NULL;
1450 ds_layout_ci.bindingCount = 1;
1451 ds_layout_ci.pBindings = &dsl_binding;
1452 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001453 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Dustin Graves40f35822016-06-23 11:12:53 -06001454 ASSERT_VK_SUCCESS(err);
1455
1456 VkDescriptorSet descriptor_set;
1457 VkDescriptorSetAllocateInfo alloc_info = {};
1458 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
1459 alloc_info.descriptorSetCount = 1;
1460 alloc_info.descriptorPool = ds_pool;
1461 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001462 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
Dustin Graves40f35822016-06-23 11:12:53 -06001463 ASSERT_VK_SUCCESS(err);
1464
1465 VkWriteDescriptorSet descriptor_write;
1466 memset(&descriptor_write, 0, sizeof(descriptor_write));
1467 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
1468 descriptor_write.dstSet = descriptor_set;
1469 descriptor_write.dstBinding = 0;
1470 descriptor_write.descriptorCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001471 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
Dustin Graves40f35822016-06-23 11:12:53 -06001472 descriptor_write.pTexelBufferView = &buffer_view;
1473
1474 // Set pImageInfo and pBufferInfo to invalid values, which should be
1475 // ignored for descriptorType ==
1476 // VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER.
1477 // This will most likely produce a crash if the parameter_validation
1478 // layer
1479 // does not correctly ignore pImageInfo and pBufferInfo.
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001480 descriptor_write.pImageInfo = reinterpret_cast<const VkDescriptorImageInfo *>(invalid_ptr);
1481 descriptor_write.pBufferInfo = reinterpret_cast<const VkDescriptorBufferInfo *>(invalid_ptr);
Dustin Graves40f35822016-06-23 11:12:53 -06001482
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001483 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
Dustin Graves40f35822016-06-23 11:12:53 -06001484
1485 m_errorMonitor->VerifyNotFound();
1486
1487 vkFreeDescriptorSets(m_device->device(), ds_pool, 1, &descriptor_set);
1488 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
1489 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
1490 vkDestroyBufferView(m_device->device(), buffer_view, NULL);
1491 vkDestroyBuffer(m_device->device(), buffer, NULL);
1492 vkFreeMemory(m_device->device(), buffer_memory, NULL);
1493 }
1494}
Cortd889ff92016-07-27 09:51:27 -07001495
1496TEST_F(VkLayerTest, PSOPolygonModeInvalid) {
1497 VkResult err;
1498
1499 TEST_DESCRIPTION("Attempt to use a non-solid polygon fill mode in a "
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001500 "pipeline when this feature is not enabled.");
Cortd889ff92016-07-27 09:51:27 -07001501
1502 ASSERT_NO_FATAL_FAILURE(InitState());
1503 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
1504
1505 std::vector<const char *> device_extension_names;
1506 auto features = m_device->phy().features();
1507 // Artificially disable support for non-solid fill modes
1508 features.fillModeNonSolid = false;
1509 // The sacrificial device object
1510 VkDeviceObj test_device(0, gpu(), device_extension_names, &features);
1511
1512 VkRenderpassObj render_pass(&test_device);
1513
1514 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
1515 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
1516 pipeline_layout_ci.setLayoutCount = 0;
1517 pipeline_layout_ci.pSetLayouts = NULL;
1518
1519 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001520 err = vkCreatePipelineLayout(test_device.device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Cortd889ff92016-07-27 09:51:27 -07001521 ASSERT_VK_SUCCESS(err);
1522
1523 VkPipelineRasterizationStateCreateInfo rs_ci = {};
1524 rs_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
1525 rs_ci.pNext = nullptr;
1526 rs_ci.lineWidth = 1.0f;
1527 rs_ci.rasterizerDiscardEnable = true;
1528
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001529 VkShaderObj vs(&test_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
1530 VkShaderObj fs(&test_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Cortd889ff92016-07-27 09:51:27 -07001531
Mark Lobodzinski5e644732016-08-15 16:51:19 -06001532 // Set polygonMode to unsupported value POINT, should fail
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001533 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
1534 "polygonMode cannot be VK_POLYGON_MODE_POINT or VK_POLYGON_MODE_LINE");
Cortd889ff92016-07-27 09:51:27 -07001535 {
1536 VkPipelineObj pipe(&test_device);
1537 pipe.AddShader(&vs);
1538 pipe.AddShader(&fs);
1539 pipe.AddColorAttachment();
1540 // Introduce failure by setting unsupported polygon mode
1541 rs_ci.polygonMode = VK_POLYGON_MODE_POINT;
1542 pipe.SetRasterization(&rs_ci);
1543 pipe.CreateVKPipeline(pipeline_layout, render_pass.handle());
1544 }
1545 m_errorMonitor->VerifyFound();
1546
1547 // Try again with polygonMode=LINE, should fail
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001548 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
1549 "polygonMode cannot be VK_POLYGON_MODE_POINT or VK_POLYGON_MODE_LINE");
Cortd889ff92016-07-27 09:51:27 -07001550 {
1551 VkPipelineObj pipe(&test_device);
1552 pipe.AddShader(&vs);
1553 pipe.AddShader(&fs);
1554 pipe.AddColorAttachment();
1555 // Introduce failure by setting unsupported polygon mode
1556 rs_ci.polygonMode = VK_POLYGON_MODE_LINE;
1557 pipe.SetRasterization(&rs_ci);
1558 pipe.CreateVKPipeline(pipeline_layout, render_pass.handle());
1559 }
1560 m_errorMonitor->VerifyFound();
1561
1562 // Try again with polygonMode=FILL. No error is expected
1563 m_errorMonitor->ExpectSuccess();
1564 {
1565 VkPipelineObj pipe(&test_device);
1566 pipe.AddShader(&vs);
1567 pipe.AddShader(&fs);
1568 pipe.AddColorAttachment();
1569 // Set polygonMode to a good value
1570 rs_ci.polygonMode = VK_POLYGON_MODE_FILL;
1571 pipe.SetRasterization(&rs_ci);
1572 pipe.CreateVKPipeline(pipeline_layout, render_pass.handle());
1573 }
1574 m_errorMonitor->VerifyNotFound();
1575
1576 vkDestroyPipelineLayout(test_device.device(), pipeline_layout, NULL);
1577}
1578
Dustin Gravesffa90fa2016-05-06 11:20:38 -06001579#endif // PARAMETER_VALIDATION_TESTS
1580
Tobin Ehlis0788f522015-05-26 16:11:58 -06001581#if MEM_TRACKER_TESTS
Tobin Ehlis8fab6562015-12-01 09:57:09 -07001582#if 0
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001583TEST_F(VkLayerTest, CallResetCommandBufferBeforeCompletion)
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001584{
1585 vk_testing::Fence testFence;
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001586 VkFenceCreateInfo fenceInfo = {};
1587 fenceInfo.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
1588 fenceInfo.pNext = NULL;
1589 fenceInfo.flags = 0;
1590
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07001591 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Resetting CB");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06001592
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001593 ASSERT_NO_FATAL_FAILURE(InitState());
Tony Barbourc1eb1a52015-07-20 13:00:10 -06001594
1595 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
1596 vk_testing::Buffer buffer;
1597 buffer.init_as_dst(*m_device, (VkDeviceSize)20, reqs);
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001598
Tony Barbourfe3351b2015-07-28 10:17:20 -06001599 BeginCommandBuffer();
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001600 m_commandBuffer->FillBuffer(buffer.handle(), 0, 4, 0x11111111);
Tony Barbourfe3351b2015-07-28 10:17:20 -06001601 EndCommandBuffer();
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001602
1603 testFence.init(*m_device, fenceInfo);
1604
1605 // Bypass framework since it does the waits automatically
1606 VkResult err = VK_SUCCESS;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06001607 VkSubmitInfo submit_info;
Chia-I Wuf9be13c2015-10-26 20:37:06 +08001608 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
1609 submit_info.pNext = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08001610 submit_info.waitSemaphoreCount = 0;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06001611 submit_info.pWaitSemaphores = NULL;
Jon Ashburn7f9716c2015-12-30 16:42:50 -07001612 submit_info.pWaitDstStageMask = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08001613 submit_info.commandBufferCount = 1;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001614 submit_info.pCommandBuffers = &m_commandBuffer->handle();
Chia-I Wud50a7d72015-10-26 20:48:51 +08001615 submit_info.signalSemaphoreCount = 0;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06001616 submit_info.pSignalSemaphores = NULL;
Courtney Goeltzenleuchter646b9072015-10-20 18:04:07 -06001617
1618 err = vkQueueSubmit( m_device->m_queue, 1, &submit_info, testFence.handle());
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001619 ASSERT_VK_SUCCESS( err );
1620
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001621 // Introduce failure by calling begin again before checking fence
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001622 vkResetCommandBuffer(m_commandBuffer->handle(), 0);
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001623
Chris Forbes8f36a8a2016-04-07 13:21:07 +12001624 m_errorMonitor->VerifyFound();
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001625}
1626
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001627TEST_F(VkLayerTest, CallBeginCommandBufferBeforeCompletion)
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001628{
1629 vk_testing::Fence testFence;
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001630 VkFenceCreateInfo fenceInfo = {};
1631 fenceInfo.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
1632 fenceInfo.pNext = NULL;
1633 fenceInfo.flags = 0;
1634
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07001635 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Calling vkBeginCommandBuffer() on active CB");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06001636
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001637 ASSERT_NO_FATAL_FAILURE(InitState());
1638 ASSERT_NO_FATAL_FAILURE(InitViewport());
1639 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
1640
Tony Barbourfe3351b2015-07-28 10:17:20 -06001641 BeginCommandBuffer();
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001642 m_commandBuffer->ClearAllBuffers(m_clear_color, m_depth_clear_color, m_stencil_clear_color, NULL);
Tony Barbourfe3351b2015-07-28 10:17:20 -06001643 EndCommandBuffer();
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001644
1645 testFence.init(*m_device, fenceInfo);
1646
1647 // Bypass framework since it does the waits automatically
1648 VkResult err = VK_SUCCESS;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06001649 VkSubmitInfo submit_info;
Chia-I Wuf9be13c2015-10-26 20:37:06 +08001650 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
1651 submit_info.pNext = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08001652 submit_info.waitSemaphoreCount = 0;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06001653 submit_info.pWaitSemaphores = NULL;
Jon Ashburn7f9716c2015-12-30 16:42:50 -07001654 submit_info.pWaitDstStageMask = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08001655 submit_info.commandBufferCount = 1;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001656 submit_info.pCommandBuffers = &m_commandBuffer->handle();
Chia-I Wud50a7d72015-10-26 20:48:51 +08001657 submit_info.signalSemaphoreCount = 0;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06001658 submit_info.pSignalSemaphores = NULL;
Courtney Goeltzenleuchter646b9072015-10-20 18:04:07 -06001659
1660 err = vkQueueSubmit( m_device->m_queue, 1, &submit_info, testFence.handle());
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001661 ASSERT_VK_SUCCESS( err );
1662
Jon Ashburnf19916e2016-01-11 13:12:43 -07001663 VkCommandBufferInheritanceInfo hinfo = {};
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001664 VkCommandBufferBeginInfo info = {};
1665 info.flags = VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT;
1666 info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
Mark Lobodzinski5fcc4212015-09-14 17:43:42 -06001667 info.renderPass = VK_NULL_HANDLE;
1668 info.subpass = 0;
1669 info.framebuffer = VK_NULL_HANDLE;
Chia-I Wub8d47ae2015-11-11 10:18:12 +08001670 info.occlusionQueryEnable = VK_FALSE;
1671 info.queryFlags = 0;
1672 info.pipelineStatistics = 0;
Mark Lobodzinski5fcc4212015-09-14 17:43:42 -06001673
1674 // Introduce failure by calling BCB again before checking fence
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001675 vkBeginCommandBuffer(m_commandBuffer->handle(), &info);
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001676
Chris Forbes8f36a8a2016-04-07 13:21:07 +12001677 m_errorMonitor->VerifyFound();
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001678}
Tobin Ehlis8fab6562015-12-01 09:57:09 -07001679#endif
Chris Forbes8f36a8a2016-04-07 13:21:07 +12001680
Mark Lobodzinski152fe252016-05-03 16:49:15 -06001681// This is a positive test. No failures are expected.
1682TEST_F(VkLayerTest, TestAliasedMemoryTracking) {
1683 VkResult err;
1684 bool pass;
1685
1686 TEST_DESCRIPTION("Create a buffer, allocate memory, bind memory, destroy "
1687 "the buffer, create an image, and bind the same memory to "
1688 "it");
1689
1690 m_errorMonitor->ExpectSuccess();
1691
1692 ASSERT_NO_FATAL_FAILURE(InitState());
1693
1694 VkBuffer buffer;
1695 VkImage image;
1696 VkDeviceMemory mem;
1697 VkMemoryRequirements mem_reqs;
1698
1699 VkBufferCreateInfo buf_info = {};
1700 buf_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
1701 buf_info.pNext = NULL;
1702 buf_info.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
1703 buf_info.size = 256;
1704 buf_info.queueFamilyIndexCount = 0;
1705 buf_info.pQueueFamilyIndices = NULL;
1706 buf_info.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
1707 buf_info.flags = 0;
1708 err = vkCreateBuffer(m_device->device(), &buf_info, NULL, &buffer);
1709 ASSERT_VK_SUCCESS(err);
1710
1711 vkGetBufferMemoryRequirements(m_device->device(), buffer, &mem_reqs);
1712
1713 VkMemoryAllocateInfo alloc_info = {};
1714 alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
1715 alloc_info.pNext = NULL;
1716 alloc_info.memoryTypeIndex = 0;
1717
1718 // Ensure memory is big enough for both bindings
1719 alloc_info.allocationSize = 0x10000;
1720
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001721 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &alloc_info, VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT);
Mark Lobodzinski152fe252016-05-03 16:49:15 -06001722 if (!pass) {
1723 vkDestroyBuffer(m_device->device(), buffer, NULL);
1724 return;
1725 }
1726
1727 err = vkAllocateMemory(m_device->device(), &alloc_info, NULL, &mem);
1728 ASSERT_VK_SUCCESS(err);
1729
1730 uint8_t *pData;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001731 err = vkMapMemory(m_device->device(), mem, 0, mem_reqs.size, 0, (void **)&pData);
Mark Lobodzinski152fe252016-05-03 16:49:15 -06001732 ASSERT_VK_SUCCESS(err);
1733
Mark Lobodzinski2abefa92016-05-05 11:45:57 -06001734 memset(pData, 0xCADECADE, static_cast<size_t>(mem_reqs.size));
Mark Lobodzinski152fe252016-05-03 16:49:15 -06001735
1736 vkUnmapMemory(m_device->device(), mem);
1737
1738 err = vkBindBufferMemory(m_device->device(), buffer, mem, 0);
1739 ASSERT_VK_SUCCESS(err);
1740
1741 // NOW, destroy the buffer. Obviously, the resource no longer occupies this
1742 // memory. In fact, it was never used by the GPU.
1743 // Just be be sure, wait for idle.
1744 vkDestroyBuffer(m_device->device(), buffer, NULL);
1745 vkDeviceWaitIdle(m_device->device());
1746
1747 VkImageCreateInfo image_create_info = {};
1748 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
1749 image_create_info.pNext = NULL;
1750 image_create_info.imageType = VK_IMAGE_TYPE_2D;
1751 image_create_info.format = VK_FORMAT_R8G8B8A8_UNORM;
1752 image_create_info.extent.width = 64;
1753 image_create_info.extent.height = 64;
1754 image_create_info.extent.depth = 1;
1755 image_create_info.mipLevels = 1;
1756 image_create_info.arrayLayers = 1;
1757 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
1758 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
1759 image_create_info.initialLayout = VK_IMAGE_LAYOUT_PREINITIALIZED;
1760 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
1761 image_create_info.queueFamilyIndexCount = 0;
1762 image_create_info.pQueueFamilyIndices = NULL;
1763 image_create_info.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
1764 image_create_info.flags = 0;
1765
1766 VkMemoryAllocateInfo mem_alloc = {};
1767 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
1768 mem_alloc.pNext = NULL;
1769 mem_alloc.allocationSize = 0;
1770 mem_alloc.memoryTypeIndex = 0;
1771
1772 /* Create a mappable image. It will be the texture if linear images are ok
1773 * to be textures or it will be the staging image if they are not.
1774 */
1775 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
1776 ASSERT_VK_SUCCESS(err);
1777
1778 vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs);
1779
1780 mem_alloc.allocationSize = mem_reqs.size;
1781
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001782 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT);
Mark Lobodzinski152fe252016-05-03 16:49:15 -06001783 if (!pass) {
1784 vkDestroyImage(m_device->device(), image, NULL);
1785 return;
1786 }
1787
Tobin Ehlis077ded32016-05-12 17:39:13 -06001788 // VALIDATION FAILURE:
Mark Lobodzinski152fe252016-05-03 16:49:15 -06001789 err = vkBindImageMemory(m_device->device(), image, mem, 0);
1790 ASSERT_VK_SUCCESS(err);
1791
1792 m_errorMonitor->VerifyNotFound();
1793
Tony Barbourdf4c0042016-06-01 15:55:43 -06001794 vkFreeMemory(m_device->device(), mem, NULL);
Mark Lobodzinski152fe252016-05-03 16:49:15 -06001795 vkDestroyBuffer(m_device->device(), buffer, NULL);
1796 vkDestroyImage(m_device->device(), image, NULL);
1797}
1798
Tobin Ehlisf11be982016-05-11 13:52:53 -06001799TEST_F(VkLayerTest, InvalidMemoryAliasing) {
1800 TEST_DESCRIPTION("Create a buffer and image, allocate memory, and bind the "
1801 "buffer and image to memory such that they will alias.");
1802 VkResult err;
1803 bool pass;
1804 ASSERT_NO_FATAL_FAILURE(InitState());
1805
Tobin Ehlis077ded32016-05-12 17:39:13 -06001806 VkBuffer buffer, buffer2;
Tobin Ehlisf11be982016-05-11 13:52:53 -06001807 VkImage image;
1808 VkDeviceMemory mem; // buffer will be bound first
1809 VkDeviceMemory mem_img; // image bound first
Tobin Ehlis077ded32016-05-12 17:39:13 -06001810 VkMemoryRequirements buff_mem_reqs, img_mem_reqs;
Tobin Ehlisf11be982016-05-11 13:52:53 -06001811
1812 VkBufferCreateInfo buf_info = {};
1813 buf_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
1814 buf_info.pNext = NULL;
1815 buf_info.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
1816 buf_info.size = 256;
1817 buf_info.queueFamilyIndexCount = 0;
1818 buf_info.pQueueFamilyIndices = NULL;
1819 buf_info.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
1820 buf_info.flags = 0;
1821 err = vkCreateBuffer(m_device->device(), &buf_info, NULL, &buffer);
1822 ASSERT_VK_SUCCESS(err);
1823
Tobin Ehlis077ded32016-05-12 17:39:13 -06001824 vkGetBufferMemoryRequirements(m_device->device(), buffer, &buff_mem_reqs);
Tobin Ehlisf11be982016-05-11 13:52:53 -06001825
1826 VkImageCreateInfo image_create_info = {};
1827 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
1828 image_create_info.pNext = NULL;
1829 image_create_info.imageType = VK_IMAGE_TYPE_2D;
1830 image_create_info.format = VK_FORMAT_R8G8B8A8_UNORM;
1831 image_create_info.extent.width = 64;
1832 image_create_info.extent.height = 64;
1833 image_create_info.extent.depth = 1;
1834 image_create_info.mipLevels = 1;
1835 image_create_info.arrayLayers = 1;
1836 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
Tobin Ehlis12a4b5e2016-08-08 12:33:11 -06001837 // Image tiling must be optimal to trigger error when aliasing linear buffer
1838 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
Tobin Ehlisf11be982016-05-11 13:52:53 -06001839 image_create_info.initialLayout = VK_IMAGE_LAYOUT_PREINITIALIZED;
1840 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
1841 image_create_info.queueFamilyIndexCount = 0;
1842 image_create_info.pQueueFamilyIndices = NULL;
1843 image_create_info.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
1844 image_create_info.flags = 0;
1845
Tobin Ehlisf11be982016-05-11 13:52:53 -06001846 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
1847 ASSERT_VK_SUCCESS(err);
1848
Tobin Ehlis077ded32016-05-12 17:39:13 -06001849 vkGetImageMemoryRequirements(m_device->device(), image, &img_mem_reqs);
1850
1851 VkMemoryAllocateInfo alloc_info = {};
1852 alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
1853 alloc_info.pNext = NULL;
1854 alloc_info.memoryTypeIndex = 0;
1855 // Ensure memory is big enough for both bindings
1856 alloc_info.allocationSize = buff_mem_reqs.size + img_mem_reqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001857 pass = m_device->phy().set_memory_type(buff_mem_reqs.memoryTypeBits & img_mem_reqs.memoryTypeBits, &alloc_info,
1858 VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT);
Tobin Ehlisf11be982016-05-11 13:52:53 -06001859 if (!pass) {
Tobin Ehlis077ded32016-05-12 17:39:13 -06001860 vkDestroyBuffer(m_device->device(), buffer, NULL);
Tobin Ehlisf11be982016-05-11 13:52:53 -06001861 vkDestroyImage(m_device->device(), image, NULL);
1862 return;
1863 }
Tobin Ehlis077ded32016-05-12 17:39:13 -06001864 err = vkAllocateMemory(m_device->device(), &alloc_info, NULL, &mem);
1865 ASSERT_VK_SUCCESS(err);
1866 err = vkBindBufferMemory(m_device->device(), buffer, mem, 0);
1867 ASSERT_VK_SUCCESS(err);
1868
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001869 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " is aliased with linear buffer 0x");
Tobin Ehlis077ded32016-05-12 17:39:13 -06001870 // VALIDATION FAILURE due to image mapping overlapping buffer mapping
Tobin Ehlisf11be982016-05-11 13:52:53 -06001871 err = vkBindImageMemory(m_device->device(), image, mem, 0);
1872 m_errorMonitor->VerifyFound();
1873
1874 // Now correctly bind image to second mem allocation before incorrectly
Tobin Ehlis077ded32016-05-12 17:39:13 -06001875 // aliasing buffer2
1876 err = vkCreateBuffer(m_device->device(), &buf_info, NULL, &buffer2);
1877 ASSERT_VK_SUCCESS(err);
Tobin Ehlisf11be982016-05-11 13:52:53 -06001878 err = vkAllocateMemory(m_device->device(), &alloc_info, NULL, &mem_img);
1879 ASSERT_VK_SUCCESS(err);
1880 err = vkBindImageMemory(m_device->device(), image, mem_img, 0);
1881 ASSERT_VK_SUCCESS(err);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001882 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "is aliased with non-linear image 0x");
Tobin Ehlis077ded32016-05-12 17:39:13 -06001883 err = vkBindBufferMemory(m_device->device(), buffer2, mem_img, 0);
Tobin Ehlisf11be982016-05-11 13:52:53 -06001884 m_errorMonitor->VerifyFound();
1885
1886 vkDestroyBuffer(m_device->device(), buffer, NULL);
Tobin Ehlis077ded32016-05-12 17:39:13 -06001887 vkDestroyBuffer(m_device->device(), buffer2, NULL);
Tobin Ehlisf11be982016-05-11 13:52:53 -06001888 vkDestroyImage(m_device->device(), image, NULL);
1889 vkFreeMemory(m_device->device(), mem, NULL);
1890 vkFreeMemory(m_device->device(), mem_img, NULL);
1891}
1892
Tobin Ehlis35372522016-05-12 08:32:31 -06001893TEST_F(VkLayerTest, InvalidMemoryMapping) {
1894 TEST_DESCRIPTION("Attempt to map memory in a number of incorrect ways");
1895 VkResult err;
1896 bool pass;
1897 ASSERT_NO_FATAL_FAILURE(InitState());
1898
1899 VkBuffer buffer;
1900 VkDeviceMemory mem;
1901 VkMemoryRequirements mem_reqs;
1902
1903 VkBufferCreateInfo buf_info = {};
1904 buf_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
1905 buf_info.pNext = NULL;
1906 buf_info.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
1907 buf_info.size = 256;
1908 buf_info.queueFamilyIndexCount = 0;
1909 buf_info.pQueueFamilyIndices = NULL;
1910 buf_info.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
1911 buf_info.flags = 0;
1912 err = vkCreateBuffer(m_device->device(), &buf_info, NULL, &buffer);
1913 ASSERT_VK_SUCCESS(err);
1914
1915 vkGetBufferMemoryRequirements(m_device->device(), buffer, &mem_reqs);
1916 VkMemoryAllocateInfo alloc_info = {};
1917 alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
1918 alloc_info.pNext = NULL;
1919 alloc_info.memoryTypeIndex = 0;
1920
1921 // Ensure memory is big enough for both bindings
1922 static const VkDeviceSize allocation_size = 0x10000;
1923 alloc_info.allocationSize = allocation_size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001924 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &alloc_info, VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT);
Tobin Ehlis35372522016-05-12 08:32:31 -06001925 if (!pass) {
1926 vkDestroyBuffer(m_device->device(), buffer, NULL);
1927 return;
1928 }
1929 err = vkAllocateMemory(m_device->device(), &alloc_info, NULL, &mem);
1930 ASSERT_VK_SUCCESS(err);
1931
1932 uint8_t *pData;
1933 // Attempt to map memory size 0 is invalid
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001934 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "VkMapMemory: Attempting to map memory range of size zero");
Tobin Ehlis35372522016-05-12 08:32:31 -06001935 err = vkMapMemory(m_device->device(), mem, 0, 0, 0, (void **)&pData);
1936 m_errorMonitor->VerifyFound();
1937 // Map memory twice
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001938 err = vkMapMemory(m_device->device(), mem, 0, mem_reqs.size, 0, (void **)&pData);
Tobin Ehlis35372522016-05-12 08:32:31 -06001939 ASSERT_VK_SUCCESS(err);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001940 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
1941 "VkMapMemory: Attempting to map memory on an already-mapped object ");
1942 err = vkMapMemory(m_device->device(), mem, 0, mem_reqs.size, 0, (void **)&pData);
Tobin Ehlis35372522016-05-12 08:32:31 -06001943 m_errorMonitor->VerifyFound();
1944
1945 // Unmap the memory to avoid re-map error
1946 vkUnmapMemory(m_device->device(), mem);
1947 // overstep allocation with VK_WHOLE_SIZE
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001948 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
1949 " with size of VK_WHOLE_SIZE oversteps total array size 0x");
1950 err = vkMapMemory(m_device->device(), mem, allocation_size + 1, VK_WHOLE_SIZE, 0, (void **)&pData);
Tobin Ehlis35372522016-05-12 08:32:31 -06001951 m_errorMonitor->VerifyFound();
1952 // overstep allocation w/o VK_WHOLE_SIZE
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001953 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " oversteps total array size 0x");
1954 err = vkMapMemory(m_device->device(), mem, 1, allocation_size, 0, (void **)&pData);
Tobin Ehlis35372522016-05-12 08:32:31 -06001955 m_errorMonitor->VerifyFound();
1956 // Now error due to unmapping memory that's not mapped
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001957 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Unmapping Memory without memory being mapped: ");
Tobin Ehlis35372522016-05-12 08:32:31 -06001958 vkUnmapMemory(m_device->device(), mem);
1959 m_errorMonitor->VerifyFound();
1960 // Now map memory and cause errors due to flushing invalid ranges
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001961 err = vkMapMemory(m_device->device(), mem, 16, VK_WHOLE_SIZE, 0, (void **)&pData);
Tobin Ehlis35372522016-05-12 08:32:31 -06001962 ASSERT_VK_SUCCESS(err);
1963 VkMappedMemoryRange mmr = {};
Chris Forbes3aec0892016-06-13 10:29:26 +12001964 mmr.sType = VK_STRUCTURE_TYPE_MAPPED_MEMORY_RANGE;
Tobin Ehlis35372522016-05-12 08:32:31 -06001965 mmr.memory = mem;
1966 mmr.offset = 15; // Error b/c offset less than offset of mapped mem
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001967 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, ") is less than Memory Object's offset (");
Tobin Ehlis35372522016-05-12 08:32:31 -06001968 vkFlushMappedMemoryRanges(m_device->device(), 1, &mmr);
1969 m_errorMonitor->VerifyFound();
1970 // Now flush range that oversteps mapped range
1971 vkUnmapMemory(m_device->device(), mem);
1972 err = vkMapMemory(m_device->device(), mem, 0, 256, 0, (void **)&pData);
1973 ASSERT_VK_SUCCESS(err);
1974 mmr.offset = 16;
1975 mmr.size = 256; // flushing bounds (272) exceed mapped bounds (256)
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001976 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, ") exceeds the Memory Object's upper-bound (");
Tobin Ehlis35372522016-05-12 08:32:31 -06001977 vkFlushMappedMemoryRanges(m_device->device(), 1, &mmr);
1978 m_errorMonitor->VerifyFound();
1979
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001980 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &alloc_info, VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT,
1981 VK_MEMORY_PROPERTY_HOST_COHERENT_BIT);
Tobin Ehlis35372522016-05-12 08:32:31 -06001982 if (!pass) {
1983 vkFreeMemory(m_device->device(), mem, NULL);
1984 vkDestroyBuffer(m_device->device(), buffer, NULL);
1985 return;
1986 }
1987 // TODO : If we can get HOST_VISIBLE w/o HOST_COHERENT we can test cases of
1988 // MEMTRACK_INVALID_MAP in validateAndCopyNoncoherentMemoryToDriver()
1989
1990 vkDestroyBuffer(m_device->device(), buffer, NULL);
1991 vkFreeMemory(m_device->device(), mem, NULL);
1992}
1993
Mark Lobodzinski1f515922016-08-16 10:03:30 -06001994TEST_F(VkLayerTest, NonCoherentMemoryMapping) {
1995
1996 TEST_DESCRIPTION("Ensure that validations handling of non-coherent memory "
1997 "mapping while using VK_WHOLE_SIZE does not cause access "
1998 "violations");
1999 VkResult err;
2000 uint8_t *pData;
2001 ASSERT_NO_FATAL_FAILURE(InitState());
2002
2003 VkDeviceMemory mem;
2004 VkMemoryRequirements mem_reqs;
2005 mem_reqs.memoryTypeBits = 0xFFFFFFFF;
2006 VkMemoryAllocateInfo alloc_info = {};
2007 alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
2008 alloc_info.pNext = NULL;
2009 alloc_info.memoryTypeIndex = 0;
2010
2011 static const VkDeviceSize allocation_size = 0x1000;
2012 alloc_info.allocationSize = allocation_size;
2013
2014 // Find a memory configurations WITHOUT a COHERENT bit, otherwise exit
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002015 bool pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &alloc_info, VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT,
2016 VK_MEMORY_PROPERTY_HOST_COHERENT_BIT);
Mark Lobodzinski1f515922016-08-16 10:03:30 -06002017 if (!pass) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002018 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &alloc_info,
2019 VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT,
2020 VK_MEMORY_PROPERTY_HOST_COHERENT_BIT);
Mark Lobodzinski1f515922016-08-16 10:03:30 -06002021 if (!pass) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002022 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &alloc_info,
2023 VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT |
2024 VK_MEMORY_PROPERTY_HOST_CACHED_BIT,
2025 VK_MEMORY_PROPERTY_HOST_COHERENT_BIT);
Mark Lobodzinski1f515922016-08-16 10:03:30 -06002026 if (!pass) {
2027 return;
2028 }
2029 }
2030 }
2031
2032 err = vkAllocateMemory(m_device->device(), &alloc_info, NULL, &mem);
2033 ASSERT_VK_SUCCESS(err);
2034
2035 // Map/Flush/Invalidate using WHOLE_SIZE and zero offsets and entire
2036 // mapped range
2037 m_errorMonitor->ExpectSuccess();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002038 err = vkMapMemory(m_device->device(), mem, 0, VK_WHOLE_SIZE, 0, (void **)&pData);
Mark Lobodzinski1f515922016-08-16 10:03:30 -06002039 ASSERT_VK_SUCCESS(err);
2040 VkMappedMemoryRange mmr = {};
2041 mmr.sType = VK_STRUCTURE_TYPE_MAPPED_MEMORY_RANGE;
2042 mmr.memory = mem;
2043 mmr.offset = 0;
2044 mmr.size = VK_WHOLE_SIZE;
2045 err = vkFlushMappedMemoryRanges(m_device->device(), 1, &mmr);
2046 ASSERT_VK_SUCCESS(err);
2047 err = vkInvalidateMappedMemoryRanges(m_device->device(), 1, &mmr);
2048 ASSERT_VK_SUCCESS(err);
2049 m_errorMonitor->VerifyNotFound();
2050 vkUnmapMemory(m_device->device(), mem);
2051
2052 // Map/Flush/Invalidate using WHOLE_SIZE and a prime offset and entire
2053 // mapped range
2054 m_errorMonitor->ExpectSuccess();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002055 err = vkMapMemory(m_device->device(), mem, 13, VK_WHOLE_SIZE, 0, (void **)&pData);
Mark Lobodzinski1f515922016-08-16 10:03:30 -06002056 ASSERT_VK_SUCCESS(err);
2057 mmr.sType = VK_STRUCTURE_TYPE_MAPPED_MEMORY_RANGE;
2058 mmr.memory = mem;
2059 mmr.offset = 13;
2060 mmr.size = VK_WHOLE_SIZE;
2061 err = vkFlushMappedMemoryRanges(m_device->device(), 1, &mmr);
2062 ASSERT_VK_SUCCESS(err);
2063 err = vkInvalidateMappedMemoryRanges(m_device->device(), 1, &mmr);
2064 ASSERT_VK_SUCCESS(err);
2065 m_errorMonitor->VerifyNotFound();
2066 vkUnmapMemory(m_device->device(), mem);
2067
2068 // Map with prime offset and size
2069 // Flush/Invalidate subrange of mapped area with prime offset and size
2070 m_errorMonitor->ExpectSuccess();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002071 err = vkMapMemory(m_device->device(), mem, allocation_size - 137, 109, 0, (void **)&pData);
Mark Lobodzinski1f515922016-08-16 10:03:30 -06002072 ASSERT_VK_SUCCESS(err);
2073 mmr.sType = VK_STRUCTURE_TYPE_MAPPED_MEMORY_RANGE;
2074 mmr.memory = mem;
2075 mmr.offset = allocation_size - 107;
2076 mmr.size = 61;
2077 err = vkFlushMappedMemoryRanges(m_device->device(), 1, &mmr);
2078 ASSERT_VK_SUCCESS(err);
2079 err = vkInvalidateMappedMemoryRanges(m_device->device(), 1, &mmr);
2080 ASSERT_VK_SUCCESS(err);
2081 m_errorMonitor->VerifyNotFound();
2082 vkUnmapMemory(m_device->device(), mem);
2083
2084 vkFreeMemory(m_device->device(), mem, NULL);
2085}
2086
Ian Elliott1c32c772016-04-28 14:47:13 -06002087TEST_F(VkLayerTest, EnableWsiBeforeUse) {
2088 VkResult err;
2089 bool pass;
2090
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002091 // FIXME: After we turn on this code for non-Linux platforms, uncomment the
2092 // following declaration (which is temporarily being moved below):
2093 // VkSurfaceKHR surface = VK_NULL_HANDLE;
Ian Elliott1c32c772016-04-28 14:47:13 -06002094 VkSwapchainKHR swapchain = VK_NULL_HANDLE;
2095 VkSwapchainCreateInfoKHR swapchain_create_info = {};
2096 uint32_t swapchain_image_count = 0;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002097 // VkImage swapchain_images[1] = {VK_NULL_HANDLE};
Ian Elliott1c32c772016-04-28 14:47:13 -06002098 uint32_t image_index = 0;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002099 // VkPresentInfoKHR present_info = {};
Ian Elliott1c32c772016-04-28 14:47:13 -06002100
2101 ASSERT_NO_FATAL_FAILURE(InitState());
2102
Ian Elliott3f06ce52016-04-29 14:46:21 -06002103#ifdef NEED_TO_TEST_THIS_ON_PLATFORM
2104#if defined(VK_USE_PLATFORM_ANDROID_KHR)
2105 // Use the functions from the VK_KHR_android_surface extension without
2106 // enabling that extension:
2107
2108 // Create a surface:
2109 VkAndroidSurfaceCreateInfoKHR android_create_info = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002110 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
2111 err = vkCreateAndroidSurfaceKHR(instance(), &android_create_info, NULL, &surface);
Ian Elliott3f06ce52016-04-29 14:46:21 -06002112 pass = (err != VK_SUCCESS);
2113 ASSERT_TRUE(pass);
2114 m_errorMonitor->VerifyFound();
2115#endif // VK_USE_PLATFORM_ANDROID_KHR
2116
Ian Elliott3f06ce52016-04-29 14:46:21 -06002117#if defined(VK_USE_PLATFORM_MIR_KHR)
2118 // Use the functions from the VK_KHR_mir_surface extension without enabling
2119 // that extension:
2120
2121 // Create a surface:
2122 VkMirSurfaceCreateInfoKHR mir_create_info = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002123 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
Ian Elliott3f06ce52016-04-29 14:46:21 -06002124 err = vkCreateMirSurfaceKHR(instance(), &mir_create_info, NULL, &surface);
2125 pass = (err != VK_SUCCESS);
2126 ASSERT_TRUE(pass);
2127 m_errorMonitor->VerifyFound();
2128
2129 // Tell whether an mir_connection supports presentation:
2130 MirConnection *mir_connection = NULL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002131 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
2132 vkGetPhysicalDeviceMirPresentationSupportKHR(gpu(), 0, mir_connection, visual_id);
Ian Elliott3f06ce52016-04-29 14:46:21 -06002133 m_errorMonitor->VerifyFound();
2134#endif // VK_USE_PLATFORM_MIR_KHR
2135
Ian Elliott3f06ce52016-04-29 14:46:21 -06002136#if defined(VK_USE_PLATFORM_WAYLAND_KHR)
2137 // Use the functions from the VK_KHR_wayland_surface extension without
2138 // enabling that extension:
2139
2140 // Create a surface:
2141 VkWaylandSurfaceCreateInfoKHR wayland_create_info = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002142 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
2143 err = vkCreateWaylandSurfaceKHR(instance(), &wayland_create_info, NULL, &surface);
Ian Elliott3f06ce52016-04-29 14:46:21 -06002144 pass = (err != VK_SUCCESS);
2145 ASSERT_TRUE(pass);
2146 m_errorMonitor->VerifyFound();
2147
2148 // Tell whether an wayland_display supports presentation:
2149 struct wl_display wayland_display = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002150 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
2151 vkGetPhysicalDeviceWaylandPresentationSupportKHR(gpu(), 0, &wayland_display);
Ian Elliott3f06ce52016-04-29 14:46:21 -06002152 m_errorMonitor->VerifyFound();
2153#endif // VK_USE_PLATFORM_WAYLAND_KHR
Ian Elliott489eec02016-05-05 14:12:44 -06002154#endif // NEED_TO_TEST_THIS_ON_PLATFORM
Ian Elliott3f06ce52016-04-29 14:46:21 -06002155
Ian Elliott3f06ce52016-04-29 14:46:21 -06002156#if defined(VK_USE_PLATFORM_WIN32_KHR)
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002157 // FIXME: REMOVE THIS HERE, AND UNCOMMENT ABOVE, WHEN THIS TEST HAS BEEN PORTED
2158 // TO NON-LINUX PLATFORMS:
2159 VkSurfaceKHR surface = VK_NULL_HANDLE;
Ian Elliott3f06ce52016-04-29 14:46:21 -06002160 // Use the functions from the VK_KHR_win32_surface extension without
2161 // enabling that extension:
2162
2163 // Create a surface:
2164 VkWin32SurfaceCreateInfoKHR win32_create_info = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002165 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
2166 err = vkCreateWin32SurfaceKHR(instance(), &win32_create_info, NULL, &surface);
Ian Elliott3f06ce52016-04-29 14:46:21 -06002167 pass = (err != VK_SUCCESS);
2168 ASSERT_TRUE(pass);
2169 m_errorMonitor->VerifyFound();
2170
2171 // Tell whether win32 supports presentation:
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002172 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
Ian Elliott489eec02016-05-05 14:12:44 -06002173 vkGetPhysicalDeviceWin32PresentationSupportKHR(gpu(), 0);
Ian Elliott3f06ce52016-04-29 14:46:21 -06002174 m_errorMonitor->VerifyFound();
Ian Elliott489eec02016-05-05 14:12:44 -06002175// Set this (for now, until all platforms are supported and tested):
2176#define NEED_TO_TEST_THIS_ON_PLATFORM
2177#endif // VK_USE_PLATFORM_WIN32_KHR
Ian Elliott3f06ce52016-04-29 14:46:21 -06002178
Ian Elliott1c32c772016-04-28 14:47:13 -06002179#if defined(VK_USE_PLATFORM_XCB_KHR)
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002180 // FIXME: REMOVE THIS HERE, AND UNCOMMENT ABOVE, WHEN THIS TEST HAS BEEN PORTED
2181 // TO NON-LINUX PLATFORMS:
2182 VkSurfaceKHR surface = VK_NULL_HANDLE;
Ian Elliott1c32c772016-04-28 14:47:13 -06002183 // Use the functions from the VK_KHR_xcb_surface extension without enabling
2184 // that extension:
2185
2186 // Create a surface:
2187 VkXcbSurfaceCreateInfoKHR xcb_create_info = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002188 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
Ian Elliott1c32c772016-04-28 14:47:13 -06002189 err = vkCreateXcbSurfaceKHR(instance(), &xcb_create_info, NULL, &surface);
2190 pass = (err != VK_SUCCESS);
2191 ASSERT_TRUE(pass);
2192 m_errorMonitor->VerifyFound();
2193
2194 // Tell whether an xcb_visualid_t supports presentation:
Ian Elliott3f06ce52016-04-29 14:46:21 -06002195 xcb_connection_t *xcb_connection = NULL;
Ian Elliott1c32c772016-04-28 14:47:13 -06002196 xcb_visualid_t visual_id = 0;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002197 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
2198 vkGetPhysicalDeviceXcbPresentationSupportKHR(gpu(), 0, xcb_connection, visual_id);
Ian Elliott1c32c772016-04-28 14:47:13 -06002199 m_errorMonitor->VerifyFound();
Ian Elliott489eec02016-05-05 14:12:44 -06002200// Set this (for now, until all platforms are supported and tested):
2201#define NEED_TO_TEST_THIS_ON_PLATFORM
Ian Elliott1c32c772016-04-28 14:47:13 -06002202#endif // VK_USE_PLATFORM_XCB_KHR
2203
Ian Elliott12630812016-04-29 14:35:43 -06002204#if defined(VK_USE_PLATFORM_XLIB_KHR)
2205 // Use the functions from the VK_KHR_xlib_surface extension without enabling
2206 // that extension:
2207
2208 // Create a surface:
2209 VkXlibSurfaceCreateInfoKHR xlib_create_info = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002210 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
Ian Elliott12630812016-04-29 14:35:43 -06002211 err = vkCreateXlibSurfaceKHR(instance(), &xlib_create_info, NULL, &surface);
2212 pass = (err != VK_SUCCESS);
2213 ASSERT_TRUE(pass);
2214 m_errorMonitor->VerifyFound();
2215
2216 // Tell whether an Xlib VisualID supports presentation:
2217 Display *dpy = NULL;
2218 VisualID visual = 0;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002219 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
Ian Elliott12630812016-04-29 14:35:43 -06002220 vkGetPhysicalDeviceXlibPresentationSupportKHR(gpu(), 0, dpy, visual);
2221 m_errorMonitor->VerifyFound();
Ian Elliott489eec02016-05-05 14:12:44 -06002222// Set this (for now, until all platforms are supported and tested):
2223#define NEED_TO_TEST_THIS_ON_PLATFORM
Ian Elliott12630812016-04-29 14:35:43 -06002224#endif // VK_USE_PLATFORM_XLIB_KHR
2225
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002226// Use the functions from the VK_KHR_surface extension without enabling
2227// that extension:
Ian Elliott1c32c772016-04-28 14:47:13 -06002228
Ian Elliott489eec02016-05-05 14:12:44 -06002229#ifdef NEED_TO_TEST_THIS_ON_PLATFORM
Ian Elliott1c32c772016-04-28 14:47:13 -06002230 // Destroy a surface:
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002231 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
Ian Elliott1c32c772016-04-28 14:47:13 -06002232 vkDestroySurfaceKHR(instance(), surface, NULL);
2233 m_errorMonitor->VerifyFound();
2234
2235 // Check if surface supports presentation:
2236 VkBool32 supported = false;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002237 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
Ian Elliott1c32c772016-04-28 14:47:13 -06002238 err = vkGetPhysicalDeviceSurfaceSupportKHR(gpu(), 0, surface, &supported);
2239 pass = (err != VK_SUCCESS);
2240 ASSERT_TRUE(pass);
2241 m_errorMonitor->VerifyFound();
2242
2243 // Check surface capabilities:
2244 VkSurfaceCapabilitiesKHR capabilities = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002245 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
2246 err = vkGetPhysicalDeviceSurfaceCapabilitiesKHR(gpu(), surface, &capabilities);
Ian Elliott1c32c772016-04-28 14:47:13 -06002247 pass = (err != VK_SUCCESS);
2248 ASSERT_TRUE(pass);
2249 m_errorMonitor->VerifyFound();
2250
2251 // Check surface formats:
2252 uint32_t format_count = 0;
2253 VkSurfaceFormatKHR *formats = NULL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002254 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
2255 err = vkGetPhysicalDeviceSurfaceFormatsKHR(gpu(), surface, &format_count, formats);
Ian Elliott1c32c772016-04-28 14:47:13 -06002256 pass = (err != VK_SUCCESS);
2257 ASSERT_TRUE(pass);
2258 m_errorMonitor->VerifyFound();
2259
2260 // Check surface present modes:
2261 uint32_t present_mode_count = 0;
2262 VkSurfaceFormatKHR *present_modes = NULL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002263 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
2264 err = vkGetPhysicalDeviceSurfaceFormatsKHR(gpu(), surface, &present_mode_count, present_modes);
Ian Elliott1c32c772016-04-28 14:47:13 -06002265 pass = (err != VK_SUCCESS);
2266 ASSERT_TRUE(pass);
2267 m_errorMonitor->VerifyFound();
Ian Elliott489eec02016-05-05 14:12:44 -06002268#endif // NEED_TO_TEST_THIS_ON_PLATFORM
Ian Elliott1c32c772016-04-28 14:47:13 -06002269
Ian Elliott1c32c772016-04-28 14:47:13 -06002270 // Use the functions from the VK_KHR_swapchain extension without enabling
2271 // that extension:
2272
2273 // Create a swapchain:
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002274 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
Ian Elliott1c32c772016-04-28 14:47:13 -06002275 swapchain_create_info.sType = VK_STRUCTURE_TYPE_SWAPCHAIN_CREATE_INFO_KHR;
2276 swapchain_create_info.pNext = NULL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002277 err = vkCreateSwapchainKHR(m_device->device(), &swapchain_create_info, NULL, &swapchain);
Ian Elliott1c32c772016-04-28 14:47:13 -06002278 pass = (err != VK_SUCCESS);
2279 ASSERT_TRUE(pass);
2280 m_errorMonitor->VerifyFound();
2281
2282 // Get the images from the swapchain:
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002283 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
2284 err = vkGetSwapchainImagesKHR(m_device->device(), swapchain, &swapchain_image_count, NULL);
Ian Elliott1c32c772016-04-28 14:47:13 -06002285 pass = (err != VK_SUCCESS);
2286 ASSERT_TRUE(pass);
2287 m_errorMonitor->VerifyFound();
2288
2289 // Try to acquire an image:
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002290 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
2291 err = vkAcquireNextImageKHR(m_device->device(), swapchain, 0, VK_NULL_HANDLE, VK_NULL_HANDLE, &image_index);
Ian Elliott1c32c772016-04-28 14:47:13 -06002292 pass = (err != VK_SUCCESS);
2293 ASSERT_TRUE(pass);
2294 m_errorMonitor->VerifyFound();
2295
2296 // Try to present an image:
Ian Elliott2c1daf52016-05-12 09:41:46 -06002297 //
2298 // NOTE: Currently can't test this because a real swapchain is needed (as
2299 // opposed to the fake one we created) in order for the layer to lookup the
2300 // VkDevice used to enable the extension:
Ian Elliott1c32c772016-04-28 14:47:13 -06002301
2302 // Destroy the swapchain:
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002303 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
Ian Elliott1c32c772016-04-28 14:47:13 -06002304 vkDestroySwapchainKHR(m_device->device(), swapchain, NULL);
2305 m_errorMonitor->VerifyFound();
2306}
2307
Ian Elliott2c1daf52016-05-12 09:41:46 -06002308TEST_F(VkWsiEnabledLayerTest, TestEnabledWsi) {
Ian Elliott2c1daf52016-05-12 09:41:46 -06002309
Dustin Graves6c6d8982016-05-17 10:09:21 -06002310#if defined(VK_USE_PLATFORM_XCB_KHR)
Ian Elliott2c1daf52016-05-12 09:41:46 -06002311 VkSurfaceKHR surface = VK_NULL_HANDLE;
Mark Lobodzinski085d27a2016-05-17 09:34:26 -06002312
Mark Lobodzinski085d27a2016-05-17 09:34:26 -06002313 VkResult err;
2314 bool pass;
Ian Elliott2c1daf52016-05-12 09:41:46 -06002315 VkSwapchainKHR swapchain = VK_NULL_HANDLE;
2316 VkSwapchainCreateInfoKHR swapchain_create_info = {};
Mark Lobodzinski085d27a2016-05-17 09:34:26 -06002317 // uint32_t swapchain_image_count = 0;
2318 // VkImage swapchain_images[1] = {VK_NULL_HANDLE};
2319 // uint32_t image_index = 0;
2320 // VkPresentInfoKHR present_info = {};
Ian Elliott2c1daf52016-05-12 09:41:46 -06002321
2322 ASSERT_NO_FATAL_FAILURE(InitState());
2323
2324 // Use the create function from one of the VK_KHR_*_surface extension in
2325 // order to create a surface, testing all known errors in the process,
2326 // before successfully creating a surface:
2327 // First, try to create a surface without a VkXcbSurfaceCreateInfoKHR:
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002328 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "required parameter pCreateInfo specified as NULL");
Ian Elliott2c1daf52016-05-12 09:41:46 -06002329 err = vkCreateXcbSurfaceKHR(instance(), NULL, NULL, &surface);
2330 pass = (err != VK_SUCCESS);
2331 ASSERT_TRUE(pass);
2332 m_errorMonitor->VerifyFound();
2333
2334 // Next, try to create a surface with the wrong
2335 // VkXcbSurfaceCreateInfoKHR::sType:
2336 VkXcbSurfaceCreateInfoKHR xcb_create_info = {};
2337 xcb_create_info.sType = VK_STRUCTURE_TYPE_APPLICATION_INFO;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002338 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "parameter pCreateInfo->sType must be");
Ian Elliott2c1daf52016-05-12 09:41:46 -06002339 err = vkCreateXcbSurfaceKHR(instance(), &xcb_create_info, NULL, &surface);
2340 pass = (err != VK_SUCCESS);
2341 ASSERT_TRUE(pass);
2342 m_errorMonitor->VerifyFound();
2343
Ian Elliott2c1daf52016-05-12 09:41:46 -06002344 // Create a native window, and then correctly create a surface:
2345 xcb_connection_t *connection;
2346 xcb_screen_t *screen;
2347 xcb_window_t xcb_window;
2348 xcb_intern_atom_reply_t *atom_wm_delete_window;
2349
2350 const xcb_setup_t *setup;
2351 xcb_screen_iterator_t iter;
2352 int scr;
2353 uint32_t value_mask, value_list[32];
2354 int width = 1;
2355 int height = 1;
2356
2357 connection = xcb_connect(NULL, &scr);
2358 ASSERT_TRUE(connection != NULL);
2359 setup = xcb_get_setup(connection);
2360 iter = xcb_setup_roots_iterator(setup);
2361 while (scr-- > 0)
2362 xcb_screen_next(&iter);
2363 screen = iter.data;
2364
2365 xcb_window = xcb_generate_id(connection);
2366
2367 value_mask = XCB_CW_BACK_PIXEL | XCB_CW_EVENT_MASK;
2368 value_list[0] = screen->black_pixel;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002369 value_list[1] = XCB_EVENT_MASK_KEY_RELEASE | XCB_EVENT_MASK_EXPOSURE | XCB_EVENT_MASK_STRUCTURE_NOTIFY;
Ian Elliott2c1daf52016-05-12 09:41:46 -06002370
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002371 xcb_create_window(connection, XCB_COPY_FROM_PARENT, xcb_window, screen->root, 0, 0, width, height, 0,
2372 XCB_WINDOW_CLASS_INPUT_OUTPUT, screen->root_visual, value_mask, value_list);
Ian Elliott2c1daf52016-05-12 09:41:46 -06002373
2374 /* Magic code that will send notification when window is destroyed */
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002375 xcb_intern_atom_cookie_t cookie = xcb_intern_atom(connection, 1, 12, "WM_PROTOCOLS");
2376 xcb_intern_atom_reply_t *reply = xcb_intern_atom_reply(connection, cookie, 0);
Ian Elliott2c1daf52016-05-12 09:41:46 -06002377
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002378 xcb_intern_atom_cookie_t cookie2 = xcb_intern_atom(connection, 0, 16, "WM_DELETE_WINDOW");
Mark Lobodzinski085d27a2016-05-17 09:34:26 -06002379 atom_wm_delete_window = xcb_intern_atom_reply(connection, cookie2, 0);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002380 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 -06002381 free(reply);
2382
2383 xcb_map_window(connection, xcb_window);
2384
2385 // Force the x/y coordinates to 100,100 results are identical in consecutive
2386 // runs
2387 const uint32_t coords[] = {100, 100};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002388 xcb_configure_window(connection, xcb_window, XCB_CONFIG_WINDOW_X | XCB_CONFIG_WINDOW_Y, coords);
Ian Elliott2c1daf52016-05-12 09:41:46 -06002389
Ian Elliott2c1daf52016-05-12 09:41:46 -06002390 // Finally, try to correctly create a surface:
2391 xcb_create_info.sType = VK_STRUCTURE_TYPE_XCB_SURFACE_CREATE_INFO_KHR;
2392 xcb_create_info.pNext = NULL;
2393 xcb_create_info.flags = 0;
2394 xcb_create_info.connection = connection;
2395 xcb_create_info.window = xcb_window;
2396 err = vkCreateXcbSurfaceKHR(instance(), &xcb_create_info, NULL, &surface);
2397 pass = (err == VK_SUCCESS);
2398 ASSERT_TRUE(pass);
2399
Ian Elliott2c1daf52016-05-12 09:41:46 -06002400 // Check if surface supports presentation:
2401
2402 // 1st, do so without having queried the queue families:
2403 VkBool32 supported = false;
2404 // TODO: Get the following error to come out:
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002405 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
2406 "called before calling the vkGetPhysicalDeviceQueueFamilyProperties "
2407 "function");
Ian Elliott2c1daf52016-05-12 09:41:46 -06002408 err = vkGetPhysicalDeviceSurfaceSupportKHR(gpu(), 0, surface, &supported);
2409 pass = (err != VK_SUCCESS);
Mark Lobodzinski085d27a2016-05-17 09:34:26 -06002410 // ASSERT_TRUE(pass);
2411 // m_errorMonitor->VerifyFound();
Ian Elliott2c1daf52016-05-12 09:41:46 -06002412
2413 // Next, query a queue family index that's too large:
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002414 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "called with a queueFamilyIndex that is too large");
2415 err = vkGetPhysicalDeviceSurfaceSupportKHR(gpu(), 100000, surface, &supported);
Ian Elliott2c1daf52016-05-12 09:41:46 -06002416 pass = (err != VK_SUCCESS);
2417 ASSERT_TRUE(pass);
2418 m_errorMonitor->VerifyFound();
2419
2420 // Finally, do so correctly:
Mark Lobodzinski085d27a2016-05-17 09:34:26 -06002421 // FIXME: THIS ISN'T CORRECT--MUST QUERY UNTIL WE FIND A QUEUE FAMILY THAT'S
2422 // SUPPORTED
Ian Elliott2c1daf52016-05-12 09:41:46 -06002423 err = vkGetPhysicalDeviceSurfaceSupportKHR(gpu(), 0, surface, &supported);
2424 pass = (err == VK_SUCCESS);
2425 ASSERT_TRUE(pass);
2426
Ian Elliott2c1daf52016-05-12 09:41:46 -06002427 // Before proceeding, try to create a swapchain without having called
2428 // vkGetPhysicalDeviceSurfaceCapabilitiesKHR():
2429 swapchain_create_info.sType = VK_STRUCTURE_TYPE_SWAPCHAIN_CREATE_INFO_KHR;
2430 swapchain_create_info.pNext = NULL;
2431 swapchain_create_info.flags = 0;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002432 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
2433 "called before calling vkGetPhysicalDeviceSurfaceCapabilitiesKHR().");
2434 err = vkCreateSwapchainKHR(m_device->device(), &swapchain_create_info, NULL, &swapchain);
Ian Elliott2c1daf52016-05-12 09:41:46 -06002435 pass = (err != VK_SUCCESS);
2436 ASSERT_TRUE(pass);
2437 m_errorMonitor->VerifyFound();
2438
Ian Elliott2c1daf52016-05-12 09:41:46 -06002439 // Get the surface capabilities:
2440 VkSurfaceCapabilitiesKHR surface_capabilities;
2441
2442 // Do so correctly (only error logged by this entrypoint is if the
2443 // extension isn't enabled):
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002444 err = vkGetPhysicalDeviceSurfaceCapabilitiesKHR(gpu(), surface, &surface_capabilities);
Ian Elliott2c1daf52016-05-12 09:41:46 -06002445 pass = (err == VK_SUCCESS);
2446 ASSERT_TRUE(pass);
2447
Ian Elliott2c1daf52016-05-12 09:41:46 -06002448 // Get the surface formats:
2449 uint32_t surface_format_count;
2450
2451 // First, try without a pointer to surface_format_count:
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002452 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "required parameter pSurfaceFormatCount "
2453 "specified as NULL");
Ian Elliott2c1daf52016-05-12 09:41:46 -06002454 vkGetPhysicalDeviceSurfaceFormatsKHR(gpu(), surface, NULL, NULL);
2455 pass = (err == VK_SUCCESS);
2456 ASSERT_TRUE(pass);
2457 m_errorMonitor->VerifyFound();
2458
2459 // Next, call with a non-NULL pSurfaceFormats, even though we haven't
2460 // correctly done a 1st try (to get the count):
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002461 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 -06002462 surface_format_count = 0;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002463 vkGetPhysicalDeviceSurfaceFormatsKHR(gpu(), surface, &surface_format_count, (VkSurfaceFormatKHR *)&surface_format_count);
Ian Elliott2c1daf52016-05-12 09:41:46 -06002464 pass = (err == VK_SUCCESS);
2465 ASSERT_TRUE(pass);
2466 m_errorMonitor->VerifyFound();
2467
2468 // Next, correctly do a 1st try (with a NULL pointer to surface_formats):
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002469 vkGetPhysicalDeviceSurfaceFormatsKHR(gpu(), surface, &surface_format_count, NULL);
Ian Elliott2c1daf52016-05-12 09:41:46 -06002470 pass = (err == VK_SUCCESS);
2471 ASSERT_TRUE(pass);
2472
2473 // Allocate memory for the correct number of VkSurfaceFormatKHR's:
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002474 VkSurfaceFormatKHR *surface_formats = (VkSurfaceFormatKHR *)malloc(surface_format_count * sizeof(VkSurfaceFormatKHR));
Ian Elliott2c1daf52016-05-12 09:41:46 -06002475
2476 // Next, do a 2nd try with surface_format_count being set too high:
2477 surface_format_count += 5;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002478 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "that is greater than the value");
2479 vkGetPhysicalDeviceSurfaceFormatsKHR(gpu(), surface, &surface_format_count, surface_formats);
Ian Elliott2c1daf52016-05-12 09:41:46 -06002480 pass = (err == VK_SUCCESS);
2481 ASSERT_TRUE(pass);
2482 m_errorMonitor->VerifyFound();
2483
2484 // Finally, do a correct 1st and 2nd try:
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002485 vkGetPhysicalDeviceSurfaceFormatsKHR(gpu(), surface, &surface_format_count, NULL);
Ian Elliott2c1daf52016-05-12 09:41:46 -06002486 pass = (err == VK_SUCCESS);
2487 ASSERT_TRUE(pass);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002488 vkGetPhysicalDeviceSurfaceFormatsKHR(gpu(), surface, &surface_format_count, surface_formats);
Ian Elliott2c1daf52016-05-12 09:41:46 -06002489 pass = (err == VK_SUCCESS);
2490 ASSERT_TRUE(pass);
2491
Ian Elliott2c1daf52016-05-12 09:41:46 -06002492 // Get the surface present modes:
2493 uint32_t surface_present_mode_count;
2494
2495 // First, try without a pointer to surface_format_count:
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002496 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "required parameter pPresentModeCount "
2497 "specified as NULL");
Mark Lobodzinskib02ea642016-08-17 13:03:57 -06002498
Ian Elliott2c1daf52016-05-12 09:41:46 -06002499 vkGetPhysicalDeviceSurfacePresentModesKHR(gpu(), surface, NULL, NULL);
2500 pass = (err == VK_SUCCESS);
2501 ASSERT_TRUE(pass);
2502 m_errorMonitor->VerifyFound();
2503
2504 // Next, call with a non-NULL VkPresentModeKHR, even though we haven't
2505 // correctly done a 1st try (to get the count):
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002506 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 -06002507 surface_present_mode_count = 0;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002508 vkGetPhysicalDeviceSurfacePresentModesKHR(gpu(), surface, &surface_present_mode_count,
2509 (VkPresentModeKHR *)&surface_present_mode_count);
Ian Elliott2c1daf52016-05-12 09:41:46 -06002510 pass = (err == VK_SUCCESS);
2511 ASSERT_TRUE(pass);
2512 m_errorMonitor->VerifyFound();
2513
2514 // Next, correctly do a 1st try (with a NULL pointer to surface_formats):
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002515 vkGetPhysicalDeviceSurfacePresentModesKHR(gpu(), surface, &surface_present_mode_count, NULL);
Ian Elliott2c1daf52016-05-12 09:41:46 -06002516 pass = (err == VK_SUCCESS);
2517 ASSERT_TRUE(pass);
2518
2519 // Allocate memory for the correct number of VkSurfaceFormatKHR's:
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002520 VkPresentModeKHR *surface_present_modes = (VkPresentModeKHR *)malloc(surface_present_mode_count * sizeof(VkPresentModeKHR));
Ian Elliott2c1daf52016-05-12 09:41:46 -06002521
2522 // Next, do a 2nd try with surface_format_count being set too high:
2523 surface_present_mode_count += 5;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002524 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "that is greater than the value");
2525 vkGetPhysicalDeviceSurfacePresentModesKHR(gpu(), surface, &surface_present_mode_count, surface_present_modes);
Ian Elliott2c1daf52016-05-12 09:41:46 -06002526 pass = (err == VK_SUCCESS);
2527 ASSERT_TRUE(pass);
2528 m_errorMonitor->VerifyFound();
2529
2530 // Finally, do a correct 1st and 2nd try:
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002531 vkGetPhysicalDeviceSurfacePresentModesKHR(gpu(), surface, &surface_present_mode_count, NULL);
Ian Elliott2c1daf52016-05-12 09:41:46 -06002532 pass = (err == VK_SUCCESS);
2533 ASSERT_TRUE(pass);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002534 vkGetPhysicalDeviceSurfacePresentModesKHR(gpu(), surface, &surface_present_mode_count, surface_present_modes);
Ian Elliott2c1daf52016-05-12 09:41:46 -06002535 pass = (err == VK_SUCCESS);
2536 ASSERT_TRUE(pass);
2537
Ian Elliott2c1daf52016-05-12 09:41:46 -06002538 // Create a swapchain:
2539
2540 // First, try without a pointer to swapchain_create_info:
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002541 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "required parameter pCreateInfo "
2542 "specified as NULL");
Mark Lobodzinskib02ea642016-08-17 13:03:57 -06002543
Ian Elliott2c1daf52016-05-12 09:41:46 -06002544 err = vkCreateSwapchainKHR(m_device->device(), NULL, NULL, &swapchain);
2545 pass = (err != VK_SUCCESS);
2546 ASSERT_TRUE(pass);
2547 m_errorMonitor->VerifyFound();
2548
2549 // Next, call with a non-NULL swapchain_create_info, that has the wrong
2550 // sType:
2551 swapchain_create_info.sType = VK_STRUCTURE_TYPE_APPLICATION_INFO;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002552 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "parameter pCreateInfo->sType must be");
Mark Lobodzinskib02ea642016-08-17 13:03:57 -06002553
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002554 err = vkCreateSwapchainKHR(m_device->device(), &swapchain_create_info, NULL, &swapchain);
Ian Elliott2c1daf52016-05-12 09:41:46 -06002555 pass = (err != VK_SUCCESS);
2556 ASSERT_TRUE(pass);
2557 m_errorMonitor->VerifyFound();
2558
2559 // Next, call with a NULL swapchain pointer:
2560 swapchain_create_info.sType = VK_STRUCTURE_TYPE_SWAPCHAIN_CREATE_INFO_KHR;
2561 swapchain_create_info.pNext = NULL;
2562 swapchain_create_info.flags = 0;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002563 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "required parameter pSwapchain "
2564 "specified as NULL");
Mark Lobodzinskib02ea642016-08-17 13:03:57 -06002565
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002566 err = vkCreateSwapchainKHR(m_device->device(), &swapchain_create_info, NULL, NULL);
Ian Elliott2c1daf52016-05-12 09:41:46 -06002567 pass = (err != VK_SUCCESS);
2568 ASSERT_TRUE(pass);
2569 m_errorMonitor->VerifyFound();
2570
Mark Lobodzinski085d27a2016-05-17 09:34:26 -06002571 // TODO: Enhance swapchain layer so that
2572 // swapchain_create_info.queueFamilyIndexCount is checked against something?
Ian Elliott2c1daf52016-05-12 09:41:46 -06002573
2574 // Next, call with a queue family index that's too large:
2575 uint32_t queueFamilyIndex[2] = {100000, 0};
2576 swapchain_create_info.imageSharingMode = VK_SHARING_MODE_CONCURRENT;
2577 swapchain_create_info.queueFamilyIndexCount = 2;
2578 swapchain_create_info.pQueueFamilyIndices = queueFamilyIndex;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002579 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "called with a queueFamilyIndex that is too large");
2580 err = vkCreateSwapchainKHR(m_device->device(), &swapchain_create_info, NULL, &swapchain);
Ian Elliott2c1daf52016-05-12 09:41:46 -06002581 pass = (err != VK_SUCCESS);
2582 ASSERT_TRUE(pass);
2583 m_errorMonitor->VerifyFound();
2584
2585 // Next, call a queueFamilyIndexCount that's too small for CONCURRENT:
2586 swapchain_create_info.imageSharingMode = VK_SHARING_MODE_CONCURRENT;
2587 swapchain_create_info.queueFamilyIndexCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002588 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
2589 "but with a bad value(s) for pCreateInfo->queueFamilyIndexCount or "
2590 "pCreateInfo->pQueueFamilyIndices).");
2591 err = vkCreateSwapchainKHR(m_device->device(), &swapchain_create_info, NULL, &swapchain);
Ian Elliott2c1daf52016-05-12 09:41:46 -06002592 pass = (err != VK_SUCCESS);
2593 ASSERT_TRUE(pass);
2594 m_errorMonitor->VerifyFound();
2595
2596 // Next, call with an invalid imageSharingMode:
2597 swapchain_create_info.imageSharingMode = VK_SHARING_MODE_MAX_ENUM;
2598 swapchain_create_info.queueFamilyIndexCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002599 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
2600 "called with a non-supported pCreateInfo->imageSharingMode (i.e.");
2601 err = vkCreateSwapchainKHR(m_device->device(), &swapchain_create_info, NULL, &swapchain);
Ian Elliott2c1daf52016-05-12 09:41:46 -06002602 pass = (err != VK_SUCCESS);
2603 ASSERT_TRUE(pass);
2604 m_errorMonitor->VerifyFound();
2605 // Fix for the future:
Mark Lobodzinski085d27a2016-05-17 09:34:26 -06002606 // FIXME: THIS ISN'T CORRECT--MUST QUERY UNTIL WE FIND A QUEUE FAMILY THAT'S
2607 // SUPPORTED
Ian Elliott2c1daf52016-05-12 09:41:46 -06002608 swapchain_create_info.queueFamilyIndexCount = 0;
2609 queueFamilyIndex[0] = 0;
2610 swapchain_create_info.imageSharingMode = VK_SHARING_MODE_EXCLUSIVE;
2611
Mark Lobodzinski085d27a2016-05-17 09:34:26 -06002612 // TODO: CONTINUE TESTING VALIDATION OF vkCreateSwapchainKHR() ...
Ian Elliott2c1daf52016-05-12 09:41:46 -06002613 // Get the images from a swapchain:
Ian Elliott2c1daf52016-05-12 09:41:46 -06002614 // Acquire an image from a swapchain:
Ian Elliott2c1daf52016-05-12 09:41:46 -06002615 // Present an image to a swapchain:
Ian Elliott2c1daf52016-05-12 09:41:46 -06002616 // Destroy the swapchain:
2617
Mark Lobodzinski085d27a2016-05-17 09:34:26 -06002618 // TODOs:
2619 //
2620 // - Try destroying the device without first destroying the swapchain
2621 //
2622 // - Try destroying the device without first destroying the surface
2623 //
2624 // - Try destroying the surface without first destroying the swapchain
Ian Elliott2c1daf52016-05-12 09:41:46 -06002625
2626 // Destroy the surface:
2627 vkDestroySurfaceKHR(instance(), surface, NULL);
2628
Ian Elliott2c1daf52016-05-12 09:41:46 -06002629 // Tear down the window:
2630 xcb_destroy_window(connection, xcb_window);
2631 xcb_disconnect(connection);
2632
2633#else // VK_USE_PLATFORM_XCB_KHR
Mark Lobodzinski085d27a2016-05-17 09:34:26 -06002634 return;
Ian Elliott2c1daf52016-05-12 09:41:46 -06002635#endif // VK_USE_PLATFORM_XCB_KHR
2636}
2637
Karl Schultz6addd812016-02-02 17:17:23 -07002638TEST_F(VkLayerTest, MapMemWithoutHostVisibleBit) {
2639 VkResult err;
2640 bool pass;
Mark Lobodzinski3780e142015-05-14 15:08:13 -05002641
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002642 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
2643 "Mapping Memory without VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06002644
Mark Lobodzinski3780e142015-05-14 15:08:13 -05002645 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinski3780e142015-05-14 15:08:13 -05002646
2647 // Create an image, allocate memory, free it, and then try to bind it
Karl Schultz6addd812016-02-02 17:17:23 -07002648 VkImage image;
2649 VkDeviceMemory mem;
2650 VkMemoryRequirements mem_reqs;
Mark Lobodzinski3780e142015-05-14 15:08:13 -05002651
Karl Schultz6addd812016-02-02 17:17:23 -07002652 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
2653 const int32_t tex_width = 32;
2654 const int32_t tex_height = 32;
Mark Lobodzinski3780e142015-05-14 15:08:13 -05002655
Tony Barboureb254902015-07-15 12:50:33 -06002656 VkImageCreateInfo image_create_info = {};
2657 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
Karl Schultz6addd812016-02-02 17:17:23 -07002658 image_create_info.pNext = NULL;
2659 image_create_info.imageType = VK_IMAGE_TYPE_2D;
2660 image_create_info.format = tex_format;
2661 image_create_info.extent.width = tex_width;
2662 image_create_info.extent.height = tex_height;
2663 image_create_info.extent.depth = 1;
2664 image_create_info.mipLevels = 1;
2665 image_create_info.arrayLayers = 1;
2666 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
2667 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
2668 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
2669 image_create_info.flags = 0;
Mark Lobodzinski5fcc4212015-09-14 17:43:42 -06002670
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002671 VkMemoryAllocateInfo mem_alloc = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08002672 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
Karl Schultz6addd812016-02-02 17:17:23 -07002673 mem_alloc.pNext = NULL;
2674 mem_alloc.allocationSize = 0;
2675 // Introduce failure, do NOT set memProps to
2676 // VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT
2677 mem_alloc.memoryTypeIndex = 1;
Mark Lobodzinski3780e142015-05-14 15:08:13 -05002678
Chia-I Wuf7458c52015-10-26 21:10:41 +08002679 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
Mark Lobodzinski3780e142015-05-14 15:08:13 -05002680 ASSERT_VK_SUCCESS(err);
2681
Karl Schultz6addd812016-02-02 17:17:23 -07002682 vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs);
Mark Lobodzinski3780e142015-05-14 15:08:13 -05002683
Mark Lobodzinski23065352015-05-29 09:32:35 -05002684 mem_alloc.allocationSize = mem_reqs.size;
Mark Lobodzinski3780e142015-05-14 15:08:13 -05002685
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002686 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 -07002687 if (!pass) { // If we can't find any unmappable memory this test doesn't
2688 // make sense
Chia-I Wuf7458c52015-10-26 21:10:41 +08002689 vkDestroyImage(m_device->device(), image, NULL);
Tony Barbour02fdc7d2015-08-04 16:13:01 -06002690 return;
Mike Stroyand1c84a52015-08-18 14:40:24 -06002691 }
Mike Stroyan713b2d72015-08-04 10:49:29 -06002692
Mark Lobodzinski3780e142015-05-14 15:08:13 -05002693 // allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002694 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem);
Mark Lobodzinski3780e142015-05-14 15:08:13 -05002695 ASSERT_VK_SUCCESS(err);
2696
2697 // Try to bind free memory that has been freed
Tony Barbour67e99152015-07-10 14:10:27 -06002698 err = vkBindImageMemory(m_device->device(), image, mem, 0);
Mark Lobodzinski3780e142015-05-14 15:08:13 -05002699 ASSERT_VK_SUCCESS(err);
2700
2701 // Map memory as if to initialize the image
2702 void *mappedAddress = NULL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002703 err = vkMapMemory(m_device->device(), mem, 0, VK_WHOLE_SIZE, 0, &mappedAddress);
Mark Lobodzinski3780e142015-05-14 15:08:13 -05002704
Chris Forbes8f36a8a2016-04-07 13:21:07 +12002705 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06002706
Chia-I Wuf7458c52015-10-26 21:10:41 +08002707 vkDestroyImage(m_device->device(), image, NULL);
Tony Barbourdf4c0042016-06-01 15:55:43 -06002708 vkFreeMemory(m_device->device(), mem, NULL);
Mark Lobodzinski3780e142015-05-14 15:08:13 -05002709}
2710
Karl Schultz6addd812016-02-02 17:17:23 -07002711TEST_F(VkLayerTest, RebindMemory) {
2712 VkResult err;
2713 bool pass;
Mark Lobodzinski944aab12015-06-05 13:59:04 -05002714
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002715 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "which has already been bound to mem object");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06002716
Mark Lobodzinski944aab12015-06-05 13:59:04 -05002717 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinski944aab12015-06-05 13:59:04 -05002718
2719 // Create an image, allocate memory, free it, and then try to bind it
Karl Schultz6addd812016-02-02 17:17:23 -07002720 VkImage image;
2721 VkDeviceMemory mem1;
2722 VkDeviceMemory mem2;
2723 VkMemoryRequirements mem_reqs;
Mark Lobodzinski944aab12015-06-05 13:59:04 -05002724
Karl Schultz6addd812016-02-02 17:17:23 -07002725 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
2726 const int32_t tex_width = 32;
2727 const int32_t tex_height = 32;
Mark Lobodzinski944aab12015-06-05 13:59:04 -05002728
Tony Barboureb254902015-07-15 12:50:33 -06002729 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -07002730 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
2731 image_create_info.pNext = NULL;
2732 image_create_info.imageType = VK_IMAGE_TYPE_2D;
2733 image_create_info.format = tex_format;
2734 image_create_info.extent.width = tex_width;
2735 image_create_info.extent.height = tex_height;
2736 image_create_info.extent.depth = 1;
2737 image_create_info.mipLevels = 1;
2738 image_create_info.arrayLayers = 1;
2739 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
2740 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
2741 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
2742 image_create_info.flags = 0;
Mark Lobodzinski944aab12015-06-05 13:59:04 -05002743
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002744 VkMemoryAllocateInfo mem_alloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -07002745 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
2746 mem_alloc.pNext = NULL;
2747 mem_alloc.allocationSize = 0;
2748 mem_alloc.memoryTypeIndex = 0;
Tony Barboureb254902015-07-15 12:50:33 -06002749
Karl Schultz6addd812016-02-02 17:17:23 -07002750 // Introduce failure, do NOT set memProps to
2751 // VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT
Tony Barboureb254902015-07-15 12:50:33 -06002752 mem_alloc.memoryTypeIndex = 1;
Chia-I Wuf7458c52015-10-26 21:10:41 +08002753 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
Mark Lobodzinski944aab12015-06-05 13:59:04 -05002754 ASSERT_VK_SUCCESS(err);
2755
Karl Schultz6addd812016-02-02 17:17:23 -07002756 vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs);
Mark Lobodzinski944aab12015-06-05 13:59:04 -05002757
2758 mem_alloc.allocationSize = mem_reqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002759 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -06002760 ASSERT_TRUE(pass);
Mark Lobodzinski944aab12015-06-05 13:59:04 -05002761
2762 // allocate 2 memory objects
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002763 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem1);
Mark Lobodzinski944aab12015-06-05 13:59:04 -05002764 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002765 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem2);
Mark Lobodzinski944aab12015-06-05 13:59:04 -05002766 ASSERT_VK_SUCCESS(err);
2767
2768 // Bind first memory object to Image object
Tony Barbour67e99152015-07-10 14:10:27 -06002769 err = vkBindImageMemory(m_device->device(), image, mem1, 0);
Mark Lobodzinski944aab12015-06-05 13:59:04 -05002770 ASSERT_VK_SUCCESS(err);
2771
Karl Schultz6addd812016-02-02 17:17:23 -07002772 // Introduce validation failure, try to bind a different memory object to
2773 // the same image object
Tony Barbour67e99152015-07-10 14:10:27 -06002774 err = vkBindImageMemory(m_device->device(), image, mem2, 0);
Mark Lobodzinski944aab12015-06-05 13:59:04 -05002775
Chris Forbes8f36a8a2016-04-07 13:21:07 +12002776 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06002777
Chia-I Wuf7458c52015-10-26 21:10:41 +08002778 vkDestroyImage(m_device->device(), image, NULL);
2779 vkFreeMemory(m_device->device(), mem1, NULL);
2780 vkFreeMemory(m_device->device(), mem2, NULL);
Mark Lobodzinski944aab12015-06-05 13:59:04 -05002781}
Mark Lobodzinski3780e142015-05-14 15:08:13 -05002782
Karl Schultz6addd812016-02-02 17:17:23 -07002783TEST_F(VkLayerTest, SubmitSignaledFence) {
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06002784 vk_testing::Fence testFence;
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06002785
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002786 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "submitted in SIGNALED state. Fences "
2787 "must be reset before being submitted");
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06002788
2789 VkFenceCreateInfo fenceInfo = {};
Tony Barbour0b4d9562015-04-09 10:48:04 -06002790 fenceInfo.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
2791 fenceInfo.pNext = NULL;
2792 fenceInfo.flags = VK_FENCE_CREATE_SIGNALED_BIT;
Tony Barbour300a6082015-04-07 13:44:53 -06002793
Tony Barbour300a6082015-04-07 13:44:53 -06002794 ASSERT_NO_FATAL_FAILURE(InitState());
2795 ASSERT_NO_FATAL_FAILURE(InitViewport());
2796 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
2797
Tony Barbourfe3351b2015-07-28 10:17:20 -06002798 BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002799 m_commandBuffer->ClearAllBuffers(m_clear_color, m_depth_clear_color, m_stencil_clear_color, NULL);
Tony Barbourfe3351b2015-07-28 10:17:20 -06002800 EndCommandBuffer();
Tony Barbour300a6082015-04-07 13:44:53 -06002801
2802 testFence.init(*m_device, fenceInfo);
Mark Lobodzinski5fcc4212015-09-14 17:43:42 -06002803
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06002804 VkSubmitInfo submit_info;
Chia-I Wuf9be13c2015-10-26 20:37:06 +08002805 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
2806 submit_info.pNext = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08002807 submit_info.waitSemaphoreCount = 0;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06002808 submit_info.pWaitSemaphores = NULL;
Jon Ashburn7f9716c2015-12-30 16:42:50 -07002809 submit_info.pWaitDstStageMask = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08002810 submit_info.commandBufferCount = 1;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002811 submit_info.pCommandBuffers = &m_commandBuffer->handle();
Chia-I Wud50a7d72015-10-26 20:48:51 +08002812 submit_info.signalSemaphoreCount = 0;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06002813 submit_info.pSignalSemaphores = NULL;
Courtney Goeltzenleuchter646b9072015-10-20 18:04:07 -06002814
2815 vkQueueSubmit(m_device->m_queue, 1, &submit_info, testFence.handle());
Karl Schultz6addd812016-02-02 17:17:23 -07002816 vkQueueWaitIdle(m_device->m_queue);
Mark Lobodzinski5fcc4212015-09-14 17:43:42 -06002817
Chris Forbes8f36a8a2016-04-07 13:21:07 +12002818 m_errorMonitor->VerifyFound();
Tony Barbour0b4d9562015-04-09 10:48:04 -06002819}
Tobin Ehlisaff7ae92016-04-18 15:45:20 -06002820// This is a positive test. We used to expect error in this case but spec now
2821// allows it
Karl Schultz6addd812016-02-02 17:17:23 -07002822TEST_F(VkLayerTest, ResetUnsignaledFence) {
Tobin Ehlisaff7ae92016-04-18 15:45:20 -06002823 m_errorMonitor->ExpectSuccess();
Tony Barbour0b4d9562015-04-09 10:48:04 -06002824 vk_testing::Fence testFence;
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06002825 VkFenceCreateInfo fenceInfo = {};
Tony Barbour0b4d9562015-04-09 10:48:04 -06002826 fenceInfo.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
2827 fenceInfo.pNext = NULL;
2828
Tony Barbour0b4d9562015-04-09 10:48:04 -06002829 ASSERT_NO_FATAL_FAILURE(InitState());
2830 testFence.init(*m_device, fenceInfo);
Chia-I Wud9e8e822015-07-03 11:45:55 +08002831 VkFence fences[1] = {testFence.handle()};
Tobin Ehlisaff7ae92016-04-18 15:45:20 -06002832 VkResult result = vkResetFences(m_device->device(), 1, fences);
2833 ASSERT_VK_SUCCESS(result);
Tony Barbour300a6082015-04-07 13:44:53 -06002834
Tobin Ehlisaff7ae92016-04-18 15:45:20 -06002835 m_errorMonitor->VerifyNotFound();
Tony Barbour300a6082015-04-07 13:44:53 -06002836}
Tobin Ehlis56ab9022016-08-17 17:59:31 -06002837#if 0 // A few devices have issues with this test so disabling for now
Chris Forbese70b7d32016-06-15 15:49:12 +12002838TEST_F(VkLayerTest, LongFenceChain)
2839{
2840 m_errorMonitor->ExpectSuccess();
2841
2842 ASSERT_NO_FATAL_FAILURE(InitState());
2843 VkResult err;
2844
2845 std::vector<VkFence> fences;
2846
2847 const int chainLength = 32768;
2848
2849 for (int i = 0; i < chainLength; i++) {
2850 VkFenceCreateInfo fci = { VK_STRUCTURE_TYPE_FENCE_CREATE_INFO, nullptr, 0 };
2851 VkFence fence;
2852 err = vkCreateFence(m_device->device(), &fci, nullptr, &fence);
2853 ASSERT_VK_SUCCESS(err);
2854
2855 fences.push_back(fence);
2856
2857 VkSubmitInfo si = { VK_STRUCTURE_TYPE_SUBMIT_INFO, nullptr, 0, nullptr, nullptr,
2858 0, nullptr, 0, nullptr };
2859 err = vkQueueSubmit(m_device->m_queue, 1, &si, fence);
2860 ASSERT_VK_SUCCESS(err);
2861
2862 }
2863
2864 // BOOM, stack overflow.
2865 vkWaitForFences(m_device->device(), 1, &fences.back(), VK_TRUE, UINT64_MAX);
2866
2867 for (auto fence : fences)
2868 vkDestroyFence(m_device->device(), fence, nullptr);
2869
2870 m_errorMonitor->VerifyNotFound();
2871}
Tobin Ehlis56ab9022016-08-17 17:59:31 -06002872#endif
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002873TEST_F(VkLayerTest, CommandBufferSimultaneousUseSync) {
Chris Forbes18127d12016-06-08 16:52:28 +12002874 m_errorMonitor->ExpectSuccess();
2875
2876 ASSERT_NO_FATAL_FAILURE(InitState());
2877 VkResult err;
2878
2879 // Record (empty!) command buffer that can be submitted multiple times
2880 // simultaneously.
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002881 VkCommandBufferBeginInfo cbbi = {VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO, nullptr,
2882 VK_COMMAND_BUFFER_USAGE_SIMULTANEOUS_USE_BIT, nullptr};
Chris Forbes18127d12016-06-08 16:52:28 +12002883 m_commandBuffer->BeginCommandBuffer(&cbbi);
2884 m_commandBuffer->EndCommandBuffer();
2885
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002886 VkFenceCreateInfo fci = {VK_STRUCTURE_TYPE_FENCE_CREATE_INFO, nullptr, 0};
Chris Forbes18127d12016-06-08 16:52:28 +12002887 VkFence fence;
2888 err = vkCreateFence(m_device->device(), &fci, nullptr, &fence);
2889 ASSERT_VK_SUCCESS(err);
2890
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002891 VkSemaphoreCreateInfo sci = {VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO, nullptr, 0};
Chris Forbes18127d12016-06-08 16:52:28 +12002892 VkSemaphore s1, s2;
2893 err = vkCreateSemaphore(m_device->device(), &sci, nullptr, &s1);
2894 ASSERT_VK_SUCCESS(err);
2895 err = vkCreateSemaphore(m_device->device(), &sci, nullptr, &s2);
2896 ASSERT_VK_SUCCESS(err);
2897
2898 // Submit CB once signaling s1, with fence so we can roll forward to its retirement.
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002899 VkSubmitInfo si = {VK_STRUCTURE_TYPE_SUBMIT_INFO, nullptr, 0, nullptr, nullptr, 1, &m_commandBuffer->handle(), 1, &s1};
Chris Forbes18127d12016-06-08 16:52:28 +12002900 err = vkQueueSubmit(m_device->m_queue, 1, &si, fence);
2901 ASSERT_VK_SUCCESS(err);
2902
2903 // Submit CB again, signaling s2.
2904 si.pSignalSemaphores = &s2;
2905 err = vkQueueSubmit(m_device->m_queue, 1, &si, VK_NULL_HANDLE);
2906 ASSERT_VK_SUCCESS(err);
2907
2908 // Wait for fence.
2909 err = vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
2910 ASSERT_VK_SUCCESS(err);
2911
2912 // CB is still in flight from second submission, but semaphore s1 is no
2913 // longer in flight. delete it.
2914 vkDestroySemaphore(m_device->device(), s1, nullptr);
2915
2916 m_errorMonitor->VerifyNotFound();
2917
2918 // Force device idle and clean up remaining objects
2919 vkDeviceWaitIdle(m_device->device());
2920 vkDestroySemaphore(m_device->device(), s2, nullptr);
2921 vkDestroyFence(m_device->device(), fence, nullptr);
2922}
2923
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002924TEST_F(VkLayerTest, FenceCreateSignaledWaitHandling) {
Chris Forbes4e44c912016-06-16 10:20:00 +12002925 m_errorMonitor->ExpectSuccess();
2926
2927 ASSERT_NO_FATAL_FAILURE(InitState());
2928 VkResult err;
2929
2930 // A fence created signaled
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002931 VkFenceCreateInfo fci1 = {VK_STRUCTURE_TYPE_FENCE_CREATE_INFO, nullptr, VK_FENCE_CREATE_SIGNALED_BIT};
Chris Forbes4e44c912016-06-16 10:20:00 +12002932 VkFence f1;
2933 err = vkCreateFence(m_device->device(), &fci1, nullptr, &f1);
2934 ASSERT_VK_SUCCESS(err);
2935
2936 // A fence created not
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002937 VkFenceCreateInfo fci2 = {VK_STRUCTURE_TYPE_FENCE_CREATE_INFO, nullptr, 0};
Chris Forbes4e44c912016-06-16 10:20:00 +12002938 VkFence f2;
2939 err = vkCreateFence(m_device->device(), &fci2, nullptr, &f2);
2940 ASSERT_VK_SUCCESS(err);
2941
2942 // Submit the unsignaled fence
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002943 VkSubmitInfo si = {VK_STRUCTURE_TYPE_SUBMIT_INFO, nullptr, 0, nullptr, nullptr, 0, nullptr, 0, nullptr};
Chris Forbes4e44c912016-06-16 10:20:00 +12002944 err = vkQueueSubmit(m_device->m_queue, 1, &si, f2);
2945
2946 // Wait on both fences, with signaled first.
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002947 VkFence fences[] = {f1, f2};
Chris Forbes4e44c912016-06-16 10:20:00 +12002948 vkWaitForFences(m_device->device(), 2, fences, VK_TRUE, UINT64_MAX);
2949
2950 // Should have both retired!
2951 vkDestroyFence(m_device->device(), f1, nullptr);
2952 vkDestroyFence(m_device->device(), f2, nullptr);
2953
2954 m_errorMonitor->VerifyNotFound();
2955}
2956
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002957TEST_F(VkLayerTest, InvalidUsageBits) {
2958 TEST_DESCRIPTION("Specify wrong usage for image then create conflicting view of image "
2959 "Initialize buffer with wrong usage then perform copy expecting errors "
2960 "from both the image and the buffer (2 calls)");
2961 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Invalid usage flag for image ");
Tobin Ehlis41376e12015-07-03 08:45:14 -06002962
2963 ASSERT_NO_FATAL_FAILURE(InitState());
Tony Barbourf92621a2016-05-02 14:28:12 -06002964 VkImageObj image(m_device);
Tony Barbour75d79f02016-08-30 09:39:07 -06002965 // Initialize image with USAGE_TRANSIENT_ATTACHMENT
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002966 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 -06002967 ASSERT_TRUE(image.initialized());
Tobin Ehlis41376e12015-07-03 08:45:14 -06002968
Tony Barbourf92621a2016-05-02 14:28:12 -06002969 VkImageView dsv;
2970 VkImageViewCreateInfo dsvci = {};
2971 dsvci.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
2972 dsvci.image = image.handle();
2973 dsvci.viewType = VK_IMAGE_VIEW_TYPE_2D;
2974 dsvci.format = VK_FORMAT_D32_SFLOAT_S8_UINT;
2975 dsvci.subresourceRange.layerCount = 1;
2976 dsvci.subresourceRange.baseMipLevel = 0;
2977 dsvci.subresourceRange.levelCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002978 dsvci.subresourceRange.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT;
Tobin Ehlis41376e12015-07-03 08:45:14 -06002979
Tony Barbourf92621a2016-05-02 14:28:12 -06002980 // Create a view with depth / stencil aspect for image with different usage
2981 vkCreateImageView(m_device->device(), &dsvci, NULL, &dsv);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06002982
Chris Forbes8f36a8a2016-04-07 13:21:07 +12002983 m_errorMonitor->VerifyFound();
Tony Barbourf92621a2016-05-02 14:28:12 -06002984
2985 // Initialize buffer with TRANSFER_DST usage
2986 vk_testing::Buffer buffer;
2987 VkMemoryPropertyFlags reqs = 0;
2988 buffer.init_as_dst(*m_device, 128 * 128, reqs);
2989 VkBufferImageCopy region = {};
2990 region.bufferRowLength = 128;
2991 region.bufferImageHeight = 128;
2992 region.imageSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
2993 region.imageSubresource.layerCount = 1;
2994 region.imageExtent.height = 16;
2995 region.imageExtent.width = 16;
2996 region.imageExtent.depth = 1;
2997
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002998 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Invalid usage flag for buffer ");
Tony Barbourf92621a2016-05-02 14:28:12 -06002999 // Buffer usage not set to TRANSFER_SRC and image usage not set to
3000 // TRANSFER_DST
3001 BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003002 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer.handle(), image.handle(),
3003 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, &region);
Tony Barbourf92621a2016-05-02 14:28:12 -06003004 m_errorMonitor->VerifyFound();
3005
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003006 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Invalid usage flag for image ");
3007 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer.handle(), image.handle(),
3008 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, &region);
Tony Barbourf92621a2016-05-02 14:28:12 -06003009 m_errorMonitor->VerifyFound();
Tobin Ehlis41376e12015-07-03 08:45:14 -06003010}
Tony Barbour75d79f02016-08-30 09:39:07 -06003011
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003012TEST_F(VkLayerTest, ValidUsage) {
3013 TEST_DESCRIPTION("Verify that creating an image view from an image with valid usage "
3014 "doesn't generate validation errors");
Tony Barbour75d79f02016-08-30 09:39:07 -06003015
3016 ASSERT_NO_FATAL_FAILURE(InitState());
3017
3018 m_errorMonitor->ExpectSuccess();
3019 // Verify that we can create a view with usage INPUT_ATTACHMENT
3020 VkImageObj image(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003021 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 -06003022 ASSERT_TRUE(image.initialized());
3023 VkImageView imageView;
3024 VkImageViewCreateInfo ivci = {};
3025 ivci.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
3026 ivci.image = image.handle();
3027 ivci.viewType = VK_IMAGE_VIEW_TYPE_2D;
3028 ivci.format = VK_FORMAT_R8G8B8A8_UNORM;
3029 ivci.subresourceRange.layerCount = 1;
3030 ivci.subresourceRange.baseMipLevel = 0;
3031 ivci.subresourceRange.levelCount = 1;
3032 ivci.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
3033
3034 vkCreateImageView(m_device->device(), &ivci, NULL, &imageView);
3035 m_errorMonitor->VerifyNotFound();
3036 vkDestroyImageView(m_device->device(), imageView, NULL);
3037}
Mark Lobodzinski209b5292015-09-17 09:44:05 -06003038#endif // MEM_TRACKER_TESTS
3039
Tobin Ehlis4bf96d12015-06-25 11:58:41 -06003040#if OBJ_TRACKER_TESTS
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06003041
3042TEST_F(VkLayerTest, LeakAnObject) {
3043 VkResult err;
3044
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003045 TEST_DESCRIPTION("Create a fence and destroy its device without first destroying the fence.");
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06003046
3047 // Note that we have to create a new device since destroying the
3048 // framework's device causes Teardown() to fail and just calling Teardown
3049 // will destroy the errorMonitor.
3050
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003051 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "has not been destroyed.");
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06003052
3053 ASSERT_NO_FATAL_FAILURE(InitState());
3054
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003055 const std::vector<VkQueueFamilyProperties> queue_props = m_device->queue_props;
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06003056 std::vector<VkDeviceQueueCreateInfo> queue_info;
3057 queue_info.reserve(queue_props.size());
3058 std::vector<std::vector<float>> queue_priorities;
3059 for (uint32_t i = 0; i < (uint32_t)queue_props.size(); i++) {
3060 VkDeviceQueueCreateInfo qi = {};
3061 qi.sType = VK_STRUCTURE_TYPE_DEVICE_QUEUE_CREATE_INFO;
3062 qi.pNext = NULL;
3063 qi.queueFamilyIndex = i;
3064 qi.queueCount = queue_props[i].queueCount;
3065 queue_priorities.emplace_back(qi.queueCount, 0.0f);
3066 qi.pQueuePriorities = queue_priorities[i].data();
3067 queue_info.push_back(qi);
3068 }
3069
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06003070 std::vector<const char *> device_extension_names;
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06003071
3072 // The sacrificial device object
3073 VkDevice testDevice;
3074 VkDeviceCreateInfo device_create_info = {};
3075 auto features = m_device->phy().features();
3076 device_create_info.sType = VK_STRUCTURE_TYPE_DEVICE_CREATE_INFO;
3077 device_create_info.pNext = NULL;
3078 device_create_info.queueCreateInfoCount = queue_info.size();
3079 device_create_info.pQueueCreateInfos = queue_info.data();
Tony Barbour4c70d102016-08-08 16:06:56 -06003080 device_create_info.enabledLayerCount = 0;
3081 device_create_info.ppEnabledLayerNames = NULL;
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06003082 device_create_info.pEnabledFeatures = &features;
3083 err = vkCreateDevice(gpu(), &device_create_info, NULL, &testDevice);
3084 ASSERT_VK_SUCCESS(err);
3085
3086 VkFence fence;
3087 VkFenceCreateInfo fence_create_info = {};
3088 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
3089 fence_create_info.pNext = NULL;
3090 fence_create_info.flags = 0;
3091 err = vkCreateFence(testDevice, &fence_create_info, NULL, &fence);
3092 ASSERT_VK_SUCCESS(err);
3093
3094 // Induce failure by not calling vkDestroyFence
3095 vkDestroyDevice(testDevice, NULL);
3096 m_errorMonitor->VerifyFound();
3097}
3098
3099TEST_F(VkLayerTest, InvalidCommandPoolConsistency) {
3100
3101 TEST_DESCRIPTION("Allocate command buffers from one command pool and "
3102 "attempt to delete them from another.");
3103
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003104 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "FreeCommandBuffers is attempting to free Command Buffer");
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06003105
Cody Northropc31a84f2016-08-22 10:41:47 -06003106 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06003107 VkCommandPool command_pool_one;
3108 VkCommandPool command_pool_two;
3109
3110 VkCommandPoolCreateInfo pool_create_info{};
3111 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
3112 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
3113 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
3114
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003115 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool_one);
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06003116
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003117 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool_two);
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06003118
3119 VkCommandBuffer command_buffer[9];
3120 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003121 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06003122 command_buffer_allocate_info.commandPool = command_pool_one;
3123 command_buffer_allocate_info.commandBufferCount = 9;
3124 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003125 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, command_buffer);
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06003126
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003127 vkFreeCommandBuffers(m_device->device(), command_pool_two, 4, &command_buffer[3]);
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06003128
3129 m_errorMonitor->VerifyFound();
3130
3131 vkDestroyCommandPool(m_device->device(), command_pool_one, NULL);
3132 vkDestroyCommandPool(m_device->device(), command_pool_two, NULL);
3133}
3134
3135TEST_F(VkLayerTest, InvalidDescriptorPoolConsistency) {
3136 VkResult err;
3137
3138 TEST_DESCRIPTION("Allocate descriptor sets from one DS pool and "
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003139 "attempt to delete them from another.");
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06003140
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003141 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "FreeDescriptorSets is attempting to free descriptorSet");
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06003142
3143 ASSERT_NO_FATAL_FAILURE(InitState());
3144 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
3145
3146 VkDescriptorPoolSize ds_type_count = {};
3147 ds_type_count.type = VK_DESCRIPTOR_TYPE_SAMPLER;
3148 ds_type_count.descriptorCount = 1;
3149
3150 VkDescriptorPoolCreateInfo ds_pool_ci = {};
3151 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
3152 ds_pool_ci.pNext = NULL;
3153 ds_pool_ci.flags = 0;
3154 ds_pool_ci.maxSets = 1;
3155 ds_pool_ci.poolSizeCount = 1;
3156 ds_pool_ci.pPoolSizes = &ds_type_count;
3157
3158 VkDescriptorPool ds_pool_one;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003159 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool_one);
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06003160 ASSERT_VK_SUCCESS(err);
3161
3162 // Create a second descriptor pool
3163 VkDescriptorPool ds_pool_two;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003164 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool_two);
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06003165 ASSERT_VK_SUCCESS(err);
3166
3167 VkDescriptorSetLayoutBinding dsl_binding = {};
3168 dsl_binding.binding = 0;
3169 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
3170 dsl_binding.descriptorCount = 1;
3171 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
3172 dsl_binding.pImmutableSamplers = NULL;
3173
3174 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
3175 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
3176 ds_layout_ci.pNext = NULL;
3177 ds_layout_ci.bindingCount = 1;
3178 ds_layout_ci.pBindings = &dsl_binding;
3179
3180 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003181 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06003182 ASSERT_VK_SUCCESS(err);
3183
3184 VkDescriptorSet descriptorSet;
3185 VkDescriptorSetAllocateInfo alloc_info = {};
3186 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
3187 alloc_info.descriptorSetCount = 1;
3188 alloc_info.descriptorPool = ds_pool_one;
3189 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003190 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06003191 ASSERT_VK_SUCCESS(err);
3192
3193 err = vkFreeDescriptorSets(m_device->device(), ds_pool_two, 1, &descriptorSet);
3194
3195 m_errorMonitor->VerifyFound();
3196
3197 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
3198 vkDestroyDescriptorPool(m_device->device(), ds_pool_one, NULL);
3199 vkDestroyDescriptorPool(m_device->device(), ds_pool_two, NULL);
3200}
3201
3202TEST_F(VkLayerTest, CreateUnknownObject) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003203 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Invalid Image Object ");
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06003204
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003205 TEST_DESCRIPTION("Pass an invalid image object handle into a Vulkan API call.");
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06003206
3207 ASSERT_NO_FATAL_FAILURE(InitState());
3208
3209 // Pass bogus handle into GetImageMemoryRequirements
3210 VkMemoryRequirements mem_reqs;
3211 uint64_t fakeImageHandle = 0xCADECADE;
3212 VkImage fauxImage = reinterpret_cast<VkImage &>(fakeImageHandle);
3213
3214 vkGetImageMemoryRequirements(m_device->device(), fauxImage, &mem_reqs);
3215
3216 m_errorMonitor->VerifyFound();
3217}
3218
Karl Schultz6addd812016-02-02 17:17:23 -07003219TEST_F(VkLayerTest, PipelineNotBound) {
3220 VkResult err;
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06003221
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003222 TEST_DESCRIPTION("Pass in an invalid pipeline object handle into a Vulkan API call.");
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06003223
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003224 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Invalid Pipeline Object ");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06003225
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06003226 ASSERT_NO_FATAL_FAILURE(InitState());
3227 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06003228
Chia-I Wu1b99bb22015-10-27 19:25:11 +08003229 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07003230 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
3231 ds_type_count.descriptorCount = 1;
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06003232
3233 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07003234 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
3235 ds_pool_ci.pNext = NULL;
3236 ds_pool_ci.maxSets = 1;
3237 ds_pool_ci.poolSizeCount = 1;
3238 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06003239
3240 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003241 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06003242 ASSERT_VK_SUCCESS(err);
3243
3244 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07003245 dsl_binding.binding = 0;
3246 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
3247 dsl_binding.descriptorCount = 1;
3248 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
3249 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06003250
3251 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07003252 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
3253 ds_layout_ci.pNext = NULL;
3254 ds_layout_ci.bindingCount = 1;
3255 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06003256
3257 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003258 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06003259 ASSERT_VK_SUCCESS(err);
3260
3261 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08003262 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08003263 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07003264 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06003265 alloc_info.descriptorPool = ds_pool;
3266 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003267 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06003268 ASSERT_VK_SUCCESS(err);
3269
3270 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07003271 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
3272 pipeline_layout_ci.pNext = NULL;
3273 pipeline_layout_ci.setLayoutCount = 1;
3274 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06003275
3276 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003277 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06003278 ASSERT_VK_SUCCESS(err);
3279
Mark Youngad779052016-01-06 14:26:04 -07003280 VkPipeline badPipeline = (VkPipeline)((size_t)0xbaadb1be);
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06003281
3282 BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003283 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, badPipeline);
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06003284
Chris Forbes8f36a8a2016-04-07 13:21:07 +12003285 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06003286
Chia-I Wuf7458c52015-10-26 21:10:41 +08003287 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
3288 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
3289 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlisec598302015-09-15 15:02:17 -06003290}
Mike Stroyan80fc6c32016-06-20 15:42:29 -06003291
Mark Lobodzinskibc185762016-06-15 16:28:53 -06003292TEST_F(VkLayerTest, BindImageInvalidMemoryType) {
3293 VkResult err;
3294
3295 TEST_DESCRIPTION("Test validation check for an invalid memory type index "
3296 "during bind[Buffer|Image]Memory time");
3297
Mark Lobodzinskibc185762016-06-15 16:28:53 -06003298 ASSERT_NO_FATAL_FAILURE(InitState());
3299
3300 // Create an image, allocate memory, set a bad typeIndex and then try to
3301 // bind it
3302 VkImage image;
3303 VkDeviceMemory mem;
3304 VkMemoryRequirements mem_reqs;
3305 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
3306 const int32_t tex_width = 32;
3307 const int32_t tex_height = 32;
3308
3309 VkImageCreateInfo image_create_info = {};
3310 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
3311 image_create_info.pNext = NULL;
3312 image_create_info.imageType = VK_IMAGE_TYPE_2D;
3313 image_create_info.format = tex_format;
3314 image_create_info.extent.width = tex_width;
3315 image_create_info.extent.height = tex_height;
3316 image_create_info.extent.depth = 1;
3317 image_create_info.mipLevels = 1;
3318 image_create_info.arrayLayers = 1;
3319 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
3320 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
3321 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
3322 image_create_info.flags = 0;
3323
3324 VkMemoryAllocateInfo mem_alloc = {};
3325 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
3326 mem_alloc.pNext = NULL;
3327 mem_alloc.allocationSize = 0;
3328 mem_alloc.memoryTypeIndex = 0;
3329
3330 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
3331 ASSERT_VK_SUCCESS(err);
3332
3333 vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs);
3334 mem_alloc.allocationSize = mem_reqs.size;
Mike Stroyan80fc6c32016-06-20 15:42:29 -06003335
3336 // Introduce Failure, select invalid TypeIndex
3337 VkPhysicalDeviceMemoryProperties memory_info;
3338
3339 vkGetPhysicalDeviceMemoryProperties(gpu(), &memory_info);
3340 unsigned int i;
3341 for (i = 0; i < memory_info.memoryTypeCount; i++) {
3342 if ((mem_reqs.memoryTypeBits & (1 << i)) == 0) {
3343 mem_alloc.memoryTypeIndex = i;
3344 break;
3345 }
3346 }
3347 if (i >= memory_info.memoryTypeCount) {
3348 printf("No invalid memory type index could be found; skipped.\n");
3349 vkDestroyImage(m_device->device(), image, NULL);
3350 return;
3351 }
3352
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003353 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 -06003354
3355 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem);
3356 ASSERT_VK_SUCCESS(err);
3357
3358 err = vkBindImageMemory(m_device->device(), image, mem, 0);
3359 (void)err;
3360
3361 m_errorMonitor->VerifyFound();
3362
3363 vkDestroyImage(m_device->device(), image, NULL);
3364 vkFreeMemory(m_device->device(), mem, NULL);
3365}
Mike Stroyan80fc6c32016-06-20 15:42:29 -06003366
Karl Schultz6addd812016-02-02 17:17:23 -07003367TEST_F(VkLayerTest, BindInvalidMemory) {
3368 VkResult err;
3369 bool pass;
Tobin Ehlisec598302015-09-15 15:02:17 -06003370
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003371 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Invalid Device Memory Object ");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06003372
Tobin Ehlisec598302015-09-15 15:02:17 -06003373 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisec598302015-09-15 15:02:17 -06003374
3375 // Create an image, allocate memory, free it, and then try to bind it
Karl Schultz6addd812016-02-02 17:17:23 -07003376 VkImage image;
3377 VkDeviceMemory mem;
3378 VkMemoryRequirements mem_reqs;
Tobin Ehlisec598302015-09-15 15:02:17 -06003379
Karl Schultz6addd812016-02-02 17:17:23 -07003380 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
3381 const int32_t tex_width = 32;
3382 const int32_t tex_height = 32;
Tobin Ehlisec598302015-09-15 15:02:17 -06003383
3384 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -07003385 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
3386 image_create_info.pNext = NULL;
3387 image_create_info.imageType = VK_IMAGE_TYPE_2D;
3388 image_create_info.format = tex_format;
3389 image_create_info.extent.width = tex_width;
3390 image_create_info.extent.height = tex_height;
3391 image_create_info.extent.depth = 1;
3392 image_create_info.mipLevels = 1;
3393 image_create_info.arrayLayers = 1;
3394 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
3395 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
3396 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
3397 image_create_info.flags = 0;
Tobin Ehlisec598302015-09-15 15:02:17 -06003398
Chia-I Wu3432a0c2015-10-27 18:04:07 +08003399 VkMemoryAllocateInfo mem_alloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -07003400 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
3401 mem_alloc.pNext = NULL;
3402 mem_alloc.allocationSize = 0;
3403 mem_alloc.memoryTypeIndex = 0;
Tobin Ehlisec598302015-09-15 15:02:17 -06003404
Chia-I Wuf7458c52015-10-26 21:10:41 +08003405 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
Tobin Ehlisec598302015-09-15 15:02:17 -06003406 ASSERT_VK_SUCCESS(err);
3407
Karl Schultz6addd812016-02-02 17:17:23 -07003408 vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs);
Tobin Ehlisec598302015-09-15 15:02:17 -06003409
3410 mem_alloc.allocationSize = mem_reqs.size;
3411
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003412 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -06003413 ASSERT_TRUE(pass);
Tobin Ehlisec598302015-09-15 15:02:17 -06003414
3415 // allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +08003416 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem);
Tobin Ehlisec598302015-09-15 15:02:17 -06003417 ASSERT_VK_SUCCESS(err);
3418
3419 // Introduce validation failure, free memory before binding
Chia-I Wuf7458c52015-10-26 21:10:41 +08003420 vkFreeMemory(m_device->device(), mem, NULL);
Tobin Ehlisec598302015-09-15 15:02:17 -06003421
3422 // Try to bind free memory that has been freed
3423 err = vkBindImageMemory(m_device->device(), image, mem, 0);
3424 // This may very well return an error.
3425 (void)err;
3426
Chris Forbes8f36a8a2016-04-07 13:21:07 +12003427 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06003428
Chia-I Wuf7458c52015-10-26 21:10:41 +08003429 vkDestroyImage(m_device->device(), image, NULL);
Tobin Ehlisec598302015-09-15 15:02:17 -06003430}
3431
Karl Schultz6addd812016-02-02 17:17:23 -07003432TEST_F(VkLayerTest, BindMemoryToDestroyedObject) {
3433 VkResult err;
3434 bool pass;
Tobin Ehlisec598302015-09-15 15:02:17 -06003435
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003436 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Invalid Image Object ");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06003437
Tobin Ehlisec598302015-09-15 15:02:17 -06003438 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisec598302015-09-15 15:02:17 -06003439
Karl Schultz6addd812016-02-02 17:17:23 -07003440 // Create an image object, allocate memory, destroy the object and then try
3441 // to bind it
3442 VkImage image;
3443 VkDeviceMemory mem;
3444 VkMemoryRequirements mem_reqs;
Tobin Ehlisec598302015-09-15 15:02:17 -06003445
Karl Schultz6addd812016-02-02 17:17:23 -07003446 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
3447 const int32_t tex_width = 32;
3448 const int32_t tex_height = 32;
Tobin Ehlisec598302015-09-15 15:02:17 -06003449
3450 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -07003451 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
3452 image_create_info.pNext = NULL;
3453 image_create_info.imageType = VK_IMAGE_TYPE_2D;
3454 image_create_info.format = tex_format;
3455 image_create_info.extent.width = tex_width;
3456 image_create_info.extent.height = tex_height;
3457 image_create_info.extent.depth = 1;
3458 image_create_info.mipLevels = 1;
3459 image_create_info.arrayLayers = 1;
3460 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
3461 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
3462 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
3463 image_create_info.flags = 0;
Tobin Ehlisec598302015-09-15 15:02:17 -06003464
Chia-I Wu3432a0c2015-10-27 18:04:07 +08003465 VkMemoryAllocateInfo mem_alloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -07003466 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
3467 mem_alloc.pNext = NULL;
3468 mem_alloc.allocationSize = 0;
3469 mem_alloc.memoryTypeIndex = 0;
Tobin Ehlisec598302015-09-15 15:02:17 -06003470
Chia-I Wuf7458c52015-10-26 21:10:41 +08003471 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
Tobin Ehlisec598302015-09-15 15:02:17 -06003472 ASSERT_VK_SUCCESS(err);
3473
Karl Schultz6addd812016-02-02 17:17:23 -07003474 vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs);
Tobin Ehlisec598302015-09-15 15:02:17 -06003475
3476 mem_alloc.allocationSize = mem_reqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003477 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -06003478 ASSERT_TRUE(pass);
Tobin Ehlisec598302015-09-15 15:02:17 -06003479
3480 // Allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +08003481 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem);
Tobin Ehlisec598302015-09-15 15:02:17 -06003482 ASSERT_VK_SUCCESS(err);
3483
3484 // Introduce validation failure, destroy Image object before binding
Chia-I Wuf7458c52015-10-26 21:10:41 +08003485 vkDestroyImage(m_device->device(), image, NULL);
Tobin Ehlisec598302015-09-15 15:02:17 -06003486 ASSERT_VK_SUCCESS(err);
3487
3488 // Now Try to bind memory to this destroyed object
3489 err = vkBindImageMemory(m_device->device(), image, mem, 0);
3490 // This may very well return an error.
Karl Schultz6addd812016-02-02 17:17:23 -07003491 (void)err;
Tobin Ehlisec598302015-09-15 15:02:17 -06003492
Chris Forbes8f36a8a2016-04-07 13:21:07 +12003493 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06003494
Chia-I Wuf7458c52015-10-26 21:10:41 +08003495 vkFreeMemory(m_device->device(), mem, NULL);
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06003496}
Tobin Ehlisa1c28562015-10-23 16:00:08 -06003497
Mark Lobodzinski209b5292015-09-17 09:44:05 -06003498#endif // OBJ_TRACKER_TESTS
3499
Tobin Ehlis0788f522015-05-26 16:11:58 -06003500#if DRAW_STATE_TESTS
Mark Lobodzinskic808d442016-04-14 10:57:23 -06003501
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06003502TEST_F(VkLayerTest, ImageSampleCounts) {
3503
3504 TEST_DESCRIPTION("Use bad sample counts in image transfer calls to trigger "
3505 "validation errors.");
3506 ASSERT_NO_FATAL_FAILURE(InitState());
3507
3508 VkMemoryPropertyFlags reqs = 0;
3509 VkImageCreateInfo image_create_info = {};
3510 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
3511 image_create_info.pNext = NULL;
3512 image_create_info.imageType = VK_IMAGE_TYPE_2D;
3513 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
3514 image_create_info.extent.width = 256;
3515 image_create_info.extent.height = 256;
3516 image_create_info.extent.depth = 1;
3517 image_create_info.mipLevels = 1;
3518 image_create_info.arrayLayers = 1;
3519 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
3520 image_create_info.flags = 0;
3521
3522 VkImageBlit blit_region = {};
3523 blit_region.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
3524 blit_region.srcSubresource.baseArrayLayer = 0;
3525 blit_region.srcSubresource.layerCount = 1;
3526 blit_region.srcSubresource.mipLevel = 0;
3527 blit_region.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
3528 blit_region.dstSubresource.baseArrayLayer = 0;
3529 blit_region.dstSubresource.layerCount = 1;
3530 blit_region.dstSubresource.mipLevel = 0;
3531
3532 // Create two images, the source with sampleCount = 2, and attempt to blit
3533 // between them
3534 {
3535 image_create_info.samples = VK_SAMPLE_COUNT_2_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003536 image_create_info.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06003537 vk_testing::Image src_image;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003538 src_image.init(*m_device, (const VkImageCreateInfo &)image_create_info, reqs);
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06003539 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003540 image_create_info.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT;
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06003541 vk_testing::Image dst_image;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003542 dst_image.init(*m_device, (const VkImageCreateInfo &)image_create_info, reqs);
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06003543 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003544 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "was created with a sample count "
3545 "of VK_SAMPLE_COUNT_2_BIT but "
3546 "must be VK_SAMPLE_COUNT_1_BIT");
3547 vkCmdBlitImage(m_commandBuffer->GetBufferHandle(), src_image.handle(), VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
3548 dst_image.handle(), VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL, 1, &blit_region, VK_FILTER_NEAREST);
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06003549 m_errorMonitor->VerifyFound();
3550 m_commandBuffer->EndCommandBuffer();
3551 }
3552
3553 // Create two images, the dest with sampleCount = 4, and attempt to blit
3554 // between them
3555 {
3556 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003557 image_create_info.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06003558 vk_testing::Image src_image;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003559 src_image.init(*m_device, (const VkImageCreateInfo &)image_create_info, reqs);
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06003560 image_create_info.samples = VK_SAMPLE_COUNT_4_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003561 image_create_info.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT;
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06003562 vk_testing::Image dst_image;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003563 dst_image.init(*m_device, (const VkImageCreateInfo &)image_create_info, reqs);
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06003564 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003565 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "was created with a sample count "
3566 "of VK_SAMPLE_COUNT_4_BIT but "
3567 "must be VK_SAMPLE_COUNT_1_BIT");
3568 vkCmdBlitImage(m_commandBuffer->GetBufferHandle(), src_image.handle(), VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
3569 dst_image.handle(), VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL, 1, &blit_region, VK_FILTER_NEAREST);
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06003570 m_errorMonitor->VerifyFound();
3571 m_commandBuffer->EndCommandBuffer();
3572 }
3573
3574 VkBufferImageCopy copy_region = {};
3575 copy_region.bufferRowLength = 128;
3576 copy_region.bufferImageHeight = 128;
3577 copy_region.imageSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
3578 copy_region.imageSubresource.layerCount = 1;
3579 copy_region.imageExtent.height = 64;
3580 copy_region.imageExtent.width = 64;
3581 copy_region.imageExtent.depth = 1;
3582
3583 // Create src buffer and dst image with sampleCount = 4 and attempt to copy
3584 // buffer to image
3585 {
3586 vk_testing::Buffer src_buffer;
3587 VkMemoryPropertyFlags reqs = 0;
3588 src_buffer.init_as_src(*m_device, 128 * 128 * 4, reqs);
3589 image_create_info.samples = VK_SAMPLE_COUNT_8_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003590 image_create_info.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT;
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06003591 vk_testing::Image dst_image;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003592 dst_image.init(*m_device, (const VkImageCreateInfo &)image_create_info, reqs);
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06003593 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003594 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "was created with a sample count "
3595 "of VK_SAMPLE_COUNT_8_BIT but "
3596 "must be VK_SAMPLE_COUNT_1_BIT");
3597 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), src_buffer.handle(), dst_image.handle(),
3598 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, &copy_region);
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06003599 m_errorMonitor->VerifyFound();
3600 m_commandBuffer->EndCommandBuffer();
3601 }
3602
3603 // Create dst buffer and src image with sampleCount = 2 and attempt to copy
3604 // image to buffer
3605 {
3606 vk_testing::Buffer dst_buffer;
3607 dst_buffer.init_as_dst(*m_device, 128 * 128 * 4, reqs);
3608 image_create_info.samples = VK_SAMPLE_COUNT_2_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003609 image_create_info.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06003610 vk_testing::Image src_image;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003611 src_image.init(*m_device, (const VkImageCreateInfo &)image_create_info, reqs);
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06003612 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003613 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "was created with a sample count "
3614 "of VK_SAMPLE_COUNT_2_BIT but "
3615 "must be VK_SAMPLE_COUNT_1_BIT");
3616 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), src_image.handle(), VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL,
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06003617 dst_buffer.handle(), 1, &copy_region);
3618 m_errorMonitor->VerifyFound();
3619 m_commandBuffer->EndCommandBuffer();
3620 }
3621}
3622
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06003623TEST_F(VkLayerTest, DSImageTransferGranularityTests) {
3624 VkResult err;
3625 bool pass;
3626
3627 TEST_DESCRIPTION("Tests for validaiton of Queue Family property minImageTransferGranularity.");
3628 ASSERT_NO_FATAL_FAILURE(InitState());
3629
3630 // If w/d/h granularity is 1, test is not meaningful
3631 // TODO: When virtual device limits are available, create a set of limits for this test that
3632 // will always have a granularity of > 1 for w, h, and d
3633 auto index = m_device->graphics_queue_node_index_;
3634 auto queue_family_properties = m_device->phy().queue_properties();
3635
3636 if ((queue_family_properties[index].minImageTransferGranularity.depth < 4) ||
3637 (queue_family_properties[index].minImageTransferGranularity.width < 4) ||
3638 (queue_family_properties[index].minImageTransferGranularity.height < 4)) {
3639 return;
3640 }
3641
3642 // Create two images of different types and try to copy between them
3643 VkImage srcImage;
3644 VkImage dstImage;
3645 VkDeviceMemory srcMem;
3646 VkDeviceMemory destMem;
3647 VkMemoryRequirements memReqs;
3648
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06003649 VkImageCreateInfo image_create_info = {};
3650 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
3651 image_create_info.pNext = NULL;
3652 image_create_info.imageType = VK_IMAGE_TYPE_2D;
3653 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
3654 image_create_info.extent.width = 32;
3655 image_create_info.extent.height = 32;
3656 image_create_info.extent.depth = 1;
3657 image_create_info.mipLevels = 1;
3658 image_create_info.arrayLayers = 4;
3659 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
3660 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
3661 image_create_info.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT;
3662 image_create_info.flags = 0;
3663
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003664 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06003665 ASSERT_VK_SUCCESS(err);
3666
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003667 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06003668 ASSERT_VK_SUCCESS(err);
3669
3670 // Allocate memory
3671 VkMemoryAllocateInfo memAlloc = {};
3672 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
3673 memAlloc.pNext = NULL;
3674 memAlloc.allocationSize = 0;
3675 memAlloc.memoryTypeIndex = 0;
3676
3677 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
3678 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003679 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06003680 ASSERT_TRUE(pass);
3681 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
3682 ASSERT_VK_SUCCESS(err);
3683
3684 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
3685 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003686 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06003687 ASSERT_VK_SUCCESS(err);
3688 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
3689 ASSERT_VK_SUCCESS(err);
3690
3691 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
3692 ASSERT_VK_SUCCESS(err);
3693 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
3694 ASSERT_VK_SUCCESS(err);
3695
3696 BeginCommandBuffer();
3697 VkImageCopy copyRegion;
3698 copyRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
3699 copyRegion.srcSubresource.mipLevel = 0;
3700 copyRegion.srcSubresource.baseArrayLayer = 0;
3701 copyRegion.srcSubresource.layerCount = 1;
3702 copyRegion.srcOffset.x = 0;
3703 copyRegion.srcOffset.y = 0;
3704 copyRegion.srcOffset.z = 0;
3705 copyRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
3706 copyRegion.dstSubresource.mipLevel = 0;
3707 copyRegion.dstSubresource.baseArrayLayer = 0;
3708 copyRegion.dstSubresource.layerCount = 1;
3709 copyRegion.dstOffset.x = 0;
3710 copyRegion.dstOffset.y = 0;
3711 copyRegion.dstOffset.z = 0;
3712 copyRegion.extent.width = 1;
3713 copyRegion.extent.height = 1;
3714 copyRegion.extent.depth = 1;
3715
3716 // Introduce failure by setting srcOffset to a bad granularity value
3717 copyRegion.srcOffset.y = 3;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003718 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "queue family image transfer granularity");
3719 m_commandBuffer->CopyImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, VK_IMAGE_LAYOUT_GENERAL, 1, &copyRegion);
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06003720 m_errorMonitor->VerifyFound();
3721
3722 // Introduce failure by setting extent to a bad granularity value
3723 copyRegion.srcOffset.y = 0;
3724 copyRegion.extent.width = 3;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003725 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "queue family image transfer granularity");
3726 m_commandBuffer->CopyImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, VK_IMAGE_LAYOUT_GENERAL, 1, &copyRegion);
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06003727 m_errorMonitor->VerifyFound();
3728
3729 // Now do some buffer/image copies
3730 vk_testing::Buffer buffer;
3731 VkMemoryPropertyFlags reqs = 0;
3732 buffer.init_as_dst(*m_device, 128 * 128, reqs);
3733 VkBufferImageCopy region = {};
3734 region.bufferOffset = 0;
3735 region.bufferRowLength = 3;
3736 region.bufferImageHeight = 128;
3737 region.imageSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
3738 region.imageSubresource.layerCount = 1;
3739 region.imageExtent.height = 16;
3740 region.imageExtent.width = 16;
3741 region.imageExtent.depth = 1;
3742 region.imageOffset.x = 0;
3743 region.imageOffset.y = 0;
3744 region.imageOffset.z = 0;
3745
3746 // Introduce failure by setting bufferRowLength to a bad granularity value
3747 region.bufferRowLength = 3;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003748 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "queue family image transfer granularity");
3749 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer.handle(), srcImage, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1,
3750 &region);
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06003751 m_errorMonitor->VerifyFound();
3752 region.bufferRowLength = 128;
3753
3754 // Introduce failure by setting bufferOffset to a bad granularity value
3755 region.bufferOffset = 3;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003756 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "queue family image transfer granularity");
3757 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), srcImage, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, buffer.handle(), 1,
3758 &region);
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06003759 m_errorMonitor->VerifyFound();
3760 region.bufferOffset = 0;
3761
3762 // Introduce failure by setting bufferImageHeight to a bad granularity value
3763 region.bufferImageHeight = 3;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003764 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "queue family image transfer granularity");
3765 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), srcImage, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, buffer.handle(), 1,
3766 &region);
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06003767 m_errorMonitor->VerifyFound();
3768 region.bufferImageHeight = 128;
3769
3770 // Introduce failure by setting imageExtent to a bad granularity value
3771 region.imageExtent.width = 3;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003772 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "queue family image transfer granularity");
3773 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), srcImage, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, buffer.handle(), 1,
3774 &region);
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06003775 m_errorMonitor->VerifyFound();
3776 region.imageExtent.width = 16;
3777
3778 // Introduce failure by setting imageOffset to a bad granularity value
3779 region.imageOffset.z = 3;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003780 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "queue family image transfer granularity");
3781 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer.handle(), srcImage, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1,
3782 &region);
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06003783 m_errorMonitor->VerifyFound();
3784
3785 EndCommandBuffer();
3786
3787 vkDestroyImage(m_device->device(), srcImage, NULL);
3788 vkDestroyImage(m_device->device(), dstImage, NULL);
3789 vkFreeMemory(m_device->device(), srcMem, NULL);
3790 vkFreeMemory(m_device->device(), destMem, NULL);
3791}
3792
Mark Lobodzinski570efc62016-08-09 16:43:19 -06003793TEST_F(VkLayerTest, MismatchedQueueFamiliesOnSubmit) {
Mark Lobodzinski570efc62016-08-09 16:43:19 -06003794 TEST_DESCRIPTION("Submit command buffer created using one queue family and "
3795 "attempt to submit them on a queue created in a different "
3796 "queue family.");
3797
Cody Northropc31a84f2016-08-22 10:41:47 -06003798 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinski570efc62016-08-09 16:43:19 -06003799 // This test is meaningless unless we have multiple queue families
3800 auto queue_family_properties = m_device->phy().queue_properties();
3801 if (queue_family_properties.size() < 2) {
3802 return;
3803 }
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003804 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " is being submitted on queue ");
Mark Lobodzinski570efc62016-08-09 16:43:19 -06003805 // Get safe index of another queue family
3806 uint32_t other_queue_family = (m_device->graphics_queue_node_index_ == 0) ? 1 : 0;
3807 ASSERT_NO_FATAL_FAILURE(InitState());
3808 // Create a second queue using a different queue family
3809 VkQueue other_queue;
3810 vkGetDeviceQueue(m_device->device(), other_queue_family, 0, &other_queue);
3811
3812 // Record an empty cmd buffer
3813 VkCommandBufferBeginInfo cmdBufBeginDesc = {};
3814 cmdBufBeginDesc.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
3815 vkBeginCommandBuffer(m_commandBuffer->handle(), &cmdBufBeginDesc);
3816 vkEndCommandBuffer(m_commandBuffer->handle());
3817
3818 // And submit on the wrong queue
3819 VkSubmitInfo submit_info = {};
3820 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
3821 submit_info.commandBufferCount = 1;
3822 submit_info.pCommandBuffers = &m_commandBuffer->handle();
Tobin Ehlisfd213ea2016-08-10 17:10:46 -06003823 vkQueueSubmit(other_queue, 1, &submit_info, VK_NULL_HANDLE);
Mark Lobodzinski570efc62016-08-09 16:43:19 -06003824
3825 m_errorMonitor->VerifyFound();
Mark Lobodzinski570efc62016-08-09 16:43:19 -06003826}
3827
Chris Forbes48a53902016-06-30 11:46:27 +12003828TEST_F(VkLayerTest, RenderPassInitialLayoutUndefined) {
3829 TEST_DESCRIPTION("Ensure that CmdBeginRenderPass with an attachment's "
3830 "initialLayout of VK_IMAGE_LAYOUT_UNDEFINED works when "
3831 "the command buffer has prior knowledge of that "
3832 "attachment's layout.");
3833
3834 m_errorMonitor->ExpectSuccess();
3835
3836 ASSERT_NO_FATAL_FAILURE(InitState());
3837
3838 // A renderpass with one color attachment.
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003839 VkAttachmentDescription attachment = {0,
3840 VK_FORMAT_R8G8B8A8_UNORM,
3841 VK_SAMPLE_COUNT_1_BIT,
3842 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
3843 VK_ATTACHMENT_STORE_OP_STORE,
3844 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
3845 VK_ATTACHMENT_STORE_OP_DONT_CARE,
3846 VK_IMAGE_LAYOUT_UNDEFINED,
3847 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL};
Chris Forbes48a53902016-06-30 11:46:27 +12003848
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003849 VkAttachmentReference att_ref = {0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL};
Chris Forbes48a53902016-06-30 11:46:27 +12003850
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003851 VkSubpassDescription subpass = {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 1, &att_ref, nullptr, nullptr, 0, nullptr};
Chris Forbes48a53902016-06-30 11:46:27 +12003852
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003853 VkRenderPassCreateInfo rpci = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 1, &attachment, 1, &subpass, 0, nullptr};
Chris Forbes48a53902016-06-30 11:46:27 +12003854
3855 VkRenderPass rp;
3856 VkResult err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
3857 ASSERT_VK_SUCCESS(err);
3858
3859 // A compatible framebuffer.
3860 VkImageObj image(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003861 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 +12003862 ASSERT_TRUE(image.initialized());
3863
3864 VkImageViewCreateInfo ivci = {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003865 VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO,
3866 nullptr,
3867 0,
3868 image.handle(),
3869 VK_IMAGE_VIEW_TYPE_2D,
3870 VK_FORMAT_R8G8B8A8_UNORM,
3871 {VK_COMPONENT_SWIZZLE_IDENTITY, VK_COMPONENT_SWIZZLE_IDENTITY, VK_COMPONENT_SWIZZLE_IDENTITY,
3872 VK_COMPONENT_SWIZZLE_IDENTITY},
3873 {VK_IMAGE_ASPECT_COLOR_BIT, 0, 1, 0, 1},
Chris Forbes48a53902016-06-30 11:46:27 +12003874 };
3875 VkImageView view;
3876 err = vkCreateImageView(m_device->device(), &ivci, nullptr, &view);
3877 ASSERT_VK_SUCCESS(err);
3878
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003879 VkFramebufferCreateInfo fci = {VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr, 0, rp, 1, &view, 32, 32, 1};
Chris Forbes48a53902016-06-30 11:46:27 +12003880 VkFramebuffer fb;
3881 err = vkCreateFramebuffer(m_device->device(), &fci, nullptr, &fb);
3882 ASSERT_VK_SUCCESS(err);
3883
3884 // Record a single command buffer which uses this renderpass twice. The
3885 // bug is triggered at the beginning of the second renderpass, when the
3886 // command buffer already has a layout recorded for the attachment.
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003887 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 +12003888 BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003889 vkCmdBeginRenderPass(m_commandBuffer->handle(), &rpbi, VK_SUBPASS_CONTENTS_INLINE);
Chris Forbes48a53902016-06-30 11:46:27 +12003890 vkCmdEndRenderPass(m_commandBuffer->handle());
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003891 vkCmdBeginRenderPass(m_commandBuffer->handle(), &rpbi, VK_SUBPASS_CONTENTS_INLINE);
Chris Forbes48a53902016-06-30 11:46:27 +12003892
3893 m_errorMonitor->VerifyNotFound();
3894
3895 vkCmdEndRenderPass(m_commandBuffer->handle());
3896 EndCommandBuffer();
3897
3898 vkDestroyFramebuffer(m_device->device(), fb, nullptr);
3899 vkDestroyRenderPass(m_device->device(), rp, nullptr);
3900 vkDestroyImageView(m_device->device(), view, nullptr);
3901}
3902
Tobin Ehlis75ac37b2016-07-29 10:55:41 -06003903TEST_F(VkLayerTest, FramebufferBindingDestroyCommandPool) {
3904 TEST_DESCRIPTION("This test should pass. Create a Framebuffer and "
3905 "command buffer, bind them together, then destroy "
3906 "command pool and framebuffer and verify there are no "
3907 "errors.");
3908
3909 m_errorMonitor->ExpectSuccess();
3910
3911 ASSERT_NO_FATAL_FAILURE(InitState());
3912
3913 // A renderpass with one color attachment.
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003914 VkAttachmentDescription attachment = {0,
3915 VK_FORMAT_R8G8B8A8_UNORM,
3916 VK_SAMPLE_COUNT_1_BIT,
3917 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
3918 VK_ATTACHMENT_STORE_OP_STORE,
3919 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
3920 VK_ATTACHMENT_STORE_OP_DONT_CARE,
3921 VK_IMAGE_LAYOUT_UNDEFINED,
3922 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL};
Tobin Ehlis75ac37b2016-07-29 10:55:41 -06003923
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003924 VkAttachmentReference att_ref = {0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL};
Tobin Ehlis75ac37b2016-07-29 10:55:41 -06003925
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003926 VkSubpassDescription subpass = {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 1, &att_ref, nullptr, nullptr, 0, nullptr};
Tobin Ehlis75ac37b2016-07-29 10:55:41 -06003927
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003928 VkRenderPassCreateInfo rpci = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 1, &attachment, 1, &subpass, 0, nullptr};
Tobin Ehlis75ac37b2016-07-29 10:55:41 -06003929
3930 VkRenderPass rp;
3931 VkResult err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
3932 ASSERT_VK_SUCCESS(err);
3933
3934 // A compatible framebuffer.
3935 VkImageObj image(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003936 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 -06003937 ASSERT_TRUE(image.initialized());
3938
3939 VkImageViewCreateInfo ivci = {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003940 VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO,
3941 nullptr,
3942 0,
3943 image.handle(),
3944 VK_IMAGE_VIEW_TYPE_2D,
3945 VK_FORMAT_R8G8B8A8_UNORM,
3946 {VK_COMPONENT_SWIZZLE_IDENTITY, VK_COMPONENT_SWIZZLE_IDENTITY, VK_COMPONENT_SWIZZLE_IDENTITY,
3947 VK_COMPONENT_SWIZZLE_IDENTITY},
3948 {VK_IMAGE_ASPECT_COLOR_BIT, 0, 1, 0, 1},
Tobin Ehlis75ac37b2016-07-29 10:55:41 -06003949 };
3950 VkImageView view;
3951 err = vkCreateImageView(m_device->device(), &ivci, nullptr, &view);
3952 ASSERT_VK_SUCCESS(err);
3953
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003954 VkFramebufferCreateInfo fci = {VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr, 0, rp, 1, &view, 32, 32, 1};
Tobin Ehlis75ac37b2016-07-29 10:55:41 -06003955 VkFramebuffer fb;
3956 err = vkCreateFramebuffer(m_device->device(), &fci, nullptr, &fb);
3957 ASSERT_VK_SUCCESS(err);
3958
3959 // Explicitly create a command buffer to bind the FB to so that we can then
3960 // destroy the command pool in order to implicitly free command buffer
3961 VkCommandPool command_pool;
3962 VkCommandPoolCreateInfo pool_create_info{};
3963 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
3964 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
3965 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003966 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
Tobin Ehlis75ac37b2016-07-29 10:55:41 -06003967
3968 VkCommandBuffer command_buffer;
3969 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003970 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
Tobin Ehlis75ac37b2016-07-29 10:55:41 -06003971 command_buffer_allocate_info.commandPool = command_pool;
3972 command_buffer_allocate_info.commandBufferCount = 1;
3973 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003974 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, &command_buffer);
Tobin Ehlis75ac37b2016-07-29 10:55:41 -06003975
3976 // Begin our cmd buffer with renderpass using our framebuffer
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003977 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 -06003978 VkCommandBufferBeginInfo begin_info{};
3979 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
3980 vkBeginCommandBuffer(command_buffer, &begin_info);
3981
3982 vkCmdBeginRenderPass(command_buffer, &rpbi, VK_SUBPASS_CONTENTS_INLINE);
3983 vkCmdEndRenderPass(command_buffer);
3984 vkEndCommandBuffer(command_buffer);
Mark Lobodzinski7d10a822016-08-03 14:08:40 -06003985 vkDestroyImageView(m_device->device(), view, nullptr);
Tobin Ehlis75ac37b2016-07-29 10:55:41 -06003986 // Destroy command pool to implicitly free command buffer
3987 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
3988 vkDestroyFramebuffer(m_device->device(), fb, nullptr);
3989 vkDestroyRenderPass(m_device->device(), rp, nullptr);
3990 m_errorMonitor->VerifyNotFound();
3991}
3992
Chris Forbes51bf7c92016-06-30 15:22:08 +12003993TEST_F(VkLayerTest, RenderPassSubpassZeroTransitionsApplied) {
3994 TEST_DESCRIPTION("Ensure that CmdBeginRenderPass applies the layout "
3995 "transitions for the first subpass");
3996
3997 m_errorMonitor->ExpectSuccess();
3998
3999 ASSERT_NO_FATAL_FAILURE(InitState());
4000
4001 // A renderpass with one color attachment.
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004002 VkAttachmentDescription attachment = {0,
4003 VK_FORMAT_R8G8B8A8_UNORM,
4004 VK_SAMPLE_COUNT_1_BIT,
4005 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
4006 VK_ATTACHMENT_STORE_OP_STORE,
4007 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
4008 VK_ATTACHMENT_STORE_OP_DONT_CARE,
4009 VK_IMAGE_LAYOUT_UNDEFINED,
4010 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL};
Chris Forbes51bf7c92016-06-30 15:22:08 +12004011
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004012 VkAttachmentReference att_ref = {0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL};
Chris Forbes51bf7c92016-06-30 15:22:08 +12004013
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004014 VkSubpassDescription subpass = {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 1, &att_ref, nullptr, nullptr, 0, nullptr};
Chris Forbes51bf7c92016-06-30 15:22:08 +12004015
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004016 VkSubpassDependency dep = {0,
4017 0,
4018 VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT,
4019 VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT,
4020 VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT,
4021 VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT,
4022 VK_DEPENDENCY_BY_REGION_BIT};
Chris Forbes51bf7c92016-06-30 15:22:08 +12004023
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004024 VkRenderPassCreateInfo rpci = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 1, &attachment, 1, &subpass, 1, &dep};
Chris Forbes51bf7c92016-06-30 15:22:08 +12004025
4026 VkResult err;
4027 VkRenderPass rp;
4028 err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
4029 ASSERT_VK_SUCCESS(err);
4030
4031 // A compatible framebuffer.
4032 VkImageObj image(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004033 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 +12004034 ASSERT_TRUE(image.initialized());
4035
4036 VkImageViewCreateInfo ivci = {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004037 VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO,
4038 nullptr,
4039 0,
4040 image.handle(),
4041 VK_IMAGE_VIEW_TYPE_2D,
4042 VK_FORMAT_R8G8B8A8_UNORM,
4043 {VK_COMPONENT_SWIZZLE_IDENTITY, VK_COMPONENT_SWIZZLE_IDENTITY, VK_COMPONENT_SWIZZLE_IDENTITY,
4044 VK_COMPONENT_SWIZZLE_IDENTITY},
4045 {VK_IMAGE_ASPECT_COLOR_BIT, 0, 1, 0, 1},
Chris Forbes51bf7c92016-06-30 15:22:08 +12004046 };
4047 VkImageView view;
4048 err = vkCreateImageView(m_device->device(), &ivci, nullptr, &view);
4049 ASSERT_VK_SUCCESS(err);
4050
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004051 VkFramebufferCreateInfo fci = {VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr, 0, rp, 1, &view, 32, 32, 1};
Chris Forbes51bf7c92016-06-30 15:22:08 +12004052 VkFramebuffer fb;
4053 err = vkCreateFramebuffer(m_device->device(), &fci, nullptr, &fb);
4054 ASSERT_VK_SUCCESS(err);
4055
4056 // Record a single command buffer which issues a pipeline barrier w/
4057 // image memory barrier for the attachment. This detects the previously
4058 // missing tracking of the subpass layout by throwing a validation error
4059 // if it doesn't occur.
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004060 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 +12004061 BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004062 vkCmdBeginRenderPass(m_commandBuffer->handle(), &rpbi, VK_SUBPASS_CONTENTS_INLINE);
Chris Forbes51bf7c92016-06-30 15:22:08 +12004063
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004064 VkImageMemoryBarrier imb = {VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER,
4065 nullptr,
4066 VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT,
4067 VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT,
4068 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
4069 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
4070 VK_QUEUE_FAMILY_IGNORED,
4071 VK_QUEUE_FAMILY_IGNORED,
4072 image.handle(),
4073 {VK_IMAGE_ASPECT_COLOR_BIT, 0, 1, 0, 1}};
4074 vkCmdPipelineBarrier(m_commandBuffer->handle(), VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT,
4075 VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT, VK_DEPENDENCY_BY_REGION_BIT, 0, nullptr, 0, nullptr, 1,
4076 &imb);
Chris Forbes51bf7c92016-06-30 15:22:08 +12004077
4078 vkCmdEndRenderPass(m_commandBuffer->handle());
4079 m_errorMonitor->VerifyNotFound();
4080 EndCommandBuffer();
4081
4082 vkDestroyFramebuffer(m_device->device(), fb, nullptr);
4083 vkDestroyRenderPass(m_device->device(), rp, nullptr);
4084 vkDestroyImageView(m_device->device(), view, nullptr);
4085}
4086
Mark Lobodzinski77a5d6f2016-08-05 09:38:18 -06004087TEST_F(VkLayerTest, DepthStencilLayoutTransitionForDepthOnlyImageview) {
4088 TEST_DESCRIPTION("Validate that when an imageView of a depth/stencil image "
4089 "is used as a depth/stencil framebuffer attachment, the "
4090 "aspectMask is ignored and both depth and stencil image "
4091 "subresources are used.");
4092
4093 VkFormatProperties format_properties;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004094 vkGetPhysicalDeviceFormatProperties(gpu(), VK_FORMAT_D32_SFLOAT_S8_UINT, &format_properties);
4095 if (!(format_properties.optimalTilingFeatures & VK_FORMAT_FEATURE_SAMPLED_IMAGE_BIT)) {
Mark Lobodzinski77a5d6f2016-08-05 09:38:18 -06004096 return;
4097 }
4098
4099 m_errorMonitor->ExpectSuccess();
4100
4101 ASSERT_NO_FATAL_FAILURE(InitState());
4102
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004103 VkAttachmentDescription attachment = {0,
4104 VK_FORMAT_D32_SFLOAT_S8_UINT,
4105 VK_SAMPLE_COUNT_1_BIT,
4106 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
4107 VK_ATTACHMENT_STORE_OP_STORE,
4108 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
4109 VK_ATTACHMENT_STORE_OP_DONT_CARE,
4110 VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL,
4111 VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL};
Mark Lobodzinski77a5d6f2016-08-05 09:38:18 -06004112
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004113 VkAttachmentReference att_ref = {0, VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL};
Mark Lobodzinski77a5d6f2016-08-05 09:38:18 -06004114
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004115 VkSubpassDescription subpass = {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 0, nullptr, nullptr, &att_ref, 0, nullptr};
Mark Lobodzinski77a5d6f2016-08-05 09:38:18 -06004116
4117 VkSubpassDependency dep = {0,
4118 0,
4119 VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT,
4120 VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT,
4121 VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT,
4122 VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT,
4123 VK_DEPENDENCY_BY_REGION_BIT};
4124
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004125 VkRenderPassCreateInfo rpci = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 1, &attachment, 1, &subpass, 1, &dep};
Mark Lobodzinski77a5d6f2016-08-05 09:38:18 -06004126
4127 VkResult err;
4128 VkRenderPass rp;
4129 err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
4130 ASSERT_VK_SUCCESS(err);
4131
4132 VkImageObj image(m_device);
4133 image.init_no_layout(32, 32, VK_FORMAT_D32_SFLOAT_S8_UINT,
4134 0x26, // usage
4135 VK_IMAGE_TILING_OPTIMAL, 0);
4136 ASSERT_TRUE(image.initialized());
4137 image.SetLayout(0x6, VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL);
4138
4139 VkImageViewCreateInfo ivci = {
4140 VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO,
4141 nullptr,
4142 0,
4143 image.handle(),
4144 VK_IMAGE_VIEW_TYPE_2D,
4145 VK_FORMAT_D32_SFLOAT_S8_UINT,
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004146 {VK_COMPONENT_SWIZZLE_R, VK_COMPONENT_SWIZZLE_G, VK_COMPONENT_SWIZZLE_B, VK_COMPONENT_SWIZZLE_A},
Mark Lobodzinski77a5d6f2016-08-05 09:38:18 -06004147 {0x2, 0, 1, 0, 1},
4148 };
4149 VkImageView view;
4150 err = vkCreateImageView(m_device->device(), &ivci, nullptr, &view);
4151 ASSERT_VK_SUCCESS(err);
4152
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004153 VkFramebufferCreateInfo fci = {VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr, 0, rp, 1, &view, 32, 32, 1};
Mark Lobodzinski77a5d6f2016-08-05 09:38:18 -06004154 VkFramebuffer fb;
4155 err = vkCreateFramebuffer(m_device->device(), &fci, nullptr, &fb);
4156 ASSERT_VK_SUCCESS(err);
4157
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004158 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 -06004159 BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004160 vkCmdBeginRenderPass(m_commandBuffer->handle(), &rpbi, VK_SUBPASS_CONTENTS_INLINE);
Mark Lobodzinski77a5d6f2016-08-05 09:38:18 -06004161
4162 VkImageMemoryBarrier imb = {};
4163 imb.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
4164 imb.pNext = nullptr;
4165 imb.srcAccessMask = VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_WRITE_BIT;
4166 imb.dstAccessMask = VK_ACCESS_SHADER_READ_BIT;
4167 imb.oldLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
4168 imb.newLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
4169 imb.srcQueueFamilyIndex = 0;
4170 imb.dstQueueFamilyIndex = 0;
4171 imb.image = image.handle();
4172 imb.subresourceRange.aspectMask = 0x6;
4173 imb.subresourceRange.baseMipLevel = 0;
4174 imb.subresourceRange.levelCount = 0x1;
4175 imb.subresourceRange.baseArrayLayer = 0;
4176 imb.subresourceRange.layerCount = 0x1;
4177
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004178 vkCmdPipelineBarrier(m_commandBuffer->handle(), VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT,
4179 VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT, VK_DEPENDENCY_BY_REGION_BIT, 0, nullptr, 0, nullptr, 1,
Mark Lobodzinski77a5d6f2016-08-05 09:38:18 -06004180 &imb);
4181
4182 vkCmdEndRenderPass(m_commandBuffer->handle());
4183 EndCommandBuffer();
4184 QueueCommandBuffer(false);
4185 m_errorMonitor->VerifyNotFound();
4186
4187 vkDestroyFramebuffer(m_device->device(), fb, nullptr);
4188 vkDestroyRenderPass(m_device->device(), rp, nullptr);
4189 vkDestroyImageView(m_device->device(), view, nullptr);
4190}
Tony Barbourd5f7b822016-08-02 15:39:33 -06004191
Tony Barbour4e919972016-08-09 13:27:40 -06004192TEST_F(VkLayerTest, RenderPassInvalidRenderArea) {
4193 TEST_DESCRIPTION("Generate INVALID_RENDER_AREA error by beginning renderpass"
4194 "with extent outside of framebuffer");
4195 ASSERT_NO_FATAL_FAILURE(InitState());
4196 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
4197
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004198 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Cannot execute a render pass with renderArea "
4199 "not within the bound of the framebuffer.");
Tony Barbour4e919972016-08-09 13:27:40 -06004200
4201 // Framebuffer for render target is 256x256, exceed that for INVALID_RENDER_AREA
4202 m_renderPassBeginInfo.renderArea.extent.width = 257;
4203 m_renderPassBeginInfo.renderArea.extent.height = 257;
4204 BeginCommandBuffer();
4205 m_errorMonitor->VerifyFound();
4206}
4207
4208TEST_F(VkLayerTest, DisabledIndependentBlend) {
4209 TEST_DESCRIPTION("Generate INDEPENDENT_BLEND by disabling independent "
4210 "blend and then specifying different blend states for two "
4211 "attachements");
Cody Northrop5703cc72016-08-19 09:57:10 -06004212 VkPhysicalDeviceFeatures features = {};
4213 features.independentBlend = VK_FALSE;
Cody Northropc31a84f2016-08-22 10:41:47 -06004214 ASSERT_NO_FATAL_FAILURE(InitState(&features));
Tony Barbour4e919972016-08-09 13:27:40 -06004215
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004216 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
4217 "Invalid Pipeline CreateInfo: If independent blend feature not "
4218 "enabled, all elements of pAttachments must be identical");
Tony Barbour4e919972016-08-09 13:27:40 -06004219
Cody Northropc31a84f2016-08-22 10:41:47 -06004220 VkDescriptorSetObj descriptorSet(m_device);
4221 descriptorSet.AppendDummy();
4222 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Tony Barbour4e919972016-08-09 13:27:40 -06004223
Cody Northropc31a84f2016-08-22 10:41:47 -06004224 VkPipelineObj pipeline(m_device);
4225 VkRenderpassObj renderpass(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004226 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
Cody Northropc31a84f2016-08-22 10:41:47 -06004227 pipeline.AddShader(&vs);
Cody Northrop5703cc72016-08-19 09:57:10 -06004228
Cody Northropc31a84f2016-08-22 10:41:47 -06004229 VkPipelineColorBlendAttachmentState att_state1 = {}, att_state2 = {};
4230 att_state1.dstAlphaBlendFactor = VK_BLEND_FACTOR_CONSTANT_COLOR;
4231 att_state1.blendEnable = VK_TRUE;
4232 att_state2.dstAlphaBlendFactor = VK_BLEND_FACTOR_CONSTANT_COLOR;
4233 att_state2.blendEnable = VK_FALSE;
4234 pipeline.AddColorAttachment(0, &att_state1);
4235 pipeline.AddColorAttachment(1, &att_state2);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004236 pipeline.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderpass.handle());
Cody Northropc31a84f2016-08-22 10:41:47 -06004237 m_errorMonitor->VerifyFound();
Tony Barbour4e919972016-08-09 13:27:40 -06004238}
4239
4240TEST_F(VkLayerTest, RenderPassDepthStencilAttachmentUnused) {
4241 TEST_DESCRIPTION("Specify no depth attachement in renderpass then specify "
4242 "depth attachments in subpass");
Cody Northropc31a84f2016-08-22 10:41:47 -06004243 ASSERT_NO_FATAL_FAILURE(InitState());
Tony Barbour4e919972016-08-09 13:27:40 -06004244
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004245 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
4246 "vkCreateRenderPass has no depth/stencil attachment, yet subpass");
Tony Barbour4e919972016-08-09 13:27:40 -06004247
4248 // Create a renderPass with a single color attachment
4249 VkAttachmentReference attach = {};
4250 attach.layout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
4251 VkSubpassDescription subpass = {};
4252 VkRenderPassCreateInfo rpci = {};
4253 rpci.subpassCount = 1;
4254 rpci.pSubpasses = &subpass;
4255 rpci.attachmentCount = 1;
4256 VkAttachmentDescription attach_desc = {};
4257 attach_desc.format = VK_FORMAT_B8G8R8A8_UNORM;
4258 attach_desc.samples = VK_SAMPLE_COUNT_1_BIT;
4259 rpci.pAttachments = &attach_desc;
4260 rpci.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
4261 VkRenderPass rp;
4262 subpass.pDepthStencilAttachment = &attach;
4263 subpass.pColorAttachments = NULL;
4264 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
4265 m_errorMonitor->VerifyFound();
4266}
4267
Chris Forbes6b3d3f42016-06-30 16:09:47 +12004268TEST_F(VkLayerTest, RenderPassTransitionsAttachmentUnused) {
4269 TEST_DESCRIPTION("Ensure that layout transitions work correctly without "
4270 "errors, when an attachment reference is "
4271 "VK_ATTACHMENT_UNUSED");
4272
4273 m_errorMonitor->ExpectSuccess();
4274
4275 ASSERT_NO_FATAL_FAILURE(InitState());
4276
4277 // A renderpass with no attachments
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004278 VkAttachmentReference att_ref = {VK_ATTACHMENT_UNUSED, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL};
Chris Forbes6b3d3f42016-06-30 16:09:47 +12004279
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004280 VkSubpassDescription subpass = {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 1, &att_ref, nullptr, nullptr, 0, nullptr};
Chris Forbes6b3d3f42016-06-30 16:09:47 +12004281
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004282 VkRenderPassCreateInfo rpci = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 0, nullptr, 1, &subpass, 0, nullptr};
Chris Forbes6b3d3f42016-06-30 16:09:47 +12004283
4284 VkRenderPass rp;
4285 VkResult err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
4286 ASSERT_VK_SUCCESS(err);
4287
4288 // A compatible framebuffer.
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004289 VkFramebufferCreateInfo fci = {VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr, 0, rp, 0, nullptr, 32, 32, 1};
Chris Forbes6b3d3f42016-06-30 16:09:47 +12004290 VkFramebuffer fb;
4291 err = vkCreateFramebuffer(m_device->device(), &fci, nullptr, &fb);
4292 ASSERT_VK_SUCCESS(err);
4293
4294 // Record a command buffer which just begins and ends the renderpass. The
4295 // bug manifests in BeginRenderPass.
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004296 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 +12004297 BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004298 vkCmdBeginRenderPass(m_commandBuffer->handle(), &rpbi, VK_SUBPASS_CONTENTS_INLINE);
Chris Forbes6b3d3f42016-06-30 16:09:47 +12004299 vkCmdEndRenderPass(m_commandBuffer->handle());
4300 m_errorMonitor->VerifyNotFound();
4301 EndCommandBuffer();
4302
4303 vkDestroyFramebuffer(m_device->device(), fb, nullptr);
4304 vkDestroyRenderPass(m_device->device(), rp, nullptr);
4305}
4306
Mark Lobodzinskice7eee72016-06-14 16:33:29 -06004307// This is a positive test. No errors are expected.
4308TEST_F(VkLayerTest, StencilLoadOp) {
4309 TEST_DESCRIPTION("Create a stencil-only attachment with a LOAD_OP set to "
4310 "CLEAR. stencil[Load|Store]Op used to be ignored.");
4311 VkResult result = VK_SUCCESS;
4312 VkImageFormatProperties formatProps;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004313 vkGetPhysicalDeviceImageFormatProperties(gpu(), VK_FORMAT_D24_UNORM_S8_UINT, VK_IMAGE_TYPE_2D, VK_IMAGE_TILING_OPTIMAL,
4314 VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_SRC_BIT, 0,
4315 &formatProps);
Mark Lobodzinskice7eee72016-06-14 16:33:29 -06004316 if (formatProps.maxExtent.width < 100 || formatProps.maxExtent.height < 100) {
4317 return;
4318 }
4319
4320 ASSERT_NO_FATAL_FAILURE(InitState());
4321 VkFormat depth_stencil_fmt = VK_FORMAT_D24_UNORM_S8_UINT;
4322 m_depthStencil->Init(m_device, 100, 100, depth_stencil_fmt,
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004323 VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_SRC_BIT);
Mark Lobodzinskice7eee72016-06-14 16:33:29 -06004324 VkAttachmentDescription att = {};
4325 VkAttachmentReference ref = {};
4326 att.format = depth_stencil_fmt;
4327 att.loadOp = VK_ATTACHMENT_LOAD_OP_DONT_CARE;
4328 att.storeOp = VK_ATTACHMENT_STORE_OP_DONT_CARE;
4329 att.stencilLoadOp = VK_ATTACHMENT_LOAD_OP_CLEAR;
4330 att.stencilStoreOp = VK_ATTACHMENT_STORE_OP_STORE;
4331 att.initialLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
4332 att.finalLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
4333
4334 VkClearValue clear;
4335 clear.depthStencil.depth = 1.0;
4336 clear.depthStencil.stencil = 0;
4337 ref.attachment = 0;
4338 ref.layout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
4339
4340 VkSubpassDescription subpass = {};
4341 subpass.pipelineBindPoint = VK_PIPELINE_BIND_POINT_GRAPHICS;
4342 subpass.flags = 0;
4343 subpass.inputAttachmentCount = 0;
4344 subpass.pInputAttachments = NULL;
4345 subpass.colorAttachmentCount = 0;
4346 subpass.pColorAttachments = NULL;
4347 subpass.pResolveAttachments = NULL;
4348 subpass.pDepthStencilAttachment = &ref;
4349 subpass.preserveAttachmentCount = 0;
4350 subpass.pPreserveAttachments = NULL;
4351
4352 VkRenderPass rp;
4353 VkRenderPassCreateInfo rp_info = {};
4354 rp_info.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
4355 rp_info.attachmentCount = 1;
4356 rp_info.pAttachments = &att;
4357 rp_info.subpassCount = 1;
4358 rp_info.pSubpasses = &subpass;
4359 result = vkCreateRenderPass(device(), &rp_info, NULL, &rp);
4360 ASSERT_VK_SUCCESS(result);
4361
4362 VkImageView *depthView = m_depthStencil->BindInfo();
4363 VkFramebufferCreateInfo fb_info = {};
4364 fb_info.sType = VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO;
4365 fb_info.pNext = NULL;
4366 fb_info.renderPass = rp;
4367 fb_info.attachmentCount = 1;
4368 fb_info.pAttachments = depthView;
4369 fb_info.width = 100;
4370 fb_info.height = 100;
4371 fb_info.layers = 1;
4372 VkFramebuffer fb;
4373 result = vkCreateFramebuffer(device(), &fb_info, NULL, &fb);
4374 ASSERT_VK_SUCCESS(result);
4375
Mark Lobodzinskice7eee72016-06-14 16:33:29 -06004376 VkRenderPassBeginInfo rpbinfo = {};
4377 rpbinfo.clearValueCount = 1;
4378 rpbinfo.pClearValues = &clear;
4379 rpbinfo.pNext = NULL;
4380 rpbinfo.renderPass = rp;
4381 rpbinfo.sType = VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO;
4382 rpbinfo.renderArea.extent.width = 100;
4383 rpbinfo.renderArea.extent.height = 100;
4384 rpbinfo.renderArea.offset.x = 0;
4385 rpbinfo.renderArea.offset.y = 0;
4386 rpbinfo.framebuffer = fb;
4387
4388 VkFence fence = {};
4389 VkFenceCreateInfo fence_ci = {};
4390 fence_ci.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
4391 fence_ci.pNext = nullptr;
4392 fence_ci.flags = 0;
4393 result = vkCreateFence(m_device->device(), &fence_ci, nullptr, &fence);
4394 ASSERT_VK_SUCCESS(result);
4395
Mark Lobodzinskice7eee72016-06-14 16:33:29 -06004396 m_commandBuffer->BeginCommandBuffer();
4397 m_commandBuffer->BeginRenderPass(rpbinfo);
4398 m_commandBuffer->EndRenderPass();
4399 m_commandBuffer->EndCommandBuffer();
4400 m_commandBuffer->QueueCommandBuffer(fence);
4401
4402 VkImageObj destImage(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004403 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 -06004404 VK_IMAGE_TILING_OPTIMAL, 0);
4405 VkImageMemoryBarrier barrier = {};
4406 VkImageSubresourceRange range;
4407 barrier.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004408 barrier.srcAccessMask = VK_ACCESS_TRANSFER_WRITE_BIT | VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_WRITE_BIT;
4409 barrier.dstAccessMask = VK_ACCESS_TRANSFER_READ_BIT | VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_READ_BIT;
Mark Lobodzinskice7eee72016-06-14 16:33:29 -06004410 barrier.oldLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
4411 barrier.newLayout = VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL;
4412 barrier.image = m_depthStencil->handle();
4413 range.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT;
4414 range.baseMipLevel = 0;
4415 range.levelCount = 1;
4416 range.baseArrayLayer = 0;
4417 range.layerCount = 1;
4418 barrier.subresourceRange = range;
4419 vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
4420 VkCommandBufferObj cmdbuf(m_device, m_commandPool);
4421 cmdbuf.BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004422 cmdbuf.PipelineBarrier(VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0, nullptr, 0, nullptr, 1,
4423 &barrier);
Mark Lobodzinskice7eee72016-06-14 16:33:29 -06004424 barrier.srcAccessMask = 0;
4425 barrier.oldLayout = VK_IMAGE_LAYOUT_UNDEFINED;
4426 barrier.newLayout = VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL;
4427 barrier.image = destImage.handle();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004428 barrier.dstAccessMask = VK_ACCESS_TRANSFER_WRITE_BIT | VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_WRITE_BIT;
4429 cmdbuf.PipelineBarrier(VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0, nullptr, 0, nullptr, 1,
4430 &barrier);
Mark Lobodzinskice7eee72016-06-14 16:33:29 -06004431 VkImageCopy cregion;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004432 cregion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT;
Mark Lobodzinskice7eee72016-06-14 16:33:29 -06004433 cregion.srcSubresource.mipLevel = 0;
4434 cregion.srcSubresource.baseArrayLayer = 0;
4435 cregion.srcSubresource.layerCount = 1;
4436 cregion.srcOffset.x = 0;
4437 cregion.srcOffset.y = 0;
4438 cregion.srcOffset.z = 0;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004439 cregion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT;
Mark Lobodzinskice7eee72016-06-14 16:33:29 -06004440 cregion.dstSubresource.mipLevel = 0;
4441 cregion.dstSubresource.baseArrayLayer = 0;
4442 cregion.dstSubresource.layerCount = 1;
4443 cregion.dstOffset.x = 0;
4444 cregion.dstOffset.y = 0;
4445 cregion.dstOffset.z = 0;
4446 cregion.extent.width = 100;
4447 cregion.extent.height = 100;
4448 cregion.extent.depth = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004449 cmdbuf.CopyImage(m_depthStencil->handle(), VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL, destImage.handle(),
Mark Lobodzinskice7eee72016-06-14 16:33:29 -06004450 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, &cregion);
4451 cmdbuf.EndCommandBuffer();
4452
4453 VkSubmitInfo submit_info;
4454 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
4455 submit_info.pNext = NULL;
4456 submit_info.waitSemaphoreCount = 0;
4457 submit_info.pWaitSemaphores = NULL;
4458 submit_info.pWaitDstStageMask = NULL;
4459 submit_info.commandBufferCount = 1;
4460 submit_info.pCommandBuffers = &cmdbuf.handle();
4461 submit_info.signalSemaphoreCount = 0;
4462 submit_info.pSignalSemaphores = NULL;
4463
4464 m_errorMonitor->ExpectSuccess();
4465 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
4466 m_errorMonitor->VerifyNotFound();
4467
Mark Lobodzinskid0440da2016-06-17 15:10:03 -06004468 vkQueueWaitIdle(m_device->m_queue);
Mark Lobodzinskice7eee72016-06-14 16:33:29 -06004469 vkDestroyFence(m_device->device(), fence, nullptr);
4470 vkDestroyRenderPass(m_device->device(), rp, nullptr);
4471 vkDestroyFramebuffer(m_device->device(), fb, nullptr);
4472}
4473
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06004474TEST_F(VkLayerTest, UnusedPreserveAttachment) {
4475 TEST_DESCRIPTION("Create a framebuffer where a subpass has a preserve "
4476 "attachment reference of VK_ATTACHMENT_UNUSED");
4477
4478 ASSERT_NO_FATAL_FAILURE(InitState());
4479 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
4480
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004481 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "must not be VK_ATTACHMENT_UNUSED");
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06004482
4483 VkAttachmentReference color_attach = {};
4484 color_attach.layout = VK_IMAGE_LAYOUT_GENERAL;
4485 color_attach.attachment = 0;
4486 uint32_t preserve_attachment = VK_ATTACHMENT_UNUSED;
4487 VkSubpassDescription subpass = {};
4488 subpass.colorAttachmentCount = 1;
4489 subpass.pColorAttachments = &color_attach;
4490 subpass.preserveAttachmentCount = 1;
4491 subpass.pPreserveAttachments = &preserve_attachment;
4492
4493 VkRenderPassCreateInfo rpci = {};
4494 rpci.subpassCount = 1;
4495 rpci.pSubpasses = &subpass;
4496 rpci.attachmentCount = 1;
4497 VkAttachmentDescription attach_desc = {};
4498 attach_desc.format = VK_FORMAT_UNDEFINED;
4499 rpci.pAttachments = &attach_desc;
4500 rpci.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
4501 VkRenderPass rp;
Mark Lobodzinskia4feeeb2016-06-17 12:00:46 -06004502 VkResult result = vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06004503
4504 m_errorMonitor->VerifyFound();
4505
Mark Lobodzinskia4feeeb2016-06-17 12:00:46 -06004506 if (result == VK_SUCCESS) {
4507 vkDestroyRenderPass(m_device->device(), rp, NULL);
4508 }
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06004509}
4510
Chris Forbesc5389742016-06-29 11:49:23 +12004511TEST_F(VkLayerTest, CreateRenderPassResolveRequiresColorMsaa) {
Chris Forbes6655bb32016-07-01 18:27:30 +12004512 TEST_DESCRIPTION("Ensure that CreateRenderPass produces a validation error "
4513 "when the source of a subpass multisample resolve "
4514 "does not have multiple samples.");
4515
Chris Forbesc5389742016-06-29 11:49:23 +12004516 ASSERT_NO_FATAL_FAILURE(InitState());
4517
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004518 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
4519 "Subpass 0 requests multisample resolve from attachment 0 which has "
4520 "VK_SAMPLE_COUNT_1_BIT");
Chris Forbesc5389742016-06-29 11:49:23 +12004521
4522 VkAttachmentDescription attachments[] = {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004523 {0, VK_FORMAT_R8G8B8A8_UNORM, VK_SAMPLE_COUNT_1_BIT, VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE,
4524 VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
4525 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL},
4526 {0, VK_FORMAT_R8G8B8A8_UNORM, VK_SAMPLE_COUNT_1_BIT, VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE,
4527 VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
4528 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL},
Chris Forbesc5389742016-06-29 11:49:23 +12004529 };
4530
4531 VkAttachmentReference color = {
4532 0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
4533 };
4534
4535 VkAttachmentReference resolve = {
4536 0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
4537 };
4538
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004539 VkSubpassDescription subpass = {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 1, &color, &resolve, nullptr, 0, nullptr};
Chris Forbesc5389742016-06-29 11:49:23 +12004540
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004541 VkRenderPassCreateInfo rpci = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 2, attachments, 1, &subpass, 0, nullptr};
Chris Forbesc5389742016-06-29 11:49:23 +12004542
4543 VkRenderPass rp;
4544 VkResult err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
4545
4546 m_errorMonitor->VerifyFound();
4547
4548 if (err == VK_SUCCESS)
4549 vkDestroyRenderPass(m_device->device(), rp, nullptr);
4550}
4551
4552TEST_F(VkLayerTest, CreateRenderPassResolveRequiresSingleSampleDest) {
Chris Forbes6655bb32016-07-01 18:27:30 +12004553 TEST_DESCRIPTION("Ensure CreateRenderPass produces a validation error "
4554 "when a subpass multisample resolve operation is "
4555 "requested, and the destination of that resolve has "
4556 "multiple samples.");
4557
Chris Forbesc5389742016-06-29 11:49:23 +12004558 ASSERT_NO_FATAL_FAILURE(InitState());
4559
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004560 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
4561 "Subpass 0 requests multisample resolve into attachment 1, which "
4562 "must have VK_SAMPLE_COUNT_1_BIT but has VK_SAMPLE_COUNT_4_BIT");
Chris Forbesc5389742016-06-29 11:49:23 +12004563
4564 VkAttachmentDescription attachments[] = {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004565 {0, VK_FORMAT_R8G8B8A8_UNORM, VK_SAMPLE_COUNT_4_BIT, VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE,
4566 VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
4567 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL},
4568 {0, VK_FORMAT_R8G8B8A8_UNORM, VK_SAMPLE_COUNT_4_BIT, VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE,
4569 VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
4570 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL},
Chris Forbesc5389742016-06-29 11:49:23 +12004571 };
4572
4573 VkAttachmentReference color = {
4574 0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
4575 };
4576
4577 VkAttachmentReference resolve = {
4578 1, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
4579 };
4580
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004581 VkSubpassDescription subpass = {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 1, &color, &resolve, nullptr, 0, nullptr};
Chris Forbesc5389742016-06-29 11:49:23 +12004582
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004583 VkRenderPassCreateInfo rpci = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 2, attachments, 1, &subpass, 0, nullptr};
Chris Forbesc5389742016-06-29 11:49:23 +12004584
4585 VkRenderPass rp;
4586 VkResult err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
4587
4588 m_errorMonitor->VerifyFound();
4589
4590 if (err == VK_SUCCESS)
4591 vkDestroyRenderPass(m_device->device(), rp, nullptr);
4592}
4593
Chris Forbes3f128ef2016-06-29 14:58:53 +12004594TEST_F(VkLayerTest, CreateRenderPassSubpassSampleCountConsistency) {
Chris Forbes6655bb32016-07-01 18:27:30 +12004595 TEST_DESCRIPTION("Ensure CreateRenderPass produces a validation error "
4596 "when the color and depth attachments used by a subpass "
4597 "have inconsistent sample counts");
4598
Chris Forbes3f128ef2016-06-29 14:58:53 +12004599 ASSERT_NO_FATAL_FAILURE(InitState());
4600
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004601 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
4602 "Subpass 0 attempts to render to attachments with inconsistent sample counts");
Chris Forbes3f128ef2016-06-29 14:58:53 +12004603
4604 VkAttachmentDescription attachments[] = {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004605 {0, VK_FORMAT_R8G8B8A8_UNORM, VK_SAMPLE_COUNT_1_BIT, VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE,
4606 VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
4607 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL},
4608 {0, VK_FORMAT_R8G8B8A8_UNORM, VK_SAMPLE_COUNT_4_BIT, VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE,
4609 VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
4610 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL},
Chris Forbes3f128ef2016-06-29 14:58:53 +12004611 };
4612
4613 VkAttachmentReference color[] = {
4614 {
4615 0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
4616 },
4617 {
4618 1, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
4619 },
4620 };
4621
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004622 VkSubpassDescription subpass = {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 2, color, nullptr, nullptr, 0, nullptr};
Chris Forbes3f128ef2016-06-29 14:58:53 +12004623
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004624 VkRenderPassCreateInfo rpci = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 2, attachments, 1, &subpass, 0, nullptr};
Chris Forbes3f128ef2016-06-29 14:58:53 +12004625
4626 VkRenderPass rp;
4627 VkResult err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
4628
4629 m_errorMonitor->VerifyFound();
4630
4631 if (err == VK_SUCCESS)
4632 vkDestroyRenderPass(m_device->device(), rp, nullptr);
4633}
4634
Tobin Ehlis2545e6f2016-06-22 10:42:19 -06004635TEST_F(VkLayerTest, FramebufferCreateErrors) {
4636 TEST_DESCRIPTION("Hit errors when attempting to create a framebuffer :\n"
4637 " 1. Mismatch between fb & renderPass attachmentCount\n"
Tobin Ehlisd3bb23a2016-06-22 13:34:46 -06004638 " 2. Use a color image as depthStencil attachment\n"
Tobin Ehlis77d717c2016-06-22 14:19:19 -06004639 " 3. Mismatch fb & renderPass attachment formats\n"
Tobin Ehlis6cfda642016-06-22 16:12:58 -06004640 " 4. Mismatch fb & renderPass attachment #samples\n"
Tobin Ehlis27f2ae82016-06-23 07:36:57 -06004641 " 5. FB attachment w/ non-1 mip-levels\n"
Tobin Ehlisb1f303b2016-06-23 08:19:55 -06004642 " 6. FB attachment where dimensions don't match\n"
Tobin Ehlis08d4b5e2016-06-23 08:52:39 -06004643 " 7. FB attachment w/o identity swizzle\n"
4644 " 8. FB dimensions exceed physical device limits\n");
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06004645
4646 ASSERT_NO_FATAL_FAILURE(InitState());
4647 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
4648
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004649 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
4650 "vkCreateFramebuffer(): VkFramebufferCreateInfo attachmentCount of 2 "
4651 "does not match attachmentCount of 1 of ");
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06004652
Tobin Ehlis2545e6f2016-06-22 10:42:19 -06004653 // Create a renderPass with a single color attachment
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06004654 VkAttachmentReference attach = {};
4655 attach.layout = VK_IMAGE_LAYOUT_GENERAL;
4656 VkSubpassDescription subpass = {};
Tobin Ehlis2545e6f2016-06-22 10:42:19 -06004657 subpass.pColorAttachments = &attach;
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06004658 VkRenderPassCreateInfo rpci = {};
4659 rpci.subpassCount = 1;
4660 rpci.pSubpasses = &subpass;
4661 rpci.attachmentCount = 1;
4662 VkAttachmentDescription attach_desc = {};
Tobin Ehlisd3bb23a2016-06-22 13:34:46 -06004663 attach_desc.format = VK_FORMAT_B8G8R8A8_UNORM;
Tobin Ehlis77d717c2016-06-22 14:19:19 -06004664 attach_desc.samples = VK_SAMPLE_COUNT_1_BIT;
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06004665 rpci.pAttachments = &attach_desc;
4666 rpci.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
4667 VkRenderPass rp;
4668 VkResult err = vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
4669 ASSERT_VK_SUCCESS(err);
4670
Tobin Ehlis2545e6f2016-06-22 10:42:19 -06004671 VkImageView ivs[2];
4672 ivs[0] = m_renderTargets[0]->targetView(VK_FORMAT_B8G8R8A8_UNORM);
4673 ivs[1] = m_renderTargets[0]->targetView(VK_FORMAT_B8G8R8A8_UNORM);
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06004674 VkFramebufferCreateInfo fb_info = {};
4675 fb_info.sType = VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO;
4676 fb_info.pNext = NULL;
4677 fb_info.renderPass = rp;
Tobin Ehlis2545e6f2016-06-22 10:42:19 -06004678 // Set mis-matching attachmentCount
4679 fb_info.attachmentCount = 2;
4680 fb_info.pAttachments = ivs;
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06004681 fb_info.width = 100;
4682 fb_info.height = 100;
4683 fb_info.layers = 1;
4684
4685 VkFramebuffer fb;
4686 err = vkCreateFramebuffer(device(), &fb_info, NULL, &fb);
4687
4688 m_errorMonitor->VerifyFound();
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06004689 if (err == VK_SUCCESS) {
4690 vkDestroyFramebuffer(m_device->device(), fb, NULL);
4691 }
4692 vkDestroyRenderPass(m_device->device(), rp, NULL);
Tobin Ehlis2545e6f2016-06-22 10:42:19 -06004693
4694 // Create a renderPass with a depth-stencil attachment created with
4695 // IMAGE_USAGE_COLOR_ATTACHMENT
4696 // Add our color attachment to pDepthStencilAttachment
4697 subpass.pDepthStencilAttachment = &attach;
4698 subpass.pColorAttachments = NULL;
4699 VkRenderPass rp_ds;
4700 err = vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp_ds);
4701 ASSERT_VK_SUCCESS(err);
4702 // Set correct attachment count, but attachment has COLOR usage bit set
4703 fb_info.attachmentCount = 1;
4704 fb_info.renderPass = rp_ds;
4705
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004706 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " conflicts with the image's IMAGE_USAGE flags ");
Tobin Ehlis2545e6f2016-06-22 10:42:19 -06004707 err = vkCreateFramebuffer(device(), &fb_info, NULL, &fb);
4708
4709 m_errorMonitor->VerifyFound();
4710 if (err == VK_SUCCESS) {
4711 vkDestroyFramebuffer(m_device->device(), fb, NULL);
4712 }
4713 vkDestroyRenderPass(m_device->device(), rp_ds, NULL);
Tobin Ehlisd3bb23a2016-06-22 13:34:46 -06004714
4715 // Create new renderpass with alternate attachment format from fb
4716 attach_desc.format = VK_FORMAT_R8G8B8A8_UNORM;
4717 subpass.pDepthStencilAttachment = NULL;
4718 subpass.pColorAttachments = &attach;
4719 err = vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
4720 ASSERT_VK_SUCCESS(err);
4721
4722 // Cause error due to mis-matched formats between rp & fb
4723 // rp attachment 0 now has RGBA8 but corresponding fb attach is BGRA8
4724 fb_info.renderPass = rp;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004725 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
4726 " has format of VK_FORMAT_B8G8R8A8_UNORM that does not match ");
Tobin Ehlisd3bb23a2016-06-22 13:34:46 -06004727 err = vkCreateFramebuffer(device(), &fb_info, NULL, &fb);
4728
4729 m_errorMonitor->VerifyFound();
4730 if (err == VK_SUCCESS) {
4731 vkDestroyFramebuffer(m_device->device(), fb, NULL);
4732 }
Tobin Ehlis77d717c2016-06-22 14:19:19 -06004733 vkDestroyRenderPass(m_device->device(), rp, NULL);
4734
4735 // Create new renderpass with alternate sample count from fb
4736 attach_desc.format = VK_FORMAT_B8G8R8A8_UNORM;
4737 attach_desc.samples = VK_SAMPLE_COUNT_4_BIT;
4738 err = vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
4739 ASSERT_VK_SUCCESS(err);
4740
4741 // Cause error due to mis-matched sample count between rp & fb
4742 fb_info.renderPass = rp;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004743 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " has VK_SAMPLE_COUNT_1_BIT samples "
4744 "that do not match the "
4745 "VK_SAMPLE_COUNT_4_BIT ");
Tobin Ehlis77d717c2016-06-22 14:19:19 -06004746 err = vkCreateFramebuffer(device(), &fb_info, NULL, &fb);
4747
4748 m_errorMonitor->VerifyFound();
4749 if (err == VK_SUCCESS) {
4750 vkDestroyFramebuffer(m_device->device(), fb, NULL);
4751 }
Tobin Ehlisd3bb23a2016-06-22 13:34:46 -06004752
4753 vkDestroyRenderPass(m_device->device(), rp, NULL);
Tobin Ehlis6cfda642016-06-22 16:12:58 -06004754
4755 // Create a custom imageView with non-1 mip levels
4756 VkImageObj image(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004757 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 -06004758 ASSERT_TRUE(image.initialized());
4759
4760 VkImageView view;
4761 VkImageViewCreateInfo ivci = {};
4762 ivci.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
4763 ivci.image = image.handle();
4764 ivci.viewType = VK_IMAGE_VIEW_TYPE_2D;
4765 ivci.format = VK_FORMAT_B8G8R8A8_UNORM;
4766 ivci.subresourceRange.layerCount = 1;
4767 ivci.subresourceRange.baseMipLevel = 0;
4768 // Set level count 2 (only 1 is allowed for FB attachment)
4769 ivci.subresourceRange.levelCount = 2;
4770 ivci.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
4771 err = vkCreateImageView(m_device->device(), &ivci, NULL, &view);
4772 ASSERT_VK_SUCCESS(err);
4773 // Re-create renderpass to have matching sample count
4774 attach_desc.samples = VK_SAMPLE_COUNT_1_BIT;
4775 err = vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
4776 ASSERT_VK_SUCCESS(err);
4777
4778 fb_info.renderPass = rp;
4779 fb_info.pAttachments = &view;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004780 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " has mip levelCount of 2 but only ");
Tobin Ehlis6cfda642016-06-22 16:12:58 -06004781 err = vkCreateFramebuffer(device(), &fb_info, NULL, &fb);
4782
4783 m_errorMonitor->VerifyFound();
4784 if (err == VK_SUCCESS) {
4785 vkDestroyFramebuffer(m_device->device(), fb, NULL);
4786 }
Tobin Ehlis6cfda642016-06-22 16:12:58 -06004787 vkDestroyImageView(m_device->device(), view, NULL);
Tobin Ehlis27f2ae82016-06-23 07:36:57 -06004788 // Update view to original color buffer and grow FB dimensions too big
4789 fb_info.pAttachments = ivs;
4790 fb_info.height = 1024;
4791 fb_info.width = 1024;
4792 fb_info.layers = 2;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004793 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " Attachment dimensions must be at "
4794 "least as large. ");
Tobin Ehlis27f2ae82016-06-23 07:36:57 -06004795 err = vkCreateFramebuffer(device(), &fb_info, NULL, &fb);
4796
4797 m_errorMonitor->VerifyFound();
4798 if (err == VK_SUCCESS) {
4799 vkDestroyFramebuffer(m_device->device(), fb, NULL);
4800 }
Tobin Ehlisb1f303b2016-06-23 08:19:55 -06004801 // Create view attachment with non-identity swizzle
4802 ivci.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
4803 ivci.image = image.handle();
4804 ivci.viewType = VK_IMAGE_VIEW_TYPE_2D;
4805 ivci.format = VK_FORMAT_B8G8R8A8_UNORM;
4806 ivci.subresourceRange.layerCount = 1;
4807 ivci.subresourceRange.baseMipLevel = 0;
4808 ivci.subresourceRange.levelCount = 1;
4809 ivci.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
4810 ivci.components.r = VK_COMPONENT_SWIZZLE_G;
4811 ivci.components.g = VK_COMPONENT_SWIZZLE_R;
4812 ivci.components.b = VK_COMPONENT_SWIZZLE_A;
4813 ivci.components.a = VK_COMPONENT_SWIZZLE_B;
4814 err = vkCreateImageView(m_device->device(), &ivci, NULL, &view);
4815 ASSERT_VK_SUCCESS(err);
4816
4817 fb_info.pAttachments = &view;
4818 fb_info.height = 100;
4819 fb_info.width = 100;
4820 fb_info.layers = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004821 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " has non-identy swizzle. All "
4822 "framebuffer attachments must have "
4823 "been created with the identity "
4824 "swizzle. ");
Tobin Ehlisb1f303b2016-06-23 08:19:55 -06004825 err = vkCreateFramebuffer(device(), &fb_info, NULL, &fb);
4826
4827 m_errorMonitor->VerifyFound();
4828 if (err == VK_SUCCESS) {
4829 vkDestroyFramebuffer(m_device->device(), fb, NULL);
4830 }
4831 vkDestroyImageView(m_device->device(), view, NULL);
Tobin Ehlis08d4b5e2016-06-23 08:52:39 -06004832 // Request fb that exceeds max dimensions
4833 // reset attachment to color attachment
4834 fb_info.pAttachments = ivs;
4835 fb_info.width = m_device->props.limits.maxFramebufferWidth + 1;
4836 fb_info.height = m_device->props.limits.maxFramebufferHeight + 1;
4837 fb_info.layers = m_device->props.limits.maxFramebufferLayers + 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004838 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " Requested VkFramebufferCreateInfo "
4839 "dimensions exceed physical device "
4840 "limits. ");
Tobin Ehlis08d4b5e2016-06-23 08:52:39 -06004841 err = vkCreateFramebuffer(device(), &fb_info, NULL, &fb);
4842
4843 m_errorMonitor->VerifyFound();
4844 if (err == VK_SUCCESS) {
4845 vkDestroyFramebuffer(m_device->device(), fb, NULL);
4846 }
Tobin Ehlis27f2ae82016-06-23 07:36:57 -06004847
Tobin Ehlis6cfda642016-06-22 16:12:58 -06004848 vkDestroyRenderPass(m_device->device(), rp, NULL);
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06004849}
4850
Mark Lobodzinskic808d442016-04-14 10:57:23 -06004851// This is a positive test. No errors should be generated.
Michael Lentine860b0fe2016-05-20 10:14:00 -05004852TEST_F(VkLayerTest, WaitEventThenSet) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004853 TEST_DESCRIPTION("Wait on a event then set it after the wait has been submitted.");
Michael Lentine860b0fe2016-05-20 10:14:00 -05004854
Michael Lentine860b0fe2016-05-20 10:14:00 -05004855 m_errorMonitor->ExpectSuccess();
Cody Northropc31a84f2016-08-22 10:41:47 -06004856 ASSERT_NO_FATAL_FAILURE(InitState());
Michael Lentine860b0fe2016-05-20 10:14:00 -05004857
4858 VkEvent event;
4859 VkEventCreateInfo event_create_info{};
4860 event_create_info.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO;
4861 vkCreateEvent(m_device->device(), &event_create_info, nullptr, &event);
4862
4863 VkCommandPool command_pool;
4864 VkCommandPoolCreateInfo pool_create_info{};
4865 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
4866 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
4867 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004868 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
Michael Lentine860b0fe2016-05-20 10:14:00 -05004869
4870 VkCommandBuffer command_buffer;
4871 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004872 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
Michael Lentine860b0fe2016-05-20 10:14:00 -05004873 command_buffer_allocate_info.commandPool = command_pool;
4874 command_buffer_allocate_info.commandBufferCount = 1;
4875 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004876 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, &command_buffer);
Michael Lentine860b0fe2016-05-20 10:14:00 -05004877
4878 VkQueue queue = VK_NULL_HANDLE;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004879 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 0, &queue);
Michael Lentine860b0fe2016-05-20 10:14:00 -05004880
4881 {
4882 VkCommandBufferBeginInfo begin_info{};
4883 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
4884 vkBeginCommandBuffer(command_buffer, &begin_info);
4885
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004886 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 -05004887 nullptr, 0, nullptr);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004888 vkCmdResetEvent(command_buffer, event, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT);
Michael Lentine860b0fe2016-05-20 10:14:00 -05004889 vkEndCommandBuffer(command_buffer);
4890 }
4891 {
4892 VkSubmitInfo submit_info{};
4893 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
4894 submit_info.commandBufferCount = 1;
4895 submit_info.pCommandBuffers = &command_buffer;
4896 submit_info.signalSemaphoreCount = 0;
4897 submit_info.pSignalSemaphores = nullptr;
4898 vkQueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE);
4899 }
4900 { vkSetEvent(m_device->device(), event); }
4901
4902 vkQueueWaitIdle(queue);
4903
4904 vkDestroyEvent(m_device->device(), event, nullptr);
4905 vkFreeCommandBuffers(m_device->device(), command_pool, 1, &command_buffer);
4906 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
4907
4908 m_errorMonitor->VerifyNotFound();
4909}
Michael Lentine5627e692016-05-20 17:45:02 -05004910// This is a positive test. No errors should be generated.
Michael Lentinef01fb382016-07-21 17:24:56 -05004911TEST_F(VkLayerTest, QueryAndCopySecondaryCommandBuffers) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004912 TEST_DESCRIPTION("Issue a query on a secondary command buffery and copy it on a primary.");
Michael Lentinef01fb382016-07-21 17:24:56 -05004913
Cody Northropc31a84f2016-08-22 10:41:47 -06004914 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004915 if ((m_device->queue_props.empty()) || (m_device->queue_props[0].queueCount < 2))
Michael Lentinef01fb382016-07-21 17:24:56 -05004916 return;
4917
4918 m_errorMonitor->ExpectSuccess();
4919
4920 VkQueryPool query_pool;
4921 VkQueryPoolCreateInfo query_pool_create_info{};
4922 query_pool_create_info.sType = VK_STRUCTURE_TYPE_QUERY_POOL_CREATE_INFO;
4923 query_pool_create_info.queryType = VK_QUERY_TYPE_TIMESTAMP;
4924 query_pool_create_info.queryCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004925 vkCreateQueryPool(m_device->device(), &query_pool_create_info, nullptr, &query_pool);
Michael Lentinef01fb382016-07-21 17:24:56 -05004926
4927 VkCommandPool command_pool;
4928 VkCommandPoolCreateInfo pool_create_info{};
4929 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
4930 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
4931 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004932 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
Michael Lentinef01fb382016-07-21 17:24:56 -05004933
4934 VkCommandBuffer command_buffer;
4935 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004936 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
Michael Lentinef01fb382016-07-21 17:24:56 -05004937 command_buffer_allocate_info.commandPool = command_pool;
4938 command_buffer_allocate_info.commandBufferCount = 1;
4939 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004940 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, &command_buffer);
Michael Lentinef01fb382016-07-21 17:24:56 -05004941
4942 VkCommandBuffer secondary_command_buffer;
4943 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_SECONDARY;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004944 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, &secondary_command_buffer);
Michael Lentinef01fb382016-07-21 17:24:56 -05004945
4946 VkQueue queue = VK_NULL_HANDLE;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004947 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 1, &queue);
Michael Lentinef01fb382016-07-21 17:24:56 -05004948
4949 uint32_t qfi = 0;
4950 VkBufferCreateInfo buff_create_info = {};
4951 buff_create_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
4952 buff_create_info.size = 1024;
4953 buff_create_info.usage = VK_BUFFER_USAGE_TRANSFER_DST_BIT;
4954 buff_create_info.queueFamilyIndexCount = 1;
4955 buff_create_info.pQueueFamilyIndices = &qfi;
4956
4957 VkResult err;
4958 VkBuffer buffer;
4959 err = vkCreateBuffer(m_device->device(), &buff_create_info, NULL, &buffer);
4960 ASSERT_VK_SUCCESS(err);
4961 VkMemoryAllocateInfo mem_alloc = {};
4962 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
4963 mem_alloc.pNext = NULL;
4964 mem_alloc.allocationSize = 1024;
4965 mem_alloc.memoryTypeIndex = 0;
4966
4967 VkMemoryRequirements memReqs;
4968 vkGetBufferMemoryRequirements(m_device->device(), buffer, &memReqs);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004969 bool pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &mem_alloc, 0);
Michael Lentinef01fb382016-07-21 17:24:56 -05004970 if (!pass) {
4971 vkDestroyBuffer(m_device->device(), buffer, NULL);
4972 return;
4973 }
4974
4975 VkDeviceMemory mem;
4976 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem);
4977 ASSERT_VK_SUCCESS(err);
4978 err = vkBindBufferMemory(m_device->device(), buffer, mem, 0);
4979 ASSERT_VK_SUCCESS(err);
4980
4981 VkCommandBufferInheritanceInfo hinfo = {};
4982 hinfo.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_INHERITANCE_INFO;
4983 hinfo.renderPass = VK_NULL_HANDLE;
4984 hinfo.subpass = 0;
4985 hinfo.framebuffer = VK_NULL_HANDLE;
4986 hinfo.occlusionQueryEnable = VK_FALSE;
4987 hinfo.queryFlags = 0;
4988 hinfo.pipelineStatistics = 0;
4989
4990 {
4991 VkCommandBufferBeginInfo begin_info{};
4992 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
4993 begin_info.pInheritanceInfo = &hinfo;
4994 vkBeginCommandBuffer(secondary_command_buffer, &begin_info);
4995
4996 vkCmdResetQueryPool(secondary_command_buffer, query_pool, 0, 1);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004997 vkCmdWriteTimestamp(secondary_command_buffer, VK_PIPELINE_STAGE_ALL_GRAPHICS_BIT, query_pool, 0);
Michael Lentinef01fb382016-07-21 17:24:56 -05004998
4999 vkEndCommandBuffer(secondary_command_buffer);
5000
5001 begin_info.pInheritanceInfo = nullptr;
5002 vkBeginCommandBuffer(command_buffer, &begin_info);
5003
5004 vkCmdExecuteCommands(command_buffer, 1, &secondary_command_buffer);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005005 vkCmdCopyQueryPoolResults(command_buffer, query_pool, 0, 1, buffer, 0, 0, 0);
Michael Lentinef01fb382016-07-21 17:24:56 -05005006
5007 vkEndCommandBuffer(command_buffer);
5008 }
5009 {
5010 VkSubmitInfo submit_info{};
5011 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
5012 submit_info.commandBufferCount = 1;
5013 submit_info.pCommandBuffers = &command_buffer;
5014 submit_info.signalSemaphoreCount = 0;
5015 submit_info.pSignalSemaphores = nullptr;
5016 vkQueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE);
5017 }
5018
5019 vkQueueWaitIdle(queue);
5020
5021 vkDestroyQueryPool(m_device->device(), query_pool, nullptr);
5022 vkFreeCommandBuffers(m_device->device(), command_pool, 1, &command_buffer);
5023 vkFreeCommandBuffers(m_device->device(), command_pool, 1, &secondary_command_buffer);
5024 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
5025 vkDestroyBuffer(m_device->device(), buffer, NULL);
5026 vkFreeMemory(m_device->device(), mem, NULL);
5027
5028 m_errorMonitor->VerifyNotFound();
5029}
5030
5031// This is a positive test. No errors should be generated.
Michael Lentine5627e692016-05-20 17:45:02 -05005032TEST_F(VkLayerTest, QueryAndCopyMultipleCommandBuffers) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005033 TEST_DESCRIPTION("Issue a query and copy from it on a second command buffer.");
Michael Lentine5627e692016-05-20 17:45:02 -05005034
Cody Northropc31a84f2016-08-22 10:41:47 -06005035 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005036 if ((m_device->queue_props.empty()) || (m_device->queue_props[0].queueCount < 2))
Michael Lentine5627e692016-05-20 17:45:02 -05005037 return;
5038
5039 m_errorMonitor->ExpectSuccess();
5040
5041 VkQueryPool query_pool;
5042 VkQueryPoolCreateInfo query_pool_create_info{};
5043 query_pool_create_info.sType = VK_STRUCTURE_TYPE_QUERY_POOL_CREATE_INFO;
5044 query_pool_create_info.queryType = VK_QUERY_TYPE_TIMESTAMP;
5045 query_pool_create_info.queryCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005046 vkCreateQueryPool(m_device->device(), &query_pool_create_info, nullptr, &query_pool);
Michael Lentine5627e692016-05-20 17:45:02 -05005047
5048 VkCommandPool command_pool;
5049 VkCommandPoolCreateInfo pool_create_info{};
5050 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
5051 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
5052 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005053 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
Michael Lentine5627e692016-05-20 17:45:02 -05005054
5055 VkCommandBuffer command_buffer[2];
5056 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005057 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
Michael Lentine5627e692016-05-20 17:45:02 -05005058 command_buffer_allocate_info.commandPool = command_pool;
5059 command_buffer_allocate_info.commandBufferCount = 2;
5060 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005061 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, command_buffer);
Michael Lentine5627e692016-05-20 17:45:02 -05005062
5063 VkQueue queue = VK_NULL_HANDLE;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005064 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 1, &queue);
Michael Lentine5627e692016-05-20 17:45:02 -05005065
5066 uint32_t qfi = 0;
5067 VkBufferCreateInfo buff_create_info = {};
5068 buff_create_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
5069 buff_create_info.size = 1024;
5070 buff_create_info.usage = VK_BUFFER_USAGE_TRANSFER_DST_BIT;
5071 buff_create_info.queueFamilyIndexCount = 1;
5072 buff_create_info.pQueueFamilyIndices = &qfi;
5073
5074 VkResult err;
5075 VkBuffer buffer;
5076 err = vkCreateBuffer(m_device->device(), &buff_create_info, NULL, &buffer);
5077 ASSERT_VK_SUCCESS(err);
5078 VkMemoryAllocateInfo mem_alloc = {};
5079 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
5080 mem_alloc.pNext = NULL;
5081 mem_alloc.allocationSize = 1024;
5082 mem_alloc.memoryTypeIndex = 0;
5083
5084 VkMemoryRequirements memReqs;
5085 vkGetBufferMemoryRequirements(m_device->device(), buffer, &memReqs);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005086 bool pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &mem_alloc, 0);
Michael Lentine5627e692016-05-20 17:45:02 -05005087 if (!pass) {
5088 vkDestroyBuffer(m_device->device(), buffer, NULL);
5089 return;
5090 }
5091
5092 VkDeviceMemory mem;
5093 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem);
5094 ASSERT_VK_SUCCESS(err);
5095 err = vkBindBufferMemory(m_device->device(), buffer, mem, 0);
5096 ASSERT_VK_SUCCESS(err);
5097
5098 {
5099 VkCommandBufferBeginInfo begin_info{};
5100 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
5101 vkBeginCommandBuffer(command_buffer[0], &begin_info);
5102
5103 vkCmdResetQueryPool(command_buffer[0], query_pool, 0, 1);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005104 vkCmdWriteTimestamp(command_buffer[0], VK_PIPELINE_STAGE_ALL_GRAPHICS_BIT, query_pool, 0);
Michael Lentine5627e692016-05-20 17:45:02 -05005105
5106 vkEndCommandBuffer(command_buffer[0]);
5107
5108 vkBeginCommandBuffer(command_buffer[1], &begin_info);
5109
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005110 vkCmdCopyQueryPoolResults(command_buffer[1], query_pool, 0, 1, buffer, 0, 0, 0);
Michael Lentine5627e692016-05-20 17:45:02 -05005111
5112 vkEndCommandBuffer(command_buffer[1]);
5113 }
5114 {
5115 VkSubmitInfo submit_info{};
5116 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
5117 submit_info.commandBufferCount = 2;
5118 submit_info.pCommandBuffers = command_buffer;
5119 submit_info.signalSemaphoreCount = 0;
5120 submit_info.pSignalSemaphores = nullptr;
5121 vkQueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE);
5122 }
5123
5124 vkQueueWaitIdle(queue);
5125
5126 vkDestroyQueryPool(m_device->device(), query_pool, nullptr);
5127 vkFreeCommandBuffers(m_device->device(), command_pool, 2, command_buffer);
5128 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
Tony Barbourdf4c0042016-06-01 15:55:43 -06005129 vkDestroyBuffer(m_device->device(), buffer, NULL);
5130 vkFreeMemory(m_device->device(), mem, NULL);
Michael Lentine5627e692016-05-20 17:45:02 -05005131
5132 m_errorMonitor->VerifyNotFound();
5133}
Michael Lentine860b0fe2016-05-20 10:14:00 -05005134
5135TEST_F(VkLayerTest, ResetEventThenSet) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005136 TEST_DESCRIPTION("Reset an event then set it after the reset has been submitted.");
Michael Lentine860b0fe2016-05-20 10:14:00 -05005137
Michael Lentine860b0fe2016-05-20 10:14:00 -05005138 m_errorMonitor->ExpectSuccess();
5139
Cody Northropc31a84f2016-08-22 10:41:47 -06005140 ASSERT_NO_FATAL_FAILURE(InitState());
Michael Lentine860b0fe2016-05-20 10:14:00 -05005141 VkEvent event;
5142 VkEventCreateInfo event_create_info{};
5143 event_create_info.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO;
5144 vkCreateEvent(m_device->device(), &event_create_info, nullptr, &event);
5145
5146 VkCommandPool command_pool;
5147 VkCommandPoolCreateInfo pool_create_info{};
5148 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
5149 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
5150 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005151 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
Michael Lentine860b0fe2016-05-20 10:14:00 -05005152
5153 VkCommandBuffer command_buffer;
5154 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005155 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
Michael Lentine860b0fe2016-05-20 10:14:00 -05005156 command_buffer_allocate_info.commandPool = command_pool;
5157 command_buffer_allocate_info.commandBufferCount = 1;
5158 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005159 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, &command_buffer);
Michael Lentine860b0fe2016-05-20 10:14:00 -05005160
5161 VkQueue queue = VK_NULL_HANDLE;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005162 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 0, &queue);
Michael Lentine860b0fe2016-05-20 10:14:00 -05005163
5164 {
5165 VkCommandBufferBeginInfo begin_info{};
5166 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
5167 vkBeginCommandBuffer(command_buffer, &begin_info);
5168
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005169 vkCmdResetEvent(command_buffer, event, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT);
5170 vkCmdWaitEvents(command_buffer, 1, &event, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0,
5171 nullptr, 0, nullptr, 0, nullptr);
Michael Lentine860b0fe2016-05-20 10:14:00 -05005172 vkEndCommandBuffer(command_buffer);
5173 }
5174 {
5175 VkSubmitInfo submit_info{};
5176 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
5177 submit_info.commandBufferCount = 1;
5178 submit_info.pCommandBuffers = &command_buffer;
5179 submit_info.signalSemaphoreCount = 0;
5180 submit_info.pSignalSemaphores = nullptr;
5181 vkQueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE);
5182 }
5183 {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005184 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "that is already in use by a "
5185 "command buffer.");
Michael Lentine860b0fe2016-05-20 10:14:00 -05005186 vkSetEvent(m_device->device(), event);
5187 m_errorMonitor->VerifyFound();
5188 }
5189
5190 vkQueueWaitIdle(queue);
5191
5192 vkDestroyEvent(m_device->device(), event, nullptr);
5193 vkFreeCommandBuffers(m_device->device(), command_pool, 1, &command_buffer);
5194 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
5195}
5196
5197// This is a positive test. No errors should be generated.
Tobin Ehlis0bb263b2016-05-10 12:13:02 -06005198TEST_F(VkLayerTest, TwoFencesThreeFrames) {
5199 TEST_DESCRIPTION("Two command buffers with two separate fences are each "
5200 "run through a Submit & WaitForFences cycle 3 times. This "
5201 "previously revealed a bug so running this positive test "
5202 "to prevent a regression.");
5203 m_errorMonitor->ExpectSuccess();
5204
5205 ASSERT_NO_FATAL_FAILURE(InitState());
5206 VkQueue queue = VK_NULL_HANDLE;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005207 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 0, &queue);
Tobin Ehlis0bb263b2016-05-10 12:13:02 -06005208
5209 static const uint32_t NUM_OBJECTS = 2;
5210 static const uint32_t NUM_FRAMES = 3;
5211 VkCommandBuffer cmd_buffers[NUM_OBJECTS] = {};
5212 VkFence fences[NUM_OBJECTS] = {};
5213
5214 VkCommandPool cmd_pool;
5215 VkCommandPoolCreateInfo cmd_pool_ci = {};
5216 cmd_pool_ci.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
5217 cmd_pool_ci.queueFamilyIndex = m_device->graphics_queue_node_index_;
5218 cmd_pool_ci.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005219 VkResult err = vkCreateCommandPool(m_device->device(), &cmd_pool_ci, nullptr, &cmd_pool);
Tobin Ehlis0bb263b2016-05-10 12:13:02 -06005220 ASSERT_VK_SUCCESS(err);
5221
5222 VkCommandBufferAllocateInfo cmd_buf_info = {};
5223 cmd_buf_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
5224 cmd_buf_info.commandPool = cmd_pool;
5225 cmd_buf_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
5226 cmd_buf_info.commandBufferCount = 1;
5227
5228 VkFenceCreateInfo fence_ci = {};
5229 fence_ci.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
5230 fence_ci.pNext = nullptr;
5231 fence_ci.flags = 0;
5232
5233 for (uint32_t i = 0; i < NUM_OBJECTS; ++i) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005234 err = vkAllocateCommandBuffers(m_device->device(), &cmd_buf_info, &cmd_buffers[i]);
Tobin Ehlis0bb263b2016-05-10 12:13:02 -06005235 ASSERT_VK_SUCCESS(err);
5236 err = vkCreateFence(m_device->device(), &fence_ci, nullptr, &fences[i]);
5237 ASSERT_VK_SUCCESS(err);
5238 }
5239
5240 for (uint32_t frame = 0; frame < NUM_FRAMES; ++frame) {
Tobin Ehlisf9025162016-05-26 06:55:21 -06005241 for (uint32_t obj = 0; obj < NUM_OBJECTS; ++obj) {
5242 // Create empty cmd buffer
5243 VkCommandBufferBeginInfo cmdBufBeginDesc = {};
5244 cmdBufBeginDesc.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
Tobin Ehlis0bb263b2016-05-10 12:13:02 -06005245
Tobin Ehlisf9025162016-05-26 06:55:21 -06005246 err = vkBeginCommandBuffer(cmd_buffers[obj], &cmdBufBeginDesc);
5247 ASSERT_VK_SUCCESS(err);
5248 err = vkEndCommandBuffer(cmd_buffers[obj]);
5249 ASSERT_VK_SUCCESS(err);
Tobin Ehlis0bb263b2016-05-10 12:13:02 -06005250
Tobin Ehlisf9025162016-05-26 06:55:21 -06005251 VkSubmitInfo submit_info = {};
5252 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
5253 submit_info.commandBufferCount = 1;
5254 submit_info.pCommandBuffers = &cmd_buffers[obj];
5255 // Submit cmd buffer and wait for fence
5256 err = vkQueueSubmit(queue, 1, &submit_info, fences[obj]);
5257 ASSERT_VK_SUCCESS(err);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005258 err = vkWaitForFences(m_device->device(), 1, &fences[obj], VK_TRUE, UINT64_MAX);
Tobin Ehlisf9025162016-05-26 06:55:21 -06005259 ASSERT_VK_SUCCESS(err);
5260 err = vkResetFences(m_device->device(), 1, &fences[obj]);
5261 ASSERT_VK_SUCCESS(err);
5262 }
Tobin Ehlis0bb263b2016-05-10 12:13:02 -06005263 }
5264 m_errorMonitor->VerifyNotFound();
Tony Barbourdf4c0042016-06-01 15:55:43 -06005265 vkDestroyCommandPool(m_device->device(), cmd_pool, NULL);
5266 for (uint32_t i = 0; i < NUM_OBJECTS; ++i) {
5267 vkDestroyFence(m_device->device(), fences[i], nullptr);
5268 }
Tobin Ehlis0bb263b2016-05-10 12:13:02 -06005269}
5270// This is a positive test. No errors should be generated.
Mark Lobodzinskic808d442016-04-14 10:57:23 -06005271TEST_F(VkLayerTest, TwoQueueSubmitsSeparateQueuesWithSemaphoreAndOneFenceQWI) {
5272
5273 TEST_DESCRIPTION("Two command buffers, each in a separate QueueSubmit call "
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005274 "submitted on separate queues followed by a QueueWaitIdle.");
Mark Lobodzinskic808d442016-04-14 10:57:23 -06005275
Cody Northropc31a84f2016-08-22 10:41:47 -06005276 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005277 if ((m_device->queue_props.empty()) || (m_device->queue_props[0].queueCount < 2))
Tony Barbourdc18b262016-04-22 14:49:48 -06005278 return;
5279
Mark Lobodzinskic808d442016-04-14 10:57:23 -06005280 m_errorMonitor->ExpectSuccess();
5281
5282 VkSemaphore semaphore;
5283 VkSemaphoreCreateInfo semaphore_create_info{};
5284 semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005285 vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr, &semaphore);
Mark Lobodzinskic808d442016-04-14 10:57:23 -06005286
5287 VkCommandPool command_pool;
5288 VkCommandPoolCreateInfo pool_create_info{};
5289 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
5290 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
5291 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005292 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
Mark Lobodzinskic808d442016-04-14 10:57:23 -06005293
5294 VkCommandBuffer command_buffer[2];
5295 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005296 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
Mark Lobodzinskic808d442016-04-14 10:57:23 -06005297 command_buffer_allocate_info.commandPool = command_pool;
5298 command_buffer_allocate_info.commandBufferCount = 2;
5299 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005300 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, command_buffer);
Mark Lobodzinskic808d442016-04-14 10:57:23 -06005301
5302 VkQueue queue = VK_NULL_HANDLE;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005303 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 1, &queue);
Mark Lobodzinskic808d442016-04-14 10:57:23 -06005304
5305 {
5306 VkCommandBufferBeginInfo begin_info{};
5307 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
5308 vkBeginCommandBuffer(command_buffer[0], &begin_info);
5309
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005310 vkCmdPipelineBarrier(command_buffer[0], VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0,
5311 nullptr, 0, nullptr, 0, nullptr);
Mark Lobodzinskic808d442016-04-14 10:57:23 -06005312
5313 VkViewport viewport{};
5314 viewport.maxDepth = 1.0f;
5315 viewport.minDepth = 0.0f;
5316 viewport.width = 512;
5317 viewport.height = 512;
5318 viewport.x = 0;
5319 viewport.y = 0;
5320 vkCmdSetViewport(command_buffer[0], 0, 1, &viewport);
5321 vkEndCommandBuffer(command_buffer[0]);
5322 }
5323 {
5324 VkCommandBufferBeginInfo begin_info{};
5325 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
5326 vkBeginCommandBuffer(command_buffer[1], &begin_info);
5327
5328 VkViewport viewport{};
5329 viewport.maxDepth = 1.0f;
5330 viewport.minDepth = 0.0f;
5331 viewport.width = 512;
5332 viewport.height = 512;
5333 viewport.x = 0;
5334 viewport.y = 0;
5335 vkCmdSetViewport(command_buffer[1], 0, 1, &viewport);
5336 vkEndCommandBuffer(command_buffer[1]);
5337 }
5338 {
5339 VkSubmitInfo submit_info{};
5340 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
5341 submit_info.commandBufferCount = 1;
5342 submit_info.pCommandBuffers = &command_buffer[0];
5343 submit_info.signalSemaphoreCount = 1;
5344 submit_info.pSignalSemaphores = &semaphore;
5345 vkQueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE);
5346 }
5347 {
5348 VkPipelineStageFlags flags[]{VK_PIPELINE_STAGE_ALL_COMMANDS_BIT};
5349 VkSubmitInfo submit_info{};
5350 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
5351 submit_info.commandBufferCount = 1;
5352 submit_info.pCommandBuffers = &command_buffer[1];
5353 submit_info.waitSemaphoreCount = 1;
5354 submit_info.pWaitSemaphores = &semaphore;
5355 submit_info.pWaitDstStageMask = flags;
5356 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
5357 }
5358
5359 vkQueueWaitIdle(m_device->m_queue);
5360
5361 vkDestroySemaphore(m_device->device(), semaphore, nullptr);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005362 vkFreeCommandBuffers(m_device->device(), command_pool, 2, &command_buffer[0]);
Mark Lobodzinskic808d442016-04-14 10:57:23 -06005363 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
5364
5365 m_errorMonitor->VerifyNotFound();
5366}
5367
5368// This is a positive test. No errors should be generated.
5369TEST_F(VkLayerTest, TwoQueueSubmitsSeparateQueuesWithSemaphoreAndOneFenceQWIFence) {
5370
5371 TEST_DESCRIPTION("Two command buffers, each in a separate QueueSubmit call "
5372 "submitted on separate queues, the second having a fence"
5373 "followed by a QueueWaitIdle.");
5374
Cody Northropc31a84f2016-08-22 10:41:47 -06005375 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005376 if ((m_device->queue_props.empty()) || (m_device->queue_props[0].queueCount < 2))
Tony Barbourdc18b262016-04-22 14:49:48 -06005377 return;
5378
Mark Lobodzinskic808d442016-04-14 10:57:23 -06005379 m_errorMonitor->ExpectSuccess();
5380
5381 VkFence fence;
5382 VkFenceCreateInfo fence_create_info{};
5383 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
5384 vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence);
5385
5386 VkSemaphore semaphore;
5387 VkSemaphoreCreateInfo semaphore_create_info{};
5388 semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005389 vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr, &semaphore);
Mark Lobodzinskic808d442016-04-14 10:57:23 -06005390
5391 VkCommandPool command_pool;
5392 VkCommandPoolCreateInfo pool_create_info{};
5393 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
5394 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
5395 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005396 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
Mark Lobodzinskic808d442016-04-14 10:57:23 -06005397
5398 VkCommandBuffer command_buffer[2];
5399 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005400 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
Mark Lobodzinskic808d442016-04-14 10:57:23 -06005401 command_buffer_allocate_info.commandPool = command_pool;
5402 command_buffer_allocate_info.commandBufferCount = 2;
5403 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005404 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, command_buffer);
Mark Lobodzinskic808d442016-04-14 10:57:23 -06005405
5406 VkQueue queue = VK_NULL_HANDLE;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005407 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 1, &queue);
Mark Lobodzinskic808d442016-04-14 10:57:23 -06005408
5409 {
5410 VkCommandBufferBeginInfo begin_info{};
5411 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
5412 vkBeginCommandBuffer(command_buffer[0], &begin_info);
5413
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005414 vkCmdPipelineBarrier(command_buffer[0], VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0,
5415 nullptr, 0, nullptr, 0, nullptr);
Mark Lobodzinskic808d442016-04-14 10:57:23 -06005416
5417 VkViewport viewport{};
5418 viewport.maxDepth = 1.0f;
5419 viewport.minDepth = 0.0f;
5420 viewport.width = 512;
5421 viewport.height = 512;
5422 viewport.x = 0;
5423 viewport.y = 0;
5424 vkCmdSetViewport(command_buffer[0], 0, 1, &viewport);
5425 vkEndCommandBuffer(command_buffer[0]);
5426 }
5427 {
5428 VkCommandBufferBeginInfo begin_info{};
5429 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
5430 vkBeginCommandBuffer(command_buffer[1], &begin_info);
5431
5432 VkViewport viewport{};
5433 viewport.maxDepth = 1.0f;
5434 viewport.minDepth = 0.0f;
5435 viewport.width = 512;
5436 viewport.height = 512;
5437 viewport.x = 0;
5438 viewport.y = 0;
5439 vkCmdSetViewport(command_buffer[1], 0, 1, &viewport);
5440 vkEndCommandBuffer(command_buffer[1]);
5441 }
5442 {
5443 VkSubmitInfo submit_info{};
5444 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
5445 submit_info.commandBufferCount = 1;
5446 submit_info.pCommandBuffers = &command_buffer[0];
5447 submit_info.signalSemaphoreCount = 1;
5448 submit_info.pSignalSemaphores = &semaphore;
5449 vkQueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE);
5450 }
5451 {
5452 VkPipelineStageFlags flags[]{VK_PIPELINE_STAGE_ALL_COMMANDS_BIT};
5453 VkSubmitInfo submit_info{};
5454 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
5455 submit_info.commandBufferCount = 1;
5456 submit_info.pCommandBuffers = &command_buffer[1];
5457 submit_info.waitSemaphoreCount = 1;
5458 submit_info.pWaitSemaphores = &semaphore;
5459 submit_info.pWaitDstStageMask = flags;
5460 vkQueueSubmit(m_device->m_queue, 1, &submit_info, fence);
5461 }
5462
5463 vkQueueWaitIdle(m_device->m_queue);
5464
5465 vkDestroyFence(m_device->device(), fence, nullptr);
5466 vkDestroySemaphore(m_device->device(), semaphore, nullptr);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005467 vkFreeCommandBuffers(m_device->device(), command_pool, 2, &command_buffer[0]);
Mark Lobodzinskic808d442016-04-14 10:57:23 -06005468 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
5469
5470 m_errorMonitor->VerifyNotFound();
5471}
5472
5473// This is a positive test. No errors should be generated.
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005474TEST_F(VkLayerTest, TwoQueueSubmitsSeparateQueuesWithSemaphoreAndOneFenceTwoWFF) {
Mark Lobodzinskic808d442016-04-14 10:57:23 -06005475
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005476 TEST_DESCRIPTION("Two command buffers, each in a separate QueueSubmit call "
5477 "submitted on separate queues, the second having a fence"
5478 "followed by two consecutive WaitForFences calls on the same fence.");
Mark Lobodzinskic808d442016-04-14 10:57:23 -06005479
Cody Northropc31a84f2016-08-22 10:41:47 -06005480 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005481 if ((m_device->queue_props.empty()) || (m_device->queue_props[0].queueCount < 2))
Tony Barbourdc18b262016-04-22 14:49:48 -06005482 return;
5483
Mark Lobodzinskic808d442016-04-14 10:57:23 -06005484 m_errorMonitor->ExpectSuccess();
5485
5486 VkFence fence;
5487 VkFenceCreateInfo fence_create_info{};
5488 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
5489 vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence);
5490
5491 VkSemaphore semaphore;
5492 VkSemaphoreCreateInfo semaphore_create_info{};
5493 semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005494 vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr, &semaphore);
Mark Lobodzinskic808d442016-04-14 10:57:23 -06005495
5496 VkCommandPool command_pool;
5497 VkCommandPoolCreateInfo pool_create_info{};
5498 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
5499 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
5500 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005501 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
Mark Lobodzinskic808d442016-04-14 10:57:23 -06005502
5503 VkCommandBuffer command_buffer[2];
5504 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005505 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
Mark Lobodzinskic808d442016-04-14 10:57:23 -06005506 command_buffer_allocate_info.commandPool = command_pool;
5507 command_buffer_allocate_info.commandBufferCount = 2;
5508 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005509 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, command_buffer);
Mark Lobodzinskic808d442016-04-14 10:57:23 -06005510
5511 VkQueue queue = VK_NULL_HANDLE;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005512 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 1, &queue);
Mark Lobodzinskic808d442016-04-14 10:57:23 -06005513
5514 {
5515 VkCommandBufferBeginInfo begin_info{};
5516 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
5517 vkBeginCommandBuffer(command_buffer[0], &begin_info);
5518
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005519 vkCmdPipelineBarrier(command_buffer[0], VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0,
5520 nullptr, 0, nullptr, 0, nullptr);
Mark Lobodzinskic808d442016-04-14 10:57:23 -06005521
5522 VkViewport viewport{};
5523 viewport.maxDepth = 1.0f;
5524 viewport.minDepth = 0.0f;
5525 viewport.width = 512;
5526 viewport.height = 512;
5527 viewport.x = 0;
5528 viewport.y = 0;
5529 vkCmdSetViewport(command_buffer[0], 0, 1, &viewport);
5530 vkEndCommandBuffer(command_buffer[0]);
5531 }
5532 {
5533 VkCommandBufferBeginInfo begin_info{};
5534 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
5535 vkBeginCommandBuffer(command_buffer[1], &begin_info);
5536
5537 VkViewport viewport{};
5538 viewport.maxDepth = 1.0f;
5539 viewport.minDepth = 0.0f;
5540 viewport.width = 512;
5541 viewport.height = 512;
5542 viewport.x = 0;
5543 viewport.y = 0;
5544 vkCmdSetViewport(command_buffer[1], 0, 1, &viewport);
5545 vkEndCommandBuffer(command_buffer[1]);
5546 }
5547 {
5548 VkSubmitInfo submit_info{};
5549 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
5550 submit_info.commandBufferCount = 1;
5551 submit_info.pCommandBuffers = &command_buffer[0];
5552 submit_info.signalSemaphoreCount = 1;
5553 submit_info.pSignalSemaphores = &semaphore;
5554 vkQueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE);
5555 }
5556 {
5557 VkPipelineStageFlags flags[]{VK_PIPELINE_STAGE_ALL_COMMANDS_BIT};
5558 VkSubmitInfo submit_info{};
5559 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
5560 submit_info.commandBufferCount = 1;
5561 submit_info.pCommandBuffers = &command_buffer[1];
5562 submit_info.waitSemaphoreCount = 1;
5563 submit_info.pWaitSemaphores = &semaphore;
5564 submit_info.pWaitDstStageMask = flags;
5565 vkQueueSubmit(m_device->m_queue, 1, &submit_info, fence);
5566 }
5567
5568 vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
5569 vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
5570
5571 vkDestroyFence(m_device->device(), fence, nullptr);
5572 vkDestroySemaphore(m_device->device(), semaphore, nullptr);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005573 vkFreeCommandBuffers(m_device->device(), command_pool, 2, &command_buffer[0]);
Mark Lobodzinskic808d442016-04-14 10:57:23 -06005574 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
5575
5576 m_errorMonitor->VerifyNotFound();
5577}
5578
Chris Forbes0f8126b2016-06-20 17:48:22 +12005579TEST_F(VkLayerTest, TwoQueuesEnsureCorrectRetirementWithWorkStolen) {
Cody Northropc31a84f2016-08-22 10:41:47 -06005580
5581 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005582 if ((m_device->queue_props.empty()) || (m_device->queue_props[0].queueCount < 2)) {
Chris Forbes0f8126b2016-06-20 17:48:22 +12005583 printf("Test requires two queues, skipping\n");
5584 return;
5585 }
5586
5587 VkResult err;
5588
5589 m_errorMonitor->ExpectSuccess();
5590
5591 VkQueue q0 = m_device->m_queue;
5592 VkQueue q1 = nullptr;
5593 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 1, &q1);
5594 ASSERT_NE(q1, nullptr);
5595
5596 // An (empty) command buffer. We must have work in the first submission --
5597 // the layer treats unfenced work differently from fenced work.
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005598 VkCommandPoolCreateInfo cpci = {VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO, nullptr, 0, 0};
Chris Forbes0f8126b2016-06-20 17:48:22 +12005599 VkCommandPool pool;
5600 err = vkCreateCommandPool(m_device->device(), &cpci, nullptr, &pool);
5601 ASSERT_VK_SUCCESS(err);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005602 VkCommandBufferAllocateInfo cbai = {VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO, nullptr, pool,
5603 VK_COMMAND_BUFFER_LEVEL_PRIMARY, 1};
Chris Forbes0f8126b2016-06-20 17:48:22 +12005604 VkCommandBuffer cb;
5605 err = vkAllocateCommandBuffers(m_device->device(), &cbai, &cb);
5606 ASSERT_VK_SUCCESS(err);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005607 VkCommandBufferBeginInfo cbbi = {VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO, nullptr, 0, nullptr};
Chris Forbes0f8126b2016-06-20 17:48:22 +12005608 err = vkBeginCommandBuffer(cb, &cbbi);
5609 ASSERT_VK_SUCCESS(err);
5610 err = vkEndCommandBuffer(cb);
5611 ASSERT_VK_SUCCESS(err);
5612
5613 // A semaphore
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005614 VkSemaphoreCreateInfo sci = {VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO, nullptr, 0};
Chris Forbes0f8126b2016-06-20 17:48:22 +12005615 VkSemaphore s;
5616 err = vkCreateSemaphore(m_device->device(), &sci, nullptr, &s);
5617 ASSERT_VK_SUCCESS(err);
5618
5619 // First submission, to q0
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005620 VkSubmitInfo s0 = {VK_STRUCTURE_TYPE_SUBMIT_INFO, nullptr, 0, nullptr, nullptr, 1, &cb, 1, &s};
Chris Forbes0f8126b2016-06-20 17:48:22 +12005621
5622 err = vkQueueSubmit(q0, 1, &s0, VK_NULL_HANDLE);
5623 ASSERT_VK_SUCCESS(err);
5624
5625 // Second submission, to q1, waiting on s
5626 VkFlags waitmask = VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT; // doesn't really matter what this value is.
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005627 VkSubmitInfo s1 = {VK_STRUCTURE_TYPE_SUBMIT_INFO, nullptr, 1, &s, &waitmask, 0, nullptr, 0, nullptr};
Chris Forbes0f8126b2016-06-20 17:48:22 +12005628
5629 err = vkQueueSubmit(q1, 1, &s1, VK_NULL_HANDLE);
5630 ASSERT_VK_SUCCESS(err);
5631
5632 // Wait for q0 idle
5633 err = vkQueueWaitIdle(q0);
5634 ASSERT_VK_SUCCESS(err);
5635
5636 // Command buffer should have been completed (it was on q0); reset the pool.
5637 vkFreeCommandBuffers(m_device->device(), pool, 1, &cb);
5638
5639 m_errorMonitor->VerifyNotFound();
5640
5641 // Force device completely idle and clean up resources
5642 vkDeviceWaitIdle(m_device->device());
5643 vkDestroyCommandPool(m_device->device(), pool, nullptr);
5644 vkDestroySemaphore(m_device->device(), s, nullptr);
5645}
Chris Forbes0f8126b2016-06-20 17:48:22 +12005646
Mark Lobodzinskic808d442016-04-14 10:57:23 -06005647// This is a positive test. No errors should be generated.
5648TEST_F(VkLayerTest, TwoQueueSubmitsSeparateQueuesWithSemaphoreAndOneFence) {
5649
5650 TEST_DESCRIPTION("Two command buffers, each in a separate QueueSubmit call "
5651 "submitted on separate queues, the second having a fence, "
5652 "followed by a WaitForFences call.");
5653
Cody Northropc31a84f2016-08-22 10:41:47 -06005654 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005655 if ((m_device->queue_props.empty()) || (m_device->queue_props[0].queueCount < 2))
Tony Barbourdc18b262016-04-22 14:49:48 -06005656 return;
5657
Mark Lobodzinskic808d442016-04-14 10:57:23 -06005658 m_errorMonitor->ExpectSuccess();
5659
Cody Northropc31a84f2016-08-22 10:41:47 -06005660 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinskic808d442016-04-14 10:57:23 -06005661 VkFence fence;
5662 VkFenceCreateInfo fence_create_info{};
5663 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
5664 vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence);
5665
5666 VkSemaphore semaphore;
5667 VkSemaphoreCreateInfo semaphore_create_info{};
5668 semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005669 vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr, &semaphore);
Mark Lobodzinskic808d442016-04-14 10:57:23 -06005670
5671 VkCommandPool command_pool;
5672 VkCommandPoolCreateInfo pool_create_info{};
5673 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
5674 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
5675 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005676 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
Mark Lobodzinskic808d442016-04-14 10:57:23 -06005677
5678 VkCommandBuffer command_buffer[2];
5679 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005680 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
Mark Lobodzinskic808d442016-04-14 10:57:23 -06005681 command_buffer_allocate_info.commandPool = command_pool;
5682 command_buffer_allocate_info.commandBufferCount = 2;
5683 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005684 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, command_buffer);
Mark Lobodzinskic808d442016-04-14 10:57:23 -06005685
5686 VkQueue queue = VK_NULL_HANDLE;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005687 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 1, &queue);
Mark Lobodzinskic808d442016-04-14 10:57:23 -06005688
5689 {
5690 VkCommandBufferBeginInfo begin_info{};
5691 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
5692 vkBeginCommandBuffer(command_buffer[0], &begin_info);
5693
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005694 vkCmdPipelineBarrier(command_buffer[0], VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0,
5695 nullptr, 0, nullptr, 0, nullptr);
Mark Lobodzinskic808d442016-04-14 10:57:23 -06005696
5697 VkViewport viewport{};
5698 viewport.maxDepth = 1.0f;
5699 viewport.minDepth = 0.0f;
5700 viewport.width = 512;
5701 viewport.height = 512;
5702 viewport.x = 0;
5703 viewport.y = 0;
5704 vkCmdSetViewport(command_buffer[0], 0, 1, &viewport);
5705 vkEndCommandBuffer(command_buffer[0]);
5706 }
5707 {
5708 VkCommandBufferBeginInfo begin_info{};
5709 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
5710 vkBeginCommandBuffer(command_buffer[1], &begin_info);
5711
5712 VkViewport viewport{};
5713 viewport.maxDepth = 1.0f;
5714 viewport.minDepth = 0.0f;
5715 viewport.width = 512;
5716 viewport.height = 512;
5717 viewport.x = 0;
5718 viewport.y = 0;
5719 vkCmdSetViewport(command_buffer[1], 0, 1, &viewport);
5720 vkEndCommandBuffer(command_buffer[1]);
5721 }
5722 {
5723 VkSubmitInfo submit_info{};
5724 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
5725 submit_info.commandBufferCount = 1;
5726 submit_info.pCommandBuffers = &command_buffer[0];
5727 submit_info.signalSemaphoreCount = 1;
5728 submit_info.pSignalSemaphores = &semaphore;
5729 vkQueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE);
5730 }
5731 {
5732 VkPipelineStageFlags flags[]{VK_PIPELINE_STAGE_ALL_COMMANDS_BIT};
5733 VkSubmitInfo submit_info{};
5734 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
5735 submit_info.commandBufferCount = 1;
5736 submit_info.pCommandBuffers = &command_buffer[1];
5737 submit_info.waitSemaphoreCount = 1;
5738 submit_info.pWaitSemaphores = &semaphore;
5739 submit_info.pWaitDstStageMask = flags;
5740 vkQueueSubmit(m_device->m_queue, 1, &submit_info, fence);
5741 }
5742
5743 vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
5744
5745 vkDestroyFence(m_device->device(), fence, nullptr);
5746 vkDestroySemaphore(m_device->device(), semaphore, nullptr);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005747 vkFreeCommandBuffers(m_device->device(), command_pool, 2, &command_buffer[0]);
Mark Lobodzinskic808d442016-04-14 10:57:23 -06005748 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
5749
5750 m_errorMonitor->VerifyNotFound();
5751}
5752
5753// This is a positive test. No errors should be generated.
5754TEST_F(VkLayerTest, TwoQueueSubmitsOneQueueWithSemaphoreAndOneFence) {
5755
5756 TEST_DESCRIPTION("Two command buffers, each in a separate QueueSubmit call "
5757 "on the same queue, sharing a signal/wait semaphore, the "
5758 "second having a fence, "
5759 "followed by a WaitForFences call.");
5760
5761 m_errorMonitor->ExpectSuccess();
5762
Cody Northropc31a84f2016-08-22 10:41:47 -06005763 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinskic808d442016-04-14 10:57:23 -06005764 VkFence fence;
5765 VkFenceCreateInfo fence_create_info{};
5766 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
5767 vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence);
5768
5769 VkSemaphore semaphore;
5770 VkSemaphoreCreateInfo semaphore_create_info{};
5771 semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005772 vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr, &semaphore);
Mark Lobodzinskic808d442016-04-14 10:57:23 -06005773
5774 VkCommandPool command_pool;
5775 VkCommandPoolCreateInfo pool_create_info{};
5776 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
5777 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
5778 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005779 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
Mark Lobodzinskic808d442016-04-14 10:57:23 -06005780
5781 VkCommandBuffer command_buffer[2];
5782 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005783 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
Mark Lobodzinskic808d442016-04-14 10:57:23 -06005784 command_buffer_allocate_info.commandPool = command_pool;
5785 command_buffer_allocate_info.commandBufferCount = 2;
5786 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005787 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, command_buffer);
Mark Lobodzinskic808d442016-04-14 10:57:23 -06005788
5789 {
5790 VkCommandBufferBeginInfo begin_info{};
5791 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
5792 vkBeginCommandBuffer(command_buffer[0], &begin_info);
5793
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005794 vkCmdPipelineBarrier(command_buffer[0], VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0,
5795 nullptr, 0, nullptr, 0, nullptr);
Mark Lobodzinskic808d442016-04-14 10:57:23 -06005796
5797 VkViewport viewport{};
5798 viewport.maxDepth = 1.0f;
5799 viewport.minDepth = 0.0f;
5800 viewport.width = 512;
5801 viewport.height = 512;
5802 viewport.x = 0;
5803 viewport.y = 0;
5804 vkCmdSetViewport(command_buffer[0], 0, 1, &viewport);
5805 vkEndCommandBuffer(command_buffer[0]);
5806 }
5807 {
5808 VkCommandBufferBeginInfo begin_info{};
5809 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
5810 vkBeginCommandBuffer(command_buffer[1], &begin_info);
5811
5812 VkViewport viewport{};
5813 viewport.maxDepth = 1.0f;
5814 viewport.minDepth = 0.0f;
5815 viewport.width = 512;
5816 viewport.height = 512;
5817 viewport.x = 0;
5818 viewport.y = 0;
5819 vkCmdSetViewport(command_buffer[1], 0, 1, &viewport);
5820 vkEndCommandBuffer(command_buffer[1]);
5821 }
5822 {
5823 VkSubmitInfo submit_info{};
5824 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
5825 submit_info.commandBufferCount = 1;
5826 submit_info.pCommandBuffers = &command_buffer[0];
5827 submit_info.signalSemaphoreCount = 1;
5828 submit_info.pSignalSemaphores = &semaphore;
5829 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
5830 }
5831 {
5832 VkPipelineStageFlags flags[]{VK_PIPELINE_STAGE_ALL_COMMANDS_BIT};
5833 VkSubmitInfo submit_info{};
5834 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
5835 submit_info.commandBufferCount = 1;
5836 submit_info.pCommandBuffers = &command_buffer[1];
5837 submit_info.waitSemaphoreCount = 1;
5838 submit_info.pWaitSemaphores = &semaphore;
5839 submit_info.pWaitDstStageMask = flags;
5840 vkQueueSubmit(m_device->m_queue, 1, &submit_info, fence);
5841 }
5842
5843 vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
5844
5845 vkDestroyFence(m_device->device(), fence, nullptr);
5846 vkDestroySemaphore(m_device->device(), semaphore, nullptr);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005847 vkFreeCommandBuffers(m_device->device(), command_pool, 2, &command_buffer[0]);
Mark Lobodzinskic808d442016-04-14 10:57:23 -06005848 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
5849
5850 m_errorMonitor->VerifyNotFound();
5851}
5852
5853// This is a positive test. No errors should be generated.
5854TEST_F(VkLayerTest, TwoQueueSubmitsOneQueueNullQueueSubmitWithFence) {
5855
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005856 TEST_DESCRIPTION("Two command buffers, each in a separate QueueSubmit call "
5857 "on the same queue, no fences, followed by a third QueueSubmit with NO "
5858 "SubmitInfos but with a fence, followed by a WaitForFences call.");
Mark Lobodzinskic808d442016-04-14 10:57:23 -06005859
5860 m_errorMonitor->ExpectSuccess();
5861
Cody Northropc31a84f2016-08-22 10:41:47 -06005862 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinskic808d442016-04-14 10:57:23 -06005863 VkFence fence;
5864 VkFenceCreateInfo fence_create_info{};
5865 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
5866 vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence);
5867
5868 VkCommandPool command_pool;
5869 VkCommandPoolCreateInfo pool_create_info{};
5870 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
5871 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
5872 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005873 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
Mark Lobodzinskic808d442016-04-14 10:57:23 -06005874
5875 VkCommandBuffer command_buffer[2];
5876 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005877 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
Mark Lobodzinskic808d442016-04-14 10:57:23 -06005878 command_buffer_allocate_info.commandPool = command_pool;
5879 command_buffer_allocate_info.commandBufferCount = 2;
5880 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005881 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, command_buffer);
Mark Lobodzinskic808d442016-04-14 10:57:23 -06005882
5883 {
5884 VkCommandBufferBeginInfo begin_info{};
5885 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
5886 vkBeginCommandBuffer(command_buffer[0], &begin_info);
5887
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005888 vkCmdPipelineBarrier(command_buffer[0], VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0,
5889 nullptr, 0, nullptr, 0, nullptr);
Mark Lobodzinskic808d442016-04-14 10:57:23 -06005890
5891 VkViewport viewport{};
5892 viewport.maxDepth = 1.0f;
5893 viewport.minDepth = 0.0f;
5894 viewport.width = 512;
5895 viewport.height = 512;
5896 viewport.x = 0;
5897 viewport.y = 0;
5898 vkCmdSetViewport(command_buffer[0], 0, 1, &viewport);
5899 vkEndCommandBuffer(command_buffer[0]);
5900 }
5901 {
5902 VkCommandBufferBeginInfo begin_info{};
5903 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
5904 vkBeginCommandBuffer(command_buffer[1], &begin_info);
5905
5906 VkViewport viewport{};
5907 viewport.maxDepth = 1.0f;
5908 viewport.minDepth = 0.0f;
5909 viewport.width = 512;
5910 viewport.height = 512;
5911 viewport.x = 0;
5912 viewport.y = 0;
5913 vkCmdSetViewport(command_buffer[1], 0, 1, &viewport);
5914 vkEndCommandBuffer(command_buffer[1]);
5915 }
5916 {
5917 VkSubmitInfo submit_info{};
5918 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
5919 submit_info.commandBufferCount = 1;
5920 submit_info.pCommandBuffers = &command_buffer[0];
5921 submit_info.signalSemaphoreCount = 0;
5922 submit_info.pSignalSemaphores = VK_NULL_HANDLE;
5923 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
5924 }
5925 {
5926 VkPipelineStageFlags flags[]{VK_PIPELINE_STAGE_ALL_COMMANDS_BIT};
5927 VkSubmitInfo submit_info{};
5928 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
5929 submit_info.commandBufferCount = 1;
5930 submit_info.pCommandBuffers = &command_buffer[1];
5931 submit_info.waitSemaphoreCount = 0;
5932 submit_info.pWaitSemaphores = VK_NULL_HANDLE;
5933 submit_info.pWaitDstStageMask = flags;
5934 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
5935 }
5936
5937 vkQueueSubmit(m_device->m_queue, 0, NULL, fence);
5938
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005939 VkResult err = vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
Mike Stroyancd1c3e52016-06-21 09:20:01 -06005940 ASSERT_VK_SUCCESS(err);
Mark Lobodzinskic808d442016-04-14 10:57:23 -06005941
5942 vkDestroyFence(m_device->device(), fence, nullptr);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005943 vkFreeCommandBuffers(m_device->device(), command_pool, 2, &command_buffer[0]);
Mark Lobodzinskic808d442016-04-14 10:57:23 -06005944 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
5945
5946 m_errorMonitor->VerifyNotFound();
5947}
5948
5949// This is a positive test. No errors should be generated.
5950TEST_F(VkLayerTest, TwoQueueSubmitsOneQueueOneFence) {
5951
5952 TEST_DESCRIPTION("Two command buffers, each in a separate QueueSubmit call "
5953 "on the same queue, the second having a fence, followed "
5954 "by a WaitForFences call.");
5955
5956 m_errorMonitor->ExpectSuccess();
5957
Cody Northropc31a84f2016-08-22 10:41:47 -06005958 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinskic808d442016-04-14 10:57:23 -06005959 VkFence fence;
5960 VkFenceCreateInfo fence_create_info{};
5961 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
5962 vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence);
5963
5964 VkCommandPool command_pool;
5965 VkCommandPoolCreateInfo pool_create_info{};
5966 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
5967 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
5968 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005969 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
Mark Lobodzinskic808d442016-04-14 10:57:23 -06005970
5971 VkCommandBuffer command_buffer[2];
5972 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005973 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
Mark Lobodzinskic808d442016-04-14 10:57:23 -06005974 command_buffer_allocate_info.commandPool = command_pool;
5975 command_buffer_allocate_info.commandBufferCount = 2;
5976 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005977 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, command_buffer);
Mark Lobodzinskic808d442016-04-14 10:57:23 -06005978
5979 {
5980 VkCommandBufferBeginInfo begin_info{};
5981 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
5982 vkBeginCommandBuffer(command_buffer[0], &begin_info);
5983
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005984 vkCmdPipelineBarrier(command_buffer[0], VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0,
5985 nullptr, 0, nullptr, 0, nullptr);
Mark Lobodzinskic808d442016-04-14 10:57:23 -06005986
5987 VkViewport viewport{};
5988 viewport.maxDepth = 1.0f;
5989 viewport.minDepth = 0.0f;
5990 viewport.width = 512;
5991 viewport.height = 512;
5992 viewport.x = 0;
5993 viewport.y = 0;
5994 vkCmdSetViewport(command_buffer[0], 0, 1, &viewport);
5995 vkEndCommandBuffer(command_buffer[0]);
5996 }
5997 {
5998 VkCommandBufferBeginInfo begin_info{};
5999 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
6000 vkBeginCommandBuffer(command_buffer[1], &begin_info);
6001
6002 VkViewport viewport{};
6003 viewport.maxDepth = 1.0f;
6004 viewport.minDepth = 0.0f;
6005 viewport.width = 512;
6006 viewport.height = 512;
6007 viewport.x = 0;
6008 viewport.y = 0;
6009 vkCmdSetViewport(command_buffer[1], 0, 1, &viewport);
6010 vkEndCommandBuffer(command_buffer[1]);
6011 }
6012 {
6013 VkSubmitInfo submit_info{};
6014 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
6015 submit_info.commandBufferCount = 1;
6016 submit_info.pCommandBuffers = &command_buffer[0];
6017 submit_info.signalSemaphoreCount = 0;
6018 submit_info.pSignalSemaphores = VK_NULL_HANDLE;
6019 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
6020 }
6021 {
6022 VkPipelineStageFlags flags[]{VK_PIPELINE_STAGE_ALL_COMMANDS_BIT};
6023 VkSubmitInfo submit_info{};
6024 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
6025 submit_info.commandBufferCount = 1;
6026 submit_info.pCommandBuffers = &command_buffer[1];
6027 submit_info.waitSemaphoreCount = 0;
6028 submit_info.pWaitSemaphores = VK_NULL_HANDLE;
6029 submit_info.pWaitDstStageMask = flags;
6030 vkQueueSubmit(m_device->m_queue, 1, &submit_info, fence);
6031 }
6032
6033 vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
6034
6035 vkDestroyFence(m_device->device(), fence, nullptr);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006036 vkFreeCommandBuffers(m_device->device(), command_pool, 2, &command_buffer[0]);
Mark Lobodzinskic808d442016-04-14 10:57:23 -06006037 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
6038
6039 m_errorMonitor->VerifyNotFound();
6040}
6041
6042// This is a positive test. No errors should be generated.
6043TEST_F(VkLayerTest, TwoSubmitInfosWithSemaphoreOneQueueSubmitsOneFence) {
6044
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006045 TEST_DESCRIPTION("Two command buffers each in a separate SubmitInfo sent in a single "
6046 "QueueSubmit call followed by a WaitForFences call.");
Cody Northropc31a84f2016-08-22 10:41:47 -06006047 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinskic808d442016-04-14 10:57:23 -06006048
6049 m_errorMonitor->ExpectSuccess();
6050
6051 VkFence fence;
6052 VkFenceCreateInfo fence_create_info{};
6053 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
6054 vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence);
6055
6056 VkSemaphore semaphore;
6057 VkSemaphoreCreateInfo semaphore_create_info{};
6058 semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006059 vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr, &semaphore);
Mark Lobodzinskic808d442016-04-14 10:57:23 -06006060
6061 VkCommandPool command_pool;
6062 VkCommandPoolCreateInfo pool_create_info{};
6063 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
6064 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
6065 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006066 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
Mark Lobodzinskic808d442016-04-14 10:57:23 -06006067
6068 VkCommandBuffer command_buffer[2];
6069 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006070 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
Mark Lobodzinskic808d442016-04-14 10:57:23 -06006071 command_buffer_allocate_info.commandPool = command_pool;
6072 command_buffer_allocate_info.commandBufferCount = 2;
6073 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006074 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, command_buffer);
Mark Lobodzinskic808d442016-04-14 10:57:23 -06006075
6076 {
6077 VkCommandBufferBeginInfo begin_info{};
6078 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
6079 vkBeginCommandBuffer(command_buffer[0], &begin_info);
6080
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006081 vkCmdPipelineBarrier(command_buffer[0], VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0,
6082 nullptr, 0, nullptr, 0, nullptr);
Mark Lobodzinskic808d442016-04-14 10:57:23 -06006083
6084 VkViewport viewport{};
6085 viewport.maxDepth = 1.0f;
6086 viewport.minDepth = 0.0f;
6087 viewport.width = 512;
6088 viewport.height = 512;
6089 viewport.x = 0;
6090 viewport.y = 0;
6091 vkCmdSetViewport(command_buffer[0], 0, 1, &viewport);
6092 vkEndCommandBuffer(command_buffer[0]);
6093 }
6094 {
6095 VkCommandBufferBeginInfo begin_info{};
6096 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
6097 vkBeginCommandBuffer(command_buffer[1], &begin_info);
6098
6099 VkViewport viewport{};
6100 viewport.maxDepth = 1.0f;
6101 viewport.minDepth = 0.0f;
6102 viewport.width = 512;
6103 viewport.height = 512;
6104 viewport.x = 0;
6105 viewport.y = 0;
6106 vkCmdSetViewport(command_buffer[1], 0, 1, &viewport);
6107 vkEndCommandBuffer(command_buffer[1]);
6108 }
6109 {
6110 VkSubmitInfo submit_info[2];
6111 VkPipelineStageFlags flags[]{VK_PIPELINE_STAGE_ALL_COMMANDS_BIT};
6112
6113 submit_info[0].sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
6114 submit_info[0].pNext = NULL;
6115 submit_info[0].commandBufferCount = 1;
6116 submit_info[0].pCommandBuffers = &command_buffer[0];
6117 submit_info[0].signalSemaphoreCount = 1;
6118 submit_info[0].pSignalSemaphores = &semaphore;
6119 submit_info[0].waitSemaphoreCount = 0;
6120 submit_info[0].pWaitSemaphores = NULL;
6121 submit_info[0].pWaitDstStageMask = 0;
6122
6123 submit_info[1].sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
6124 submit_info[1].pNext = NULL;
6125 submit_info[1].commandBufferCount = 1;
6126 submit_info[1].pCommandBuffers = &command_buffer[1];
6127 submit_info[1].waitSemaphoreCount = 1;
6128 submit_info[1].pWaitSemaphores = &semaphore;
6129 submit_info[1].pWaitDstStageMask = flags;
6130 submit_info[1].signalSemaphoreCount = 0;
6131 submit_info[1].pSignalSemaphores = NULL;
6132 vkQueueSubmit(m_device->m_queue, 2, &submit_info[0], fence);
6133 }
6134
6135 vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
6136
6137 vkDestroyFence(m_device->device(), fence, nullptr);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006138 vkFreeCommandBuffers(m_device->device(), command_pool, 2, &command_buffer[0]);
Mark Lobodzinskic808d442016-04-14 10:57:23 -06006139 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
Tony Barbourdf4c0042016-06-01 15:55:43 -06006140 vkDestroySemaphore(m_device->device(), semaphore, nullptr);
Mark Lobodzinskic808d442016-04-14 10:57:23 -06006141
6142 m_errorMonitor->VerifyNotFound();
6143}
6144
Tobin Ehlisb1a87992016-05-25 16:42:47 -06006145TEST_F(VkLayerTest, DynamicDepthBiasNotBound) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006146 TEST_DESCRIPTION("Run a simple draw calls to validate failure when Depth Bias dynamic "
6147 "state is required but not correctly bound.");
Tobin Ehlisb1a87992016-05-25 16:42:47 -06006148
Cody Northropc31a84f2016-08-22 10:41:47 -06006149 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisb1a87992016-05-25 16:42:47 -06006150 // Dynamic depth bias
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006151 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Dynamic depth bias state not set for this command buffer");
6152 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailDepthBias);
Tobin Ehlisb1a87992016-05-25 16:42:47 -06006153 m_errorMonitor->VerifyFound();
6154}
6155
6156TEST_F(VkLayerTest, DynamicLineWidthNotBound) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006157 TEST_DESCRIPTION("Run a simple draw calls to validate failure when Line Width dynamic "
6158 "state is required but not correctly bound.");
Tobin Ehlisa5200ef2016-05-03 10:34:08 -06006159
Cody Northropc31a84f2016-08-22 10:41:47 -06006160 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisa5200ef2016-05-03 10:34:08 -06006161 // Dynamic line width
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006162 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Dynamic line width state not set for this command buffer");
6163 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailLineWidth);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006164 m_errorMonitor->VerifyFound();
Tobin Ehlisb1a87992016-05-25 16:42:47 -06006165}
6166
6167TEST_F(VkLayerTest, DynamicViewportNotBound) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006168 TEST_DESCRIPTION("Run a simple draw calls to validate failure when Viewport dynamic "
6169 "state is required but not correctly bound.");
Tobin Ehlisb1a87992016-05-25 16:42:47 -06006170
Cody Northropc31a84f2016-08-22 10:41:47 -06006171 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisa5200ef2016-05-03 10:34:08 -06006172 // Dynamic viewport state
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006173 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Dynamic viewport state not set for this command buffer");
6174 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailViewport);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006175 m_errorMonitor->VerifyFound();
Tobin Ehlisb1a87992016-05-25 16:42:47 -06006176}
6177
6178TEST_F(VkLayerTest, DynamicScissorNotBound) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006179 TEST_DESCRIPTION("Run a simple draw calls to validate failure when Scissor dynamic "
6180 "state is required but not correctly bound.");
Tobin Ehlisb1a87992016-05-25 16:42:47 -06006181
Cody Northropc31a84f2016-08-22 10:41:47 -06006182 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisa5200ef2016-05-03 10:34:08 -06006183 // Dynamic scissor state
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006184 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Dynamic scissor state not set for this command buffer");
6185 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailScissor);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006186 m_errorMonitor->VerifyFound();
Tobin Ehlisb1a87992016-05-25 16:42:47 -06006187}
6188
Cortd713fe82016-07-27 09:51:27 -07006189TEST_F(VkLayerTest, DynamicBlendConstantsNotBound) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006190 TEST_DESCRIPTION("Run a simple draw calls to validate failure when Blend Constants "
6191 "dynamic state is required but not correctly bound.");
Cody Northropc31a84f2016-08-22 10:41:47 -06006192
6193 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlis21c88352016-05-26 06:15:45 -06006194 // Dynamic blend constant state
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006195 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
6196 "Dynamic blend constants state not set for this command buffer");
6197 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailBlend);
Tobin Ehlis21c88352016-05-26 06:15:45 -06006198 m_errorMonitor->VerifyFound();
6199}
6200
6201TEST_F(VkLayerTest, DynamicDepthBoundsNotBound) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006202 TEST_DESCRIPTION("Run a simple draw calls to validate failure when Depth Bounds dynamic "
6203 "state is required but not correctly bound.");
Cody Northropc31a84f2016-08-22 10:41:47 -06006204
6205 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlis21c88352016-05-26 06:15:45 -06006206 if (!m_device->phy().features().depthBounds) {
6207 printf("Device does not support depthBounds test; skipped.\n");
6208 return;
6209 }
6210 // Dynamic depth bounds
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006211 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
6212 "Dynamic depth bounds state not set for this command buffer");
6213 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailDepthBounds);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006214 m_errorMonitor->VerifyFound();
Tobin Ehlisb1a87992016-05-25 16:42:47 -06006215}
6216
6217TEST_F(VkLayerTest, DynamicStencilReadNotBound) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006218 TEST_DESCRIPTION("Run a simple draw calls to validate failure when Stencil Read dynamic "
6219 "state is required but not correctly bound.");
Cody Northropc31a84f2016-08-22 10:41:47 -06006220
6221 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisa5200ef2016-05-03 10:34:08 -06006222 // Dynamic stencil read mask
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006223 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
6224 "Dynamic stencil read mask state not set for this command buffer");
6225 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailStencilReadMask);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006226 m_errorMonitor->VerifyFound();
Tobin Ehlisb1a87992016-05-25 16:42:47 -06006227}
6228
6229TEST_F(VkLayerTest, DynamicStencilWriteNotBound) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006230 TEST_DESCRIPTION("Run a simple draw calls to validate failure when Stencil Write dynamic"
6231 " state is required but not correctly bound.");
Cody Northropc31a84f2016-08-22 10:41:47 -06006232
6233 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisa5200ef2016-05-03 10:34:08 -06006234 // Dynamic stencil write mask
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006235 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
6236 "Dynamic stencil write mask state not set for this command buffer");
6237 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailStencilWriteMask);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006238 m_errorMonitor->VerifyFound();
Tobin Ehlisb1a87992016-05-25 16:42:47 -06006239}
6240
6241TEST_F(VkLayerTest, DynamicStencilRefNotBound) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006242 TEST_DESCRIPTION("Run a simple draw calls to validate failure when Stencil Ref dynamic "
6243 "state is required but not correctly bound.");
Cody Northropc31a84f2016-08-22 10:41:47 -06006244
6245 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisa5200ef2016-05-03 10:34:08 -06006246 // Dynamic stencil reference
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006247 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
6248 "Dynamic stencil reference state not set for this command buffer");
6249 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailStencilReference);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006250 m_errorMonitor->VerifyFound();
Tobin Ehlis963a4042015-09-29 08:18:34 -06006251}
6252
Tobin Ehlis379ba3b2016-07-19 11:22:29 -06006253TEST_F(VkLayerTest, IndexBufferNotBound) {
6254 TEST_DESCRIPTION("Run an indexed draw call without an index buffer bound.");
Cody Northropc31a84f2016-08-22 10:41:47 -06006255
6256 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006257 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
6258 "Index buffer object not bound to this command buffer when Indexed ");
6259 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailIndexBuffer);
Tobin Ehlis379ba3b2016-07-19 11:22:29 -06006260 m_errorMonitor->VerifyFound();
6261}
6262
Karl Schultz6addd812016-02-02 17:17:23 -07006263TEST_F(VkLayerTest, CommandBufferTwoSubmits) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006264 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
6265 "was begun w/ VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT set, but has "
6266 "been submitted");
Tobin Ehlis59278bf2015-08-18 07:10:58 -06006267
Tobin Ehlis59278bf2015-08-18 07:10:58 -06006268 ASSERT_NO_FATAL_FAILURE(InitState());
6269 ASSERT_NO_FATAL_FAILURE(InitViewport());
6270 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
6271
Karl Schultz6addd812016-02-02 17:17:23 -07006272 // We luck out b/c by default the framework creates CB w/ the
6273 // VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT set
Tobin Ehlis59278bf2015-08-18 07:10:58 -06006274 BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006275 m_commandBuffer->ClearAllBuffers(m_clear_color, m_depth_clear_color, m_stencil_clear_color, NULL);
Tobin Ehlis59278bf2015-08-18 07:10:58 -06006276 EndCommandBuffer();
6277
Tobin Ehlis59278bf2015-08-18 07:10:58 -06006278 // Bypass framework since it does the waits automatically
6279 VkResult err = VK_SUCCESS;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06006280 VkSubmitInfo submit_info;
Chia-I Wuf9be13c2015-10-26 20:37:06 +08006281 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
6282 submit_info.pNext = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08006283 submit_info.waitSemaphoreCount = 0;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06006284 submit_info.pWaitSemaphores = NULL;
Jon Ashburn7f9716c2015-12-30 16:42:50 -07006285 submit_info.pWaitDstStageMask = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08006286 submit_info.commandBufferCount = 1;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08006287 submit_info.pCommandBuffers = &m_commandBuffer->handle();
Chia-I Wud50a7d72015-10-26 20:48:51 +08006288 submit_info.signalSemaphoreCount = 0;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06006289 submit_info.pSignalSemaphores = NULL;
6290
Chris Forbes40028e22016-06-13 09:59:34 +12006291 err = vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
Karl Schultz6addd812016-02-02 17:17:23 -07006292 ASSERT_VK_SUCCESS(err);
Tobin Ehlis59278bf2015-08-18 07:10:58 -06006293
Karl Schultz6addd812016-02-02 17:17:23 -07006294 // Cause validation error by re-submitting cmd buffer that should only be
6295 // submitted once
Chris Forbes40028e22016-06-13 09:59:34 +12006296 err = vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
Tobin Ehlis59278bf2015-08-18 07:10:58 -06006297
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006298 m_errorMonitor->VerifyFound();
Tobin Ehlis59278bf2015-08-18 07:10:58 -06006299}
6300
Karl Schultz6addd812016-02-02 17:17:23 -07006301TEST_F(VkLayerTest, AllocDescriptorFromEmptyPool) {
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06006302 // Initiate Draw w/o a PSO bound
Karl Schultz6addd812016-02-02 17:17:23 -07006303 VkResult err;
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06006304
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006305 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Unable to allocate 1 descriptors of "
6306 "type "
6307 "VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER ");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06006308
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06006309 ASSERT_NO_FATAL_FAILURE(InitState());
6310 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06006311
Karl Schultz6addd812016-02-02 17:17:23 -07006312 // Create Pool w/ 1 Sampler descriptor, but try to alloc Uniform Buffer
6313 // descriptor from it
Chia-I Wu1b99bb22015-10-27 19:25:11 +08006314 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006315 ds_type_count.type = VK_DESCRIPTOR_TYPE_SAMPLER;
6316 ds_type_count.descriptorCount = 1;
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06006317
6318 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006319 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
6320 ds_pool_ci.pNext = NULL;
6321 ds_pool_ci.flags = 0;
6322 ds_pool_ci.maxSets = 1;
6323 ds_pool_ci.poolSizeCount = 1;
6324 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06006325
6326 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006327 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06006328 ASSERT_VK_SUCCESS(err);
6329
6330 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006331 dsl_binding.binding = 0;
6332 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
6333 dsl_binding.descriptorCount = 1;
6334 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
6335 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06006336
6337 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006338 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
6339 ds_layout_ci.pNext = NULL;
6340 ds_layout_ci.bindingCount = 1;
6341 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06006342
6343 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006344 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06006345 ASSERT_VK_SUCCESS(err);
6346
6347 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08006348 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08006349 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07006350 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06006351 alloc_info.descriptorPool = ds_pool;
6352 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006353 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06006354
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006355 m_errorMonitor->VerifyFound();
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06006356
Chia-I Wuf7458c52015-10-26 21:10:41 +08006357 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
6358 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06006359}
6360
Karl Schultz6addd812016-02-02 17:17:23 -07006361TEST_F(VkLayerTest, FreeDescriptorFromOneShotPool) {
6362 VkResult err;
Tobin Ehlise735c692015-10-08 13:13:50 -06006363
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006364 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
6365 "It is invalid to call vkFreeDescriptorSets() with a pool created "
6366 "without setting VK_DESCRIPTOR_POOL_CREATE_FREE_DESCRIPTOR_SET_BIT.");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06006367
Tobin Ehlise735c692015-10-08 13:13:50 -06006368 ASSERT_NO_FATAL_FAILURE(InitState());
6369 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlise735c692015-10-08 13:13:50 -06006370
Chia-I Wu1b99bb22015-10-27 19:25:11 +08006371 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006372 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
6373 ds_type_count.descriptorCount = 1;
Tobin Ehlise735c692015-10-08 13:13:50 -06006374
6375 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006376 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
6377 ds_pool_ci.pNext = NULL;
6378 ds_pool_ci.maxSets = 1;
6379 ds_pool_ci.poolSizeCount = 1;
6380 ds_pool_ci.flags = 0;
6381 // Not specifying VK_DESCRIPTOR_POOL_CREATE_FREE_DESCRIPTOR_SET_BIT means
6382 // app can only call vkResetDescriptorPool on this pool.;
6383 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlise735c692015-10-08 13:13:50 -06006384
6385 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006386 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlise735c692015-10-08 13:13:50 -06006387 ASSERT_VK_SUCCESS(err);
6388
6389 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006390 dsl_binding.binding = 0;
6391 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
6392 dsl_binding.descriptorCount = 1;
6393 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
6394 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlise735c692015-10-08 13:13:50 -06006395
6396 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006397 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
6398 ds_layout_ci.pNext = NULL;
6399 ds_layout_ci.bindingCount = 1;
6400 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlise735c692015-10-08 13:13:50 -06006401
6402 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006403 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlise735c692015-10-08 13:13:50 -06006404 ASSERT_VK_SUCCESS(err);
6405
6406 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08006407 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08006408 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07006409 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06006410 alloc_info.descriptorPool = ds_pool;
6411 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006412 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlise735c692015-10-08 13:13:50 -06006413 ASSERT_VK_SUCCESS(err);
6414
6415 err = vkFreeDescriptorSets(m_device->device(), ds_pool, 1, &descriptorSet);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006416 m_errorMonitor->VerifyFound();
Tobin Ehlise735c692015-10-08 13:13:50 -06006417
Chia-I Wuf7458c52015-10-26 21:10:41 +08006418 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
6419 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlise735c692015-10-08 13:13:50 -06006420}
6421
Karl Schultz6addd812016-02-02 17:17:23 -07006422TEST_F(VkLayerTest, InvalidDescriptorPool) {
Karl Schultzbdb75952016-04-19 11:36:49 -06006423 // Attempt to clear Descriptor Pool with bad object.
6424 // ObjectTracker should catch this.
Cody Northropc31a84f2016-08-22 10:41:47 -06006425
6426 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006427 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Invalid Descriptor Pool Object 0xbaad6001");
Mark Lobodzinski02bf89d2016-05-10 14:45:13 -06006428 uint64_t fake_pool_handle = 0xbaad6001;
6429 VkDescriptorPool bad_pool = reinterpret_cast<VkDescriptorPool &>(fake_pool_handle);
6430 vkResetDescriptorPool(device(), bad_pool, 0);
Karl Schultzbdb75952016-04-19 11:36:49 -06006431 m_errorMonitor->VerifyFound();
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06006432}
6433
Karl Schultz6addd812016-02-02 17:17:23 -07006434TEST_F(VkLayerTest, InvalidDescriptorSet) {
Karl Schultzbdb75952016-04-19 11:36:49 -06006435 // Attempt to bind an invalid Descriptor Set to a valid Command Buffer
6436 // ObjectTracker should catch this.
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06006437 // Create a valid cmd buffer
Karl Schultzbdb75952016-04-19 11:36:49 -06006438 // call vkCmdBindDescriptorSets w/ false Descriptor Set
Mark Lobodzinski02bf89d2016-05-10 14:45:13 -06006439
6440 uint64_t fake_set_handle = 0xbaad6001;
6441 VkDescriptorSet bad_set = reinterpret_cast<VkDescriptorSet &>(fake_set_handle);
Karl Schultzbdb75952016-04-19 11:36:49 -06006442 VkResult err;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006443 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Invalid Descriptor Set Object 0xbaad6001");
Karl Schultzbdb75952016-04-19 11:36:49 -06006444
6445 ASSERT_NO_FATAL_FAILURE(InitState());
6446
6447 VkDescriptorSetLayoutBinding layout_bindings[1] = {};
6448 layout_bindings[0].binding = 0;
6449 layout_bindings[0].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
6450 layout_bindings[0].descriptorCount = 1;
6451 layout_bindings[0].stageFlags = VK_SHADER_STAGE_VERTEX_BIT;
6452 layout_bindings[0].pImmutableSamplers = NULL;
6453
6454 VkDescriptorSetLayout descriptor_set_layout;
6455 VkDescriptorSetLayoutCreateInfo dslci = {};
6456 dslci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
6457 dslci.pNext = NULL;
6458 dslci.bindingCount = 1;
6459 dslci.pBindings = layout_bindings;
6460 err = vkCreateDescriptorSetLayout(device(), &dslci, NULL, &descriptor_set_layout);
Karl Schultz5cb21112016-04-21 17:17:40 -06006461 ASSERT_VK_SUCCESS(err);
Karl Schultzbdb75952016-04-19 11:36:49 -06006462
6463 VkPipelineLayout pipeline_layout;
6464 VkPipelineLayoutCreateInfo plci = {};
6465 plci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
6466 plci.pNext = NULL;
6467 plci.setLayoutCount = 1;
6468 plci.pSetLayouts = &descriptor_set_layout;
6469 err = vkCreatePipelineLayout(device(), &plci, NULL, &pipeline_layout);
Karl Schultz5cb21112016-04-21 17:17:40 -06006470 ASSERT_VK_SUCCESS(err);
Karl Schultzbdb75952016-04-19 11:36:49 -06006471
6472 BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006473 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1, &bad_set, 0,
6474 NULL);
Karl Schultzbdb75952016-04-19 11:36:49 -06006475 m_errorMonitor->VerifyFound();
6476 EndCommandBuffer();
6477 vkDestroyPipelineLayout(device(), pipeline_layout, NULL);
6478 vkDestroyDescriptorSetLayout(device(), descriptor_set_layout, NULL);
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06006479}
6480
Karl Schultz6addd812016-02-02 17:17:23 -07006481TEST_F(VkLayerTest, InvalidDescriptorSetLayout) {
Karl Schultzbdb75952016-04-19 11:36:49 -06006482 // Attempt to create a Pipeline Layout with an invalid Descriptor Set Layout.
6483 // ObjectTracker should catch this.
Mark Lobodzinski02bf89d2016-05-10 14:45:13 -06006484 uint64_t fake_layout_handle = 0xbaad6001;
6485 VkDescriptorSetLayout bad_layout = reinterpret_cast<VkDescriptorSetLayout &>(fake_layout_handle);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006486 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Invalid Descriptor Set Layout Object 0xbaad6001");
Cody Northropc31a84f2016-08-22 10:41:47 -06006487 ASSERT_NO_FATAL_FAILURE(InitState());
Karl Schultzbdb75952016-04-19 11:36:49 -06006488 VkPipelineLayout pipeline_layout;
6489 VkPipelineLayoutCreateInfo plci = {};
6490 plci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
6491 plci.pNext = NULL;
6492 plci.setLayoutCount = 1;
6493 plci.pSetLayouts = &bad_layout;
6494 vkCreatePipelineLayout(device(), &plci, NULL, &pipeline_layout);
6495
6496 m_errorMonitor->VerifyFound();
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06006497}
6498
Mark Muellerd4914412016-06-13 17:52:06 -06006499TEST_F(VkLayerTest, WriteDescriptorSetIntegrityCheck) {
6500 TEST_DESCRIPTION("This test verifies some requirements of chapter 13.2.3 of the Vulkan Spec "
6501 "1) A uniform buffer update must have a valid buffer index."
6502 "2) When using an array of descriptors in a single WriteDescriptor,"
6503 " the descriptor types and stageflags must all be the same."
6504 "3) Immutable Sampler state must match across descriptors");
6505
6506 const char *invalid_BufferInfo_ErrorMessage =
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006507 "vkUpdateDescriptorSets: if pDescriptorWrites[0].descriptorType is VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, "
6508 "VK_DESCRIPTOR_TYPE_STORAGE_BUFFER, VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC or "
6509 "VK_DESCRIPTOR_TYPE_STORAGE_BUFFER_DYNAMIC, pDescriptorWrites[0].pBufferInfo must not be NULL";
6510 const char *stateFlag_ErrorMessage = "Attempting write update to descriptor set ";
6511 const char *immutable_ErrorMessage = "Attempting write update to descriptor set ";
Mark Muellerd4914412016-06-13 17:52:06 -06006512
Mark Muellerd4914412016-06-13 17:52:06 -06006513 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, invalid_BufferInfo_ErrorMessage);
6514
6515 ASSERT_NO_FATAL_FAILURE(InitState());
6516 VkDescriptorPoolSize ds_type_count[4] = {};
6517 ds_type_count[0].type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
6518 ds_type_count[0].descriptorCount = 1;
6519 ds_type_count[1].type = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
6520 ds_type_count[1].descriptorCount = 1;
6521 ds_type_count[2].type = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
6522 ds_type_count[2].descriptorCount = 1;
6523 ds_type_count[3].type = VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT;
6524 ds_type_count[3].descriptorCount = 1;
6525
6526 VkDescriptorPoolCreateInfo ds_pool_ci = {};
6527 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
6528 ds_pool_ci.maxSets = 1;
6529 ds_pool_ci.poolSizeCount = sizeof(ds_type_count) / sizeof(VkDescriptorPoolSize);
6530 ds_pool_ci.pPoolSizes = ds_type_count;
6531
6532 VkDescriptorPool ds_pool;
6533 VkResult err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
6534 ASSERT_VK_SUCCESS(err);
6535
Mark Muellerb9896722016-06-16 09:54:29 -06006536 VkDescriptorSetLayoutBinding layout_binding[3] = {};
Mark Muellerd4914412016-06-13 17:52:06 -06006537 layout_binding[0].binding = 0;
6538 layout_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
6539 layout_binding[0].descriptorCount = 1;
6540 layout_binding[0].stageFlags = VK_SHADER_STAGE_ALL;
6541 layout_binding[0].pImmutableSamplers = NULL;
6542
6543 layout_binding[1].binding = 1;
6544 layout_binding[1].descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
6545 layout_binding[1].descriptorCount = 1;
6546 layout_binding[1].stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
6547 layout_binding[1].pImmutableSamplers = NULL;
6548
6549 VkSamplerCreateInfo sampler_ci = {};
6550 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
6551 sampler_ci.pNext = NULL;
6552 sampler_ci.magFilter = VK_FILTER_NEAREST;
6553 sampler_ci.minFilter = VK_FILTER_NEAREST;
6554 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
6555 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
6556 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
6557 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
6558 sampler_ci.mipLodBias = 1.0;
6559 sampler_ci.anisotropyEnable = VK_FALSE;
6560 sampler_ci.maxAnisotropy = 1;
6561 sampler_ci.compareEnable = VK_FALSE;
6562 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
6563 sampler_ci.minLod = 1.0;
6564 sampler_ci.maxLod = 1.0;
6565 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
6566 sampler_ci.unnormalizedCoordinates = VK_FALSE;
6567 VkSampler sampler;
6568
6569 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
6570 ASSERT_VK_SUCCESS(err);
6571
6572 layout_binding[2].binding = 2;
6573 layout_binding[2].descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
6574 layout_binding[2].descriptorCount = 1;
6575 layout_binding[2].stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
6576 layout_binding[2].pImmutableSamplers = static_cast<VkSampler *>(&sampler);
6577
Mark Muellerd4914412016-06-13 17:52:06 -06006578 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
6579 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
6580 ds_layout_ci.bindingCount = sizeof(layout_binding) / sizeof(VkDescriptorSetLayoutBinding);
6581 ds_layout_ci.pBindings = layout_binding;
6582 VkDescriptorSetLayout ds_layout;
6583 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
6584 ASSERT_VK_SUCCESS(err);
6585
6586 VkDescriptorSetAllocateInfo alloc_info = {};
6587 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
6588 alloc_info.descriptorSetCount = 1;
6589 alloc_info.descriptorPool = ds_pool;
6590 alloc_info.pSetLayouts = &ds_layout;
6591 VkDescriptorSet descriptorSet;
6592 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
6593 ASSERT_VK_SUCCESS(err);
6594
6595 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
6596 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
6597 pipeline_layout_ci.pNext = NULL;
6598 pipeline_layout_ci.setLayoutCount = 1;
6599 pipeline_layout_ci.pSetLayouts = &ds_layout;
6600
6601 VkPipelineLayout pipeline_layout;
6602 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
6603 ASSERT_VK_SUCCESS(err);
6604
Mark Mueller5c838ce2016-06-16 09:54:29 -06006605 VkWriteDescriptorSet descriptor_write = {};
Mark Muellerd4914412016-06-13 17:52:06 -06006606 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
6607 descriptor_write.dstSet = descriptorSet;
6608 descriptor_write.dstBinding = 0;
6609 descriptor_write.descriptorCount = 1;
6610 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
6611
Mark Mueller5c838ce2016-06-16 09:54:29 -06006612 // 1) The uniform buffer is intentionally invalid here
Mark Muellerd4914412016-06-13 17:52:06 -06006613 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
6614 m_errorMonitor->VerifyFound();
6615
6616 // Create a buffer to update the descriptor with
6617 uint32_t qfi = 0;
6618 VkBufferCreateInfo buffCI = {};
6619 buffCI.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
6620 buffCI.size = 1024;
6621 buffCI.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
6622 buffCI.queueFamilyIndexCount = 1;
6623 buffCI.pQueueFamilyIndices = &qfi;
6624
6625 VkBuffer dyub;
6626 err = vkCreateBuffer(m_device->device(), &buffCI, NULL, &dyub);
6627 ASSERT_VK_SUCCESS(err);
6628 VkDescriptorBufferInfo buffInfo = {};
6629 buffInfo.buffer = dyub;
6630 buffInfo.offset = 0;
6631 buffInfo.range = 1024;
6632
6633 descriptor_write.pBufferInfo = &buffInfo;
6634 descriptor_write.descriptorCount = 2;
6635
Mark Mueller5c838ce2016-06-16 09:54:29 -06006636 // 2) The stateFlags don't match between the first and second descriptor
Mark Muellerd4914412016-06-13 17:52:06 -06006637 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, stateFlag_ErrorMessage);
6638 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
6639 m_errorMonitor->VerifyFound();
6640
Mark Mueller5c838ce2016-06-16 09:54:29 -06006641 // 3) The second descriptor has a null_ptr pImmutableSamplers and
6642 // the third descriptor contains an immutable sampler
Mark Muellerd4914412016-06-13 17:52:06 -06006643 descriptor_write.dstBinding = 1;
6644 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
Mark Mueller5c838ce2016-06-16 09:54:29 -06006645
Mark Mueller5c838ce2016-06-16 09:54:29 -06006646 // Make pImageInfo index non-null to avoid complaints of it missing
6647 VkDescriptorImageInfo imageInfo = {};
6648 imageInfo.imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
6649 descriptor_write.pImageInfo = &imageInfo;
Mark Muellerd4914412016-06-13 17:52:06 -06006650 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, immutable_ErrorMessage);
6651 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
6652 m_errorMonitor->VerifyFound();
6653
Mark Muellerd4914412016-06-13 17:52:06 -06006654 vkDestroyBuffer(m_device->device(), dyub, NULL);
6655 vkDestroySampler(m_device->device(), sampler, NULL);
6656 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
6657 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
6658 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
6659}
6660
Tobin Ehlis0283c4d2016-06-28 17:57:07 -06006661TEST_F(VkLayerTest, InvalidCmdBufferBufferDestroyed) {
6662 TEST_DESCRIPTION("Attempt to draw with a command buffer that is invalid "
6663 "due to a buffer dependency being destroyed.");
6664 ASSERT_NO_FATAL_FAILURE(InitState());
6665
6666 VkImageObj image(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006667 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 -06006668 VK_IMAGE_TILING_OPTIMAL, 0);
6669 ASSERT_TRUE(image.initialized());
6670
6671 VkBuffer buffer;
6672 VkDeviceMemory mem;
6673 VkMemoryRequirements mem_reqs;
6674
6675 VkBufferCreateInfo buf_info = {};
6676 buf_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
6677 buf_info.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
6678 buf_info.size = 256;
6679 buf_info.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
6680 VkResult err = vkCreateBuffer(m_device->device(), &buf_info, NULL, &buffer);
6681 ASSERT_VK_SUCCESS(err);
6682
6683 vkGetBufferMemoryRequirements(m_device->device(), buffer, &mem_reqs);
6684
6685 VkMemoryAllocateInfo alloc_info = {};
6686 alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
6687 alloc_info.allocationSize = 256;
6688 bool pass = false;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006689 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 -06006690 if (!pass) {
6691 vkDestroyBuffer(m_device->device(), buffer, NULL);
6692 return;
6693 }
6694 err = vkAllocateMemory(m_device->device(), &alloc_info, NULL, &mem);
6695 ASSERT_VK_SUCCESS(err);
6696
6697 err = vkBindBufferMemory(m_device->device(), buffer, mem, 0);
6698 ASSERT_VK_SUCCESS(err);
6699
6700 VkBufferImageCopy region = {};
6701 region.bufferRowLength = 128;
6702 region.bufferImageHeight = 128;
6703 region.imageSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
6704
6705 region.imageSubresource.layerCount = 1;
6706 region.imageExtent.height = 4;
6707 region.imageExtent.width = 4;
6708 region.imageExtent.depth = 1;
6709 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006710 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer, image.handle(), VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1,
6711 &region);
Tobin Ehlis0283c4d2016-06-28 17:57:07 -06006712 m_commandBuffer->EndCommandBuffer();
6713
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006714 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " that is invalid because bound buffer ");
Tobin Ehlis0283c4d2016-06-28 17:57:07 -06006715 // Destroy buffer dependency prior to submit to cause ERROR
6716 vkDestroyBuffer(m_device->device(), buffer, NULL);
6717
6718 VkSubmitInfo submit_info = {};
6719 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
6720 submit_info.commandBufferCount = 1;
6721 submit_info.pCommandBuffers = &m_commandBuffer->handle();
6722 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
6723
6724 m_errorMonitor->VerifyFound();
6725 vkFreeMemory(m_device->handle(), mem, NULL);
6726}
6727
Tobin Ehlis11c8cea2016-06-28 17:44:21 -06006728TEST_F(VkLayerTest, InvalidCmdBufferImageDestroyed) {
6729 TEST_DESCRIPTION("Attempt to draw with a command buffer that is invalid "
6730 "due to an image dependency being destroyed.");
6731 ASSERT_NO_FATAL_FAILURE(InitState());
6732
6733 VkImage image;
6734 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
6735 VkImageCreateInfo image_create_info = {};
6736 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
6737 image_create_info.pNext = NULL;
6738 image_create_info.imageType = VK_IMAGE_TYPE_2D;
6739 image_create_info.format = tex_format;
6740 image_create_info.extent.width = 32;
6741 image_create_info.extent.height = 32;
6742 image_create_info.extent.depth = 1;
6743 image_create_info.mipLevels = 1;
6744 image_create_info.arrayLayers = 1;
6745 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
6746 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006747 image_create_info.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT;
Tobin Ehlis11c8cea2016-06-28 17:44:21 -06006748 image_create_info.flags = 0;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006749 VkResult err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
Tobin Ehlis11c8cea2016-06-28 17:44:21 -06006750 ASSERT_VK_SUCCESS(err);
Tobin Ehlis3d09fd52016-07-06 08:12:56 -06006751 // Have to bind memory to image before recording cmd in cmd buffer using it
6752 VkMemoryRequirements mem_reqs;
6753 VkDeviceMemory image_mem;
6754 bool pass;
6755 VkMemoryAllocateInfo mem_alloc = {};
6756 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
6757 mem_alloc.pNext = NULL;
6758 mem_alloc.memoryTypeIndex = 0;
6759 vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs);
6760 mem_alloc.allocationSize = mem_reqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006761 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0);
Tobin Ehlis3d09fd52016-07-06 08:12:56 -06006762 ASSERT_TRUE(pass);
6763 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &image_mem);
6764 ASSERT_VK_SUCCESS(err);
6765 err = vkBindImageMemory(m_device->device(), image, image_mem, 0);
6766 ASSERT_VK_SUCCESS(err);
Tobin Ehlis11c8cea2016-06-28 17:44:21 -06006767
Tobin Ehlis11c8cea2016-06-28 17:44:21 -06006768 m_commandBuffer->BeginCommandBuffer();
Tobin Ehlis764d7072016-07-01 12:54:29 -06006769 VkClearColorValue ccv;
6770 ccv.float32[0] = 1.0f;
6771 ccv.float32[1] = 1.0f;
6772 ccv.float32[2] = 1.0f;
6773 ccv.float32[3] = 1.0f;
6774 VkImageSubresourceRange isr = {};
6775 isr.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Tobin Ehlis3d09fd52016-07-06 08:12:56 -06006776 isr.baseArrayLayer = 0;
6777 isr.baseMipLevel = 0;
Tobin Ehlis764d7072016-07-01 12:54:29 -06006778 isr.layerCount = 1;
6779 isr.levelCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006780 vkCmdClearColorImage(m_commandBuffer->GetBufferHandle(), image, VK_IMAGE_LAYOUT_GENERAL, &ccv, 1, &isr);
Tobin Ehlis11c8cea2016-06-28 17:44:21 -06006781 m_commandBuffer->EndCommandBuffer();
6782
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006783 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " that is invalid because bound image ");
Tobin Ehlis11c8cea2016-06-28 17:44:21 -06006784 // Destroy image dependency prior to submit to cause ERROR
6785 vkDestroyImage(m_device->device(), image, NULL);
6786
6787 VkSubmitInfo submit_info = {};
6788 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
6789 submit_info.commandBufferCount = 1;
6790 submit_info.pCommandBuffers = &m_commandBuffer->handle();
6791 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
6792
6793 m_errorMonitor->VerifyFound();
Tobin Ehlis3d09fd52016-07-06 08:12:56 -06006794 vkFreeMemory(m_device->device(), image_mem, nullptr);
Tobin Ehlis11c8cea2016-06-28 17:44:21 -06006795}
6796
Tobin Ehlis59f68ab2016-09-06 21:59:07 -06006797TEST_F(VkLayerTest, InvalidCmdBufferFramebufferImageDestroyed) {
6798 TEST_DESCRIPTION("Attempt to draw with a command buffer that is invalid "
6799 "due to a framebuffer image dependency being destroyed.");
6800 VkFormatProperties format_properties;
6801 VkResult err = VK_SUCCESS;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006802 vkGetPhysicalDeviceFormatProperties(gpu(), VK_FORMAT_B8G8R8A8_UNORM, &format_properties);
6803 if (!(format_properties.optimalTilingFeatures & VK_FORMAT_FEATURE_SAMPLED_IMAGE_BIT)) {
Tobin Ehlis59f68ab2016-09-06 21:59:07 -06006804 return;
6805 }
6806
6807 ASSERT_NO_FATAL_FAILURE(InitState());
6808 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
6809
6810 VkImageCreateInfo image_ci = {};
6811 image_ci.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
6812 image_ci.pNext = NULL;
6813 image_ci.imageType = VK_IMAGE_TYPE_2D;
6814 image_ci.format = VK_FORMAT_B8G8R8A8_UNORM;
6815 image_ci.extent.width = 32;
6816 image_ci.extent.height = 32;
6817 image_ci.extent.depth = 1;
6818 image_ci.mipLevels = 1;
6819 image_ci.arrayLayers = 1;
6820 image_ci.samples = VK_SAMPLE_COUNT_1_BIT;
6821 image_ci.tiling = VK_IMAGE_TILING_OPTIMAL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006822 image_ci.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_SAMPLED_BIT;
Tobin Ehlis59f68ab2016-09-06 21:59:07 -06006823 image_ci.initialLayout = VK_IMAGE_LAYOUT_UNDEFINED;
6824 image_ci.flags = 0;
6825 VkImage image;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006826 ASSERT_VK_SUCCESS(vkCreateImage(m_device->handle(), &image_ci, NULL, &image));
Tobin Ehlis59f68ab2016-09-06 21:59:07 -06006827
6828 VkMemoryRequirements memory_reqs;
6829 VkDeviceMemory image_memory;
6830 bool pass;
6831 VkMemoryAllocateInfo memory_info = {};
6832 memory_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
6833 memory_info.pNext = NULL;
6834 memory_info.allocationSize = 0;
6835 memory_info.memoryTypeIndex = 0;
6836 vkGetImageMemoryRequirements(m_device->device(), image, &memory_reqs);
6837 memory_info.allocationSize = memory_reqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006838 pass = m_device->phy().set_memory_type(memory_reqs.memoryTypeBits, &memory_info, 0);
Tobin Ehlis59f68ab2016-09-06 21:59:07 -06006839 ASSERT_TRUE(pass);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006840 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &image_memory);
Tobin Ehlis59f68ab2016-09-06 21:59:07 -06006841 ASSERT_VK_SUCCESS(err);
6842 err = vkBindImageMemory(m_device->device(), image, image_memory, 0);
6843 ASSERT_VK_SUCCESS(err);
6844
6845 VkImageViewCreateInfo ivci = {
6846 VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO,
6847 nullptr,
6848 0,
6849 image,
6850 VK_IMAGE_VIEW_TYPE_2D,
6851 VK_FORMAT_B8G8R8A8_UNORM,
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006852 {VK_COMPONENT_SWIZZLE_R, VK_COMPONENT_SWIZZLE_G, VK_COMPONENT_SWIZZLE_B, VK_COMPONENT_SWIZZLE_A},
Tobin Ehlis59f68ab2016-09-06 21:59:07 -06006853 {VK_IMAGE_ASPECT_COLOR_BIT, 0, 1, 0, 1},
6854 };
6855 VkImageView view;
6856 err = vkCreateImageView(m_device->device(), &ivci, nullptr, &view);
6857 ASSERT_VK_SUCCESS(err);
6858
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006859 VkFramebufferCreateInfo fci = {VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr, 0, m_renderPass, 1, &view, 32, 32, 1};
Tobin Ehlis59f68ab2016-09-06 21:59:07 -06006860 VkFramebuffer fb;
6861 err = vkCreateFramebuffer(m_device->device(), &fci, nullptr, &fb);
6862 ASSERT_VK_SUCCESS(err);
6863
6864 // Just use default renderpass with our framebuffer
6865 m_renderPassBeginInfo.framebuffer = fb;
6866 // Create Null cmd buffer for submit
6867 BeginCommandBuffer();
6868 EndCommandBuffer();
6869 // Destroy image attached to framebuffer to invalidate cmd buffer
6870 vkDestroyImage(m_device->device(), image, NULL);
6871 // Now attempt to submit cmd buffer and verify error
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006872 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " that is invalid because bound image ");
Tobin Ehlis59f68ab2016-09-06 21:59:07 -06006873 QueueCommandBuffer(false);
6874 m_errorMonitor->VerifyFound();
6875
6876 vkDestroyFramebuffer(m_device->device(), fb, nullptr);
6877 vkDestroyImageView(m_device->device(), view, nullptr);
6878 vkFreeMemory(m_device->device(), image_memory, nullptr);
6879}
6880
Mark Lobodzinskia4df3632016-07-14 09:57:41 -06006881TEST_F(VkLayerTest, ImageMemoryNotBound) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006882 TEST_DESCRIPTION("Attempt to draw with an image which has not had memory bound to it.");
Mark Lobodzinskia4df3632016-07-14 09:57:41 -06006883 ASSERT_NO_FATAL_FAILURE(InitState());
6884
6885 VkImage image;
6886 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
6887 VkImageCreateInfo image_create_info = {};
6888 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
6889 image_create_info.pNext = NULL;
6890 image_create_info.imageType = VK_IMAGE_TYPE_2D;
6891 image_create_info.format = tex_format;
6892 image_create_info.extent.width = 32;
6893 image_create_info.extent.height = 32;
6894 image_create_info.extent.depth = 1;
6895 image_create_info.mipLevels = 1;
6896 image_create_info.arrayLayers = 1;
6897 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
6898 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006899 image_create_info.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT;
Mark Lobodzinskia4df3632016-07-14 09:57:41 -06006900 image_create_info.flags = 0;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006901 VkResult err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
Mark Lobodzinskia4df3632016-07-14 09:57:41 -06006902 ASSERT_VK_SUCCESS(err);
6903 // Have to bind memory to image before recording cmd in cmd buffer using it
6904 VkMemoryRequirements mem_reqs;
6905 VkDeviceMemory image_mem;
6906 bool pass;
6907 VkMemoryAllocateInfo mem_alloc = {};
6908 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
6909 mem_alloc.pNext = NULL;
6910 mem_alloc.memoryTypeIndex = 0;
6911 vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs);
6912 mem_alloc.allocationSize = mem_reqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006913 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0);
Mark Lobodzinskia4df3632016-07-14 09:57:41 -06006914 ASSERT_TRUE(pass);
6915 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &image_mem);
6916 ASSERT_VK_SUCCESS(err);
6917
6918 // Introduce error, do not call vkBindImageMemory(m_device->device(), image,
6919 // image_mem, 0);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006920 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "used without first calling vkBindImageMemory");
Mark Lobodzinskia4df3632016-07-14 09:57:41 -06006921
6922 m_commandBuffer->BeginCommandBuffer();
6923 VkClearColorValue ccv;
6924 ccv.float32[0] = 1.0f;
6925 ccv.float32[1] = 1.0f;
6926 ccv.float32[2] = 1.0f;
6927 ccv.float32[3] = 1.0f;
6928 VkImageSubresourceRange isr = {};
6929 isr.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
6930 isr.baseArrayLayer = 0;
6931 isr.baseMipLevel = 0;
6932 isr.layerCount = 1;
6933 isr.levelCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006934 vkCmdClearColorImage(m_commandBuffer->GetBufferHandle(), image, VK_IMAGE_LAYOUT_GENERAL, &ccv, 1, &isr);
Mark Lobodzinskia4df3632016-07-14 09:57:41 -06006935 m_commandBuffer->EndCommandBuffer();
6936
6937 m_errorMonitor->VerifyFound();
6938 vkDestroyImage(m_device->device(), image, NULL);
6939 vkFreeMemory(m_device->device(), image_mem, nullptr);
6940}
6941
6942TEST_F(VkLayerTest, BufferMemoryNotBound) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006943 TEST_DESCRIPTION("Attempt to copy from a buffer which has not had memory bound to it.");
Mark Lobodzinskia4df3632016-07-14 09:57:41 -06006944 ASSERT_NO_FATAL_FAILURE(InitState());
6945
6946 VkImageObj image(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006947 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 -06006948 VK_IMAGE_TILING_OPTIMAL, 0);
6949 ASSERT_TRUE(image.initialized());
6950
6951 VkBuffer buffer;
6952 VkDeviceMemory mem;
6953 VkMemoryRequirements mem_reqs;
6954
6955 VkBufferCreateInfo buf_info = {};
6956 buf_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
6957 buf_info.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
6958 buf_info.size = 256;
6959 buf_info.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
6960 VkResult err = vkCreateBuffer(m_device->device(), &buf_info, NULL, &buffer);
6961 ASSERT_VK_SUCCESS(err);
6962
6963 vkGetBufferMemoryRequirements(m_device->device(), buffer, &mem_reqs);
6964
6965 VkMemoryAllocateInfo alloc_info = {};
6966 alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
6967 alloc_info.allocationSize = 256;
6968 bool pass = false;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006969 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 -06006970 if (!pass) {
6971 vkDestroyBuffer(m_device->device(), buffer, NULL);
6972 return;
6973 }
6974 err = vkAllocateMemory(m_device->device(), &alloc_info, NULL, &mem);
6975 ASSERT_VK_SUCCESS(err);
6976
6977 // Introduce failure by not calling vkBindBufferMemory(m_device->device(),
6978 // buffer, mem, 0);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006979 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "used without first calling vkBindBufferMemory");
Mark Lobodzinskia4df3632016-07-14 09:57:41 -06006980 VkBufferImageCopy region = {};
6981 region.bufferRowLength = 128;
6982 region.bufferImageHeight = 128;
6983 region.imageSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
6984
6985 region.imageSubresource.layerCount = 1;
6986 region.imageExtent.height = 4;
6987 region.imageExtent.width = 4;
6988 region.imageExtent.depth = 1;
6989 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006990 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer, image.handle(), VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1,
6991 &region);
Mark Lobodzinskia4df3632016-07-14 09:57:41 -06006992 m_commandBuffer->EndCommandBuffer();
6993
6994 m_errorMonitor->VerifyFound();
6995
6996 vkDestroyBuffer(m_device->device(), buffer, NULL);
6997 vkFreeMemory(m_device->handle(), mem, NULL);
6998}
6999
Tobin Ehlis85940f52016-07-07 16:57:21 -06007000TEST_F(VkLayerTest, InvalidCmdBufferEventDestroyed) {
7001 TEST_DESCRIPTION("Attempt to draw with a command buffer that is invalid "
7002 "due to an event dependency being destroyed.");
7003 ASSERT_NO_FATAL_FAILURE(InitState());
7004
7005 VkEvent event;
7006 VkEventCreateInfo evci = {};
7007 evci.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO;
7008 VkResult result = vkCreateEvent(m_device->device(), &evci, NULL, &event);
7009 ASSERT_VK_SUCCESS(result);
7010
7011 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007012 vkCmdSetEvent(m_commandBuffer->GetBufferHandle(), event, VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT);
Tobin Ehlis85940f52016-07-07 16:57:21 -06007013 m_commandBuffer->EndCommandBuffer();
7014
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007015 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " that is invalid because bound event ");
Tobin Ehlis85940f52016-07-07 16:57:21 -06007016 // Destroy event dependency prior to submit to cause ERROR
7017 vkDestroyEvent(m_device->device(), event, NULL);
7018
7019 VkSubmitInfo submit_info = {};
7020 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
7021 submit_info.commandBufferCount = 1;
7022 submit_info.pCommandBuffers = &m_commandBuffer->handle();
7023 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
7024
7025 m_errorMonitor->VerifyFound();
7026}
7027
Tobin Ehlisdbea7552016-07-08 14:33:31 -06007028TEST_F(VkLayerTest, InvalidCmdBufferQueryPoolDestroyed) {
7029 TEST_DESCRIPTION("Attempt to draw with a command buffer that is invalid "
7030 "due to a query pool dependency being destroyed.");
7031 ASSERT_NO_FATAL_FAILURE(InitState());
7032
7033 VkQueryPool query_pool;
7034 VkQueryPoolCreateInfo qpci{};
7035 qpci.sType = VK_STRUCTURE_TYPE_QUERY_POOL_CREATE_INFO;
7036 qpci.queryType = VK_QUERY_TYPE_TIMESTAMP;
7037 qpci.queryCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007038 VkResult result = vkCreateQueryPool(m_device->device(), &qpci, nullptr, &query_pool);
Tobin Ehlisdbea7552016-07-08 14:33:31 -06007039 ASSERT_VK_SUCCESS(result);
7040
7041 m_commandBuffer->BeginCommandBuffer();
7042 vkCmdResetQueryPool(m_commandBuffer->GetBufferHandle(), query_pool, 0, 1);
7043 m_commandBuffer->EndCommandBuffer();
7044
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007045 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " that is invalid because bound query pool ");
Tobin Ehlisdbea7552016-07-08 14:33:31 -06007046 // Destroy query pool dependency prior to submit to cause ERROR
7047 vkDestroyQueryPool(m_device->device(), query_pool, NULL);
7048
7049 VkSubmitInfo submit_info = {};
7050 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
7051 submit_info.commandBufferCount = 1;
7052 submit_info.pCommandBuffers = &m_commandBuffer->handle();
7053 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
7054
7055 m_errorMonitor->VerifyFound();
7056}
7057
Tobin Ehlis24130d92016-07-08 15:50:53 -06007058TEST_F(VkLayerTest, InvalidCmdBufferPipelineDestroyed) {
7059 TEST_DESCRIPTION("Attempt to draw with a command buffer that is invalid "
7060 "due to a pipeline dependency being destroyed.");
7061 ASSERT_NO_FATAL_FAILURE(InitState());
7062 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
7063
7064 VkResult err;
7065
7066 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
7067 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
7068
7069 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007070 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis24130d92016-07-08 15:50:53 -06007071 ASSERT_VK_SUCCESS(err);
7072
7073 VkPipelineViewportStateCreateInfo vp_state_ci = {};
7074 vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
7075 vp_state_ci.viewportCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007076 VkViewport vp = {}; // Just need dummy vp to point to
Tobin Ehlis52b504f2016-07-19 13:25:12 -06007077 vp_state_ci.pViewports = &vp;
Tobin Ehlis24130d92016-07-08 15:50:53 -06007078 vp_state_ci.scissorCount = 1;
7079 VkRect2D scissors = {}; // Dummy scissors to point to
7080 vp_state_ci.pScissors = &scissors;
7081 // No dynamic state
7082 VkPipelineDynamicStateCreateInfo dyn_state_ci = {};
7083 dyn_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_DYNAMIC_STATE_CREATE_INFO;
7084
7085 VkPipelineShaderStageCreateInfo shaderStages[2];
7086 memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo));
7087
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007088 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
7089 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this); // We shouldn't need a fragment shader
7090 // but add it to be able to run on more devices
Tobin Ehlis24130d92016-07-08 15:50:53 -06007091 shaderStages[0] = vs.GetStageCreateInfo();
7092 shaderStages[1] = fs.GetStageCreateInfo();
7093
7094 VkPipelineVertexInputStateCreateInfo vi_ci = {};
7095 vi_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
7096
7097 VkPipelineInputAssemblyStateCreateInfo ia_ci = {};
7098 ia_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
7099 ia_ci.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP;
7100
7101 VkPipelineRasterizationStateCreateInfo rs_ci = {};
7102 rs_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
7103
7104 VkPipelineColorBlendAttachmentState att = {};
7105 att.blendEnable = VK_FALSE;
7106 att.colorWriteMask = 0xf;
7107
7108 VkPipelineColorBlendStateCreateInfo cb_ci = {};
7109 cb_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO;
7110 cb_ci.attachmentCount = 1;
7111 cb_ci.pAttachments = &att;
7112
7113 VkGraphicsPipelineCreateInfo gp_ci = {};
7114 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
7115 gp_ci.stageCount = 2;
7116 gp_ci.pStages = shaderStages;
7117 gp_ci.pVertexInputState = &vi_ci;
7118 gp_ci.pInputAssemblyState = &ia_ci;
7119 gp_ci.pViewportState = &vp_state_ci;
7120 gp_ci.pRasterizationState = &rs_ci;
7121 gp_ci.pColorBlendState = &cb_ci;
7122 gp_ci.pDynamicState = &dyn_state_ci;
7123 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
7124 gp_ci.layout = pipeline_layout;
7125 gp_ci.renderPass = renderPass();
7126
7127 VkPipelineCacheCreateInfo pc_ci = {};
7128 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
7129
7130 VkPipeline pipeline;
7131 VkPipelineCache pipelineCache;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007132 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Tobin Ehlis24130d92016-07-08 15:50:53 -06007133 ASSERT_VK_SUCCESS(err);
7134
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007135 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Tobin Ehlis24130d92016-07-08 15:50:53 -06007136 ASSERT_VK_SUCCESS(err);
7137
7138 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007139 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline);
Tobin Ehlis24130d92016-07-08 15:50:53 -06007140 m_commandBuffer->EndCommandBuffer();
7141 // Now destroy pipeline in order to cause error when submitting
7142 vkDestroyPipeline(m_device->device(), pipeline, nullptr);
7143
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007144 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " that is invalid because bound pipeline ");
Tobin Ehlis24130d92016-07-08 15:50:53 -06007145
7146 VkSubmitInfo submit_info = {};
7147 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
7148 submit_info.commandBufferCount = 1;
7149 submit_info.pCommandBuffers = &m_commandBuffer->handle();
7150 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
7151
7152 m_errorMonitor->VerifyFound();
7153 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
7154 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
7155}
7156
Tobin Ehlis31289162016-08-17 14:57:58 -06007157TEST_F(VkLayerTest, InvalidCmdBufferDescriptorSetBufferDestroyed) {
7158 TEST_DESCRIPTION("Attempt to draw with a command buffer that is invalid "
7159 "due to a bound descriptor set with a buffer dependency "
7160 "being destroyed.");
7161 ASSERT_NO_FATAL_FAILURE(InitState());
7162 ASSERT_NO_FATAL_FAILURE(InitViewport());
7163 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
7164
7165 VkDescriptorPoolSize ds_type_count = {};
7166 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
7167 ds_type_count.descriptorCount = 1;
7168
7169 VkDescriptorPoolCreateInfo ds_pool_ci = {};
7170 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
7171 ds_pool_ci.pNext = NULL;
7172 ds_pool_ci.maxSets = 1;
7173 ds_pool_ci.poolSizeCount = 1;
7174 ds_pool_ci.pPoolSizes = &ds_type_count;
7175
7176 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007177 VkResult err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis31289162016-08-17 14:57:58 -06007178 ASSERT_VK_SUCCESS(err);
7179
7180 VkDescriptorSetLayoutBinding dsl_binding = {};
7181 dsl_binding.binding = 0;
7182 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
7183 dsl_binding.descriptorCount = 1;
7184 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
7185 dsl_binding.pImmutableSamplers = NULL;
7186
7187 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
7188 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
7189 ds_layout_ci.pNext = NULL;
7190 ds_layout_ci.bindingCount = 1;
7191 ds_layout_ci.pBindings = &dsl_binding;
7192 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007193 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis31289162016-08-17 14:57:58 -06007194 ASSERT_VK_SUCCESS(err);
7195
7196 VkDescriptorSet descriptorSet;
7197 VkDescriptorSetAllocateInfo alloc_info = {};
7198 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
7199 alloc_info.descriptorSetCount = 1;
7200 alloc_info.descriptorPool = ds_pool;
7201 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007202 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis31289162016-08-17 14:57:58 -06007203 ASSERT_VK_SUCCESS(err);
7204
7205 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
7206 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
7207 pipeline_layout_ci.pNext = NULL;
7208 pipeline_layout_ci.setLayoutCount = 1;
7209 pipeline_layout_ci.pSetLayouts = &ds_layout;
7210
7211 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007212 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis31289162016-08-17 14:57:58 -06007213 ASSERT_VK_SUCCESS(err);
7214
7215 // Create a buffer to update the descriptor with
7216 uint32_t qfi = 0;
7217 VkBufferCreateInfo buffCI = {};
7218 buffCI.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
7219 buffCI.size = 1024;
7220 buffCI.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
7221 buffCI.queueFamilyIndexCount = 1;
7222 buffCI.pQueueFamilyIndices = &qfi;
7223
7224 VkBuffer buffer;
7225 err = vkCreateBuffer(m_device->device(), &buffCI, NULL, &buffer);
7226 ASSERT_VK_SUCCESS(err);
7227 // Allocate memory and bind to buffer so we can make it to the appropriate
7228 // error
7229 VkMemoryAllocateInfo mem_alloc = {};
7230 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
7231 mem_alloc.pNext = NULL;
7232 mem_alloc.allocationSize = 1024;
7233 mem_alloc.memoryTypeIndex = 0;
7234
7235 VkMemoryRequirements memReqs;
7236 vkGetBufferMemoryRequirements(m_device->device(), buffer, &memReqs);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007237 bool pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &mem_alloc, 0);
Tobin Ehlis31289162016-08-17 14:57:58 -06007238 if (!pass) {
7239 vkDestroyBuffer(m_device->device(), buffer, NULL);
7240 return;
7241 }
7242
7243 VkDeviceMemory mem;
7244 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem);
7245 ASSERT_VK_SUCCESS(err);
7246 err = vkBindBufferMemory(m_device->device(), buffer, mem, 0);
7247 ASSERT_VK_SUCCESS(err);
7248 // Correctly update descriptor to avoid "NOT_UPDATED" error
7249 VkDescriptorBufferInfo buffInfo = {};
7250 buffInfo.buffer = buffer;
7251 buffInfo.offset = 0;
7252 buffInfo.range = 1024;
7253
7254 VkWriteDescriptorSet descriptor_write;
7255 memset(&descriptor_write, 0, sizeof(descriptor_write));
7256 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
7257 descriptor_write.dstSet = descriptorSet;
7258 descriptor_write.dstBinding = 0;
7259 descriptor_write.descriptorCount = 1;
7260 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
7261 descriptor_write.pBufferInfo = &buffInfo;
7262
7263 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
7264
7265 // Create PSO to be used for draw-time errors below
7266 char const *vsSource = "#version 450\n"
7267 "\n"
7268 "out gl_PerVertex { \n"
7269 " vec4 gl_Position;\n"
7270 "};\n"
7271 "void main(){\n"
7272 " gl_Position = vec4(1);\n"
7273 "}\n";
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007274 char const *fsSource = "#version 450\n"
7275 "\n"
7276 "layout(location=0) out vec4 x;\n"
7277 "layout(set=0) layout(binding=0) uniform foo { int x; int y; } bar;\n"
7278 "void main(){\n"
7279 " x = vec4(bar.y);\n"
7280 "}\n";
Tobin Ehlis31289162016-08-17 14:57:58 -06007281 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
7282 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
7283 VkPipelineObj pipe(m_device);
7284 pipe.AddShader(&vs);
7285 pipe.AddShader(&fs);
7286 pipe.AddColorAttachment();
7287 pipe.CreateVKPipeline(pipeline_layout, renderPass());
7288
7289 BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007290 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
7291 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
7292 &descriptorSet, 0, NULL);
Tobin Ehlis31289162016-08-17 14:57:58 -06007293 Draw(1, 0, 0, 0);
7294 EndCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007295 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " that is invalid because bound buffer ");
Tobin Ehlis31289162016-08-17 14:57:58 -06007296 // Destroy buffer should invalidate the cmd buffer, causing error on submit
7297 vkDestroyBuffer(m_device->device(), buffer, NULL);
7298 // Attempt to submit cmd buffer
7299 VkSubmitInfo submit_info = {};
7300 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
7301 submit_info.commandBufferCount = 1;
7302 submit_info.pCommandBuffers = &m_commandBuffer->handle();
7303 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
7304 m_errorMonitor->VerifyFound();
7305 // Cleanup
7306 vkFreeMemory(m_device->device(), mem, NULL);
7307
7308 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
7309 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
7310 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
7311}
7312
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06007313TEST_F(VkLayerTest, InvalidCmdBufferDescriptorSetImageSamplerDestroyed) {
7314 TEST_DESCRIPTION("Attempt to draw with a command buffer that is invalid "
7315 "due to a bound descriptor sets with a combined image "
7316 "sampler having their image, sampler, and descriptor set "
7317 "each respectively destroyed and then attempting to "
Mark Mueller917f6bc2016-08-30 10:57:19 -06007318 "submit associated cmd buffers. Attempt to destroy a "
7319 "DescriptorSet that is in use.");
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06007320 ASSERT_NO_FATAL_FAILURE(InitState());
7321 ASSERT_NO_FATAL_FAILURE(InitViewport());
7322 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
7323
7324 VkDescriptorPoolSize ds_type_count = {};
7325 ds_type_count.type = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
7326 ds_type_count.descriptorCount = 1;
7327
7328 VkDescriptorPoolCreateInfo ds_pool_ci = {};
7329 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
7330 ds_pool_ci.pNext = NULL;
7331 ds_pool_ci.maxSets = 1;
7332 ds_pool_ci.poolSizeCount = 1;
7333 ds_pool_ci.pPoolSizes = &ds_type_count;
7334
7335 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007336 VkResult err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06007337 ASSERT_VK_SUCCESS(err);
7338
7339 VkDescriptorSetLayoutBinding dsl_binding = {};
7340 dsl_binding.binding = 0;
7341 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
7342 dsl_binding.descriptorCount = 1;
7343 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
7344 dsl_binding.pImmutableSamplers = NULL;
7345
7346 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
7347 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
7348 ds_layout_ci.pNext = NULL;
7349 ds_layout_ci.bindingCount = 1;
7350 ds_layout_ci.pBindings = &dsl_binding;
7351 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007352 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06007353 ASSERT_VK_SUCCESS(err);
7354
7355 VkDescriptorSet descriptorSet;
7356 VkDescriptorSetAllocateInfo alloc_info = {};
7357 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
7358 alloc_info.descriptorSetCount = 1;
7359 alloc_info.descriptorPool = ds_pool;
7360 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007361 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06007362 ASSERT_VK_SUCCESS(err);
7363
7364 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
7365 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
7366 pipeline_layout_ci.pNext = NULL;
7367 pipeline_layout_ci.setLayoutCount = 1;
7368 pipeline_layout_ci.pSetLayouts = &ds_layout;
7369
7370 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007371 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06007372 ASSERT_VK_SUCCESS(err);
7373
7374 // Create images to update the descriptor with
7375 VkImage image;
7376 VkImage image2;
7377 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
7378 const int32_t tex_width = 32;
7379 const int32_t tex_height = 32;
7380 VkImageCreateInfo image_create_info = {};
7381 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
7382 image_create_info.pNext = NULL;
7383 image_create_info.imageType = VK_IMAGE_TYPE_2D;
7384 image_create_info.format = tex_format;
7385 image_create_info.extent.width = tex_width;
7386 image_create_info.extent.height = tex_height;
7387 image_create_info.extent.depth = 1;
7388 image_create_info.mipLevels = 1;
7389 image_create_info.arrayLayers = 1;
7390 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
7391 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
7392 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
7393 image_create_info.flags = 0;
7394 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
7395 ASSERT_VK_SUCCESS(err);
7396 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image2);
7397 ASSERT_VK_SUCCESS(err);
7398
7399 VkMemoryRequirements memory_reqs;
7400 VkDeviceMemory image_memory;
7401 bool pass;
7402 VkMemoryAllocateInfo memory_info = {};
7403 memory_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
7404 memory_info.pNext = NULL;
7405 memory_info.allocationSize = 0;
7406 memory_info.memoryTypeIndex = 0;
7407 vkGetImageMemoryRequirements(m_device->device(), image, &memory_reqs);
7408 // Allocate enough memory for both images
7409 memory_info.allocationSize = memory_reqs.size * 2;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007410 pass = m_device->phy().set_memory_type(memory_reqs.memoryTypeBits, &memory_info, 0);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06007411 ASSERT_TRUE(pass);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007412 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &image_memory);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06007413 ASSERT_VK_SUCCESS(err);
7414 err = vkBindImageMemory(m_device->device(), image, image_memory, 0);
7415 ASSERT_VK_SUCCESS(err);
7416 // Bind second image to memory right after first image
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007417 err = vkBindImageMemory(m_device->device(), image2, image_memory, memory_reqs.size);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06007418 ASSERT_VK_SUCCESS(err);
7419
7420 VkImageViewCreateInfo image_view_create_info = {};
7421 image_view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
7422 image_view_create_info.image = image;
7423 image_view_create_info.viewType = VK_IMAGE_VIEW_TYPE_2D;
7424 image_view_create_info.format = tex_format;
7425 image_view_create_info.subresourceRange.layerCount = 1;
7426 image_view_create_info.subresourceRange.baseMipLevel = 0;
7427 image_view_create_info.subresourceRange.levelCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007428 image_view_create_info.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06007429
7430 VkImageView view;
7431 VkImageView view2;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007432 err = vkCreateImageView(m_device->device(), &image_view_create_info, NULL, &view);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06007433 ASSERT_VK_SUCCESS(err);
7434 image_view_create_info.image = image2;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007435 err = vkCreateImageView(m_device->device(), &image_view_create_info, NULL, &view2);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06007436 ASSERT_VK_SUCCESS(err);
7437 // Create Samplers
7438 VkSamplerCreateInfo sampler_ci = {};
7439 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
7440 sampler_ci.pNext = NULL;
7441 sampler_ci.magFilter = VK_FILTER_NEAREST;
7442 sampler_ci.minFilter = VK_FILTER_NEAREST;
7443 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
7444 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
7445 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
7446 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
7447 sampler_ci.mipLodBias = 1.0;
7448 sampler_ci.anisotropyEnable = VK_FALSE;
7449 sampler_ci.maxAnisotropy = 1;
7450 sampler_ci.compareEnable = VK_FALSE;
7451 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
7452 sampler_ci.minLod = 1.0;
7453 sampler_ci.maxLod = 1.0;
7454 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
7455 sampler_ci.unnormalizedCoordinates = VK_FALSE;
7456 VkSampler sampler;
7457 VkSampler sampler2;
7458 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
7459 ASSERT_VK_SUCCESS(err);
7460 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler2);
7461 ASSERT_VK_SUCCESS(err);
7462 // Update descriptor with image and sampler
7463 VkDescriptorImageInfo img_info = {};
7464 img_info.sampler = sampler;
7465 img_info.imageView = view;
7466 img_info.imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
7467
7468 VkWriteDescriptorSet descriptor_write;
7469 memset(&descriptor_write, 0, sizeof(descriptor_write));
7470 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
7471 descriptor_write.dstSet = descriptorSet;
7472 descriptor_write.dstBinding = 0;
7473 descriptor_write.descriptorCount = 1;
7474 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
7475 descriptor_write.pImageInfo = &img_info;
7476
7477 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
7478
7479 // Create PSO to be used for draw-time errors below
7480 char const *vsSource = "#version 450\n"
7481 "\n"
7482 "out gl_PerVertex { \n"
7483 " vec4 gl_Position;\n"
7484 "};\n"
7485 "void main(){\n"
7486 " gl_Position = vec4(1);\n"
7487 "}\n";
7488 char const *fsSource = "#version 450\n"
7489 "\n"
7490 "layout(set=0, binding=0) uniform sampler2D s;\n"
7491 "layout(location=0) out vec4 x;\n"
7492 "void main(){\n"
7493 " x = texture(s, vec2(1));\n"
7494 "}\n";
7495 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
7496 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
7497 VkPipelineObj pipe(m_device);
7498 pipe.AddShader(&vs);
7499 pipe.AddShader(&fs);
7500 pipe.AddColorAttachment();
7501 pipe.CreateVKPipeline(pipeline_layout, renderPass());
7502
7503 // First error case is destroying sampler prior to cmd buffer submission
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007504 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Cannot submit cmd buffer using deleted sampler ");
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06007505 BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007506 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
7507 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
7508 &descriptorSet, 0, NULL);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06007509 Draw(1, 0, 0, 0);
7510 EndCommandBuffer();
7511 // Destroy sampler invalidates the cmd buffer, causing error on submit
7512 vkDestroySampler(m_device->device(), sampler, NULL);
7513 // Attempt to submit cmd buffer
7514 VkSubmitInfo submit_info = {};
7515 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
7516 submit_info.commandBufferCount = 1;
7517 submit_info.pCommandBuffers = &m_commandBuffer->handle();
7518 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
7519 m_errorMonitor->VerifyFound();
7520 // Now re-update descriptor with valid sampler and delete image
7521 img_info.sampler = sampler2;
7522 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007523 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " that is invalid because bound image ");
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06007524 BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007525 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
7526 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
7527 &descriptorSet, 0, NULL);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06007528 Draw(1, 0, 0, 0);
7529 EndCommandBuffer();
7530 // Destroy image invalidates the cmd buffer, causing error on submit
7531 vkDestroyImage(m_device->device(), image, NULL);
7532 // Attempt to submit cmd buffer
7533 submit_info = {};
7534 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
7535 submit_info.commandBufferCount = 1;
7536 submit_info.pCommandBuffers = &m_commandBuffer->handle();
7537 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
7538 m_errorMonitor->VerifyFound();
7539 // Now update descriptor to be valid, but then free descriptor
7540 img_info.imageView = view2;
7541 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007542 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " that is invalid because bound descriptor set ");
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06007543 BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007544 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
7545 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
7546 &descriptorSet, 0, NULL);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06007547 Draw(1, 0, 0, 0);
7548 EndCommandBuffer();
7549 // Destroy descriptor set invalidates the cb, causing error on submit
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007550 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Cannot call vkFreeDescriptorSets() on descriptor set 0x");
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06007551 vkFreeDescriptorSets(m_device->device(), ds_pool, 1, &descriptorSet);
Mark Mueller917f6bc2016-08-30 10:57:19 -06007552 m_errorMonitor->VerifyFound();
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06007553 // Attempt to submit cmd buffer
7554 submit_info = {};
7555 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
7556 submit_info.commandBufferCount = 1;
7557 submit_info.pCommandBuffers = &m_commandBuffer->handle();
7558 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
7559 m_errorMonitor->VerifyFound();
7560 // Cleanup
7561 vkFreeMemory(m_device->device(), image_memory, NULL);
7562 vkDestroySampler(m_device->device(), sampler2, NULL);
7563 vkDestroyImage(m_device->device(), image2, NULL);
7564 vkDestroyImageView(m_device->device(), view, NULL);
7565 vkDestroyImageView(m_device->device(), view2, NULL);
7566 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
7567 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
7568 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
7569}
7570
Karl Schultz6addd812016-02-02 17:17:23 -07007571TEST_F(VkLayerTest, InvalidPipeline) {
Karl Schultzbdb75952016-04-19 11:36:49 -06007572 // Attempt to bind an invalid Pipeline to a valid Command Buffer
7573 // ObjectTracker should catch this.
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06007574 // Create a valid cmd buffer
7575 // call vkCmdBindPipeline w/ false Pipeline
Mark Lobodzinski02bf89d2016-05-10 14:45:13 -06007576 uint64_t fake_pipeline_handle = 0xbaad6001;
7577 VkPipeline bad_pipeline = reinterpret_cast<VkPipeline &>(fake_pipeline_handle);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007578 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Invalid Pipeline Object 0xbaad6001");
Karl Schultzbdb75952016-04-19 11:36:49 -06007579 ASSERT_NO_FATAL_FAILURE(InitState());
7580 BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007581 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, bad_pipeline);
Karl Schultzbdb75952016-04-19 11:36:49 -06007582 m_errorMonitor->VerifyFound();
Tobin Ehlisb8b6b272016-05-02 13:26:06 -06007583 // Now issue a draw call with no pipeline bound
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007584 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 -06007585
Tobin Ehlisb8b6b272016-05-02 13:26:06 -06007586 BeginCommandBuffer();
7587 Draw(1, 0, 0, 0);
7588 m_errorMonitor->VerifyFound();
7589 // Finally same check once more but with Dispatch/Compute
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!");
Tobin Ehlisb8b6b272016-05-02 13:26:06 -06007591 BeginCommandBuffer();
7592 vkCmdDispatch(m_commandBuffer->GetBufferHandle(), 0, 0, 0);
7593 m_errorMonitor->VerifyFound();
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06007594}
7595
Karl Schultz6addd812016-02-02 17:17:23 -07007596TEST_F(VkLayerTest, DescriptorSetNotUpdated) {
Tobin Ehlis5a5f5ef2016-08-17 13:56:55 -06007597 TEST_DESCRIPTION("Bind a descriptor set that hasn't been updated.");
Karl Schultz6addd812016-02-02 17:17:23 -07007598 VkResult err;
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06007599
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007600 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT, " bound but it was never updated. ");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06007601
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06007602 ASSERT_NO_FATAL_FAILURE(InitState());
Mike Stroyan713b2d72015-08-04 10:49:29 -06007603 ASSERT_NO_FATAL_FAILURE(InitViewport());
7604 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chia-I Wu1b99bb22015-10-27 19:25:11 +08007605 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007606 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
7607 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -06007608
7609 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007610 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
7611 ds_pool_ci.pNext = NULL;
7612 ds_pool_ci.maxSets = 1;
7613 ds_pool_ci.poolSizeCount = 1;
7614 ds_pool_ci.pPoolSizes = &ds_type_count;
Mike Stroyan713b2d72015-08-04 10:49:29 -06007615
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06007616 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007617 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06007618 ASSERT_VK_SUCCESS(err);
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06007619
Tony Barboureb254902015-07-15 12:50:33 -06007620 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007621 dsl_binding.binding = 0;
7622 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
7623 dsl_binding.descriptorCount = 1;
7624 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
7625 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06007626
Tony Barboureb254902015-07-15 12:50:33 -06007627 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007628 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
7629 ds_layout_ci.pNext = NULL;
7630 ds_layout_ci.bindingCount = 1;
7631 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06007632 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007633 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06007634 ASSERT_VK_SUCCESS(err);
7635
7636 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08007637 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08007638 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07007639 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06007640 alloc_info.descriptorPool = ds_pool;
7641 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007642 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06007643 ASSERT_VK_SUCCESS(err);
7644
Tony Barboureb254902015-07-15 12:50:33 -06007645 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007646 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
7647 pipeline_layout_ci.pNext = NULL;
7648 pipeline_layout_ci.setLayoutCount = 1;
7649 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06007650
7651 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007652 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06007653 ASSERT_VK_SUCCESS(err);
7654
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007655 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
Karl Schultzbdb75952016-04-19 11:36:49 -06007656 // We shouldn't need a fragment shader but add it to be able to run
Karl Schultz6addd812016-02-02 17:17:23 -07007657 // on more devices
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007658 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06007659
Tony Barbourc95e4ac2015-08-04 17:05:26 -06007660 VkPipelineObj pipe(m_device);
7661 pipe.AddShader(&vs);
Tony Barbour1c94d372015-08-06 11:21:08 -06007662 pipe.AddShader(&fs);
Mark Youngc89c6312016-03-31 16:03:20 -06007663 pipe.AddColorAttachment();
Tony Barbourc95e4ac2015-08-04 17:05:26 -06007664 pipe.CreateVKPipeline(pipeline_layout, renderPass());
Tony Barbourfe3351b2015-07-28 10:17:20 -06007665
7666 BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007667 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
7668 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
7669 &descriptorSet, 0, NULL);
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06007670
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007671 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06007672
Chia-I Wuf7458c52015-10-26 21:10:41 +08007673 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
7674 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
7675 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06007676}
7677
Karl Schultz6addd812016-02-02 17:17:23 -07007678TEST_F(VkLayerTest, InvalidBufferViewObject) {
Tobin Ehlisba31cab2015-11-02 15:24:32 -07007679 // Create a single TEXEL_BUFFER descriptor and send it an invalid bufferView
Karl Schultz6addd812016-02-02 17:17:23 -07007680 VkResult err;
Tobin Ehlisba31cab2015-11-02 15:24:32 -07007681
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007682 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Attempted write update to texel buffer "
7683 "descriptor with invalid buffer view");
Tobin Ehlisba31cab2015-11-02 15:24:32 -07007684
7685 ASSERT_NO_FATAL_FAILURE(InitState());
7686 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007687 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER;
7688 ds_type_count.descriptorCount = 1;
Tobin Ehlisba31cab2015-11-02 15:24:32 -07007689
7690 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007691 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
7692 ds_pool_ci.pNext = NULL;
7693 ds_pool_ci.maxSets = 1;
7694 ds_pool_ci.poolSizeCount = 1;
7695 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlisba31cab2015-11-02 15:24:32 -07007696
7697 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007698 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlisba31cab2015-11-02 15:24:32 -07007699 ASSERT_VK_SUCCESS(err);
7700
7701 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007702 dsl_binding.binding = 0;
7703 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER;
7704 dsl_binding.descriptorCount = 1;
7705 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
7706 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlisba31cab2015-11-02 15:24:32 -07007707
7708 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007709 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
7710 ds_layout_ci.pNext = NULL;
7711 ds_layout_ci.bindingCount = 1;
7712 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlisba31cab2015-11-02 15:24:32 -07007713 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007714 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlisba31cab2015-11-02 15:24:32 -07007715 ASSERT_VK_SUCCESS(err);
7716
7717 VkDescriptorSet descriptorSet;
7718 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08007719 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07007720 alloc_info.descriptorSetCount = 1;
Tobin Ehlisba31cab2015-11-02 15:24:32 -07007721 alloc_info.descriptorPool = ds_pool;
7722 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007723 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlisba31cab2015-11-02 15:24:32 -07007724 ASSERT_VK_SUCCESS(err);
7725
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007726 VkBufferView view = (VkBufferView)((size_t)0xbaadbeef); // invalid bufferView object
Tobin Ehlisba31cab2015-11-02 15:24:32 -07007727 VkWriteDescriptorSet descriptor_write;
7728 memset(&descriptor_write, 0, sizeof(descriptor_write));
7729 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
7730 descriptor_write.dstSet = descriptorSet;
7731 descriptor_write.dstBinding = 0;
7732 descriptor_write.descriptorCount = 1;
7733 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER;
7734 descriptor_write.pTexelBufferView = &view;
7735
7736 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
7737
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007738 m_errorMonitor->VerifyFound();
Tobin Ehlisba31cab2015-11-02 15:24:32 -07007739
7740 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
7741 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
7742}
7743
Mark Youngd339ba32016-05-30 13:28:35 -06007744TEST_F(VkLayerTest, CreateBufferViewNoMemoryBoundToBuffer) {
7745 TEST_DESCRIPTION("Attempt to create a buffer view with a buffer that has"
7746 " no memory bound to it.");
7747
7748 VkResult err;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007749 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "used without first calling vkBindBufferMemory");
Mark Youngd339ba32016-05-30 13:28:35 -06007750
7751 ASSERT_NO_FATAL_FAILURE(InitState());
7752
7753 // Create a buffer with no bound memory and then attempt to create
7754 // a buffer view.
7755 VkBufferCreateInfo buff_ci = {};
7756 buff_ci.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
7757 buff_ci.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
7758 buff_ci.size = 256;
7759 buff_ci.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
7760 VkBuffer buffer;
7761 err = vkCreateBuffer(m_device->device(), &buff_ci, NULL, &buffer);
7762 ASSERT_VK_SUCCESS(err);
7763
7764 VkBufferViewCreateInfo buff_view_ci = {};
7765 buff_view_ci.sType = VK_STRUCTURE_TYPE_BUFFER_VIEW_CREATE_INFO;
7766 buff_view_ci.buffer = buffer;
7767 buff_view_ci.format = VK_FORMAT_R8_UNORM;
7768 buff_view_ci.range = VK_WHOLE_SIZE;
7769 VkBufferView buff_view;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007770 err = vkCreateBufferView(m_device->device(), &buff_view_ci, NULL, &buff_view);
Mark Youngd339ba32016-05-30 13:28:35 -06007771
7772 m_errorMonitor->VerifyFound();
7773 vkDestroyBuffer(m_device->device(), buffer, NULL);
7774 // If last error is success, it still created the view, so delete it.
7775 if (err == VK_SUCCESS) {
7776 vkDestroyBufferView(m_device->device(), buff_view, NULL);
7777 }
7778}
7779
Karl Schultz6addd812016-02-02 17:17:23 -07007780TEST_F(VkLayerTest, InvalidDynamicOffsetCases) {
7781 // Create a descriptorSet w/ dynamic descriptor and then hit 3 offset error
7782 // cases:
Tobin Ehlisf6585052015-12-17 11:48:42 -07007783 // 1. No dynamicOffset supplied
7784 // 2. Too many dynamicOffsets supplied
7785 // 3. Dynamic offset oversteps buffer being updated
Karl Schultz6addd812016-02-02 17:17:23 -07007786 VkResult err;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007787 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " requires 1 dynamicOffsets, but only "
7788 "0 dynamicOffsets are left in "
7789 "pDynamicOffsets ");
Tobin Ehlis49f903e2015-11-04 13:30:34 -07007790
7791 ASSERT_NO_FATAL_FAILURE(InitState());
7792 ASSERT_NO_FATAL_FAILURE(InitViewport());
7793 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
7794
7795 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007796 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
7797 ds_type_count.descriptorCount = 1;
Tobin Ehlis49f903e2015-11-04 13:30:34 -07007798
7799 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007800 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
7801 ds_pool_ci.pNext = NULL;
7802 ds_pool_ci.maxSets = 1;
7803 ds_pool_ci.poolSizeCount = 1;
7804 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlis49f903e2015-11-04 13:30:34 -07007805
7806 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007807 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis49f903e2015-11-04 13:30:34 -07007808 ASSERT_VK_SUCCESS(err);
7809
7810 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007811 dsl_binding.binding = 0;
7812 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
7813 dsl_binding.descriptorCount = 1;
7814 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
7815 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis49f903e2015-11-04 13:30:34 -07007816
7817 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007818 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
7819 ds_layout_ci.pNext = NULL;
7820 ds_layout_ci.bindingCount = 1;
7821 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlis49f903e2015-11-04 13:30:34 -07007822 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007823 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis49f903e2015-11-04 13:30:34 -07007824 ASSERT_VK_SUCCESS(err);
7825
7826 VkDescriptorSet descriptorSet;
7827 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08007828 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07007829 alloc_info.descriptorSetCount = 1;
Tobin Ehlis49f903e2015-11-04 13:30:34 -07007830 alloc_info.descriptorPool = ds_pool;
7831 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007832 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis49f903e2015-11-04 13:30:34 -07007833 ASSERT_VK_SUCCESS(err);
7834
7835 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007836 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
7837 pipeline_layout_ci.pNext = NULL;
7838 pipeline_layout_ci.setLayoutCount = 1;
7839 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlis49f903e2015-11-04 13:30:34 -07007840
7841 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007842 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis49f903e2015-11-04 13:30:34 -07007843 ASSERT_VK_SUCCESS(err);
7844
7845 // Create a buffer to update the descriptor with
7846 uint32_t qfi = 0;
7847 VkBufferCreateInfo buffCI = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007848 buffCI.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
7849 buffCI.size = 1024;
7850 buffCI.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
7851 buffCI.queueFamilyIndexCount = 1;
7852 buffCI.pQueueFamilyIndices = &qfi;
Tobin Ehlis49f903e2015-11-04 13:30:34 -07007853
7854 VkBuffer dyub;
7855 err = vkCreateBuffer(m_device->device(), &buffCI, NULL, &dyub);
7856 ASSERT_VK_SUCCESS(err);
Tobin Ehlis0a43bde2016-05-03 08:31:08 -06007857 // Allocate memory and bind to buffer so we can make it to the appropriate
7858 // error
7859 VkMemoryAllocateInfo mem_alloc = {};
7860 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
7861 mem_alloc.pNext = NULL;
7862 mem_alloc.allocationSize = 1024;
Chris Forbesb6116cc2016-05-08 11:39:59 +12007863 mem_alloc.memoryTypeIndex = 0;
7864
7865 VkMemoryRequirements memReqs;
7866 vkGetBufferMemoryRequirements(m_device->device(), dyub, &memReqs);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007867 bool pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &mem_alloc, 0);
Chris Forbesb6116cc2016-05-08 11:39:59 +12007868 if (!pass) {
7869 vkDestroyBuffer(m_device->device(), dyub, NULL);
7870 return;
7871 }
7872
Tobin Ehlis0a43bde2016-05-03 08:31:08 -06007873 VkDeviceMemory mem;
7874 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem);
7875 ASSERT_VK_SUCCESS(err);
7876 err = vkBindBufferMemory(m_device->device(), dyub, mem, 0);
7877 ASSERT_VK_SUCCESS(err);
Tobin Ehlis49f903e2015-11-04 13:30:34 -07007878 // Correctly update descriptor to avoid "NOT_UPDATED" error
7879 VkDescriptorBufferInfo buffInfo = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007880 buffInfo.buffer = dyub;
7881 buffInfo.offset = 0;
7882 buffInfo.range = 1024;
Tobin Ehlis49f903e2015-11-04 13:30:34 -07007883
7884 VkWriteDescriptorSet descriptor_write;
7885 memset(&descriptor_write, 0, sizeof(descriptor_write));
7886 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
7887 descriptor_write.dstSet = descriptorSet;
7888 descriptor_write.dstBinding = 0;
7889 descriptor_write.descriptorCount = 1;
7890 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
7891 descriptor_write.pBufferInfo = &buffInfo;
7892
7893 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
7894
7895 BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007896 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
7897 &descriptorSet, 0, NULL);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007898 m_errorMonitor->VerifyFound();
Tobin Ehlisf6585052015-12-17 11:48:42 -07007899 uint32_t pDynOff[2] = {512, 756};
7900 // Now cause error b/c too many dynOffsets in array for # of dyn descriptors
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007901 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
7902 "Attempting to bind 1 descriptorSets with 1 dynamic descriptors, but ");
7903 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
7904 &descriptorSet, 2, pDynOff);
Chris Forbes7b342802016-04-07 13:20:10 +12007905 m_errorMonitor->VerifyFound();
Tobin Ehlisf6585052015-12-17 11:48:42 -07007906 // Finally cause error due to dynamicOffset being too big
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007907 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " dynamic offset 512 combined with "
7908 "offset 0 and range 1024 that "
7909 "oversteps the buffer size of 1024");
Tobin Ehlisf6585052015-12-17 11:48:42 -07007910 // Create PSO to be used for draw-time errors below
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007911 char const *vsSource = "#version 450\n"
7912 "\n"
7913 "out gl_PerVertex { \n"
7914 " vec4 gl_Position;\n"
7915 "};\n"
7916 "void main(){\n"
7917 " gl_Position = vec4(1);\n"
7918 "}\n";
7919 char const *fsSource = "#version 450\n"
7920 "\n"
7921 "layout(location=0) out vec4 x;\n"
7922 "layout(set=0) layout(binding=0) uniform foo { int x; int y; } bar;\n"
7923 "void main(){\n"
7924 " x = vec4(bar.y);\n"
7925 "}\n";
Tobin Ehlisf6585052015-12-17 11:48:42 -07007926 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
7927 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
7928 VkPipelineObj pipe(m_device);
7929 pipe.AddShader(&vs);
7930 pipe.AddShader(&fs);
7931 pipe.AddColorAttachment();
7932 pipe.CreateVKPipeline(pipeline_layout, renderPass());
7933
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007934 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Karl Schultz6addd812016-02-02 17:17:23 -07007935 // This update should succeed, but offset size of 512 will overstep buffer
7936 // /w range 1024 & size 1024
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007937 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
7938 &descriptorSet, 1, pDynOff);
Tobin Ehlisf6585052015-12-17 11:48:42 -07007939 Draw(1, 0, 0, 0);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007940 m_errorMonitor->VerifyFound();
Tobin Ehlis49f903e2015-11-04 13:30:34 -07007941
Tobin Ehlis0a43bde2016-05-03 08:31:08 -06007942 vkDestroyBuffer(m_device->device(), dyub, NULL);
Tobin Ehlis512098e2016-05-05 09:06:12 -06007943 vkFreeMemory(m_device->device(), mem, NULL);
Tobin Ehlis0a43bde2016-05-03 08:31:08 -06007944
Tobin Ehlis49f903e2015-11-04 13:30:34 -07007945 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
Tony Barbourdf4c0042016-06-01 15:55:43 -06007946 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
Tobin Ehlis49f903e2015-11-04 13:30:34 -07007947 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
7948}
7949
Tobin Ehlis8ef479c2016-07-20 16:14:49 -06007950TEST_F(VkLayerTest, DescriptorBufferUpdateNoMemoryBound) {
7951 TEST_DESCRIPTION("Attempt to update a descriptor with a non-sparse buffer "
7952 "that doesn't have memory bound");
7953 VkResult err;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007954 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " used without first calling vkBindBufferMemory.");
Tobin Ehlis8ef479c2016-07-20 16:14:49 -06007955
7956 ASSERT_NO_FATAL_FAILURE(InitState());
7957 ASSERT_NO_FATAL_FAILURE(InitViewport());
7958 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
7959
7960 VkDescriptorPoolSize ds_type_count = {};
7961 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
7962 ds_type_count.descriptorCount = 1;
7963
7964 VkDescriptorPoolCreateInfo ds_pool_ci = {};
7965 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
7966 ds_pool_ci.pNext = NULL;
7967 ds_pool_ci.maxSets = 1;
7968 ds_pool_ci.poolSizeCount = 1;
7969 ds_pool_ci.pPoolSizes = &ds_type_count;
7970
7971 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007972 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis8ef479c2016-07-20 16:14:49 -06007973 ASSERT_VK_SUCCESS(err);
7974
7975 VkDescriptorSetLayoutBinding dsl_binding = {};
7976 dsl_binding.binding = 0;
7977 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
7978 dsl_binding.descriptorCount = 1;
7979 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
7980 dsl_binding.pImmutableSamplers = NULL;
7981
7982 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
7983 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
7984 ds_layout_ci.pNext = NULL;
7985 ds_layout_ci.bindingCount = 1;
7986 ds_layout_ci.pBindings = &dsl_binding;
7987 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007988 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis8ef479c2016-07-20 16:14:49 -06007989 ASSERT_VK_SUCCESS(err);
7990
7991 VkDescriptorSet descriptorSet;
7992 VkDescriptorSetAllocateInfo alloc_info = {};
7993 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
7994 alloc_info.descriptorSetCount = 1;
7995 alloc_info.descriptorPool = ds_pool;
7996 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007997 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis8ef479c2016-07-20 16:14:49 -06007998 ASSERT_VK_SUCCESS(err);
7999
8000 // Create a buffer to update the descriptor with
8001 uint32_t qfi = 0;
8002 VkBufferCreateInfo buffCI = {};
8003 buffCI.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
8004 buffCI.size = 1024;
8005 buffCI.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
8006 buffCI.queueFamilyIndexCount = 1;
8007 buffCI.pQueueFamilyIndices = &qfi;
8008
8009 VkBuffer dyub;
8010 err = vkCreateBuffer(m_device->device(), &buffCI, NULL, &dyub);
8011 ASSERT_VK_SUCCESS(err);
8012
8013 // Attempt to update descriptor without binding memory to it
8014 VkDescriptorBufferInfo buffInfo = {};
8015 buffInfo.buffer = dyub;
8016 buffInfo.offset = 0;
8017 buffInfo.range = 1024;
8018
8019 VkWriteDescriptorSet descriptor_write;
8020 memset(&descriptor_write, 0, sizeof(descriptor_write));
8021 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
8022 descriptor_write.dstSet = descriptorSet;
8023 descriptor_write.dstBinding = 0;
8024 descriptor_write.descriptorCount = 1;
8025 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
8026 descriptor_write.pBufferInfo = &buffInfo;
8027
8028 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
8029 m_errorMonitor->VerifyFound();
8030
8031 vkDestroyBuffer(m_device->device(), dyub, NULL);
8032 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
8033 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
8034}
8035
Tobin Ehlis3a23b6a2016-02-17 10:35:18 -07008036TEST_F(VkLayerTest, InvalidPushConstants) {
Tobin Ehlis3a23b6a2016-02-17 10:35:18 -07008037 VkResult err;
Tobin Ehlis3a23b6a2016-02-17 10:35:18 -07008038 ASSERT_NO_FATAL_FAILURE(InitState());
8039 ASSERT_NO_FATAL_FAILURE(InitViewport());
8040 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
8041
Karl Schultzfc8eaf12016-05-06 13:56:42 -06008042 VkPipelineLayout pipeline_layout;
Tobin Ehlis3a23b6a2016-02-17 10:35:18 -07008043 VkPushConstantRange pc_range = {};
Tobin Ehlis3a23b6a2016-02-17 10:35:18 -07008044 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
8045 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
8046 pipeline_layout_ci.pushConstantRangeCount = 1;
8047 pipeline_layout_ci.pPushConstantRanges = &pc_range;
8048
Karl Schultzfc8eaf12016-05-06 13:56:42 -06008049 //
8050 // Check for invalid push constant ranges in pipeline layouts.
8051 //
8052 struct PipelineLayoutTestCase {
Karl Schultzc81037d2016-05-12 08:11:23 -06008053 VkPushConstantRange const range;
Karl Schultzfc8eaf12016-05-06 13:56:42 -06008054 char const *msg;
8055 };
Tobin Ehlis3a23b6a2016-02-17 10:35:18 -07008056
Karl Schultzc81037d2016-05-12 08:11:23 -06008057 const uint32_t too_big = m_device->props.limits.maxPushConstantsSize + 0x4;
8058 const std::array<PipelineLayoutTestCase, 10> range_tests = {{
8059 {{VK_SHADER_STAGE_VERTEX_BIT, 0, 0},
8060 "vkCreatePipelineLayout() call has push constants index 0 with "
8061 "size 0."},
8062 {{VK_SHADER_STAGE_VERTEX_BIT, 0, 1},
8063 "vkCreatePipelineLayout() call has push constants index 0 with "
8064 "size 1."},
8065 {{VK_SHADER_STAGE_VERTEX_BIT, 1, 1},
8066 "vkCreatePipelineLayout() call has push constants index 0 with "
8067 "size 1."},
8068 {{VK_SHADER_STAGE_VERTEX_BIT, 1, 0},
8069 "vkCreatePipelineLayout() call has push constants index 0 with "
8070 "size 0."},
8071 {{VK_SHADER_STAGE_VERTEX_BIT, 1, 4},
8072 "vkCreatePipelineLayout() call has push constants index 0 with "
8073 "offset 1. Offset must"},
8074 {{VK_SHADER_STAGE_VERTEX_BIT, 0, too_big},
8075 "vkCreatePipelineLayout() call has push constants index 0 "
8076 "with offset "},
8077 {{VK_SHADER_STAGE_VERTEX_BIT, too_big, too_big},
8078 "vkCreatePipelineLayout() call has push constants "
8079 "index 0 with offset "},
8080 {{VK_SHADER_STAGE_VERTEX_BIT, too_big, 0},
8081 "vkCreatePipelineLayout() call has push constants index 0 "
8082 "with offset "},
8083 {{VK_SHADER_STAGE_VERTEX_BIT, 0xFFFFFFF0, 0x00000020},
8084 "vkCreatePipelineLayout() call has push "
8085 "constants index 0 with offset "},
8086 {{VK_SHADER_STAGE_VERTEX_BIT, 0x00000020, 0xFFFFFFF0},
8087 "vkCreatePipelineLayout() call has push "
8088 "constants index 0 with offset "},
Karl Schultzfc8eaf12016-05-06 13:56:42 -06008089 }};
8090
8091 // Check for invalid offset and size
Karl Schultzc81037d2016-05-12 08:11:23 -06008092 for (const auto &iter : range_tests) {
8093 pc_range = iter.range;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008094 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, iter.msg);
8095 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Karl Schultzfc8eaf12016-05-06 13:56:42 -06008096 m_errorMonitor->VerifyFound();
8097 if (VK_SUCCESS == err) {
8098 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
8099 }
8100 }
8101
8102 // Check for invalid stage flag
8103 pc_range.offset = 0;
8104 pc_range.size = 16;
8105 pc_range.stageFlags = 0;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008106 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "vkCreatePipelineLayout() call has no stageFlags set.");
8107 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008108 m_errorMonitor->VerifyFound();
Karl Schultzfc8eaf12016-05-06 13:56:42 -06008109 if (VK_SUCCESS == err) {
8110 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
8111 }
8112
8113 // Check for overlapping ranges
Karl Schultzc81037d2016-05-12 08:11:23 -06008114 const uint32_t ranges_per_test = 5;
Karl Schultzfc8eaf12016-05-06 13:56:42 -06008115 struct OverlappingRangeTestCase {
Karl Schultzc81037d2016-05-12 08:11:23 -06008116 VkPushConstantRange const ranges[ranges_per_test];
Karl Schultzfc8eaf12016-05-06 13:56:42 -06008117 char const *msg;
8118 };
8119
Karl Schultzc81037d2016-05-12 08:11:23 -06008120 const std::array<OverlappingRangeTestCase, 5> overlapping_range_tests = {
Karl Schultzfc8eaf12016-05-06 13:56:42 -06008121 {{{{VK_SHADER_STAGE_VERTEX_BIT, 0, 4},
8122 {VK_SHADER_STAGE_VERTEX_BIT, 0, 4},
8123 {VK_SHADER_STAGE_VERTEX_BIT, 0, 4},
8124 {VK_SHADER_STAGE_VERTEX_BIT, 0, 4},
8125 {VK_SHADER_STAGE_VERTEX_BIT, 0, 4}},
8126 "vkCreatePipelineLayout() call has push constants with overlapping "
8127 "ranges: 0:[0, 4), 1:[0, 4)"},
8128 {
8129 {{VK_SHADER_STAGE_VERTEX_BIT, 0, 4},
8130 {VK_SHADER_STAGE_VERTEX_BIT, 4, 4},
8131 {VK_SHADER_STAGE_VERTEX_BIT, 8, 4},
8132 {VK_SHADER_STAGE_VERTEX_BIT, 12, 8},
8133 {VK_SHADER_STAGE_VERTEX_BIT, 16, 4}},
8134 "vkCreatePipelineLayout() call has push constants with "
8135 "overlapping "
8136 "ranges: 3:[12, 20), 4:[16, 20)",
8137 },
8138 {
8139 {{VK_SHADER_STAGE_VERTEX_BIT, 16, 4},
8140 {VK_SHADER_STAGE_VERTEX_BIT, 12, 8},
8141 {VK_SHADER_STAGE_VERTEX_BIT, 8, 4},
8142 {VK_SHADER_STAGE_VERTEX_BIT, 4, 4},
8143 {VK_SHADER_STAGE_VERTEX_BIT, 0, 4}},
8144 "vkCreatePipelineLayout() call has push constants with "
8145 "overlapping "
8146 "ranges: 0:[16, 20), 1:[12, 20)",
8147 },
8148 {
8149 {{VK_SHADER_STAGE_VERTEX_BIT, 16, 4},
8150 {VK_SHADER_STAGE_VERTEX_BIT, 8, 4},
8151 {VK_SHADER_STAGE_VERTEX_BIT, 4, 4},
8152 {VK_SHADER_STAGE_VERTEX_BIT, 12, 8},
8153 {VK_SHADER_STAGE_VERTEX_BIT, 0, 4}},
8154 "vkCreatePipelineLayout() call has push constants with "
8155 "overlapping "
8156 "ranges: 0:[16, 20), 3:[12, 20)",
8157 },
8158 {
8159 {{VK_SHADER_STAGE_VERTEX_BIT, 16, 4},
8160 {VK_SHADER_STAGE_VERTEX_BIT, 32, 4},
8161 {VK_SHADER_STAGE_VERTEX_BIT, 4, 96},
8162 {VK_SHADER_STAGE_VERTEX_BIT, 40, 8},
8163 {VK_SHADER_STAGE_VERTEX_BIT, 52, 4}},
8164 "vkCreatePipelineLayout() call has push constants with "
8165 "overlapping "
8166 "ranges: 0:[16, 20), 2:[4, 100)",
8167 }}};
Karl Schultzfc8eaf12016-05-06 13:56:42 -06008168
Karl Schultzc81037d2016-05-12 08:11:23 -06008169 for (const auto &iter : overlapping_range_tests) {
Karl Schultzfc8eaf12016-05-06 13:56:42 -06008170 pipeline_layout_ci.pPushConstantRanges = iter.ranges;
Karl Schultzc81037d2016-05-12 08:11:23 -06008171 pipeline_layout_ci.pushConstantRangeCount = ranges_per_test;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008172 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT, iter.msg);
8173 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Karl Schultzfc8eaf12016-05-06 13:56:42 -06008174 m_errorMonitor->VerifyFound();
8175 if (VK_SUCCESS == err) {
8176 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
8177 }
8178 }
8179
8180 // Run some positive tests to make sure overlap checking in the layer is OK
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008181 const std::array<OverlappingRangeTestCase, 2> overlapping_range_tests_pos = {{{{{VK_SHADER_STAGE_VERTEX_BIT, 0, 4},
8182 {VK_SHADER_STAGE_VERTEX_BIT, 4, 4},
8183 {VK_SHADER_STAGE_VERTEX_BIT, 8, 4},
8184 {VK_SHADER_STAGE_VERTEX_BIT, 12, 4},
8185 {VK_SHADER_STAGE_VERTEX_BIT, 16, 4}},
8186 ""},
8187 {{{VK_SHADER_STAGE_VERTEX_BIT, 92, 24},
8188 {VK_SHADER_STAGE_VERTEX_BIT, 80, 4},
8189 {VK_SHADER_STAGE_VERTEX_BIT, 64, 8},
8190 {VK_SHADER_STAGE_VERTEX_BIT, 4, 16},
8191 {VK_SHADER_STAGE_VERTEX_BIT, 0, 4}},
8192 ""}}};
Karl Schultzc81037d2016-05-12 08:11:23 -06008193 for (const auto &iter : overlapping_range_tests_pos) {
Karl Schultzfc8eaf12016-05-06 13:56:42 -06008194 pipeline_layout_ci.pPushConstantRanges = iter.ranges;
8195 m_errorMonitor->ExpectSuccess();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008196 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Karl Schultzfc8eaf12016-05-06 13:56:42 -06008197 m_errorMonitor->VerifyNotFound();
8198 if (VK_SUCCESS == err) {
8199 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
8200 }
8201 }
8202
8203 //
8204 // CmdPushConstants tests
8205 //
Karl Schultzc81037d2016-05-12 08:11:23 -06008206 const uint8_t dummy_values[100] = {};
Karl Schultzfc8eaf12016-05-06 13:56:42 -06008207
8208 // Check for invalid offset and size and if range is within layout range(s)
Karl Schultzc81037d2016-05-12 08:11:23 -06008209 const std::array<PipelineLayoutTestCase, 16> cmd_range_tests = {{
8210 {{VK_SHADER_STAGE_VERTEX_BIT, 0, 0},
8211 "vkCmdPushConstants() call has push constants with size 0. Size "
8212 "must be greater than zero and a multiple of 4."},
8213 {{VK_SHADER_STAGE_VERTEX_BIT, 0, 1},
8214 "vkCmdPushConstants() call has push constants with size 1. Size "
8215 "must be greater than zero and a multiple of 4."},
8216 {{VK_SHADER_STAGE_VERTEX_BIT, 1, 1},
8217 "vkCmdPushConstants() call has push constants with size 1. Size "
8218 "must be greater than zero and a multiple of 4."},
8219 {{VK_SHADER_STAGE_VERTEX_BIT, 1, 0},
8220 "vkCmdPushConstants() call has push constants with offset 1. "
8221 "Offset must be a multiple of 4."},
8222 {{VK_SHADER_STAGE_VERTEX_BIT, 1, 4},
8223 "vkCmdPushConstants() call has push constants with offset 1. "
8224 "Offset must be a multiple of 4."},
8225 {{VK_SHADER_STAGE_VERTEX_BIT, 0, 20},
8226 "vkCmdPushConstants() Push constant range [0, 20) with stageFlags = "
8227 "0x1 not within flag-matching ranges in pipeline layout"},
8228 {{VK_SHADER_STAGE_VERTEX_BIT, 60, 8},
8229 "vkCmdPushConstants() Push constant range [60, 68) with stageFlags = "
8230 "0x1 not within flag-matching ranges in pipeline layout"},
8231 {{VK_SHADER_STAGE_VERTEX_BIT, 76, 8},
8232 "vkCmdPushConstants() Push constant range [76, 84) with stageFlags = "
8233 "0x1 not within flag-matching ranges in pipeline layout"},
8234 {{VK_SHADER_STAGE_VERTEX_BIT, 0, 80},
8235 "vkCmdPushConstants() Push constant range [0, 80) with stageFlags = "
8236 "0x1 not within flag-matching ranges in pipeline layout"},
8237 {{VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT, 0, 4},
8238 "vkCmdPushConstants() stageFlags = 0x2 do not match the stageFlags in "
8239 "any of the ranges in pipeline layout"},
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008240 {{VK_SHADER_STAGE_VERTEX_BIT | VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT, 0, 16},
Karl Schultzc81037d2016-05-12 08:11:23 -06008241 "vkCmdPushConstants() stageFlags = 0x3 do not match the stageFlags in "
8242 "any of the ranges in pipeline layout"},
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008243 {{VK_SHADER_STAGE_VERTEX_BIT, 0, too_big}, "vkCmdPushConstants() call has push constants with offset "},
8244 {{VK_SHADER_STAGE_VERTEX_BIT, too_big, too_big}, "vkCmdPushConstants() call has push constants with offset "},
8245 {{VK_SHADER_STAGE_VERTEX_BIT, too_big, 0}, "vkCmdPushConstants() call has push constants with offset "},
8246 {{VK_SHADER_STAGE_VERTEX_BIT, 0xFFFFFFF0, 0x00000020}, "vkCmdPushConstants() call has push constants with offset "},
8247 {{VK_SHADER_STAGE_VERTEX_BIT, 0x00000020, 0xFFFFFFF0}, "vkCmdPushConstants() call has push constants with offset "},
Karl Schultzfc8eaf12016-05-06 13:56:42 -06008248 }};
8249
8250 // Two ranges for testing robustness
Karl Schultzc81037d2016-05-12 08:11:23 -06008251 const VkPushConstantRange pc_range2[] = {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008252 {VK_SHADER_STAGE_VERTEX_BIT, 64, 16}, {VK_SHADER_STAGE_VERTEX_BIT, 0, 16},
Karl Schultzfc8eaf12016-05-06 13:56:42 -06008253 };
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008254 pipeline_layout_ci.pushConstantRangeCount = sizeof(pc_range2) / sizeof(VkPushConstantRange);
Karl Schultzfc8eaf12016-05-06 13:56:42 -06008255 pipeline_layout_ci.pPushConstantRanges = pc_range2;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008256 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis3a23b6a2016-02-17 10:35:18 -07008257 ASSERT_VK_SUCCESS(err);
8258 BeginCommandBuffer();
Karl Schultzc81037d2016-05-12 08:11:23 -06008259 for (const auto &iter : cmd_range_tests) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008260 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, iter.msg);
8261 vkCmdPushConstants(m_commandBuffer->GetBufferHandle(), pipeline_layout, iter.range.stageFlags, iter.range.offset,
Karl Schultzc81037d2016-05-12 08:11:23 -06008262 iter.range.size, dummy_values);
Karl Schultzfc8eaf12016-05-06 13:56:42 -06008263 m_errorMonitor->VerifyFound();
8264 }
8265
8266 // Check for invalid stage flag
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008267 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "vkCmdPushConstants() call has no stageFlags set.");
8268 vkCmdPushConstants(m_commandBuffer->GetBufferHandle(), pipeline_layout, 0, 0, 16, dummy_values);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008269 m_errorMonitor->VerifyFound();
Karl Schultzc81037d2016-05-12 08:11:23 -06008270 EndCommandBuffer();
8271 vkResetCommandBuffer(m_commandBuffer->GetBufferHandle(), 0);
8272 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
Karl Schultzfc8eaf12016-05-06 13:56:42 -06008273
Karl Schultzc81037d2016-05-12 08:11:23 -06008274 // overlapping range tests with cmd
8275 const std::array<PipelineLayoutTestCase, 3> cmd_overlap_tests = {{
8276 {{VK_SHADER_STAGE_VERTEX_BIT, 0, 20},
8277 "vkCmdPushConstants() Push constant range [0, 20) with stageFlags = "
8278 "0x1 not within flag-matching ranges in pipeline layout"},
8279 {{VK_SHADER_STAGE_VERTEX_BIT, 16, 4},
8280 "vkCmdPushConstants() Push constant range [16, 20) with stageFlags = "
8281 "0x1 not within flag-matching ranges in pipeline layout"},
8282 {{VK_SHADER_STAGE_VERTEX_BIT, 40, 16},
8283 "vkCmdPushConstants() Push constant range [40, 56) with stageFlags = "
8284 "0x1 not within flag-matching ranges in pipeline layout"},
8285 }};
8286 const VkPushConstantRange pc_range3[] = {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008287 {VK_SHADER_STAGE_VERTEX_BIT, 20, 16}, {VK_SHADER_STAGE_VERTEX_BIT, 0, 16}, {VK_SHADER_STAGE_VERTEX_BIT, 0, 4},
8288 {VK_SHADER_STAGE_VERTEX_BIT, 44, 8}, {VK_SHADER_STAGE_VERTEX_BIT, 80, 12}, {VK_SHADER_STAGE_VERTEX_BIT, 36, 8},
Karl Schultzc81037d2016-05-12 08:11:23 -06008289 {VK_SHADER_STAGE_VERTEX_BIT, 56, 28},
8290 };
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008291 pipeline_layout_ci.pushConstantRangeCount = sizeof(pc_range3) / sizeof(VkPushConstantRange);
Karl Schultzc81037d2016-05-12 08:11:23 -06008292 pipeline_layout_ci.pPushConstantRanges = pc_range3;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008293 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Karl Schultzc81037d2016-05-12 08:11:23 -06008294 ASSERT_VK_SUCCESS(err);
8295 BeginCommandBuffer();
8296 for (const auto &iter : cmd_overlap_tests) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008297 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, iter.msg);
8298 vkCmdPushConstants(m_commandBuffer->GetBufferHandle(), pipeline_layout, iter.range.stageFlags, iter.range.offset,
Karl Schultzc81037d2016-05-12 08:11:23 -06008299 iter.range.size, dummy_values);
8300 m_errorMonitor->VerifyFound();
8301 }
8302 EndCommandBuffer();
8303 vkResetCommandBuffer(m_commandBuffer->GetBufferHandle(), 0);
8304 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
8305
8306 // positive overlapping range tests with cmd
8307 const std::array<PipelineLayoutTestCase, 4> cmd_overlap_tests_pos = {{
8308 {{VK_SHADER_STAGE_VERTEX_BIT, 0, 16}, ""},
8309 {{VK_SHADER_STAGE_VERTEX_BIT, 0, 4}, ""},
8310 {{VK_SHADER_STAGE_VERTEX_BIT, 20, 12}, ""},
8311 {{VK_SHADER_STAGE_VERTEX_BIT, 56, 36}, ""},
8312 }};
8313 const VkPushConstantRange pc_range4[] = {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008314 {VK_SHADER_STAGE_VERTEX_BIT, 0, 64}, {VK_SHADER_STAGE_VERTEX_BIT, 20, 16}, {VK_SHADER_STAGE_VERTEX_BIT, 0, 16},
8315 {VK_SHADER_STAGE_VERTEX_BIT, 0, 4}, {VK_SHADER_STAGE_VERTEX_BIT, 44, 8}, {VK_SHADER_STAGE_VERTEX_BIT, 80, 12},
8316 {VK_SHADER_STAGE_VERTEX_BIT, 36, 8}, {VK_SHADER_STAGE_VERTEX_BIT, 56, 28},
Karl Schultzc81037d2016-05-12 08:11:23 -06008317 };
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008318 pipeline_layout_ci.pushConstantRangeCount = sizeof(pc_range4) / sizeof(VkPushConstantRange);
Karl Schultzc81037d2016-05-12 08:11:23 -06008319 pipeline_layout_ci.pPushConstantRanges = pc_range4;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008320 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Karl Schultzc81037d2016-05-12 08:11:23 -06008321 ASSERT_VK_SUCCESS(err);
8322 BeginCommandBuffer();
8323 for (const auto &iter : cmd_overlap_tests_pos) {
8324 m_errorMonitor->ExpectSuccess();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008325 vkCmdPushConstants(m_commandBuffer->GetBufferHandle(), pipeline_layout, iter.range.stageFlags, iter.range.offset,
Karl Schultzc81037d2016-05-12 08:11:23 -06008326 iter.range.size, dummy_values);
8327 m_errorMonitor->VerifyNotFound();
8328 }
8329 EndCommandBuffer();
8330 vkResetCommandBuffer(m_commandBuffer->GetBufferHandle(), 0);
Tobin Ehlis3a23b6a2016-02-17 10:35:18 -07008331 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
8332}
8333
Karl Schultz6addd812016-02-02 17:17:23 -07008334TEST_F(VkLayerTest, DescriptorSetCompatibility) {
Tobin Ehlis559c6382015-11-05 09:52:49 -07008335 // Test various desriptorSet errors with bad binding combinations
Karl Schultz6addd812016-02-02 17:17:23 -07008336 VkResult err;
Tobin Ehlis559c6382015-11-05 09:52:49 -07008337
8338 ASSERT_NO_FATAL_FAILURE(InitState());
8339 ASSERT_NO_FATAL_FAILURE(InitViewport());
8340 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
8341
Mike Stroyanb8a61002016-06-20 16:00:28 -06008342 const VkFormat tex_format = VK_FORMAT_R8G8B8A8_UNORM;
8343 VkImageTiling tiling;
8344 VkFormatProperties format_properties;
8345 vkGetPhysicalDeviceFormatProperties(gpu(), tex_format, &format_properties);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008346 if (format_properties.linearTilingFeatures & VK_FORMAT_FEATURE_STORAGE_IMAGE_BIT) {
Mike Stroyanb8a61002016-06-20 16:00:28 -06008347 tiling = VK_IMAGE_TILING_LINEAR;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008348 } else if (format_properties.optimalTilingFeatures & VK_FORMAT_FEATURE_STORAGE_IMAGE_BIT) {
Mike Stroyanb8a61002016-06-20 16:00:28 -06008349 tiling = VK_IMAGE_TILING_OPTIMAL;
8350 } else {
8351 printf("Device does not support VK_FORMAT_FEATURE_STORAGE_IMAGE_BIT; "
8352 "skipped.\n");
8353 return;
8354 }
8355
Tobin Ehlis559c6382015-11-05 09:52:49 -07008356 static const uint32_t NUM_DESCRIPTOR_TYPES = 5;
8357 VkDescriptorPoolSize ds_type_count[NUM_DESCRIPTOR_TYPES] = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008358 ds_type_count[0].type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
8359 ds_type_count[0].descriptorCount = 10;
8360 ds_type_count[1].type = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE;
8361 ds_type_count[1].descriptorCount = 2;
8362 ds_type_count[2].type = VK_DESCRIPTOR_TYPE_STORAGE_IMAGE;
8363 ds_type_count[2].descriptorCount = 2;
8364 ds_type_count[3].type = VK_DESCRIPTOR_TYPE_SAMPLER;
8365 ds_type_count[3].descriptorCount = 5;
8366 // TODO : LunarG ILO driver currently asserts in desc.c w/ INPUT_ATTACHMENT
8367 // type
8368 // ds_type_count[4].type = VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT;
8369 ds_type_count[4].type = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
8370 ds_type_count[4].descriptorCount = 2;
Tobin Ehlis559c6382015-11-05 09:52:49 -07008371
8372 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008373 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
8374 ds_pool_ci.pNext = NULL;
8375 ds_pool_ci.maxSets = 5;
8376 ds_pool_ci.poolSizeCount = NUM_DESCRIPTOR_TYPES;
8377 ds_pool_ci.pPoolSizes = ds_type_count;
Tobin Ehlis559c6382015-11-05 09:52:49 -07008378
8379 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008380 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis559c6382015-11-05 09:52:49 -07008381 ASSERT_VK_SUCCESS(err);
8382
8383 static const uint32_t MAX_DS_TYPES_IN_LAYOUT = 2;
8384 VkDescriptorSetLayoutBinding dsl_binding[MAX_DS_TYPES_IN_LAYOUT] = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008385 dsl_binding[0].binding = 0;
8386 dsl_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
8387 dsl_binding[0].descriptorCount = 5;
8388 dsl_binding[0].stageFlags = VK_SHADER_STAGE_ALL;
8389 dsl_binding[0].pImmutableSamplers = NULL;
Tobin Ehlis559c6382015-11-05 09:52:49 -07008390
Tobin Ehlis8fab6562015-12-01 09:57:09 -07008391 // Create layout identical to set0 layout but w/ different stageFlags
8392 VkDescriptorSetLayoutBinding dsl_fs_stage_only = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008393 dsl_fs_stage_only.binding = 0;
8394 dsl_fs_stage_only.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
8395 dsl_fs_stage_only.descriptorCount = 5;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008396 dsl_fs_stage_only.stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT; // Different stageFlags to cause error at
8397 // bind time
Karl Schultz6addd812016-02-02 17:17:23 -07008398 dsl_fs_stage_only.pImmutableSamplers = NULL;
Tobin Ehlis559c6382015-11-05 09:52:49 -07008399 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008400 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
8401 ds_layout_ci.pNext = NULL;
8402 ds_layout_ci.bindingCount = 1;
8403 ds_layout_ci.pBindings = dsl_binding;
Tobin Ehlis559c6382015-11-05 09:52:49 -07008404 static const uint32_t NUM_LAYOUTS = 4;
8405 VkDescriptorSetLayout ds_layout[NUM_LAYOUTS] = {};
Tobin Ehlis8fab6562015-12-01 09:57:09 -07008406 VkDescriptorSetLayout ds_layout_fs_only = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008407 // Create 4 unique layouts for full pipelineLayout, and 1 special fs-only
8408 // layout for error case
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008409 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout[0]);
Tobin Ehlis559c6382015-11-05 09:52:49 -07008410 ASSERT_VK_SUCCESS(err);
Jon Ashburn6e23c1f2015-12-30 18:01:16 -07008411 ds_layout_ci.pBindings = &dsl_fs_stage_only;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008412 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout_fs_only);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07008413 ASSERT_VK_SUCCESS(err);
Tobin Ehlis559c6382015-11-05 09:52:49 -07008414 dsl_binding[0].binding = 0;
8415 dsl_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE;
Tobin Ehlis8fab6562015-12-01 09:57:09 -07008416 dsl_binding[0].descriptorCount = 2;
Mike Stroyan9c70cdb2016-01-06 14:14:17 -07008417 dsl_binding[1].binding = 1;
8418 dsl_binding[1].descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_IMAGE;
8419 dsl_binding[1].descriptorCount = 2;
8420 dsl_binding[1].stageFlags = VK_SHADER_STAGE_ALL;
8421 dsl_binding[1].pImmutableSamplers = NULL;
Jon Ashburn6e23c1f2015-12-30 18:01:16 -07008422 ds_layout_ci.pBindings = dsl_binding;
Tobin Ehlis559c6382015-11-05 09:52:49 -07008423 ds_layout_ci.bindingCount = 2;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008424 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout[1]);
Tobin Ehlis559c6382015-11-05 09:52:49 -07008425 ASSERT_VK_SUCCESS(err);
8426 dsl_binding[0].binding = 0;
8427 dsl_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
Tobin Ehlis8fab6562015-12-01 09:57:09 -07008428 dsl_binding[0].descriptorCount = 5;
Tobin Ehlis559c6382015-11-05 09:52:49 -07008429 ds_layout_ci.bindingCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008430 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout[2]);
Tobin Ehlis559c6382015-11-05 09:52:49 -07008431 ASSERT_VK_SUCCESS(err);
8432 dsl_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
Tobin Ehlis8fab6562015-12-01 09:57:09 -07008433 dsl_binding[0].descriptorCount = 2;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008434 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout[3]);
Tobin Ehlis559c6382015-11-05 09:52:49 -07008435 ASSERT_VK_SUCCESS(err);
8436
8437 static const uint32_t NUM_SETS = 4;
8438 VkDescriptorSet descriptorSet[NUM_SETS] = {};
8439 VkDescriptorSetAllocateInfo alloc_info = {};
Tobin Ehlis8fab6562015-12-01 09:57:09 -07008440 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07008441 alloc_info.descriptorSetCount = NUM_LAYOUTS;
Tobin Ehlis559c6382015-11-05 09:52:49 -07008442 alloc_info.descriptorPool = ds_pool;
8443 alloc_info.pSetLayouts = ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008444 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, descriptorSet);
Tobin Ehlis559c6382015-11-05 09:52:49 -07008445 ASSERT_VK_SUCCESS(err);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07008446 VkDescriptorSet ds0_fs_only = {};
Jon Ashburnf19916e2016-01-11 13:12:43 -07008447 alloc_info.descriptorSetCount = 1;
Tobin Ehlis8fab6562015-12-01 09:57:09 -07008448 alloc_info.pSetLayouts = &ds_layout_fs_only;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008449 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &ds0_fs_only);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07008450 ASSERT_VK_SUCCESS(err);
Tobin Ehlis559c6382015-11-05 09:52:49 -07008451
8452 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008453 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
8454 pipeline_layout_ci.pNext = NULL;
8455 pipeline_layout_ci.setLayoutCount = NUM_LAYOUTS;
8456 pipeline_layout_ci.pSetLayouts = ds_layout;
Tobin Ehlis559c6382015-11-05 09:52:49 -07008457
8458 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008459 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis559c6382015-11-05 09:52:49 -07008460 ASSERT_VK_SUCCESS(err);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07008461 // Create pipelineLayout with only one setLayout
8462 pipeline_layout_ci.setLayoutCount = 1;
8463 VkPipelineLayout single_pipe_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008464 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &single_pipe_layout);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07008465 ASSERT_VK_SUCCESS(err);
8466 // Create pipelineLayout with 2 descriptor setLayout at index 0
8467 pipeline_layout_ci.pSetLayouts = &ds_layout[3];
8468 VkPipelineLayout pipe_layout_one_desc;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008469 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipe_layout_one_desc);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07008470 ASSERT_VK_SUCCESS(err);
8471 // Create pipelineLayout with 5 SAMPLER descriptor setLayout at index 0
8472 pipeline_layout_ci.pSetLayouts = &ds_layout[2];
8473 VkPipelineLayout pipe_layout_five_samp;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008474 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipe_layout_five_samp);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07008475 ASSERT_VK_SUCCESS(err);
8476 // Create pipelineLayout with UB type, but stageFlags for FS only
8477 pipeline_layout_ci.pSetLayouts = &ds_layout_fs_only;
8478 VkPipelineLayout pipe_layout_fs_only;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008479 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipe_layout_fs_only);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07008480 ASSERT_VK_SUCCESS(err);
8481 // Create pipelineLayout w/ incompatible set0 layout, but set1 is fine
8482 VkDescriptorSetLayout pl_bad_s0[2] = {};
8483 pl_bad_s0[0] = ds_layout_fs_only;
8484 pl_bad_s0[1] = ds_layout[1];
8485 pipeline_layout_ci.setLayoutCount = 2;
8486 pipeline_layout_ci.pSetLayouts = pl_bad_s0;
8487 VkPipelineLayout pipe_layout_bad_set0;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008488 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipe_layout_bad_set0);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07008489 ASSERT_VK_SUCCESS(err);
Tobin Ehlis559c6382015-11-05 09:52:49 -07008490
8491 // Create a buffer to update the descriptor with
8492 uint32_t qfi = 0;
8493 VkBufferCreateInfo buffCI = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008494 buffCI.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
8495 buffCI.size = 1024;
8496 buffCI.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
8497 buffCI.queueFamilyIndexCount = 1;
8498 buffCI.pQueueFamilyIndices = &qfi;
Tobin Ehlis559c6382015-11-05 09:52:49 -07008499
8500 VkBuffer dyub;
8501 err = vkCreateBuffer(m_device->device(), &buffCI, NULL, &dyub);
8502 ASSERT_VK_SUCCESS(err);
8503 // Correctly update descriptor to avoid "NOT_UPDATED" error
8504 static const uint32_t NUM_BUFFS = 5;
8505 VkDescriptorBufferInfo buffInfo[NUM_BUFFS] = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008506 for (uint32_t i = 0; i < NUM_BUFFS; ++i) {
Tobin Ehlis559c6382015-11-05 09:52:49 -07008507 buffInfo[i].buffer = dyub;
8508 buffInfo[i].offset = 0;
8509 buffInfo[i].range = 1024;
8510 }
Karl Schultz6addd812016-02-02 17:17:23 -07008511 VkImage image;
Karl Schultz6addd812016-02-02 17:17:23 -07008512 const int32_t tex_width = 32;
8513 const int32_t tex_height = 32;
Tobin Ehlis8fab6562015-12-01 09:57:09 -07008514 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008515 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
8516 image_create_info.pNext = NULL;
8517 image_create_info.imageType = VK_IMAGE_TYPE_2D;
8518 image_create_info.format = tex_format;
8519 image_create_info.extent.width = tex_width;
8520 image_create_info.extent.height = tex_height;
8521 image_create_info.extent.depth = 1;
8522 image_create_info.mipLevels = 1;
8523 image_create_info.arrayLayers = 1;
8524 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
Mike Stroyanb8a61002016-06-20 16:00:28 -06008525 image_create_info.tiling = tiling;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008526 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT | VK_IMAGE_USAGE_STORAGE_BIT;
Karl Schultz6addd812016-02-02 17:17:23 -07008527 image_create_info.flags = 0;
Tobin Ehlis8fab6562015-12-01 09:57:09 -07008528 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
8529 ASSERT_VK_SUCCESS(err);
Tobin Ehlis559c6382015-11-05 09:52:49 -07008530
Karl Schultz6addd812016-02-02 17:17:23 -07008531 VkMemoryRequirements memReqs;
8532 VkDeviceMemory imageMem;
8533 bool pass;
Mike Stroyan9c70cdb2016-01-06 14:14:17 -07008534 VkMemoryAllocateInfo memAlloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008535 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
8536 memAlloc.pNext = NULL;
8537 memAlloc.allocationSize = 0;
8538 memAlloc.memoryTypeIndex = 0;
Mike Stroyan9c70cdb2016-01-06 14:14:17 -07008539 vkGetImageMemoryRequirements(m_device->device(), image, &memReqs);
8540 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008541 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Mike Stroyan9c70cdb2016-01-06 14:14:17 -07008542 ASSERT_TRUE(pass);
8543 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &imageMem);
8544 ASSERT_VK_SUCCESS(err);
8545 err = vkBindImageMemory(m_device->device(), image, imageMem, 0);
8546 ASSERT_VK_SUCCESS(err);
8547
Tobin Ehlis8fab6562015-12-01 09:57:09 -07008548 VkImageViewCreateInfo image_view_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008549 image_view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
8550 image_view_create_info.image = image;
8551 image_view_create_info.viewType = VK_IMAGE_VIEW_TYPE_2D;
8552 image_view_create_info.format = tex_format;
8553 image_view_create_info.subresourceRange.layerCount = 1;
8554 image_view_create_info.subresourceRange.baseMipLevel = 0;
8555 image_view_create_info.subresourceRange.levelCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008556 image_view_create_info.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Tobin Ehlis559c6382015-11-05 09:52:49 -07008557
Tobin Ehlis8fab6562015-12-01 09:57:09 -07008558 VkImageView view;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008559 err = vkCreateImageView(m_device->device(), &image_view_create_info, NULL, &view);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07008560 ASSERT_VK_SUCCESS(err);
Tobin Ehlis991d45a2016-01-06 08:48:41 -07008561 VkDescriptorImageInfo imageInfo[4] = {};
Tobin Ehlis8fab6562015-12-01 09:57:09 -07008562 imageInfo[0].imageView = view;
8563 imageInfo[0].imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
8564 imageInfo[1].imageView = view;
8565 imageInfo[1].imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
Tobin Ehlis991d45a2016-01-06 08:48:41 -07008566 imageInfo[2].imageView = view;
8567 imageInfo[2].imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
8568 imageInfo[3].imageView = view;
8569 imageInfo[3].imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
Tobin Ehlis8fab6562015-12-01 09:57:09 -07008570
8571 static const uint32_t NUM_SET_UPDATES = 3;
8572 VkWriteDescriptorSet descriptor_write[NUM_SET_UPDATES] = {};
8573 descriptor_write[0].sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
8574 descriptor_write[0].dstSet = descriptorSet[0];
8575 descriptor_write[0].dstBinding = 0;
8576 descriptor_write[0].descriptorCount = 5;
8577 descriptor_write[0].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
8578 descriptor_write[0].pBufferInfo = buffInfo;
8579 descriptor_write[1].sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
8580 descriptor_write[1].dstSet = descriptorSet[1];
8581 descriptor_write[1].dstBinding = 0;
8582 descriptor_write[1].descriptorCount = 2;
8583 descriptor_write[1].descriptorType = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE;
8584 descriptor_write[1].pImageInfo = imageInfo;
8585 descriptor_write[2].sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
8586 descriptor_write[2].dstSet = descriptorSet[1];
8587 descriptor_write[2].dstBinding = 1;
8588 descriptor_write[2].descriptorCount = 2;
8589 descriptor_write[2].descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_IMAGE;
Tobin Ehlis991d45a2016-01-06 08:48:41 -07008590 descriptor_write[2].pImageInfo = &imageInfo[2];
Tobin Ehlis8fab6562015-12-01 09:57:09 -07008591
8592 vkUpdateDescriptorSets(m_device->device(), 3, descriptor_write, 0, NULL);
Tobin Ehlis559c6382015-11-05 09:52:49 -07008593
Tobin Ehlis88452832015-12-03 09:40:56 -07008594 // Create PSO to be used for draw-time errors below
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008595 char const *vsSource = "#version 450\n"
8596 "\n"
8597 "out gl_PerVertex {\n"
8598 " vec4 gl_Position;\n"
8599 "};\n"
8600 "void main(){\n"
8601 " gl_Position = vec4(1);\n"
8602 "}\n";
8603 char const *fsSource = "#version 450\n"
8604 "\n"
8605 "layout(location=0) out vec4 x;\n"
8606 "layout(set=0) layout(binding=0) uniform foo { int x; int y; } bar;\n"
8607 "void main(){\n"
8608 " x = vec4(bar.y);\n"
8609 "}\n";
Tobin Ehlis88452832015-12-03 09:40:56 -07008610 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
8611 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Tobin Ehlis559c6382015-11-05 09:52:49 -07008612 VkPipelineObj pipe(m_device);
8613 pipe.AddShader(&vs);
8614 pipe.AddShader(&fs);
Tobin Ehlis88452832015-12-03 09:40:56 -07008615 pipe.AddColorAttachment();
8616 pipe.CreateVKPipeline(pipe_layout_fs_only, renderPass());
Tobin Ehlis559c6382015-11-05 09:52:49 -07008617
8618 BeginCommandBuffer();
Tobin Ehlis88452832015-12-03 09:40:56 -07008619
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008620 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Karl Schultz6addd812016-02-02 17:17:23 -07008621 // NOTE : I believe LunarG ilo driver has bug (LX#189) that requires binding
8622 // of PSO
8623 // here before binding DSs. Otherwise we assert in cmd_copy_dset_data() of
8624 // cmd_pipeline.c
8625 // due to the fact that cmd_alloc_dset_data() has not been called in
8626 // cmd_bind_graphics_pipeline()
8627 // TODO : Want to cause various binding incompatibility issues here to test
8628 // DrawState
Tobin Ehlis559c6382015-11-05 09:52:49 -07008629 // First cause various verify_layout_compatibility() fails
8630 // Second disturb early and late sets and verify INFO msgs
Tobin Ehlis8fab6562015-12-01 09:57:09 -07008631 // verify_set_layout_compatibility fail cases:
8632 // 1. invalid VkPipelineLayout (layout) passed into vkCmdBindDescriptorSets
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008633 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Invalid Pipeline Layout Object ");
8634 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS,
8635 (VkPipelineLayout)((size_t)0xbaadb1be), 0, 1, &descriptorSet[0], 0, NULL);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008636 m_errorMonitor->VerifyFound();
8637
Tobin Ehlis8fab6562015-12-01 09:57:09 -07008638 // 2. layoutIndex exceeds # of layouts in layout
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008639 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " attempting to bind set to index 1");
8640 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, single_pipe_layout, 0, 2,
8641 &descriptorSet[0], 0, NULL);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008642 m_errorMonitor->VerifyFound();
8643
Tobin Ehlis8fab6562015-12-01 09:57:09 -07008644 vkDestroyPipelineLayout(m_device->device(), single_pipe_layout, NULL);
Karl Schultz6addd812016-02-02 17:17:23 -07008645 // 3. Pipeline setLayout[0] has 2 descriptors, but set being bound has 5
8646 // descriptors
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008647 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " has 2 descriptors, but DescriptorSetLayout ");
8648 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe_layout_one_desc, 0, 1,
8649 &descriptorSet[0], 0, NULL);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008650 m_errorMonitor->VerifyFound();
8651
Tobin Ehlis8fab6562015-12-01 09:57:09 -07008652 vkDestroyPipelineLayout(m_device->device(), pipe_layout_one_desc, NULL);
8653 // 4. same # of descriptors but mismatch in type
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008654 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " is type 'VK_DESCRIPTOR_TYPE_SAMPLER' but binding ");
8655 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe_layout_five_samp, 0, 1,
8656 &descriptorSet[0], 0, NULL);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008657 m_errorMonitor->VerifyFound();
8658
Tobin Ehlis8fab6562015-12-01 09:57:09 -07008659 vkDestroyPipelineLayout(m_device->device(), pipe_layout_five_samp, NULL);
8660 // 5. same # of descriptors but mismatch in stageFlags
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008661 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
8662 " has stageFlags 16 but binding 0 for DescriptorSetLayout ");
8663 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe_layout_fs_only, 0, 1,
8664 &descriptorSet[0], 0, NULL);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008665 m_errorMonitor->VerifyFound();
8666
Tobin Ehlis8fab6562015-12-01 09:57:09 -07008667 // Cause INFO messages due to disturbing previously bound Sets
8668 // First bind sets 0 & 1
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008669 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 2,
8670 &descriptorSet[0], 0, NULL);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07008671 // 1. Disturb bound set0 by re-binding set1 w/ updated pipelineLayout
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008672 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT, " previously bound as set #0 was disturbed ");
8673 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe_layout_bad_set0, 1, 1,
8674 &descriptorSet[1], 0, NULL);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008675 m_errorMonitor->VerifyFound();
8676
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008677 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 2,
8678 &descriptorSet[0], 0, NULL);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07008679 // 2. Disturb set after last bound set
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008680 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT, " newly bound as set #0 so set #1 and "
8681 "any subsequent sets were disturbed ");
8682 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe_layout_fs_only, 0, 1,
8683 &ds0_fs_only, 0, NULL);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008684 m_errorMonitor->VerifyFound();
8685
Tobin Ehlis10fad692016-07-07 12:00:36 -06008686 // Now that we're done actively using the pipelineLayout that gfx pipeline
8687 // was created with, we should be able to delete it. Do that now to verify
8688 // that validation obeys pipelineLayout lifetime
8689 vkDestroyPipelineLayout(m_device->device(), pipe_layout_fs_only, NULL);
8690
Tobin Ehlis88452832015-12-03 09:40:56 -07008691 // Cause draw-time errors due to PSO incompatibilities
Karl Schultz6addd812016-02-02 17:17:23 -07008692 // 1. Error due to not binding required set (we actually use same code as
8693 // above to disturb set0)
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008694 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 2,
8695 &descriptorSet[0], 0, NULL);
8696 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe_layout_bad_set0, 1, 1,
8697 &descriptorSet[1], 0, NULL);
8698 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 -07008699 Draw(1, 0, 0, 0);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008700 m_errorMonitor->VerifyFound();
8701
Tobin Ehlis991d45a2016-01-06 08:48:41 -07008702 vkDestroyPipelineLayout(m_device->device(), pipe_layout_bad_set0, NULL);
Karl Schultz6addd812016-02-02 17:17:23 -07008703 // 2. Error due to bound set not being compatible with PSO's
8704 // VkPipelineLayout (diff stageFlags in this case)
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008705 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 2,
8706 &descriptorSet[0], 0, NULL);
8707 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " bound as set #0 is not compatible with ");
Tobin Ehlis88452832015-12-03 09:40:56 -07008708 Draw(1, 0, 0, 0);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008709 m_errorMonitor->VerifyFound();
8710
Tobin Ehlis8fab6562015-12-01 09:57:09 -07008711 // Remaining clean-up
Karl Schultz6addd812016-02-02 17:17:23 -07008712 for (uint32_t i = 0; i < NUM_LAYOUTS; ++i) {
Tobin Ehlis8fab6562015-12-01 09:57:09 -07008713 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout[i], NULL);
8714 }
8715 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout_fs_only, NULL);
Tobin Ehlis9bfd4492016-05-05 15:09:11 -06008716 vkFreeDescriptorSets(m_device->device(), ds_pool, 1, &ds0_fs_only);
8717 vkFreeDescriptorSets(m_device->device(), ds_pool, NUM_SETS, descriptorSet);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07008718 vkDestroyBuffer(m_device->device(), dyub, NULL);
Tobin Ehlis559c6382015-11-05 09:52:49 -07008719 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
8720 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tony Barbourdf4c0042016-06-01 15:55:43 -06008721 vkFreeMemory(m_device->device(), imageMem, NULL);
8722 vkDestroyImage(m_device->device(), image, NULL);
8723 vkDestroyImageView(m_device->device(), view, NULL);
Tobin Ehlis559c6382015-11-05 09:52:49 -07008724}
Tobin Ehlis559c6382015-11-05 09:52:49 -07008725
Karl Schultz6addd812016-02-02 17:17:23 -07008726TEST_F(VkLayerTest, NoBeginCommandBuffer) {
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06008727
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008728 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
8729 "You must call vkBeginCommandBuffer() before this call to ");
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06008730
8731 ASSERT_NO_FATAL_FAILURE(InitState());
Chia-I Wu3432a0c2015-10-27 18:04:07 +08008732 VkCommandBufferObj commandBuffer(m_device, m_commandPool);
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06008733 // Call EndCommandBuffer() w/o calling BeginCommandBuffer()
Chia-I Wu3432a0c2015-10-27 18:04:07 +08008734 vkEndCommandBuffer(commandBuffer.GetBufferHandle());
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06008735
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008736 m_errorMonitor->VerifyFound();
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06008737}
8738
Karl Schultz6addd812016-02-02 17:17:23 -07008739TEST_F(VkLayerTest, SecondaryCommandBufferNullRenderpass) {
8740 VkResult err;
8741 VkCommandBuffer draw_cmd;
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06008742
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008743 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " must specify a valid renderpass parameter.");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06008744
Mark Lobodzinskid9139a62015-08-04 16:24:20 -06008745 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinskid9139a62015-08-04 16:24:20 -06008746
Chia-I Wu3432a0c2015-10-27 18:04:07 +08008747 VkCommandBufferAllocateInfo cmd = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08008748 cmd.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
Cody Northropb4569702015-08-04 17:35:57 -06008749 cmd.pNext = NULL;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08008750 cmd.commandPool = m_commandPool;
8751 cmd.level = VK_COMMAND_BUFFER_LEVEL_SECONDARY;
Jon Ashburnf19916e2016-01-11 13:12:43 -07008752 cmd.commandBufferCount = 1;
Cody Northropb4569702015-08-04 17:35:57 -06008753
Chia-I Wu3432a0c2015-10-27 18:04:07 +08008754 err = vkAllocateCommandBuffers(m_device->device(), &cmd, &draw_cmd);
Mike Stroyand1c84a52015-08-18 14:40:24 -06008755 ASSERT_VK_SUCCESS(err);
Mark Lobodzinskid9139a62015-08-04 16:24:20 -06008756
8757 // Force the failure by not setting the Renderpass and Framebuffer fields
Chia-I Wu3432a0c2015-10-27 18:04:07 +08008758 VkCommandBufferBeginInfo cmd_buf_info = {};
Jon Ashburnf19916e2016-01-11 13:12:43 -07008759 VkCommandBufferInheritanceInfo cmd_buf_hinfo = {};
Chia-I Wu3432a0c2015-10-27 18:04:07 +08008760 cmd_buf_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
Cody Northropb4569702015-08-04 17:35:57 -06008761 cmd_buf_info.pNext = NULL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008762 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 -07008763 cmd_buf_info.pInheritanceInfo = &cmd_buf_hinfo;
Mark Lobodzinskid9139a62015-08-04 16:24:20 -06008764
8765 // The error should be caught by validation of the BeginCommandBuffer call
8766 vkBeginCommandBuffer(draw_cmd, &cmd_buf_info);
8767
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008768 m_errorMonitor->VerifyFound();
Chia-I Wu3432a0c2015-10-27 18:04:07 +08008769 vkFreeCommandBuffers(m_device->device(), m_commandPool, 1, &draw_cmd);
Mark Lobodzinskid9139a62015-08-04 16:24:20 -06008770}
8771
Karl Schultz6addd812016-02-02 17:17:23 -07008772TEST_F(VkLayerTest, CommandBufferResetErrors) {
Tobin Ehlisac0ef842015-12-14 13:46:38 -07008773 // Cause error due to Begin while recording CB
8774 // Then cause 2 errors for attempting to reset CB w/o having
8775 // VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT set for the pool from
8776 // which CBs were allocated. Note that this bit is off by default.
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008777 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Cannot call Begin on CB");
Tobin Ehlisac0ef842015-12-14 13:46:38 -07008778
8779 ASSERT_NO_FATAL_FAILURE(InitState());
8780
8781 // Calls AllocateCommandBuffers
8782 VkCommandBufferObj commandBuffer(m_device, m_commandPool);
8783
Karl Schultz6addd812016-02-02 17:17:23 -07008784 // Force the failure by setting the Renderpass and Framebuffer fields with
8785 // (fake) data
Tobin Ehlisac0ef842015-12-14 13:46:38 -07008786 VkCommandBufferBeginInfo cmd_buf_info = {};
Jon Ashburnf19916e2016-01-11 13:12:43 -07008787 VkCommandBufferInheritanceInfo cmd_buf_hinfo = {};
Tobin Ehlisac0ef842015-12-14 13:46:38 -07008788 cmd_buf_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
8789 cmd_buf_info.pNext = NULL;
8790 cmd_buf_info.flags = VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT;
Jon Ashburnf19916e2016-01-11 13:12:43 -07008791 cmd_buf_info.pInheritanceInfo = &cmd_buf_hinfo;
Tobin Ehlisac0ef842015-12-14 13:46:38 -07008792
8793 // Begin CB to transition to recording state
8794 vkBeginCommandBuffer(commandBuffer.GetBufferHandle(), &cmd_buf_info);
8795 // Can't re-begin. This should trigger error
8796 vkBeginCommandBuffer(commandBuffer.GetBufferHandle(), &cmd_buf_info);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008797 m_errorMonitor->VerifyFound();
8798
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008799 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Attempt to reset command buffer ");
Tobin Ehlisac0ef842015-12-14 13:46:38 -07008800 VkCommandBufferResetFlags flags = 0; // Don't care about flags for this test
8801 // Reset attempt will trigger error due to incorrect CommandPool state
8802 vkResetCommandBuffer(commandBuffer.GetBufferHandle(), flags);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008803 m_errorMonitor->VerifyFound();
8804
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008805 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " attempts to implicitly reset cmdBuffer created from ");
Tobin Ehlisac0ef842015-12-14 13:46:38 -07008806 // Transition CB to RECORDED state
8807 vkEndCommandBuffer(commandBuffer.GetBufferHandle());
8808 // Now attempting to Begin will implicitly reset, which triggers error
8809 vkBeginCommandBuffer(commandBuffer.GetBufferHandle(), &cmd_buf_info);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008810 m_errorMonitor->VerifyFound();
Tobin Ehlisac0ef842015-12-14 13:46:38 -07008811}
8812
Karl Schultz6addd812016-02-02 17:17:23 -07008813TEST_F(VkLayerTest, InvalidPipelineCreateState) {
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06008814 // Attempt to Create Gfx Pipeline w/o a VS
Karl Schultz6addd812016-02-02 17:17:23 -07008815 VkResult err;
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06008816
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008817 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Invalid Pipeline CreateInfo State: Vtx Shader required");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06008818
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06008819 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06008820 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Mark Lobodzinski209b5292015-09-17 09:44:05 -06008821
Chia-I Wu1b99bb22015-10-27 19:25:11 +08008822 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008823 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
8824 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -06008825
8826 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008827 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
8828 ds_pool_ci.pNext = NULL;
8829 ds_pool_ci.maxSets = 1;
8830 ds_pool_ci.poolSizeCount = 1;
8831 ds_pool_ci.pPoolSizes = &ds_type_count;
Mark Lobodzinski209b5292015-09-17 09:44:05 -06008832
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06008833 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008834 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06008835 ASSERT_VK_SUCCESS(err);
8836
Tony Barboureb254902015-07-15 12:50:33 -06008837 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008838 dsl_binding.binding = 0;
8839 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
8840 dsl_binding.descriptorCount = 1;
8841 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
8842 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06008843
Tony Barboureb254902015-07-15 12:50:33 -06008844 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008845 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
8846 ds_layout_ci.pNext = NULL;
8847 ds_layout_ci.bindingCount = 1;
8848 ds_layout_ci.pBindings = &dsl_binding;
Tony Barboureb254902015-07-15 12:50:33 -06008849
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06008850 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008851 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06008852 ASSERT_VK_SUCCESS(err);
8853
8854 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08008855 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08008856 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07008857 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06008858 alloc_info.descriptorPool = ds_pool;
8859 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008860 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06008861 ASSERT_VK_SUCCESS(err);
8862
Tony Barboureb254902015-07-15 12:50:33 -06008863 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008864 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
8865 pipeline_layout_ci.setLayoutCount = 1;
8866 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06008867
8868 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008869 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06008870 ASSERT_VK_SUCCESS(err);
8871
Tobin Ehlise68360f2015-10-01 11:15:13 -06008872 VkViewport vp = {}; // Just need dummy vp to point to
Karl Schultz6addd812016-02-02 17:17:23 -07008873 VkRect2D sc = {}; // dummy scissor to point to
Tobin Ehlise68360f2015-10-01 11:15:13 -06008874
8875 VkPipelineViewportStateCreateInfo vp_state_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008876 vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
8877 vp_state_ci.scissorCount = 1;
8878 vp_state_ci.pScissors = &sc;
8879 vp_state_ci.viewportCount = 1;
8880 vp_state_ci.pViewports = &vp;
Tobin Ehlise68360f2015-10-01 11:15:13 -06008881
Karl Schultzdfdb8d42016-03-08 10:30:21 -07008882 VkPipelineRasterizationStateCreateInfo rs_state_ci = {};
8883 rs_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
8884 rs_state_ci.polygonMode = VK_POLYGON_MODE_FILL;
8885 rs_state_ci.cullMode = VK_CULL_MODE_BACK_BIT;
8886 rs_state_ci.frontFace = VK_FRONT_FACE_COUNTER_CLOCKWISE;
8887 rs_state_ci.depthClampEnable = VK_FALSE;
8888 rs_state_ci.rasterizerDiscardEnable = VK_FALSE;
8889 rs_state_ci.depthBiasEnable = VK_FALSE;
8890
Tony Barboureb254902015-07-15 12:50:33 -06008891 VkGraphicsPipelineCreateInfo gp_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008892 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
8893 gp_ci.pViewportState = &vp_state_ci;
Karl Schultzdfdb8d42016-03-08 10:30:21 -07008894 gp_ci.pRasterizationState = &rs_state_ci;
Karl Schultz6addd812016-02-02 17:17:23 -07008895 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
8896 gp_ci.layout = pipeline_layout;
8897 gp_ci.renderPass = renderPass();
Tony Barboureb254902015-07-15 12:50:33 -06008898
8899 VkPipelineCacheCreateInfo pc_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008900 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
8901 pc_ci.initialDataSize = 0;
8902 pc_ci.pInitialData = 0;
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06008903
8904 VkPipeline pipeline;
Jon Ashburnc669cc62015-07-09 15:02:25 -06008905 VkPipelineCache pipelineCache;
8906
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008907 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Jon Ashburnc669cc62015-07-09 15:02:25 -06008908 ASSERT_VK_SUCCESS(err);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008909 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06008910
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008911 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06008912
Chia-I Wuf7458c52015-10-26 21:10:41 +08008913 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
8914 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
8915 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
8916 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06008917}
Tobin Ehlis912df022015-09-17 08:46:18 -06008918/*// TODO : This test should be good, but needs Tess support in compiler to run
8919TEST_F(VkLayerTest, InvalidPatchControlPoints)
8920{
8921 // Attempt to Create Gfx Pipeline w/o a VS
Tobin Ehlis912df022015-09-17 08:46:18 -06008922 VkResult err;
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06008923
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07008924 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Karl Schultz6addd812016-02-02 17:17:23 -07008925 "Invalid Pipeline CreateInfo State: VK_PRIMITIVE_TOPOLOGY_PATCH
8926primitive ");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06008927
Tobin Ehlis912df022015-09-17 08:46:18 -06008928 ASSERT_NO_FATAL_FAILURE(InitState());
8929 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlis912df022015-09-17 08:46:18 -06008930
Chia-I Wu1b99bb22015-10-27 19:25:11 +08008931 VkDescriptorPoolSize ds_type_count = {};
Tobin Ehlis912df022015-09-17 08:46:18 -06008932 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Chia-I Wud50a7d72015-10-26 20:48:51 +08008933 ds_type_count.descriptorCount = 1;
Tobin Ehlis912df022015-09-17 08:46:18 -06008934
8935 VkDescriptorPoolCreateInfo ds_pool_ci = {};
8936 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
8937 ds_pool_ci.pNext = NULL;
Chia-I Wu1b99bb22015-10-27 19:25:11 +08008938 ds_pool_ci.poolSizeCount = 1;
8939 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlis912df022015-09-17 08:46:18 -06008940
8941 VkDescriptorPool ds_pool;
Karl Schultz6addd812016-02-02 17:17:23 -07008942 err = vkCreateDescriptorPool(m_device->device(),
8943VK_DESCRIPTOR_POOL_USAGE_NON_FREE, 1, &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis912df022015-09-17 08:46:18 -06008944 ASSERT_VK_SUCCESS(err);
8945
8946 VkDescriptorSetLayoutBinding dsl_binding = {};
Chia-I Wud46e6ae2015-10-31 00:31:16 +08008947 dsl_binding.binding = 0;
Tobin Ehlis912df022015-09-17 08:46:18 -06008948 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Chia-I Wu02124482015-11-06 06:42:02 +08008949 dsl_binding.descriptorCount = 1;
Tobin Ehlis912df022015-09-17 08:46:18 -06008950 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
8951 dsl_binding.pImmutableSamplers = NULL;
8952
8953 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008954 ds_layout_ci.sType =
8955VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
Tobin Ehlis912df022015-09-17 08:46:18 -06008956 ds_layout_ci.pNext = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08008957 ds_layout_ci.bindingCount = 1;
Jon Ashburn6e23c1f2015-12-30 18:01:16 -07008958 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlis912df022015-09-17 08:46:18 -06008959
8960 VkDescriptorSetLayout ds_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07008961 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL,
8962&ds_layout);
Tobin Ehlis912df022015-09-17 08:46:18 -06008963 ASSERT_VK_SUCCESS(err);
8964
8965 VkDescriptorSet descriptorSet;
Karl Schultz6addd812016-02-02 17:17:23 -07008966 err = vkAllocateDescriptorSets(m_device->device(), ds_pool,
8967VK_DESCRIPTOR_SET_USAGE_NON_FREE, 1, &ds_layout, &descriptorSet);
Tobin Ehlis912df022015-09-17 08:46:18 -06008968 ASSERT_VK_SUCCESS(err);
8969
8970 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008971 pipeline_layout_ci.sType =
8972VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
Tobin Ehlis912df022015-09-17 08:46:18 -06008973 pipeline_layout_ci.pNext = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08008974 pipeline_layout_ci.setLayoutCount = 1;
Tobin Ehlis912df022015-09-17 08:46:18 -06008975 pipeline_layout_ci.pSetLayouts = &ds_layout;
8976
8977 VkPipelineLayout pipeline_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07008978 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL,
8979&pipeline_layout);
Tobin Ehlis912df022015-09-17 08:46:18 -06008980 ASSERT_VK_SUCCESS(err);
8981
8982 VkPipelineShaderStageCreateInfo shaderStages[3];
8983 memset(&shaderStages, 0, 3 * sizeof(VkPipelineShaderStageCreateInfo));
8984
Karl Schultz6addd812016-02-02 17:17:23 -07008985 VkShaderObj vs(m_device,bindStateVertShaderText,VK_SHADER_STAGE_VERTEX_BIT,
8986this);
Tobin Ehlis912df022015-09-17 08:46:18 -06008987 // Just using VS txt for Tess shaders as we don't care about functionality
Karl Schultz6addd812016-02-02 17:17:23 -07008988 VkShaderObj
8989tc(m_device,bindStateVertShaderText,VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT,
8990this);
8991 VkShaderObj
8992te(m_device,bindStateVertShaderText,VK_SHADER_STAGE_TESSELLATION_EVALUATION_BIT,
8993this);
Tobin Ehlis912df022015-09-17 08:46:18 -06008994
Karl Schultz6addd812016-02-02 17:17:23 -07008995 shaderStages[0].sType =
8996VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO;
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -06008997 shaderStages[0].stage = VK_SHADER_STAGE_VERTEX_BIT;
Tobin Ehlis912df022015-09-17 08:46:18 -06008998 shaderStages[0].shader = vs.handle();
Karl Schultz6addd812016-02-02 17:17:23 -07008999 shaderStages[1].sType =
9000VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO;
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -06009001 shaderStages[1].stage = VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT;
Tobin Ehlis912df022015-09-17 08:46:18 -06009002 shaderStages[1].shader = tc.handle();
Karl Schultz6addd812016-02-02 17:17:23 -07009003 shaderStages[2].sType =
9004VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO;
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -06009005 shaderStages[2].stage = VK_SHADER_STAGE_TESSELLATION_EVALUATION_BIT;
Tobin Ehlis912df022015-09-17 08:46:18 -06009006 shaderStages[2].shader = te.handle();
9007
9008 VkPipelineInputAssemblyStateCreateInfo iaCI = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009009 iaCI.sType =
9010VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
Chia-I Wu515eb8f2015-10-31 00:31:16 +08009011 iaCI.topology = VK_PRIMITIVE_TOPOLOGY_PATCH_LIST;
Tobin Ehlis912df022015-09-17 08:46:18 -06009012
9013 VkPipelineTessellationStateCreateInfo tsCI = {};
9014 tsCI.sType = VK_STRUCTURE_TYPE_PIPELINE_TESSELLATION_STATE_CREATE_INFO;
9015 tsCI.patchControlPoints = 0; // This will cause an error
9016
9017 VkGraphicsPipelineCreateInfo gp_ci = {};
9018 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
9019 gp_ci.pNext = NULL;
9020 gp_ci.stageCount = 3;
9021 gp_ci.pStages = shaderStages;
9022 gp_ci.pVertexInputState = NULL;
9023 gp_ci.pInputAssemblyState = &iaCI;
9024 gp_ci.pTessellationState = &tsCI;
9025 gp_ci.pViewportState = NULL;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009026 gp_ci.pRasterizationState = NULL;
Tobin Ehlis912df022015-09-17 08:46:18 -06009027 gp_ci.pMultisampleState = NULL;
9028 gp_ci.pDepthStencilState = NULL;
9029 gp_ci.pColorBlendState = NULL;
9030 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
9031 gp_ci.layout = pipeline_layout;
9032 gp_ci.renderPass = renderPass();
9033
9034 VkPipelineCacheCreateInfo pc_ci = {};
9035 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
9036 pc_ci.pNext = NULL;
9037 pc_ci.initialSize = 0;
9038 pc_ci.initialData = 0;
9039 pc_ci.maxSize = 0;
9040
9041 VkPipeline pipeline;
9042 VkPipelineCache pipelineCache;
9043
Karl Schultz6addd812016-02-02 17:17:23 -07009044 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL,
9045&pipelineCache);
Tobin Ehlis912df022015-09-17 08:46:18 -06009046 ASSERT_VK_SUCCESS(err);
Karl Schultz6addd812016-02-02 17:17:23 -07009047 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1,
9048&gp_ci, NULL, &pipeline);
Tobin Ehlis912df022015-09-17 08:46:18 -06009049
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009050 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06009051
Chia-I Wuf7458c52015-10-26 21:10:41 +08009052 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
9053 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
9054 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
9055 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis912df022015-09-17 08:46:18 -06009056}
9057*/
Tobin Ehlise68360f2015-10-01 11:15:13 -06009058// Set scissor and viewport counts to different numbers
Karl Schultz6addd812016-02-02 17:17:23 -07009059TEST_F(VkLayerTest, PSOViewportScissorCountMismatch) {
Karl Schultz6addd812016-02-02 17:17:23 -07009060 VkResult err;
Tobin Ehlise68360f2015-10-01 11:15:13 -06009061
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009062 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
9063 "Gfx Pipeline viewport count (1) must match scissor count (0).");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06009064
Tobin Ehlise68360f2015-10-01 11:15:13 -06009065 ASSERT_NO_FATAL_FAILURE(InitState());
9066 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlise68360f2015-10-01 11:15:13 -06009067
Chia-I Wu1b99bb22015-10-27 19:25:11 +08009068 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009069 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
9070 ds_type_count.descriptorCount = 1;
Tobin Ehlise68360f2015-10-01 11:15:13 -06009071
9072 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009073 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
9074 ds_pool_ci.maxSets = 1;
9075 ds_pool_ci.poolSizeCount = 1;
9076 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlise68360f2015-10-01 11:15:13 -06009077
9078 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009079 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlise68360f2015-10-01 11:15:13 -06009080 ASSERT_VK_SUCCESS(err);
9081
9082 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009083 dsl_binding.binding = 0;
9084 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
9085 dsl_binding.descriptorCount = 1;
9086 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
Tobin Ehlise68360f2015-10-01 11:15:13 -06009087
9088 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009089 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
9090 ds_layout_ci.bindingCount = 1;
9091 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlise68360f2015-10-01 11:15:13 -06009092
9093 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009094 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlise68360f2015-10-01 11:15:13 -06009095 ASSERT_VK_SUCCESS(err);
9096
9097 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009098 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08009099 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07009100 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06009101 alloc_info.descriptorPool = ds_pool;
9102 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009103 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlise68360f2015-10-01 11:15:13 -06009104 ASSERT_VK_SUCCESS(err);
9105
9106 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009107 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
9108 pipeline_layout_ci.setLayoutCount = 1;
9109 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlise68360f2015-10-01 11:15:13 -06009110
9111 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009112 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlise68360f2015-10-01 11:15:13 -06009113 ASSERT_VK_SUCCESS(err);
9114
9115 VkViewport vp = {}; // Just need dummy vp to point to
9116
9117 VkPipelineViewportStateCreateInfo vp_state_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009118 vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
9119 vp_state_ci.scissorCount = 0;
9120 vp_state_ci.viewportCount = 1; // Count mismatch should cause error
9121 vp_state_ci.pViewports = &vp;
Tobin Ehlise68360f2015-10-01 11:15:13 -06009122
Karl Schultzdfdb8d42016-03-08 10:30:21 -07009123 VkPipelineRasterizationStateCreateInfo rs_state_ci = {};
9124 rs_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
9125 rs_state_ci.polygonMode = VK_POLYGON_MODE_FILL;
9126 rs_state_ci.cullMode = VK_CULL_MODE_BACK_BIT;
9127 rs_state_ci.frontFace = VK_FRONT_FACE_COUNTER_CLOCKWISE;
9128 rs_state_ci.depthClampEnable = VK_FALSE;
9129 rs_state_ci.rasterizerDiscardEnable = VK_FALSE;
9130 rs_state_ci.depthBiasEnable = VK_FALSE;
9131
Cody Northropeb3a6c12015-10-05 14:44:45 -06009132 VkPipelineShaderStageCreateInfo shaderStages[2];
Karl Schultz6addd812016-02-02 17:17:23 -07009133 memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo));
Tobin Ehlise68360f2015-10-01 11:15:13 -06009134
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009135 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
9136 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this); // We shouldn't need a fragment shader
9137 // but add it to be able to run on more devices
Chia-I Wu28e06912015-10-31 00:31:16 +08009138 shaderStages[0] = vs.GetStageCreateInfo();
9139 shaderStages[1] = fs.GetStageCreateInfo();
Tobin Ehlise68360f2015-10-01 11:15:13 -06009140
9141 VkGraphicsPipelineCreateInfo gp_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009142 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
9143 gp_ci.stageCount = 2;
9144 gp_ci.pStages = shaderStages;
9145 gp_ci.pViewportState = &vp_state_ci;
Karl Schultzdfdb8d42016-03-08 10:30:21 -07009146 gp_ci.pRasterizationState = &rs_state_ci;
Karl Schultz6addd812016-02-02 17:17:23 -07009147 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
9148 gp_ci.layout = pipeline_layout;
9149 gp_ci.renderPass = renderPass();
Tobin Ehlise68360f2015-10-01 11:15:13 -06009150
9151 VkPipelineCacheCreateInfo pc_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009152 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
Tobin Ehlise68360f2015-10-01 11:15:13 -06009153
9154 VkPipeline pipeline;
9155 VkPipelineCache pipelineCache;
9156
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009157 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Tobin Ehlise68360f2015-10-01 11:15:13 -06009158 ASSERT_VK_SUCCESS(err);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009159 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Tobin Ehlise68360f2015-10-01 11:15:13 -06009160
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009161 m_errorMonitor->VerifyFound();
Tobin Ehlise68360f2015-10-01 11:15:13 -06009162
Chia-I Wuf7458c52015-10-26 21:10:41 +08009163 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
9164 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
9165 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
9166 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlise68360f2015-10-01 11:15:13 -06009167}
Karl Schultz6addd812016-02-02 17:17:23 -07009168// Don't set viewport state in PSO. This is an error b/c we always need this
9169// state
Tobin Ehlisd332f282015-10-02 11:00:56 -06009170// for the counts even if the data is going to be set dynamically.
Karl Schultz6addd812016-02-02 17:17:23 -07009171TEST_F(VkLayerTest, PSOViewportStateNotSet) {
Tobin Ehlise68360f2015-10-01 11:15:13 -06009172 // Attempt to Create Gfx Pipeline w/o a VS
Karl Schultz6addd812016-02-02 17:17:23 -07009173 VkResult err;
Tobin Ehlise68360f2015-10-01 11:15:13 -06009174
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009175 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Gfx Pipeline pViewportState is null. Even if ");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06009176
Tobin Ehlise68360f2015-10-01 11:15:13 -06009177 ASSERT_NO_FATAL_FAILURE(InitState());
9178 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlise68360f2015-10-01 11:15:13 -06009179
Chia-I Wu1b99bb22015-10-27 19:25:11 +08009180 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009181 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
9182 ds_type_count.descriptorCount = 1;
Tobin Ehlise68360f2015-10-01 11:15:13 -06009183
9184 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009185 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
9186 ds_pool_ci.maxSets = 1;
9187 ds_pool_ci.poolSizeCount = 1;
9188 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlise68360f2015-10-01 11:15:13 -06009189
9190 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009191 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlise68360f2015-10-01 11:15:13 -06009192 ASSERT_VK_SUCCESS(err);
9193
9194 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009195 dsl_binding.binding = 0;
9196 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
9197 dsl_binding.descriptorCount = 1;
9198 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
Tobin Ehlise68360f2015-10-01 11:15:13 -06009199
9200 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009201 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
9202 ds_layout_ci.bindingCount = 1;
9203 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlise68360f2015-10-01 11:15:13 -06009204
9205 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009206 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlise68360f2015-10-01 11:15:13 -06009207 ASSERT_VK_SUCCESS(err);
9208
9209 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009210 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08009211 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07009212 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06009213 alloc_info.descriptorPool = ds_pool;
9214 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009215 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlise68360f2015-10-01 11:15:13 -06009216 ASSERT_VK_SUCCESS(err);
9217
9218 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009219 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
9220 pipeline_layout_ci.setLayoutCount = 1;
9221 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlise68360f2015-10-01 11:15:13 -06009222
9223 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009224 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlise68360f2015-10-01 11:15:13 -06009225 ASSERT_VK_SUCCESS(err);
9226
9227 VkDynamicState sc_state = VK_DYNAMIC_STATE_SCISSOR;
9228 // Set scissor as dynamic to avoid second error
9229 VkPipelineDynamicStateCreateInfo dyn_state_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009230 dyn_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_DYNAMIC_STATE_CREATE_INFO;
9231 dyn_state_ci.dynamicStateCount = 1;
9232 dyn_state_ci.pDynamicStates = &sc_state;
Tobin Ehlise68360f2015-10-01 11:15:13 -06009233
Cody Northropeb3a6c12015-10-05 14:44:45 -06009234 VkPipelineShaderStageCreateInfo shaderStages[2];
Karl Schultz6addd812016-02-02 17:17:23 -07009235 memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo));
Tobin Ehlise68360f2015-10-01 11:15:13 -06009236
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009237 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
9238 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this); // We shouldn't need a fragment shader
9239 // but add it to be able to run on more devices
Chia-I Wu28e06912015-10-31 00:31:16 +08009240 shaderStages[0] = vs.GetStageCreateInfo();
9241 shaderStages[1] = fs.GetStageCreateInfo();
Tobin Ehlise68360f2015-10-01 11:15:13 -06009242
Karl Schultzdfdb8d42016-03-08 10:30:21 -07009243 VkPipelineRasterizationStateCreateInfo rs_state_ci = {};
9244 rs_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
9245 rs_state_ci.polygonMode = VK_POLYGON_MODE_FILL;
9246 rs_state_ci.cullMode = VK_CULL_MODE_BACK_BIT;
9247 rs_state_ci.frontFace = VK_FRONT_FACE_COUNTER_CLOCKWISE;
9248 rs_state_ci.depthClampEnable = VK_FALSE;
9249 rs_state_ci.rasterizerDiscardEnable = VK_FALSE;
9250 rs_state_ci.depthBiasEnable = VK_FALSE;
9251
Tobin Ehlise68360f2015-10-01 11:15:13 -06009252 VkGraphicsPipelineCreateInfo gp_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009253 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
9254 gp_ci.stageCount = 2;
9255 gp_ci.pStages = shaderStages;
Karl Schultzdfdb8d42016-03-08 10:30:21 -07009256 gp_ci.pRasterizationState = &rs_state_ci;
Karl Schultz6addd812016-02-02 17:17:23 -07009257 gp_ci.pViewportState = NULL; // Not setting VP state w/o dynamic vp state
9258 // should cause validation error
9259 gp_ci.pDynamicState = &dyn_state_ci;
9260 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
9261 gp_ci.layout = pipeline_layout;
9262 gp_ci.renderPass = renderPass();
Tobin Ehlise68360f2015-10-01 11:15:13 -06009263
9264 VkPipelineCacheCreateInfo pc_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009265 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
Tobin Ehlise68360f2015-10-01 11:15:13 -06009266
9267 VkPipeline pipeline;
9268 VkPipelineCache pipelineCache;
9269
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009270 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Tobin Ehlise68360f2015-10-01 11:15:13 -06009271 ASSERT_VK_SUCCESS(err);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009272 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Tobin Ehlise68360f2015-10-01 11:15:13 -06009273
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009274 m_errorMonitor->VerifyFound();
Tobin Ehlise68360f2015-10-01 11:15:13 -06009275
Chia-I Wuf7458c52015-10-26 21:10:41 +08009276 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
9277 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
9278 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
9279 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlise68360f2015-10-01 11:15:13 -06009280}
9281// Create PSO w/o non-zero viewportCount but no viewport data
Karl Schultz6addd812016-02-02 17:17:23 -07009282// Then run second test where dynamic scissor count doesn't match PSO scissor
9283// count
9284TEST_F(VkLayerTest, PSOViewportCountWithoutDataAndDynScissorMismatch) {
9285 VkResult err;
Tobin Ehlise68360f2015-10-01 11:15:13 -06009286
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009287 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
9288 "Gfx Pipeline viewportCount is 1, but pViewports is NULL. ");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06009289
Tobin Ehlise68360f2015-10-01 11:15:13 -06009290 ASSERT_NO_FATAL_FAILURE(InitState());
Chris Forbesc08a6ca2016-07-28 14:14:07 +12009291
9292 if (!m_device->phy().features().multiViewport) {
9293 printf("Device does not support multiple viewports/scissors; skipped.\n");
9294 return;
9295 }
9296
Tobin Ehlise68360f2015-10-01 11:15:13 -06009297 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlise68360f2015-10-01 11:15:13 -06009298
Chia-I Wu1b99bb22015-10-27 19:25:11 +08009299 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009300 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
9301 ds_type_count.descriptorCount = 1;
Tobin Ehlise68360f2015-10-01 11:15:13 -06009302
9303 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009304 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
9305 ds_pool_ci.maxSets = 1;
9306 ds_pool_ci.poolSizeCount = 1;
9307 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlise68360f2015-10-01 11:15:13 -06009308
9309 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009310 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlise68360f2015-10-01 11:15:13 -06009311 ASSERT_VK_SUCCESS(err);
9312
9313 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009314 dsl_binding.binding = 0;
9315 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
9316 dsl_binding.descriptorCount = 1;
9317 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
Tobin Ehlise68360f2015-10-01 11:15:13 -06009318
9319 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009320 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
9321 ds_layout_ci.bindingCount = 1;
9322 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlise68360f2015-10-01 11:15:13 -06009323
9324 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009325 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlise68360f2015-10-01 11:15:13 -06009326 ASSERT_VK_SUCCESS(err);
9327
9328 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009329 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08009330 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07009331 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06009332 alloc_info.descriptorPool = ds_pool;
9333 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009334 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlise68360f2015-10-01 11:15:13 -06009335 ASSERT_VK_SUCCESS(err);
9336
9337 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009338 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
9339 pipeline_layout_ci.setLayoutCount = 1;
9340 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlise68360f2015-10-01 11:15:13 -06009341
9342 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009343 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlise68360f2015-10-01 11:15:13 -06009344 ASSERT_VK_SUCCESS(err);
9345
9346 VkPipelineViewportStateCreateInfo vp_state_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009347 vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
9348 vp_state_ci.viewportCount = 1;
9349 vp_state_ci.pViewports = NULL; // Null vp w/ count of 1 should cause error
9350 vp_state_ci.scissorCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009351 vp_state_ci.pScissors = NULL; // Scissor is dynamic (below) so this won't cause error
Tobin Ehlise68360f2015-10-01 11:15:13 -06009352
9353 VkDynamicState sc_state = VK_DYNAMIC_STATE_SCISSOR;
9354 // Set scissor as dynamic to avoid that error
9355 VkPipelineDynamicStateCreateInfo dyn_state_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009356 dyn_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_DYNAMIC_STATE_CREATE_INFO;
9357 dyn_state_ci.dynamicStateCount = 1;
9358 dyn_state_ci.pDynamicStates = &sc_state;
Tobin Ehlise68360f2015-10-01 11:15:13 -06009359
Cody Northropeb3a6c12015-10-05 14:44:45 -06009360 VkPipelineShaderStageCreateInfo shaderStages[2];
Karl Schultz6addd812016-02-02 17:17:23 -07009361 memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo));
Tobin Ehlise68360f2015-10-01 11:15:13 -06009362
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009363 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
9364 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this); // We shouldn't need a fragment shader
9365 // but add it to be able to run on more devices
Chia-I Wu28e06912015-10-31 00:31:16 +08009366 shaderStages[0] = vs.GetStageCreateInfo();
9367 shaderStages[1] = fs.GetStageCreateInfo();
Tobin Ehlise68360f2015-10-01 11:15:13 -06009368
Cody Northropf6622dc2015-10-06 10:33:21 -06009369 VkPipelineVertexInputStateCreateInfo vi_ci = {};
9370 vi_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
9371 vi_ci.pNext = nullptr;
Chia-I Wud50a7d72015-10-26 20:48:51 +08009372 vi_ci.vertexBindingDescriptionCount = 0;
Cody Northropf6622dc2015-10-06 10:33:21 -06009373 vi_ci.pVertexBindingDescriptions = nullptr;
Chia-I Wud50a7d72015-10-26 20:48:51 +08009374 vi_ci.vertexAttributeDescriptionCount = 0;
Cody Northropf6622dc2015-10-06 10:33:21 -06009375 vi_ci.pVertexAttributeDescriptions = nullptr;
9376
9377 VkPipelineInputAssemblyStateCreateInfo ia_ci = {};
9378 ia_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
9379 ia_ci.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP;
9380
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009381 VkPipelineRasterizationStateCreateInfo rs_ci = {};
Chia-I Wu1b99bb22015-10-27 19:25:11 +08009382 rs_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
Cody Northropf6622dc2015-10-06 10:33:21 -06009383 rs_ci.pNext = nullptr;
9384
Mark Youngc89c6312016-03-31 16:03:20 -06009385 VkPipelineColorBlendAttachmentState att = {};
9386 att.blendEnable = VK_FALSE;
9387 att.colorWriteMask = 0xf;
9388
Cody Northropf6622dc2015-10-06 10:33:21 -06009389 VkPipelineColorBlendStateCreateInfo cb_ci = {};
9390 cb_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO;
9391 cb_ci.pNext = nullptr;
Mark Youngc89c6312016-03-31 16:03:20 -06009392 cb_ci.attachmentCount = 1;
9393 cb_ci.pAttachments = &att;
Cody Northropf6622dc2015-10-06 10:33:21 -06009394
Tobin Ehlise68360f2015-10-01 11:15:13 -06009395 VkGraphicsPipelineCreateInfo gp_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009396 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
9397 gp_ci.stageCount = 2;
9398 gp_ci.pStages = shaderStages;
9399 gp_ci.pVertexInputState = &vi_ci;
9400 gp_ci.pInputAssemblyState = &ia_ci;
9401 gp_ci.pViewportState = &vp_state_ci;
9402 gp_ci.pRasterizationState = &rs_ci;
9403 gp_ci.pColorBlendState = &cb_ci;
9404 gp_ci.pDynamicState = &dyn_state_ci;
9405 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
9406 gp_ci.layout = pipeline_layout;
9407 gp_ci.renderPass = renderPass();
Tobin Ehlise68360f2015-10-01 11:15:13 -06009408
9409 VkPipelineCacheCreateInfo pc_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009410 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
Tobin Ehlise68360f2015-10-01 11:15:13 -06009411
9412 VkPipeline pipeline;
9413 VkPipelineCache pipelineCache;
9414
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009415 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Tobin Ehlise68360f2015-10-01 11:15:13 -06009416 ASSERT_VK_SUCCESS(err);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009417 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Tobin Ehlise68360f2015-10-01 11:15:13 -06009418
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009419 m_errorMonitor->VerifyFound();
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06009420
Tobin Ehlisd332f282015-10-02 11:00:56 -06009421 // Now hit second fail case where we set scissor w/ different count than PSO
Karl Schultz6addd812016-02-02 17:17:23 -07009422 // First need to successfully create the PSO from above by setting
9423 // pViewports
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009424 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Dynamic scissor(s) 0 are used by PSO, ");
Karl Schultz6addd812016-02-02 17:17:23 -07009425
9426 VkViewport vp = {}; // Just need dummy vp to point to
9427 vp_state_ci.pViewports = &vp;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009428 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Karl Schultz6addd812016-02-02 17:17:23 -07009429 ASSERT_VK_SUCCESS(err);
9430 BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009431 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline);
Chris Forbesc08a6ca2016-07-28 14:14:07 +12009432 VkRect2D scissors[1] = {}; // don't care about data
Karl Schultz6addd812016-02-02 17:17:23 -07009433 // Count of 2 doesn't match PSO count of 1
Chris Forbesc08a6ca2016-07-28 14:14:07 +12009434 vkCmdSetScissor(m_commandBuffer->GetBufferHandle(), 1, 1, scissors);
Karl Schultz6addd812016-02-02 17:17:23 -07009435 Draw(1, 0, 0, 0);
9436
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009437 m_errorMonitor->VerifyFound();
Karl Schultz6addd812016-02-02 17:17:23 -07009438
9439 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
9440 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
9441 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
9442 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tony Barbourdf4c0042016-06-01 15:55:43 -06009443 vkDestroyPipeline(m_device->device(), pipeline, NULL);
Karl Schultz6addd812016-02-02 17:17:23 -07009444}
9445// Create PSO w/o non-zero scissorCount but no scissor data
9446// Then run second test where dynamic viewportCount doesn't match PSO
9447// viewportCount
9448TEST_F(VkLayerTest, PSOScissorCountWithoutDataAndDynViewportMismatch) {
9449 VkResult err;
9450
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009451 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 -07009452
9453 ASSERT_NO_FATAL_FAILURE(InitState());
Chris Forbesc08a6ca2016-07-28 14:14:07 +12009454
9455 if (!m_device->phy().features().multiViewport) {
9456 printf("Device does not support multiple viewports/scissors; skipped.\n");
9457 return;
9458 }
9459
Karl Schultz6addd812016-02-02 17:17:23 -07009460 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
9461
9462 VkDescriptorPoolSize ds_type_count = {};
9463 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
9464 ds_type_count.descriptorCount = 1;
9465
9466 VkDescriptorPoolCreateInfo ds_pool_ci = {};
9467 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
9468 ds_pool_ci.maxSets = 1;
9469 ds_pool_ci.poolSizeCount = 1;
9470 ds_pool_ci.pPoolSizes = &ds_type_count;
9471
9472 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009473 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Karl Schultz6addd812016-02-02 17:17:23 -07009474 ASSERT_VK_SUCCESS(err);
9475
9476 VkDescriptorSetLayoutBinding dsl_binding = {};
9477 dsl_binding.binding = 0;
9478 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
9479 dsl_binding.descriptorCount = 1;
9480 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
9481
9482 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
9483 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
9484 ds_layout_ci.bindingCount = 1;
9485 ds_layout_ci.pBindings = &dsl_binding;
9486
9487 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009488 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Karl Schultz6addd812016-02-02 17:17:23 -07009489 ASSERT_VK_SUCCESS(err);
9490
9491 VkDescriptorSet descriptorSet;
9492 VkDescriptorSetAllocateInfo alloc_info = {};
9493 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
9494 alloc_info.descriptorSetCount = 1;
9495 alloc_info.descriptorPool = ds_pool;
9496 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009497 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Karl Schultz6addd812016-02-02 17:17:23 -07009498 ASSERT_VK_SUCCESS(err);
9499
9500 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
9501 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
9502 pipeline_layout_ci.setLayoutCount = 1;
9503 pipeline_layout_ci.pSetLayouts = &ds_layout;
9504
9505 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009506 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Karl Schultz6addd812016-02-02 17:17:23 -07009507 ASSERT_VK_SUCCESS(err);
9508
9509 VkPipelineViewportStateCreateInfo vp_state_ci = {};
9510 vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
9511 vp_state_ci.scissorCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009512 vp_state_ci.pScissors = NULL; // Null scissor w/ count of 1 should cause error
Karl Schultz6addd812016-02-02 17:17:23 -07009513 vp_state_ci.viewportCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009514 vp_state_ci.pViewports = NULL; // vp is dynamic (below) so this won't cause error
Karl Schultz6addd812016-02-02 17:17:23 -07009515
9516 VkDynamicState vp_state = VK_DYNAMIC_STATE_VIEWPORT;
9517 // Set scissor as dynamic to avoid that error
9518 VkPipelineDynamicStateCreateInfo dyn_state_ci = {};
9519 dyn_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_DYNAMIC_STATE_CREATE_INFO;
9520 dyn_state_ci.dynamicStateCount = 1;
9521 dyn_state_ci.pDynamicStates = &vp_state;
9522
9523 VkPipelineShaderStageCreateInfo shaderStages[2];
9524 memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo));
9525
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009526 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
9527 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this); // We shouldn't need a fragment shader
9528 // but add it to be able to run on more devices
Karl Schultz6addd812016-02-02 17:17:23 -07009529 shaderStages[0] = vs.GetStageCreateInfo();
9530 shaderStages[1] = fs.GetStageCreateInfo();
9531
9532 VkPipelineVertexInputStateCreateInfo vi_ci = {};
9533 vi_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
9534 vi_ci.pNext = nullptr;
9535 vi_ci.vertexBindingDescriptionCount = 0;
9536 vi_ci.pVertexBindingDescriptions = nullptr;
9537 vi_ci.vertexAttributeDescriptionCount = 0;
9538 vi_ci.pVertexAttributeDescriptions = nullptr;
9539
9540 VkPipelineInputAssemblyStateCreateInfo ia_ci = {};
9541 ia_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
9542 ia_ci.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP;
9543
9544 VkPipelineRasterizationStateCreateInfo rs_ci = {};
9545 rs_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
9546 rs_ci.pNext = nullptr;
9547
Mark Youngc89c6312016-03-31 16:03:20 -06009548 VkPipelineColorBlendAttachmentState att = {};
9549 att.blendEnable = VK_FALSE;
9550 att.colorWriteMask = 0xf;
9551
Karl Schultz6addd812016-02-02 17:17:23 -07009552 VkPipelineColorBlendStateCreateInfo cb_ci = {};
9553 cb_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO;
9554 cb_ci.pNext = nullptr;
Mark Youngc89c6312016-03-31 16:03:20 -06009555 cb_ci.attachmentCount = 1;
9556 cb_ci.pAttachments = &att;
Karl Schultz6addd812016-02-02 17:17:23 -07009557
9558 VkGraphicsPipelineCreateInfo gp_ci = {};
9559 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
9560 gp_ci.stageCount = 2;
9561 gp_ci.pStages = shaderStages;
9562 gp_ci.pVertexInputState = &vi_ci;
9563 gp_ci.pInputAssemblyState = &ia_ci;
9564 gp_ci.pViewportState = &vp_state_ci;
9565 gp_ci.pRasterizationState = &rs_ci;
9566 gp_ci.pColorBlendState = &cb_ci;
9567 gp_ci.pDynamicState = &dyn_state_ci;
9568 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
9569 gp_ci.layout = pipeline_layout;
9570 gp_ci.renderPass = renderPass();
9571
9572 VkPipelineCacheCreateInfo pc_ci = {};
9573 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
9574
9575 VkPipeline pipeline;
9576 VkPipelineCache pipelineCache;
9577
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009578 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Karl Schultz6addd812016-02-02 17:17:23 -07009579 ASSERT_VK_SUCCESS(err);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009580 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Karl Schultz6addd812016-02-02 17:17:23 -07009581
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009582 m_errorMonitor->VerifyFound();
Karl Schultz6addd812016-02-02 17:17:23 -07009583
9584 // Now hit second fail case where we set scissor w/ different count than PSO
9585 // First need to successfully create the PSO from above by setting
9586 // pViewports
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009587 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Dynamic viewport(s) 0 are used by PSO, ");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06009588
Tobin Ehlisd332f282015-10-02 11:00:56 -06009589 VkRect2D sc = {}; // Just need dummy vp to point to
9590 vp_state_ci.pScissors = &sc;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009591 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Tobin Ehlisd332f282015-10-02 11:00:56 -06009592 ASSERT_VK_SUCCESS(err);
9593 BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009594 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline);
Chris Forbesc08a6ca2016-07-28 14:14:07 +12009595 VkViewport viewports[1] = {}; // don't care about data
Tobin Ehlisd332f282015-10-02 11:00:56 -06009596 // Count of 2 doesn't match PSO count of 1
Chris Forbesc08a6ca2016-07-28 14:14:07 +12009597 vkCmdSetViewport(m_commandBuffer->GetBufferHandle(), 1, 1, viewports);
Tobin Ehlisd332f282015-10-02 11:00:56 -06009598 Draw(1, 0, 0, 0);
9599
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009600 m_errorMonitor->VerifyFound();
Tobin Ehlise68360f2015-10-01 11:15:13 -06009601
Chia-I Wuf7458c52015-10-26 21:10:41 +08009602 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
9603 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
9604 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
9605 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tony Barbourdf4c0042016-06-01 15:55:43 -06009606 vkDestroyPipeline(m_device->device(), pipeline, NULL);
Tobin Ehlise68360f2015-10-01 11:15:13 -06009607}
9608
Mark Young7394fdd2016-03-31 14:56:43 -06009609TEST_F(VkLayerTest, PSOLineWidthInvalid) {
9610 VkResult err;
9611
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009612 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Attempt to set lineWidth to -1");
Mark Young7394fdd2016-03-31 14:56:43 -06009613
9614 ASSERT_NO_FATAL_FAILURE(InitState());
9615 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
9616
9617 VkDescriptorPoolSize ds_type_count = {};
9618 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
9619 ds_type_count.descriptorCount = 1;
9620
9621 VkDescriptorPoolCreateInfo ds_pool_ci = {};
9622 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
9623 ds_pool_ci.maxSets = 1;
9624 ds_pool_ci.poolSizeCount = 1;
9625 ds_pool_ci.pPoolSizes = &ds_type_count;
9626
9627 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009628 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Mark Young7394fdd2016-03-31 14:56:43 -06009629 ASSERT_VK_SUCCESS(err);
9630
9631 VkDescriptorSetLayoutBinding dsl_binding = {};
9632 dsl_binding.binding = 0;
9633 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
9634 dsl_binding.descriptorCount = 1;
9635 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
9636
9637 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
9638 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
9639 ds_layout_ci.bindingCount = 1;
9640 ds_layout_ci.pBindings = &dsl_binding;
9641
9642 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009643 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Mark Young7394fdd2016-03-31 14:56:43 -06009644 ASSERT_VK_SUCCESS(err);
9645
9646 VkDescriptorSet descriptorSet;
9647 VkDescriptorSetAllocateInfo alloc_info = {};
9648 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
9649 alloc_info.descriptorSetCount = 1;
9650 alloc_info.descriptorPool = ds_pool;
9651 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009652 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Mark Young7394fdd2016-03-31 14:56:43 -06009653 ASSERT_VK_SUCCESS(err);
9654
9655 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
9656 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
9657 pipeline_layout_ci.setLayoutCount = 1;
9658 pipeline_layout_ci.pSetLayouts = &ds_layout;
9659
9660 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009661 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Mark Young7394fdd2016-03-31 14:56:43 -06009662 ASSERT_VK_SUCCESS(err);
9663
9664 VkPipelineViewportStateCreateInfo vp_state_ci = {};
9665 vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
9666 vp_state_ci.scissorCount = 1;
9667 vp_state_ci.pScissors = NULL;
9668 vp_state_ci.viewportCount = 1;
9669 vp_state_ci.pViewports = NULL;
9670
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009671 VkDynamicState dynamic_states[3] = {VK_DYNAMIC_STATE_VIEWPORT, VK_DYNAMIC_STATE_SCISSOR, VK_DYNAMIC_STATE_LINE_WIDTH};
Mark Young7394fdd2016-03-31 14:56:43 -06009672 // Set scissor as dynamic to avoid that error
9673 VkPipelineDynamicStateCreateInfo dyn_state_ci = {};
9674 dyn_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_DYNAMIC_STATE_CREATE_INFO;
9675 dyn_state_ci.dynamicStateCount = 2;
9676 dyn_state_ci.pDynamicStates = dynamic_states;
9677
9678 VkPipelineShaderStageCreateInfo shaderStages[2];
9679 memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo));
9680
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009681 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
9682 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT,
Mark Young7394fdd2016-03-31 14:56:43 -06009683 this); // TODO - We shouldn't need a fragment shader
9684 // but add it to be able to run on more devices
9685 shaderStages[0] = vs.GetStageCreateInfo();
9686 shaderStages[1] = fs.GetStageCreateInfo();
9687
9688 VkPipelineVertexInputStateCreateInfo vi_ci = {};
9689 vi_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
9690 vi_ci.pNext = nullptr;
9691 vi_ci.vertexBindingDescriptionCount = 0;
9692 vi_ci.pVertexBindingDescriptions = nullptr;
9693 vi_ci.vertexAttributeDescriptionCount = 0;
9694 vi_ci.pVertexAttributeDescriptions = nullptr;
9695
9696 VkPipelineInputAssemblyStateCreateInfo ia_ci = {};
9697 ia_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
9698 ia_ci.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP;
9699
9700 VkPipelineRasterizationStateCreateInfo rs_ci = {};
9701 rs_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
9702 rs_ci.pNext = nullptr;
9703
Mark Young47107952016-05-02 15:59:55 -06009704 // Check too low (line width of -1.0f).
9705 rs_ci.lineWidth = -1.0f;
Mark Young7394fdd2016-03-31 14:56:43 -06009706
9707 VkPipelineColorBlendAttachmentState att = {};
9708 att.blendEnable = VK_FALSE;
9709 att.colorWriteMask = 0xf;
9710
9711 VkPipelineColorBlendStateCreateInfo cb_ci = {};
9712 cb_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO;
9713 cb_ci.pNext = nullptr;
9714 cb_ci.attachmentCount = 1;
9715 cb_ci.pAttachments = &att;
9716
9717 VkGraphicsPipelineCreateInfo gp_ci = {};
9718 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
9719 gp_ci.stageCount = 2;
9720 gp_ci.pStages = shaderStages;
9721 gp_ci.pVertexInputState = &vi_ci;
9722 gp_ci.pInputAssemblyState = &ia_ci;
9723 gp_ci.pViewportState = &vp_state_ci;
9724 gp_ci.pRasterizationState = &rs_ci;
9725 gp_ci.pColorBlendState = &cb_ci;
9726 gp_ci.pDynamicState = &dyn_state_ci;
9727 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
9728 gp_ci.layout = pipeline_layout;
9729 gp_ci.renderPass = renderPass();
9730
9731 VkPipelineCacheCreateInfo pc_ci = {};
9732 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
9733
9734 VkPipeline pipeline;
9735 VkPipelineCache pipelineCache;
9736
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009737 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Mark Young7394fdd2016-03-31 14:56:43 -06009738 ASSERT_VK_SUCCESS(err);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009739 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Mark Young7394fdd2016-03-31 14:56:43 -06009740
9741 m_errorMonitor->VerifyFound();
Tony Barbourdf4c0042016-06-01 15:55:43 -06009742 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
Mark Young7394fdd2016-03-31 14:56:43 -06009743
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009744 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Attempt to set lineWidth to 65536");
Mark Young7394fdd2016-03-31 14:56:43 -06009745
9746 // Check too high (line width of 65536.0f).
9747 rs_ci.lineWidth = 65536.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
9753 m_errorMonitor->VerifyFound();
Tony Barbourdf4c0042016-06-01 15:55:43 -06009754 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
Mark Young7394fdd2016-03-31 14:56:43 -06009755
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009756 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Attempt to set lineWidth to -1");
Mark Young7394fdd2016-03-31 14:56:43 -06009757
9758 dyn_state_ci.dynamicStateCount = 3;
9759
9760 rs_ci.lineWidth = 1.0f;
9761
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009762 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Mark Young7394fdd2016-03-31 14:56:43 -06009763 ASSERT_VK_SUCCESS(err);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009764 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Mark Young7394fdd2016-03-31 14:56:43 -06009765 BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009766 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline);
Mark Young7394fdd2016-03-31 14:56:43 -06009767
9768 // Check too low with dynamic setting.
Mark Young47107952016-05-02 15:59:55 -06009769 vkCmdSetLineWidth(m_commandBuffer->GetBufferHandle(), -1.0f);
Mark Young7394fdd2016-03-31 14:56:43 -06009770 m_errorMonitor->VerifyFound();
9771
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009772 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Attempt to set lineWidth to 65536");
Mark Young7394fdd2016-03-31 14:56:43 -06009773
9774 // Check too high with dynamic setting.
9775 vkCmdSetLineWidth(m_commandBuffer->GetBufferHandle(), 65536.0f);
9776 m_errorMonitor->VerifyFound();
9777 EndCommandBuffer();
9778
9779 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
9780 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
9781 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
9782 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tony Barbourdf4c0042016-06-01 15:55:43 -06009783 vkDestroyPipeline(m_device->device(), pipeline, NULL);
Mark Young7394fdd2016-03-31 14:56:43 -06009784}
9785
Karl Schultz6addd812016-02-02 17:17:23 -07009786TEST_F(VkLayerTest, NullRenderPass) {
Tobin Ehlis98aa0ed2015-06-25 16:27:19 -06009787 // Bind a NULL RenderPass
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009788 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
9789 "You cannot use a NULL RenderPass object in vkCmdBeginRenderPass()");
Tobin Ehlis98aa0ed2015-06-25 16:27:19 -06009790
9791 ASSERT_NO_FATAL_FAILURE(InitState());
9792 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlis98aa0ed2015-06-25 16:27:19 -06009793
Tony Barbourfe3351b2015-07-28 10:17:20 -06009794 BeginCommandBuffer();
Karl Schultz6addd812016-02-02 17:17:23 -07009795 // Don't care about RenderPass handle b/c error should be flagged before
9796 // that
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009797 vkCmdBeginRenderPass(m_commandBuffer->GetBufferHandle(), NULL, VK_SUBPASS_CONTENTS_INLINE);
Tobin Ehlis98aa0ed2015-06-25 16:27:19 -06009798
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009799 m_errorMonitor->VerifyFound();
Tobin Ehlis98aa0ed2015-06-25 16:27:19 -06009800}
9801
Karl Schultz6addd812016-02-02 17:17:23 -07009802TEST_F(VkLayerTest, RenderPassWithinRenderPass) {
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06009803 // Bind a BeginRenderPass within an active RenderPass
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009804 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
9805 "It is invalid to issue this call inside an active render pass");
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06009806
9807 ASSERT_NO_FATAL_FAILURE(InitState());
9808 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06009809
Tony Barbourfe3351b2015-07-28 10:17:20 -06009810 BeginCommandBuffer();
Karl Schultz6addd812016-02-02 17:17:23 -07009811 // Just create a dummy Renderpass that's non-NULL so we can get to the
9812 // proper error
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009813 vkCmdBeginRenderPass(m_commandBuffer->GetBufferHandle(), &m_renderPassBeginInfo, VK_SUBPASS_CONTENTS_INLINE);
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06009814
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009815 m_errorMonitor->VerifyFound();
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06009816}
9817
Chris Forbes2eeabe32016-06-21 20:52:34 +12009818TEST_F(VkLayerTest, RenderPassSecondaryCommandBuffersMultipleTimes) {
9819 m_errorMonitor->ExpectSuccess();
9820
9821 ASSERT_NO_FATAL_FAILURE(InitState());
9822 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
9823
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009824 BeginCommandBuffer(); // framework implicitly begins the renderpass.
Chris Forbes2eeabe32016-06-21 20:52:34 +12009825 vkCmdEndRenderPass(m_commandBuffer->GetBufferHandle()); // end implicit.
9826
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009827 vkCmdBeginRenderPass(m_commandBuffer->GetBufferHandle(), &m_renderPassBeginInfo, VK_SUBPASS_CONTENTS_SECONDARY_COMMAND_BUFFERS);
Chris Forbes2eeabe32016-06-21 20:52:34 +12009828 vkCmdEndRenderPass(m_commandBuffer->GetBufferHandle());
9829 m_errorMonitor->VerifyNotFound();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009830 vkCmdBeginRenderPass(m_commandBuffer->GetBufferHandle(), &m_renderPassBeginInfo, VK_SUBPASS_CONTENTS_INLINE);
Chris Forbes2eeabe32016-06-21 20:52:34 +12009831 m_errorMonitor->VerifyNotFound();
9832 vkCmdEndRenderPass(m_commandBuffer->GetBufferHandle());
9833 m_errorMonitor->VerifyNotFound();
9834
9835 m_commandBuffer->EndCommandBuffer();
9836 m_errorMonitor->VerifyNotFound();
9837}
9838
Tobin Ehlis5a1c0332016-05-31 13:59:26 -06009839TEST_F(VkLayerTest, RenderPassClearOpMismatch) {
9840 TEST_DESCRIPTION("Begin a renderPass where clearValueCount is less than"
9841 "the number of renderPass attachments that use loadOp"
9842 "VK_ATTACHMENT_LOAD_OP_CLEAR.");
9843
9844 ASSERT_NO_FATAL_FAILURE(InitState());
9845 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
9846
9847 // Create a renderPass with a single attachment that uses loadOp CLEAR
9848 VkAttachmentReference attach = {};
9849 attach.layout = VK_IMAGE_LAYOUT_GENERAL;
9850 VkSubpassDescription subpass = {};
9851 subpass.inputAttachmentCount = 1;
9852 subpass.pInputAttachments = &attach;
9853 VkRenderPassCreateInfo rpci = {};
9854 rpci.subpassCount = 1;
9855 rpci.pSubpasses = &subpass;
9856 rpci.attachmentCount = 1;
9857 VkAttachmentDescription attach_desc = {};
9858 attach_desc.format = VK_FORMAT_UNDEFINED;
9859 // Set loadOp to CLEAR
9860 attach_desc.loadOp = VK_ATTACHMENT_LOAD_OP_CLEAR;
9861 rpci.pAttachments = &attach_desc;
9862 rpci.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
9863 VkRenderPass rp;
9864 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
9865
9866 VkCommandBufferInheritanceInfo hinfo = {};
9867 hinfo.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_INHERITANCE_INFO;
9868 hinfo.renderPass = VK_NULL_HANDLE;
9869 hinfo.subpass = 0;
9870 hinfo.framebuffer = VK_NULL_HANDLE;
9871 hinfo.occlusionQueryEnable = VK_FALSE;
9872 hinfo.queryFlags = 0;
9873 hinfo.pipelineStatistics = 0;
9874 VkCommandBufferBeginInfo info = {};
9875 info.flags = VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT;
9876 info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
9877 info.pInheritanceInfo = &hinfo;
9878
9879 vkBeginCommandBuffer(m_commandBuffer->handle(), &info);
9880 VkRenderPassBeginInfo rp_begin = {};
9881 rp_begin.sType = VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO;
9882 rp_begin.pNext = NULL;
9883 rp_begin.renderPass = renderPass();
9884 rp_begin.framebuffer = framebuffer();
9885 rp_begin.clearValueCount = 0; // Should be 1
9886
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009887 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " has a clearValueCount of 0 but "
9888 "there must be at least 1 entries in "
9889 "pClearValues array to account for ");
Tobin Ehlis5a1c0332016-05-31 13:59:26 -06009890
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009891 vkCmdBeginRenderPass(m_commandBuffer->GetBufferHandle(), &rp_begin, VK_SUBPASS_CONTENTS_INLINE);
Tobin Ehlis5a1c0332016-05-31 13:59:26 -06009892
9893 m_errorMonitor->VerifyFound();
Mark Lobodzinski5c70ebd2016-06-09 13:45:00 -06009894
9895 vkDestroyRenderPass(m_device->device(), rp, NULL);
Tobin Ehlis5a1c0332016-05-31 13:59:26 -06009896}
9897
Cody Northrop3bb4d962016-05-09 16:15:57 -06009898TEST_F(VkLayerTest, EndCommandBufferWithinRenderPass) {
9899
9900 TEST_DESCRIPTION("End a command buffer with an active render pass");
9901
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009902 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
9903 "It is invalid to issue this call inside an active render pass");
Cody Northrop3bb4d962016-05-09 16:15:57 -06009904
9905 ASSERT_NO_FATAL_FAILURE(InitState());
9906 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
9907
9908 // The framework's BeginCommandBuffer calls CreateRenderPass
9909 BeginCommandBuffer();
9910
9911 // Call directly into vkEndCommandBuffer instead of the
9912 // the framework's EndCommandBuffer, which inserts a
9913 // vkEndRenderPass
9914 vkEndCommandBuffer(m_commandBuffer->GetBufferHandle());
9915
9916 m_errorMonitor->VerifyFound();
9917
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009918 // TODO: Add test for VK_COMMAND_BUFFER_LEVEL_SECONDARY
9919 // TODO: Add test for VK_COMMAND_BUFFER_USAGE_RENDER_PASS_CONTINUE_BIT
Cody Northrop3bb4d962016-05-09 16:15:57 -06009920}
9921
Karl Schultz6addd812016-02-02 17:17:23 -07009922TEST_F(VkLayerTest, FillBufferWithinRenderPass) {
Mark Lobodzinskid5639502015-09-24 09:51:47 -06009923 // Call CmdFillBuffer within an active renderpass
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009924 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
9925 "It is invalid to issue this call inside an active render pass");
Mark Lobodzinskid5639502015-09-24 09:51:47 -06009926
9927 ASSERT_NO_FATAL_FAILURE(InitState());
9928 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Mark Lobodzinskid5639502015-09-24 09:51:47 -06009929
9930 // Renderpass is started here
9931 BeginCommandBuffer();
9932
9933 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009934 vk_testing::Buffer dstBuffer;
9935 dstBuffer.init_as_dst(*m_device, (VkDeviceSize)1024, reqs);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06009936
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009937 m_commandBuffer->FillBuffer(dstBuffer.handle(), 0, 4, 0x11111111);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06009938
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009939 m_errorMonitor->VerifyFound();
Mark Lobodzinskid5639502015-09-24 09:51:47 -06009940}
9941
Karl Schultz6addd812016-02-02 17:17:23 -07009942TEST_F(VkLayerTest, UpdateBufferWithinRenderPass) {
Mark Lobodzinskid5639502015-09-24 09:51:47 -06009943 // Call CmdUpdateBuffer within an active renderpass
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009944 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
9945 "It is invalid to issue this call inside an active render pass");
Mark Lobodzinskid5639502015-09-24 09:51:47 -06009946
9947 ASSERT_NO_FATAL_FAILURE(InitState());
9948 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Mark Lobodzinskid5639502015-09-24 09:51:47 -06009949
9950 // Renderpass is started here
9951 BeginCommandBuffer();
9952
9953 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009954 vk_testing::Buffer dstBuffer;
9955 dstBuffer.init_as_dst(*m_device, (VkDeviceSize)1024, reqs);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06009956
Karl Schultz6addd812016-02-02 17:17:23 -07009957 VkDeviceSize dstOffset = 0;
9958 VkDeviceSize dataSize = 1024;
Karl Schultzee344492016-07-11 15:09:57 -06009959 const void *pData = NULL;
Mark Lobodzinskid5639502015-09-24 09:51:47 -06009960
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009961 vkCmdUpdateBuffer(m_commandBuffer->GetBufferHandle(), dstBuffer.handle(), dstOffset, dataSize, pData);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06009962
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009963 m_errorMonitor->VerifyFound();
Mark Lobodzinskid5639502015-09-24 09:51:47 -06009964}
9965
Karl Schultz6addd812016-02-02 17:17:23 -07009966TEST_F(VkLayerTest, ClearColorImageWithinRenderPass) {
Mark Lobodzinskid5639502015-09-24 09:51:47 -06009967 // Call CmdClearColorImage within an active RenderPass
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009968 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
9969 "It is invalid to issue this call inside an active render pass");
Mark Lobodzinskid5639502015-09-24 09:51:47 -06009970
9971 ASSERT_NO_FATAL_FAILURE(InitState());
9972 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Mark Lobodzinskid5639502015-09-24 09:51:47 -06009973
9974 // Renderpass is started here
9975 BeginCommandBuffer();
9976
Michael Lentine0a369f62016-02-03 16:51:46 -06009977 VkClearColorValue clear_color;
9978 memset(clear_color.uint32, 0, sizeof(uint32_t) * 4);
Karl Schultz6addd812016-02-02 17:17:23 -07009979 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
9980 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
9981 const int32_t tex_width = 32;
9982 const int32_t tex_height = 32;
9983 VkImageCreateInfo image_create_info = {};
9984 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
9985 image_create_info.pNext = NULL;
9986 image_create_info.imageType = VK_IMAGE_TYPE_2D;
9987 image_create_info.format = tex_format;
9988 image_create_info.extent.width = tex_width;
9989 image_create_info.extent.height = tex_height;
9990 image_create_info.extent.depth = 1;
9991 image_create_info.mipLevels = 1;
9992 image_create_info.arrayLayers = 1;
9993 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
9994 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
9995 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
Mark Lobodzinskid5639502015-09-24 09:51:47 -06009996
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009997 vk_testing::Image dstImage;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009998 dstImage.init(*m_device, (const VkImageCreateInfo &)image_create_info, reqs);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06009999
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010000 const VkImageSubresourceRange range = vk_testing::Image::subresource_range(image_create_info, VK_IMAGE_ASPECT_COLOR_BIT);
Mark Lobodzinskid5639502015-09-24 09:51:47 -060010001
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010002 vkCmdClearColorImage(m_commandBuffer->GetBufferHandle(), dstImage.handle(), VK_IMAGE_LAYOUT_GENERAL, &clear_color, 1, &range);
Mark Lobodzinskid5639502015-09-24 09:51:47 -060010003
Chris Forbes8f36a8a2016-04-07 13:21:07 +120010004 m_errorMonitor->VerifyFound();
Mark Lobodzinskid5639502015-09-24 09:51:47 -060010005}
10006
Karl Schultz6addd812016-02-02 17:17:23 -070010007TEST_F(VkLayerTest, ClearDepthStencilImageWithinRenderPass) {
Mark Lobodzinskid5639502015-09-24 09:51:47 -060010008 // Call CmdClearDepthStencilImage within an active RenderPass
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010009 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
10010 "It is invalid to issue this call inside an active render pass");
Mark Lobodzinskid5639502015-09-24 09:51:47 -060010011
10012 ASSERT_NO_FATAL_FAILURE(InitState());
10013 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Mark Lobodzinskid5639502015-09-24 09:51:47 -060010014
10015 // Renderpass is started here
10016 BeginCommandBuffer();
10017
10018 VkClearDepthStencilValue clear_value = {0};
Dustin Gravesa2e5c942016-02-11 18:28:06 -070010019 VkMemoryPropertyFlags reqs = 0;
Karl Schultz6addd812016-02-02 17:17:23 -070010020 VkImageCreateInfo image_create_info = vk_testing::Image::create_info();
10021 image_create_info.imageType = VK_IMAGE_TYPE_2D;
10022 image_create_info.format = VK_FORMAT_D24_UNORM_S8_UINT;
10023 image_create_info.extent.width = 64;
10024 image_create_info.extent.height = 64;
10025 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
10026 image_create_info.usage = VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT;
Mark Lobodzinskid5639502015-09-24 09:51:47 -060010027
Chia-I Wu3432a0c2015-10-27 18:04:07 +080010028 vk_testing::Image dstImage;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010029 dstImage.init(*m_device, (const VkImageCreateInfo &)image_create_info, reqs);
Mark Lobodzinskid5639502015-09-24 09:51:47 -060010030
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010031 const VkImageSubresourceRange range = vk_testing::Image::subresource_range(image_create_info, VK_IMAGE_ASPECT_DEPTH_BIT);
Mark Lobodzinskid5639502015-09-24 09:51:47 -060010032
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010033 vkCmdClearDepthStencilImage(m_commandBuffer->GetBufferHandle(), dstImage.handle(),
10034 VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL, &clear_value, 1, &range);
Mark Lobodzinskid5639502015-09-24 09:51:47 -060010035
Chris Forbes8f36a8a2016-04-07 13:21:07 +120010036 m_errorMonitor->VerifyFound();
Mark Lobodzinskid5639502015-09-24 09:51:47 -060010037}
10038
Karl Schultz6addd812016-02-02 17:17:23 -070010039TEST_F(VkLayerTest, ClearColorAttachmentsOutsideRenderPass) {
Courtney Goeltzenleuchterc9323e02015-10-15 16:51:05 -060010040 // Call CmdClearAttachmentss outside of an active RenderPass
Karl Schultz6addd812016-02-02 17:17:23 -070010041 VkResult err;
Mark Lobodzinskid5639502015-09-24 09:51:47 -060010042
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010043 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "vkCmdClearAttachments(): This call "
10044 "must be issued inside an active "
10045 "render pass");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060010046
Mark Lobodzinskid5639502015-09-24 09:51:47 -060010047 ASSERT_NO_FATAL_FAILURE(InitState());
10048 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Mark Lobodzinskid5639502015-09-24 09:51:47 -060010049
10050 // Start no RenderPass
Chia-I Wu3432a0c2015-10-27 18:04:07 +080010051 err = m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskid5639502015-09-24 09:51:47 -060010052 ASSERT_VK_SUCCESS(err);
10053
Courtney Goeltzenleuchterc9323e02015-10-15 16:51:05 -060010054 VkClearAttachment color_attachment;
10055 color_attachment.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
10056 color_attachment.clearValue.color.float32[0] = 0;
10057 color_attachment.clearValue.color.float32[1] = 0;
10058 color_attachment.clearValue.color.float32[2] = 0;
10059 color_attachment.clearValue.color.float32[3] = 0;
10060 color_attachment.colorAttachment = 0;
Karl Schultz6addd812016-02-02 17:17:23 -070010061 VkClearRect clear_rect = {{{0, 0}, {32, 32}}};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010062 vkCmdClearAttachments(m_commandBuffer->GetBufferHandle(), 1, &color_attachment, 1, &clear_rect);
Mark Lobodzinskid5639502015-09-24 09:51:47 -060010063
Chris Forbes8f36a8a2016-04-07 13:21:07 +120010064 m_errorMonitor->VerifyFound();
Mark Lobodzinskid5639502015-09-24 09:51:47 -060010065}
10066
Chris Forbes3b97e932016-09-07 11:29:24 +120010067TEST_F(VkLayerTest, RenderPassExcessiveNextSubpass) {
10068 TEST_DESCRIPTION("Test that an error is produced when CmdNextSubpass is "
10069 "called too many times in a renderpass instance");
10070
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010071 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "vkCmdNextSubpass(): Attempted to advance "
10072 "beyond final subpass");
Chris Forbes3b97e932016-09-07 11:29:24 +120010073
10074 ASSERT_NO_FATAL_FAILURE(InitState());
10075 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
10076
10077 BeginCommandBuffer();
10078
10079 // error here.
10080 vkCmdNextSubpass(m_commandBuffer->GetBufferHandle(), VK_SUBPASS_CONTENTS_INLINE);
10081 m_errorMonitor->VerifyFound();
10082
10083 EndCommandBuffer();
10084}
10085
Chris Forbes6d624702016-09-07 13:57:05 +120010086TEST_F(VkLayerTest, RenderPassEndedBeforeFinalSubpass) {
10087 TEST_DESCRIPTION("Test that an error is produced when CmdEndRenderPass is "
10088 "called before the final subpass has been reached");
10089
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010090 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "vkCmdEndRenderPass(): Called before reaching "
10091 "final subpass");
Chris Forbes6d624702016-09-07 13:57:05 +120010092
10093 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010094 VkSubpassDescription sd[2] = {{0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 0, nullptr, nullptr, nullptr, 0, nullptr},
10095 {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 0, nullptr, nullptr, nullptr, 0, nullptr}};
Chris Forbes6d624702016-09-07 13:57:05 +120010096
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010097 VkRenderPassCreateInfo rcpi = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 0, nullptr, 2, sd, 0, nullptr};
Chris Forbes6d624702016-09-07 13:57:05 +120010098
10099 VkRenderPass rp;
10100 VkResult err = vkCreateRenderPass(m_device->device(), &rcpi, nullptr, &rp);
10101 ASSERT_VK_SUCCESS(err);
10102
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010103 VkFramebufferCreateInfo fbci = {VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr, 0, rp, 0, nullptr, 16, 16, 1};
Chris Forbes6d624702016-09-07 13:57:05 +120010104
10105 VkFramebuffer fb;
10106 err = vkCreateFramebuffer(m_device->device(), &fbci, nullptr, &fb);
10107 ASSERT_VK_SUCCESS(err);
10108
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010109 m_commandBuffer->BeginCommandBuffer(); // no implicit RP begin
Chris Forbes6d624702016-09-07 13:57:05 +120010110
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010111 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 +120010112
10113 vkCmdBeginRenderPass(m_commandBuffer->GetBufferHandle(), &rpbi, VK_SUBPASS_CONTENTS_INLINE);
10114
10115 // Error here.
10116 vkCmdEndRenderPass(m_commandBuffer->GetBufferHandle());
10117 m_errorMonitor->VerifyFound();
10118
10119 // Clean up.
10120 vkDestroyFramebuffer(m_device->device(), fb, nullptr);
10121 vkDestroyRenderPass(m_device->device(), rp, nullptr);
10122}
10123
Karl Schultz9e66a292016-04-21 15:57:51 -060010124TEST_F(VkLayerTest, BufferMemoryBarrierNoBuffer) {
10125 // Try to add a buffer memory barrier with no buffer.
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010126 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
10127 "required parameter pBufferMemoryBarriers[0].buffer specified as VK_NULL_HANDLE");
Karl Schultz9e66a292016-04-21 15:57:51 -060010128
10129 ASSERT_NO_FATAL_FAILURE(InitState());
10130 BeginCommandBuffer();
10131
10132 VkBufferMemoryBarrier buf_barrier = {};
10133 buf_barrier.sType = VK_STRUCTURE_TYPE_BUFFER_MEMORY_BARRIER;
10134 buf_barrier.srcAccessMask = VK_ACCESS_HOST_WRITE_BIT;
10135 buf_barrier.dstAccessMask = VK_ACCESS_SHADER_READ_BIT;
10136 buf_barrier.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
10137 buf_barrier.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
10138 buf_barrier.buffer = VK_NULL_HANDLE;
10139 buf_barrier.offset = 0;
10140 buf_barrier.size = VK_WHOLE_SIZE;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010141 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
10142 nullptr, 1, &buf_barrier, 0, nullptr);
Karl Schultz9e66a292016-04-21 15:57:51 -060010143
10144 m_errorMonitor->VerifyFound();
10145}
10146
Tony Barbour7fd5c0f2016-05-03 16:11:53 -060010147TEST_F(VkLayerTest, InvalidBarriers) {
10148 TEST_DESCRIPTION("A variety of ways to get VK_INVALID_BARRIER ");
10149
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010150 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Barriers cannot be set during subpass");
Tony Barbour7fd5c0f2016-05-03 16:11:53 -060010151
10152 ASSERT_NO_FATAL_FAILURE(InitState());
10153 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
10154
10155 VkMemoryBarrier mem_barrier = {};
10156 mem_barrier.sType = VK_STRUCTURE_TYPE_MEMORY_BARRIER;
10157 mem_barrier.pNext = NULL;
10158 mem_barrier.srcAccessMask = VK_ACCESS_HOST_WRITE_BIT;
10159 mem_barrier.dstAccessMask = VK_ACCESS_SHADER_READ_BIT;
10160 BeginCommandBuffer();
10161 // BeginCommandBuffer() starts a render pass
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010162 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 1,
Tony Barbour7fd5c0f2016-05-03 16:11:53 -060010163 &mem_barrier, 0, nullptr, 0, nullptr);
10164 m_errorMonitor->VerifyFound();
10165
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010166 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Image Layout cannot be transitioned to UNDEFINED");
Tony Barbour7fd5c0f2016-05-03 16:11:53 -060010167 VkImageObj image(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010168 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 -060010169 ASSERT_TRUE(image.initialized());
10170 VkImageMemoryBarrier img_barrier = {};
10171 img_barrier.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
10172 img_barrier.pNext = NULL;
10173 img_barrier.srcAccessMask = VK_ACCESS_HOST_WRITE_BIT;
10174 img_barrier.dstAccessMask = VK_ACCESS_SHADER_READ_BIT;
10175 img_barrier.oldLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
10176 // New layout can't be UNDEFINED
10177 img_barrier.newLayout = VK_IMAGE_LAYOUT_UNDEFINED;
10178 img_barrier.image = image.handle();
10179 img_barrier.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
10180 img_barrier.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
10181 img_barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
10182 img_barrier.subresourceRange.baseArrayLayer = 0;
10183 img_barrier.subresourceRange.baseMipLevel = 0;
10184 img_barrier.subresourceRange.layerCount = 1;
10185 img_barrier.subresourceRange.levelCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010186 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
10187 nullptr, 0, nullptr, 1, &img_barrier);
Tony Barbour7fd5c0f2016-05-03 16:11:53 -060010188 m_errorMonitor->VerifyFound();
10189 img_barrier.newLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
10190
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010191 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Subresource must have the sum of the "
10192 "baseArrayLayer");
Tony Barbour7fd5c0f2016-05-03 16:11:53 -060010193 // baseArrayLayer + layerCount must be <= image's arrayLayers
10194 img_barrier.subresourceRange.baseArrayLayer = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010195 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
10196 nullptr, 0, nullptr, 1, &img_barrier);
Tony Barbour7fd5c0f2016-05-03 16:11:53 -060010197 m_errorMonitor->VerifyFound();
10198 img_barrier.subresourceRange.baseArrayLayer = 0;
10199
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010200 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Subresource must have the sum of the baseMipLevel");
Tony Barbour7fd5c0f2016-05-03 16:11:53 -060010201 // baseMipLevel + levelCount must be <= image's mipLevels
10202 img_barrier.subresourceRange.baseMipLevel = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010203 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
10204 nullptr, 0, nullptr, 1, &img_barrier);
Tony Barbour7fd5c0f2016-05-03 16:11:53 -060010205 m_errorMonitor->VerifyFound();
10206 img_barrier.subresourceRange.baseMipLevel = 0;
10207
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010208 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 -060010209 vk_testing::Buffer buffer;
10210 buffer.init(*m_device, 256);
10211 VkBufferMemoryBarrier buf_barrier = {};
10212 buf_barrier.sType = VK_STRUCTURE_TYPE_BUFFER_MEMORY_BARRIER;
10213 buf_barrier.pNext = NULL;
10214 buf_barrier.srcAccessMask = VK_ACCESS_HOST_WRITE_BIT;
10215 buf_barrier.dstAccessMask = VK_ACCESS_SHADER_READ_BIT;
10216 buf_barrier.buffer = buffer.handle();
10217 buf_barrier.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
10218 buf_barrier.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
10219 buf_barrier.offset = 0;
10220 buf_barrier.size = VK_WHOLE_SIZE;
10221 // Can't send buffer barrier during a render pass
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010222 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
10223 nullptr, 1, &buf_barrier, 0, nullptr);
Tony Barbour7fd5c0f2016-05-03 16:11:53 -060010224 m_errorMonitor->VerifyFound();
10225 vkCmdEndRenderPass(m_commandBuffer->GetBufferHandle());
10226
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010227 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "which is not less than total size");
Tony Barbour7fd5c0f2016-05-03 16:11:53 -060010228 buf_barrier.offset = 257;
10229 // Offset greater than total size
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010230 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
10231 nullptr, 1, &buf_barrier, 0, nullptr);
Tony Barbour7fd5c0f2016-05-03 16:11:53 -060010232 m_errorMonitor->VerifyFound();
10233 buf_barrier.offset = 0;
10234
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010235 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "whose sum is greater than total size");
Tony Barbour7fd5c0f2016-05-03 16:11:53 -060010236 buf_barrier.size = 257;
10237 // Size greater than total size
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010238 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
10239 nullptr, 1, &buf_barrier, 0, nullptr);
Tony Barbour7fd5c0f2016-05-03 16:11:53 -060010240 m_errorMonitor->VerifyFound();
Tony Barbour7fd5c0f2016-05-03 16:11:53 -060010241
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -060010242 // Now exercise barrier aspect bit errors, first DS
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010243 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Image is a depth and stencil format and thus must "
10244 "have either one or both of VK_IMAGE_ASPECT_DEPTH_BIT and "
10245 "VK_IMAGE_ASPECT_STENCIL_BIT set.");
Tony Barbour7fd5c0f2016-05-03 16:11:53 -060010246 VkDepthStencilObj ds_image(m_device);
10247 ds_image.Init(m_device, 128, 128, VK_FORMAT_D24_UNORM_S8_UINT);
10248 ASSERT_TRUE(ds_image.initialized());
Tobin Ehlis15684a02016-07-21 14:55:26 -060010249 img_barrier.oldLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
10250 img_barrier.newLayout = VK_IMAGE_LAYOUT_GENERAL;
Tony Barbour7fd5c0f2016-05-03 16:11:53 -060010251 img_barrier.image = ds_image.handle();
Tobin Ehlis15684a02016-07-21 14:55:26 -060010252 // Use of COLOR aspect on DS image is error
10253 img_barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010254 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
10255 nullptr, 0, nullptr, 1, &img_barrier);
Tony Barbour7fd5c0f2016-05-03 16:11:53 -060010256 m_errorMonitor->VerifyFound();
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -060010257 // Now test depth-only
10258 VkFormatProperties format_props;
10259
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010260 vkGetPhysicalDeviceFormatProperties(m_device->phy().handle(), VK_FORMAT_D16_UNORM, &format_props);
10261 if (format_props.optimalTilingFeatures & VK_FORMAT_FEATURE_DEPTH_STENCIL_ATTACHMENT_BIT) {
10262 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Image is a depth-only format and thus must "
10263 "have VK_IMAGE_ASPECT_DEPTH_BIT set.");
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -060010264 VkDepthStencilObj d_image(m_device);
10265 d_image.Init(m_device, 128, 128, VK_FORMAT_D16_UNORM);
10266 ASSERT_TRUE(d_image.initialized());
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010267 img_barrier.oldLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
Tobin Ehlis15684a02016-07-21 14:55:26 -060010268 img_barrier.newLayout = VK_IMAGE_LAYOUT_GENERAL;
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -060010269 img_barrier.image = d_image.handle();
Tobin Ehlis15684a02016-07-21 14:55:26 -060010270 // Use of COLOR aspect on depth image is error
10271 img_barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010272 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0,
10273 0, nullptr, 0, nullptr, 1, &img_barrier);
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -060010274 m_errorMonitor->VerifyFound();
10275 }
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010276 vkGetPhysicalDeviceFormatProperties(m_device->phy().handle(), VK_FORMAT_S8_UINT, &format_props);
10277 if (format_props.optimalTilingFeatures & VK_FORMAT_FEATURE_DEPTH_STENCIL_ATTACHMENT_BIT) {
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -060010278 // Now test stencil-only
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010279 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Image is a stencil-only format and thus must "
10280 "have VK_IMAGE_ASPECT_STENCIL_BIT set.");
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -060010281 VkDepthStencilObj s_image(m_device);
10282 s_image.Init(m_device, 128, 128, VK_FORMAT_S8_UINT);
10283 ASSERT_TRUE(s_image.initialized());
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010284 img_barrier.oldLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
Tobin Ehlis15684a02016-07-21 14:55:26 -060010285 img_barrier.newLayout = VK_IMAGE_LAYOUT_GENERAL;
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -060010286 img_barrier.image = s_image.handle();
Tobin Ehlis15684a02016-07-21 14:55:26 -060010287 // Use of COLOR aspect on depth image is error
10288 img_barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010289 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0,
10290 0, nullptr, 0, nullptr, 1, &img_barrier);
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -060010291 m_errorMonitor->VerifyFound();
10292 }
10293 // Finally test color
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010294 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Image is a color format and thus must "
10295 "have VK_IMAGE_ASPECT_COLOR_BIT set.");
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -060010296 VkImageObj c_image(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010297 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 -060010298 ASSERT_TRUE(c_image.initialized());
10299 img_barrier.oldLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
10300 img_barrier.newLayout = VK_IMAGE_LAYOUT_GENERAL;
10301 img_barrier.image = c_image.handle();
10302 // Set aspect to depth (non-color)
10303 img_barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010304 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
10305 nullptr, 0, nullptr, 1, &img_barrier);
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -060010306 m_errorMonitor->VerifyFound();
Tony Barbour7fd5c0f2016-05-03 16:11:53 -060010307}
10308
Karl Schultz6addd812016-02-02 17:17:23 -070010309TEST_F(VkLayerTest, IdxBufferAlignmentError) {
Tobin Ehlisc4c23182015-09-17 12:24:13 -060010310 // Bind a BeginRenderPass within an active RenderPass
Karl Schultz6addd812016-02-02 17:17:23 -070010311 VkResult err;
Tobin Ehlisc4c23182015-09-17 12:24:13 -060010312
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010313 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "vkCmdBindIndexBuffer() offset (0x7) does not fall on ");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060010314
Tobin Ehlisc4c23182015-09-17 12:24:13 -060010315 ASSERT_NO_FATAL_FAILURE(InitState());
10316 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlisc4c23182015-09-17 12:24:13 -060010317 uint32_t qfi = 0;
10318 VkBufferCreateInfo buffCI = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010319 buffCI.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
10320 buffCI.size = 1024;
10321 buffCI.usage = VK_BUFFER_USAGE_INDEX_BUFFER_BIT;
10322 buffCI.queueFamilyIndexCount = 1;
10323 buffCI.pQueueFamilyIndices = &qfi;
Tobin Ehlisc4c23182015-09-17 12:24:13 -060010324
10325 VkBuffer ib;
Chia-I Wuf7458c52015-10-26 21:10:41 +080010326 err = vkCreateBuffer(m_device->device(), &buffCI, NULL, &ib);
Tobin Ehlisc4c23182015-09-17 12:24:13 -060010327 ASSERT_VK_SUCCESS(err);
10328
10329 BeginCommandBuffer();
10330 ASSERT_VK_SUCCESS(err);
Karl Schultz6addd812016-02-02 17:17:23 -070010331 // vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(),
10332 // VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Tobin Ehlisc4c23182015-09-17 12:24:13 -060010333 // Should error before calling to driver so don't care about actual data
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010334 vkCmdBindIndexBuffer(m_commandBuffer->GetBufferHandle(), ib, 7, VK_INDEX_TYPE_UINT16);
Tobin Ehlisc4c23182015-09-17 12:24:13 -060010335
Chris Forbes8f36a8a2016-04-07 13:21:07 +120010336 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -060010337
Chia-I Wuf7458c52015-10-26 21:10:41 +080010338 vkDestroyBuffer(m_device->device(), ib, NULL);
Tobin Ehlisc4c23182015-09-17 12:24:13 -060010339}
10340
Mark Lobodzinski52a6e7d2016-02-25 15:09:52 -070010341TEST_F(VkLayerTest, InvalidQueueFamilyIndex) {
10342 // Create an out-of-range queueFamilyIndex
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010343 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
10344 "vkCreateBuffer: pCreateInfo->pQueueFamilyIndices[0] (777) must be one "
10345 "of the indices specified when the device was created, via the "
10346 "VkDeviceQueueCreateInfo structure.");
Mark Lobodzinski52a6e7d2016-02-25 15:09:52 -070010347
10348 ASSERT_NO_FATAL_FAILURE(InitState());
10349 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
10350 VkBufferCreateInfo buffCI = {};
10351 buffCI.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
10352 buffCI.size = 1024;
10353 buffCI.usage = VK_BUFFER_USAGE_INDEX_BUFFER_BIT;
10354 buffCI.queueFamilyIndexCount = 1;
10355 // Introduce failure by specifying invalid queue_family_index
10356 uint32_t qfi = 777;
10357 buffCI.pQueueFamilyIndices = &qfi;
Tobin Ehlis24aab042016-03-24 10:54:18 -060010358 buffCI.sharingMode = VK_SHARING_MODE_CONCURRENT; // qfi only matters in CONCURRENT mode
Mark Lobodzinski52a6e7d2016-02-25 15:09:52 -070010359
10360 VkBuffer ib;
10361 vkCreateBuffer(m_device->device(), &buffCI, NULL, &ib);
10362
Chris Forbes8f36a8a2016-04-07 13:21:07 +120010363 m_errorMonitor->VerifyFound();
Tony Barbourdf4c0042016-06-01 15:55:43 -060010364 vkDestroyBuffer(m_device->device(), ib, NULL);
Mark Lobodzinski52a6e7d2016-02-25 15:09:52 -070010365}
10366
Karl Schultz6addd812016-02-02 17:17:23 -070010367TEST_F(VkLayerTest, ExecuteCommandsPrimaryCB) {
Tobin Ehlis0c94db02016-07-19 10:49:32 -060010368 TEST_DESCRIPTION("Attempt vkCmdExecuteCommands w/ a primary cmd buffer"
10369 " (should only be secondary)");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060010370
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010371 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "vkCmdExecuteCommands() called w/ Primary Cmd Buffer ");
Tobin Ehlis4b34ddc2015-09-17 14:18:16 -060010372
10373 ASSERT_NO_FATAL_FAILURE(InitState());
10374 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlis4b34ddc2015-09-17 14:18:16 -060010375
10376 BeginCommandBuffer();
Tobin Ehlis0c94db02016-07-19 10:49:32 -060010377
Chia-I Wu3432a0c2015-10-27 18:04:07 +080010378 VkCommandBuffer primCB = m_commandBuffer->GetBufferHandle();
10379 vkCmdExecuteCommands(m_commandBuffer->GetBufferHandle(), 1, &primCB);
Tobin Ehlis4b34ddc2015-09-17 14:18:16 -060010380
Chris Forbes8f36a8a2016-04-07 13:21:07 +120010381 m_errorMonitor->VerifyFound();
Tobin Ehlis4b34ddc2015-09-17 14:18:16 -060010382}
10383
Tobin Ehlis17826bd2016-05-25 11:12:50 -060010384TEST_F(VkLayerTest, DSUsageBitsErrors) {
10385 TEST_DESCRIPTION("Attempt to update descriptor sets for images and buffers "
10386 "that do not have correct usage bits sets.");
10387 VkResult err;
10388
10389 ASSERT_NO_FATAL_FAILURE(InitState());
10390 VkDescriptorPoolSize ds_type_count[VK_DESCRIPTOR_TYPE_RANGE_SIZE] = {};
10391 for (uint32_t i = 0; i < VK_DESCRIPTOR_TYPE_RANGE_SIZE; ++i) {
10392 ds_type_count[i].type = VkDescriptorType(i);
10393 ds_type_count[i].descriptorCount = 1;
10394 }
10395 VkDescriptorPoolCreateInfo ds_pool_ci = {};
10396 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
10397 ds_pool_ci.pNext = NULL;
10398 ds_pool_ci.maxSets = VK_DESCRIPTOR_TYPE_RANGE_SIZE;
10399 ds_pool_ci.poolSizeCount = VK_DESCRIPTOR_TYPE_RANGE_SIZE;
10400 ds_pool_ci.pPoolSizes = ds_type_count;
10401
10402 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010403 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis17826bd2016-05-25 11:12:50 -060010404 ASSERT_VK_SUCCESS(err);
10405
10406 // Create 10 layouts where each has a single descriptor of different type
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010407 VkDescriptorSetLayoutBinding dsl_binding[VK_DESCRIPTOR_TYPE_RANGE_SIZE] = {};
Tobin Ehlis17826bd2016-05-25 11:12:50 -060010408 for (uint32_t i = 0; i < VK_DESCRIPTOR_TYPE_RANGE_SIZE; ++i) {
10409 dsl_binding[i].binding = 0;
10410 dsl_binding[i].descriptorType = VkDescriptorType(i);
10411 dsl_binding[i].descriptorCount = 1;
10412 dsl_binding[i].stageFlags = VK_SHADER_STAGE_ALL;
10413 dsl_binding[i].pImmutableSamplers = NULL;
10414 }
10415
10416 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
10417 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
10418 ds_layout_ci.pNext = NULL;
10419 ds_layout_ci.bindingCount = 1;
10420 VkDescriptorSetLayout ds_layouts[VK_DESCRIPTOR_TYPE_RANGE_SIZE];
10421 for (uint32_t i = 0; i < VK_DESCRIPTOR_TYPE_RANGE_SIZE; ++i) {
10422 ds_layout_ci.pBindings = dsl_binding + i;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010423 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, ds_layouts + i);
Tobin Ehlis17826bd2016-05-25 11:12:50 -060010424 ASSERT_VK_SUCCESS(err);
10425 }
10426 VkDescriptorSet descriptor_sets[VK_DESCRIPTOR_TYPE_RANGE_SIZE] = {};
10427 VkDescriptorSetAllocateInfo alloc_info = {};
10428 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
10429 alloc_info.descriptorSetCount = VK_DESCRIPTOR_TYPE_RANGE_SIZE;
10430 alloc_info.descriptorPool = ds_pool;
10431 alloc_info.pSetLayouts = ds_layouts;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010432 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, descriptor_sets);
Tobin Ehlis17826bd2016-05-25 11:12:50 -060010433 ASSERT_VK_SUCCESS(err);
10434
10435 // Create a buffer & bufferView to be used for invalid updates
10436 VkBufferCreateInfo buff_ci = {};
10437 buff_ci.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
10438 // This usage is not valid for any descriptor type
10439 buff_ci.usage = VK_BUFFER_USAGE_TRANSFER_SRC_BIT;
10440 buff_ci.size = 256;
10441 buff_ci.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
10442 VkBuffer buffer;
10443 err = vkCreateBuffer(m_device->device(), &buff_ci, NULL, &buffer);
10444 ASSERT_VK_SUCCESS(err);
10445
10446 VkBufferViewCreateInfo buff_view_ci = {};
10447 buff_view_ci.sType = VK_STRUCTURE_TYPE_BUFFER_VIEW_CREATE_INFO;
10448 buff_view_ci.buffer = buffer;
10449 buff_view_ci.format = VK_FORMAT_R8_UNORM;
10450 buff_view_ci.range = VK_WHOLE_SIZE;
10451 VkBufferView buff_view;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010452 err = vkCreateBufferView(m_device->device(), &buff_view_ci, NULL, &buff_view);
Tobin Ehlis17826bd2016-05-25 11:12:50 -060010453 ASSERT_VK_SUCCESS(err);
10454
10455 // Create an image to be used for invalid updates
10456 VkImageCreateInfo image_ci = {};
10457 image_ci.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
10458 image_ci.imageType = VK_IMAGE_TYPE_2D;
10459 image_ci.format = VK_FORMAT_R8G8B8A8_UNORM;
10460 image_ci.extent.width = 64;
10461 image_ci.extent.height = 64;
10462 image_ci.extent.depth = 1;
10463 image_ci.mipLevels = 1;
10464 image_ci.arrayLayers = 1;
10465 image_ci.samples = VK_SAMPLE_COUNT_1_BIT;
10466 image_ci.tiling = VK_IMAGE_TILING_LINEAR;
10467 image_ci.initialLayout = VK_IMAGE_LAYOUT_PREINITIALIZED;
10468 // This usage is not valid for any descriptor type
10469 image_ci.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
10470 image_ci.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
10471 VkImage image;
10472 err = vkCreateImage(m_device->device(), &image_ci, NULL, &image);
10473 ASSERT_VK_SUCCESS(err);
10474 // Bind memory to image
10475 VkMemoryRequirements mem_reqs;
10476 VkDeviceMemory image_mem;
10477 bool pass;
10478 VkMemoryAllocateInfo mem_alloc = {};
10479 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
10480 mem_alloc.pNext = NULL;
10481 mem_alloc.allocationSize = 0;
10482 mem_alloc.memoryTypeIndex = 0;
10483 vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs);
10484 mem_alloc.allocationSize = mem_reqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010485 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0);
Tobin Ehlis17826bd2016-05-25 11:12:50 -060010486 ASSERT_TRUE(pass);
10487 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &image_mem);
10488 ASSERT_VK_SUCCESS(err);
10489 err = vkBindImageMemory(m_device->device(), image, image_mem, 0);
10490 ASSERT_VK_SUCCESS(err);
10491 // Now create view for image
10492 VkImageViewCreateInfo image_view_ci = {};
10493 image_view_ci.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
10494 image_view_ci.image = image;
10495 image_view_ci.format = VK_FORMAT_R8G8B8A8_UNORM;
10496 image_view_ci.viewType = VK_IMAGE_VIEW_TYPE_2D;
10497 image_view_ci.subresourceRange.layerCount = 1;
10498 image_view_ci.subresourceRange.baseArrayLayer = 0;
10499 image_view_ci.subresourceRange.levelCount = 1;
10500 image_view_ci.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
10501 VkImageView image_view;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010502 err = vkCreateImageView(m_device->device(), &image_view_ci, NULL, &image_view);
Tobin Ehlis17826bd2016-05-25 11:12:50 -060010503 ASSERT_VK_SUCCESS(err);
10504
10505 VkDescriptorBufferInfo buff_info = {};
10506 buff_info.buffer = buffer;
10507 VkDescriptorImageInfo img_info = {};
10508 img_info.imageView = image_view;
10509 VkWriteDescriptorSet descriptor_write = {};
10510 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
10511 descriptor_write.dstBinding = 0;
10512 descriptor_write.descriptorCount = 1;
10513 descriptor_write.pTexelBufferView = &buff_view;
10514 descriptor_write.pBufferInfo = &buff_info;
10515 descriptor_write.pImageInfo = &img_info;
10516
10517 // These error messages align with VkDescriptorType struct
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010518 const char *error_msgs[] = {"", // placeholder, no error for SAMPLER descriptor
10519 " does not have VK_IMAGE_USAGE_SAMPLED_BIT set.",
10520 " does not have VK_IMAGE_USAGE_SAMPLED_BIT set.",
10521 " does not have VK_IMAGE_USAGE_STORAGE_BIT set.",
10522 " does not have VK_BUFFER_USAGE_UNIFORM_TEXEL_BUFFER_BIT set.",
10523 " does not have VK_BUFFER_USAGE_STORAGE_TEXEL_BUFFER_BIT set.",
10524 " does not have VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT set.",
10525 " does not have VK_BUFFER_USAGE_STORAGE_BUFFER_BIT set.",
10526 " does not have VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT set.",
10527 " does not have VK_BUFFER_USAGE_STORAGE_BUFFER_BIT set.",
10528 " does not have VK_IMAGE_USAGE_INPUT_ATTACHMENT_BIT set."};
Tobin Ehlis17826bd2016-05-25 11:12:50 -060010529 // Start loop at 1 as SAMPLER desc type has no usage bit error
10530 for (uint32_t i = 1; i < VK_DESCRIPTOR_TYPE_RANGE_SIZE; ++i) {
10531 descriptor_write.descriptorType = VkDescriptorType(i);
10532 descriptor_write.dstSet = descriptor_sets[i];
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010533 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, error_msgs[i]);
Tobin Ehlis17826bd2016-05-25 11:12:50 -060010534
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010535 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
Tobin Ehlis17826bd2016-05-25 11:12:50 -060010536
10537 m_errorMonitor->VerifyFound();
10538 vkDestroyDescriptorSetLayout(m_device->device(), ds_layouts[i], NULL);
10539 }
10540 vkDestroyDescriptorSetLayout(m_device->device(), ds_layouts[0], NULL);
10541 vkDestroyImage(m_device->device(), image, NULL);
Tony Barbourdf4c0042016-06-01 15:55:43 -060010542 vkFreeMemory(m_device->device(), image_mem, NULL);
Tobin Ehlis17826bd2016-05-25 11:12:50 -060010543 vkDestroyImageView(m_device->device(), image_view, NULL);
10544 vkDestroyBuffer(m_device->device(), buffer, NULL);
10545 vkDestroyBufferView(m_device->device(), buff_view, NULL);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010546 vkFreeDescriptorSets(m_device->device(), ds_pool, VK_DESCRIPTOR_TYPE_RANGE_SIZE, descriptor_sets);
Tobin Ehlis17826bd2016-05-25 11:12:50 -060010547 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
10548}
10549
Tobin Ehlis585f66d2016-07-01 18:23:58 -060010550TEST_F(VkLayerTest, DSBufferInfoErrors) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010551 TEST_DESCRIPTION("Attempt to update buffer descriptor set that has incorrect "
10552 "parameters in VkDescriptorBufferInfo struct. This includes:\n"
10553 "1. offset value greater than buffer size\n"
10554 "2. range value of 0\n"
10555 "3. range value greater than buffer (size - offset)");
Tobin Ehlis585f66d2016-07-01 18:23:58 -060010556 VkResult err;
10557
10558 ASSERT_NO_FATAL_FAILURE(InitState());
10559 VkDescriptorPoolSize ds_type_count = {};
10560 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
10561 ds_type_count.descriptorCount = 1;
10562
10563 VkDescriptorPoolCreateInfo ds_pool_ci = {};
10564 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
10565 ds_pool_ci.pNext = NULL;
10566 ds_pool_ci.maxSets = 1;
10567 ds_pool_ci.poolSizeCount = 1;
10568 ds_pool_ci.pPoolSizes = &ds_type_count;
10569
10570 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010571 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis585f66d2016-07-01 18:23:58 -060010572 ASSERT_VK_SUCCESS(err);
10573
10574 // Create layout with single uniform buffer descriptor
10575 VkDescriptorSetLayoutBinding dsl_binding = {};
10576 dsl_binding.binding = 0;
10577 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
10578 dsl_binding.descriptorCount = 1;
10579 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
10580 dsl_binding.pImmutableSamplers = NULL;
10581
10582 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
10583 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
10584 ds_layout_ci.pNext = NULL;
10585 ds_layout_ci.bindingCount = 1;
10586 ds_layout_ci.pBindings = &dsl_binding;
10587 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010588 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis585f66d2016-07-01 18:23:58 -060010589 ASSERT_VK_SUCCESS(err);
10590
10591 VkDescriptorSet descriptor_set = {};
10592 VkDescriptorSetAllocateInfo alloc_info = {};
10593 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
10594 alloc_info.descriptorSetCount = 1;
10595 alloc_info.descriptorPool = ds_pool;
10596 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010597 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
Tobin Ehlis585f66d2016-07-01 18:23:58 -060010598 ASSERT_VK_SUCCESS(err);
10599
10600 // Create a buffer to be used for invalid updates
10601 VkBufferCreateInfo buff_ci = {};
10602 buff_ci.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
10603 buff_ci.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
10604 buff_ci.size = 256;
10605 buff_ci.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
10606 VkBuffer buffer;
10607 err = vkCreateBuffer(m_device->device(), &buff_ci, NULL, &buffer);
10608 ASSERT_VK_SUCCESS(err);
10609 // Have to bind memory to buffer before descriptor update
10610 VkMemoryAllocateInfo mem_alloc = {};
10611 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
10612 mem_alloc.pNext = NULL;
10613 mem_alloc.allocationSize = 256;
10614 mem_alloc.memoryTypeIndex = 0;
10615
10616 VkMemoryRequirements mem_reqs;
10617 vkGetBufferMemoryRequirements(m_device->device(), buffer, &mem_reqs);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010618 bool pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0);
Tobin Ehlis585f66d2016-07-01 18:23:58 -060010619 if (!pass) {
10620 vkDestroyBuffer(m_device->device(), buffer, NULL);
10621 return;
10622 }
10623
10624 VkDeviceMemory mem;
10625 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem);
10626 ASSERT_VK_SUCCESS(err);
10627 err = vkBindBufferMemory(m_device->device(), buffer, mem, 0);
10628 ASSERT_VK_SUCCESS(err);
10629
10630 VkDescriptorBufferInfo buff_info = {};
10631 buff_info.buffer = buffer;
10632 // First make offset 1 larger than buffer size
10633 buff_info.offset = 257;
10634 buff_info.range = VK_WHOLE_SIZE;
10635 VkWriteDescriptorSet descriptor_write = {};
10636 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
10637 descriptor_write.dstBinding = 0;
10638 descriptor_write.descriptorCount = 1;
10639 descriptor_write.pTexelBufferView = nullptr;
10640 descriptor_write.pBufferInfo = &buff_info;
10641 descriptor_write.pImageInfo = nullptr;
10642
10643 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
10644 descriptor_write.dstSet = descriptor_set;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010645 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " offset of 257 is greater than buffer ");
Tobin Ehlis585f66d2016-07-01 18:23:58 -060010646
10647 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
10648
10649 m_errorMonitor->VerifyFound();
10650 // Now cause error due to range of 0
10651 buff_info.offset = 0;
10652 buff_info.range = 0;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010653 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
10654 " range is not VK_WHOLE_SIZE and is zero, which is not allowed.");
Tobin Ehlis585f66d2016-07-01 18:23:58 -060010655
10656 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
10657
10658 m_errorMonitor->VerifyFound();
10659 // Now cause error due to range exceeding buffer size - offset
10660 buff_info.offset = 128;
10661 buff_info.range = 200;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010662 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 -060010663
10664 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
10665
10666 m_errorMonitor->VerifyFound();
Mark Lobodzinski4bb54092016-07-06 14:27:19 -060010667 vkFreeMemory(m_device->device(), mem, NULL);
Tobin Ehlis585f66d2016-07-01 18:23:58 -060010668 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
10669 vkDestroyBuffer(m_device->device(), buffer, NULL);
10670 vkFreeDescriptorSets(m_device->device(), ds_pool, 1, &descriptor_set);
10671 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
10672}
10673
Tobin Ehlis2fc296b2016-06-15 14:05:27 -060010674TEST_F(VkLayerTest, DSAspectBitsErrors) {
10675 // TODO : Initially only catching case where DEPTH & STENCIL aspect bits
10676 // are set, but could expand this test to hit more cases.
10677 TEST_DESCRIPTION("Attempt to update descriptor sets for images "
10678 "that do not have correct aspect bits sets.");
10679 VkResult err;
10680
10681 ASSERT_NO_FATAL_FAILURE(InitState());
10682 VkDescriptorPoolSize ds_type_count = {};
10683 ds_type_count.type = VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT;
10684 ds_type_count.descriptorCount = 1;
10685
10686 VkDescriptorPoolCreateInfo ds_pool_ci = {};
10687 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
10688 ds_pool_ci.pNext = NULL;
10689 ds_pool_ci.maxSets = 5;
10690 ds_pool_ci.poolSizeCount = 1;
10691 ds_pool_ci.pPoolSizes = &ds_type_count;
10692
10693 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010694 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis2fc296b2016-06-15 14:05:27 -060010695 ASSERT_VK_SUCCESS(err);
10696
10697 VkDescriptorSetLayoutBinding dsl_binding = {};
10698 dsl_binding.binding = 0;
10699 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT;
10700 dsl_binding.descriptorCount = 1;
10701 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
10702 dsl_binding.pImmutableSamplers = NULL;
10703
10704 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
10705 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
10706 ds_layout_ci.pNext = NULL;
10707 ds_layout_ci.bindingCount = 1;
10708 ds_layout_ci.pBindings = &dsl_binding;
10709 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010710 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis2fc296b2016-06-15 14:05:27 -060010711 ASSERT_VK_SUCCESS(err);
10712
10713 VkDescriptorSet descriptor_set = {};
10714 VkDescriptorSetAllocateInfo alloc_info = {};
10715 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
10716 alloc_info.descriptorSetCount = 1;
10717 alloc_info.descriptorPool = ds_pool;
10718 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010719 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
Tobin Ehlis2fc296b2016-06-15 14:05:27 -060010720 ASSERT_VK_SUCCESS(err);
10721
10722 // Create an image to be used for invalid updates
10723 VkImageCreateInfo image_ci = {};
10724 image_ci.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
10725 image_ci.imageType = VK_IMAGE_TYPE_2D;
10726 image_ci.format = VK_FORMAT_D24_UNORM_S8_UINT;
10727 image_ci.extent.width = 64;
10728 image_ci.extent.height = 64;
10729 image_ci.extent.depth = 1;
10730 image_ci.mipLevels = 1;
10731 image_ci.arrayLayers = 1;
10732 image_ci.samples = VK_SAMPLE_COUNT_1_BIT;
10733 image_ci.tiling = VK_IMAGE_TILING_LINEAR;
10734 image_ci.initialLayout = VK_IMAGE_LAYOUT_PREINITIALIZED;
10735 image_ci.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
10736 image_ci.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
10737 VkImage image;
10738 err = vkCreateImage(m_device->device(), &image_ci, NULL, &image);
10739 ASSERT_VK_SUCCESS(err);
10740 // Bind memory to image
10741 VkMemoryRequirements mem_reqs;
10742 VkDeviceMemory image_mem;
10743 bool pass;
10744 VkMemoryAllocateInfo mem_alloc = {};
10745 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
10746 mem_alloc.pNext = NULL;
10747 mem_alloc.allocationSize = 0;
10748 mem_alloc.memoryTypeIndex = 0;
10749 vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs);
10750 mem_alloc.allocationSize = mem_reqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010751 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0);
Tobin Ehlis2fc296b2016-06-15 14:05:27 -060010752 ASSERT_TRUE(pass);
10753 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &image_mem);
10754 ASSERT_VK_SUCCESS(err);
10755 err = vkBindImageMemory(m_device->device(), image, image_mem, 0);
10756 ASSERT_VK_SUCCESS(err);
10757 // Now create view for image
10758 VkImageViewCreateInfo image_view_ci = {};
10759 image_view_ci.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
10760 image_view_ci.image = image;
10761 image_view_ci.format = VK_FORMAT_D24_UNORM_S8_UINT;
10762 image_view_ci.viewType = VK_IMAGE_VIEW_TYPE_2D;
10763 image_view_ci.subresourceRange.layerCount = 1;
10764 image_view_ci.subresourceRange.baseArrayLayer = 0;
10765 image_view_ci.subresourceRange.levelCount = 1;
10766 // Setting both depth & stencil aspect bits is illegal for descriptor
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010767 image_view_ci.subresourceRange.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT;
Tobin Ehlis2fc296b2016-06-15 14:05:27 -060010768
10769 VkImageView image_view;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010770 err = vkCreateImageView(m_device->device(), &image_view_ci, NULL, &image_view);
Tobin Ehlis2fc296b2016-06-15 14:05:27 -060010771 ASSERT_VK_SUCCESS(err);
10772
10773 VkDescriptorImageInfo img_info = {};
10774 img_info.imageView = image_view;
10775 VkWriteDescriptorSet descriptor_write = {};
10776 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
10777 descriptor_write.dstBinding = 0;
10778 descriptor_write.descriptorCount = 1;
10779 descriptor_write.pTexelBufferView = NULL;
10780 descriptor_write.pBufferInfo = NULL;
10781 descriptor_write.pImageInfo = &img_info;
10782 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT;
10783 descriptor_write.dstSet = descriptor_set;
10784 const char *error_msg = " please only set either VK_IMAGE_ASPECT_DEPTH_BIT "
10785 "or VK_IMAGE_ASPECT_STENCIL_BIT ";
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010786 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, error_msg);
Tobin Ehlis2fc296b2016-06-15 14:05:27 -060010787
10788 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
10789
10790 m_errorMonitor->VerifyFound();
10791 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
10792 vkDestroyImage(m_device->device(), image, NULL);
10793 vkFreeMemory(m_device->device(), image_mem, NULL);
10794 vkDestroyImageView(m_device->device(), image_view, NULL);
10795 vkFreeDescriptorSets(m_device->device(), ds_pool, 1, &descriptor_set);
10796 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
10797}
10798
Karl Schultz6addd812016-02-02 17:17:23 -070010799TEST_F(VkLayerTest, DSTypeMismatch) {
Tobin Ehlis49eb23d2015-05-22 12:38:55 -060010800 // Create DS w/ layout of one type and attempt Update w/ mis-matched type
Karl Schultz6addd812016-02-02 17:17:23 -070010801 VkResult err;
Tobin Ehlis3b780662015-05-28 12:11:26 -060010802
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010803 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
10804 " binding #0 with type VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER but update "
10805 "type is VK_DESCRIPTOR_TYPE_SAMPLER");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060010806
Tobin Ehlis3b780662015-05-28 12:11:26 -060010807 ASSERT_NO_FATAL_FAILURE(InitState());
Karl Schultz6addd812016-02-02 17:17:23 -070010808 // VkDescriptorSetObj descriptorSet(m_device);
Chia-I Wu1b99bb22015-10-27 19:25:11 +080010809 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010810 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
10811 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -060010812
10813 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010814 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
10815 ds_pool_ci.pNext = NULL;
10816 ds_pool_ci.maxSets = 1;
10817 ds_pool_ci.poolSizeCount = 1;
10818 ds_pool_ci.pPoolSizes = &ds_type_count;
Tony Barboureb254902015-07-15 12:50:33 -060010819
Tobin Ehlis3b780662015-05-28 12:11:26 -060010820 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010821 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis3b780662015-05-28 12:11:26 -060010822 ASSERT_VK_SUCCESS(err);
Tony Barboureb254902015-07-15 12:50:33 -060010823 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010824 dsl_binding.binding = 0;
10825 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
10826 dsl_binding.descriptorCount = 1;
10827 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
10828 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis3b780662015-05-28 12:11:26 -060010829
Tony Barboureb254902015-07-15 12:50:33 -060010830 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010831 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
10832 ds_layout_ci.pNext = NULL;
10833 ds_layout_ci.bindingCount = 1;
10834 ds_layout_ci.pBindings = &dsl_binding;
Tony Barboureb254902015-07-15 12:50:33 -060010835
Tobin Ehlis3b780662015-05-28 12:11:26 -060010836 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010837 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis3b780662015-05-28 12:11:26 -060010838 ASSERT_VK_SUCCESS(err);
10839
10840 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080010841 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +080010842 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -070010843 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -060010844 alloc_info.descriptorPool = ds_pool;
10845 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010846 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis3b780662015-05-28 12:11:26 -060010847 ASSERT_VK_SUCCESS(err);
Tobin Ehlis3b780662015-05-28 12:11:26 -060010848
Tobin Ehlis30db8f82016-05-05 08:19:48 -060010849 VkSamplerCreateInfo sampler_ci = {};
10850 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
10851 sampler_ci.pNext = NULL;
10852 sampler_ci.magFilter = VK_FILTER_NEAREST;
10853 sampler_ci.minFilter = VK_FILTER_NEAREST;
10854 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
10855 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
10856 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
10857 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
10858 sampler_ci.mipLodBias = 1.0;
10859 sampler_ci.anisotropyEnable = VK_FALSE;
10860 sampler_ci.maxAnisotropy = 1;
10861 sampler_ci.compareEnable = VK_FALSE;
10862 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
10863 sampler_ci.minLod = 1.0;
10864 sampler_ci.maxLod = 1.0;
10865 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
10866 sampler_ci.unnormalizedCoordinates = VK_FALSE;
10867 VkSampler sampler;
10868 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
10869 ASSERT_VK_SUCCESS(err);
10870
10871 VkDescriptorImageInfo info = {};
10872 info.sampler = sampler;
Chia-I Wu9d00ed72015-05-25 16:27:55 +080010873
10874 VkWriteDescriptorSet descriptor_write;
10875 memset(&descriptor_write, 0, sizeof(descriptor_write));
10876 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080010877 descriptor_write.dstSet = descriptorSet;
Chia-I Wud50a7d72015-10-26 20:48:51 +080010878 descriptor_write.descriptorCount = 1;
Tobin Ehlis3b780662015-05-28 12:11:26 -060010879 // This is a mismatched type for the layout which expects BUFFER
Chia-I Wu9d00ed72015-05-25 16:27:55 +080010880 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
Courtney Goeltzenleuchter4cb6d922015-10-23 13:38:14 -060010881 descriptor_write.pImageInfo = &info;
Chia-I Wu9d00ed72015-05-25 16:27:55 +080010882
10883 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
10884
Chris Forbes8f36a8a2016-04-07 13:21:07 +120010885 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -060010886
Chia-I Wuf7458c52015-10-26 21:10:41 +080010887 vkDestroySampler(m_device->device(), sampler, NULL);
10888 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
10889 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis49eb23d2015-05-22 12:38:55 -060010890}
10891
Karl Schultz6addd812016-02-02 17:17:23 -070010892TEST_F(VkLayerTest, DSUpdateOutOfBounds) {
Tobin Ehlis49eb23d2015-05-22 12:38:55 -060010893 // For overlapping Update, have arrayIndex exceed that of layout
Karl Schultz6addd812016-02-02 17:17:23 -070010894 VkResult err;
Tobin Ehlis3b780662015-05-28 12:11:26 -060010895
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010896 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
10897 " binding #0 with 1 total descriptors but update of 1 descriptors "
10898 "starting at binding offset of 0 combined with update array element "
10899 "offset of 1 oversteps the size of this descriptor set.");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060010900
Tobin Ehlis3b780662015-05-28 12:11:26 -060010901 ASSERT_NO_FATAL_FAILURE(InitState());
Karl Schultz6addd812016-02-02 17:17:23 -070010902 // VkDescriptorSetObj descriptorSet(m_device);
Chia-I Wu1b99bb22015-10-27 19:25:11 +080010903 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010904 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
10905 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -060010906
10907 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010908 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
10909 ds_pool_ci.pNext = NULL;
10910 ds_pool_ci.maxSets = 1;
10911 ds_pool_ci.poolSizeCount = 1;
10912 ds_pool_ci.pPoolSizes = &ds_type_count;
Tony Barboureb254902015-07-15 12:50:33 -060010913
Tobin Ehlis3b780662015-05-28 12:11:26 -060010914 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010915 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis3b780662015-05-28 12:11:26 -060010916 ASSERT_VK_SUCCESS(err);
Tobin Ehlis3b780662015-05-28 12:11:26 -060010917
Tony Barboureb254902015-07-15 12:50:33 -060010918 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010919 dsl_binding.binding = 0;
10920 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
10921 dsl_binding.descriptorCount = 1;
10922 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
10923 dsl_binding.pImmutableSamplers = NULL;
Tony Barboureb254902015-07-15 12:50:33 -060010924
10925 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010926 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
10927 ds_layout_ci.pNext = NULL;
10928 ds_layout_ci.bindingCount = 1;
10929 ds_layout_ci.pBindings = &dsl_binding;
Tony Barboureb254902015-07-15 12:50:33 -060010930
Tobin Ehlis3b780662015-05-28 12:11:26 -060010931 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010932 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis3b780662015-05-28 12:11:26 -060010933 ASSERT_VK_SUCCESS(err);
10934
10935 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080010936 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +080010937 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -070010938 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -060010939 alloc_info.descriptorPool = ds_pool;
10940 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010941 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis3b780662015-05-28 12:11:26 -060010942 ASSERT_VK_SUCCESS(err);
Tobin Ehlis3b780662015-05-28 12:11:26 -060010943
Tobin Ehlis30db8f82016-05-05 08:19:48 -060010944 // Correctly update descriptor to avoid "NOT_UPDATED" error
10945 VkDescriptorBufferInfo buff_info = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010946 buff_info.buffer = VkBuffer(0); // Don't care about buffer handle for this test
Tobin Ehlis30db8f82016-05-05 08:19:48 -060010947 buff_info.offset = 0;
10948 buff_info.range = 1024;
Chia-I Wu9d00ed72015-05-25 16:27:55 +080010949
10950 VkWriteDescriptorSet descriptor_write;
10951 memset(&descriptor_write, 0, sizeof(descriptor_write));
10952 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080010953 descriptor_write.dstSet = descriptorSet;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010954 descriptor_write.dstArrayElement = 1; /* This index out of bounds for the update */
Chia-I Wud50a7d72015-10-26 20:48:51 +080010955 descriptor_write.descriptorCount = 1;
Tobin Ehlis0a43bde2016-05-03 08:31:08 -060010956 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
10957 descriptor_write.pBufferInfo = &buff_info;
Chia-I Wu9d00ed72015-05-25 16:27:55 +080010958
10959 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
10960
Chris Forbes8f36a8a2016-04-07 13:21:07 +120010961 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -060010962
Chia-I Wuf7458c52015-10-26 21:10:41 +080010963 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
10964 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis49eb23d2015-05-22 12:38:55 -060010965}
10966
Karl Schultz6addd812016-02-02 17:17:23 -070010967TEST_F(VkLayerTest, InvalidDSUpdateIndex) {
10968 // Create layout w/ count of 1 and attempt update to that layout w/ binding
10969 // index 2
10970 VkResult err;
Tobin Ehlis3b780662015-05-28 12:11:26 -060010971
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010972 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " does not have binding 2.");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060010973
Tobin Ehlis3b780662015-05-28 12:11:26 -060010974 ASSERT_NO_FATAL_FAILURE(InitState());
Karl Schultz6addd812016-02-02 17:17:23 -070010975 // VkDescriptorSetObj descriptorSet(m_device);
Chia-I Wu1b99bb22015-10-27 19:25:11 +080010976 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010977 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
10978 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -060010979
10980 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010981 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
10982 ds_pool_ci.pNext = NULL;
10983 ds_pool_ci.maxSets = 1;
10984 ds_pool_ci.poolSizeCount = 1;
10985 ds_pool_ci.pPoolSizes = &ds_type_count;
Courtney Goeltzenleuchterfe908d32015-09-16 16:12:45 -060010986
Tobin Ehlis3b780662015-05-28 12:11:26 -060010987 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010988 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis3b780662015-05-28 12:11:26 -060010989 ASSERT_VK_SUCCESS(err);
Tobin Ehlis3b780662015-05-28 12:11:26 -060010990
Tony Barboureb254902015-07-15 12:50:33 -060010991 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010992 dsl_binding.binding = 0;
10993 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
10994 dsl_binding.descriptorCount = 1;
10995 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
10996 dsl_binding.pImmutableSamplers = NULL;
Tony Barboureb254902015-07-15 12:50:33 -060010997
10998 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010999 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
11000 ds_layout_ci.pNext = NULL;
11001 ds_layout_ci.bindingCount = 1;
11002 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlis3b780662015-05-28 12:11:26 -060011003 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011004 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis3b780662015-05-28 12:11:26 -060011005 ASSERT_VK_SUCCESS(err);
11006
11007 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080011008 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +080011009 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -070011010 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -060011011 alloc_info.descriptorPool = ds_pool;
11012 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011013 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis3b780662015-05-28 12:11:26 -060011014 ASSERT_VK_SUCCESS(err);
Tobin Ehlis3b780662015-05-28 12:11:26 -060011015
Tony Barboureb254902015-07-15 12:50:33 -060011016 VkSamplerCreateInfo sampler_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011017 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
11018 sampler_ci.pNext = NULL;
11019 sampler_ci.magFilter = VK_FILTER_NEAREST;
11020 sampler_ci.minFilter = VK_FILTER_NEAREST;
11021 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
11022 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
11023 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
11024 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
11025 sampler_ci.mipLodBias = 1.0;
11026 sampler_ci.anisotropyEnable = VK_FALSE;
11027 sampler_ci.maxAnisotropy = 1;
11028 sampler_ci.compareEnable = VK_FALSE;
11029 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
11030 sampler_ci.minLod = 1.0;
11031 sampler_ci.maxLod = 1.0;
11032 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
11033 sampler_ci.unnormalizedCoordinates = VK_FALSE;
Tony Barboureb254902015-07-15 12:50:33 -060011034
Tobin Ehlis3b780662015-05-28 12:11:26 -060011035 VkSampler sampler;
Chia-I Wuf7458c52015-10-26 21:10:41 +080011036 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
Tobin Ehlis3b780662015-05-28 12:11:26 -060011037 ASSERT_VK_SUCCESS(err);
Chia-I Wu9d00ed72015-05-25 16:27:55 +080011038
Courtney Goeltzenleuchter4cb6d922015-10-23 13:38:14 -060011039 VkDescriptorImageInfo info = {};
11040 info.sampler = sampler;
Chia-I Wu9d00ed72015-05-25 16:27:55 +080011041
11042 VkWriteDescriptorSet descriptor_write;
11043 memset(&descriptor_write, 0, sizeof(descriptor_write));
11044 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080011045 descriptor_write.dstSet = descriptorSet;
11046 descriptor_write.dstBinding = 2;
Chia-I Wud50a7d72015-10-26 20:48:51 +080011047 descriptor_write.descriptorCount = 1;
Tobin Ehlis3b780662015-05-28 12:11:26 -060011048 // This is the wrong type, but out of bounds will be flagged first
Chia-I Wu9d00ed72015-05-25 16:27:55 +080011049 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
Courtney Goeltzenleuchter4cb6d922015-10-23 13:38:14 -060011050 descriptor_write.pImageInfo = &info;
Chia-I Wu9d00ed72015-05-25 16:27:55 +080011051
11052 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
11053
Chris Forbes8f36a8a2016-04-07 13:21:07 +120011054 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -060011055
Chia-I Wuf7458c52015-10-26 21:10:41 +080011056 vkDestroySampler(m_device->device(), sampler, NULL);
11057 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
11058 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis49eb23d2015-05-22 12:38:55 -060011059}
11060
Karl Schultz6addd812016-02-02 17:17:23 -070011061TEST_F(VkLayerTest, InvalidDSUpdateStruct) {
11062 // Call UpdateDS w/ struct type other than valid VK_STRUCTUR_TYPE_UPDATE_*
11063 // types
11064 VkResult err;
Tobin Ehlis3b780662015-05-28 12:11:26 -060011065
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011066 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 -060011067
Tobin Ehlis3b780662015-05-28 12:11:26 -060011068 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinski209b5292015-09-17 09:44:05 -060011069
Chia-I Wu1b99bb22015-10-27 19:25:11 +080011070 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011071 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
11072 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -060011073
11074 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011075 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
11076 ds_pool_ci.pNext = NULL;
11077 ds_pool_ci.maxSets = 1;
11078 ds_pool_ci.poolSizeCount = 1;
11079 ds_pool_ci.pPoolSizes = &ds_type_count;
Courtney Goeltzenleuchterfe908d32015-09-16 16:12:45 -060011080
Tobin Ehlis3b780662015-05-28 12:11:26 -060011081 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011082 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis3b780662015-05-28 12:11:26 -060011083 ASSERT_VK_SUCCESS(err);
Tony Barboureb254902015-07-15 12:50:33 -060011084 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011085 dsl_binding.binding = 0;
11086 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
11087 dsl_binding.descriptorCount = 1;
11088 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
11089 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis3b780662015-05-28 12:11:26 -060011090
Tony Barboureb254902015-07-15 12:50:33 -060011091 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011092 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
11093 ds_layout_ci.pNext = NULL;
11094 ds_layout_ci.bindingCount = 1;
11095 ds_layout_ci.pBindings = &dsl_binding;
Tony Barboureb254902015-07-15 12:50:33 -060011096
Tobin Ehlis3b780662015-05-28 12:11:26 -060011097 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011098 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis3b780662015-05-28 12:11:26 -060011099 ASSERT_VK_SUCCESS(err);
11100
11101 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080011102 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +080011103 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -070011104 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -060011105 alloc_info.descriptorPool = ds_pool;
11106 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011107 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis3b780662015-05-28 12:11:26 -060011108 ASSERT_VK_SUCCESS(err);
Tobin Ehlis3b780662015-05-28 12:11:26 -060011109
Tony Barboureb254902015-07-15 12:50:33 -060011110 VkSamplerCreateInfo sampler_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011111 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
11112 sampler_ci.pNext = NULL;
11113 sampler_ci.magFilter = VK_FILTER_NEAREST;
11114 sampler_ci.minFilter = VK_FILTER_NEAREST;
11115 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
11116 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
11117 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
11118 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
11119 sampler_ci.mipLodBias = 1.0;
11120 sampler_ci.anisotropyEnable = VK_FALSE;
11121 sampler_ci.maxAnisotropy = 1;
11122 sampler_ci.compareEnable = VK_FALSE;
11123 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
11124 sampler_ci.minLod = 1.0;
11125 sampler_ci.maxLod = 1.0;
11126 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
11127 sampler_ci.unnormalizedCoordinates = VK_FALSE;
Tobin Ehlis3b780662015-05-28 12:11:26 -060011128 VkSampler sampler;
Chia-I Wuf7458c52015-10-26 21:10:41 +080011129 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
Tobin Ehlis3b780662015-05-28 12:11:26 -060011130 ASSERT_VK_SUCCESS(err);
Chia-I Wu9d00ed72015-05-25 16:27:55 +080011131
Courtney Goeltzenleuchter4cb6d922015-10-23 13:38:14 -060011132 VkDescriptorImageInfo info = {};
11133 info.sampler = sampler;
Chia-I Wu9d00ed72015-05-25 16:27:55 +080011134
11135 VkWriteDescriptorSet descriptor_write;
11136 memset(&descriptor_write, 0, sizeof(descriptor_write));
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011137 descriptor_write.sType = (VkStructureType)0x99999999; /* Intentionally broken struct type */
Chia-I Wu3432a0c2015-10-27 18:04:07 +080011138 descriptor_write.dstSet = descriptorSet;
Chia-I Wud50a7d72015-10-26 20:48:51 +080011139 descriptor_write.descriptorCount = 1;
Tobin Ehlis3b780662015-05-28 12:11:26 -060011140 // This is the wrong type, but out of bounds will be flagged first
Chia-I Wu9d00ed72015-05-25 16:27:55 +080011141 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
Courtney Goeltzenleuchter4cb6d922015-10-23 13:38:14 -060011142 descriptor_write.pImageInfo = &info;
Chia-I Wu9d00ed72015-05-25 16:27:55 +080011143
11144 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
11145
Chris Forbes8f36a8a2016-04-07 13:21:07 +120011146 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -060011147
Chia-I Wuf7458c52015-10-26 21:10:41 +080011148 vkDestroySampler(m_device->device(), sampler, NULL);
11149 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
11150 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis49eb23d2015-05-22 12:38:55 -060011151}
11152
Karl Schultz6addd812016-02-02 17:17:23 -070011153TEST_F(VkLayerTest, SampleDescriptorUpdateError) {
Tobin Ehlisa1c28562015-10-23 16:00:08 -060011154 // Create a single Sampler descriptor and send it an invalid Sampler
Karl Schultz6addd812016-02-02 17:17:23 -070011155 VkResult err;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060011156
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011157 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
11158 "Attempted write update to sampler descriptor with invalid sampler");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060011159
Tobin Ehlisa1c28562015-10-23 16:00:08 -060011160 ASSERT_NO_FATAL_FAILURE(InitState());
Karl Schultz6addd812016-02-02 17:17:23 -070011161 // TODO : Farm Descriptor setup code to helper function(s) to reduce copied
11162 // code
Chia-I Wu1b99bb22015-10-27 19:25:11 +080011163 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011164 ds_type_count.type = VK_DESCRIPTOR_TYPE_SAMPLER;
11165 ds_type_count.descriptorCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060011166
11167 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011168 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
11169 ds_pool_ci.pNext = NULL;
11170 ds_pool_ci.maxSets = 1;
11171 ds_pool_ci.poolSizeCount = 1;
11172 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060011173
11174 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011175 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060011176 ASSERT_VK_SUCCESS(err);
11177
11178 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011179 dsl_binding.binding = 0;
11180 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
11181 dsl_binding.descriptorCount = 1;
11182 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
11183 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060011184
11185 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011186 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
11187 ds_layout_ci.pNext = NULL;
11188 ds_layout_ci.bindingCount = 1;
11189 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060011190 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011191 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060011192 ASSERT_VK_SUCCESS(err);
11193
11194 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080011195 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +080011196 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -070011197 alloc_info.descriptorSetCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060011198 alloc_info.descriptorPool = ds_pool;
11199 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011200 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060011201 ASSERT_VK_SUCCESS(err);
11202
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011203 VkSampler sampler = (VkSampler)((size_t)0xbaadbeef); // Sampler with invalid handle
Tobin Ehlisa1c28562015-10-23 16:00:08 -060011204
11205 VkDescriptorImageInfo descriptor_info;
11206 memset(&descriptor_info, 0, sizeof(VkDescriptorImageInfo));
11207 descriptor_info.sampler = sampler;
11208
11209 VkWriteDescriptorSet descriptor_write;
11210 memset(&descriptor_write, 0, sizeof(descriptor_write));
11211 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080011212 descriptor_write.dstSet = descriptorSet;
11213 descriptor_write.dstBinding = 0;
Chia-I Wud50a7d72015-10-26 20:48:51 +080011214 descriptor_write.descriptorCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060011215 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
11216 descriptor_write.pImageInfo = &descriptor_info;
11217
11218 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
11219
Chris Forbes8f36a8a2016-04-07 13:21:07 +120011220 m_errorMonitor->VerifyFound();
Tobin Ehlisa1c28562015-10-23 16:00:08 -060011221
Chia-I Wuf7458c52015-10-26 21:10:41 +080011222 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
11223 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060011224}
11225
Karl Schultz6addd812016-02-02 17:17:23 -070011226TEST_F(VkLayerTest, ImageViewDescriptorUpdateError) {
11227 // Create a single combined Image/Sampler descriptor and send it an invalid
11228 // imageView
11229 VkResult err;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060011230
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011231 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Attempted write update to combined "
11232 "image sampler descriptor failed due "
11233 "to: Invalid VkImageView:");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060011234
Tobin Ehlisa1c28562015-10-23 16:00:08 -060011235 ASSERT_NO_FATAL_FAILURE(InitState());
Chia-I Wu1b99bb22015-10-27 19:25:11 +080011236 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011237 ds_type_count.type = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
11238 ds_type_count.descriptorCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060011239
11240 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011241 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
11242 ds_pool_ci.pNext = NULL;
11243 ds_pool_ci.maxSets = 1;
11244 ds_pool_ci.poolSizeCount = 1;
11245 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060011246
11247 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011248 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060011249 ASSERT_VK_SUCCESS(err);
11250
11251 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011252 dsl_binding.binding = 0;
11253 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
11254 dsl_binding.descriptorCount = 1;
11255 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
11256 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060011257
11258 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011259 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
11260 ds_layout_ci.pNext = NULL;
11261 ds_layout_ci.bindingCount = 1;
11262 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060011263 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011264 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060011265 ASSERT_VK_SUCCESS(err);
11266
11267 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080011268 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +080011269 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -070011270 alloc_info.descriptorSetCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060011271 alloc_info.descriptorPool = ds_pool;
11272 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011273 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060011274 ASSERT_VK_SUCCESS(err);
11275
11276 VkSamplerCreateInfo sampler_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011277 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
11278 sampler_ci.pNext = NULL;
11279 sampler_ci.magFilter = VK_FILTER_NEAREST;
11280 sampler_ci.minFilter = VK_FILTER_NEAREST;
11281 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
11282 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
11283 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
11284 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
11285 sampler_ci.mipLodBias = 1.0;
11286 sampler_ci.anisotropyEnable = VK_FALSE;
11287 sampler_ci.maxAnisotropy = 1;
11288 sampler_ci.compareEnable = VK_FALSE;
11289 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
11290 sampler_ci.minLod = 1.0;
11291 sampler_ci.maxLod = 1.0;
11292 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
11293 sampler_ci.unnormalizedCoordinates = VK_FALSE;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060011294
11295 VkSampler sampler;
Chia-I Wuf7458c52015-10-26 21:10:41 +080011296 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060011297 ASSERT_VK_SUCCESS(err);
11298
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011299 VkImageView view = (VkImageView)((size_t)0xbaadbeef); // invalid imageView object
Tobin Ehlisa1c28562015-10-23 16:00:08 -060011300
11301 VkDescriptorImageInfo descriptor_info;
11302 memset(&descriptor_info, 0, sizeof(VkDescriptorImageInfo));
11303 descriptor_info.sampler = sampler;
11304 descriptor_info.imageView = view;
11305
11306 VkWriteDescriptorSet descriptor_write;
11307 memset(&descriptor_write, 0, sizeof(descriptor_write));
11308 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080011309 descriptor_write.dstSet = descriptorSet;
11310 descriptor_write.dstBinding = 0;
Chia-I Wud50a7d72015-10-26 20:48:51 +080011311 descriptor_write.descriptorCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060011312 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
11313 descriptor_write.pImageInfo = &descriptor_info;
11314
11315 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
11316
Chris Forbes8f36a8a2016-04-07 13:21:07 +120011317 m_errorMonitor->VerifyFound();
Tobin Ehlisa1c28562015-10-23 16:00:08 -060011318
Chia-I Wuf7458c52015-10-26 21:10:41 +080011319 vkDestroySampler(m_device->device(), sampler, NULL);
11320 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
11321 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060011322}
11323
Karl Schultz6addd812016-02-02 17:17:23 -070011324TEST_F(VkLayerTest, CopyDescriptorUpdateErrors) {
11325 // Create DS w/ layout of 2 types, write update 1 and attempt to copy-update
11326 // into the other
11327 VkResult err;
Tobin Ehlis04356f92015-10-27 16:35:27 -060011328
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011329 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " binding #1 with type "
11330 "VK_DESCRIPTOR_TYPE_SAMPLER. Types do "
11331 "not match.");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060011332
Tobin Ehlis04356f92015-10-27 16:35:27 -060011333 ASSERT_NO_FATAL_FAILURE(InitState());
Karl Schultz6addd812016-02-02 17:17:23 -070011334 // VkDescriptorSetObj descriptorSet(m_device);
Chia-I Wu1b99bb22015-10-27 19:25:11 +080011335 VkDescriptorPoolSize ds_type_count[2] = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011336 ds_type_count[0].type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
11337 ds_type_count[0].descriptorCount = 1;
11338 ds_type_count[1].type = VK_DESCRIPTOR_TYPE_SAMPLER;
11339 ds_type_count[1].descriptorCount = 1;
Tobin Ehlis04356f92015-10-27 16:35:27 -060011340
11341 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011342 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
11343 ds_pool_ci.pNext = NULL;
11344 ds_pool_ci.maxSets = 1;
11345 ds_pool_ci.poolSizeCount = 2;
11346 ds_pool_ci.pPoolSizes = ds_type_count;
Tobin Ehlis04356f92015-10-27 16:35:27 -060011347
11348 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011349 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis04356f92015-10-27 16:35:27 -060011350 ASSERT_VK_SUCCESS(err);
11351 VkDescriptorSetLayoutBinding dsl_binding[2] = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011352 dsl_binding[0].binding = 0;
11353 dsl_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
11354 dsl_binding[0].descriptorCount = 1;
11355 dsl_binding[0].stageFlags = VK_SHADER_STAGE_ALL;
11356 dsl_binding[0].pImmutableSamplers = NULL;
11357 dsl_binding[1].binding = 1;
11358 dsl_binding[1].descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
11359 dsl_binding[1].descriptorCount = 1;
11360 dsl_binding[1].stageFlags = VK_SHADER_STAGE_ALL;
11361 dsl_binding[1].pImmutableSamplers = NULL;
Tobin Ehlis04356f92015-10-27 16:35:27 -060011362
11363 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011364 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
11365 ds_layout_ci.pNext = NULL;
11366 ds_layout_ci.bindingCount = 2;
11367 ds_layout_ci.pBindings = dsl_binding;
Tobin Ehlis04356f92015-10-27 16:35:27 -060011368
11369 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011370 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis04356f92015-10-27 16:35:27 -060011371 ASSERT_VK_SUCCESS(err);
11372
11373 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080011374 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +080011375 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -070011376 alloc_info.descriptorSetCount = 1;
Tobin Ehlis04356f92015-10-27 16:35:27 -060011377 alloc_info.descriptorPool = ds_pool;
11378 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011379 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis04356f92015-10-27 16:35:27 -060011380 ASSERT_VK_SUCCESS(err);
11381
11382 VkSamplerCreateInfo sampler_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011383 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
11384 sampler_ci.pNext = NULL;
11385 sampler_ci.magFilter = VK_FILTER_NEAREST;
11386 sampler_ci.minFilter = VK_FILTER_NEAREST;
11387 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
11388 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
11389 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
11390 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
11391 sampler_ci.mipLodBias = 1.0;
11392 sampler_ci.anisotropyEnable = VK_FALSE;
11393 sampler_ci.maxAnisotropy = 1;
11394 sampler_ci.compareEnable = VK_FALSE;
11395 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
11396 sampler_ci.minLod = 1.0;
11397 sampler_ci.maxLod = 1.0;
11398 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
11399 sampler_ci.unnormalizedCoordinates = VK_FALSE;
Tobin Ehlis04356f92015-10-27 16:35:27 -060011400
11401 VkSampler sampler;
Chia-I Wuf7458c52015-10-26 21:10:41 +080011402 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
Tobin Ehlis04356f92015-10-27 16:35:27 -060011403 ASSERT_VK_SUCCESS(err);
11404
11405 VkDescriptorImageInfo info = {};
11406 info.sampler = sampler;
11407
11408 VkWriteDescriptorSet descriptor_write;
11409 memset(&descriptor_write, 0, sizeof(VkWriteDescriptorSet));
11410 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080011411 descriptor_write.dstSet = descriptorSet;
11412 descriptor_write.dstBinding = 1; // SAMPLER binding from layout above
Chia-I Wud50a7d72015-10-26 20:48:51 +080011413 descriptor_write.descriptorCount = 1;
Tobin Ehlis04356f92015-10-27 16:35:27 -060011414 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
11415 descriptor_write.pImageInfo = &info;
11416 // This write update should succeed
11417 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
11418 // Now perform a copy update that fails due to type mismatch
11419 VkCopyDescriptorSet copy_ds_update;
11420 memset(&copy_ds_update, 0, sizeof(VkCopyDescriptorSet));
11421 copy_ds_update.sType = VK_STRUCTURE_TYPE_COPY_DESCRIPTOR_SET;
11422 copy_ds_update.srcSet = descriptorSet;
Mark Young29927482016-05-04 14:38:51 -060011423 copy_ds_update.srcBinding = 1; // Copy from SAMPLER binding
Chia-I Wu3432a0c2015-10-27 18:04:07 +080011424 copy_ds_update.dstSet = descriptorSet;
Karl Schultz6addd812016-02-02 17:17:23 -070011425 copy_ds_update.dstBinding = 0; // ERROR : copy to UNIFORM binding
Chia-I Wud50a7d72015-10-26 20:48:51 +080011426 copy_ds_update.descriptorCount = 1; // copy 1 descriptor
Tobin Ehlis04356f92015-10-27 16:35:27 -060011427 vkUpdateDescriptorSets(m_device->device(), 0, NULL, 1, &copy_ds_update);
11428
Chris Forbes8f36a8a2016-04-07 13:21:07 +120011429 m_errorMonitor->VerifyFound();
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, " does not have copy update src binding of 3.");
Tobin Ehlis04356f92015-10-27 16:35:27 -060011432 memset(&copy_ds_update, 0, sizeof(VkCopyDescriptorSet));
11433 copy_ds_update.sType = VK_STRUCTURE_TYPE_COPY_DESCRIPTOR_SET;
11434 copy_ds_update.srcSet = descriptorSet;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011435 copy_ds_update.srcBinding = 3; // ERROR : Invalid binding for matching layout
Chia-I Wu3432a0c2015-10-27 18:04:07 +080011436 copy_ds_update.dstSet = descriptorSet;
11437 copy_ds_update.dstBinding = 0;
Mark Young29927482016-05-04 14:38:51 -060011438 copy_ds_update.descriptorCount = 1; // Copy 1 descriptor
Tobin Ehlis04356f92015-10-27 16:35:27 -060011439 vkUpdateDescriptorSets(m_device->device(), 0, NULL, 1, &copy_ds_update);
11440
Chris Forbes8f36a8a2016-04-07 13:21:07 +120011441 m_errorMonitor->VerifyFound();
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060011442
Tobin Ehlis04356f92015-10-27 16:35:27 -060011443 // Now perform a copy update that fails due to binding out of bounds
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011444 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " binding#1 with offset index of 1 plus "
11445 "update array offset of 0 and update of "
11446 "5 descriptors oversteps total number "
11447 "of descriptors in set: 2.");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060011448
Tobin Ehlis04356f92015-10-27 16:35:27 -060011449 memset(&copy_ds_update, 0, sizeof(VkCopyDescriptorSet));
11450 copy_ds_update.sType = VK_STRUCTURE_TYPE_COPY_DESCRIPTOR_SET;
11451 copy_ds_update.srcSet = descriptorSet;
11452 copy_ds_update.srcBinding = 1;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080011453 copy_ds_update.dstSet = descriptorSet;
11454 copy_ds_update.dstBinding = 0;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011455 copy_ds_update.descriptorCount = 5; // ERROR copy 5 descriptors (out of bounds for layout)
Tobin Ehlis04356f92015-10-27 16:35:27 -060011456 vkUpdateDescriptorSets(m_device->device(), 0, NULL, 1, &copy_ds_update);
11457
Chris Forbes8f36a8a2016-04-07 13:21:07 +120011458 m_errorMonitor->VerifyFound();
Tobin Ehlis04356f92015-10-27 16:35:27 -060011459
Chia-I Wuf7458c52015-10-26 21:10:41 +080011460 vkDestroySampler(m_device->device(), sampler, NULL);
11461 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
11462 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis04356f92015-10-27 16:35:27 -060011463}
11464
Karl Schultz6addd812016-02-02 17:17:23 -070011465TEST_F(VkLayerTest, NumSamplesMismatch) {
11466 // Create CommandBuffer where MSAA samples doesn't match RenderPass
11467 // sampleCount
11468 VkResult err;
Tobin Ehlis3b780662015-05-28 12:11:26 -060011469
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011470 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Num samples mismatch! ");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060011471
Tobin Ehlis3b780662015-05-28 12:11:26 -060011472 ASSERT_NO_FATAL_FAILURE(InitState());
11473 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chia-I Wu1b99bb22015-10-27 19:25:11 +080011474 VkDescriptorPoolSize ds_type_count = {};
Tony Barboureb254902015-07-15 12:50:33 -060011475 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Chia-I Wud50a7d72015-10-26 20:48:51 +080011476 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -060011477
11478 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011479 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
11480 ds_pool_ci.pNext = NULL;
11481 ds_pool_ci.maxSets = 1;
11482 ds_pool_ci.poolSizeCount = 1;
11483 ds_pool_ci.pPoolSizes = &ds_type_count;
Courtney Goeltzenleuchterfe908d32015-09-16 16:12:45 -060011484
Tobin Ehlis3b780662015-05-28 12:11:26 -060011485 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011486 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis3b780662015-05-28 12:11:26 -060011487 ASSERT_VK_SUCCESS(err);
Tobin Ehlis3b780662015-05-28 12:11:26 -060011488
Tony Barboureb254902015-07-15 12:50:33 -060011489 VkDescriptorSetLayoutBinding dsl_binding = {};
Chia-I Wud46e6ae2015-10-31 00:31:16 +080011490 dsl_binding.binding = 0;
Tony Barboureb254902015-07-15 12:50:33 -060011491 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Chia-I Wu02124482015-11-06 06:42:02 +080011492 dsl_binding.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -060011493 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
11494 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis3b780662015-05-28 12:11:26 -060011495
Tony Barboureb254902015-07-15 12:50:33 -060011496 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
11497 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
11498 ds_layout_ci.pNext = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +080011499 ds_layout_ci.bindingCount = 1;
Jon Ashburn6e23c1f2015-12-30 18:01:16 -070011500 ds_layout_ci.pBindings = &dsl_binding;
Tony Barboureb254902015-07-15 12:50:33 -060011501
Tobin Ehlis3b780662015-05-28 12:11:26 -060011502 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011503 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis3b780662015-05-28 12:11:26 -060011504 ASSERT_VK_SUCCESS(err);
11505
11506 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080011507 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +080011508 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -070011509 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -060011510 alloc_info.descriptorPool = ds_pool;
11511 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011512 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis3b780662015-05-28 12:11:26 -060011513 ASSERT_VK_SUCCESS(err);
11514
Tony Barboureb254902015-07-15 12:50:33 -060011515 VkPipelineMultisampleStateCreateInfo pipe_ms_state_ci = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011516 pipe_ms_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
Karl Schultz6addd812016-02-02 17:17:23 -070011517 pipe_ms_state_ci.pNext = NULL;
11518 pipe_ms_state_ci.rasterizationSamples = VK_SAMPLE_COUNT_4_BIT;
11519 pipe_ms_state_ci.sampleShadingEnable = 0;
11520 pipe_ms_state_ci.minSampleShading = 1.0;
11521 pipe_ms_state_ci.pSampleMask = NULL;
Tobin Ehlis3b780662015-05-28 12:11:26 -060011522
Tony Barboureb254902015-07-15 12:50:33 -060011523 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011524 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
11525 pipeline_layout_ci.pNext = NULL;
11526 pipeline_layout_ci.setLayoutCount = 1;
11527 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlis3b780662015-05-28 12:11:26 -060011528
11529 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011530 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis3b780662015-05-28 12:11:26 -060011531 ASSERT_VK_SUCCESS(err);
11532
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011533 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
11534 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this); // We shouldn't need a fragment shader
11535 // but add it to be able to run on more devices
Tony Barbour62e1a5b2015-08-06 10:16:07 -060011536 VkPipelineObj pipe(m_device);
11537 pipe.AddShader(&vs);
Tony Barbour1c94d372015-08-06 11:21:08 -060011538 pipe.AddShader(&fs);
Mark Youngc89c6312016-03-31 16:03:20 -060011539 pipe.AddColorAttachment();
Tony Barbour62e1a5b2015-08-06 10:16:07 -060011540 pipe.SetMSAA(&pipe_ms_state_ci);
11541 pipe.CreateVKPipeline(pipeline_layout, renderPass());
Tobin Ehlis3b780662015-05-28 12:11:26 -060011542
Tony Barbourfe3351b2015-07-28 10:17:20 -060011543 BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011544 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Tobin Ehlis3b780662015-05-28 12:11:26 -060011545
Mark Young29927482016-05-04 14:38:51 -060011546 // Render triangle (the error should trigger on the attempt to draw).
11547 Draw(3, 1, 0, 0);
11548
11549 // Finalize recording of the command buffer
11550 EndCommandBuffer();
11551
Chris Forbes8f36a8a2016-04-07 13:21:07 +120011552 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -060011553
Chia-I Wuf7458c52015-10-26 21:10:41 +080011554 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
11555 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
11556 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis49eb23d2015-05-22 12:38:55 -060011557}
Mark Young29927482016-05-04 14:38:51 -060011558
Tobin Ehlis85aa15a2016-06-15 10:52:37 -060011559TEST_F(VkLayerTest, RenderPassIncompatible) {
11560 TEST_DESCRIPTION("Hit RenderPass incompatible cases. "
11561 "Initial case is drawing with an active renderpass that's "
11562 "not compatible with the bound PSO's creation renderpass");
11563 VkResult err;
11564
11565 ASSERT_NO_FATAL_FAILURE(InitState());
11566 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
11567
11568 VkDescriptorSetLayoutBinding dsl_binding = {};
11569 dsl_binding.binding = 0;
11570 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
11571 dsl_binding.descriptorCount = 1;
11572 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
11573 dsl_binding.pImmutableSamplers = NULL;
11574
11575 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
11576 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
11577 ds_layout_ci.pNext = NULL;
11578 ds_layout_ci.bindingCount = 1;
11579 ds_layout_ci.pBindings = &dsl_binding;
11580
11581 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011582 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis85aa15a2016-06-15 10:52:37 -060011583 ASSERT_VK_SUCCESS(err);
11584
11585 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
11586 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
11587 pipeline_layout_ci.pNext = NULL;
11588 pipeline_layout_ci.setLayoutCount = 1;
11589 pipeline_layout_ci.pSetLayouts = &ds_layout;
11590
11591 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011592 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis85aa15a2016-06-15 10:52:37 -060011593 ASSERT_VK_SUCCESS(err);
11594
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011595 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
11596 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this); // We shouldn't need a fragment shader
11597 // but add it to be able to run on more devices
Tobin Ehlis85aa15a2016-06-15 10:52:37 -060011598 // Create a renderpass that will be incompatible with default renderpass
11599 VkAttachmentReference attach = {};
11600 attach.layout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
11601 VkAttachmentReference color_att = {};
11602 color_att.layout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
11603 VkSubpassDescription subpass = {};
11604 subpass.inputAttachmentCount = 1;
11605 subpass.pInputAttachments = &attach;
11606 subpass.colorAttachmentCount = 1;
11607 subpass.pColorAttachments = &color_att;
11608 VkRenderPassCreateInfo rpci = {};
11609 rpci.subpassCount = 1;
11610 rpci.pSubpasses = &subpass;
11611 rpci.attachmentCount = 1;
11612 VkAttachmentDescription attach_desc = {};
11613 attach_desc.samples = VK_SAMPLE_COUNT_1_BIT;
Cody Northropbd16af12016-06-21 09:25:48 -060011614 // Format incompatible with PSO RP color attach format B8G8R8A8_UNORM
11615 attach_desc.format = VK_FORMAT_R8G8B8A8_UNORM;
Tobin Ehlis85aa15a2016-06-15 10:52:37 -060011616 rpci.pAttachments = &attach_desc;
11617 rpci.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
11618 VkRenderPass rp;
11619 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
11620 VkPipelineObj pipe(m_device);
11621 pipe.AddShader(&vs);
11622 pipe.AddShader(&fs);
11623 pipe.AddColorAttachment();
11624 VkViewport view_port = {};
11625 m_viewports.push_back(view_port);
11626 pipe.SetViewport(m_viewports);
11627 VkRect2D rect = {};
11628 m_scissors.push_back(rect);
11629 pipe.SetScissor(m_scissors);
11630 pipe.CreateVKPipeline(pipeline_layout, renderPass());
11631
11632 VkCommandBufferInheritanceInfo cbii = {};
11633 cbii.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_INHERITANCE_INFO;
11634 cbii.renderPass = rp;
11635 cbii.subpass = 0;
11636 VkCommandBufferBeginInfo cbbi = {};
11637 cbbi.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
11638 cbbi.pInheritanceInfo = &cbii;
11639 vkBeginCommandBuffer(m_commandBuffer->handle(), &cbbi);
11640 VkRenderPassBeginInfo rpbi = {};
11641 rpbi.sType = VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO;
11642 rpbi.framebuffer = m_framebuffer;
11643 rpbi.renderPass = rp;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011644 vkCmdBeginRenderPass(m_commandBuffer->GetBufferHandle(), &rpbi, VK_SUBPASS_CONTENTS_INLINE);
11645 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Tobin Ehlis85aa15a2016-06-15 10:52:37 -060011646
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011647 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " is incompatible w/ gfx pipeline ");
Tobin Ehlis85aa15a2016-06-15 10:52:37 -060011648 // Render triangle (the error should trigger on the attempt to draw).
11649 Draw(3, 1, 0, 0);
11650
11651 // Finalize recording of the command buffer
11652 EndCommandBuffer();
11653
11654 m_errorMonitor->VerifyFound();
11655
11656 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
11657 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
11658 vkDestroyRenderPass(m_device->device(), rp, NULL);
11659}
11660
Mark Youngc89c6312016-03-31 16:03:20 -060011661TEST_F(VkLayerTest, NumBlendAttachMismatch) {
11662 // Create Pipeline where the number of blend attachments doesn't match the
11663 // number of color attachments. In this case, we don't add any color
11664 // blend attachments even though we have a color attachment.
11665 VkResult err;
11666
11667 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011668 "Render pass subpass 0 mismatch with blending state defined and blend state attachment");
Mark Youngc89c6312016-03-31 16:03:20 -060011669
11670 ASSERT_NO_FATAL_FAILURE(InitState());
11671 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
11672 VkDescriptorPoolSize ds_type_count = {};
11673 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
11674 ds_type_count.descriptorCount = 1;
11675
11676 VkDescriptorPoolCreateInfo ds_pool_ci = {};
11677 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
11678 ds_pool_ci.pNext = NULL;
11679 ds_pool_ci.maxSets = 1;
11680 ds_pool_ci.poolSizeCount = 1;
11681 ds_pool_ci.pPoolSizes = &ds_type_count;
11682
11683 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011684 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Mark Youngc89c6312016-03-31 16:03:20 -060011685 ASSERT_VK_SUCCESS(err);
11686
11687 VkDescriptorSetLayoutBinding dsl_binding = {};
11688 dsl_binding.binding = 0;
11689 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
11690 dsl_binding.descriptorCount = 1;
11691 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
11692 dsl_binding.pImmutableSamplers = NULL;
11693
11694 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
11695 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
11696 ds_layout_ci.pNext = NULL;
11697 ds_layout_ci.bindingCount = 1;
11698 ds_layout_ci.pBindings = &dsl_binding;
11699
11700 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011701 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Mark Youngc89c6312016-03-31 16:03:20 -060011702 ASSERT_VK_SUCCESS(err);
11703
11704 VkDescriptorSet descriptorSet;
11705 VkDescriptorSetAllocateInfo alloc_info = {};
11706 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
11707 alloc_info.descriptorSetCount = 1;
11708 alloc_info.descriptorPool = ds_pool;
11709 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011710 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Mark Youngc89c6312016-03-31 16:03:20 -060011711 ASSERT_VK_SUCCESS(err);
11712
11713 VkPipelineMultisampleStateCreateInfo pipe_ms_state_ci = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011714 pipe_ms_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
Mark Youngc89c6312016-03-31 16:03:20 -060011715 pipe_ms_state_ci.pNext = NULL;
11716 pipe_ms_state_ci.rasterizationSamples = VK_SAMPLE_COUNT_1_BIT;
11717 pipe_ms_state_ci.sampleShadingEnable = 0;
11718 pipe_ms_state_ci.minSampleShading = 1.0;
11719 pipe_ms_state_ci.pSampleMask = NULL;
11720
11721 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
11722 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
11723 pipeline_layout_ci.pNext = NULL;
11724 pipeline_layout_ci.setLayoutCount = 1;
11725 pipeline_layout_ci.pSetLayouts = &ds_layout;
11726
11727 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011728 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Mark Youngc89c6312016-03-31 16:03:20 -060011729 ASSERT_VK_SUCCESS(err);
11730
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011731 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
11732 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this); // We shouldn't need a fragment shader
11733 // but add it to be able to run on more devices
Mark Youngc89c6312016-03-31 16:03:20 -060011734 VkPipelineObj pipe(m_device);
11735 pipe.AddShader(&vs);
11736 pipe.AddShader(&fs);
11737 pipe.SetMSAA(&pipe_ms_state_ci);
11738 pipe.CreateVKPipeline(pipeline_layout, renderPass());
11739
11740 BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011741 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Mark Youngc89c6312016-03-31 16:03:20 -060011742
Mark Young29927482016-05-04 14:38:51 -060011743 // Render triangle (the error should trigger on the attempt to draw).
11744 Draw(3, 1, 0, 0);
11745
11746 // Finalize recording of the command buffer
11747 EndCommandBuffer();
11748
Chris Forbes8f36a8a2016-04-07 13:21:07 +120011749 m_errorMonitor->VerifyFound();
Mark Youngc89c6312016-03-31 16:03:20 -060011750
11751 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
11752 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
11753 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
11754}
Mark Young29927482016-05-04 14:38:51 -060011755
Mark Muellerd4914412016-06-13 17:52:06 -060011756TEST_F(VkLayerTest, MissingClearAttachment) {
11757 TEST_DESCRIPTION("Points to a wrong colorAttachment index in a VkClearAttachment "
11758 "structure passed to vkCmdClearAttachments");
Cody Northropc31a84f2016-08-22 10:41:47 -060011759 ASSERT_NO_FATAL_FAILURE(InitState());
Chris Forbesda6ae6f2016-09-09 14:36:33 +120011760 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Chris Forbesef5e2842016-09-08 15:25:24 +120011761 "vkCmdClearAttachments() color attachment index 1 out of range for active subpass 0; ignored");
Mark Muellerd4914412016-06-13 17:52:06 -060011762
11763 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailCmdClearAttachments);
11764 m_errorMonitor->VerifyFound();
11765}
11766
Karl Schultz6addd812016-02-02 17:17:23 -070011767TEST_F(VkLayerTest, ClearCmdNoDraw) {
11768 // Create CommandBuffer where we add ClearCmd for FB Color attachment prior
11769 // to issuing a Draw
11770 VkResult err;
Tobin Ehlis53eddda2015-07-01 16:46:13 -060011771
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011772 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
11773 "vkCmdClearAttachments() issued on CB object ");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060011774
Tobin Ehlis53eddda2015-07-01 16:46:13 -060011775 ASSERT_NO_FATAL_FAILURE(InitState());
11776 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barboureb254902015-07-15 12:50:33 -060011777
Chia-I Wu1b99bb22015-10-27 19:25:11 +080011778 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011779 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
11780 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -060011781
11782 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011783 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
11784 ds_pool_ci.pNext = NULL;
11785 ds_pool_ci.maxSets = 1;
11786 ds_pool_ci.poolSizeCount = 1;
11787 ds_pool_ci.pPoolSizes = &ds_type_count;
Tony Barboureb254902015-07-15 12:50:33 -060011788
Tobin Ehlis53eddda2015-07-01 16:46:13 -060011789 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011790 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis53eddda2015-07-01 16:46:13 -060011791 ASSERT_VK_SUCCESS(err);
11792
Tony Barboureb254902015-07-15 12:50:33 -060011793 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011794 dsl_binding.binding = 0;
11795 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
11796 dsl_binding.descriptorCount = 1;
11797 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
11798 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis53eddda2015-07-01 16:46:13 -060011799
Tony Barboureb254902015-07-15 12:50:33 -060011800 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011801 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
11802 ds_layout_ci.pNext = NULL;
11803 ds_layout_ci.bindingCount = 1;
11804 ds_layout_ci.pBindings = &dsl_binding;
Mark Lobodzinski209b5292015-09-17 09:44:05 -060011805
Tobin Ehlis53eddda2015-07-01 16:46:13 -060011806 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011807 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis53eddda2015-07-01 16:46:13 -060011808 ASSERT_VK_SUCCESS(err);
11809
11810 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080011811 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +080011812 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -070011813 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -060011814 alloc_info.descriptorPool = ds_pool;
11815 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011816 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis53eddda2015-07-01 16:46:13 -060011817 ASSERT_VK_SUCCESS(err);
11818
Tony Barboureb254902015-07-15 12:50:33 -060011819 VkPipelineMultisampleStateCreateInfo pipe_ms_state_ci = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011820 pipe_ms_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
Karl Schultz6addd812016-02-02 17:17:23 -070011821 pipe_ms_state_ci.pNext = NULL;
11822 pipe_ms_state_ci.rasterizationSamples = VK_SAMPLE_COUNT_4_BIT;
11823 pipe_ms_state_ci.sampleShadingEnable = 0;
11824 pipe_ms_state_ci.minSampleShading = 1.0;
11825 pipe_ms_state_ci.pSampleMask = NULL;
Tobin Ehlis53eddda2015-07-01 16:46:13 -060011826
Tony Barboureb254902015-07-15 12:50:33 -060011827 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011828 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
11829 pipeline_layout_ci.pNext = NULL;
11830 pipeline_layout_ci.setLayoutCount = 1;
11831 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlis53eddda2015-07-01 16:46:13 -060011832
11833 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011834 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis53eddda2015-07-01 16:46:13 -060011835 ASSERT_VK_SUCCESS(err);
Mark Lobodzinski209b5292015-09-17 09:44:05 -060011836
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011837 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
Karl Schultzbdb75952016-04-19 11:36:49 -060011838 // We shouldn't need a fragment shader but add it to be able to run
Karl Schultz6addd812016-02-02 17:17:23 -070011839 // on more devices
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011840 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060011841
Tony Barbour62e1a5b2015-08-06 10:16:07 -060011842 VkPipelineObj pipe(m_device);
11843 pipe.AddShader(&vs);
Tony Barbour1c94d372015-08-06 11:21:08 -060011844 pipe.AddShader(&fs);
Tony Barbour62e1a5b2015-08-06 10:16:07 -060011845 pipe.SetMSAA(&pipe_ms_state_ci);
11846 pipe.CreateVKPipeline(pipeline_layout, renderPass());
Tony Barbourfe3351b2015-07-28 10:17:20 -060011847
11848 BeginCommandBuffer();
Tobin Ehlis53eddda2015-07-01 16:46:13 -060011849
Karl Schultz6addd812016-02-02 17:17:23 -070011850 // Main thing we care about for this test is that the VkImage obj we're
11851 // clearing matches Color Attachment of FB
Tobin Ehlis53eddda2015-07-01 16:46:13 -060011852 // Also pass down other dummy params to keep driver and paramchecker happy
Courtney Goeltzenleuchterc9323e02015-10-15 16:51:05 -060011853 VkClearAttachment color_attachment;
11854 color_attachment.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
11855 color_attachment.clearValue.color.float32[0] = 1.0;
11856 color_attachment.clearValue.color.float32[1] = 1.0;
11857 color_attachment.clearValue.color.float32[2] = 1.0;
11858 color_attachment.clearValue.color.float32[3] = 1.0;
11859 color_attachment.colorAttachment = 0;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011860 VkClearRect clear_rect = {{{0, 0}, {(uint32_t)m_width, (uint32_t)m_height}}};
Tobin Ehlis53eddda2015-07-01 16:46:13 -060011861
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011862 vkCmdClearAttachments(m_commandBuffer->GetBufferHandle(), 1, &color_attachment, 1, &clear_rect);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060011863
Chris Forbes8f36a8a2016-04-07 13:21:07 +120011864 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -060011865
Chia-I Wuf7458c52015-10-26 21:10:41 +080011866 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
11867 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
11868 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis53eddda2015-07-01 16:46:13 -060011869}
11870
Karl Schultz6addd812016-02-02 17:17:23 -070011871TEST_F(VkLayerTest, VtxBufferBadIndex) {
11872 VkResult err;
Tobin Ehlis502480b2015-06-24 15:53:07 -060011873
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011874 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
11875 "but no vertex buffers are attached to this Pipeline State Object");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060011876
Tobin Ehlis502480b2015-06-24 15:53:07 -060011877 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisd332f282015-10-02 11:00:56 -060011878 ASSERT_NO_FATAL_FAILURE(InitViewport());
Tobin Ehlis502480b2015-06-24 15:53:07 -060011879 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barboureb254902015-07-15 12:50:33 -060011880
Chia-I Wu1b99bb22015-10-27 19:25:11 +080011881 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011882 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
11883 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -060011884
11885 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011886 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
11887 ds_pool_ci.pNext = NULL;
11888 ds_pool_ci.maxSets = 1;
11889 ds_pool_ci.poolSizeCount = 1;
11890 ds_pool_ci.pPoolSizes = &ds_type_count;
Tony Barboureb254902015-07-15 12:50:33 -060011891
Courtney Goeltzenleuchterfe908d32015-09-16 16:12:45 -060011892 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011893 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis502480b2015-06-24 15:53:07 -060011894 ASSERT_VK_SUCCESS(err);
11895
Tony Barboureb254902015-07-15 12:50:33 -060011896 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011897 dsl_binding.binding = 0;
11898 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
11899 dsl_binding.descriptorCount = 1;
11900 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
11901 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis502480b2015-06-24 15:53:07 -060011902
Tony Barboureb254902015-07-15 12:50:33 -060011903 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011904 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
11905 ds_layout_ci.pNext = NULL;
11906 ds_layout_ci.bindingCount = 1;
11907 ds_layout_ci.pBindings = &dsl_binding;
Tony Barboureb254902015-07-15 12:50:33 -060011908
Tobin Ehlis502480b2015-06-24 15:53:07 -060011909 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011910 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis502480b2015-06-24 15:53:07 -060011911 ASSERT_VK_SUCCESS(err);
11912
11913 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080011914 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +080011915 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -070011916 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -060011917 alloc_info.descriptorPool = ds_pool;
11918 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011919 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis502480b2015-06-24 15:53:07 -060011920 ASSERT_VK_SUCCESS(err);
11921
Tony Barboureb254902015-07-15 12:50:33 -060011922 VkPipelineMultisampleStateCreateInfo pipe_ms_state_ci = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011923 pipe_ms_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
Karl Schultz6addd812016-02-02 17:17:23 -070011924 pipe_ms_state_ci.pNext = NULL;
11925 pipe_ms_state_ci.rasterizationSamples = VK_SAMPLE_COUNT_1_BIT;
11926 pipe_ms_state_ci.sampleShadingEnable = 0;
11927 pipe_ms_state_ci.minSampleShading = 1.0;
11928 pipe_ms_state_ci.pSampleMask = NULL;
Tobin Ehlis502480b2015-06-24 15:53:07 -060011929
Tony Barboureb254902015-07-15 12:50:33 -060011930 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011931 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
11932 pipeline_layout_ci.pNext = NULL;
11933 pipeline_layout_ci.setLayoutCount = 1;
11934 pipeline_layout_ci.pSetLayouts = &ds_layout;
11935 VkPipelineLayout pipeline_layout;
Tobin Ehlis502480b2015-06-24 15:53:07 -060011936
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011937 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis502480b2015-06-24 15:53:07 -060011938 ASSERT_VK_SUCCESS(err);
11939
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011940 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
11941 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this); // We shouldn't need a fragment shader
11942 // but add it to be able to run on more devices
Tony Barbour62e1a5b2015-08-06 10:16:07 -060011943 VkPipelineObj pipe(m_device);
11944 pipe.AddShader(&vs);
Tony Barbour1c94d372015-08-06 11:21:08 -060011945 pipe.AddShader(&fs);
Mark Youngc89c6312016-03-31 16:03:20 -060011946 pipe.AddColorAttachment();
Tony Barbour62e1a5b2015-08-06 10:16:07 -060011947 pipe.SetMSAA(&pipe_ms_state_ci);
Tobin Ehlisd332f282015-10-02 11:00:56 -060011948 pipe.SetViewport(m_viewports);
11949 pipe.SetScissor(m_scissors);
Tony Barbour62e1a5b2015-08-06 10:16:07 -060011950 pipe.CreateVKPipeline(pipeline_layout, renderPass());
Tony Barbourfe3351b2015-07-28 10:17:20 -060011951
11952 BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011953 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Tobin Ehlisf7bf4502015-09-09 15:12:35 -060011954 // Don't care about actual data, just need to get to draw to flag error
11955 static const float vbo_data[3] = {1.f, 0.f, 1.f};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011956 VkConstantBufferObj vbo(m_device, sizeof(vbo_data), sizeof(float), (const void *)&vbo_data);
Tobin Ehlisf7bf4502015-09-09 15:12:35 -060011957 BindVertexBuffer(&vbo, (VkDeviceSize)0, 1); // VBO idx 1, but no VBO in PSO
Courtney Goeltzenleuchter08c26372015-09-23 12:31:50 -060011958 Draw(1, 0, 0, 0);
Tobin Ehlis502480b2015-06-24 15:53:07 -060011959
Chris Forbes8f36a8a2016-04-07 13:21:07 +120011960 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -060011961
Chia-I Wuf7458c52015-10-26 21:10:41 +080011962 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
11963 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
11964 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis502480b2015-06-24 15:53:07 -060011965}
Mark Muellerdfe37552016-07-07 14:47:42 -060011966
Mark Mueller2ee294f2016-08-04 12:59:48 -060011967TEST_F(VkLayerTest, MismatchCountQueueCreateRequestedFeature) {
11968 TEST_DESCRIPTION("Use an invalid count in a vkEnumeratePhysicalDevices call."
11969 "Use invalid Queue Family Index in vkCreateDevice");
Cody Northropc31a84f2016-08-22 10:41:47 -060011970 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Mueller2ee294f2016-08-04 12:59:48 -060011971
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011972 const char *mismatch_count_message = "Call to vkEnumeratePhysicalDevices() "
11973 "w/ pPhysicalDeviceCount value ";
Mark Mueller2ee294f2016-08-04 12:59:48 -060011974
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011975 const char *invalid_queueFamilyIndex_message = "Invalid queue create request in vkCreateDevice(). Invalid "
11976 "queueFamilyIndex ";
Mark Mueller2ee294f2016-08-04 12:59:48 -060011977
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011978 const char *unavailable_feature_message = "While calling vkCreateDevice(), requesting feature #";
Mark Mueller2ee294f2016-08-04 12:59:48 -060011979
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011980 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT, mismatch_count_message);
Mark Mueller880fce52016-08-17 15:23:23 -060011981 // The following test fails with recent NVidia drivers.
11982 // By the time core_validation is reached, the NVidia
11983 // driver has sanitized the invalid condition and core_validation
11984 // is not introduced to the failure condition. This is not the case
11985 // with AMD and Mesa drivers. Futher investigation is required
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011986 // uint32_t count = static_cast<uint32_t>(~0);
11987 // VkPhysicalDevice physical_device;
11988 // vkEnumeratePhysicalDevices(instance(), &count, &physical_device);
11989 // m_errorMonitor->VerifyFound();
Mark Mueller2ee294f2016-08-04 12:59:48 -060011990
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011991 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, invalid_queueFamilyIndex_message);
Mark Mueller2ee294f2016-08-04 12:59:48 -060011992 float queue_priority = 0.0;
11993
11994 VkDeviceQueueCreateInfo queue_create_info = {};
11995 queue_create_info.sType = VK_STRUCTURE_TYPE_DEVICE_QUEUE_CREATE_INFO;
11996 queue_create_info.queueCount = 1;
11997 queue_create_info.pQueuePriorities = &queue_priority;
11998 queue_create_info.queueFamilyIndex = static_cast<uint32_t>(~0);
11999
12000 VkPhysicalDeviceFeatures features = m_device->phy().features();
12001 VkDevice testDevice;
12002 VkDeviceCreateInfo device_create_info = {};
12003 device_create_info.sType = VK_STRUCTURE_TYPE_DEVICE_CREATE_INFO;
12004 device_create_info.queueCreateInfoCount = 1;
12005 device_create_info.pQueueCreateInfos = &queue_create_info;
12006 device_create_info.pEnabledFeatures = &features;
12007 vkCreateDevice(gpu(), &device_create_info, nullptr, &testDevice);
12008 m_errorMonitor->VerifyFound();
12009
12010 queue_create_info.queueFamilyIndex = 1;
12011
12012 unsigned feature_count = sizeof(VkPhysicalDeviceFeatures) / sizeof(VkBool32);
12013 VkBool32 *feature_array = reinterpret_cast<VkBool32 *>(&features);
12014 for (unsigned i = 0; i < feature_count; i++) {
12015 if (VK_FALSE == feature_array[i]) {
12016 feature_array[i] = VK_TRUE;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012017 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, unavailable_feature_message);
Mark Mueller2ee294f2016-08-04 12:59:48 -060012018 device_create_info.pEnabledFeatures = &features;
12019 vkCreateDevice(gpu(), &device_create_info, nullptr, &testDevice);
12020 m_errorMonitor->VerifyFound();
12021 break;
12022 }
12023 }
12024}
12025
12026TEST_F(VkLayerTest, InvalidQueueIndexInvalidQuery) {
12027 TEST_DESCRIPTION("Use an invalid queue index in a vkCmdWaitEvents call."
12028 "End a command buffer with a query still in progress.");
12029
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012030 const char *invalid_queue_index = "was created with sharingMode of VK_SHARING_MODE_EXCLUSIVE. If one "
12031 "of src- or dstQueueFamilyIndex is VK_QUEUE_FAMILY_IGNORED, both "
12032 "must be.";
Mark Mueller2ee294f2016-08-04 12:59:48 -060012033
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012034 const char *invalid_query = "Ending command buffer with in progress query: queryPool 0x";
Mark Mueller2ee294f2016-08-04 12:59:48 -060012035
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012036 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, invalid_queue_index);
Mark Mueller2ee294f2016-08-04 12:59:48 -060012037
12038 ASSERT_NO_FATAL_FAILURE(InitState());
12039
12040 VkEvent event;
12041 VkEventCreateInfo event_create_info{};
12042 event_create_info.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO;
12043 vkCreateEvent(m_device->device(), &event_create_info, nullptr, &event);
12044
Mark Mueller2ee294f2016-08-04 12:59:48 -060012045 VkQueue queue = VK_NULL_HANDLE;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012046 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 0, &queue);
Mark Mueller2ee294f2016-08-04 12:59:48 -060012047
12048 BeginCommandBuffer();
12049
12050 VkImageObj image(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012051 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 -060012052 ASSERT_TRUE(image.initialized());
12053 VkImageMemoryBarrier img_barrier = {};
12054 img_barrier.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
12055 img_barrier.pNext = NULL;
12056 img_barrier.srcAccessMask = VK_ACCESS_HOST_WRITE_BIT;
12057 img_barrier.dstAccessMask = VK_ACCESS_SHADER_READ_BIT;
12058 img_barrier.oldLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
12059 img_barrier.newLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
12060 img_barrier.image = image.handle();
12061 img_barrier.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
Mark Lobodzinski2a74c5c2016-08-17 13:26:28 -060012062
12063 // QueueFamilyIndex must be VK_QUEUE_FAMILY_IGNORED, this verifies
12064 // that layer validation catches the case when it is not.
12065 img_barrier.dstQueueFamilyIndex = 0;
Mark Mueller2ee294f2016-08-04 12:59:48 -060012066 img_barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
12067 img_barrier.subresourceRange.baseArrayLayer = 0;
12068 img_barrier.subresourceRange.baseMipLevel = 0;
12069 img_barrier.subresourceRange.layerCount = 1;
12070 img_barrier.subresourceRange.levelCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012071 vkCmdWaitEvents(m_commandBuffer->handle(), 1, &event, VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0,
12072 nullptr, 0, nullptr, 1, &img_barrier);
Mark Mueller2ee294f2016-08-04 12:59:48 -060012073 m_errorMonitor->VerifyFound();
12074
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012075 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, invalid_query);
Mark Mueller2ee294f2016-08-04 12:59:48 -060012076
12077 VkQueryPool query_pool;
12078 VkQueryPoolCreateInfo query_pool_create_info = {};
12079 query_pool_create_info.sType = VK_STRUCTURE_TYPE_QUERY_POOL_CREATE_INFO;
12080 query_pool_create_info.queryType = VK_QUERY_TYPE_OCCLUSION;
12081 query_pool_create_info.queryCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012082 vkCreateQueryPool(m_device->device(), &query_pool_create_info, nullptr, &query_pool);
Mark Mueller2ee294f2016-08-04 12:59:48 -060012083
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012084 vkCmdResetQueryPool(m_commandBuffer->handle(), query_pool, 0 /*startQuery*/, 1 /*queryCount*/);
Mark Mueller2ee294f2016-08-04 12:59:48 -060012085 vkCmdBeginQuery(m_commandBuffer->handle(), query_pool, 0, 0);
12086
12087 vkEndCommandBuffer(m_commandBuffer->handle());
12088 m_errorMonitor->VerifyFound();
12089
12090 vkDestroyQueryPool(m_device->device(), query_pool, nullptr);
12091 vkDestroyEvent(m_device->device(), event, nullptr);
12092}
12093
Mark Muellerdfe37552016-07-07 14:47:42 -060012094TEST_F(VkLayerTest, VertexBufferInvalid) {
12095 TEST_DESCRIPTION("Submit a command buffer using deleted vertex buffer, "
12096 "delete a buffer twice, use an invalid offset for each "
12097 "buffer type, and attempt to bind a null buffer");
12098
12099 const char *deleted_buffer_in_command_buffer = "Cannot submit cmd buffer "
12100 "using deleted buffer ";
12101 const char *double_destroy_message = "Cannot free buffer 0x";
12102 const char *invalid_offset_message = "vkBindBufferMemory(): "
12103 "memoryOffset is 0x";
12104 const char *invalid_storage_buffer_offset_message = "vkBindBufferMemory(): "
12105 "storage memoryOffset "
12106 "is 0x";
12107 const char *invalid_texel_buffer_offset_message = "vkBindBufferMemory(): "
12108 "texel memoryOffset "
12109 "is 0x";
12110 const char *invalid_uniform_buffer_offset_message = "vkBindBufferMemory(): "
12111 "uniform memoryOffset "
12112 "is 0x";
12113 const char *bind_null_buffer_message = "In vkBindBufferMemory, attempting"
12114 " to Bind Obj(0x";
12115 const char *free_invalid_buffer_message = "Request to delete memory "
12116 "object 0x";
12117
12118 ASSERT_NO_FATAL_FAILURE(InitState());
12119 ASSERT_NO_FATAL_FAILURE(InitViewport());
12120 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12121
12122 VkPipelineMultisampleStateCreateInfo pipe_ms_state_ci = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012123 pipe_ms_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
Mark Muellerdfe37552016-07-07 14:47:42 -060012124 pipe_ms_state_ci.pNext = NULL;
12125 pipe_ms_state_ci.rasterizationSamples = VK_SAMPLE_COUNT_1_BIT;
12126 pipe_ms_state_ci.sampleShadingEnable = 0;
12127 pipe_ms_state_ci.minSampleShading = 1.0;
12128 pipe_ms_state_ci.pSampleMask = nullptr;
12129
12130 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
12131 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
12132 VkPipelineLayout pipeline_layout;
12133
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012134 VkResult err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, nullptr, &pipeline_layout);
Mark Muellerdfe37552016-07-07 14:47:42 -060012135 ASSERT_VK_SUCCESS(err);
12136
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012137 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
12138 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Mark Muellerdfe37552016-07-07 14:47:42 -060012139 VkPipelineObj pipe(m_device);
12140 pipe.AddShader(&vs);
12141 pipe.AddShader(&fs);
12142 pipe.AddColorAttachment();
12143 pipe.SetMSAA(&pipe_ms_state_ci);
12144 pipe.SetViewport(m_viewports);
12145 pipe.SetScissor(m_scissors);
12146 pipe.CreateVKPipeline(pipeline_layout, renderPass());
12147
12148 BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012149 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Mark Muellerdfe37552016-07-07 14:47:42 -060012150
12151 {
12152 // Create and bind a vertex buffer in a reduced scope, which will cause
12153 // it to be deleted upon leaving this scope
12154 const float vbo_data[3] = {1.f, 0.f, 1.f};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012155 VkVerticesObj draw_verticies(m_device, 1, 1, sizeof(vbo_data), 3, vbo_data);
Mark Muellerdfe37552016-07-07 14:47:42 -060012156 draw_verticies.BindVertexBuffers(m_commandBuffer->handle());
12157 draw_verticies.AddVertexInputToPipe(pipe);
12158 }
12159
12160 Draw(1, 0, 0, 0);
12161
12162 EndCommandBuffer();
12163
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012164 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, deleted_buffer_in_command_buffer);
Mark Muellerdfe37552016-07-07 14:47:42 -060012165 QueueCommandBuffer(false);
12166 m_errorMonitor->VerifyFound();
12167
12168 {
12169 // Create and bind a vertex buffer in a reduced scope, and delete it
12170 // twice, the second through the destructor
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012171 VkBufferTest buffer_test(m_device, VK_BUFFER_USAGE_STORAGE_BUFFER_BIT, VkBufferTest::eDoubleDelete);
12172 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, double_destroy_message);
Mark Muellerdfe37552016-07-07 14:47:42 -060012173 buffer_test.TestDoubleDestroy();
12174 }
12175 m_errorMonitor->VerifyFound();
12176
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012177 if (VkBufferTest::GetTestConditionValid(m_device, VkBufferTest::eInvalidMemoryOffset)) {
Mark Muellerdfe37552016-07-07 14:47:42 -060012178 // Create and bind a memory buffer with an invalid offset.
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012179 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, invalid_offset_message);
12180 VkBufferTest buffer_test(m_device, VK_BUFFER_USAGE_UNIFORM_TEXEL_BUFFER_BIT, VkBufferTest::eInvalidMemoryOffset);
12181 (void)buffer_test;
Mark Muellerdfe37552016-07-07 14:47:42 -060012182 m_errorMonitor->VerifyFound();
12183 }
12184
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012185 if (VkBufferTest::GetTestConditionValid(m_device, VkBufferTest::eInvalidDeviceOffset,
12186 VK_BUFFER_USAGE_UNIFORM_TEXEL_BUFFER_BIT)) {
Mark Muellerdfe37552016-07-07 14:47:42 -060012187 // Create and bind a memory buffer with an invalid offset again,
12188 // but look for a texel buffer message.
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012189 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, invalid_texel_buffer_offset_message);
12190 VkBufferTest buffer_test(m_device, VK_BUFFER_USAGE_UNIFORM_TEXEL_BUFFER_BIT, VkBufferTest::eInvalidDeviceOffset);
12191 (void)buffer_test;
Mark Muellerdfe37552016-07-07 14:47:42 -060012192 m_errorMonitor->VerifyFound();
12193 }
12194
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012195 if (VkBufferTest::GetTestConditionValid(m_device, VkBufferTest::eInvalidDeviceOffset, VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT)) {
Mark Muellerdfe37552016-07-07 14:47:42 -060012196 // Create and bind a memory buffer with an invalid offset again, but
12197 // look for a uniform buffer message.
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012198 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, invalid_uniform_buffer_offset_message);
12199 VkBufferTest buffer_test(m_device, VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT, VkBufferTest::eInvalidDeviceOffset);
12200 (void)buffer_test;
Mark Muellerdfe37552016-07-07 14:47:42 -060012201 m_errorMonitor->VerifyFound();
12202 }
12203
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012204 if (VkBufferTest::GetTestConditionValid(m_device, VkBufferTest::eInvalidDeviceOffset, VK_BUFFER_USAGE_STORAGE_BUFFER_BIT)) {
Mark Muellerdfe37552016-07-07 14:47:42 -060012205 // Create and bind a memory buffer with an invalid offset again, but
12206 // look for a storage buffer message.
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012207 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, invalid_storage_buffer_offset_message);
12208 VkBufferTest buffer_test(m_device, VK_BUFFER_USAGE_STORAGE_BUFFER_BIT, VkBufferTest::eInvalidDeviceOffset);
12209 (void)buffer_test;
Mark Muellerdfe37552016-07-07 14:47:42 -060012210 m_errorMonitor->VerifyFound();
12211 }
12212
12213 {
12214 // Attempt to bind a null buffer.
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012215 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, bind_null_buffer_message);
12216 VkBufferTest buffer_test(m_device, VK_BUFFER_USAGE_STORAGE_BUFFER_BIT, VkBufferTest::eBindNullBuffer);
12217 (void)buffer_test;
Mark Muellerdfe37552016-07-07 14:47:42 -060012218 m_errorMonitor->VerifyFound();
12219 }
12220
12221 {
12222 // Attempt to use an invalid handle to delete a buffer.
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012223 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, free_invalid_buffer_message);
12224 VkBufferTest buffer_test(m_device, VK_BUFFER_USAGE_STORAGE_BUFFER_BIT, VkBufferTest::eFreeInvalidHandle);
12225 (void)buffer_test;
Mark Muellerdfe37552016-07-07 14:47:42 -060012226 }
12227 m_errorMonitor->VerifyFound();
12228
12229 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
12230}
12231
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060012232// INVALID_IMAGE_LAYOUT tests (one other case is hit by MapMemWithoutHostVisibleBit and not here)
12233TEST_F(VkLayerTest, InvalidImageLayout) {
12234 TEST_DESCRIPTION("Hit all possible validation checks associated with the "
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012235 "DRAWSTATE_INVALID_IMAGE_LAYOUT enum. Generally these involve having"
12236 "images in the wrong layout when they're copied or transitioned.");
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060012237 // 3 in ValidateCmdBufImageLayouts
12238 // * -1 Attempt to submit cmd buf w/ deleted image
12239 // * -2 Cmd buf submit of image w/ layout not matching first use w/ subresource
12240 // * -3 Cmd buf submit of image w/ layout not matching first use w/o subresource
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012241 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
12242 "Layout for input image should be TRANSFER_SRC_OPTIMAL instead of GENERAL.");
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060012243
12244 ASSERT_NO_FATAL_FAILURE(InitState());
12245 // Create src & dst images to use for copy operations
12246 VkImage src_image;
12247 VkImage dst_image;
12248
12249 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
12250 const int32_t tex_width = 32;
12251 const int32_t tex_height = 32;
12252
12253 VkImageCreateInfo image_create_info = {};
12254 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
12255 image_create_info.pNext = NULL;
12256 image_create_info.imageType = VK_IMAGE_TYPE_2D;
12257 image_create_info.format = tex_format;
12258 image_create_info.extent.width = tex_width;
12259 image_create_info.extent.height = tex_height;
12260 image_create_info.extent.depth = 1;
12261 image_create_info.mipLevels = 1;
12262 image_create_info.arrayLayers = 4;
12263 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
12264 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
12265 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
12266 image_create_info.flags = 0;
12267
12268 VkResult err = vkCreateImage(m_device->device(), &image_create_info, NULL, &src_image);
12269 ASSERT_VK_SUCCESS(err);
12270 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &dst_image);
12271 ASSERT_VK_SUCCESS(err);
12272
12273 BeginCommandBuffer();
12274 VkImageCopy copyRegion;
12275 copyRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
12276 copyRegion.srcSubresource.mipLevel = 0;
12277 copyRegion.srcSubresource.baseArrayLayer = 0;
12278 copyRegion.srcSubresource.layerCount = 1;
12279 copyRegion.srcOffset.x = 0;
12280 copyRegion.srcOffset.y = 0;
12281 copyRegion.srcOffset.z = 0;
12282 copyRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
12283 copyRegion.dstSubresource.mipLevel = 0;
12284 copyRegion.dstSubresource.baseArrayLayer = 0;
12285 copyRegion.dstSubresource.layerCount = 1;
12286 copyRegion.dstOffset.x = 0;
12287 copyRegion.dstOffset.y = 0;
12288 copyRegion.dstOffset.z = 0;
12289 copyRegion.extent.width = 1;
12290 copyRegion.extent.height = 1;
12291 copyRegion.extent.depth = 1;
12292 m_commandBuffer->CopyImage(src_image, VK_IMAGE_LAYOUT_GENERAL, dst_image, VK_IMAGE_LAYOUT_GENERAL, 1, &copyRegion);
12293 m_errorMonitor->VerifyFound();
12294 // Now cause error due to src image layout changing
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012295 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Cannot copy from an image whose source layout is "
12296 "VK_IMAGE_LAYOUT_UNDEFINED and doesn't match the current "
12297 "layout VK_IMAGE_LAYOUT_GENERAL.");
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060012298 m_commandBuffer->CopyImage(src_image, VK_IMAGE_LAYOUT_UNDEFINED, dst_image, VK_IMAGE_LAYOUT_GENERAL, 1, &copyRegion);
12299 m_errorMonitor->VerifyFound();
12300 // Final src error is due to bad layout type
12301 m_errorMonitor->SetDesiredFailureMsg(
12302 VK_DEBUG_REPORT_ERROR_BIT_EXT,
12303 "Layout for input image is VK_IMAGE_LAYOUT_UNDEFINED but can only be TRANSFER_SRC_OPTIMAL or GENERAL.");
12304 m_commandBuffer->CopyImage(src_image, VK_IMAGE_LAYOUT_UNDEFINED, dst_image, VK_IMAGE_LAYOUT_GENERAL, 1, &copyRegion);
12305 m_errorMonitor->VerifyFound();
12306 // Now verify same checks for dst
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012307 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
12308 "Layout for output image should be TRANSFER_DST_OPTIMAL instead of GENERAL.");
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060012309 m_commandBuffer->CopyImage(src_image, VK_IMAGE_LAYOUT_GENERAL, dst_image, VK_IMAGE_LAYOUT_GENERAL, 1, &copyRegion);
12310 m_errorMonitor->VerifyFound();
12311 // Now cause error due to src image layout changing
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012312 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Cannot copy from an image whose dest layout is "
12313 "VK_IMAGE_LAYOUT_UNDEFINED and doesn't match the current "
12314 "layout VK_IMAGE_LAYOUT_GENERAL.");
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060012315 m_commandBuffer->CopyImage(src_image, VK_IMAGE_LAYOUT_GENERAL, dst_image, VK_IMAGE_LAYOUT_UNDEFINED, 1, &copyRegion);
12316 m_errorMonitor->VerifyFound();
12317 m_errorMonitor->SetDesiredFailureMsg(
12318 VK_DEBUG_REPORT_ERROR_BIT_EXT,
12319 "Layout for output image is VK_IMAGE_LAYOUT_UNDEFINED but can only be TRANSFER_DST_OPTIMAL or GENERAL.");
12320 m_commandBuffer->CopyImage(src_image, VK_IMAGE_LAYOUT_GENERAL, dst_image, VK_IMAGE_LAYOUT_UNDEFINED, 1, &copyRegion);
12321 m_errorMonitor->VerifyFound();
12322 // Now cause error due to bad image layout transition in PipelineBarrier
12323 VkImageMemoryBarrier image_barrier[1] = {};
12324 image_barrier[0].oldLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL;
12325 image_barrier[0].image = src_image;
12326 image_barrier[0].subresourceRange.layerCount = 2;
12327 image_barrier[0].subresourceRange.levelCount = 2;
12328 image_barrier[0].subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012329 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "You cannot transition the layout from "
12330 "VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL when "
12331 "current layout is VK_IMAGE_LAYOUT_GENERAL.");
12332 vkCmdPipelineBarrier(m_commandBuffer->handle(), VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0,
12333 NULL, 0, NULL, 1, image_barrier);
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060012334 m_errorMonitor->VerifyFound();
12335
12336 // Finally some layout errors at RenderPass create time
12337 // Just hacking in specific state to get to the errors we want so don't copy this unless you know what you're doing.
12338 VkAttachmentReference attach = {};
12339 // perf warning for GENERAL layout w/ non-DS input attachment
12340 attach.layout = VK_IMAGE_LAYOUT_GENERAL;
12341 VkSubpassDescription subpass = {};
12342 subpass.inputAttachmentCount = 1;
12343 subpass.pInputAttachments = &attach;
12344 VkRenderPassCreateInfo rpci = {};
12345 rpci.subpassCount = 1;
12346 rpci.pSubpasses = &subpass;
12347 rpci.attachmentCount = 1;
12348 VkAttachmentDescription attach_desc = {};
12349 attach_desc.format = VK_FORMAT_UNDEFINED;
12350 rpci.pAttachments = &attach_desc;
Tobin Ehlis1efce022016-05-11 10:40:34 -060012351 rpci.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060012352 VkRenderPass rp;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012353 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
12354 "Layout for input attachment is GENERAL but should be READ_ONLY_OPTIMAL.");
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060012355 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
12356 m_errorMonitor->VerifyFound();
12357 // error w/ non-general layout
12358 attach.layout = VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL;
12359
12360 m_errorMonitor->SetDesiredFailureMsg(
12361 VK_DEBUG_REPORT_ERROR_BIT_EXT,
12362 "Layout for input attachment is VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL but can only be READ_ONLY_OPTIMAL or GENERAL.");
12363 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
12364 m_errorMonitor->VerifyFound();
12365 subpass.inputAttachmentCount = 0;
12366 subpass.colorAttachmentCount = 1;
12367 subpass.pColorAttachments = &attach;
12368 attach.layout = VK_IMAGE_LAYOUT_GENERAL;
12369 // perf warning for GENERAL layout on color attachment
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012370 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
12371 "Layout for color attachment is GENERAL but should be COLOR_ATTACHMENT_OPTIMAL.");
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060012372 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
12373 m_errorMonitor->VerifyFound();
12374 // error w/ non-color opt or GENERAL layout for color attachment
12375 attach.layout = VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL;
12376 m_errorMonitor->SetDesiredFailureMsg(
12377 VK_DEBUG_REPORT_ERROR_BIT_EXT,
12378 "Layout for color attachment is VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL but can only be COLOR_ATTACHMENT_OPTIMAL or GENERAL.");
12379 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
12380 m_errorMonitor->VerifyFound();
12381 subpass.colorAttachmentCount = 0;
12382 subpass.pDepthStencilAttachment = &attach;
12383 attach.layout = VK_IMAGE_LAYOUT_GENERAL;
12384 // perf warning for GENERAL layout on DS attachment
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012385 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
12386 "GENERAL layout for depth attachment may not give optimal performance.");
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060012387 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
12388 m_errorMonitor->VerifyFound();
12389 // error w/ non-ds opt or GENERAL layout for color attachment
12390 attach.layout = VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012391 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
12392 "Layout for depth attachment is VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL but can only be "
12393 "DEPTH_STENCIL_ATTACHMENT_OPTIMAL, DEPTH_STENCIL_READ_ONLY_OPTIMAL or GENERAL.");
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060012394 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
12395 m_errorMonitor->VerifyFound();
Tobin Ehlis1efce022016-05-11 10:40:34 -060012396 // For this error we need a valid renderpass so create default one
12397 attach.layout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL;
12398 attach.attachment = 0;
12399 attach_desc.format = VK_FORMAT_D24_UNORM_S8_UINT;
12400 attach_desc.samples = VK_SAMPLE_COUNT_1_BIT;
12401 attach_desc.storeOp = VK_ATTACHMENT_STORE_OP_STORE;
12402 attach_desc.stencilLoadOp = VK_ATTACHMENT_LOAD_OP_DONT_CARE;
12403 attach_desc.stencilStoreOp = VK_ATTACHMENT_STORE_OP_DONT_CARE;
12404 // Can't do a CLEAR load on READ_ONLY initialLayout
12405 attach_desc.loadOp = VK_ATTACHMENT_LOAD_OP_CLEAR;
12406 attach_desc.initialLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL;
12407 attach_desc.finalLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012408 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " with invalid first layout "
12409 "VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_"
12410 "ONLY_OPTIMAL");
Tobin Ehlis1efce022016-05-11 10:40:34 -060012411 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
12412 m_errorMonitor->VerifyFound();
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060012413
12414 vkDestroyImage(m_device->device(), src_image, NULL);
12415 vkDestroyImage(m_device->device(), dst_image, NULL);
12416}
Tobin Ehlisd8d89182016-07-18 20:13:11 -060012417
12418TEST_F(VkLayerTest, ValidRenderPassAttachmentLayoutWithLoadOp) {
12419 TEST_DESCRIPTION("Positive test where we create a renderpass with an "
12420 "attachment that uses LOAD_OP_CLEAR, the first subpass "
12421 "has a valid layout, and a second subpass then uses a "
12422 "valid *READ_ONLY* layout.");
12423 m_errorMonitor->ExpectSuccess();
12424 ASSERT_NO_FATAL_FAILURE(InitState());
12425
12426 VkAttachmentReference attach[2] = {};
12427 attach[0].attachment = 0;
12428 attach[0].layout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
12429 attach[1].attachment = 0;
12430 attach[1].layout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL;
12431 VkSubpassDescription subpasses[2] = {};
12432 // First subpass clears DS attach on load
12433 subpasses[0].pDepthStencilAttachment = &attach[0];
12434 // 2nd subpass reads in DS as input attachment
12435 subpasses[1].inputAttachmentCount = 1;
12436 subpasses[1].pInputAttachments = &attach[1];
12437 VkAttachmentDescription attach_desc = {};
12438 attach_desc.format = VK_FORMAT_D24_UNORM_S8_UINT;
12439 attach_desc.samples = VK_SAMPLE_COUNT_1_BIT;
12440 attach_desc.storeOp = VK_ATTACHMENT_STORE_OP_STORE;
12441 attach_desc.stencilStoreOp = VK_ATTACHMENT_STORE_OP_DONT_CARE;
12442 attach_desc.loadOp = VK_ATTACHMENT_LOAD_OP_CLEAR;
12443 attach_desc.stencilLoadOp = VK_ATTACHMENT_LOAD_OP_CLEAR;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012444 attach_desc.initialLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
Tobin Ehlisd8d89182016-07-18 20:13:11 -060012445 attach_desc.finalLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL;
12446 VkRenderPassCreateInfo rpci = {};
12447 rpci.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
12448 rpci.attachmentCount = 1;
12449 rpci.pAttachments = &attach_desc;
12450 rpci.subpassCount = 2;
12451 rpci.pSubpasses = subpasses;
12452
12453 // Now create RenderPass and verify no errors
12454 VkRenderPass rp;
12455 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
12456 m_errorMonitor->VerifyNotFound();
12457
12458 vkDestroyRenderPass(m_device->device(), rp, NULL);
12459}
Tobin Ehlis4af23302016-07-19 10:50:30 -060012460
Mark Mueller93b938f2016-08-18 10:27:40 -060012461TEST_F(VkLayerTest, SimultaneousUse) {
12462 TEST_DESCRIPTION("Use vkCmdExecuteCommands with invalid state "
12463 "in primary and secondary command buffers.");
12464
12465 ASSERT_NO_FATAL_FAILURE(InitState());
12466 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12467
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012468 const char *simultaneous_use_message1 = "w/o VK_COMMAND_BUFFER_USAGE_SIMULTANEOUS_USE_BIT set!";
12469 const char *simultaneous_use_message2 = "does not have VK_COMMAND_BUFFER_USAGE_SIMULTANEOUS_USE_BIT set and "
12470 "will cause primary command buffer";
Mark Mueller93b938f2016-08-18 10:27:40 -060012471
12472 VkCommandBufferAllocateInfo command_buffer_allocate_info = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012473 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
Mark Mueller93b938f2016-08-18 10:27:40 -060012474 command_buffer_allocate_info.commandPool = m_commandPool;
12475 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_SECONDARY;
12476 command_buffer_allocate_info.commandBufferCount = 1;
12477
12478 VkCommandBuffer secondary_command_buffer;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012479 ASSERT_VK_SUCCESS(vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, &secondary_command_buffer));
Mark Mueller93b938f2016-08-18 10:27:40 -060012480 VkCommandBufferBeginInfo command_buffer_begin_info = {};
12481 VkCommandBufferInheritanceInfo command_buffer_inheritance_info = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012482 command_buffer_inheritance_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_INHERITANCE_INFO;
Mark Mueller93b938f2016-08-18 10:27:40 -060012483 command_buffer_inheritance_info.renderPass = m_renderPass;
12484 command_buffer_inheritance_info.framebuffer = m_framebuffer;
12485 command_buffer_begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012486 command_buffer_begin_info.flags =
12487 VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT | VK_COMMAND_BUFFER_USAGE_RENDER_PASS_CONTINUE_BIT;
Mark Mueller93b938f2016-08-18 10:27:40 -060012488 command_buffer_begin_info.pInheritanceInfo = &command_buffer_inheritance_info;
12489
12490 vkBeginCommandBuffer(secondary_command_buffer, &command_buffer_begin_info);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012491 vkCmdBeginRenderPass(m_commandBuffer->handle(), &renderPassBeginInfo(), VK_SUBPASS_CONTENTS_SECONDARY_COMMAND_BUFFERS);
12492 vkCmdExecuteCommands(m_commandBuffer->handle(), 1, &secondary_command_buffer);
Mark Mueller4042b652016-09-05 22:52:21 -060012493 vkCmdEndRenderPass(m_commandBuffer->GetBufferHandle());
Mark Mueller93b938f2016-08-18 10:27:40 -060012494 vkEndCommandBuffer(secondary_command_buffer);
12495
Mark Mueller93b938f2016-08-18 10:27:40 -060012496 VkSubmitInfo submit_info = {};
12497 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
12498 submit_info.commandBufferCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012499 submit_info.pCommandBuffers = &m_commandBuffer->handle();
Mark Mueller4042b652016-09-05 22:52:21 -060012500 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
Mark Mueller93b938f2016-08-18 10:27:40 -060012501
Mark Mueller4042b652016-09-05 22:52:21 -060012502 vkBeginCommandBuffer(m_commandBuffer->handle(), &command_buffer_begin_info);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012503 vkCmdBeginRenderPass(m_commandBuffer->handle(), &renderPassBeginInfo(), VK_SUBPASS_CONTENTS_SECONDARY_COMMAND_BUFFERS);
12504 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, simultaneous_use_message1);
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 m_errorMonitor->SetDesiredFailureMsg(0, "");
Mark Mueller93b938f2016-08-18 10:27:40 -060012511 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
12512
Mark Mueller4042b652016-09-05 22:52:21 -060012513 command_buffer_begin_info.flags = VK_COMMAND_BUFFER_USAGE_SIMULTANEOUS_USE_BIT;
Mark Mueller93b938f2016-08-18 10:27:40 -060012514 vkBeginCommandBuffer(m_commandBuffer->handle(), &command_buffer_begin_info);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012515 vkCmdBeginRenderPass(m_commandBuffer->handle(), &renderPassBeginInfo(), VK_SUBPASS_CONTENTS_SECONDARY_COMMAND_BUFFERS);
Mark Mueller4042b652016-09-05 22:52:21 -060012516
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012517 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT, simultaneous_use_message2);
12518 vkCmdExecuteCommands(m_commandBuffer->handle(), 1, &secondary_command_buffer);
Mark Mueller93b938f2016-08-18 10:27:40 -060012519 m_errorMonitor->VerifyFound();
Mark Mueller4042b652016-09-05 22:52:21 -060012520 vkCmdEndRenderPass(m_commandBuffer->GetBufferHandle());
12521 vkEndCommandBuffer(m_commandBuffer->handle());
Mark Mueller93b938f2016-08-18 10:27:40 -060012522}
12523
Mark Mueller917f6bc2016-08-30 10:57:19 -060012524TEST_F(VkLayerTest, InUseDestroyedSignaled) {
12525 TEST_DESCRIPTION("Use vkCmdExecuteCommands with invalid state "
12526 "in primary and secondary command buffers. "
Mark Muellerc8d441e2016-08-23 17:36:00 -060012527 "Delete objects that are inuse. Call VkQueueSubmit "
12528 "with an event that has been deleted.");
Mark Mueller917f6bc2016-08-30 10:57:19 -060012529
12530 ASSERT_NO_FATAL_FAILURE(InitState());
12531 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12532
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012533 const char *submit_with_deleted_event_message = "Cannot submit cmd buffer using deleted event 0x";
12534 const char *cannot_delete_event_message = "Cannot delete event 0x";
12535 const char *cannot_delete_semaphore_message = "Cannot delete semaphore 0x";
12536 const char *cannot_destroy_fence_message = "Fence 0x";
Mark Mueller917f6bc2016-08-30 10:57:19 -060012537
12538 BeginCommandBuffer();
12539
12540 VkEvent event;
12541 VkEventCreateInfo event_create_info = {};
12542 event_create_info.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO;
12543 vkCreateEvent(m_device->device(), &event_create_info, nullptr, &event);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012544 vkCmdSetEvent(m_commandBuffer->handle(), event, VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT);
Mark Mueller917f6bc2016-08-30 10:57:19 -060012545
Mark Muellerc8d441e2016-08-23 17:36:00 -060012546 EndCommandBuffer();
12547 vkDestroyEvent(m_device->device(), event, nullptr);
12548
12549 VkSubmitInfo submit_info = {};
12550 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
12551 submit_info.commandBufferCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012552 submit_info.pCommandBuffers = &m_commandBuffer->handle();
12553 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, submit_with_deleted_event_message);
Mark Muellerc8d441e2016-08-23 17:36:00 -060012554 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
12555 m_errorMonitor->VerifyFound();
12556
12557 m_errorMonitor->SetDesiredFailureMsg(0, "");
12558 vkResetCommandBuffer(m_commandBuffer->handle(), 0);
12559
12560 vkCreateEvent(m_device->device(), &event_create_info, nullptr, &event);
12561
Mark Mueller917f6bc2016-08-30 10:57:19 -060012562 VkSemaphoreCreateInfo semaphore_create_info = {};
12563 semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
12564 VkSemaphore semaphore;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012565 ASSERT_VK_SUCCESS(vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr, &semaphore));
Mark Mueller917f6bc2016-08-30 10:57:19 -060012566 VkFenceCreateInfo fence_create_info = {};
12567 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
12568 VkFence fence;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012569 ASSERT_VK_SUCCESS(vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence));
Mark Mueller917f6bc2016-08-30 10:57:19 -060012570
12571 VkDescriptorPoolSize descriptor_pool_type_count = {};
Mark Mueller4042b652016-09-05 22:52:21 -060012572 descriptor_pool_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Mark Mueller917f6bc2016-08-30 10:57:19 -060012573 descriptor_pool_type_count.descriptorCount = 1;
12574
12575 VkDescriptorPoolCreateInfo descriptor_pool_create_info = {};
12576 descriptor_pool_create_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
12577 descriptor_pool_create_info.maxSets = 1;
12578 descriptor_pool_create_info.poolSizeCount = 1;
12579 descriptor_pool_create_info.pPoolSizes = &descriptor_pool_type_count;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012580 descriptor_pool_create_info.flags = VK_DESCRIPTOR_POOL_CREATE_FREE_DESCRIPTOR_SET_BIT;
Mark Mueller917f6bc2016-08-30 10:57:19 -060012581
12582 VkDescriptorPool descriptorset_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012583 ASSERT_VK_SUCCESS(vkCreateDescriptorPool(m_device->device(), &descriptor_pool_create_info, nullptr, &descriptorset_pool));
Mark Mueller917f6bc2016-08-30 10:57:19 -060012584
12585 VkDescriptorSetLayoutBinding descriptorset_layout_binding = {};
Mark Mueller4042b652016-09-05 22:52:21 -060012586 descriptorset_layout_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Mark Mueller917f6bc2016-08-30 10:57:19 -060012587 descriptorset_layout_binding.descriptorCount = 1;
12588 descriptorset_layout_binding.stageFlags = VK_SHADER_STAGE_ALL;
12589
12590 VkDescriptorSetLayoutCreateInfo descriptorset_layout_create_info = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012591 descriptorset_layout_create_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
Mark Mueller917f6bc2016-08-30 10:57:19 -060012592 descriptorset_layout_create_info.bindingCount = 1;
12593 descriptorset_layout_create_info.pBindings = &descriptorset_layout_binding;
12594
12595 VkDescriptorSetLayout descriptorset_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012596 ASSERT_VK_SUCCESS(
12597 vkCreateDescriptorSetLayout(m_device->device(), &descriptorset_layout_create_info, nullptr, &descriptorset_layout));
Mark Mueller917f6bc2016-08-30 10:57:19 -060012598
12599 VkDescriptorSet descriptorset;
12600 VkDescriptorSetAllocateInfo descriptorset_allocate_info = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012601 descriptorset_allocate_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Mark Mueller917f6bc2016-08-30 10:57:19 -060012602 descriptorset_allocate_info.descriptorSetCount = 1;
12603 descriptorset_allocate_info.descriptorPool = descriptorset_pool;
12604 descriptorset_allocate_info.pSetLayouts = &descriptorset_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012605 ASSERT_VK_SUCCESS(vkAllocateDescriptorSets(m_device->device(), &descriptorset_allocate_info, &descriptorset));
Mark Mueller917f6bc2016-08-30 10:57:19 -060012606
Mark Mueller4042b652016-09-05 22:52:21 -060012607 VkBufferTest buffer_test(m_device, VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT);
12608
12609 VkDescriptorBufferInfo buffer_info = {};
12610 buffer_info.buffer = buffer_test.GetBuffer();
12611 buffer_info.offset = 0;
12612 buffer_info.range = 1024;
12613
12614 VkWriteDescriptorSet write_descriptor_set = {};
12615 write_descriptor_set.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
12616 write_descriptor_set.dstSet = descriptorset;
12617 write_descriptor_set.descriptorCount = 1;
12618 write_descriptor_set.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
12619 write_descriptor_set.pBufferInfo = &buffer_info;
12620
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012621 vkUpdateDescriptorSets(m_device->device(), 1, &write_descriptor_set, 0, nullptr);
Mark Mueller4042b652016-09-05 22:52:21 -060012622
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012623 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
12624 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Mark Mueller917f6bc2016-08-30 10:57:19 -060012625
12626 VkPipelineObj pipe(m_device);
12627 pipe.AddColorAttachment();
12628 pipe.AddShader(&vs);
12629 pipe.AddShader(&fs);
12630
12631 VkPipelineLayoutCreateInfo pipeline_layout_create_info = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012632 pipeline_layout_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
Mark Mueller917f6bc2016-08-30 10:57:19 -060012633 pipeline_layout_create_info.setLayoutCount = 1;
12634 pipeline_layout_create_info.pSetLayouts = &descriptorset_layout;
12635
12636 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012637 ASSERT_VK_SUCCESS(vkCreatePipelineLayout(m_device->device(), &pipeline_layout_create_info, nullptr, &pipeline_layout));
Mark Mueller917f6bc2016-08-30 10:57:19 -060012638
12639 pipe.CreateVKPipeline(pipeline_layout, m_renderPass);
12640
Mark Muellerc8d441e2016-08-23 17:36:00 -060012641 BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012642 vkCmdSetEvent(m_commandBuffer->handle(), event, VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT);
Mark Muellerc8d441e2016-08-23 17:36:00 -060012643
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012644 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
12645 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
12646 &descriptorset, 0, NULL);
Mark Mueller917f6bc2016-08-30 10:57:19 -060012647
Mark Muellerc8d441e2016-08-23 17:36:00 -060012648 EndCommandBuffer();
Mark Mueller917f6bc2016-08-30 10:57:19 -060012649
Mark Mueller917f6bc2016-08-30 10:57:19 -060012650 submit_info.signalSemaphoreCount = 1;
12651 submit_info.pSignalSemaphores = &semaphore;
12652 vkQueueSubmit(m_device->m_queue, 1, &submit_info, fence);
Mark Muellerc8d441e2016-08-23 17:36:00 -060012653
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012654 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, cannot_delete_event_message);
Mark Mueller917f6bc2016-08-30 10:57:19 -060012655 vkDestroyEvent(m_device->device(), event, nullptr);
12656 m_errorMonitor->VerifyFound();
12657
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012658 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, cannot_delete_semaphore_message);
Mark Mueller917f6bc2016-08-30 10:57:19 -060012659 vkDestroySemaphore(m_device->device(), semaphore, nullptr);
12660 m_errorMonitor->VerifyFound();
12661
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012662 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, cannot_destroy_fence_message);
Mark Mueller917f6bc2016-08-30 10:57:19 -060012663 vkDestroyFence(m_device->device(), fence, nullptr);
12664 m_errorMonitor->VerifyFound();
12665
Tobin Ehlis122207b2016-09-01 08:50:06 -070012666 vkQueueWaitIdle(m_device->m_queue);
Mark Mueller917f6bc2016-08-30 10:57:19 -060012667 vkDestroySemaphore(m_device->device(), semaphore, nullptr);
12668 vkDestroyFence(m_device->device(), fence, nullptr);
12669 vkDestroyEvent(m_device->device(), event, nullptr);
12670 vkDestroyDescriptorPool(m_device->device(), descriptorset_pool, nullptr);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012671 vkDestroyDescriptorSetLayout(m_device->device(), descriptorset_layout, nullptr);
Mark Mueller917f6bc2016-08-30 10:57:19 -060012672 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, nullptr);
12673}
12674
Tobin Ehlis2adda372016-09-01 08:51:06 -070012675TEST_F(VkLayerTest, QueryPoolInUseDestroyedSignaled) {
12676 TEST_DESCRIPTION("Delete in-use query pool.");
12677
12678 ASSERT_NO_FATAL_FAILURE(InitState());
12679 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12680
12681 VkQueryPool query_pool;
12682 VkQueryPoolCreateInfo query_pool_ci{};
12683 query_pool_ci.sType = VK_STRUCTURE_TYPE_QUERY_POOL_CREATE_INFO;
12684 query_pool_ci.queryType = VK_QUERY_TYPE_TIMESTAMP;
12685 query_pool_ci.queryCount = 1;
12686 vkCreateQueryPool(m_device->device(), &query_pool_ci, nullptr, &query_pool);
12687 BeginCommandBuffer();
12688 // Reset query pool to create binding with cmd buffer
12689 vkCmdResetQueryPool(m_commandBuffer->handle(), query_pool, 0, 1);
12690
12691 EndCommandBuffer();
12692
12693 VkSubmitInfo submit_info = {};
12694 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
12695 submit_info.commandBufferCount = 1;
12696 submit_info.pCommandBuffers = &m_commandBuffer->handle();
12697 // Submit cmd buffer and then destroy query pool while in-flight
12698 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
12699
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012700 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Cannot delete query pool 0x");
Tobin Ehlis2adda372016-09-01 08:51:06 -070012701 vkDestroyQueryPool(m_device->handle(), query_pool, NULL);
12702 m_errorMonitor->VerifyFound();
12703
12704 vkQueueWaitIdle(m_device->m_queue);
12705 // Now that cmd buffer done we can safely destroy query_pool
12706 vkDestroyQueryPool(m_device->handle(), query_pool, NULL);
12707}
12708
Tobin Ehlisfafab2d2016-09-07 13:51:24 -060012709TEST_F(VkLayerTest, PipelineInUseDestroyedSignaled) {
12710 TEST_DESCRIPTION("Delete in-use pipeline.");
12711
12712 ASSERT_NO_FATAL_FAILURE(InitState());
12713 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12714
12715 // Empty pipeline layout used for binding PSO
12716 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
12717 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
12718 pipeline_layout_ci.setLayoutCount = 0;
12719 pipeline_layout_ci.pSetLayouts = NULL;
12720
12721 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012722 VkResult err = vkCreatePipelineLayout(m_device->handle(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlisfafab2d2016-09-07 13:51:24 -060012723 ASSERT_VK_SUCCESS(err);
12724
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012725 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Cannot delete pipeline 0x");
Tobin Ehlisfafab2d2016-09-07 13:51:24 -060012726 // Create PSO to be used for draw-time errors below
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012727 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
12728 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Tobin Ehlisfafab2d2016-09-07 13:51:24 -060012729 // Store pipeline handle so we can actually delete it before test finishes
12730 VkPipeline delete_this_pipeline;
12731 { // Scope pipeline so it will be auto-deleted
12732 VkPipelineObj pipe(m_device);
12733 pipe.AddShader(&vs);
12734 pipe.AddShader(&fs);
12735 pipe.AddColorAttachment();
12736 pipe.CreateVKPipeline(pipeline_layout, renderPass());
12737 delete_this_pipeline = pipe.handle();
12738
12739 BeginCommandBuffer();
12740 // Bind pipeline to cmd buffer
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012741 vkCmdBindPipeline(m_commandBuffer->handle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Tobin Ehlisfafab2d2016-09-07 13:51:24 -060012742
12743 EndCommandBuffer();
12744
12745 VkSubmitInfo submit_info = {};
12746 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
12747 submit_info.commandBufferCount = 1;
12748 submit_info.pCommandBuffers = &m_commandBuffer->handle();
12749 // Submit cmd buffer and then pipeline destroyed while in-flight
12750 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
12751 } // Pipeline deletion triggered here
12752 m_errorMonitor->VerifyFound();
12753 // Make sure queue finished and then actually delete pipeline
12754 vkQueueWaitIdle(m_device->m_queue);
12755 vkDestroyPipeline(m_device->handle(), delete_this_pipeline, nullptr);
12756 vkDestroyPipelineLayout(m_device->handle(), pipeline_layout, nullptr);
12757}
12758
Tobin Ehlis209532e2016-09-07 13:52:18 -060012759TEST_F(VkLayerTest, SamplerInUseDestroyedSignaled) {
12760 TEST_DESCRIPTION("Delete in-use sampler.");
12761
12762 ASSERT_NO_FATAL_FAILURE(InitState());
12763 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12764
12765 VkDescriptorPoolSize ds_type_count;
12766 ds_type_count.type = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
12767 ds_type_count.descriptorCount = 1;
12768
12769 VkDescriptorPoolCreateInfo ds_pool_ci = {};
12770 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
12771 ds_pool_ci.maxSets = 1;
12772 ds_pool_ci.poolSizeCount = 1;
12773 ds_pool_ci.pPoolSizes = &ds_type_count;
12774
12775 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012776 VkResult err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis209532e2016-09-07 13:52:18 -060012777 ASSERT_VK_SUCCESS(err);
12778
12779 VkSamplerCreateInfo sampler_ci = {};
12780 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
12781 sampler_ci.pNext = NULL;
12782 sampler_ci.magFilter = VK_FILTER_NEAREST;
12783 sampler_ci.minFilter = VK_FILTER_NEAREST;
12784 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
12785 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
12786 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
12787 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
12788 sampler_ci.mipLodBias = 1.0;
12789 sampler_ci.anisotropyEnable = VK_FALSE;
12790 sampler_ci.maxAnisotropy = 1;
12791 sampler_ci.compareEnable = VK_FALSE;
12792 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
12793 sampler_ci.minLod = 1.0;
12794 sampler_ci.maxLod = 1.0;
12795 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
12796 sampler_ci.unnormalizedCoordinates = VK_FALSE;
12797 VkSampler sampler;
12798
12799 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
12800 ASSERT_VK_SUCCESS(err);
12801
12802 VkDescriptorSetLayoutBinding layout_binding;
12803 layout_binding.binding = 0;
12804 layout_binding.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
12805 layout_binding.descriptorCount = 1;
12806 layout_binding.stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
12807 layout_binding.pImmutableSamplers = NULL;
12808
12809 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
12810 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
12811 ds_layout_ci.bindingCount = 1;
12812 ds_layout_ci.pBindings = &layout_binding;
12813 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012814 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis209532e2016-09-07 13:52:18 -060012815 ASSERT_VK_SUCCESS(err);
12816
12817 VkDescriptorSetAllocateInfo alloc_info = {};
12818 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
12819 alloc_info.descriptorSetCount = 1;
12820 alloc_info.descriptorPool = ds_pool;
12821 alloc_info.pSetLayouts = &ds_layout;
12822 VkDescriptorSet descriptor_set;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012823 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
Tobin Ehlis209532e2016-09-07 13:52:18 -060012824 ASSERT_VK_SUCCESS(err);
12825
12826 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
12827 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
12828 pipeline_layout_ci.pNext = NULL;
12829 pipeline_layout_ci.setLayoutCount = 1;
12830 pipeline_layout_ci.pSetLayouts = &ds_layout;
12831
12832 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012833 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis209532e2016-09-07 13:52:18 -060012834 ASSERT_VK_SUCCESS(err);
12835
12836 VkImageObj image(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012837 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 -060012838 ASSERT_TRUE(image.initialized());
12839
12840 VkImageView view;
12841 VkImageViewCreateInfo ivci = {};
12842 ivci.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
12843 ivci.image = image.handle();
12844 ivci.viewType = VK_IMAGE_VIEW_TYPE_2D;
12845 ivci.format = VK_FORMAT_R8G8B8A8_UNORM;
12846 ivci.subresourceRange.layerCount = 1;
12847 ivci.subresourceRange.baseMipLevel = 0;
12848 ivci.subresourceRange.levelCount = 1;
12849 ivci.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
12850
12851 err = vkCreateImageView(m_device->device(), &ivci, NULL, &view);
12852 ASSERT_VK_SUCCESS(err);
12853
12854 VkDescriptorImageInfo image_info{};
12855 image_info.imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
12856 image_info.imageView = view;
12857 image_info.sampler = sampler;
12858
12859 VkWriteDescriptorSet descriptor_write = {};
12860 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
12861 descriptor_write.dstSet = descriptor_set;
12862 descriptor_write.dstBinding = 0;
12863 descriptor_write.descriptorCount = 1;
12864 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
12865 descriptor_write.pImageInfo = &image_info;
12866
12867 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
12868
12869 // Create PSO to use the sampler
12870 char const *vsSource = "#version 450\n"
12871 "\n"
12872 "out gl_PerVertex { \n"
12873 " vec4 gl_Position;\n"
12874 "};\n"
12875 "void main(){\n"
12876 " gl_Position = vec4(1);\n"
12877 "}\n";
12878 char const *fsSource = "#version 450\n"
12879 "\n"
12880 "layout(set=0, binding=0) uniform sampler2D s;\n"
12881 "layout(location=0) out vec4 x;\n"
12882 "void main(){\n"
12883 " x = texture(s, vec2(1));\n"
12884 "}\n";
12885 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
12886 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
12887 VkPipelineObj pipe(m_device);
12888 pipe.AddShader(&vs);
12889 pipe.AddShader(&fs);
12890 pipe.AddColorAttachment();
12891 pipe.CreateVKPipeline(pipeline_layout, renderPass());
12892
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012893 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Cannot delete sampler 0x");
Tobin Ehlis209532e2016-09-07 13:52:18 -060012894
12895 BeginCommandBuffer();
12896 // Bind pipeline to cmd buffer
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012897 vkCmdBindPipeline(m_commandBuffer->handle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
12898 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
12899 &descriptor_set, 0, nullptr);
Tobin Ehlis209532e2016-09-07 13:52:18 -060012900 Draw(1, 0, 0, 0);
12901 EndCommandBuffer();
12902 // Submit cmd buffer then destroy sampler
12903 VkSubmitInfo submit_info = {};
12904 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
12905 submit_info.commandBufferCount = 1;
12906 submit_info.pCommandBuffers = &m_commandBuffer->handle();
12907 // Submit cmd buffer and then destroy sampler while in-flight
12908 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
12909
12910 vkDestroySampler(m_device->device(), sampler, nullptr);
12911 m_errorMonitor->VerifyFound();
12912 vkQueueWaitIdle(m_device->m_queue);
12913 // Now we can actually destroy sampler
12914 vkDestroySampler(m_device->device(), sampler, nullptr);
12915 vkDestroyImageView(m_device->device(), view, NULL);
12916 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
12917 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
12918 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
12919}
12920
Mark Mueller1cd9f412016-08-25 13:23:52 -060012921TEST_F(VkLayerTest, QueueForwardProgressFenceWait) {
Mark Mueller96a56d52016-08-24 10:28:05 -060012922 TEST_DESCRIPTION("Call VkQueueSubmit with a semaphore that is already "
Mark Mueller1cd9f412016-08-25 13:23:52 -060012923 "signaled but not waited on by the queue. Wait on a "
12924 "fence that has not yet been submitted to a queue.");
Mark Mueller96a56d52016-08-24 10:28:05 -060012925
12926 ASSERT_NO_FATAL_FAILURE(InitState());
12927 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12928
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012929 const char *queue_forward_progress_message = " that has already been signaled but not waited on by queue 0x";
12930 const char *invalid_fence_wait_message = " which has not been submitted on a Queue or during "
12931 "acquire next image.";
Mark Mueller96a56d52016-08-24 10:28:05 -060012932
12933 BeginCommandBuffer();
12934 EndCommandBuffer();
12935
12936 VkSemaphoreCreateInfo semaphore_create_info = {};
12937 semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
12938 VkSemaphore semaphore;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012939 ASSERT_VK_SUCCESS(vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr, &semaphore));
Mark Mueller96a56d52016-08-24 10:28:05 -060012940 VkSubmitInfo submit_info = {};
12941 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
12942 submit_info.commandBufferCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012943 submit_info.pCommandBuffers = &m_commandBuffer->handle();
Mark Mueller96a56d52016-08-24 10:28:05 -060012944 submit_info.signalSemaphoreCount = 1;
12945 submit_info.pSignalSemaphores = &semaphore;
12946 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
12947 m_errorMonitor->SetDesiredFailureMsg(0, "");
12948 vkResetCommandBuffer(m_commandBuffer->handle(), 0);
12949 BeginCommandBuffer();
12950 EndCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012951 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, queue_forward_progress_message);
Mark Mueller96a56d52016-08-24 10:28:05 -060012952 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
12953 m_errorMonitor->VerifyFound();
12954
Mark Mueller1cd9f412016-08-25 13:23:52 -060012955 VkFenceCreateInfo fence_create_info = {};
12956 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
12957 VkFence fence;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012958 ASSERT_VK_SUCCESS(vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence));
Mark Mueller1cd9f412016-08-25 13:23:52 -060012959
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012960 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT, invalid_fence_wait_message);
Mark Mueller1cd9f412016-08-25 13:23:52 -060012961 vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
12962 m_errorMonitor->VerifyFound();
12963
Mark Mueller4042b652016-09-05 22:52:21 -060012964 vkDeviceWaitIdle(m_device->device());
Mark Mueller1cd9f412016-08-25 13:23:52 -060012965 vkDestroyFence(m_device->device(), fence, nullptr);
Mark Mueller96a56d52016-08-24 10:28:05 -060012966 vkDestroySemaphore(m_device->device(), semaphore, nullptr);
12967}
12968
Tobin Ehlis4af23302016-07-19 10:50:30 -060012969TEST_F(VkLayerTest, FramebufferIncompatible) {
12970 TEST_DESCRIPTION("Bind a secondary command buffer with with a framebuffer "
12971 "that does not match the framebuffer for the active "
12972 "renderpass.");
12973 ASSERT_NO_FATAL_FAILURE(InitState());
12974 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12975
12976 // A renderpass with one color attachment.
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012977 VkAttachmentDescription attachment = {0,
12978 VK_FORMAT_B8G8R8A8_UNORM,
12979 VK_SAMPLE_COUNT_1_BIT,
12980 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
12981 VK_ATTACHMENT_STORE_OP_STORE,
12982 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
12983 VK_ATTACHMENT_STORE_OP_DONT_CARE,
12984 VK_IMAGE_LAYOUT_UNDEFINED,
12985 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL};
Tobin Ehlis4af23302016-07-19 10:50:30 -060012986
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012987 VkAttachmentReference att_ref = {0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL};
Tobin Ehlis4af23302016-07-19 10:50:30 -060012988
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012989 VkSubpassDescription subpass = {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 1, &att_ref, nullptr, nullptr, 0, nullptr};
Tobin Ehlis4af23302016-07-19 10:50:30 -060012990
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012991 VkRenderPassCreateInfo rpci = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 1, &attachment, 1, &subpass, 0, nullptr};
Tobin Ehlis4af23302016-07-19 10:50:30 -060012992
12993 VkRenderPass rp;
12994 VkResult err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
12995 ASSERT_VK_SUCCESS(err);
12996
12997 // A compatible framebuffer.
12998 VkImageObj image(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012999 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 -060013000 ASSERT_TRUE(image.initialized());
13001
13002 VkImageViewCreateInfo ivci = {
13003 VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO,
13004 nullptr,
13005 0,
13006 image.handle(),
13007 VK_IMAGE_VIEW_TYPE_2D,
13008 VK_FORMAT_B8G8R8A8_UNORM,
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013009 {VK_COMPONENT_SWIZZLE_IDENTITY, VK_COMPONENT_SWIZZLE_IDENTITY, VK_COMPONENT_SWIZZLE_IDENTITY,
13010 VK_COMPONENT_SWIZZLE_IDENTITY},
Tobin Ehlis4af23302016-07-19 10:50:30 -060013011 {VK_IMAGE_ASPECT_COLOR_BIT, 0, 1, 0, 1},
13012 };
13013 VkImageView view;
13014 err = vkCreateImageView(m_device->device(), &ivci, nullptr, &view);
13015 ASSERT_VK_SUCCESS(err);
13016
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013017 VkFramebufferCreateInfo fci = {VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr, 0, rp, 1, &view, 32, 32, 1};
Tobin Ehlis4af23302016-07-19 10:50:30 -060013018 VkFramebuffer fb;
13019 err = vkCreateFramebuffer(m_device->device(), &fci, nullptr, &fb);
13020 ASSERT_VK_SUCCESS(err);
13021
13022 VkCommandBufferAllocateInfo cbai = {};
13023 cbai.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
13024 cbai.commandPool = m_commandPool;
13025 cbai.level = VK_COMMAND_BUFFER_LEVEL_SECONDARY;
13026 cbai.commandBufferCount = 1;
13027
13028 VkCommandBuffer sec_cb;
13029 err = vkAllocateCommandBuffers(m_device->device(), &cbai, &sec_cb);
13030 ASSERT_VK_SUCCESS(err);
13031 VkCommandBufferBeginInfo cbbi = {};
13032 VkCommandBufferInheritanceInfo cbii = {};
13033 cbii.renderPass = renderPass();
13034 cbii.framebuffer = fb;
13035 cbbi.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
13036 cbbi.pNext = NULL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013037 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 -060013038 cbbi.pInheritanceInfo = &cbii;
13039 vkBeginCommandBuffer(sec_cb, &cbbi);
13040 vkEndCommandBuffer(sec_cb);
13041
13042 BeginCommandBuffer();
13043
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013044 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
13045 " that is not the same as the primaryCB's current active framebuffer ");
Tobin Ehlis4af23302016-07-19 10:50:30 -060013046 vkCmdExecuteCommands(m_commandBuffer->GetBufferHandle(), 1, &sec_cb);
13047 m_errorMonitor->VerifyFound();
13048 // Cleanup
13049 vkDestroyImageView(m_device->device(), view, NULL);
13050 vkDestroyRenderPass(m_device->device(), rp, NULL);
13051 vkDestroyFramebuffer(m_device->device(), fb, NULL);
13052}
Tobin Ehlis52b504f2016-07-19 13:25:12 -060013053
13054TEST_F(VkLayerTest, ColorBlendLogicOpTests) {
13055 TEST_DESCRIPTION("If logicOp is available on the device, set it to an "
13056 "invalid value. If logicOp is not available, attempt to "
13057 "use it and verify that we see the correct error.");
13058 ASSERT_NO_FATAL_FAILURE(InitState());
13059 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13060
13061 auto features = m_device->phy().features();
13062 // Set the expected error depending on whether or not logicOp available
13063 if (VK_FALSE == features.logicOp) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013064 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "If logic operations feature not "
13065 "enabled, logicOpEnable must be "
13066 "VK_FALSE");
Tobin Ehlis52b504f2016-07-19 13:25:12 -060013067 } else {
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013068 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, ", logicOp must be a valid VkLogicOp value");
Tobin Ehlis52b504f2016-07-19 13:25:12 -060013069 }
13070 // Create a pipeline using logicOp
13071 VkResult err;
13072
13073 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
13074 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
13075
13076 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013077 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis52b504f2016-07-19 13:25:12 -060013078 ASSERT_VK_SUCCESS(err);
13079
13080 VkPipelineViewportStateCreateInfo vp_state_ci = {};
13081 vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
13082 vp_state_ci.viewportCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013083 VkViewport vp = {}; // Just need dummy vp to point to
Tobin Ehlis52b504f2016-07-19 13:25:12 -060013084 vp_state_ci.pViewports = &vp;
13085 vp_state_ci.scissorCount = 1;
13086 VkRect2D scissors = {}; // Dummy scissors to point to
13087 vp_state_ci.pScissors = &scissors;
13088 // No dynamic state
13089 VkPipelineDynamicStateCreateInfo dyn_state_ci = {};
13090 dyn_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_DYNAMIC_STATE_CREATE_INFO;
13091
13092 VkPipelineShaderStageCreateInfo shaderStages[2];
13093 memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo));
13094
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013095 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
13096 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Tobin Ehlis52b504f2016-07-19 13:25:12 -060013097 shaderStages[0] = vs.GetStageCreateInfo();
13098 shaderStages[1] = fs.GetStageCreateInfo();
13099
13100 VkPipelineVertexInputStateCreateInfo vi_ci = {};
13101 vi_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
13102
13103 VkPipelineInputAssemblyStateCreateInfo ia_ci = {};
13104 ia_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
13105 ia_ci.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP;
13106
13107 VkPipelineRasterizationStateCreateInfo rs_ci = {};
13108 rs_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
13109
13110 VkPipelineColorBlendAttachmentState att = {};
13111 att.blendEnable = VK_FALSE;
13112 att.colorWriteMask = 0xf;
13113
13114 VkPipelineColorBlendStateCreateInfo cb_ci = {};
13115 cb_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO;
13116 // Enable logicOp & set logicOp to value 1 beyond allowed entries
13117 cb_ci.logicOpEnable = VK_TRUE;
13118 cb_ci.logicOp = VK_LOGIC_OP_RANGE_SIZE; // This should cause an error
13119 cb_ci.attachmentCount = 1;
13120 cb_ci.pAttachments = &att;
13121
13122 VkGraphicsPipelineCreateInfo gp_ci = {};
13123 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
13124 gp_ci.stageCount = 2;
13125 gp_ci.pStages = shaderStages;
13126 gp_ci.pVertexInputState = &vi_ci;
13127 gp_ci.pInputAssemblyState = &ia_ci;
13128 gp_ci.pViewportState = &vp_state_ci;
13129 gp_ci.pRasterizationState = &rs_ci;
13130 gp_ci.pColorBlendState = &cb_ci;
13131 gp_ci.pDynamicState = &dyn_state_ci;
13132 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
13133 gp_ci.layout = pipeline_layout;
13134 gp_ci.renderPass = renderPass();
13135
13136 VkPipelineCacheCreateInfo pc_ci = {};
13137 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
13138
13139 VkPipeline pipeline;
13140 VkPipelineCache pipelineCache;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013141 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Tobin Ehlis52b504f2016-07-19 13:25:12 -060013142 ASSERT_VK_SUCCESS(err);
13143
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013144 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Tobin Ehlis52b504f2016-07-19 13:25:12 -060013145 m_errorMonitor->VerifyFound();
13146 if (VK_SUCCESS == err) {
13147 vkDestroyPipeline(m_device->device(), pipeline, NULL);
13148 }
13149 m_errorMonitor->VerifyFound();
13150 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
13151 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
13152}
Mark Lobodzinski209b5292015-09-17 09:44:05 -060013153#endif // DRAW_STATE_TESTS
13154
Tobin Ehlis0788f522015-05-26 16:11:58 -060013155#if THREADING_TESTS
Mike Stroyanaccf7692015-05-12 16:00:45 -060013156#if GTEST_IS_THREADSAFE
13157struct thread_data_struct {
Chia-I Wu3432a0c2015-10-27 18:04:07 +080013158 VkCommandBuffer commandBuffer;
Mike Stroyanaccf7692015-05-12 16:00:45 -060013159 VkEvent event;
13160 bool bailout;
13161};
13162
Karl Schultz6addd812016-02-02 17:17:23 -070013163extern "C" void *AddToCommandBuffer(void *arg) {
13164 struct thread_data_struct *data = (struct thread_data_struct *)arg;
Mike Stroyanaccf7692015-05-12 16:00:45 -060013165
Mike Stroyana6d14942016-07-13 15:10:05 -060013166 for (int i = 0; i < 80000; i++) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013167 vkCmdSetEvent(data->commandBuffer, data->event, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT);
Mike Stroyanaccf7692015-05-12 16:00:45 -060013168 if (data->bailout) {
13169 break;
13170 }
13171 }
13172 return NULL;
13173}
13174
Karl Schultz6addd812016-02-02 17:17:23 -070013175TEST_F(VkLayerTest, ThreadCommandBufferCollision) {
Mike Stroyan4268d1f2015-07-13 14:45:35 -060013176 test_platform_thread thread;
Mike Stroyanaccf7692015-05-12 16:00:45 -060013177
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013178 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "THREADING ERROR");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060013179
Mike Stroyanaccf7692015-05-12 16:00:45 -060013180 ASSERT_NO_FATAL_FAILURE(InitState());
13181 ASSERT_NO_FATAL_FAILURE(InitViewport());
13182 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13183
Chia-I Wu3432a0c2015-10-27 18:04:07 +080013184 // Calls AllocateCommandBuffers
13185 VkCommandBufferObj commandBuffer(m_device, m_commandPool);
Mark Lobodzinski5495d132015-09-30 16:19:16 -060013186
13187 // Avoid creating RenderPass
Chia-I Wu3432a0c2015-10-27 18:04:07 +080013188 commandBuffer.BeginCommandBuffer();
Mike Stroyanaccf7692015-05-12 16:00:45 -060013189
13190 VkEventCreateInfo event_info;
13191 VkEvent event;
Mike Stroyanaccf7692015-05-12 16:00:45 -060013192 VkResult err;
13193
13194 memset(&event_info, 0, sizeof(event_info));
13195 event_info.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO;
13196
Chia-I Wuf7458c52015-10-26 21:10:41 +080013197 err = vkCreateEvent(device(), &event_info, NULL, &event);
Mike Stroyanaccf7692015-05-12 16:00:45 -060013198 ASSERT_VK_SUCCESS(err);
13199
Mike Stroyanaccf7692015-05-12 16:00:45 -060013200 err = vkResetEvent(device(), event);
13201 ASSERT_VK_SUCCESS(err);
13202
13203 struct thread_data_struct data;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080013204 data.commandBuffer = commandBuffer.GetBufferHandle();
Mike Stroyanaccf7692015-05-12 16:00:45 -060013205 data.event = event;
13206 data.bailout = false;
13207 m_errorMonitor->SetBailout(&data.bailout);
Mike Stroyana6d14942016-07-13 15:10:05 -060013208
13209 // First do some correct operations using multiple threads.
13210 // Add many entries to command buffer from another thread.
13211 test_platform_thread_create(&thread, AddToCommandBuffer, (void *)&data);
13212 // Make non-conflicting calls from this thread at the same time.
13213 for (int i = 0; i < 80000; i++) {
Mike Stroyand6343902016-07-14 08:56:16 -060013214 uint32_t count;
13215 vkEnumeratePhysicalDevices(instance(), &count, NULL);
Mike Stroyana6d14942016-07-13 15:10:05 -060013216 }
13217 test_platform_thread_join(thread, NULL);
13218
13219 // Then do some incorrect operations using multiple threads.
Mike Stroyanaccf7692015-05-12 16:00:45 -060013220 // Add many entries to command buffer from another thread.
Mike Stroyan4268d1f2015-07-13 14:45:35 -060013221 test_platform_thread_create(&thread, AddToCommandBuffer, (void *)&data);
Mike Stroyanaccf7692015-05-12 16:00:45 -060013222 // Add many entries to command buffer from this thread at the same time.
13223 AddToCommandBuffer(&data);
Mark Lobodzinski5495d132015-09-30 16:19:16 -060013224
Mike Stroyan4268d1f2015-07-13 14:45:35 -060013225 test_platform_thread_join(thread, NULL);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080013226 commandBuffer.EndCommandBuffer();
Mike Stroyanaccf7692015-05-12 16:00:45 -060013227
Mike Stroyan10b8cb72016-01-22 15:22:03 -070013228 m_errorMonitor->SetBailout(NULL);
13229
Chris Forbes8f36a8a2016-04-07 13:21:07 +120013230 m_errorMonitor->VerifyFound();
Mike Stroyanaccf7692015-05-12 16:00:45 -060013231
Chia-I Wuf7458c52015-10-26 21:10:41 +080013232 vkDestroyEvent(device(), event, NULL);
Mike Stroyanaccf7692015-05-12 16:00:45 -060013233}
Mark Lobodzinski209b5292015-09-17 09:44:05 -060013234#endif // GTEST_IS_THREADSAFE
13235#endif // THREADING_TESTS
13236
Chris Forbes9f7ff632015-05-25 11:13:08 +120013237#if SHADER_CHECKER_TESTS
Karl Schultz6addd812016-02-02 17:17:23 -070013238TEST_F(VkLayerTest, InvalidSPIRVCodeSize) {
Chris Forbes1cc79542016-07-20 11:13:44 +120013239 TEST_DESCRIPTION("Test that an error is produced for a spirv module "
13240 "with an impossible code size");
13241
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013242 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Invalid SPIR-V header");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060013243
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060013244 ASSERT_NO_FATAL_FAILURE(InitState());
13245 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13246
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060013247 VkShaderModule module;
13248 VkShaderModuleCreateInfo moduleCreateInfo;
13249 struct icd_spv_header spv;
13250
13251 spv.magic = ICD_SPV_MAGIC;
13252 spv.version = ICD_SPV_VERSION;
13253 spv.gen_magic = 0;
13254
13255 moduleCreateInfo.sType = VK_STRUCTURE_TYPE_SHADER_MODULE_CREATE_INFO;
13256 moduleCreateInfo.pNext = NULL;
Karl Schultz6addd812016-02-02 17:17:23 -070013257 moduleCreateInfo.pCode = (const uint32_t *)&spv;
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060013258 moduleCreateInfo.codeSize = 4;
13259 moduleCreateInfo.flags = 0;
Chia-I Wuf7458c52015-10-26 21:10:41 +080013260 vkCreateShaderModule(m_device->device(), &moduleCreateInfo, NULL, &module);
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060013261
Chris Forbes8f36a8a2016-04-07 13:21:07 +120013262 m_errorMonitor->VerifyFound();
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060013263}
13264
Karl Schultz6addd812016-02-02 17:17:23 -070013265TEST_F(VkLayerTest, InvalidSPIRVMagic) {
Chris Forbes1cc79542016-07-20 11:13:44 +120013266 TEST_DESCRIPTION("Test that an error is produced for a spirv module "
13267 "with a bad magic number");
13268
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013269 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Invalid SPIR-V magic number");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060013270
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060013271 ASSERT_NO_FATAL_FAILURE(InitState());
13272 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13273
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060013274 VkShaderModule module;
13275 VkShaderModuleCreateInfo moduleCreateInfo;
13276 struct icd_spv_header spv;
13277
13278 spv.magic = ~ICD_SPV_MAGIC;
13279 spv.version = ICD_SPV_VERSION;
13280 spv.gen_magic = 0;
13281
13282 moduleCreateInfo.sType = VK_STRUCTURE_TYPE_SHADER_MODULE_CREATE_INFO;
13283 moduleCreateInfo.pNext = NULL;
Karl Schultz6addd812016-02-02 17:17:23 -070013284 moduleCreateInfo.pCode = (const uint32_t *)&spv;
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060013285 moduleCreateInfo.codeSize = sizeof(spv) + 10;
13286 moduleCreateInfo.flags = 0;
Chia-I Wuf7458c52015-10-26 21:10:41 +080013287 vkCreateShaderModule(m_device->device(), &moduleCreateInfo, NULL, &module);
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060013288
Chris Forbes8f36a8a2016-04-07 13:21:07 +120013289 m_errorMonitor->VerifyFound();
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060013290}
13291
Chris Forbesb4afd0f2016-04-04 10:48:35 +120013292#if 0
13293// Not currently covered by SPIRV-Tools validator
Karl Schultz6addd812016-02-02 17:17:23 -070013294TEST_F(VkLayerTest, InvalidSPIRVVersion) {
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -070013295 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Chris Forbesb4afd0f2016-04-04 10:48:35 +120013296 "Invalid SPIR-V header");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060013297
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060013298 ASSERT_NO_FATAL_FAILURE(InitState());
13299 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13300
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060013301 VkShaderModule module;
13302 VkShaderModuleCreateInfo moduleCreateInfo;
13303 struct icd_spv_header spv;
13304
13305 spv.magic = ICD_SPV_MAGIC;
13306 spv.version = ~ICD_SPV_VERSION;
13307 spv.gen_magic = 0;
13308
13309 moduleCreateInfo.sType = VK_STRUCTURE_TYPE_SHADER_MODULE_CREATE_INFO;
13310 moduleCreateInfo.pNext = NULL;
13311
Karl Schultz6addd812016-02-02 17:17:23 -070013312 moduleCreateInfo.pCode = (const uint32_t *)&spv;
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060013313 moduleCreateInfo.codeSize = sizeof(spv) + 10;
13314 moduleCreateInfo.flags = 0;
Chia-I Wuf7458c52015-10-26 21:10:41 +080013315 vkCreateShaderModule(m_device->device(), &moduleCreateInfo, NULL, &module);
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060013316
Chris Forbes8f36a8a2016-04-07 13:21:07 +120013317 m_errorMonitor->VerifyFound();
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060013318}
Chris Forbesb4afd0f2016-04-04 10:48:35 +120013319#endif
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060013320
Karl Schultz6addd812016-02-02 17:17:23 -070013321TEST_F(VkLayerTest, CreatePipelineVertexOutputNotConsumed) {
Chris Forbes1cc79542016-07-20 11:13:44 +120013322 TEST_DESCRIPTION("Test that a warning is produced for a vertex output that "
13323 "is not consumed by the fragment stage");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013324 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT, "not consumed by fragment shader");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060013325
Chris Forbes9f7ff632015-05-25 11:13:08 +120013326 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -060013327 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbes9f7ff632015-05-25 11:13:08 +120013328
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013329 char const *vsSource = "#version 450\n"
13330 "\n"
13331 "layout(location=0) out float x;\n"
13332 "out gl_PerVertex {\n"
13333 " vec4 gl_Position;\n"
13334 "};\n"
13335 "void main(){\n"
13336 " gl_Position = vec4(1);\n"
13337 " x = 0;\n"
13338 "}\n";
13339 char const *fsSource = "#version 450\n"
13340 "\n"
13341 "layout(location=0) out vec4 color;\n"
13342 "void main(){\n"
13343 " color = vec4(1);\n"
13344 "}\n";
Chris Forbes9f7ff632015-05-25 11:13:08 +120013345
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060013346 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13347 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbes9f7ff632015-05-25 11:13:08 +120013348
13349 VkPipelineObj pipe(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +080013350 pipe.AddColorAttachment();
Chris Forbes9f7ff632015-05-25 11:13:08 +120013351 pipe.AddShader(&vs);
13352 pipe.AddShader(&fs);
13353
Chris Forbes9f7ff632015-05-25 11:13:08 +120013354 VkDescriptorSetObj descriptorSet(m_device);
13355 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080013356 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbes9f7ff632015-05-25 11:13:08 +120013357
Tony Barbour5781e8f2015-08-04 16:23:11 -060013358 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbes9f7ff632015-05-25 11:13:08 +120013359
Chris Forbes8f36a8a2016-04-07 13:21:07 +120013360 m_errorMonitor->VerifyFound();
Chris Forbes9f7ff632015-05-25 11:13:08 +120013361}
Chris Forbes9f7ff632015-05-25 11:13:08 +120013362
Karl Schultz6addd812016-02-02 17:17:23 -070013363TEST_F(VkLayerTest, CreatePipelineFragmentInputNotProvided) {
Chris Forbes1cc79542016-07-20 11:13:44 +120013364 TEST_DESCRIPTION("Test that an error is produced for a fragment shader input "
13365 "which is not present in the outputs of the previous stage");
13366
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013367 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "not written by vertex shader");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060013368
Chris Forbes59cb88d2015-05-25 11:13:13 +120013369 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -060013370 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbes59cb88d2015-05-25 11:13:13 +120013371
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013372 char const *vsSource = "#version 450\n"
13373 "\n"
13374 "out gl_PerVertex {\n"
13375 " vec4 gl_Position;\n"
13376 "};\n"
13377 "void main(){\n"
13378 " gl_Position = vec4(1);\n"
13379 "}\n";
13380 char const *fsSource = "#version 450\n"
13381 "\n"
13382 "layout(location=0) in float x;\n"
13383 "layout(location=0) out vec4 color;\n"
13384 "void main(){\n"
13385 " color = vec4(x);\n"
13386 "}\n";
Chris Forbes59cb88d2015-05-25 11:13:13 +120013387
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060013388 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13389 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbes59cb88d2015-05-25 11:13:13 +120013390
13391 VkPipelineObj pipe(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +080013392 pipe.AddColorAttachment();
Chris Forbes59cb88d2015-05-25 11:13:13 +120013393 pipe.AddShader(&vs);
13394 pipe.AddShader(&fs);
13395
Chris Forbes59cb88d2015-05-25 11:13:13 +120013396 VkDescriptorSetObj descriptorSet(m_device);
13397 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080013398 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbes59cb88d2015-05-25 11:13:13 +120013399
Tony Barbour5781e8f2015-08-04 16:23:11 -060013400 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbes59cb88d2015-05-25 11:13:13 +120013401
Chris Forbes8f36a8a2016-04-07 13:21:07 +120013402 m_errorMonitor->VerifyFound();
Chris Forbes59cb88d2015-05-25 11:13:13 +120013403}
13404
Karl Schultz6addd812016-02-02 17:17:23 -070013405TEST_F(VkLayerTest, CreatePipelineFragmentInputNotProvidedInBlock) {
Chris Forbes1cc79542016-07-20 11:13:44 +120013406 TEST_DESCRIPTION("Test that an error is produced for a fragment shader input "
13407 "within an interace block, which is not present in the outputs "
13408 "of the previous stage.");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013409 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "not written by vertex shader");
Chris Forbesa3e85f62016-01-15 14:53:11 +130013410
13411 ASSERT_NO_FATAL_FAILURE(InitState());
13412 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13413
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013414 char const *vsSource = "#version 450\n"
13415 "\n"
13416 "out gl_PerVertex {\n"
13417 " vec4 gl_Position;\n"
13418 "};\n"
13419 "void main(){\n"
13420 " gl_Position = vec4(1);\n"
13421 "}\n";
13422 char const *fsSource = "#version 450\n"
13423 "\n"
13424 "in block { layout(location=0) float x; } ins;\n"
13425 "layout(location=0) out vec4 color;\n"
13426 "void main(){\n"
13427 " color = vec4(ins.x);\n"
13428 "}\n";
Chris Forbesa3e85f62016-01-15 14:53:11 +130013429
13430 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13431 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
13432
13433 VkPipelineObj pipe(m_device);
13434 pipe.AddColorAttachment();
13435 pipe.AddShader(&vs);
13436 pipe.AddShader(&fs);
13437
13438 VkDescriptorSetObj descriptorSet(m_device);
13439 descriptorSet.AppendDummy();
13440 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
13441
13442 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
13443
Chris Forbes8f36a8a2016-04-07 13:21:07 +120013444 m_errorMonitor->VerifyFound();
Chris Forbesa3e85f62016-01-15 14:53:11 +130013445}
13446
Karl Schultz6addd812016-02-02 17:17:23 -070013447TEST_F(VkLayerTest, CreatePipelineVsFsTypeMismatchArraySize) {
Chris Forbes1cc79542016-07-20 11:13:44 +120013448 TEST_DESCRIPTION("Test that an error is produced for mismatched array sizes "
13449 "across the VS->FS interface");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013450 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Type mismatch on location 0.0: 'ptr to "
13451 "output arr[2] of float32' vs 'ptr to "
13452 "input arr[3] of float32'");
Chris Forbes0036fd12016-01-26 14:19:49 +130013453
13454 ASSERT_NO_FATAL_FAILURE(InitState());
13455 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13456
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013457 char const *vsSource = "#version 450\n"
13458 "\n"
13459 "layout(location=0) out float x[2];\n"
13460 "out gl_PerVertex {\n"
13461 " vec4 gl_Position;\n"
13462 "};\n"
13463 "void main(){\n"
13464 " x[0] = 0; x[1] = 0;\n"
13465 " gl_Position = vec4(1);\n"
13466 "}\n";
13467 char const *fsSource = "#version 450\n"
13468 "\n"
13469 "layout(location=0) in float x[3];\n"
13470 "layout(location=0) out vec4 color;\n"
13471 "void main(){\n"
13472 " color = vec4(x[0] + x[1] + x[2]);\n"
13473 "}\n";
Chris Forbes0036fd12016-01-26 14:19:49 +130013474
13475 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13476 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
13477
13478 VkPipelineObj pipe(m_device);
13479 pipe.AddColorAttachment();
13480 pipe.AddShader(&vs);
13481 pipe.AddShader(&fs);
13482
13483 VkDescriptorSetObj descriptorSet(m_device);
13484 descriptorSet.AppendDummy();
13485 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
13486
13487 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
13488
Chris Forbes8f36a8a2016-04-07 13:21:07 +120013489 m_errorMonitor->VerifyFound();
Chris Forbes0036fd12016-01-26 14:19:49 +130013490}
13491
Karl Schultz6addd812016-02-02 17:17:23 -070013492TEST_F(VkLayerTest, CreatePipelineVsFsTypeMismatch) {
Chris Forbes1cc79542016-07-20 11:13:44 +120013493 TEST_DESCRIPTION("Test that an error is produced for mismatched types across "
13494 "the VS->FS interface");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013495 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Type mismatch on location 0");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060013496
Chris Forbesb56af562015-05-25 11:13:17 +120013497 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -060013498 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbesb56af562015-05-25 11:13:17 +120013499
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013500 char const *vsSource = "#version 450\n"
13501 "\n"
13502 "layout(location=0) out int x;\n"
13503 "out gl_PerVertex {\n"
13504 " vec4 gl_Position;\n"
13505 "};\n"
13506 "void main(){\n"
13507 " x = 0;\n"
13508 " gl_Position = vec4(1);\n"
13509 "}\n";
13510 char const *fsSource = "#version 450\n"
13511 "\n"
13512 "layout(location=0) in float x;\n" /* VS writes int */
13513 "layout(location=0) out vec4 color;\n"
13514 "void main(){\n"
13515 " color = vec4(x);\n"
13516 "}\n";
Chris Forbesb56af562015-05-25 11:13:17 +120013517
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060013518 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13519 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbesb56af562015-05-25 11:13:17 +120013520
13521 VkPipelineObj pipe(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +080013522 pipe.AddColorAttachment();
Chris Forbesb56af562015-05-25 11:13:17 +120013523 pipe.AddShader(&vs);
13524 pipe.AddShader(&fs);
13525
Chris Forbesb56af562015-05-25 11:13:17 +120013526 VkDescriptorSetObj descriptorSet(m_device);
13527 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080013528 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbesb56af562015-05-25 11:13:17 +120013529
Tony Barbour5781e8f2015-08-04 16:23:11 -060013530 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbesb56af562015-05-25 11:13:17 +120013531
Chris Forbes8f36a8a2016-04-07 13:21:07 +120013532 m_errorMonitor->VerifyFound();
Chris Forbesb56af562015-05-25 11:13:17 +120013533}
13534
Karl Schultz6addd812016-02-02 17:17:23 -070013535TEST_F(VkLayerTest, CreatePipelineVsFsTypeMismatchInBlock) {
Chris Forbes1cc79542016-07-20 11:13:44 +120013536 TEST_DESCRIPTION("Test that an error is produced for mismatched types across "
13537 "the VS->FS interface, when the variable is contained within "
13538 "an interface block");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013539 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Type mismatch on location 0");
Chris Forbesa3e85f62016-01-15 14:53:11 +130013540
13541 ASSERT_NO_FATAL_FAILURE(InitState());
13542 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13543
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013544 char const *vsSource = "#version 450\n"
13545 "\n"
13546 "out block { layout(location=0) int x; } outs;\n"
13547 "out gl_PerVertex {\n"
13548 " vec4 gl_Position;\n"
13549 "};\n"
13550 "void main(){\n"
13551 " outs.x = 0;\n"
13552 " gl_Position = vec4(1);\n"
13553 "}\n";
13554 char const *fsSource = "#version 450\n"
13555 "\n"
13556 "in block { layout(location=0) float x; } ins;\n" /* VS writes int */
13557 "layout(location=0) out vec4 color;\n"
13558 "void main(){\n"
13559 " color = vec4(ins.x);\n"
13560 "}\n";
Chris Forbesa3e85f62016-01-15 14:53:11 +130013561
13562 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13563 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
13564
13565 VkPipelineObj pipe(m_device);
13566 pipe.AddColorAttachment();
13567 pipe.AddShader(&vs);
13568 pipe.AddShader(&fs);
13569
13570 VkDescriptorSetObj descriptorSet(m_device);
13571 descriptorSet.AppendDummy();
13572 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
13573
13574 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
13575
Chris Forbes8f36a8a2016-04-07 13:21:07 +120013576 m_errorMonitor->VerifyFound();
Chris Forbese9928822016-02-17 14:44:52 +130013577}
13578
13579TEST_F(VkLayerTest, CreatePipelineVsFsMismatchByLocation) {
Chris Forbes1cc79542016-07-20 11:13:44 +120013580 TEST_DESCRIPTION("Test that an error is produced for location mismatches across "
13581 "the VS->FS interface; This should manifest as a not-written/not-consumed "
13582 "pair, but flushes out broken walking of the interfaces");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013583 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 +130013584
13585 ASSERT_NO_FATAL_FAILURE(InitState());
13586 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13587
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013588 char const *vsSource = "#version 450\n"
13589 "\n"
13590 "out block { layout(location=1) float x; } outs;\n"
13591 "out gl_PerVertex {\n"
13592 " vec4 gl_Position;\n"
13593 "};\n"
13594 "void main(){\n"
13595 " outs.x = 0;\n"
13596 " gl_Position = vec4(1);\n"
13597 "}\n";
13598 char const *fsSource = "#version 450\n"
13599 "\n"
13600 "in block { layout(location=0) float x; } ins;\n"
13601 "layout(location=0) out vec4 color;\n"
13602 "void main(){\n"
13603 " color = vec4(ins.x);\n"
13604 "}\n";
Chris Forbese9928822016-02-17 14:44:52 +130013605
13606 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13607 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
13608
13609 VkPipelineObj pipe(m_device);
13610 pipe.AddColorAttachment();
13611 pipe.AddShader(&vs);
13612 pipe.AddShader(&fs);
13613
13614 VkDescriptorSetObj descriptorSet(m_device);
13615 descriptorSet.AppendDummy();
13616 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
13617
13618 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
13619
Chris Forbes8f36a8a2016-04-07 13:21:07 +120013620 m_errorMonitor->VerifyFound();
Chris Forbese9928822016-02-17 14:44:52 +130013621}
13622
13623TEST_F(VkLayerTest, CreatePipelineVsFsMismatchByComponent) {
Chris Forbes1cc79542016-07-20 11:13:44 +120013624 TEST_DESCRIPTION("Test that an error is produced for component mismatches across the "
13625 "VS->FS interface. It's not enough to have the same set of locations in "
13626 "use; matching is defined in terms of spirv variables.");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013627 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 +130013628
13629 ASSERT_NO_FATAL_FAILURE(InitState());
13630 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13631
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013632 char const *vsSource = "#version 450\n"
13633 "\n"
13634 "out block { layout(location=0, component=0) float x; } outs;\n"
13635 "out gl_PerVertex {\n"
13636 " vec4 gl_Position;\n"
13637 "};\n"
13638 "void main(){\n"
13639 " outs.x = 0;\n"
13640 " gl_Position = vec4(1);\n"
13641 "}\n";
13642 char const *fsSource = "#version 450\n"
13643 "\n"
13644 "in block { layout(location=0, component=1) float x; } ins;\n"
13645 "layout(location=0) out vec4 color;\n"
13646 "void main(){\n"
13647 " color = vec4(ins.x);\n"
13648 "}\n";
Chris Forbese9928822016-02-17 14:44:52 +130013649
13650 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13651 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
13652
13653 VkPipelineObj pipe(m_device);
13654 pipe.AddColorAttachment();
13655 pipe.AddShader(&vs);
13656 pipe.AddShader(&fs);
13657
13658 VkDescriptorSetObj descriptorSet(m_device);
13659 descriptorSet.AppendDummy();
13660 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
13661
13662 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
13663
Chris Forbes8f36a8a2016-04-07 13:21:07 +120013664 m_errorMonitor->VerifyFound();
Chris Forbesa3e85f62016-01-15 14:53:11 +130013665}
13666
Karl Schultz6addd812016-02-02 17:17:23 -070013667TEST_F(VkLayerTest, CreatePipelineAttribNotConsumed) {
Chris Forbes1cc79542016-07-20 11:13:44 +120013668 TEST_DESCRIPTION("Test that a warning is produced for a vertex attribute which is "
13669 "not consumed by the vertex shader");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013670 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT, "location 0 not consumed by VS");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060013671
Chris Forbesde136e02015-05-25 11:13:28 +120013672 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -060013673 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbesde136e02015-05-25 11:13:28 +120013674
13675 VkVertexInputBindingDescription input_binding;
13676 memset(&input_binding, 0, sizeof(input_binding));
13677
13678 VkVertexInputAttributeDescription input_attrib;
13679 memset(&input_attrib, 0, sizeof(input_attrib));
13680 input_attrib.format = VK_FORMAT_R32_SFLOAT;
13681
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013682 char const *vsSource = "#version 450\n"
13683 "\n"
13684 "out gl_PerVertex {\n"
13685 " vec4 gl_Position;\n"
13686 "};\n"
13687 "void main(){\n"
13688 " gl_Position = vec4(1);\n"
13689 "}\n";
13690 char const *fsSource = "#version 450\n"
13691 "\n"
13692 "layout(location=0) out vec4 color;\n"
13693 "void main(){\n"
13694 " color = vec4(1);\n"
13695 "}\n";
Chris Forbesde136e02015-05-25 11:13:28 +120013696
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060013697 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13698 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbesde136e02015-05-25 11:13:28 +120013699
13700 VkPipelineObj pipe(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +080013701 pipe.AddColorAttachment();
Chris Forbesde136e02015-05-25 11:13:28 +120013702 pipe.AddShader(&vs);
13703 pipe.AddShader(&fs);
13704
13705 pipe.AddVertexInputBindings(&input_binding, 1);
13706 pipe.AddVertexInputAttribs(&input_attrib, 1);
13707
Chris Forbesde136e02015-05-25 11:13:28 +120013708 VkDescriptorSetObj descriptorSet(m_device);
13709 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080013710 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbesde136e02015-05-25 11:13:28 +120013711
Tony Barbour5781e8f2015-08-04 16:23:11 -060013712 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbesde136e02015-05-25 11:13:28 +120013713
Chris Forbes8f36a8a2016-04-07 13:21:07 +120013714 m_errorMonitor->VerifyFound();
Chris Forbesde136e02015-05-25 11:13:28 +120013715}
13716
Karl Schultz6addd812016-02-02 17:17:23 -070013717TEST_F(VkLayerTest, CreatePipelineAttribLocationMismatch) {
Chris Forbes1cc79542016-07-20 11:13:44 +120013718 TEST_DESCRIPTION("Test that a warning is produced for a location mismatch on "
13719 "vertex attributes. This flushes out bad behavior in the interface walker");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013720 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT, "location 0 not consumed by VS");
Chris Forbes7d83cd52016-01-15 11:32:03 +130013721
13722 ASSERT_NO_FATAL_FAILURE(InitState());
13723 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13724
13725 VkVertexInputBindingDescription input_binding;
13726 memset(&input_binding, 0, sizeof(input_binding));
13727
13728 VkVertexInputAttributeDescription input_attrib;
13729 memset(&input_attrib, 0, sizeof(input_attrib));
13730 input_attrib.format = VK_FORMAT_R32_SFLOAT;
13731
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013732 char const *vsSource = "#version 450\n"
13733 "\n"
13734 "layout(location=1) in float x;\n"
13735 "out gl_PerVertex {\n"
13736 " vec4 gl_Position;\n"
13737 "};\n"
13738 "void main(){\n"
13739 " gl_Position = vec4(x);\n"
13740 "}\n";
13741 char const *fsSource = "#version 450\n"
13742 "\n"
13743 "layout(location=0) out vec4 color;\n"
13744 "void main(){\n"
13745 " color = vec4(1);\n"
13746 "}\n";
Chris Forbes7d83cd52016-01-15 11:32:03 +130013747
13748 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13749 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
13750
13751 VkPipelineObj pipe(m_device);
13752 pipe.AddColorAttachment();
13753 pipe.AddShader(&vs);
13754 pipe.AddShader(&fs);
13755
13756 pipe.AddVertexInputBindings(&input_binding, 1);
13757 pipe.AddVertexInputAttribs(&input_attrib, 1);
13758
13759 VkDescriptorSetObj descriptorSet(m_device);
13760 descriptorSet.AppendDummy();
13761 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
13762
13763 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
13764
Chris Forbes8f36a8a2016-04-07 13:21:07 +120013765 m_errorMonitor->VerifyFound();
Chris Forbes7d83cd52016-01-15 11:32:03 +130013766}
13767
Karl Schultz6addd812016-02-02 17:17:23 -070013768TEST_F(VkLayerTest, CreatePipelineAttribNotProvided) {
Chris Forbes1cc79542016-07-20 11:13:44 +120013769 TEST_DESCRIPTION("Test that an error is produced for a VS input which is not "
13770 "provided by a vertex attribute");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013771 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 -060013772
Chris Forbes62e8e502015-05-25 11:13:29 +120013773 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -060013774 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbes62e8e502015-05-25 11:13:29 +120013775
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013776 char const *vsSource = "#version 450\n"
13777 "\n"
13778 "layout(location=0) in vec4 x;\n" /* not provided */
13779 "out gl_PerVertex {\n"
13780 " vec4 gl_Position;\n"
13781 "};\n"
13782 "void main(){\n"
13783 " gl_Position = x;\n"
13784 "}\n";
13785 char const *fsSource = "#version 450\n"
13786 "\n"
13787 "layout(location=0) out vec4 color;\n"
13788 "void main(){\n"
13789 " color = vec4(1);\n"
13790 "}\n";
Chris Forbes62e8e502015-05-25 11:13:29 +120013791
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060013792 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13793 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbes62e8e502015-05-25 11:13:29 +120013794
13795 VkPipelineObj pipe(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +080013796 pipe.AddColorAttachment();
Chris Forbes62e8e502015-05-25 11:13:29 +120013797 pipe.AddShader(&vs);
13798 pipe.AddShader(&fs);
13799
Chris Forbes62e8e502015-05-25 11:13:29 +120013800 VkDescriptorSetObj descriptorSet(m_device);
13801 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080013802 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbes62e8e502015-05-25 11:13:29 +120013803
Tony Barbour5781e8f2015-08-04 16:23:11 -060013804 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbes62e8e502015-05-25 11:13:29 +120013805
Chris Forbes8f36a8a2016-04-07 13:21:07 +120013806 m_errorMonitor->VerifyFound();
Chris Forbes62e8e502015-05-25 11:13:29 +120013807}
13808
Karl Schultz6addd812016-02-02 17:17:23 -070013809TEST_F(VkLayerTest, CreatePipelineAttribTypeMismatch) {
Chris Forbes1cc79542016-07-20 11:13:44 +120013810 TEST_DESCRIPTION("Test that an error is produced for a mismatch between the "
13811 "fundamental type (float/int/uint) of an attribute and the "
13812 "VS input that consumes it");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013813 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "location 0 does not match VS input type");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060013814
Chris Forbesc97d98e2015-05-25 11:13:31 +120013815 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -060013816 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbesc97d98e2015-05-25 11:13:31 +120013817
13818 VkVertexInputBindingDescription input_binding;
13819 memset(&input_binding, 0, sizeof(input_binding));
13820
13821 VkVertexInputAttributeDescription input_attrib;
13822 memset(&input_attrib, 0, sizeof(input_attrib));
13823 input_attrib.format = VK_FORMAT_R32_SFLOAT;
13824
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013825 char const *vsSource = "#version 450\n"
13826 "\n"
13827 "layout(location=0) in int x;\n" /* attrib provided float */
13828 "out gl_PerVertex {\n"
13829 " vec4 gl_Position;\n"
13830 "};\n"
13831 "void main(){\n"
13832 " gl_Position = vec4(x);\n"
13833 "}\n";
13834 char const *fsSource = "#version 450\n"
13835 "\n"
13836 "layout(location=0) out vec4 color;\n"
13837 "void main(){\n"
13838 " color = vec4(1);\n"
13839 "}\n";
Chris Forbesc97d98e2015-05-25 11:13:31 +120013840
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060013841 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13842 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbesc97d98e2015-05-25 11:13:31 +120013843
13844 VkPipelineObj pipe(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +080013845 pipe.AddColorAttachment();
Chris Forbesc97d98e2015-05-25 11:13:31 +120013846 pipe.AddShader(&vs);
13847 pipe.AddShader(&fs);
13848
13849 pipe.AddVertexInputBindings(&input_binding, 1);
13850 pipe.AddVertexInputAttribs(&input_attrib, 1);
13851
Chris Forbesc97d98e2015-05-25 11:13:31 +120013852 VkDescriptorSetObj descriptorSet(m_device);
13853 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080013854 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbesc97d98e2015-05-25 11:13:31 +120013855
Tony Barbour5781e8f2015-08-04 16:23:11 -060013856 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbesc97d98e2015-05-25 11:13:31 +120013857
Chris Forbes8f36a8a2016-04-07 13:21:07 +120013858 m_errorMonitor->VerifyFound();
Chris Forbesc97d98e2015-05-25 11:13:31 +120013859}
13860
Chris Forbesc68b43c2016-04-06 11:18:47 +120013861TEST_F(VkLayerTest, CreatePipelineDuplicateStage) {
Chris Forbes1cc79542016-07-20 11:13:44 +120013862 TEST_DESCRIPTION("Test that an error is produced for a pipeline containing multiple "
13863 "shaders for the same stage");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013864 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
13865 "Multiple shaders provided for stage VK_SHADER_STAGE_VERTEX_BIT");
Chris Forbesc68b43c2016-04-06 11:18:47 +120013866
13867 ASSERT_NO_FATAL_FAILURE(InitState());
13868 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13869
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013870 char const *vsSource = "#version 450\n"
13871 "\n"
13872 "out gl_PerVertex {\n"
13873 " vec4 gl_Position;\n"
13874 "};\n"
13875 "void main(){\n"
13876 " gl_Position = vec4(1);\n"
13877 "}\n";
13878 char const *fsSource = "#version 450\n"
13879 "\n"
13880 "layout(location=0) out vec4 color;\n"
13881 "void main(){\n"
13882 " color = vec4(1);\n"
13883 "}\n";
Chris Forbesc68b43c2016-04-06 11:18:47 +120013884
13885 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13886 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
13887
13888 VkPipelineObj pipe(m_device);
13889 pipe.AddColorAttachment();
13890 pipe.AddShader(&vs);
13891 pipe.AddShader(&vs);
13892 pipe.AddShader(&fs);
13893
13894 VkDescriptorSetObj descriptorSet(m_device);
13895 descriptorSet.AppendDummy();
13896 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
13897
13898 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
13899
Chris Forbes8f36a8a2016-04-07 13:21:07 +120013900 m_errorMonitor->VerifyFound();
Chris Forbesc68b43c2016-04-06 11:18:47 +120013901}
13902
Karl Schultz6addd812016-02-02 17:17:23 -070013903TEST_F(VkLayerTest, CreatePipelineAttribMatrixType) {
Chris Forbes1cc79542016-07-20 11:13:44 +120013904 TEST_DESCRIPTION("Test that pipeline validation accepts matrices passed "
13905 "as vertex attributes");
Chris Forbes8f36a8a2016-04-07 13:21:07 +120013906 m_errorMonitor->ExpectSuccess();
Chris Forbes2682b242015-11-24 11:13:14 +130013907
13908 ASSERT_NO_FATAL_FAILURE(InitState());
13909 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13910
13911 VkVertexInputBindingDescription input_binding;
13912 memset(&input_binding, 0, sizeof(input_binding));
13913
13914 VkVertexInputAttributeDescription input_attribs[2];
13915 memset(input_attribs, 0, sizeof(input_attribs));
13916
13917 for (int i = 0; i < 2; i++) {
13918 input_attribs[i].format = VK_FORMAT_R32G32B32A32_SFLOAT;
13919 input_attribs[i].location = i;
13920 }
13921
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013922 char const *vsSource = "#version 450\n"
13923 "\n"
13924 "layout(location=0) in mat2x4 x;\n"
13925 "out gl_PerVertex {\n"
13926 " vec4 gl_Position;\n"
13927 "};\n"
13928 "void main(){\n"
13929 " gl_Position = x[0] + x[1];\n"
13930 "}\n";
13931 char const *fsSource = "#version 450\n"
13932 "\n"
13933 "layout(location=0) out vec4 color;\n"
13934 "void main(){\n"
13935 " color = vec4(1);\n"
13936 "}\n";
Chris Forbes2682b242015-11-24 11:13:14 +130013937
13938 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13939 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
13940
13941 VkPipelineObj pipe(m_device);
13942 pipe.AddColorAttachment();
13943 pipe.AddShader(&vs);
13944 pipe.AddShader(&fs);
13945
13946 pipe.AddVertexInputBindings(&input_binding, 1);
13947 pipe.AddVertexInputAttribs(input_attribs, 2);
13948
13949 VkDescriptorSetObj descriptorSet(m_device);
13950 descriptorSet.AppendDummy();
13951 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
13952
13953 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
13954
13955 /* expect success */
Chris Forbes8f36a8a2016-04-07 13:21:07 +120013956 m_errorMonitor->VerifyNotFound();
Chris Forbes2682b242015-11-24 11:13:14 +130013957}
13958
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013959TEST_F(VkLayerTest, CreatePipelineAttribArrayType) {
Chris Forbes8f36a8a2016-04-07 13:21:07 +120013960 m_errorMonitor->ExpectSuccess();
Chris Forbes2682b242015-11-24 11:13:14 +130013961
13962 ASSERT_NO_FATAL_FAILURE(InitState());
13963 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13964
13965 VkVertexInputBindingDescription input_binding;
13966 memset(&input_binding, 0, sizeof(input_binding));
13967
13968 VkVertexInputAttributeDescription input_attribs[2];
13969 memset(input_attribs, 0, sizeof(input_attribs));
13970
13971 for (int i = 0; i < 2; i++) {
13972 input_attribs[i].format = VK_FORMAT_R32G32B32A32_SFLOAT;
13973 input_attribs[i].location = i;
13974 }
13975
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013976 char const *vsSource = "#version 450\n"
13977 "\n"
13978 "layout(location=0) in vec4 x[2];\n"
13979 "out gl_PerVertex {\n"
13980 " vec4 gl_Position;\n"
13981 "};\n"
13982 "void main(){\n"
13983 " gl_Position = x[0] + x[1];\n"
13984 "}\n";
13985 char const *fsSource = "#version 450\n"
13986 "\n"
13987 "layout(location=0) out vec4 color;\n"
13988 "void main(){\n"
13989 " color = vec4(1);\n"
13990 "}\n";
Chris Forbes2682b242015-11-24 11:13:14 +130013991
13992 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13993 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
13994
13995 VkPipelineObj pipe(m_device);
13996 pipe.AddColorAttachment();
13997 pipe.AddShader(&vs);
13998 pipe.AddShader(&fs);
13999
14000 pipe.AddVertexInputBindings(&input_binding, 1);
14001 pipe.AddVertexInputAttribs(input_attribs, 2);
14002
14003 VkDescriptorSetObj descriptorSet(m_device);
14004 descriptorSet.AppendDummy();
14005 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
14006
14007 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
14008
Chris Forbes8f36a8a2016-04-07 13:21:07 +120014009 m_errorMonitor->VerifyNotFound();
Chris Forbes2682b242015-11-24 11:13:14 +130014010}
Chris Forbes2682b242015-11-24 11:13:14 +130014011
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014012TEST_F(VkLayerTest, CreatePipelineAttribComponents) {
Chris Forbes1cc79542016-07-20 11:13:44 +120014013 TEST_DESCRIPTION("Test that pipeline validation accepts consuming a vertex attribute "
14014 "through multiple VS inputs, each consuming a different subset of the "
14015 "components.");
Chris Forbesbc290ce2016-07-06 12:01:49 +120014016 m_errorMonitor->ExpectSuccess();
14017
14018 ASSERT_NO_FATAL_FAILURE(InitState());
14019 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
14020
14021 VkVertexInputBindingDescription input_binding;
14022 memset(&input_binding, 0, sizeof(input_binding));
14023
14024 VkVertexInputAttributeDescription input_attribs[3];
14025 memset(input_attribs, 0, sizeof(input_attribs));
14026
14027 for (int i = 0; i < 3; i++) {
14028 input_attribs[i].format = VK_FORMAT_R32G32B32A32_SFLOAT;
14029 input_attribs[i].location = i;
14030 }
14031
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014032 char const *vsSource = "#version 450\n"
14033 "\n"
14034 "layout(location=0) in vec4 x;\n"
14035 "layout(location=1) in vec3 y1;\n"
14036 "layout(location=1, component=3) in float y2;\n"
14037 "layout(location=2) in vec4 z;\n"
14038 "out gl_PerVertex {\n"
14039 " vec4 gl_Position;\n"
14040 "};\n"
14041 "void main(){\n"
14042 " gl_Position = x + vec4(y1, y2) + z;\n"
14043 "}\n";
14044 char const *fsSource = "#version 450\n"
14045 "\n"
14046 "layout(location=0) out vec4 color;\n"
14047 "void main(){\n"
14048 " color = vec4(1);\n"
14049 "}\n";
Chris Forbesbc290ce2016-07-06 12:01:49 +120014050
14051 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
14052 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
14053
14054 VkPipelineObj pipe(m_device);
14055 pipe.AddColorAttachment();
14056 pipe.AddShader(&vs);
14057 pipe.AddShader(&fs);
14058
14059 pipe.AddVertexInputBindings(&input_binding, 1);
14060 pipe.AddVertexInputAttribs(input_attribs, 3);
14061
14062 VkDescriptorSetObj descriptorSet(m_device);
14063 descriptorSet.AppendDummy();
14064 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
14065
14066 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
14067
14068 m_errorMonitor->VerifyNotFound();
14069}
14070
Chris Forbes82ff92a2016-09-09 10:50:24 +120014071TEST_F(VkLayerTest, CreatePipelineMissingEntrypoint) {
14072 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
14073 "No entrypoint found named `foo`");
14074
14075 ASSERT_NO_FATAL_FAILURE(InitState());
14076 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
14077
14078 char const *vsSource = "#version 450\n"
14079 "out gl_PerVertex {\n"
14080 " vec4 gl_Position;\n"
14081 "};\n"
14082 "void main(){\n"
14083 " gl_Position = vec4(0);\n"
14084 "}\n";
14085 char const *fsSource = "#version 450\n"
14086 "\n"
14087 "layout(location=0) out vec4 color;\n"
14088 "void main(){\n"
14089 " color = vec4(1);\n"
14090 "}\n";
14091
14092 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
14093 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this, "foo");
14094
14095 VkPipelineObj pipe(m_device);
14096 pipe.AddColorAttachment();
14097 pipe.AddShader(&vs);
14098 pipe.AddShader(&fs);
14099
14100 VkDescriptorSetObj descriptorSet(m_device);
14101 descriptorSet.AppendDummy();
14102 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
14103
14104 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
14105
14106 m_errorMonitor->VerifyFound();
14107}
14108
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014109TEST_F(VkLayerTest, CreatePipelineSimplePositive) {
Chris Forbes8f36a8a2016-04-07 13:21:07 +120014110 m_errorMonitor->ExpectSuccess();
Chris Forbes4ea14fc2016-04-04 18:52:54 +120014111
14112 ASSERT_NO_FATAL_FAILURE(InitState());
14113 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
14114
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014115 char const *vsSource = "#version 450\n"
14116 "out gl_PerVertex {\n"
14117 " vec4 gl_Position;\n"
14118 "};\n"
14119 "void main(){\n"
14120 " gl_Position = vec4(0);\n"
14121 "}\n";
14122 char const *fsSource = "#version 450\n"
14123 "\n"
14124 "layout(location=0) out vec4 color;\n"
14125 "void main(){\n"
14126 " color = vec4(1);\n"
14127 "}\n";
Chris Forbes4ea14fc2016-04-04 18:52:54 +120014128
14129 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
14130 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
14131
14132 VkPipelineObj pipe(m_device);
14133 pipe.AddColorAttachment();
14134 pipe.AddShader(&vs);
14135 pipe.AddShader(&fs);
14136
14137 VkDescriptorSetObj descriptorSet(m_device);
14138 descriptorSet.AppendDummy();
14139 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
14140
14141 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
14142
Chris Forbes8f36a8a2016-04-07 13:21:07 +120014143 m_errorMonitor->VerifyNotFound();
Chris Forbes4ea14fc2016-04-04 18:52:54 +120014144}
14145
Chris Forbesae9d8cd2016-09-13 16:32:57 +120014146TEST_F(VkLayerTest, CreatePipelineDepthStencilRequired) {
14147 m_errorMonitor->SetDesiredFailureMsg(
14148 VK_DEBUG_REPORT_ERROR_BIT_EXT,
14149 "pDepthStencilState is NULL when rasterization is enabled and subpass "
14150 "uses a depth/stencil attachment");
14151
14152 ASSERT_NO_FATAL_FAILURE(InitState());
14153 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
14154
14155 char const *vsSource = "#version 450\n"
14156 "void main(){ gl_Position = vec4(0); }\n";
14157 char const *fsSource = "#version 450\n"
14158 "\n"
14159 "layout(location=0) out vec4 color;\n"
14160 "void main(){\n"
14161 " color = vec4(1);\n"
14162 "}\n";
14163
14164 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
14165 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
14166
14167 VkPipelineObj pipe(m_device);
14168 pipe.AddColorAttachment();
14169 pipe.AddShader(&vs);
14170 pipe.AddShader(&fs);
14171
14172 VkDescriptorSetObj descriptorSet(m_device);
14173 descriptorSet.AppendDummy();
14174 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
14175
14176 VkAttachmentDescription attachments[] = {
14177 { 0, VK_FORMAT_B8G8R8A8_UNORM, VK_SAMPLE_COUNT_1_BIT,
14178 VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE,
14179 VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE,
14180 VK_IMAGE_LAYOUT_UNDEFINED, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
14181 },
14182 { 0, VK_FORMAT_D16_UNORM, VK_SAMPLE_COUNT_1_BIT,
14183 VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE,
14184 VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE,
14185 VK_IMAGE_LAYOUT_UNDEFINED, VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL,
14186 },
14187 };
14188 VkAttachmentReference refs[] = {
14189 { 0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL },
14190 { 1, VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL },
14191 };
14192 VkSubpassDescription subpass = {
14193 0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr,
14194 1, &refs[0], nullptr, &refs[1],
14195 0, nullptr
14196 };
14197 VkRenderPassCreateInfo rpci = {
14198 VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr,
14199 0, 2, attachments, 1, &subpass, 0, nullptr
14200 };
14201 VkRenderPass rp;
14202 VkResult err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
14203 ASSERT_VK_SUCCESS(err);
14204
14205 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), rp);
14206
14207 m_errorMonitor->VerifyFound();
14208
14209 vkDestroyRenderPass(m_device->device(), rp, nullptr);
14210}
14211
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014212TEST_F(VkLayerTest, CreatePipelineRelaxedTypeMatch) {
Chris Forbes1cc79542016-07-20 11:13:44 +120014213 TEST_DESCRIPTION("Test that pipeline validation accepts the relaxed type matching rules "
14214 "set out in 14.1.3: fundamental type must match, and producer side must "
14215 "have at least as many components");
Chris Forbes8f36a8a2016-04-07 13:21:07 +120014216 m_errorMonitor->ExpectSuccess();
Chris Forbes912c9192016-04-05 17:50:35 +120014217
14218 // VK 1.0.8 Specification, 14.1.3 "Additionally,..." block
14219
14220 ASSERT_NO_FATAL_FAILURE(InitState());
14221 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
14222
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014223 char const *vsSource = "#version 450\n"
14224 "out gl_PerVertex {\n"
14225 " vec4 gl_Position;\n"
14226 "};\n"
14227 "layout(location=0) out vec3 x;\n"
14228 "layout(location=1) out ivec3 y;\n"
14229 "layout(location=2) out vec3 z;\n"
14230 "void main(){\n"
14231 " gl_Position = vec4(0);\n"
14232 " x = vec3(0); y = ivec3(0); z = vec3(0);\n"
14233 "}\n";
14234 char const *fsSource = "#version 450\n"
14235 "\n"
14236 "layout(location=0) out vec4 color;\n"
14237 "layout(location=0) in float x;\n"
14238 "layout(location=1) flat in int y;\n"
14239 "layout(location=2) in vec2 z;\n"
14240 "void main(){\n"
14241 " color = vec4(1 + x + y + z.x);\n"
14242 "}\n";
Chris Forbes912c9192016-04-05 17:50:35 +120014243
14244 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
14245 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
14246
14247 VkPipelineObj pipe(m_device);
14248 pipe.AddColorAttachment();
14249 pipe.AddShader(&vs);
14250 pipe.AddShader(&fs);
14251
14252 VkDescriptorSetObj descriptorSet(m_device);
14253 descriptorSet.AppendDummy();
14254 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
14255
Mike Stroyan255e9582016-06-24 09:49:32 -060014256 VkResult err = VK_SUCCESS;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014257 err = pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Mike Stroyan255e9582016-06-24 09:49:32 -060014258 ASSERT_VK_SUCCESS(err);
14259
Chris Forbes8f36a8a2016-04-07 13:21:07 +120014260 m_errorMonitor->VerifyNotFound();
Chris Forbes912c9192016-04-05 17:50:35 +120014261}
14262
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014263TEST_F(VkLayerTest, CreatePipelineTessPerVertex) {
Chris Forbes1cc79542016-07-20 11:13:44 +120014264 TEST_DESCRIPTION("Test that pipeline validation accepts per-vertex variables "
14265 "passed between the TCS and TES stages");
Chris Forbes8f36a8a2016-04-07 13:21:07 +120014266 m_errorMonitor->ExpectSuccess();
Chris Forbes4ea14fc2016-04-04 18:52:54 +120014267
14268 ASSERT_NO_FATAL_FAILURE(InitState());
14269 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
14270
Chris Forbesc1e852d2016-04-04 19:26:42 +120014271 if (!m_device->phy().features().tessellationShader) {
14272 printf("Device does not support tessellation shaders; skipped.\n");
14273 return;
14274 }
14275
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014276 char const *vsSource = "#version 450\n"
14277 "void main(){}\n";
14278 char const *tcsSource = "#version 450\n"
14279 "layout(location=0) out int x[];\n"
14280 "layout(vertices=3) out;\n"
14281 "void main(){\n"
14282 " gl_TessLevelOuter[0] = gl_TessLevelOuter[1] = gl_TessLevelOuter[2] = 1;\n"
14283 " gl_TessLevelInner[0] = 1;\n"
14284 " x[gl_InvocationID] = gl_InvocationID;\n"
14285 "}\n";
14286 char const *tesSource = "#version 450\n"
14287 "layout(triangles, equal_spacing, cw) in;\n"
14288 "layout(location=0) in int x[];\n"
14289 "out gl_PerVertex { vec4 gl_Position; };\n"
14290 "void main(){\n"
14291 " gl_Position.xyz = gl_TessCoord;\n"
14292 " gl_Position.w = x[0] + x[1] + x[2];\n"
14293 "}\n";
14294 char const *fsSource = "#version 450\n"
14295 "layout(location=0) out vec4 color;\n"
14296 "void main(){\n"
14297 " color = vec4(1);\n"
14298 "}\n";
Chris Forbes4ea14fc2016-04-04 18:52:54 +120014299
14300 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
14301 VkShaderObj tcs(m_device, tcsSource, VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT, this);
14302 VkShaderObj tes(m_device, tesSource, VK_SHADER_STAGE_TESSELLATION_EVALUATION_BIT, this);
14303 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
14304
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014305 VkPipelineInputAssemblyStateCreateInfo iasci{VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO, nullptr, 0,
14306 VK_PRIMITIVE_TOPOLOGY_PATCH_LIST, VK_FALSE};
Chris Forbes4ea14fc2016-04-04 18:52:54 +120014307
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014308 VkPipelineTessellationStateCreateInfo tsci{VK_STRUCTURE_TYPE_PIPELINE_TESSELLATION_STATE_CREATE_INFO, nullptr, 0, 3};
Chris Forbesb4cacb62016-04-04 19:15:00 +120014309
Chris Forbes4ea14fc2016-04-04 18:52:54 +120014310 VkPipelineObj pipe(m_device);
14311 pipe.SetInputAssembly(&iasci);
Chris Forbesb4cacb62016-04-04 19:15:00 +120014312 pipe.SetTessellation(&tsci);
Chris Forbes4ea14fc2016-04-04 18:52:54 +120014313 pipe.AddColorAttachment();
14314 pipe.AddShader(&vs);
14315 pipe.AddShader(&tcs);
14316 pipe.AddShader(&tes);
14317 pipe.AddShader(&fs);
14318
14319 VkDescriptorSetObj descriptorSet(m_device);
14320 descriptorSet.AppendDummy();
14321 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
14322
14323 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
14324
Chris Forbes8f36a8a2016-04-07 13:21:07 +120014325 m_errorMonitor->VerifyNotFound();
Chris Forbes4ea14fc2016-04-04 18:52:54 +120014326}
14327
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014328TEST_F(VkLayerTest, CreatePipelineGeometryInputBlockPositive) {
Chris Forbes1cc79542016-07-20 11:13:44 +120014329 TEST_DESCRIPTION("Test that pipeline validation accepts a user-defined "
14330 "interface block passed into the geometry shader. This "
14331 "is interesting because the 'extra' array level is not "
14332 "present on the member type, but on the block instance.");
Chris Forbesa0ab8152016-04-20 13:34:27 +120014333 m_errorMonitor->ExpectSuccess();
14334
14335 ASSERT_NO_FATAL_FAILURE(InitState());
14336 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
14337
14338 if (!m_device->phy().features().geometryShader) {
14339 printf("Device does not support geometry shaders; skipped.\n");
14340 return;
14341 }
14342
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014343 char const *vsSource = "#version 450\n"
14344 "layout(location=0) out VertexData { vec4 x; } vs_out;\n"
14345 "void main(){\n"
14346 " vs_out.x = vec4(1);\n"
14347 "}\n";
14348 char const *gsSource = "#version 450\n"
14349 "layout(triangles) in;\n"
14350 "layout(triangle_strip, max_vertices=3) out;\n"
14351 "layout(location=0) in VertexData { vec4 x; } gs_in[];\n"
14352 "out gl_PerVertex { vec4 gl_Position; };\n"
14353 "void main() {\n"
14354 " gl_Position = gs_in[0].x;\n"
14355 " EmitVertex();\n"
14356 "}\n";
14357 char const *fsSource = "#version 450\n"
14358 "layout(location=0) out vec4 color;\n"
14359 "void main(){\n"
14360 " color = vec4(1);\n"
14361 "}\n";
Chris Forbesa0ab8152016-04-20 13:34:27 +120014362
14363 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
14364 VkShaderObj gs(m_device, gsSource, VK_SHADER_STAGE_GEOMETRY_BIT, this);
14365 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
14366
14367 VkPipelineObj pipe(m_device);
14368 pipe.AddColorAttachment();
14369 pipe.AddShader(&vs);
14370 pipe.AddShader(&gs);
14371 pipe.AddShader(&fs);
14372
14373 VkDescriptorSetObj descriptorSet(m_device);
14374 descriptorSet.AppendDummy();
14375 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
14376
14377 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
14378
14379 m_errorMonitor->VerifyNotFound();
14380}
14381
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014382TEST_F(VkLayerTest, CreatePipelineTessPatchDecorationMismatch) {
Chris Forbes1cc79542016-07-20 11:13:44 +120014383 TEST_DESCRIPTION("Test that an error is produced for a variable output from "
14384 "the TCS without the patch decoration, but consumed in the TES "
14385 "with the decoration.");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014386 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "is per-vertex in tessellation control shader stage "
14387 "but per-patch in tessellation evaluation shader stage");
Chris Forbesa0193bc2016-04-04 19:19:47 +120014388
14389 ASSERT_NO_FATAL_FAILURE(InitState());
14390 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
14391
Chris Forbesc1e852d2016-04-04 19:26:42 +120014392 if (!m_device->phy().features().tessellationShader) {
14393 printf("Device does not support tessellation shaders; skipped.\n");
14394 return;
14395 }
14396
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014397 char const *vsSource = "#version 450\n"
14398 "void main(){}\n";
14399 char const *tcsSource = "#version 450\n"
14400 "layout(location=0) out int x[];\n"
14401 "layout(vertices=3) out;\n"
14402 "void main(){\n"
14403 " gl_TessLevelOuter[0] = gl_TessLevelOuter[1] = gl_TessLevelOuter[2] = 1;\n"
14404 " gl_TessLevelInner[0] = 1;\n"
14405 " x[gl_InvocationID] = gl_InvocationID;\n"
14406 "}\n";
14407 char const *tesSource = "#version 450\n"
14408 "layout(triangles, equal_spacing, cw) in;\n"
14409 "layout(location=0) patch in int x;\n"
14410 "out gl_PerVertex { vec4 gl_Position; };\n"
14411 "void main(){\n"
14412 " gl_Position.xyz = gl_TessCoord;\n"
14413 " gl_Position.w = x;\n"
14414 "}\n";
14415 char const *fsSource = "#version 450\n"
14416 "layout(location=0) out vec4 color;\n"
14417 "void main(){\n"
14418 " color = vec4(1);\n"
14419 "}\n";
Chris Forbesa0193bc2016-04-04 19:19:47 +120014420
14421 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
14422 VkShaderObj tcs(m_device, tcsSource, VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT, this);
14423 VkShaderObj tes(m_device, tesSource, VK_SHADER_STAGE_TESSELLATION_EVALUATION_BIT, this);
14424 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
14425
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014426 VkPipelineInputAssemblyStateCreateInfo iasci{VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO, nullptr, 0,
14427 VK_PRIMITIVE_TOPOLOGY_PATCH_LIST, VK_FALSE};
Chris Forbesa0193bc2016-04-04 19:19:47 +120014428
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014429 VkPipelineTessellationStateCreateInfo tsci{VK_STRUCTURE_TYPE_PIPELINE_TESSELLATION_STATE_CREATE_INFO, nullptr, 0, 3};
Chris Forbesa0193bc2016-04-04 19:19:47 +120014430
14431 VkPipelineObj pipe(m_device);
14432 pipe.SetInputAssembly(&iasci);
14433 pipe.SetTessellation(&tsci);
14434 pipe.AddColorAttachment();
14435 pipe.AddShader(&vs);
14436 pipe.AddShader(&tcs);
14437 pipe.AddShader(&tes);
14438 pipe.AddShader(&fs);
14439
14440 VkDescriptorSetObj descriptorSet(m_device);
14441 descriptorSet.AppendDummy();
14442 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
14443
14444 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
14445
Chris Forbes8f36a8a2016-04-07 13:21:07 +120014446 m_errorMonitor->VerifyFound();
Chris Forbesa0193bc2016-04-04 19:19:47 +120014447}
14448
Karl Schultz6addd812016-02-02 17:17:23 -070014449TEST_F(VkLayerTest, CreatePipelineAttribBindingConflict) {
Chris Forbes1cc79542016-07-20 11:13:44 +120014450 TEST_DESCRIPTION("Test that an error is produced for a vertex attribute setup where multiple "
14451 "bindings provide the same location");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014452 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
14453 "Duplicate vertex input binding descriptions for binding 0");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060014454
Chris Forbes280ba2c2015-06-12 11:16:41 +120014455 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -060014456 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbes280ba2c2015-06-12 11:16:41 +120014457
14458 /* Two binding descriptions for binding 0 */
14459 VkVertexInputBindingDescription input_bindings[2];
14460 memset(input_bindings, 0, sizeof(input_bindings));
14461
14462 VkVertexInputAttributeDescription input_attrib;
14463 memset(&input_attrib, 0, sizeof(input_attrib));
14464 input_attrib.format = VK_FORMAT_R32_SFLOAT;
14465
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014466 char const *vsSource = "#version 450\n"
14467 "\n"
14468 "layout(location=0) in float x;\n" /* attrib provided float */
14469 "out gl_PerVertex {\n"
14470 " vec4 gl_Position;\n"
14471 "};\n"
14472 "void main(){\n"
14473 " gl_Position = vec4(x);\n"
14474 "}\n";
14475 char const *fsSource = "#version 450\n"
14476 "\n"
14477 "layout(location=0) out vec4 color;\n"
14478 "void main(){\n"
14479 " color = vec4(1);\n"
14480 "}\n";
Chris Forbes280ba2c2015-06-12 11:16:41 +120014481
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060014482 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
14483 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbes280ba2c2015-06-12 11:16:41 +120014484
14485 VkPipelineObj pipe(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +080014486 pipe.AddColorAttachment();
Chris Forbes280ba2c2015-06-12 11:16:41 +120014487 pipe.AddShader(&vs);
14488 pipe.AddShader(&fs);
14489
14490 pipe.AddVertexInputBindings(input_bindings, 2);
14491 pipe.AddVertexInputAttribs(&input_attrib, 1);
14492
Chris Forbes280ba2c2015-06-12 11:16:41 +120014493 VkDescriptorSetObj descriptorSet(m_device);
14494 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014495 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbes280ba2c2015-06-12 11:16:41 +120014496
Tony Barbour5781e8f2015-08-04 16:23:11 -060014497 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbes280ba2c2015-06-12 11:16:41 +120014498
Chris Forbes8f36a8a2016-04-07 13:21:07 +120014499 m_errorMonitor->VerifyFound();
Chris Forbes280ba2c2015-06-12 11:16:41 +120014500}
Chris Forbes8f68b562015-05-25 11:13:32 +120014501
Chris Forbes35efec72016-04-21 14:32:08 +120014502TEST_F(VkLayerTest, CreatePipeline64BitAttributesPositive) {
Chris Forbes1cc79542016-07-20 11:13:44 +120014503 TEST_DESCRIPTION("Test that pipeline validation accepts basic use of 64bit vertex "
14504 "attributes. This is interesting because they consume multiple "
14505 "locations.");
Chris Forbes35efec72016-04-21 14:32:08 +120014506 m_errorMonitor->ExpectSuccess();
14507
14508 ASSERT_NO_FATAL_FAILURE(InitState());
14509 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
14510
Chris Forbes91cf3a82016-06-28 17:51:35 +120014511 if (!m_device->phy().features().shaderFloat64) {
Chris Forbes35efec72016-04-21 14:32:08 +120014512 printf("Device does not support 64bit vertex attributes; skipped.\n");
14513 return;
14514 }
14515
14516 VkVertexInputBindingDescription input_bindings[1];
14517 memset(input_bindings, 0, sizeof(input_bindings));
14518
14519 VkVertexInputAttributeDescription input_attribs[4];
14520 memset(input_attribs, 0, sizeof(input_attribs));
14521 input_attribs[0].location = 0;
14522 input_attribs[0].offset = 0;
14523 input_attribs[0].format = VK_FORMAT_R64G64B64A64_SFLOAT;
14524 input_attribs[1].location = 2;
14525 input_attribs[1].offset = 32;
14526 input_attribs[1].format = VK_FORMAT_R64G64B64A64_SFLOAT;
14527 input_attribs[2].location = 4;
14528 input_attribs[2].offset = 64;
14529 input_attribs[2].format = VK_FORMAT_R64G64B64A64_SFLOAT;
14530 input_attribs[3].location = 6;
14531 input_attribs[3].offset = 96;
14532 input_attribs[3].format = VK_FORMAT_R64G64B64A64_SFLOAT;
14533
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014534 char const *vsSource = "#version 450\n"
14535 "\n"
14536 "layout(location=0) in dmat4 x;\n"
14537 "out gl_PerVertex {\n"
14538 " vec4 gl_Position;\n"
14539 "};\n"
14540 "void main(){\n"
14541 " gl_Position = vec4(x[0][0]);\n"
14542 "}\n";
14543 char const *fsSource = "#version 450\n"
14544 "\n"
14545 "layout(location=0) out vec4 color;\n"
14546 "void main(){\n"
14547 " color = vec4(1);\n"
14548 "}\n";
Chris Forbes35efec72016-04-21 14:32:08 +120014549
14550 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
14551 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
14552
14553 VkPipelineObj pipe(m_device);
14554 pipe.AddColorAttachment();
14555 pipe.AddShader(&vs);
14556 pipe.AddShader(&fs);
14557
14558 pipe.AddVertexInputBindings(input_bindings, 1);
14559 pipe.AddVertexInputAttribs(input_attribs, 4);
14560
14561 VkDescriptorSetObj descriptorSet(m_device);
14562 descriptorSet.AppendDummy();
14563 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
14564
14565 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
14566
14567 m_errorMonitor->VerifyNotFound();
14568}
14569
Karl Schultz6addd812016-02-02 17:17:23 -070014570TEST_F(VkLayerTest, CreatePipelineFragmentOutputNotWritten) {
Chris Forbes1cc79542016-07-20 11:13:44 +120014571 TEST_DESCRIPTION("Test that an error is produced for a FS which does not "
14572 "provide an output for one of the pipeline's color attachments");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014573 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Attachment 0 not written by FS");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060014574
Chris Forbes4d6d1e52015-05-25 11:13:40 +120014575 ASSERT_NO_FATAL_FAILURE(InitState());
Chris Forbes4d6d1e52015-05-25 11:13:40 +120014576
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014577 char const *vsSource = "#version 450\n"
14578 "\n"
14579 "out gl_PerVertex {\n"
14580 " vec4 gl_Position;\n"
14581 "};\n"
14582 "void main(){\n"
14583 " gl_Position = vec4(1);\n"
14584 "}\n";
14585 char const *fsSource = "#version 450\n"
14586 "\n"
14587 "void main(){\n"
14588 "}\n";
Chris Forbes4d6d1e52015-05-25 11:13:40 +120014589
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060014590 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
14591 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbes4d6d1e52015-05-25 11:13:40 +120014592
14593 VkPipelineObj pipe(m_device);
14594 pipe.AddShader(&vs);
14595 pipe.AddShader(&fs);
14596
Chia-I Wu08accc62015-07-07 11:50:03 +080014597 /* set up CB 0, not written */
14598 pipe.AddColorAttachment();
14599 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbes4d6d1e52015-05-25 11:13:40 +120014600
Chris Forbes4d6d1e52015-05-25 11:13:40 +120014601 VkDescriptorSetObj descriptorSet(m_device);
14602 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014603 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbes4d6d1e52015-05-25 11:13:40 +120014604
Tony Barbour5781e8f2015-08-04 16:23:11 -060014605 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbes4d6d1e52015-05-25 11:13:40 +120014606
Chris Forbes8f36a8a2016-04-07 13:21:07 +120014607 m_errorMonitor->VerifyFound();
Chris Forbes4d6d1e52015-05-25 11:13:40 +120014608}
14609
Karl Schultz6addd812016-02-02 17:17:23 -070014610TEST_F(VkLayerTest, CreatePipelineFragmentOutputNotConsumed) {
Chris Forbes1cc79542016-07-20 11:13:44 +120014611 TEST_DESCRIPTION("Test that a warning is produced for a FS which provides a spurious "
14612 "output with no matching attachment");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014613 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT,
14614 "FS writes to output location 1 with no matching attachment");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060014615
Chris Forbesf3fffaa2015-05-25 11:13:43 +120014616 ASSERT_NO_FATAL_FAILURE(InitState());
Chris Forbesf3fffaa2015-05-25 11:13:43 +120014617
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014618 char const *vsSource = "#version 450\n"
14619 "\n"
14620 "out gl_PerVertex {\n"
14621 " vec4 gl_Position;\n"
14622 "};\n"
14623 "void main(){\n"
14624 " gl_Position = vec4(1);\n"
14625 "}\n";
14626 char const *fsSource = "#version 450\n"
14627 "\n"
14628 "layout(location=0) out vec4 x;\n"
14629 "layout(location=1) out vec4 y;\n" /* no matching attachment for this */
14630 "void main(){\n"
14631 " x = vec4(1);\n"
14632 " y = vec4(1);\n"
14633 "}\n";
Chris Forbesf3fffaa2015-05-25 11:13:43 +120014634
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060014635 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
14636 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbesf3fffaa2015-05-25 11:13:43 +120014637
14638 VkPipelineObj pipe(m_device);
14639 pipe.AddShader(&vs);
14640 pipe.AddShader(&fs);
14641
Chia-I Wu08accc62015-07-07 11:50:03 +080014642 /* set up CB 0, not written */
14643 pipe.AddColorAttachment();
14644 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbesf3fffaa2015-05-25 11:13:43 +120014645 /* FS writes CB 1, but we don't configure it */
14646
Chris Forbesf3fffaa2015-05-25 11:13:43 +120014647 VkDescriptorSetObj descriptorSet(m_device);
14648 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014649 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbesf3fffaa2015-05-25 11:13:43 +120014650
Tony Barbour5781e8f2015-08-04 16:23:11 -060014651 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbesf3fffaa2015-05-25 11:13:43 +120014652
Chris Forbes8f36a8a2016-04-07 13:21:07 +120014653 m_errorMonitor->VerifyFound();
Chris Forbesf3fffaa2015-05-25 11:13:43 +120014654}
14655
Karl Schultz6addd812016-02-02 17:17:23 -070014656TEST_F(VkLayerTest, CreatePipelineFragmentOutputTypeMismatch) {
Chris Forbes1cc79542016-07-20 11:13:44 +120014657 TEST_DESCRIPTION("Test that an error is produced for a mismatch between the fundamental "
14658 "type of an FS output variable, and the format of the corresponding attachment");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014659 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "does not match FS output type");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060014660
Chris Forbesa36d69e2015-05-25 11:13:44 +120014661 ASSERT_NO_FATAL_FAILURE(InitState());
Chris Forbesa36d69e2015-05-25 11:13:44 +120014662
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014663 char const *vsSource = "#version 450\n"
14664 "\n"
14665 "out gl_PerVertex {\n"
14666 " vec4 gl_Position;\n"
14667 "};\n"
14668 "void main(){\n"
14669 " gl_Position = vec4(1);\n"
14670 "}\n";
14671 char const *fsSource = "#version 450\n"
14672 "\n"
14673 "layout(location=0) out ivec4 x;\n" /* not UNORM */
14674 "void main(){\n"
14675 " x = ivec4(1);\n"
14676 "}\n";
Chris Forbesa36d69e2015-05-25 11:13:44 +120014677
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060014678 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
14679 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbesa36d69e2015-05-25 11:13:44 +120014680
14681 VkPipelineObj pipe(m_device);
14682 pipe.AddShader(&vs);
14683 pipe.AddShader(&fs);
14684
Chia-I Wu08accc62015-07-07 11:50:03 +080014685 /* set up CB 0; type is UNORM by default */
14686 pipe.AddColorAttachment();
14687 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbesa36d69e2015-05-25 11:13:44 +120014688
Chris Forbesa36d69e2015-05-25 11:13:44 +120014689 VkDescriptorSetObj descriptorSet(m_device);
14690 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014691 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbesa36d69e2015-05-25 11:13:44 +120014692
Tony Barbour5781e8f2015-08-04 16:23:11 -060014693 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbesa36d69e2015-05-25 11:13:44 +120014694
Chris Forbes8f36a8a2016-04-07 13:21:07 +120014695 m_errorMonitor->VerifyFound();
Chris Forbesa36d69e2015-05-25 11:13:44 +120014696}
Chris Forbes7b1b8932015-06-05 14:43:36 +120014697
Karl Schultz6addd812016-02-02 17:17:23 -070014698TEST_F(VkLayerTest, CreatePipelineUniformBlockNotProvided) {
Chris Forbes1cc79542016-07-20 11:13:44 +120014699 TEST_DESCRIPTION("Test that an error is produced for a shader consuming a uniform "
14700 "block which has no corresponding binding in the pipeline layout");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014701 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "not declared in pipeline layout");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060014702
Chris Forbes556c76c2015-08-14 12:04:59 +120014703 ASSERT_NO_FATAL_FAILURE(InitState());
Chris Forbes556c76c2015-08-14 12:04:59 +120014704
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014705 char const *vsSource = "#version 450\n"
14706 "\n"
14707 "out gl_PerVertex {\n"
14708 " vec4 gl_Position;\n"
14709 "};\n"
14710 "void main(){\n"
14711 " gl_Position = vec4(1);\n"
14712 "}\n";
14713 char const *fsSource = "#version 450\n"
14714 "\n"
14715 "layout(location=0) out vec4 x;\n"
14716 "layout(set=0) layout(binding=0) uniform foo { int x; int y; } bar;\n"
14717 "void main(){\n"
14718 " x = vec4(bar.y);\n"
14719 "}\n";
Chris Forbes556c76c2015-08-14 12:04:59 +120014720
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060014721 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
14722 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbes556c76c2015-08-14 12:04:59 +120014723
Chris Forbes556c76c2015-08-14 12:04:59 +120014724 VkPipelineObj pipe(m_device);
14725 pipe.AddShader(&vs);
14726 pipe.AddShader(&fs);
14727
14728 /* set up CB 0; type is UNORM by default */
14729 pipe.AddColorAttachment();
14730 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
14731
14732 VkDescriptorSetObj descriptorSet(m_device);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014733 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbes556c76c2015-08-14 12:04:59 +120014734
14735 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
14736
Chris Forbes8f36a8a2016-04-07 13:21:07 +120014737 m_errorMonitor->VerifyFound();
Chris Forbes556c76c2015-08-14 12:04:59 +120014738}
14739
Chris Forbes5c59e902016-02-26 16:56:09 +130014740TEST_F(VkLayerTest, CreatePipelinePushConstantsNotInLayout) {
Chris Forbes1cc79542016-07-20 11:13:44 +120014741 TEST_DESCRIPTION("Test that an error is produced for a shader consuming push constants "
14742 "which are not provided in the pipeline layout");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014743 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "not declared in layout");
Chris Forbes5c59e902016-02-26 16:56:09 +130014744
14745 ASSERT_NO_FATAL_FAILURE(InitState());
14746
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014747 char const *vsSource = "#version 450\n"
14748 "\n"
14749 "layout(push_constant, std430) uniform foo { float x; } consts;\n"
14750 "out gl_PerVertex {\n"
14751 " vec4 gl_Position;\n"
14752 "};\n"
14753 "void main(){\n"
14754 " gl_Position = vec4(consts.x);\n"
14755 "}\n";
14756 char const *fsSource = "#version 450\n"
14757 "\n"
14758 "layout(location=0) out vec4 x;\n"
14759 "void main(){\n"
14760 " x = vec4(1);\n"
14761 "}\n";
Chris Forbes5c59e902016-02-26 16:56:09 +130014762
14763 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
14764 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
14765
14766 VkPipelineObj pipe(m_device);
14767 pipe.AddShader(&vs);
14768 pipe.AddShader(&fs);
14769
14770 /* set up CB 0; type is UNORM by default */
14771 pipe.AddColorAttachment();
14772 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
14773
14774 VkDescriptorSetObj descriptorSet(m_device);
14775 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
14776
14777 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
14778
14779 /* should have generated an error -- no push constant ranges provided! */
Chris Forbes8f36a8a2016-04-07 13:21:07 +120014780 m_errorMonitor->VerifyFound();
Chris Forbes5c59e902016-02-26 16:56:09 +130014781}
14782
Chris Forbes3fb17902016-08-22 14:57:55 +120014783TEST_F(VkLayerTest, CreatePipelineInputAttachmentMissing) {
14784 TEST_DESCRIPTION("Test that an error is produced for a shader consuming an input attachment "
14785 "which is not included in the subpass description");
14786 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
14787 "consumes input attachment index 0 but not provided in subpass");
14788
14789 ASSERT_NO_FATAL_FAILURE(InitState());
14790
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014791 char const *vsSource = "#version 450\n"
14792 "\n"
14793 "out gl_PerVertex {\n"
14794 " vec4 gl_Position;\n"
14795 "};\n"
14796 "void main(){\n"
14797 " gl_Position = vec4(1);\n"
14798 "}\n";
14799 char const *fsSource = "#version 450\n"
14800 "\n"
14801 "layout(input_attachment_index=0, set=0, binding=0) uniform subpassInput x;\n"
14802 "layout(location=0) out vec4 color;\n"
14803 "void main() {\n"
14804 " color = subpassLoad(x);\n"
14805 "}\n";
Chris Forbes3fb17902016-08-22 14:57:55 +120014806
14807 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
14808 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
14809
14810 VkPipelineObj pipe(m_device);
14811 pipe.AddShader(&vs);
14812 pipe.AddShader(&fs);
14813 pipe.AddColorAttachment();
14814 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
14815
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014816 VkDescriptorSetLayoutBinding dslb = {0, VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT, 1, VK_SHADER_STAGE_FRAGMENT_BIT, nullptr};
14817 VkDescriptorSetLayoutCreateInfo dslci = {VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dslb};
Chris Forbes3fb17902016-08-22 14:57:55 +120014818 VkDescriptorSetLayout dsl;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014819 VkResult err = vkCreateDescriptorSetLayout(m_device->device(), &dslci, nullptr, &dsl);
Chris Forbes3fb17902016-08-22 14:57:55 +120014820 ASSERT_VK_SUCCESS(err);
14821
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014822 VkPipelineLayoutCreateInfo plci = {VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dsl, 0, nullptr};
Chris Forbes3fb17902016-08-22 14:57:55 +120014823 VkPipelineLayout pl;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014824 err = vkCreatePipelineLayout(m_device->device(), &plci, nullptr, &pl);
Chris Forbes3fb17902016-08-22 14:57:55 +120014825 ASSERT_VK_SUCCESS(err);
14826
14827 // error here.
14828 pipe.CreateVKPipeline(pl, renderPass());
14829
14830 m_errorMonitor->VerifyFound();
14831
14832 vkDestroyPipelineLayout(m_device->device(), pl, nullptr);
14833 vkDestroyDescriptorSetLayout(m_device->device(), dsl, nullptr);
14834}
14835
Chris Forbes663b5a82016-08-22 16:14:06 +120014836TEST_F(VkLayerTest, CreatePipelineInputAttachmentPositive) {
14837 TEST_DESCRIPTION("Positive test for a correctly matched input attachment");
14838 m_errorMonitor->ExpectSuccess();
14839
14840 ASSERT_NO_FATAL_FAILURE(InitState());
14841
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014842 char const *vsSource = "#version 450\n"
14843 "\n"
14844 "out gl_PerVertex {\n"
14845 " vec4 gl_Position;\n"
14846 "};\n"
14847 "void main(){\n"
14848 " gl_Position = vec4(1);\n"
14849 "}\n";
14850 char const *fsSource = "#version 450\n"
14851 "\n"
14852 "layout(input_attachment_index=0, set=0, binding=0) uniform subpassInput x;\n"
14853 "layout(location=0) out vec4 color;\n"
14854 "void main() {\n"
14855 " color = subpassLoad(x);\n"
14856 "}\n";
Chris Forbes663b5a82016-08-22 16:14:06 +120014857
14858 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
14859 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
14860
14861 VkPipelineObj pipe(m_device);
14862 pipe.AddShader(&vs);
14863 pipe.AddShader(&fs);
14864 pipe.AddColorAttachment();
14865 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
14866
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014867 VkDescriptorSetLayoutBinding dslb = {0, VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT, 1, VK_SHADER_STAGE_FRAGMENT_BIT, nullptr};
14868 VkDescriptorSetLayoutCreateInfo dslci = {VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dslb};
Chris Forbes663b5a82016-08-22 16:14:06 +120014869 VkDescriptorSetLayout dsl;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014870 VkResult err = vkCreateDescriptorSetLayout(m_device->device(), &dslci, nullptr, &dsl);
Chris Forbes663b5a82016-08-22 16:14:06 +120014871 ASSERT_VK_SUCCESS(err);
14872
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014873 VkPipelineLayoutCreateInfo plci = {VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dsl, 0, nullptr};
Chris Forbes663b5a82016-08-22 16:14:06 +120014874 VkPipelineLayout pl;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014875 err = vkCreatePipelineLayout(m_device->device(), &plci, nullptr, &pl);
Chris Forbes663b5a82016-08-22 16:14:06 +120014876 ASSERT_VK_SUCCESS(err);
14877
14878 VkAttachmentDescription descs[2] = {
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014879 {0, VK_FORMAT_R8G8B8A8_UNORM, VK_SAMPLE_COUNT_1_BIT, VK_ATTACHMENT_LOAD_OP_LOAD, VK_ATTACHMENT_STORE_OP_STORE,
14880 VK_ATTACHMENT_LOAD_OP_LOAD, VK_ATTACHMENT_STORE_OP_STORE, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
14881 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL},
14882 {0, VK_FORMAT_R8G8B8A8_UNORM, VK_SAMPLE_COUNT_1_BIT, VK_ATTACHMENT_LOAD_OP_LOAD, VK_ATTACHMENT_STORE_OP_STORE,
14883 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 +120014884 };
14885 VkAttachmentReference color = {
14886 0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
14887 };
14888 VkAttachmentReference input = {
14889 1, VK_IMAGE_LAYOUT_GENERAL,
14890 };
14891
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014892 VkSubpassDescription sd = {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 1, &input, 1, &color, nullptr, nullptr, 0, nullptr};
Chris Forbes663b5a82016-08-22 16:14:06 +120014893
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014894 VkRenderPassCreateInfo rpci = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 2, descs, 1, &sd, 0, nullptr};
Chris Forbes663b5a82016-08-22 16:14:06 +120014895 VkRenderPass rp;
14896 err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
14897 ASSERT_VK_SUCCESS(err);
14898
14899 // should be OK. would go wrong here if it's going to...
14900 pipe.CreateVKPipeline(pl, rp);
14901
14902 m_errorMonitor->VerifyNotFound();
14903
14904 vkDestroyRenderPass(m_device->device(), rp, nullptr);
14905 vkDestroyPipelineLayout(m_device->device(), pl, nullptr);
14906 vkDestroyDescriptorSetLayout(m_device->device(), dsl, nullptr);
14907}
14908
Chris Forbes5a9a0472016-08-22 16:02:09 +120014909TEST_F(VkLayerTest, CreatePipelineInputAttachmentTypeMismatch) {
14910 TEST_DESCRIPTION("Test that an error is produced for a shader consuming an input attachment "
14911 "with a format having a different fundamental type");
14912 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
14913 "input attachment 0 format of VK_FORMAT_R8G8B8A8_UINT does not match");
14914
14915 ASSERT_NO_FATAL_FAILURE(InitState());
14916
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014917 char const *vsSource = "#version 450\n"
14918 "\n"
14919 "out gl_PerVertex {\n"
14920 " vec4 gl_Position;\n"
14921 "};\n"
14922 "void main(){\n"
14923 " gl_Position = vec4(1);\n"
14924 "}\n";
14925 char const *fsSource = "#version 450\n"
14926 "\n"
14927 "layout(input_attachment_index=0, set=0, binding=0) uniform subpassInput x;\n"
14928 "layout(location=0) out vec4 color;\n"
14929 "void main() {\n"
14930 " color = subpassLoad(x);\n"
14931 "}\n";
Chris Forbes5a9a0472016-08-22 16:02:09 +120014932
14933 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
14934 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
14935
14936 VkPipelineObj pipe(m_device);
14937 pipe.AddShader(&vs);
14938 pipe.AddShader(&fs);
14939 pipe.AddColorAttachment();
14940 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
14941
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014942 VkDescriptorSetLayoutBinding dslb = {0, VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT, 1, VK_SHADER_STAGE_FRAGMENT_BIT, nullptr};
14943 VkDescriptorSetLayoutCreateInfo dslci = {VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dslb};
Chris Forbes5a9a0472016-08-22 16:02:09 +120014944 VkDescriptorSetLayout dsl;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014945 VkResult err = vkCreateDescriptorSetLayout(m_device->device(), &dslci, nullptr, &dsl);
Chris Forbes5a9a0472016-08-22 16:02:09 +120014946 ASSERT_VK_SUCCESS(err);
14947
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014948 VkPipelineLayoutCreateInfo plci = {VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dsl, 0, nullptr};
Chris Forbes5a9a0472016-08-22 16:02:09 +120014949 VkPipelineLayout pl;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014950 err = vkCreatePipelineLayout(m_device->device(), &plci, nullptr, &pl);
Chris Forbes5a9a0472016-08-22 16:02:09 +120014951 ASSERT_VK_SUCCESS(err);
14952
14953 VkAttachmentDescription descs[2] = {
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014954 {0, VK_FORMAT_R8G8B8A8_UNORM, VK_SAMPLE_COUNT_1_BIT, VK_ATTACHMENT_LOAD_OP_LOAD, VK_ATTACHMENT_STORE_OP_STORE,
14955 VK_ATTACHMENT_LOAD_OP_LOAD, VK_ATTACHMENT_STORE_OP_STORE, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
14956 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL},
14957 {0, VK_FORMAT_R8G8B8A8_UINT, VK_SAMPLE_COUNT_1_BIT, VK_ATTACHMENT_LOAD_OP_LOAD, VK_ATTACHMENT_STORE_OP_STORE,
14958 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 +120014959 };
14960 VkAttachmentReference color = {
14961 0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
14962 };
14963 VkAttachmentReference input = {
14964 1, VK_IMAGE_LAYOUT_GENERAL,
14965 };
14966
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014967 VkSubpassDescription sd = {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 1, &input, 1, &color, nullptr, nullptr, 0, nullptr};
Chris Forbes5a9a0472016-08-22 16:02:09 +120014968
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014969 VkRenderPassCreateInfo rpci = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 2, descs, 1, &sd, 0, nullptr};
Chris Forbes5a9a0472016-08-22 16:02:09 +120014970 VkRenderPass rp;
14971 err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
14972 ASSERT_VK_SUCCESS(err);
14973
14974 // error here.
14975 pipe.CreateVKPipeline(pl, rp);
14976
14977 m_errorMonitor->VerifyFound();
14978
14979 vkDestroyRenderPass(m_device->device(), rp, nullptr);
14980 vkDestroyPipelineLayout(m_device->device(), pl, nullptr);
14981 vkDestroyDescriptorSetLayout(m_device->device(), dsl, nullptr);
14982}
14983
Chris Forbes541f7b02016-08-22 15:30:27 +120014984TEST_F(VkLayerTest, CreatePipelineInputAttachmentMissingArray) {
14985 TEST_DESCRIPTION("Test that an error is produced for a shader consuming an input attachment "
14986 "which is not included in the subpass description -- array case");
14987 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
14988 "consumes input attachment index 1 but not provided in subpass");
14989
14990 ASSERT_NO_FATAL_FAILURE(InitState());
14991
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014992 char const *vsSource = "#version 450\n"
14993 "\n"
14994 "out gl_PerVertex {\n"
14995 " vec4 gl_Position;\n"
14996 "};\n"
14997 "void main(){\n"
14998 " gl_Position = vec4(1);\n"
14999 "}\n";
15000 char const *fsSource = "#version 450\n"
15001 "\n"
15002 "layout(input_attachment_index=0, set=0, binding=0) uniform subpassInput xs[2];\n"
15003 "layout(location=0) out vec4 color;\n"
15004 "void main() {\n"
15005 " color = subpassLoad(xs[1]);\n"
15006 "}\n";
Chris Forbes541f7b02016-08-22 15:30:27 +120015007
15008 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
15009 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
15010
15011 VkPipelineObj pipe(m_device);
15012 pipe.AddShader(&vs);
15013 pipe.AddShader(&fs);
15014 pipe.AddColorAttachment();
15015 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
15016
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015017 VkDescriptorSetLayoutBinding dslb = {0, VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT, 2, VK_SHADER_STAGE_FRAGMENT_BIT, nullptr};
15018 VkDescriptorSetLayoutCreateInfo dslci = {VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dslb};
Chris Forbes541f7b02016-08-22 15:30:27 +120015019 VkDescriptorSetLayout dsl;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015020 VkResult err = vkCreateDescriptorSetLayout(m_device->device(), &dslci, nullptr, &dsl);
Chris Forbes541f7b02016-08-22 15:30:27 +120015021 ASSERT_VK_SUCCESS(err);
15022
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015023 VkPipelineLayoutCreateInfo plci = {VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dsl, 0, nullptr};
Chris Forbes541f7b02016-08-22 15:30:27 +120015024 VkPipelineLayout pl;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015025 err = vkCreatePipelineLayout(m_device->device(), &plci, nullptr, &pl);
Chris Forbes541f7b02016-08-22 15:30:27 +120015026 ASSERT_VK_SUCCESS(err);
15027
15028 // error here.
15029 pipe.CreateVKPipeline(pl, renderPass());
15030
15031 m_errorMonitor->VerifyFound();
15032
15033 vkDestroyPipelineLayout(m_device->device(), pl, nullptr);
15034 vkDestroyDescriptorSetLayout(m_device->device(), dsl, nullptr);
15035}
15036
Chris Forbes10eb9ae2016-05-31 16:09:42 +120015037TEST_F(VkLayerTest, CreateComputePipelineMissingDescriptor) {
Chris Forbes1cc79542016-07-20 11:13:44 +120015038 TEST_DESCRIPTION("Test that an error is produced for a compute pipeline consuming a "
15039 "descriptor which is not provided in the pipeline layout");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015040 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Shader uses descriptor slot 0.0");
Chris Forbes10eb9ae2016-05-31 16:09:42 +120015041
15042 ASSERT_NO_FATAL_FAILURE(InitState());
15043
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015044 char const *csSource = "#version 450\n"
15045 "\n"
15046 "layout(local_size_x=1) in;\n"
15047 "layout(set=0, binding=0) buffer block { vec4 x; };\n"
15048 "void main(){\n"
15049 " x = vec4(1);\n"
15050 "}\n";
Chris Forbes10eb9ae2016-05-31 16:09:42 +120015051
15052 VkShaderObj cs(m_device, csSource, VK_SHADER_STAGE_COMPUTE_BIT, this);
15053
15054 VkDescriptorSetObj descriptorSet(m_device);
15055 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
15056
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015057 VkComputePipelineCreateInfo cpci = {VK_STRUCTURE_TYPE_COMPUTE_PIPELINE_CREATE_INFO,
15058 nullptr,
15059 0,
15060 {VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO, nullptr, 0,
15061 VK_SHADER_STAGE_COMPUTE_BIT, cs.handle(), "main", nullptr},
15062 descriptorSet.GetPipelineLayout(),
15063 VK_NULL_HANDLE,
15064 -1};
Chris Forbes10eb9ae2016-05-31 16:09:42 +120015065
15066 VkPipeline pipe;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015067 VkResult err = vkCreateComputePipelines(m_device->device(), VK_NULL_HANDLE, 1, &cpci, nullptr, &pipe);
Chris Forbes10eb9ae2016-05-31 16:09:42 +120015068
15069 m_errorMonitor->VerifyFound();
15070
15071 if (err == VK_SUCCESS) {
15072 vkDestroyPipeline(m_device->device(), pipe, nullptr);
15073 }
15074}
15075
15076TEST_F(VkLayerTest, CreateComputePipelineMissingDescriptorUnusedPositive) {
Chris Forbes1cc79542016-07-20 11:13:44 +120015077 TEST_DESCRIPTION("Test that pipeline validation accepts a compute pipeline which declares a "
15078 "descriptor-backed resource which is not provided, but the shader does not "
15079 "statically use it. This is interesting because it requires compute pipelines "
15080 "to have a proper descriptor use walk, which they didn't for some time.");
Chris Forbes10eb9ae2016-05-31 16:09:42 +120015081 m_errorMonitor->ExpectSuccess();
15082
15083 ASSERT_NO_FATAL_FAILURE(InitState());
15084
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015085 char const *csSource = "#version 450\n"
15086 "\n"
15087 "layout(local_size_x=1) in;\n"
15088 "layout(set=0, binding=0) buffer block { vec4 x; };\n"
15089 "void main(){\n"
15090 " // x is not used.\n"
15091 "}\n";
Chris Forbes10eb9ae2016-05-31 16:09:42 +120015092
15093 VkShaderObj cs(m_device, csSource, VK_SHADER_STAGE_COMPUTE_BIT, this);
15094
15095 VkDescriptorSetObj descriptorSet(m_device);
15096 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
15097
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015098 VkComputePipelineCreateInfo cpci = {VK_STRUCTURE_TYPE_COMPUTE_PIPELINE_CREATE_INFO,
15099 nullptr,
15100 0,
15101 {VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO, nullptr, 0,
15102 VK_SHADER_STAGE_COMPUTE_BIT, cs.handle(), "main", nullptr},
15103 descriptorSet.GetPipelineLayout(),
15104 VK_NULL_HANDLE,
15105 -1};
Chris Forbes10eb9ae2016-05-31 16:09:42 +120015106
15107 VkPipeline pipe;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015108 VkResult err = vkCreateComputePipelines(m_device->device(), VK_NULL_HANDLE, 1, &cpci, nullptr, &pipe);
Chris Forbes10eb9ae2016-05-31 16:09:42 +120015109
15110 m_errorMonitor->VerifyNotFound();
15111
15112 if (err == VK_SUCCESS) {
15113 vkDestroyPipeline(m_device->device(), pipe, nullptr);
15114 }
15115}
15116
Chris Forbes22a9b092016-07-19 14:34:05 +120015117TEST_F(VkLayerTest, CreateComputePipelineDescriptorTypeMismatch) {
Chris Forbes1cc79542016-07-20 11:13:44 +120015118 TEST_DESCRIPTION("Test that an error is produced for a pipeline consuming a "
15119 "descriptor-backed resource of a mismatched type");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015120 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
15121 "but descriptor of type VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER");
Chris Forbes22a9b092016-07-19 14:34:05 +120015122
15123 ASSERT_NO_FATAL_FAILURE(InitState());
15124
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015125 VkDescriptorSetLayoutBinding binding = {0, VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, 1, VK_SHADER_STAGE_COMPUTE_BIT, nullptr};
15126 VkDescriptorSetLayoutCreateInfo dslci = {VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO, nullptr, 0, 1, &binding};
Chris Forbes22a9b092016-07-19 14:34:05 +120015127 VkDescriptorSetLayout dsl;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015128 VkResult err = vkCreateDescriptorSetLayout(m_device->device(), &dslci, nullptr, &dsl);
Chris Forbes22a9b092016-07-19 14:34:05 +120015129 ASSERT_VK_SUCCESS(err);
15130
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015131 VkPipelineLayoutCreateInfo plci = {VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dsl, 0, nullptr};
Chris Forbes22a9b092016-07-19 14:34:05 +120015132 VkPipelineLayout pl;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015133 err = vkCreatePipelineLayout(m_device->device(), &plci, nullptr, &pl);
Chris Forbes22a9b092016-07-19 14:34:05 +120015134 ASSERT_VK_SUCCESS(err);
15135
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015136 char const *csSource = "#version 450\n"
15137 "\n"
15138 "layout(local_size_x=1) in;\n"
15139 "layout(set=0, binding=0) buffer block { vec4 x; };\n"
15140 "void main() {\n"
15141 " x.x = 1.0f;\n"
15142 "}\n";
Chris Forbes22a9b092016-07-19 14:34:05 +120015143 VkShaderObj cs(m_device, csSource, VK_SHADER_STAGE_COMPUTE_BIT, this);
15144
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015145 VkComputePipelineCreateInfo cpci = {VK_STRUCTURE_TYPE_COMPUTE_PIPELINE_CREATE_INFO,
15146 nullptr,
15147 0,
15148 {VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO, nullptr, 0,
15149 VK_SHADER_STAGE_COMPUTE_BIT, cs.handle(), "main", nullptr},
15150 pl,
15151 VK_NULL_HANDLE,
15152 -1};
Chris Forbes22a9b092016-07-19 14:34:05 +120015153
15154 VkPipeline pipe;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015155 err = vkCreateComputePipelines(m_device->device(), VK_NULL_HANDLE, 1, &cpci, nullptr, &pipe);
Chris Forbes22a9b092016-07-19 14:34:05 +120015156
15157 m_errorMonitor->VerifyFound();
15158
15159 if (err == VK_SUCCESS) {
15160 vkDestroyPipeline(m_device->device(), pipe, nullptr);
15161 }
15162
15163 vkDestroyPipelineLayout(m_device->device(), pl, nullptr);
15164 vkDestroyDescriptorSetLayout(m_device->device(), dsl, nullptr);
15165}
15166
Chris Forbese10a51f2016-07-19 14:42:51 +120015167TEST_F(VkLayerTest, CreateComputePipelineCombinedImageSamplerConsumedAsSampler) {
Chris Forbes1cc79542016-07-20 11:13:44 +120015168 TEST_DESCRIPTION("Test that pipeline validation accepts a shader consuming only the "
15169 "sampler portion of a combined image + sampler");
Chris Forbese10a51f2016-07-19 14:42:51 +120015170 m_errorMonitor->ExpectSuccess();
15171
15172 ASSERT_NO_FATAL_FAILURE(InitState());
15173
15174 VkDescriptorSetLayoutBinding bindings[] = {
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015175 {0, VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, 1, VK_SHADER_STAGE_COMPUTE_BIT, nullptr},
15176 {1, VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE, 1, VK_SHADER_STAGE_COMPUTE_BIT, nullptr},
15177 {2, VK_DESCRIPTOR_TYPE_STORAGE_BUFFER, 1, VK_SHADER_STAGE_COMPUTE_BIT, nullptr},
Chris Forbese10a51f2016-07-19 14:42:51 +120015178 };
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015179 VkDescriptorSetLayoutCreateInfo dslci = {VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO, nullptr, 0, 3, bindings};
Chris Forbese10a51f2016-07-19 14:42:51 +120015180 VkDescriptorSetLayout dsl;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015181 VkResult err = vkCreateDescriptorSetLayout(m_device->device(), &dslci, nullptr, &dsl);
Chris Forbese10a51f2016-07-19 14:42:51 +120015182 ASSERT_VK_SUCCESS(err);
15183
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015184 VkPipelineLayoutCreateInfo plci = {VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dsl, 0, nullptr};
Chris Forbese10a51f2016-07-19 14:42:51 +120015185 VkPipelineLayout pl;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015186 err = vkCreatePipelineLayout(m_device->device(), &plci, nullptr, &pl);
Chris Forbese10a51f2016-07-19 14:42:51 +120015187 ASSERT_VK_SUCCESS(err);
15188
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015189 char const *csSource = "#version 450\n"
15190 "\n"
15191 "layout(local_size_x=1) in;\n"
15192 "layout(set=0, binding=0) uniform sampler s;\n"
15193 "layout(set=0, binding=1) uniform texture2D t;\n"
15194 "layout(set=0, binding=2) buffer block { vec4 x; };\n"
15195 "void main() {\n"
15196 " x = texture(sampler2D(t, s), vec2(0));\n"
15197 "}\n";
Chris Forbese10a51f2016-07-19 14:42:51 +120015198 VkShaderObj cs(m_device, csSource, VK_SHADER_STAGE_COMPUTE_BIT, this);
15199
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015200 VkComputePipelineCreateInfo cpci = {VK_STRUCTURE_TYPE_COMPUTE_PIPELINE_CREATE_INFO,
15201 nullptr,
15202 0,
15203 {VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO, nullptr, 0,
15204 VK_SHADER_STAGE_COMPUTE_BIT, cs.handle(), "main", nullptr},
15205 pl,
15206 VK_NULL_HANDLE,
15207 -1};
Chris Forbese10a51f2016-07-19 14:42:51 +120015208
15209 VkPipeline pipe;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015210 err = vkCreateComputePipelines(m_device->device(), VK_NULL_HANDLE, 1, &cpci, nullptr, &pipe);
Chris Forbese10a51f2016-07-19 14:42:51 +120015211
15212 m_errorMonitor->VerifyNotFound();
15213
15214 if (err == VK_SUCCESS) {
15215 vkDestroyPipeline(m_device->device(), pipe, nullptr);
15216 }
15217
15218 vkDestroyPipelineLayout(m_device->device(), pl, nullptr);
15219 vkDestroyDescriptorSetLayout(m_device->device(), dsl, nullptr);
15220}
15221
Chris Forbes91c3b2a2016-07-19 14:46:38 +120015222TEST_F(VkLayerTest, CreateComputePipelineCombinedImageSamplerConsumedAsImage) {
Chris Forbes1cc79542016-07-20 11:13:44 +120015223 TEST_DESCRIPTION("Test that pipeline validation accepts a shader consuming only the "
15224 "image portion of a combined image + sampler");
Chris Forbes91c3b2a2016-07-19 14:46:38 +120015225 m_errorMonitor->ExpectSuccess();
15226
15227 ASSERT_NO_FATAL_FAILURE(InitState());
15228
15229 VkDescriptorSetLayoutBinding bindings[] = {
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015230 {0, VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, 1, VK_SHADER_STAGE_COMPUTE_BIT, nullptr},
15231 {1, VK_DESCRIPTOR_TYPE_SAMPLER, 1, VK_SHADER_STAGE_COMPUTE_BIT, nullptr},
15232 {2, VK_DESCRIPTOR_TYPE_STORAGE_BUFFER, 1, VK_SHADER_STAGE_COMPUTE_BIT, nullptr},
Chris Forbes91c3b2a2016-07-19 14:46:38 +120015233 };
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015234 VkDescriptorSetLayoutCreateInfo dslci = {VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO, nullptr, 0, 3, bindings};
Chris Forbes91c3b2a2016-07-19 14:46:38 +120015235 VkDescriptorSetLayout dsl;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015236 VkResult err = vkCreateDescriptorSetLayout(m_device->device(), &dslci, nullptr, &dsl);
Chris Forbes91c3b2a2016-07-19 14:46:38 +120015237 ASSERT_VK_SUCCESS(err);
15238
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015239 VkPipelineLayoutCreateInfo plci = {VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dsl, 0, nullptr};
Chris Forbes91c3b2a2016-07-19 14:46:38 +120015240 VkPipelineLayout pl;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015241 err = vkCreatePipelineLayout(m_device->device(), &plci, nullptr, &pl);
Chris Forbes91c3b2a2016-07-19 14:46:38 +120015242 ASSERT_VK_SUCCESS(err);
15243
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015244 char const *csSource = "#version 450\n"
15245 "\n"
15246 "layout(local_size_x=1) in;\n"
15247 "layout(set=0, binding=0) uniform texture2D t;\n"
15248 "layout(set=0, binding=1) uniform sampler s;\n"
15249 "layout(set=0, binding=2) buffer block { vec4 x; };\n"
15250 "void main() {\n"
15251 " x = texture(sampler2D(t, s), vec2(0));\n"
15252 "}\n";
Chris Forbes91c3b2a2016-07-19 14:46:38 +120015253 VkShaderObj cs(m_device, csSource, VK_SHADER_STAGE_COMPUTE_BIT, this);
15254
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015255 VkComputePipelineCreateInfo cpci = {VK_STRUCTURE_TYPE_COMPUTE_PIPELINE_CREATE_INFO,
15256 nullptr,
15257 0,
15258 {VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO, nullptr, 0,
15259 VK_SHADER_STAGE_COMPUTE_BIT, cs.handle(), "main", nullptr},
15260 pl,
15261 VK_NULL_HANDLE,
15262 -1};
Chris Forbes91c3b2a2016-07-19 14:46:38 +120015263
15264 VkPipeline pipe;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015265 err = vkCreateComputePipelines(m_device->device(), VK_NULL_HANDLE, 1, &cpci, nullptr, &pipe);
Chris Forbes91c3b2a2016-07-19 14:46:38 +120015266
15267 m_errorMonitor->VerifyNotFound();
15268
15269 if (err == VK_SUCCESS) {
15270 vkDestroyPipeline(m_device->device(), pipe, nullptr);
15271 }
15272
15273 vkDestroyPipelineLayout(m_device->device(), pl, nullptr);
15274 vkDestroyDescriptorSetLayout(m_device->device(), dsl, nullptr);
15275}
15276
Chris Forbes6a4991a2016-07-19 15:07:32 +120015277TEST_F(VkLayerTest, CreateComputePipelineCombinedImageSamplerConsumedAsBoth) {
Chris Forbes1cc79542016-07-20 11:13:44 +120015278 TEST_DESCRIPTION("Test that pipeline validation accepts a shader consuming "
15279 "both the sampler and the image of a combined image+sampler "
15280 "but via separate variables");
Chris Forbes6a4991a2016-07-19 15:07:32 +120015281 m_errorMonitor->ExpectSuccess();
15282
15283 ASSERT_NO_FATAL_FAILURE(InitState());
15284
15285 VkDescriptorSetLayoutBinding bindings[] = {
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015286 {0, VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, 1, VK_SHADER_STAGE_COMPUTE_BIT, nullptr},
15287 {1, VK_DESCRIPTOR_TYPE_STORAGE_BUFFER, 1, VK_SHADER_STAGE_COMPUTE_BIT, nullptr},
Chris Forbes6a4991a2016-07-19 15:07:32 +120015288 };
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015289 VkDescriptorSetLayoutCreateInfo dslci = {VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO, nullptr, 0, 2, bindings};
Chris Forbes6a4991a2016-07-19 15:07:32 +120015290 VkDescriptorSetLayout dsl;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015291 VkResult err = vkCreateDescriptorSetLayout(m_device->device(), &dslci, nullptr, &dsl);
Chris Forbes6a4991a2016-07-19 15:07:32 +120015292 ASSERT_VK_SUCCESS(err);
15293
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015294 VkPipelineLayoutCreateInfo plci = {VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dsl, 0, nullptr};
Chris Forbes6a4991a2016-07-19 15:07:32 +120015295 VkPipelineLayout pl;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015296 err = vkCreatePipelineLayout(m_device->device(), &plci, nullptr, &pl);
Chris Forbes6a4991a2016-07-19 15:07:32 +120015297 ASSERT_VK_SUCCESS(err);
15298
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015299 char const *csSource = "#version 450\n"
15300 "\n"
15301 "layout(local_size_x=1) in;\n"
15302 "layout(set=0, binding=0) uniform texture2D t;\n"
15303 "layout(set=0, binding=0) uniform sampler s; // both binding 0!\n"
15304 "layout(set=0, binding=1) buffer block { vec4 x; };\n"
15305 "void main() {\n"
15306 " x = texture(sampler2D(t, s), vec2(0));\n"
15307 "}\n";
Chris Forbes6a4991a2016-07-19 15:07:32 +120015308 VkShaderObj cs(m_device, csSource, VK_SHADER_STAGE_COMPUTE_BIT, this);
15309
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015310 VkComputePipelineCreateInfo cpci = {VK_STRUCTURE_TYPE_COMPUTE_PIPELINE_CREATE_INFO,
15311 nullptr,
15312 0,
15313 {VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO, nullptr, 0,
15314 VK_SHADER_STAGE_COMPUTE_BIT, cs.handle(), "main", nullptr},
15315 pl,
15316 VK_NULL_HANDLE,
15317 -1};
Chris Forbes6a4991a2016-07-19 15:07:32 +120015318
15319 VkPipeline pipe;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015320 err = vkCreateComputePipelines(m_device->device(), VK_NULL_HANDLE, 1, &cpci, nullptr, &pipe);
Chris Forbes6a4991a2016-07-19 15:07:32 +120015321
15322 m_errorMonitor->VerifyNotFound();
15323
15324 if (err == VK_SUCCESS) {
15325 vkDestroyPipeline(m_device->device(), pipe, nullptr);
15326 }
15327
15328 vkDestroyPipelineLayout(m_device->device(), pl, nullptr);
15329 vkDestroyDescriptorSetLayout(m_device->device(), dsl, nullptr);
15330}
15331
Chris Forbes50020592016-07-27 13:52:41 +120015332TEST_F(VkLayerTest, DrawTimeImageViewTypeMismatchWithPipeline) {
15333 TEST_DESCRIPTION("Test that an error is produced when an image view type "
15334 "does not match the dimensionality declared in the shader");
15335
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015336 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 +120015337
15338 ASSERT_NO_FATAL_FAILURE(InitState());
15339 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
15340
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015341 char const *vsSource = "#version 450\n"
15342 "\n"
15343 "out gl_PerVertex { vec4 gl_Position; };\n"
15344 "void main() { gl_Position = vec4(0); }\n";
15345 char const *fsSource = "#version 450\n"
15346 "\n"
15347 "layout(set=0, binding=0) uniform sampler3D s;\n"
15348 "layout(location=0) out vec4 color;\n"
15349 "void main() {\n"
15350 " color = texture(s, vec3(0));\n"
15351 "}\n";
Chris Forbes50020592016-07-27 13:52:41 +120015352 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
15353 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
15354
15355 VkPipelineObj pipe(m_device);
15356 pipe.AddShader(&vs);
15357 pipe.AddShader(&fs);
15358 pipe.AddColorAttachment();
15359
15360 VkTextureObj texture(m_device, nullptr);
15361 VkSamplerObj sampler(m_device);
15362
15363 VkDescriptorSetObj descriptorSet(m_device);
15364 descriptorSet.AppendSamplerTexture(&sampler, &texture);
15365 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
15366
15367 VkResult err = pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
15368 ASSERT_VK_SUCCESS(err);
15369
15370 BeginCommandBuffer();
15371
15372 m_commandBuffer->BindPipeline(pipe);
15373 m_commandBuffer->BindDescriptorSet(descriptorSet);
15374
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015375 VkViewport viewport = {0, 0, 16, 16, 0, 1};
Chris Forbes50020592016-07-27 13:52:41 +120015376 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015377 VkRect2D scissor = {{0, 0}, {16, 16}};
Chris Forbes50020592016-07-27 13:52:41 +120015378 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
15379
15380 // error produced here.
15381 vkCmdDraw(m_commandBuffer->handle(), 3, 1, 0, 0);
15382
15383 m_errorMonitor->VerifyFound();
15384
15385 EndCommandBuffer();
15386}
15387
Chris Forbes5533bfc2016-07-27 14:12:34 +120015388TEST_F(VkLayerTest, DrawTimeImageMultisampleMismatchWithPipeline) {
15389 TEST_DESCRIPTION("Test that an error is produced when a multisampled images "
15390 "are consumed via singlesample images types in the shader, or vice versa.");
15391
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015392 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "requires bound image to have multiple samples");
Chris Forbes5533bfc2016-07-27 14:12:34 +120015393
15394 ASSERT_NO_FATAL_FAILURE(InitState());
15395 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
15396
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015397 char const *vsSource = "#version 450\n"
15398 "\n"
15399 "out gl_PerVertex { vec4 gl_Position; };\n"
15400 "void main() { gl_Position = vec4(0); }\n";
15401 char const *fsSource = "#version 450\n"
15402 "\n"
15403 "layout(set=0, binding=0) uniform sampler2DMS s;\n"
15404 "layout(location=0) out vec4 color;\n"
15405 "void main() {\n"
15406 " color = texelFetch(s, ivec2(0), 0);\n"
15407 "}\n";
Chris Forbes5533bfc2016-07-27 14:12:34 +120015408 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
15409 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
15410
15411 VkPipelineObj pipe(m_device);
15412 pipe.AddShader(&vs);
15413 pipe.AddShader(&fs);
15414 pipe.AddColorAttachment();
15415
15416 VkTextureObj texture(m_device, nullptr);
15417 VkSamplerObj sampler(m_device);
15418
15419 VkDescriptorSetObj descriptorSet(m_device);
15420 descriptorSet.AppendSamplerTexture(&sampler, &texture);
15421 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
15422
15423 VkResult err = pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
15424 ASSERT_VK_SUCCESS(err);
15425
15426 BeginCommandBuffer();
15427
15428 m_commandBuffer->BindPipeline(pipe);
15429 m_commandBuffer->BindDescriptorSet(descriptorSet);
15430
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015431 VkViewport viewport = {0, 0, 16, 16, 0, 1};
Chris Forbes5533bfc2016-07-27 14:12:34 +120015432 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015433 VkRect2D scissor = {{0, 0}, {16, 16}};
Chris Forbes5533bfc2016-07-27 14:12:34 +120015434 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
15435
15436 // error produced here.
15437 vkCmdDraw(m_commandBuffer->handle(), 3, 1, 0, 0);
15438
15439 m_errorMonitor->VerifyFound();
15440
15441 EndCommandBuffer();
15442}
15443
Mark Lobodzinski209b5292015-09-17 09:44:05 -060015444#endif // SHADER_CHECKER_TESTS
15445
15446#if DEVICE_LIMITS_TESTS
Mark Youngc48c4c12016-04-11 14:26:49 -060015447TEST_F(VkLayerTest, CreateImageLimitsViolationMaxWidth) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015448 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "CreateImage extents exceed allowable limits for format");
Mark Lobodzinski6f2274e2015-09-22 09:33:21 -060015449
15450 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinski6f2274e2015-09-22 09:33:21 -060015451
15452 // Create an image
15453 VkImage image;
15454
Karl Schultz6addd812016-02-02 17:17:23 -070015455 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
15456 const int32_t tex_width = 32;
15457 const int32_t tex_height = 32;
Mark Lobodzinski6f2274e2015-09-22 09:33:21 -060015458
15459 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070015460 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
15461 image_create_info.pNext = NULL;
15462 image_create_info.imageType = VK_IMAGE_TYPE_2D;
15463 image_create_info.format = tex_format;
15464 image_create_info.extent.width = tex_width;
Mark Lobodzinski6f2274e2015-09-22 09:33:21 -060015465 image_create_info.extent.height = tex_height;
Karl Schultz6addd812016-02-02 17:17:23 -070015466 image_create_info.extent.depth = 1;
15467 image_create_info.mipLevels = 1;
15468 image_create_info.arrayLayers = 1;
15469 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
15470 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
15471 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
15472 image_create_info.flags = 0;
Mark Lobodzinski6f2274e2015-09-22 09:33:21 -060015473
15474 // Introduce error by sending down a bogus width extent
15475 image_create_info.extent.width = 65536;
Chia-I Wuf7458c52015-10-26 21:10:41 +080015476 vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
Mark Lobodzinski6f2274e2015-09-22 09:33:21 -060015477
Chris Forbes8f36a8a2016-04-07 13:21:07 +120015478 m_errorMonitor->VerifyFound();
Mark Lobodzinski6f2274e2015-09-22 09:33:21 -060015479}
15480
Mark Youngc48c4c12016-04-11 14:26:49 -060015481TEST_F(VkLayerTest, CreateImageLimitsViolationMinWidth) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015482 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
15483 "CreateImage extents is 0 for at least one required dimension");
Mark Youngc48c4c12016-04-11 14:26:49 -060015484
15485 ASSERT_NO_FATAL_FAILURE(InitState());
15486
15487 // Create an image
15488 VkImage image;
15489
15490 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
15491 const int32_t tex_width = 32;
15492 const int32_t tex_height = 32;
15493
15494 VkImageCreateInfo image_create_info = {};
15495 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
15496 image_create_info.pNext = NULL;
15497 image_create_info.imageType = VK_IMAGE_TYPE_2D;
15498 image_create_info.format = tex_format;
15499 image_create_info.extent.width = tex_width;
15500 image_create_info.extent.height = tex_height;
15501 image_create_info.extent.depth = 1;
15502 image_create_info.mipLevels = 1;
15503 image_create_info.arrayLayers = 1;
15504 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
15505 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
15506 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
15507 image_create_info.flags = 0;
15508
15509 // Introduce error by sending down a bogus width extent
15510 image_create_info.extent.width = 0;
15511 vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
15512
15513 m_errorMonitor->VerifyFound();
15514}
Mark Lobodzinski209b5292015-09-17 09:44:05 -060015515#endif // DEVICE_LIMITS_TESTS
Chris Forbesa36d69e2015-05-25 11:13:44 +120015516
Tobin Ehliscde08892015-09-22 10:11:37 -060015517#if IMAGE_TESTS
Mark Lobodzinskidf4c57d2016-08-05 11:47:16 -060015518TEST_F(VkLayerTest, AttachmentDescriptionUndefinedFormat) {
15519 TEST_DESCRIPTION("Create a render pass with an attachment description "
15520 "format set to VK_FORMAT_UNDEFINED");
15521
15522 ASSERT_NO_FATAL_FAILURE(InitState());
15523 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
15524
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015525 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "format is VK_FORMAT_UNDEFINED");
Mark Lobodzinskidf4c57d2016-08-05 11:47:16 -060015526
15527 VkAttachmentReference color_attach = {};
15528 color_attach.layout = VK_IMAGE_LAYOUT_GENERAL;
15529 color_attach.attachment = 0;
15530 VkSubpassDescription subpass = {};
15531 subpass.colorAttachmentCount = 1;
15532 subpass.pColorAttachments = &color_attach;
15533
15534 VkRenderPassCreateInfo rpci = {};
15535 rpci.subpassCount = 1;
15536 rpci.pSubpasses = &subpass;
15537 rpci.attachmentCount = 1;
15538 VkAttachmentDescription attach_desc = {};
15539 attach_desc.format = VK_FORMAT_UNDEFINED;
15540 rpci.pAttachments = &attach_desc;
15541 rpci.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
15542 VkRenderPass rp;
15543 VkResult result = vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
15544
15545 m_errorMonitor->VerifyFound();
15546
15547 if (result == VK_SUCCESS) {
15548 vkDestroyRenderPass(m_device->device(), rp, NULL);
15549 }
15550}
15551
Karl Schultz6addd812016-02-02 17:17:23 -070015552TEST_F(VkLayerTest, InvalidImageView) {
15553 VkResult err;
Tobin Ehliscde08892015-09-22 10:11:37 -060015554
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015555 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "vkCreateImageView called with baseMipLevel 10 ");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060015556
Tobin Ehliscde08892015-09-22 10:11:37 -060015557 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehliscde08892015-09-22 10:11:37 -060015558
Mike Stroyana3082432015-09-25 13:39:21 -060015559 // Create an image and try to create a view with bad baseMipLevel
Karl Schultz6addd812016-02-02 17:17:23 -070015560 VkImage image;
Tobin Ehliscde08892015-09-22 10:11:37 -060015561
Karl Schultz6addd812016-02-02 17:17:23 -070015562 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
15563 const int32_t tex_width = 32;
15564 const int32_t tex_height = 32;
Tobin Ehliscde08892015-09-22 10:11:37 -060015565
15566 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070015567 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
15568 image_create_info.pNext = NULL;
15569 image_create_info.imageType = VK_IMAGE_TYPE_2D;
15570 image_create_info.format = tex_format;
15571 image_create_info.extent.width = tex_width;
15572 image_create_info.extent.height = tex_height;
15573 image_create_info.extent.depth = 1;
15574 image_create_info.mipLevels = 1;
15575 image_create_info.arrayLayers = 1;
15576 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
15577 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
15578 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
15579 image_create_info.flags = 0;
Tobin Ehliscde08892015-09-22 10:11:37 -060015580
Chia-I Wuf7458c52015-10-26 21:10:41 +080015581 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
Tobin Ehliscde08892015-09-22 10:11:37 -060015582 ASSERT_VK_SUCCESS(err);
15583
15584 VkImageViewCreateInfo image_view_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070015585 image_view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
15586 image_view_create_info.image = image;
15587 image_view_create_info.viewType = VK_IMAGE_VIEW_TYPE_2D;
15588 image_view_create_info.format = tex_format;
15589 image_view_create_info.subresourceRange.layerCount = 1;
15590 image_view_create_info.subresourceRange.baseMipLevel = 10; // cause an error
15591 image_view_create_info.subresourceRange.levelCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015592 image_view_create_info.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Tobin Ehliscde08892015-09-22 10:11:37 -060015593
15594 VkImageView view;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015595 err = vkCreateImageView(m_device->device(), &image_view_create_info, NULL, &view);
Tobin Ehliscde08892015-09-22 10:11:37 -060015596
Chris Forbes8f36a8a2016-04-07 13:21:07 +120015597 m_errorMonitor->VerifyFound();
Tony Barbourdf4c0042016-06-01 15:55:43 -060015598 vkDestroyImage(m_device->device(), image, NULL);
Tobin Ehliscde08892015-09-22 10:11:37 -060015599}
Mike Stroyana3082432015-09-25 13:39:21 -060015600
Mark Youngd339ba32016-05-30 13:28:35 -060015601TEST_F(VkLayerTest, CreateImageViewNoMemoryBoundToImage) {
15602 VkResult err;
15603
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015604 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "used without first calling vkBindImageMemory");
Mark Youngd339ba32016-05-30 13:28:35 -060015605
15606 ASSERT_NO_FATAL_FAILURE(InitState());
15607
15608 // Create an image and try to create a view with no memory backing the image
15609 VkImage image;
15610
15611 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
15612 const int32_t tex_width = 32;
15613 const int32_t tex_height = 32;
15614
15615 VkImageCreateInfo image_create_info = {};
15616 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
15617 image_create_info.pNext = NULL;
15618 image_create_info.imageType = VK_IMAGE_TYPE_2D;
15619 image_create_info.format = tex_format;
15620 image_create_info.extent.width = tex_width;
15621 image_create_info.extent.height = tex_height;
15622 image_create_info.extent.depth = 1;
15623 image_create_info.mipLevels = 1;
15624 image_create_info.arrayLayers = 1;
15625 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
15626 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
15627 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
15628 image_create_info.flags = 0;
15629
15630 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
15631 ASSERT_VK_SUCCESS(err);
15632
15633 VkImageViewCreateInfo image_view_create_info = {};
15634 image_view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
15635 image_view_create_info.image = image;
15636 image_view_create_info.viewType = VK_IMAGE_VIEW_TYPE_2D;
15637 image_view_create_info.format = tex_format;
15638 image_view_create_info.subresourceRange.layerCount = 1;
15639 image_view_create_info.subresourceRange.baseMipLevel = 0;
15640 image_view_create_info.subresourceRange.levelCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015641 image_view_create_info.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mark Youngd339ba32016-05-30 13:28:35 -060015642
15643 VkImageView view;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015644 err = vkCreateImageView(m_device->device(), &image_view_create_info, NULL, &view);
Mark Youngd339ba32016-05-30 13:28:35 -060015645
15646 m_errorMonitor->VerifyFound();
15647 vkDestroyImage(m_device->device(), image, NULL);
15648 // If last error is success, it still created the view, so delete it.
15649 if (err == VK_SUCCESS) {
15650 vkDestroyImageView(m_device->device(), view, NULL);
15651 }
Mark Youngd339ba32016-05-30 13:28:35 -060015652}
15653
Karl Schultz6addd812016-02-02 17:17:23 -070015654TEST_F(VkLayerTest, InvalidImageViewAspect) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015655 TEST_DESCRIPTION("Create an image and try to create a view with an invalid aspectMask");
15656 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "vkCreateImageView: Color image "
15657 "formats must have ONLY the "
15658 "VK_IMAGE_ASPECT_COLOR_BIT set");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060015659
Mark Lobodzinskidc86b852015-10-23 14:20:31 -060015660 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinskidc86b852015-10-23 14:20:31 -060015661
Karl Schultz6addd812016-02-02 17:17:23 -070015662 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
Tobin Ehlis1f567a22016-05-25 16:15:18 -060015663 VkImageObj image(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015664 image.init(32, 32, tex_format, VK_IMAGE_USAGE_SAMPLED_BIT, VK_IMAGE_TILING_LINEAR, 0);
Tobin Ehlis1f567a22016-05-25 16:15:18 -060015665 ASSERT_TRUE(image.initialized());
Mark Lobodzinskidc86b852015-10-23 14:20:31 -060015666
15667 VkImageViewCreateInfo image_view_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070015668 image_view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
Tobin Ehlis1f567a22016-05-25 16:15:18 -060015669 image_view_create_info.image = image.handle();
Karl Schultz6addd812016-02-02 17:17:23 -070015670 image_view_create_info.viewType = VK_IMAGE_VIEW_TYPE_2D;
15671 image_view_create_info.format = tex_format;
15672 image_view_create_info.subresourceRange.baseMipLevel = 0;
15673 image_view_create_info.subresourceRange.levelCount = 1;
15674 // Cause an error by setting an invalid image aspect
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015675 image_view_create_info.subresourceRange.aspectMask = VK_IMAGE_ASPECT_METADATA_BIT;
Mark Lobodzinskidc86b852015-10-23 14:20:31 -060015676
15677 VkImageView view;
Tobin Ehlis1f567a22016-05-25 16:15:18 -060015678 vkCreateImageView(m_device->device(), &image_view_create_info, NULL, &view);
Mark Lobodzinskidc86b852015-10-23 14:20:31 -060015679
Chris Forbes8f36a8a2016-04-07 13:21:07 +120015680 m_errorMonitor->VerifyFound();
Mark Lobodzinskidc86b852015-10-23 14:20:31 -060015681}
15682
Mark Lobodzinskidb117632016-03-31 10:45:56 -060015683TEST_F(VkLayerTest, CopyImageLayerCountMismatch) {
Karl Schultz6addd812016-02-02 17:17:23 -070015684 VkResult err;
15685 bool pass;
Mike Stroyana3082432015-09-25 13:39:21 -060015686
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015687 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
15688 "vkCmdCopyImage: number of layers in source and destination subresources for pRegions");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060015689
Mike Stroyana3082432015-09-25 13:39:21 -060015690 ASSERT_NO_FATAL_FAILURE(InitState());
Mike Stroyana3082432015-09-25 13:39:21 -060015691
15692 // Create two images of different types and try to copy between them
Karl Schultz6addd812016-02-02 17:17:23 -070015693 VkImage srcImage;
15694 VkImage dstImage;
15695 VkDeviceMemory srcMem;
15696 VkDeviceMemory destMem;
15697 VkMemoryRequirements memReqs;
Mike Stroyana3082432015-09-25 13:39:21 -060015698
15699 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070015700 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
15701 image_create_info.pNext = NULL;
15702 image_create_info.imageType = VK_IMAGE_TYPE_2D;
15703 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
15704 image_create_info.extent.width = 32;
15705 image_create_info.extent.height = 32;
15706 image_create_info.extent.depth = 1;
15707 image_create_info.mipLevels = 1;
Mark Lobodzinskidb117632016-03-31 10:45:56 -060015708 image_create_info.arrayLayers = 4;
Karl Schultz6addd812016-02-02 17:17:23 -070015709 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
15710 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
15711 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
15712 image_create_info.flags = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060015713
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015714 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
Mike Stroyana3082432015-09-25 13:39:21 -060015715 ASSERT_VK_SUCCESS(err);
15716
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015717 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
Mike Stroyana3082432015-09-25 13:39:21 -060015718 ASSERT_VK_SUCCESS(err);
15719
15720 // Allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015721 VkMemoryAllocateInfo memAlloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -070015722 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
15723 memAlloc.pNext = NULL;
15724 memAlloc.allocationSize = 0;
15725 memAlloc.memoryTypeIndex = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060015726
Courtney Goeltzenleuchter06d89472015-10-20 16:40:38 -060015727 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060015728 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015729 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060015730 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015731 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
Mike Stroyana3082432015-09-25 13:39:21 -060015732 ASSERT_VK_SUCCESS(err);
15733
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015734 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060015735 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015736 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Mike Stroyana3082432015-09-25 13:39:21 -060015737 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015738 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
Mike Stroyana3082432015-09-25 13:39:21 -060015739 ASSERT_VK_SUCCESS(err);
15740
15741 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
15742 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015743 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
Mike Stroyana3082432015-09-25 13:39:21 -060015744 ASSERT_VK_SUCCESS(err);
15745
15746 BeginCommandBuffer();
15747 VkImageCopy copyRegion;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080015748 copyRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060015749 copyRegion.srcSubresource.mipLevel = 0;
Courtney Goeltzenleuchter8367ce02015-10-16 09:46:00 -060015750 copyRegion.srcSubresource.baseArrayLayer = 0;
Mark Lobodzinskidb117632016-03-31 10:45:56 -060015751 copyRegion.srcSubresource.layerCount = 1;
Mike Stroyana3082432015-09-25 13:39:21 -060015752 copyRegion.srcOffset.x = 0;
15753 copyRegion.srcOffset.y = 0;
15754 copyRegion.srcOffset.z = 0;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080015755 copyRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015756 copyRegion.dstSubresource.mipLevel = 0;
15757 copyRegion.dstSubresource.baseArrayLayer = 0;
Mark Lobodzinskidb117632016-03-31 10:45:56 -060015758 // Introduce failure by forcing the dst layerCount to differ from src
15759 copyRegion.dstSubresource.layerCount = 3;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015760 copyRegion.dstOffset.x = 0;
15761 copyRegion.dstOffset.y = 0;
15762 copyRegion.dstOffset.z = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060015763 copyRegion.extent.width = 1;
15764 copyRegion.extent.height = 1;
15765 copyRegion.extent.depth = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015766 m_commandBuffer->CopyImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, VK_IMAGE_LAYOUT_GENERAL, 1, &copyRegion);
Mike Stroyana3082432015-09-25 13:39:21 -060015767 EndCommandBuffer();
15768
Chris Forbes8f36a8a2016-04-07 13:21:07 +120015769 m_errorMonitor->VerifyFound();
Mike Stroyana3082432015-09-25 13:39:21 -060015770
Chia-I Wuf7458c52015-10-26 21:10:41 +080015771 vkDestroyImage(m_device->device(), srcImage, NULL);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015772 vkDestroyImage(m_device->device(), dstImage, NULL);
Chia-I Wuf7458c52015-10-26 21:10:41 +080015773 vkFreeMemory(m_device->device(), srcMem, NULL);
15774 vkFreeMemory(m_device->device(), destMem, NULL);
Mike Stroyana3082432015-09-25 13:39:21 -060015775}
15776
Tony Barbourd6673642016-05-05 14:46:39 -060015777TEST_F(VkLayerTest, ImageLayerUnsupportedFormat) {
15778
15779 TEST_DESCRIPTION("Creating images with unsuported formats ");
15780
15781 ASSERT_NO_FATAL_FAILURE(InitState());
15782 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
15783 VkImageObj image(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015784 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 -060015785 VK_IMAGE_TILING_OPTIMAL, 0);
15786 ASSERT_TRUE(image.initialized());
15787
Mark Lobodzinskiba5c6862016-05-17 08:14:00 -060015788 // Create image with unsupported format - Expect FORMAT_UNSUPPORTED
15789 VkImageCreateInfo image_create_info;
15790 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
15791 image_create_info.pNext = NULL;
15792 image_create_info.imageType = VK_IMAGE_TYPE_2D;
15793 image_create_info.format = VK_FORMAT_UNDEFINED;
15794 image_create_info.extent.width = 32;
15795 image_create_info.extent.height = 32;
15796 image_create_info.extent.depth = 1;
15797 image_create_info.mipLevels = 1;
15798 image_create_info.arrayLayers = 1;
15799 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
15800 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
15801 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
15802 image_create_info.flags = 0;
15803
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015804 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
15805 "vkCreateImage: VkFormat for image must not be VK_FORMAT_UNDEFINED");
Mark Lobodzinskiba5c6862016-05-17 08:14:00 -060015806
15807 VkImage localImage;
15808 vkCreateImage(m_device->handle(), &image_create_info, NULL, &localImage);
15809 m_errorMonitor->VerifyFound();
15810
Tony Barbourd6673642016-05-05 14:46:39 -060015811 VkFormat unsupported = VK_FORMAT_UNDEFINED;
Mark Lobodzinskiba5c6862016-05-17 08:14:00 -060015812 // Look for a format that is COMPLETELY unsupported with this hardware
Tony Barbourd6673642016-05-05 14:46:39 -060015813 for (int f = VK_FORMAT_BEGIN_RANGE; f <= VK_FORMAT_END_RANGE; f++) {
15814 VkFormat format = static_cast<VkFormat>(f);
15815 VkFormatProperties fProps = m_device->format_properties(format);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015816 if (format != VK_FORMAT_UNDEFINED && fProps.linearTilingFeatures == 0 && fProps.optimalTilingFeatures == 0) {
Tony Barbourd6673642016-05-05 14:46:39 -060015817 unsupported = format;
15818 break;
15819 }
15820 }
Mark Lobodzinskiba5c6862016-05-17 08:14:00 -060015821
Tony Barbourd6673642016-05-05 14:46:39 -060015822 if (unsupported != VK_FORMAT_UNDEFINED) {
Tony Barbourd6673642016-05-05 14:46:39 -060015823 image_create_info.format = unsupported;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015824 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "is an unsupported format");
Tony Barbourd6673642016-05-05 14:46:39 -060015825
Mark Lobodzinskiba5c6862016-05-17 08:14:00 -060015826 vkCreateImage(m_device->handle(), &image_create_info, NULL, &localImage);
Tony Barbourd6673642016-05-05 14:46:39 -060015827 m_errorMonitor->VerifyFound();
15828 }
15829}
15830
15831TEST_F(VkLayerTest, ImageLayerViewTests) {
15832 VkResult ret;
15833 TEST_DESCRIPTION("Passing bad parameters to CreateImageView");
15834
15835 ASSERT_NO_FATAL_FAILURE(InitState());
15836
15837 VkImageObj image(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015838 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 -060015839 VK_IMAGE_TILING_OPTIMAL, 0);
15840 ASSERT_TRUE(image.initialized());
15841
15842 VkImageView imgView;
15843 VkImageViewCreateInfo imgViewInfo = {};
15844 imgViewInfo.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
15845 imgViewInfo.image = image.handle();
15846 imgViewInfo.viewType = VK_IMAGE_VIEW_TYPE_2D;
15847 imgViewInfo.format = VK_FORMAT_B8G8R8A8_UNORM;
15848 imgViewInfo.subresourceRange.layerCount = 1;
15849 imgViewInfo.subresourceRange.baseMipLevel = 0;
15850 imgViewInfo.subresourceRange.levelCount = 1;
15851 imgViewInfo.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
15852
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015853 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "vkCreateImageView called with baseMipLevel");
Tony Barbourd6673642016-05-05 14:46:39 -060015854 // View can't have baseMipLevel >= image's mipLevels - Expect
15855 // VIEW_CREATE_ERROR
15856 imgViewInfo.subresourceRange.baseMipLevel = 1;
15857 vkCreateImageView(m_device->handle(), &imgViewInfo, NULL, &imgView);
15858 m_errorMonitor->VerifyFound();
15859 imgViewInfo.subresourceRange.baseMipLevel = 0;
15860
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015861 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "vkCreateImageView called with baseArrayLayer");
Tony Barbourd6673642016-05-05 14:46:39 -060015862 // View can't have baseArrayLayer >= image's arraySize - Expect
15863 // VIEW_CREATE_ERROR
15864 imgViewInfo.subresourceRange.baseArrayLayer = 1;
15865 vkCreateImageView(m_device->handle(), &imgViewInfo, NULL, &imgView);
15866 m_errorMonitor->VerifyFound();
15867 imgViewInfo.subresourceRange.baseArrayLayer = 0;
15868
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015869 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "vkCreateImageView called with 0 in "
15870 "pCreateInfo->subresourceRange."
15871 "levelCount");
Tony Barbourd6673642016-05-05 14:46:39 -060015872 // View's levelCount can't be 0 - Expect VIEW_CREATE_ERROR
15873 imgViewInfo.subresourceRange.levelCount = 0;
15874 vkCreateImageView(m_device->handle(), &imgViewInfo, NULL, &imgView);
15875 m_errorMonitor->VerifyFound();
15876 imgViewInfo.subresourceRange.levelCount = 1;
15877
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015878 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "vkCreateImageView called with 0 in "
15879 "pCreateInfo->subresourceRange."
15880 "layerCount");
Tony Barbourd6673642016-05-05 14:46:39 -060015881 // View's layerCount can't be 0 - Expect VIEW_CREATE_ERROR
15882 imgViewInfo.subresourceRange.layerCount = 0;
15883 vkCreateImageView(m_device->handle(), &imgViewInfo, NULL, &imgView);
15884 m_errorMonitor->VerifyFound();
15885 imgViewInfo.subresourceRange.layerCount = 1;
15886
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015887 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "but both must be color formats");
Tony Barbourd6673642016-05-05 14:46:39 -060015888 // Can't use depth format for view into color image - Expect INVALID_FORMAT
15889 imgViewInfo.format = VK_FORMAT_D24_UNORM_S8_UINT;
15890 vkCreateImageView(m_device->handle(), &imgViewInfo, NULL, &imgView);
15891 m_errorMonitor->VerifyFound();
15892 imgViewInfo.format = VK_FORMAT_B8G8R8A8_UNORM;
15893
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015894 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Formats MUST be IDENTICAL unless "
15895 "VK_IMAGE_CREATE_MUTABLE_FORMAT BIT "
15896 "was set on image creation.");
Tony Barbourd6673642016-05-05 14:46:39 -060015897 // Same compatibility class but no MUTABLE_FORMAT bit - Expect
15898 // VIEW_CREATE_ERROR
15899 imgViewInfo.format = VK_FORMAT_B8G8R8A8_UINT;
15900 vkCreateImageView(m_device->handle(), &imgViewInfo, NULL, &imgView);
15901 m_errorMonitor->VerifyFound();
15902 imgViewInfo.format = VK_FORMAT_B8G8R8A8_UNORM;
15903
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015904 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "can support ImageViews with "
15905 "differing formats but they must be "
15906 "in the same compatibility class.");
Tony Barbourd6673642016-05-05 14:46:39 -060015907 // Have MUTABLE_FORMAT bit but not in same compatibility class - Expect
15908 // VIEW_CREATE_ERROR
15909 VkImageCreateInfo mutImgInfo = image.create_info();
15910 VkImage mutImage;
15911 mutImgInfo.format = VK_FORMAT_R8_UINT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015912 assert(m_device->format_properties(VK_FORMAT_R8_UINT).optimalTilingFeatures & VK_FORMAT_FEATURE_COLOR_ATTACHMENT_BIT);
Tony Barbourd6673642016-05-05 14:46:39 -060015913 mutImgInfo.flags = VK_IMAGE_CREATE_MUTABLE_FORMAT_BIT;
15914 mutImgInfo.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
15915 ret = vkCreateImage(m_device->handle(), &mutImgInfo, NULL, &mutImage);
15916 ASSERT_VK_SUCCESS(ret);
15917 imgViewInfo.image = mutImage;
15918 vkCreateImageView(m_device->handle(), &imgViewInfo, NULL, &imgView);
15919 m_errorMonitor->VerifyFound();
15920 imgViewInfo.image = image.handle();
15921 vkDestroyImage(m_device->handle(), mutImage, NULL);
15922}
15923
15924TEST_F(VkLayerTest, MiscImageLayerTests) {
15925
15926 TEST_DESCRIPTION("Image layer tests that don't belong elsewhare");
15927
15928 ASSERT_NO_FATAL_FAILURE(InitState());
15929
15930 VkImageObj image(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015931 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 -060015932 VK_IMAGE_TILING_OPTIMAL, 0);
15933 ASSERT_TRUE(image.initialized());
15934
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015935 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "number of layers in image subresource is zero");
Tony Barbourd6673642016-05-05 14:46:39 -060015936 vk_testing::Buffer buffer;
15937 VkMemoryPropertyFlags reqs = 0;
15938 buffer.init_as_src(*m_device, 128 * 128 * 4, reqs);
15939 VkBufferImageCopy region = {};
15940 region.bufferRowLength = 128;
15941 region.bufferImageHeight = 128;
15942 region.imageSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
15943 // layerCount can't be 0 - Expect MISMATCHED_IMAGE_ASPECT
15944 region.imageSubresource.layerCount = 0;
15945 region.imageExtent.height = 4;
15946 region.imageExtent.width = 4;
15947 region.imageExtent.depth = 1;
15948 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015949 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer.handle(), image.handle(),
15950 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, &region);
Tony Barbourd6673642016-05-05 14:46:39 -060015951 m_errorMonitor->VerifyFound();
15952 region.imageSubresource.layerCount = 1;
15953
Mark Lobodzinski7d8cf142016-08-19 10:53:26 -060015954 // BufferOffset must be a multiple of the calling command's VkImage parameter's texel size
15955 // Introduce failure by setting bufferOffset to 1 and 1/2 texels
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 this format's texel size");
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 // BufferOffset must be a multiple of 4
15963 // Introduce failure by setting bufferOffset to a value not divisible by 4
15964 region.bufferOffset = 6;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015965 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "must be a multiple of 4");
15966 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer.handle(), image.handle(),
15967 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, &region);
Mark Lobodzinski7d8cf142016-08-19 10:53:26 -060015968 m_errorMonitor->VerifyFound();
15969
15970 // BufferRowLength must be 0, or greater than or equal to the width member of imageExtent
15971 region.bufferOffset = 0;
15972 region.imageExtent.height = 128;
15973 region.imageExtent.width = 128;
15974 // Introduce failure by setting bufferRowLength > 0 but less than width
15975 region.bufferRowLength = 64;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015976 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
15977 "must be zero or greater-than-or-equal-to imageExtent.width");
15978 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer.handle(), image.handle(),
15979 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, &region);
Mark Lobodzinski7d8cf142016-08-19 10:53:26 -060015980 m_errorMonitor->VerifyFound();
15981
15982 // BufferImageHeight must be 0, or greater than or equal to the height member of imageExtent
15983 region.bufferRowLength = 128;
15984 // Introduce failure by setting bufferRowHeight > 0 but less than height
15985 region.bufferImageHeight = 64;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015986 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
15987 "must be zero or greater-than-or-equal-to imageExtent.height");
15988 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer.handle(), image.handle(),
15989 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, &region);
Mark Lobodzinski7d8cf142016-08-19 10:53:26 -060015990 m_errorMonitor->VerifyFound();
15991
15992 region.bufferImageHeight = 128;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015993 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "aspectMasks for each region must "
15994 "specify only COLOR or DEPTH or "
15995 "STENCIL");
Tony Barbourd6673642016-05-05 14:46:39 -060015996 // Expect MISMATCHED_IMAGE_ASPECT
15997 region.imageSubresource.aspectMask = VK_IMAGE_ASPECT_METADATA_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015998 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer.handle(), image.handle(),
15999 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, &region);
Tony Barbourd6673642016-05-05 14:46:39 -060016000 m_errorMonitor->VerifyFound();
16001 region.imageSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
16002
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016003 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
16004 "If the format of srcImage is a depth, stencil, depth stencil or "
16005 "integer-based format then filter must be VK_FILTER_NEAREST");
Tony Barbourd6673642016-05-05 14:46:39 -060016006 // Expect INVALID_FILTER
16007 VkImageObj intImage1(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016008 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 -060016009 VkImageObj intImage2(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016010 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 -060016011 VkImageBlit blitRegion = {};
16012 blitRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
16013 blitRegion.srcSubresource.baseArrayLayer = 0;
16014 blitRegion.srcSubresource.layerCount = 1;
16015 blitRegion.srcSubresource.mipLevel = 0;
16016 blitRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
16017 blitRegion.dstSubresource.baseArrayLayer = 0;
16018 blitRegion.dstSubresource.layerCount = 1;
16019 blitRegion.dstSubresource.mipLevel = 0;
16020
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016021 vkCmdBlitImage(m_commandBuffer->GetBufferHandle(), intImage1.handle(), intImage1.layout(), intImage2.handle(),
16022 intImage2.layout(), 16, &blitRegion, VK_FILTER_LINEAR);
Tony Barbourd6673642016-05-05 14:46:39 -060016023 m_errorMonitor->VerifyFound();
16024
Mark Lobodzinskib02ea642016-08-17 13:03:57 -060016025 // Look for NULL-blit warning
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016026 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT, "Offsets specify a zero-volume area.");
16027 vkCmdBlitImage(m_commandBuffer->GetBufferHandle(), intImage1.handle(), intImage1.layout(), intImage2.handle(),
16028 intImage2.layout(), 1, &blitRegion, VK_FILTER_LINEAR);
Mark Lobodzinskib02ea642016-08-17 13:03:57 -060016029 m_errorMonitor->VerifyFound();
16030
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016031 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "called with 0 in ppMemoryBarriers");
Tony Barbourd6673642016-05-05 14:46:39 -060016032 VkImageMemoryBarrier img_barrier;
16033 img_barrier.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
16034 img_barrier.pNext = NULL;
16035 img_barrier.srcAccessMask = VK_ACCESS_HOST_WRITE_BIT;
16036 img_barrier.dstAccessMask = VK_ACCESS_SHADER_READ_BIT;
16037 img_barrier.oldLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
16038 img_barrier.newLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
16039 img_barrier.image = image.handle();
16040 img_barrier.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
16041 img_barrier.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
16042 img_barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
16043 img_barrier.subresourceRange.baseArrayLayer = 0;
16044 img_barrier.subresourceRange.baseMipLevel = 0;
16045 // layerCount should not be 0 - Expect INVALID_IMAGE_RESOURCE
16046 img_barrier.subresourceRange.layerCount = 0;
16047 img_barrier.subresourceRange.levelCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016048 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
16049 nullptr, 0, nullptr, 1, &img_barrier);
Tony Barbourd6673642016-05-05 14:46:39 -060016050 m_errorMonitor->VerifyFound();
16051 img_barrier.subresourceRange.layerCount = 1;
16052}
16053
16054TEST_F(VkLayerTest, ImageFormatLimits) {
16055
16056 TEST_DESCRIPTION("Exceed the limits of image format ");
16057
Cody Northropc31a84f2016-08-22 10:41:47 -060016058 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016059 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "CreateImage extents exceed allowable limits for format");
Tony Barbourd6673642016-05-05 14:46:39 -060016060 VkImageCreateInfo image_create_info = {};
16061 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
16062 image_create_info.pNext = NULL;
16063 image_create_info.imageType = VK_IMAGE_TYPE_2D;
16064 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
16065 image_create_info.extent.width = 32;
16066 image_create_info.extent.height = 32;
16067 image_create_info.extent.depth = 1;
16068 image_create_info.mipLevels = 1;
16069 image_create_info.arrayLayers = 1;
16070 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
16071 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
16072 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
16073 image_create_info.initialLayout = VK_IMAGE_LAYOUT_UNDEFINED;
16074 image_create_info.flags = 0;
16075
16076 VkImage nullImg;
16077 VkImageFormatProperties imgFmtProps;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016078 vkGetPhysicalDeviceImageFormatProperties(gpu(), image_create_info.format, image_create_info.imageType, image_create_info.tiling,
16079 image_create_info.usage, image_create_info.flags, &imgFmtProps);
Tony Barbourd6673642016-05-05 14:46:39 -060016080 image_create_info.extent.depth = imgFmtProps.maxExtent.depth + 1;
16081 // Expect INVALID_FORMAT_LIMITS_VIOLATION
16082 vkCreateImage(m_device->handle(), &image_create_info, NULL, &nullImg);
16083 m_errorMonitor->VerifyFound();
16084 image_create_info.extent.depth = 1;
16085
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016086 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "exceeds allowable maximum supported by format of");
Tony Barbourd6673642016-05-05 14:46:39 -060016087 image_create_info.mipLevels = imgFmtProps.maxMipLevels + 1;
16088 // Expect INVALID_FORMAT_LIMITS_VIOLATION
16089 vkCreateImage(m_device->handle(), &image_create_info, NULL, &nullImg);
16090 m_errorMonitor->VerifyFound();
16091 image_create_info.mipLevels = 1;
16092
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016093 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "exceeds allowable maximum supported by format of");
Tony Barbourd6673642016-05-05 14:46:39 -060016094 image_create_info.arrayLayers = imgFmtProps.maxArrayLayers + 1;
16095 // Expect INVALID_FORMAT_LIMITS_VIOLATION
16096 vkCreateImage(m_device->handle(), &image_create_info, NULL, &nullImg);
16097 m_errorMonitor->VerifyFound();
16098 image_create_info.arrayLayers = 1;
16099
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016100 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "is not supported by format");
Tony Barbourd6673642016-05-05 14:46:39 -060016101 int samples = imgFmtProps.sampleCounts >> 1;
16102 image_create_info.samples = (VkSampleCountFlagBits)samples;
16103 // Expect INVALID_FORMAT_LIMITS_VIOLATION
16104 vkCreateImage(m_device->handle(), &image_create_info, NULL, &nullImg);
16105 m_errorMonitor->VerifyFound();
16106 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
16107
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016108 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "pCreateInfo->initialLayout, must be "
16109 "VK_IMAGE_LAYOUT_UNDEFINED or "
16110 "VK_IMAGE_LAYOUT_PREINITIALIZED");
Tony Barbourd6673642016-05-05 14:46:39 -060016111 image_create_info.initialLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
16112 // Expect INVALID_LAYOUT
16113 vkCreateImage(m_device->handle(), &image_create_info, NULL, &nullImg);
16114 m_errorMonitor->VerifyFound();
16115 image_create_info.initialLayout = VK_IMAGE_LAYOUT_UNDEFINED;
16116}
16117
Karl Schultz6addd812016-02-02 17:17:23 -070016118TEST_F(VkLayerTest, CopyImageFormatSizeMismatch) {
Karl Schultzbdb75952016-04-19 11:36:49 -060016119 VkResult err;
16120 bool pass;
16121
16122 // Create color images with different format sizes and try to copy between them
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016123 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
16124 "vkCmdCopyImage called with unmatched source and dest image format sizes");
Karl Schultzbdb75952016-04-19 11:36:49 -060016125
16126 ASSERT_NO_FATAL_FAILURE(InitState());
16127
16128 // Create two images of different types and try to copy between them
16129 VkImage srcImage;
16130 VkImage dstImage;
16131 VkDeviceMemory srcMem;
16132 VkDeviceMemory destMem;
16133 VkMemoryRequirements memReqs;
16134
16135 VkImageCreateInfo image_create_info = {};
16136 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
16137 image_create_info.pNext = NULL;
16138 image_create_info.imageType = VK_IMAGE_TYPE_2D;
16139 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
16140 image_create_info.extent.width = 32;
16141 image_create_info.extent.height = 32;
16142 image_create_info.extent.depth = 1;
16143 image_create_info.mipLevels = 1;
16144 image_create_info.arrayLayers = 1;
16145 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
16146 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
16147 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
16148 image_create_info.flags = 0;
16149
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016150 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
Karl Schultzbdb75952016-04-19 11:36:49 -060016151 ASSERT_VK_SUCCESS(err);
16152
16153 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT;
16154 // Introduce failure by creating second image with a different-sized format.
16155 image_create_info.format = VK_FORMAT_R5G5B5A1_UNORM_PACK16;
16156
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016157 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
Karl Schultzbdb75952016-04-19 11:36:49 -060016158 ASSERT_VK_SUCCESS(err);
16159
16160 // Allocate memory
16161 VkMemoryAllocateInfo memAlloc = {};
16162 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
16163 memAlloc.pNext = NULL;
16164 memAlloc.allocationSize = 0;
16165 memAlloc.memoryTypeIndex = 0;
16166
16167 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
16168 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016169 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Karl Schultzbdb75952016-04-19 11:36:49 -060016170 ASSERT_TRUE(pass);
16171 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
16172 ASSERT_VK_SUCCESS(err);
16173
16174 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
16175 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016176 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Karl Schultzbdb75952016-04-19 11:36:49 -060016177 ASSERT_TRUE(pass);
16178 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
16179 ASSERT_VK_SUCCESS(err);
16180
16181 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
16182 ASSERT_VK_SUCCESS(err);
16183 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
16184 ASSERT_VK_SUCCESS(err);
16185
16186 BeginCommandBuffer();
16187 VkImageCopy copyRegion;
16188 copyRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
16189 copyRegion.srcSubresource.mipLevel = 0;
16190 copyRegion.srcSubresource.baseArrayLayer = 0;
16191 copyRegion.srcSubresource.layerCount = 0;
16192 copyRegion.srcOffset.x = 0;
16193 copyRegion.srcOffset.y = 0;
16194 copyRegion.srcOffset.z = 0;
16195 copyRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
16196 copyRegion.dstSubresource.mipLevel = 0;
16197 copyRegion.dstSubresource.baseArrayLayer = 0;
16198 copyRegion.dstSubresource.layerCount = 0;
16199 copyRegion.dstOffset.x = 0;
16200 copyRegion.dstOffset.y = 0;
16201 copyRegion.dstOffset.z = 0;
16202 copyRegion.extent.width = 1;
16203 copyRegion.extent.height = 1;
16204 copyRegion.extent.depth = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016205 m_commandBuffer->CopyImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, VK_IMAGE_LAYOUT_GENERAL, 1, &copyRegion);
Karl Schultzbdb75952016-04-19 11:36:49 -060016206 EndCommandBuffer();
16207
16208 m_errorMonitor->VerifyFound();
16209
16210 vkDestroyImage(m_device->device(), srcImage, NULL);
16211 vkDestroyImage(m_device->device(), dstImage, NULL);
16212 vkFreeMemory(m_device->device(), srcMem, NULL);
16213 vkFreeMemory(m_device->device(), destMem, NULL);
Mike Stroyana3082432015-09-25 13:39:21 -060016214}
16215
Karl Schultz6addd812016-02-02 17:17:23 -070016216TEST_F(VkLayerTest, CopyImageDepthStencilFormatMismatch) {
16217 VkResult err;
16218 bool pass;
Mike Stroyana3082432015-09-25 13:39:21 -060016219
Mark Lobodzinskidb117632016-03-31 10:45:56 -060016220 // Create a color image and a depth/stencil image and try to copy between them
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016221 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
16222 "vkCmdCopyImage called with unmatched source and dest image depth");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060016223
Mike Stroyana3082432015-09-25 13:39:21 -060016224 ASSERT_NO_FATAL_FAILURE(InitState());
Mike Stroyana3082432015-09-25 13:39:21 -060016225
16226 // Create two images of different types and try to copy between them
Karl Schultz6addd812016-02-02 17:17:23 -070016227 VkImage srcImage;
16228 VkImage dstImage;
16229 VkDeviceMemory srcMem;
16230 VkDeviceMemory destMem;
16231 VkMemoryRequirements memReqs;
Mike Stroyana3082432015-09-25 13:39:21 -060016232
16233 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070016234 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
16235 image_create_info.pNext = NULL;
16236 image_create_info.imageType = VK_IMAGE_TYPE_2D;
16237 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
16238 image_create_info.extent.width = 32;
16239 image_create_info.extent.height = 32;
16240 image_create_info.extent.depth = 1;
16241 image_create_info.mipLevels = 1;
16242 image_create_info.arrayLayers = 1;
16243 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
16244 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
16245 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
16246 image_create_info.flags = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060016247
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016248 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
Mike Stroyana3082432015-09-25 13:39:21 -060016249 ASSERT_VK_SUCCESS(err);
16250
Karl Schultzbdb75952016-04-19 11:36:49 -060016251 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT;
16252
Mark Lobodzinskidb117632016-03-31 10:45:56 -060016253 // Introduce failure by creating second image with a depth/stencil format
Karl Schultz6addd812016-02-02 17:17:23 -070016254 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
Mark Lobodzinskidb117632016-03-31 10:45:56 -060016255 image_create_info.format = VK_FORMAT_D24_UNORM_S8_UINT;
16256 image_create_info.usage = VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060016257
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016258 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
Mike Stroyana3082432015-09-25 13:39:21 -060016259 ASSERT_VK_SUCCESS(err);
16260
16261 // Allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016262 VkMemoryAllocateInfo memAlloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -070016263 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
16264 memAlloc.pNext = NULL;
16265 memAlloc.allocationSize = 0;
16266 memAlloc.memoryTypeIndex = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060016267
Courtney Goeltzenleuchter06d89472015-10-20 16:40:38 -060016268 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060016269 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016270 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060016271 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016272 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
Mike Stroyana3082432015-09-25 13:39:21 -060016273 ASSERT_VK_SUCCESS(err);
16274
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016275 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060016276 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016277 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060016278 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016279 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
Mike Stroyana3082432015-09-25 13:39:21 -060016280 ASSERT_VK_SUCCESS(err);
16281
16282 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
16283 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016284 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
Mike Stroyana3082432015-09-25 13:39:21 -060016285 ASSERT_VK_SUCCESS(err);
16286
16287 BeginCommandBuffer();
16288 VkImageCopy copyRegion;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080016289 copyRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060016290 copyRegion.srcSubresource.mipLevel = 0;
Courtney Goeltzenleuchter8367ce02015-10-16 09:46:00 -060016291 copyRegion.srcSubresource.baseArrayLayer = 0;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016292 copyRegion.srcSubresource.layerCount = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060016293 copyRegion.srcOffset.x = 0;
16294 copyRegion.srcOffset.y = 0;
16295 copyRegion.srcOffset.z = 0;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080016296 copyRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016297 copyRegion.dstSubresource.mipLevel = 0;
16298 copyRegion.dstSubresource.baseArrayLayer = 0;
16299 copyRegion.dstSubresource.layerCount = 0;
16300 copyRegion.dstOffset.x = 0;
16301 copyRegion.dstOffset.y = 0;
16302 copyRegion.dstOffset.z = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060016303 copyRegion.extent.width = 1;
16304 copyRegion.extent.height = 1;
16305 copyRegion.extent.depth = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016306 m_commandBuffer->CopyImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, VK_IMAGE_LAYOUT_GENERAL, 1, &copyRegion);
Mike Stroyana3082432015-09-25 13:39:21 -060016307 EndCommandBuffer();
16308
Chris Forbes8f36a8a2016-04-07 13:21:07 +120016309 m_errorMonitor->VerifyFound();
Mike Stroyana3082432015-09-25 13:39:21 -060016310
Chia-I Wuf7458c52015-10-26 21:10:41 +080016311 vkDestroyImage(m_device->device(), srcImage, NULL);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016312 vkDestroyImage(m_device->device(), dstImage, NULL);
Chia-I Wuf7458c52015-10-26 21:10:41 +080016313 vkFreeMemory(m_device->device(), srcMem, NULL);
16314 vkFreeMemory(m_device->device(), destMem, NULL);
Mike Stroyana3082432015-09-25 13:39:21 -060016315}
16316
Karl Schultz6addd812016-02-02 17:17:23 -070016317TEST_F(VkLayerTest, ResolveImageLowSampleCount) {
16318 VkResult err;
16319 bool pass;
Mike Stroyana3082432015-09-25 13:39:21 -060016320
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016321 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
16322 "vkCmdResolveImage called with source sample count less than 2.");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060016323
Mike Stroyana3082432015-09-25 13:39:21 -060016324 ASSERT_NO_FATAL_FAILURE(InitState());
Mike Stroyana3082432015-09-25 13:39:21 -060016325
16326 // Create two images of sample count 1 and try to Resolve between them
Karl Schultz6addd812016-02-02 17:17:23 -070016327 VkImage srcImage;
16328 VkImage dstImage;
16329 VkDeviceMemory srcMem;
16330 VkDeviceMemory destMem;
16331 VkMemoryRequirements memReqs;
Mike Stroyana3082432015-09-25 13:39:21 -060016332
16333 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070016334 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
16335 image_create_info.pNext = NULL;
16336 image_create_info.imageType = VK_IMAGE_TYPE_2D;
16337 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
16338 image_create_info.extent.width = 32;
16339 image_create_info.extent.height = 1;
16340 image_create_info.extent.depth = 1;
16341 image_create_info.mipLevels = 1;
16342 image_create_info.arrayLayers = 1;
16343 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
16344 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
16345 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
16346 image_create_info.flags = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060016347
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016348 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
Mike Stroyana3082432015-09-25 13:39:21 -060016349 ASSERT_VK_SUCCESS(err);
16350
Karl Schultz6addd812016-02-02 17:17:23 -070016351 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060016352
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016353 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
Mike Stroyana3082432015-09-25 13:39:21 -060016354 ASSERT_VK_SUCCESS(err);
16355
16356 // Allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016357 VkMemoryAllocateInfo memAlloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -070016358 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
16359 memAlloc.pNext = NULL;
16360 memAlloc.allocationSize = 0;
16361 memAlloc.memoryTypeIndex = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060016362
Courtney Goeltzenleuchter06d89472015-10-20 16:40:38 -060016363 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060016364 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016365 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060016366 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016367 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
Mike Stroyana3082432015-09-25 13:39:21 -060016368 ASSERT_VK_SUCCESS(err);
16369
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016370 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060016371 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016372 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060016373 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016374 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
Mike Stroyana3082432015-09-25 13:39:21 -060016375 ASSERT_VK_SUCCESS(err);
16376
16377 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
16378 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016379 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
Mike Stroyana3082432015-09-25 13:39:21 -060016380 ASSERT_VK_SUCCESS(err);
16381
16382 BeginCommandBuffer();
16383 // Need memory barrier to VK_IMAGE_LAYOUT_GENERAL for source and dest?
Karl Schultz6addd812016-02-02 17:17:23 -070016384 // VK_IMAGE_LAYOUT_UNDEFINED = 0,
16385 // VK_IMAGE_LAYOUT_GENERAL = 1,
Mike Stroyana3082432015-09-25 13:39:21 -060016386 VkImageResolve resolveRegion;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080016387 resolveRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060016388 resolveRegion.srcSubresource.mipLevel = 0;
Courtney Goeltzenleuchter8367ce02015-10-16 09:46:00 -060016389 resolveRegion.srcSubresource.baseArrayLayer = 0;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016390 resolveRegion.srcSubresource.layerCount = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060016391 resolveRegion.srcOffset.x = 0;
16392 resolveRegion.srcOffset.y = 0;
16393 resolveRegion.srcOffset.z = 0;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080016394 resolveRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016395 resolveRegion.dstSubresource.mipLevel = 0;
16396 resolveRegion.dstSubresource.baseArrayLayer = 0;
16397 resolveRegion.dstSubresource.layerCount = 0;
16398 resolveRegion.dstOffset.x = 0;
16399 resolveRegion.dstOffset.y = 0;
16400 resolveRegion.dstOffset.z = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060016401 resolveRegion.extent.width = 1;
16402 resolveRegion.extent.height = 1;
16403 resolveRegion.extent.depth = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016404 m_commandBuffer->ResolveImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, VK_IMAGE_LAYOUT_GENERAL, 1, &resolveRegion);
Mike Stroyana3082432015-09-25 13:39:21 -060016405 EndCommandBuffer();
16406
Chris Forbes8f36a8a2016-04-07 13:21:07 +120016407 m_errorMonitor->VerifyFound();
Mike Stroyana3082432015-09-25 13:39:21 -060016408
Chia-I Wuf7458c52015-10-26 21:10:41 +080016409 vkDestroyImage(m_device->device(), srcImage, NULL);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016410 vkDestroyImage(m_device->device(), dstImage, NULL);
Chia-I Wuf7458c52015-10-26 21:10:41 +080016411 vkFreeMemory(m_device->device(), srcMem, NULL);
16412 vkFreeMemory(m_device->device(), destMem, NULL);
Mike Stroyana3082432015-09-25 13:39:21 -060016413}
16414
Karl Schultz6addd812016-02-02 17:17:23 -070016415TEST_F(VkLayerTest, ResolveImageHighSampleCount) {
16416 VkResult err;
16417 bool pass;
Mike Stroyana3082432015-09-25 13:39:21 -060016418
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016419 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
16420 "vkCmdResolveImage called with dest sample count greater than 1.");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060016421
Mike Stroyana3082432015-09-25 13:39:21 -060016422 ASSERT_NO_FATAL_FAILURE(InitState());
Mike Stroyana3082432015-09-25 13:39:21 -060016423
Chris Forbesa7530692016-05-08 12:35:39 +120016424 // Create two images of sample count 4 and try to Resolve between them
Karl Schultz6addd812016-02-02 17:17:23 -070016425 VkImage srcImage;
16426 VkImage dstImage;
16427 VkDeviceMemory srcMem;
16428 VkDeviceMemory destMem;
16429 VkMemoryRequirements memReqs;
Mike Stroyana3082432015-09-25 13:39:21 -060016430
16431 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070016432 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
16433 image_create_info.pNext = NULL;
16434 image_create_info.imageType = VK_IMAGE_TYPE_2D;
16435 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
16436 image_create_info.extent.width = 32;
16437 image_create_info.extent.height = 1;
16438 image_create_info.extent.depth = 1;
16439 image_create_info.mipLevels = 1;
16440 image_create_info.arrayLayers = 1;
Chris Forbesa7530692016-05-08 12:35:39 +120016441 image_create_info.samples = VK_SAMPLE_COUNT_4_BIT;
Karl Schultz6addd812016-02-02 17:17:23 -070016442 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
16443 // 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_SRC_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
Karl Schultz6addd812016-02-02 17:17:23 -070016446 image_create_info.flags = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060016447
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016448 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
Mike Stroyana3082432015-09-25 13:39:21 -060016449 ASSERT_VK_SUCCESS(err);
16450
Karl Schultz6addd812016-02-02 17:17:23 -070016451 // Note: Some implementations expect color attachment usage for any
16452 // multisample surface
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016453 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060016454
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016455 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
Mike Stroyana3082432015-09-25 13:39:21 -060016456 ASSERT_VK_SUCCESS(err);
16457
16458 // Allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016459 VkMemoryAllocateInfo memAlloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -070016460 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
16461 memAlloc.pNext = NULL;
16462 memAlloc.allocationSize = 0;
16463 memAlloc.memoryTypeIndex = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060016464
Courtney Goeltzenleuchter06d89472015-10-20 16:40:38 -060016465 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060016466 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016467 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060016468 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016469 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
Mike Stroyana3082432015-09-25 13:39:21 -060016470 ASSERT_VK_SUCCESS(err);
16471
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016472 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060016473 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016474 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060016475 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016476 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
Mike Stroyana3082432015-09-25 13:39:21 -060016477 ASSERT_VK_SUCCESS(err);
16478
16479 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
16480 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016481 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
Mike Stroyana3082432015-09-25 13:39:21 -060016482 ASSERT_VK_SUCCESS(err);
16483
16484 BeginCommandBuffer();
16485 // Need memory barrier to VK_IMAGE_LAYOUT_GENERAL for source and dest?
Karl Schultz6addd812016-02-02 17:17:23 -070016486 // VK_IMAGE_LAYOUT_UNDEFINED = 0,
16487 // VK_IMAGE_LAYOUT_GENERAL = 1,
Mike Stroyana3082432015-09-25 13:39:21 -060016488 VkImageResolve resolveRegion;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080016489 resolveRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060016490 resolveRegion.srcSubresource.mipLevel = 0;
Courtney Goeltzenleuchter8367ce02015-10-16 09:46:00 -060016491 resolveRegion.srcSubresource.baseArrayLayer = 0;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016492 resolveRegion.srcSubresource.layerCount = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060016493 resolveRegion.srcOffset.x = 0;
16494 resolveRegion.srcOffset.y = 0;
16495 resolveRegion.srcOffset.z = 0;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080016496 resolveRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016497 resolveRegion.dstSubresource.mipLevel = 0;
16498 resolveRegion.dstSubresource.baseArrayLayer = 0;
16499 resolveRegion.dstSubresource.layerCount = 0;
16500 resolveRegion.dstOffset.x = 0;
16501 resolveRegion.dstOffset.y = 0;
16502 resolveRegion.dstOffset.z = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060016503 resolveRegion.extent.width = 1;
16504 resolveRegion.extent.height = 1;
16505 resolveRegion.extent.depth = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016506 m_commandBuffer->ResolveImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, VK_IMAGE_LAYOUT_GENERAL, 1, &resolveRegion);
Mike Stroyana3082432015-09-25 13:39:21 -060016507 EndCommandBuffer();
16508
Chris Forbes8f36a8a2016-04-07 13:21:07 +120016509 m_errorMonitor->VerifyFound();
Mike Stroyana3082432015-09-25 13:39:21 -060016510
Chia-I Wuf7458c52015-10-26 21:10:41 +080016511 vkDestroyImage(m_device->device(), srcImage, NULL);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016512 vkDestroyImage(m_device->device(), dstImage, NULL);
Chia-I Wuf7458c52015-10-26 21:10:41 +080016513 vkFreeMemory(m_device->device(), srcMem, NULL);
16514 vkFreeMemory(m_device->device(), destMem, NULL);
Mike Stroyana3082432015-09-25 13:39:21 -060016515}
16516
Karl Schultz6addd812016-02-02 17:17:23 -070016517TEST_F(VkLayerTest, ResolveImageFormatMismatch) {
16518 VkResult err;
16519 bool pass;
Mike Stroyana3082432015-09-25 13:39:21 -060016520
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016521 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
16522 "vkCmdResolveImage called with unmatched source and dest formats.");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060016523
Mike Stroyana3082432015-09-25 13:39:21 -060016524 ASSERT_NO_FATAL_FAILURE(InitState());
Mike Stroyana3082432015-09-25 13:39:21 -060016525
16526 // Create two images of different types and try to copy between them
Karl Schultz6addd812016-02-02 17:17:23 -070016527 VkImage srcImage;
16528 VkImage dstImage;
16529 VkDeviceMemory srcMem;
16530 VkDeviceMemory destMem;
16531 VkMemoryRequirements memReqs;
Mike Stroyana3082432015-09-25 13:39:21 -060016532
16533 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070016534 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
16535 image_create_info.pNext = NULL;
16536 image_create_info.imageType = VK_IMAGE_TYPE_2D;
16537 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
16538 image_create_info.extent.width = 32;
16539 image_create_info.extent.height = 1;
16540 image_create_info.extent.depth = 1;
16541 image_create_info.mipLevels = 1;
16542 image_create_info.arrayLayers = 1;
16543 image_create_info.samples = VK_SAMPLE_COUNT_2_BIT;
16544 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
16545 // Note: Some implementations expect color attachment usage for any
16546 // multisample surface
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016547 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
Karl Schultz6addd812016-02-02 17:17:23 -070016548 image_create_info.flags = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060016549
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016550 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
Mike Stroyana3082432015-09-25 13:39:21 -060016551 ASSERT_VK_SUCCESS(err);
16552
Karl Schultz6addd812016-02-02 17:17:23 -070016553 // Set format to something other than source image
16554 image_create_info.format = VK_FORMAT_R32_SFLOAT;
16555 // Note: Some implementations expect color attachment usage for any
16556 // multisample surface
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016557 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
Karl Schultz6addd812016-02-02 17:17:23 -070016558 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060016559
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016560 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
Mike Stroyana3082432015-09-25 13:39:21 -060016561 ASSERT_VK_SUCCESS(err);
16562
16563 // Allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016564 VkMemoryAllocateInfo memAlloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -070016565 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
16566 memAlloc.pNext = NULL;
16567 memAlloc.allocationSize = 0;
16568 memAlloc.memoryTypeIndex = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060016569
Courtney Goeltzenleuchter06d89472015-10-20 16:40:38 -060016570 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060016571 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016572 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060016573 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016574 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
Mike Stroyana3082432015-09-25 13:39:21 -060016575 ASSERT_VK_SUCCESS(err);
16576
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016577 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060016578 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016579 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060016580 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016581 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
Mike Stroyana3082432015-09-25 13:39:21 -060016582 ASSERT_VK_SUCCESS(err);
16583
16584 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
16585 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016586 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
Mike Stroyana3082432015-09-25 13:39:21 -060016587 ASSERT_VK_SUCCESS(err);
16588
16589 BeginCommandBuffer();
16590 // Need memory barrier to VK_IMAGE_LAYOUT_GENERAL for source and dest?
Karl Schultz6addd812016-02-02 17:17:23 -070016591 // VK_IMAGE_LAYOUT_UNDEFINED = 0,
16592 // VK_IMAGE_LAYOUT_GENERAL = 1,
Mike Stroyana3082432015-09-25 13:39:21 -060016593 VkImageResolve resolveRegion;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080016594 resolveRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060016595 resolveRegion.srcSubresource.mipLevel = 0;
Courtney Goeltzenleuchter8367ce02015-10-16 09:46:00 -060016596 resolveRegion.srcSubresource.baseArrayLayer = 0;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016597 resolveRegion.srcSubresource.layerCount = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060016598 resolveRegion.srcOffset.x = 0;
16599 resolveRegion.srcOffset.y = 0;
16600 resolveRegion.srcOffset.z = 0;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080016601 resolveRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016602 resolveRegion.dstSubresource.mipLevel = 0;
16603 resolveRegion.dstSubresource.baseArrayLayer = 0;
16604 resolveRegion.dstSubresource.layerCount = 0;
16605 resolveRegion.dstOffset.x = 0;
16606 resolveRegion.dstOffset.y = 0;
16607 resolveRegion.dstOffset.z = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060016608 resolveRegion.extent.width = 1;
16609 resolveRegion.extent.height = 1;
16610 resolveRegion.extent.depth = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016611 m_commandBuffer->ResolveImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, VK_IMAGE_LAYOUT_GENERAL, 1, &resolveRegion);
Mike Stroyana3082432015-09-25 13:39:21 -060016612 EndCommandBuffer();
16613
Chris Forbes8f36a8a2016-04-07 13:21:07 +120016614 m_errorMonitor->VerifyFound();
Mike Stroyana3082432015-09-25 13:39:21 -060016615
Chia-I Wuf7458c52015-10-26 21:10:41 +080016616 vkDestroyImage(m_device->device(), srcImage, NULL);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016617 vkDestroyImage(m_device->device(), dstImage, NULL);
Chia-I Wuf7458c52015-10-26 21:10:41 +080016618 vkFreeMemory(m_device->device(), srcMem, NULL);
16619 vkFreeMemory(m_device->device(), destMem, NULL);
Mike Stroyana3082432015-09-25 13:39:21 -060016620}
16621
Karl Schultz6addd812016-02-02 17:17:23 -070016622TEST_F(VkLayerTest, ResolveImageTypeMismatch) {
16623 VkResult err;
16624 bool pass;
Mike Stroyana3082432015-09-25 13:39:21 -060016625
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016626 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
16627 "vkCmdResolveImage called with unmatched source and dest image types.");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060016628
Mike Stroyana3082432015-09-25 13:39:21 -060016629 ASSERT_NO_FATAL_FAILURE(InitState());
Mike Stroyana3082432015-09-25 13:39:21 -060016630
16631 // Create two images of different types and try to copy between them
Karl Schultz6addd812016-02-02 17:17:23 -070016632 VkImage srcImage;
16633 VkImage dstImage;
16634 VkDeviceMemory srcMem;
16635 VkDeviceMemory destMem;
16636 VkMemoryRequirements memReqs;
Mike Stroyana3082432015-09-25 13:39:21 -060016637
16638 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070016639 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
16640 image_create_info.pNext = NULL;
16641 image_create_info.imageType = VK_IMAGE_TYPE_2D;
16642 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
16643 image_create_info.extent.width = 32;
16644 image_create_info.extent.height = 1;
16645 image_create_info.extent.depth = 1;
16646 image_create_info.mipLevels = 1;
16647 image_create_info.arrayLayers = 1;
16648 image_create_info.samples = VK_SAMPLE_COUNT_2_BIT;
16649 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
16650 // Note: Some implementations expect color attachment usage for any
16651 // multisample surface
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016652 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
Karl Schultz6addd812016-02-02 17:17:23 -070016653 image_create_info.flags = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060016654
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016655 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
Mike Stroyana3082432015-09-25 13:39:21 -060016656 ASSERT_VK_SUCCESS(err);
16657
Karl Schultz6addd812016-02-02 17:17:23 -070016658 image_create_info.imageType = VK_IMAGE_TYPE_1D;
16659 // Note: Some implementations expect color attachment usage for any
16660 // multisample surface
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016661 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
Karl Schultz6addd812016-02-02 17:17:23 -070016662 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060016663
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016664 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
Mike Stroyana3082432015-09-25 13:39:21 -060016665 ASSERT_VK_SUCCESS(err);
16666
16667 // Allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016668 VkMemoryAllocateInfo memAlloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -070016669 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
16670 memAlloc.pNext = NULL;
16671 memAlloc.allocationSize = 0;
16672 memAlloc.memoryTypeIndex = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060016673
Courtney Goeltzenleuchter06d89472015-10-20 16:40:38 -060016674 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060016675 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016676 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060016677 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016678 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
Mike Stroyana3082432015-09-25 13:39:21 -060016679 ASSERT_VK_SUCCESS(err);
16680
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016681 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060016682 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016683 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060016684 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016685 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
Mike Stroyana3082432015-09-25 13:39:21 -060016686 ASSERT_VK_SUCCESS(err);
16687
16688 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
16689 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016690 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
Mike Stroyana3082432015-09-25 13:39:21 -060016691 ASSERT_VK_SUCCESS(err);
16692
16693 BeginCommandBuffer();
16694 // Need memory barrier to VK_IMAGE_LAYOUT_GENERAL for source and dest?
Karl Schultz6addd812016-02-02 17:17:23 -070016695 // VK_IMAGE_LAYOUT_UNDEFINED = 0,
16696 // VK_IMAGE_LAYOUT_GENERAL = 1,
Mike Stroyana3082432015-09-25 13:39:21 -060016697 VkImageResolve resolveRegion;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080016698 resolveRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060016699 resolveRegion.srcSubresource.mipLevel = 0;
Courtney Goeltzenleuchter8367ce02015-10-16 09:46:00 -060016700 resolveRegion.srcSubresource.baseArrayLayer = 0;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016701 resolveRegion.srcSubresource.layerCount = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060016702 resolveRegion.srcOffset.x = 0;
16703 resolveRegion.srcOffset.y = 0;
16704 resolveRegion.srcOffset.z = 0;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080016705 resolveRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016706 resolveRegion.dstSubresource.mipLevel = 0;
16707 resolveRegion.dstSubresource.baseArrayLayer = 0;
16708 resolveRegion.dstSubresource.layerCount = 0;
16709 resolveRegion.dstOffset.x = 0;
16710 resolveRegion.dstOffset.y = 0;
16711 resolveRegion.dstOffset.z = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060016712 resolveRegion.extent.width = 1;
16713 resolveRegion.extent.height = 1;
16714 resolveRegion.extent.depth = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016715 m_commandBuffer->ResolveImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, VK_IMAGE_LAYOUT_GENERAL, 1, &resolveRegion);
Mike Stroyana3082432015-09-25 13:39:21 -060016716 EndCommandBuffer();
16717
Chris Forbes8f36a8a2016-04-07 13:21:07 +120016718 m_errorMonitor->VerifyFound();
Mike Stroyana3082432015-09-25 13:39:21 -060016719
Chia-I Wuf7458c52015-10-26 21:10:41 +080016720 vkDestroyImage(m_device->device(), srcImage, NULL);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016721 vkDestroyImage(m_device->device(), dstImage, NULL);
Chia-I Wuf7458c52015-10-26 21:10:41 +080016722 vkFreeMemory(m_device->device(), srcMem, NULL);
16723 vkFreeMemory(m_device->device(), destMem, NULL);
Mike Stroyana3082432015-09-25 13:39:21 -060016724}
Tobin Ehlisa1c28562015-10-23 16:00:08 -060016725
Karl Schultz6addd812016-02-02 17:17:23 -070016726TEST_F(VkLayerTest, DepthStencilImageViewWithColorAspectBitError) {
Tobin Ehlisa1c28562015-10-23 16:00:08 -060016727 // Create a single Image descriptor and cause it to first hit an error due
Karl Schultz6addd812016-02-02 17:17:23 -070016728 // to using a DS format, then cause it to hit error due to COLOR_BIT not
16729 // set in aspect
Tobin Ehlisa1c28562015-10-23 16:00:08 -060016730 // The image format check comes 2nd in validation so we trigger it first,
16731 // then when we cause aspect fail next, bad format check will be preempted
Karl Schultz6addd812016-02-02 17:17:23 -070016732 VkResult err;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060016733
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016734 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
16735 "Combination depth/stencil image formats can have only the ");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060016736
Tobin Ehlisa1c28562015-10-23 16:00:08 -060016737 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060016738
Chia-I Wu1b99bb22015-10-27 19:25:11 +080016739 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -070016740 ds_type_count.type = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE;
16741 ds_type_count.descriptorCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060016742
16743 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070016744 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
16745 ds_pool_ci.pNext = NULL;
16746 ds_pool_ci.maxSets = 1;
16747 ds_pool_ci.poolSizeCount = 1;
16748 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060016749
16750 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016751 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060016752 ASSERT_VK_SUCCESS(err);
16753
16754 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -070016755 dsl_binding.binding = 0;
16756 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE;
16757 dsl_binding.descriptorCount = 1;
16758 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
16759 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060016760
16761 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070016762 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
16763 ds_layout_ci.pNext = NULL;
16764 ds_layout_ci.bindingCount = 1;
16765 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060016766 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016767 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060016768 ASSERT_VK_SUCCESS(err);
16769
16770 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016771 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +080016772 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -070016773 alloc_info.descriptorSetCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060016774 alloc_info.descriptorPool = ds_pool;
16775 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016776 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060016777 ASSERT_VK_SUCCESS(err);
16778
Karl Schultz6addd812016-02-02 17:17:23 -070016779 VkImage image_bad;
16780 VkImage image_good;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060016781 // One bad format and one good format for Color attachment
Tobin Ehlis269f0322016-05-25 16:24:21 -060016782 const VkFormat tex_format_bad = VK_FORMAT_D24_UNORM_S8_UINT;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060016783 const VkFormat tex_format_good = VK_FORMAT_B8G8R8A8_UNORM;
Karl Schultz6addd812016-02-02 17:17:23 -070016784 const int32_t tex_width = 32;
16785 const int32_t tex_height = 32;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060016786
16787 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070016788 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
16789 image_create_info.pNext = NULL;
16790 image_create_info.imageType = VK_IMAGE_TYPE_2D;
16791 image_create_info.format = tex_format_bad;
16792 image_create_info.extent.width = tex_width;
16793 image_create_info.extent.height = tex_height;
16794 image_create_info.extent.depth = 1;
16795 image_create_info.mipLevels = 1;
16796 image_create_info.arrayLayers = 1;
16797 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
16798 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016799 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT | VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT;
Karl Schultz6addd812016-02-02 17:17:23 -070016800 image_create_info.flags = 0;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060016801
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016802 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image_bad);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060016803 ASSERT_VK_SUCCESS(err);
16804 image_create_info.format = tex_format_good;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016805 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
16806 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image_good);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060016807 ASSERT_VK_SUCCESS(err);
16808
16809 VkImageViewCreateInfo image_view_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070016810 image_view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
16811 image_view_create_info.image = image_bad;
16812 image_view_create_info.viewType = VK_IMAGE_VIEW_TYPE_2D;
16813 image_view_create_info.format = tex_format_bad;
16814 image_view_create_info.subresourceRange.baseArrayLayer = 0;
16815 image_view_create_info.subresourceRange.baseMipLevel = 0;
16816 image_view_create_info.subresourceRange.layerCount = 1;
16817 image_view_create_info.subresourceRange.levelCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016818 image_view_create_info.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060016819
16820 VkImageView view;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016821 err = vkCreateImageView(m_device->device(), &image_view_create_info, NULL, &view);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060016822
Chris Forbes8f36a8a2016-04-07 13:21:07 +120016823 m_errorMonitor->VerifyFound();
Tobin Ehlisa1c28562015-10-23 16:00:08 -060016824
Chia-I Wuf7458c52015-10-26 21:10:41 +080016825 vkDestroyImage(m_device->device(), image_bad, NULL);
16826 vkDestroyImage(m_device->device(), image_good, NULL);
Chia-I Wuf7458c52015-10-26 21:10:41 +080016827 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
16828 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060016829}
Tobin Ehlis6e23d772016-05-19 11:08:34 -060016830
16831TEST_F(VkLayerTest, ClearImageErrors) {
16832 TEST_DESCRIPTION("Call ClearColorImage w/ a depth|stencil image and "
16833 "ClearDepthStencilImage with a color image.");
16834
16835 ASSERT_NO_FATAL_FAILURE(InitState());
16836 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
16837
16838 // Renderpass is started here so end it as Clear cmds can't be in renderpass
16839 BeginCommandBuffer();
16840 m_commandBuffer->EndRenderPass();
16841
16842 // Color image
16843 VkClearColorValue clear_color;
16844 memset(clear_color.uint32, 0, sizeof(uint32_t) * 4);
16845 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
16846 const VkFormat color_format = VK_FORMAT_B8G8R8A8_UNORM;
16847 const int32_t img_width = 32;
16848 const int32_t img_height = 32;
16849 VkImageCreateInfo image_create_info = {};
16850 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
16851 image_create_info.pNext = NULL;
16852 image_create_info.imageType = VK_IMAGE_TYPE_2D;
16853 image_create_info.format = color_format;
16854 image_create_info.extent.width = img_width;
16855 image_create_info.extent.height = img_height;
16856 image_create_info.extent.depth = 1;
16857 image_create_info.mipLevels = 1;
16858 image_create_info.arrayLayers = 1;
16859 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
16860 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
16861 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
16862
16863 vk_testing::Image color_image;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016864 color_image.init(*m_device, (const VkImageCreateInfo &)image_create_info, reqs);
Tobin Ehlis6e23d772016-05-19 11:08:34 -060016865
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016866 const VkImageSubresourceRange color_range = vk_testing::Image::subresource_range(image_create_info, VK_IMAGE_ASPECT_COLOR_BIT);
Tobin Ehlis6e23d772016-05-19 11:08:34 -060016867
16868 // Depth/Stencil image
16869 VkClearDepthStencilValue clear_value = {0};
16870 reqs = 0; // don't need HOST_VISIBLE DS image
16871 VkImageCreateInfo ds_image_create_info = vk_testing::Image::create_info();
16872 ds_image_create_info.imageType = VK_IMAGE_TYPE_2D;
16873 ds_image_create_info.format = VK_FORMAT_D24_UNORM_S8_UINT;
16874 ds_image_create_info.extent.width = 64;
16875 ds_image_create_info.extent.height = 64;
16876 ds_image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
16877 ds_image_create_info.usage = VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT;
16878
16879 vk_testing::Image ds_image;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016880 ds_image.init(*m_device, (const VkImageCreateInfo &)ds_image_create_info, reqs);
Tobin Ehlis6e23d772016-05-19 11:08:34 -060016881
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016882 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 -060016883
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016884 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "vkCmdClearColorImage called with depth/stencil image.");
Tobin Ehlis6e23d772016-05-19 11:08:34 -060016885
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016886 vkCmdClearColorImage(m_commandBuffer->GetBufferHandle(), ds_image.handle(), VK_IMAGE_LAYOUT_GENERAL, &clear_color, 1,
Tobin Ehlis6e23d772016-05-19 11:08:34 -060016887 &color_range);
16888
16889 m_errorMonitor->VerifyFound();
16890
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016891 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "vkCmdClearColorImage called with "
16892 "image created without "
16893 "VK_IMAGE_USAGE_TRANSFER_DST_BIT");
Tony Barbour26434b92016-06-02 09:43:50 -060016894
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016895 vkCmdClearColorImage(m_commandBuffer->GetBufferHandle(), ds_image.handle(), VK_IMAGE_LAYOUT_GENERAL, &clear_color, 1,
Tony Barbour26434b92016-06-02 09:43:50 -060016896 &color_range);
16897
16898 m_errorMonitor->VerifyFound();
16899
Tobin Ehlis6e23d772016-05-19 11:08:34 -060016900 // Call CmdClearDepthStencilImage with color image
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016901 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
16902 "vkCmdClearDepthStencilImage called without a depth/stencil image.");
Tobin Ehlis6e23d772016-05-19 11:08:34 -060016903
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016904 vkCmdClearDepthStencilImage(m_commandBuffer->GetBufferHandle(), color_image.handle(),
16905 VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL, &clear_value, 1, &ds_range);
Tobin Ehlis6e23d772016-05-19 11:08:34 -060016906
16907 m_errorMonitor->VerifyFound();
16908}
Tobin Ehliscde08892015-09-22 10:11:37 -060016909#endif // IMAGE_TESTS
16910
Cody Northrop1242dfd2016-07-13 17:24:59 -060016911#if defined(ANDROID) && defined(VALIDATION_APK)
16912static bool initialized = false;
16913static bool active = false;
16914
16915// Convert Intents to argv
16916// Ported from Hologram sample, only difference is flexible key
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016917std::vector<std::string> get_args(android_app &app, const char *intent_extra_data_key) {
Cody Northrop1242dfd2016-07-13 17:24:59 -060016918 std::vector<std::string> args;
16919 JavaVM &vm = *app.activity->vm;
16920 JNIEnv *p_env;
16921 if (vm.AttachCurrentThread(&p_env, nullptr) != JNI_OK)
16922 return args;
16923
16924 JNIEnv &env = *p_env;
16925 jobject activity = app.activity->clazz;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016926 jmethodID get_intent_method = env.GetMethodID(env.GetObjectClass(activity), "getIntent", "()Landroid/content/Intent;");
Cody Northrop1242dfd2016-07-13 17:24:59 -060016927 jobject intent = env.CallObjectMethod(activity, get_intent_method);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016928 jmethodID get_string_extra_method =
16929 env.GetMethodID(env.GetObjectClass(intent), "getStringExtra", "(Ljava/lang/String;)Ljava/lang/String;");
Cody Northrop1242dfd2016-07-13 17:24:59 -060016930 jvalue get_string_extra_args;
16931 get_string_extra_args.l = env.NewStringUTF(intent_extra_data_key);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016932 jstring extra_str = static_cast<jstring>(env.CallObjectMethodA(intent, get_string_extra_method, &get_string_extra_args));
Cody Northrop1242dfd2016-07-13 17:24:59 -060016933
16934 std::string args_str;
16935 if (extra_str) {
16936 const char *extra_utf = env.GetStringUTFChars(extra_str, nullptr);
16937 args_str = extra_utf;
16938 env.ReleaseStringUTFChars(extra_str, extra_utf);
16939 env.DeleteLocalRef(extra_str);
16940 }
16941
16942 env.DeleteLocalRef(get_string_extra_args.l);
16943 env.DeleteLocalRef(intent);
16944 vm.DetachCurrentThread();
16945
16946 // split args_str
16947 std::stringstream ss(args_str);
16948 std::string arg;
16949 while (std::getline(ss, arg, ' ')) {
16950 if (!arg.empty())
16951 args.push_back(arg);
16952 }
16953
16954 return args;
16955}
16956
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016957static int32_t processInput(struct android_app *app, AInputEvent *event) { return 0; }
Cody Northrop1242dfd2016-07-13 17:24:59 -060016958
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016959static void processCommand(struct android_app *app, int32_t cmd) {
16960 switch (cmd) {
16961 case APP_CMD_INIT_WINDOW: {
16962 if (app->window) {
16963 initialized = true;
Cody Northrop1242dfd2016-07-13 17:24:59 -060016964 }
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016965 break;
16966 }
16967 case APP_CMD_GAINED_FOCUS: {
16968 active = true;
16969 break;
16970 }
16971 case APP_CMD_LOST_FOCUS: {
16972 active = false;
16973 break;
16974 }
Cody Northrop1242dfd2016-07-13 17:24:59 -060016975 }
16976}
16977
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016978void android_main(struct android_app *app) {
Cody Northrop1242dfd2016-07-13 17:24:59 -060016979 app_dummy();
16980
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016981 const char *appTag = "VulkanLayerValidationTests";
Cody Northrop1242dfd2016-07-13 17:24:59 -060016982
16983 int vulkanSupport = InitVulkan();
16984 if (vulkanSupport == 0) {
16985 __android_log_print(ANDROID_LOG_INFO, appTag, "==== FAILED ==== No Vulkan support found");
16986 return;
16987 }
16988
16989 app->onAppCmd = processCommand;
16990 app->onInputEvent = processInput;
16991
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016992 while (1) {
Cody Northrop1242dfd2016-07-13 17:24:59 -060016993 int events;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016994 struct android_poll_source *source;
16995 while (ALooper_pollAll(active ? 0 : -1, NULL, &events, (void **)&source) >= 0) {
Cody Northrop1242dfd2016-07-13 17:24:59 -060016996 if (source) {
16997 source->process(app, source);
16998 }
16999
17000 if (app->destroyRequested != 0) {
17001 VkTestFramework::Finish();
17002 return;
17003 }
17004 }
17005
17006 if (initialized && active) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017007 // Use the following key to send arguments to gtest, i.e.
17008 // --es args "--gtest_filter=-VkLayerTest.foo"
17009 const char key[] = "args";
17010 std::vector<std::string> args = get_args(*app, key);
Cody Northrop1242dfd2016-07-13 17:24:59 -060017011
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017012 std::string filter = "";
17013 if (args.size() > 0) {
17014 __android_log_print(ANDROID_LOG_INFO, appTag, "Intent args = %s", args[0].c_str());
17015 filter += args[0];
17016 } else {
17017 __android_log_print(ANDROID_LOG_INFO, appTag, "No Intent args detected");
17018 }
Cody Northrop1242dfd2016-07-13 17:24:59 -060017019
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017020 int argc = 2;
17021 char *argv[] = {(char *)"foo", (char *)filter.c_str()};
17022 __android_log_print(ANDROID_LOG_DEBUG, appTag, "filter = %s", argv[1]);
Cody Northrop1242dfd2016-07-13 17:24:59 -060017023
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017024 // Route output to files until we can override the gtest output
17025 freopen("/sdcard/Android/data/com.example.VulkanLayerValidationTests/files/out.txt", "w", stdout);
17026 freopen("/sdcard/Android/data/com.example.VulkanLayerValidationTests/files/err.txt", "w", stderr);
Cody Northrop1242dfd2016-07-13 17:24:59 -060017027
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017028 ::testing::InitGoogleTest(&argc, argv);
17029 VkTestFramework::InitArgs(&argc, argv);
17030 ::testing::AddGlobalTestEnvironment(new TestEnvironment);
Cody Northrop1242dfd2016-07-13 17:24:59 -060017031
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017032 int result = RUN_ALL_TESTS();
Cody Northrop1242dfd2016-07-13 17:24:59 -060017033
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017034 if (result != 0) {
17035 __android_log_print(ANDROID_LOG_INFO, appTag, "==== Tests FAILED ====");
17036 } else {
17037 __android_log_print(ANDROID_LOG_INFO, appTag, "==== Tests PASSED ====");
17038 }
Cody Northrop1242dfd2016-07-13 17:24:59 -060017039
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017040 VkTestFramework::Finish();
Cody Northrop1242dfd2016-07-13 17:24:59 -060017041
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017042 fclose(stdout);
17043 fclose(stderr);
Cody Northrop1242dfd2016-07-13 17:24:59 -060017044
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017045 ANativeActivity_finish(app->activity);
Cody Northrop1242dfd2016-07-13 17:24:59 -060017046
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017047 return;
Cody Northrop1242dfd2016-07-13 17:24:59 -060017048 }
17049 }
17050}
17051#endif
17052
Tony Barbour300a6082015-04-07 13:44:53 -060017053int main(int argc, char **argv) {
17054 int result;
17055
Cody Northrop8e54a402016-03-08 22:25:52 -070017056#ifdef ANDROID
17057 int vulkanSupport = InitVulkan();
17058 if (vulkanSupport == 0)
17059 return 1;
17060#endif
17061
Tony Barbour300a6082015-04-07 13:44:53 -060017062 ::testing::InitGoogleTest(&argc, argv);
Tony Barbour6918cd52015-04-09 12:58:51 -060017063 VkTestFramework::InitArgs(&argc, argv);
Tony Barbour300a6082015-04-07 13:44:53 -060017064
17065 ::testing::AddGlobalTestEnvironment(new TestEnvironment);
17066
17067 result = RUN_ALL_TESTS();
17068
Tony Barbour6918cd52015-04-09 12:58:51 -060017069 VkTestFramework::Finish();
Tony Barbour300a6082015-04-07 13:44:53 -060017070 return result;
17071}