blob: eff01664cd26ddc95e158d8c79964de4935b3ada [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
Chris Forbeseb7d5502016-09-13 18:19:21 +12002289 // Add a fence to avoid (justifiable) error about not providing fence OR semaphore
2290 VkFenceCreateInfo fci = { VK_STRUCTURE_TYPE_FENCE_CREATE_INFO, nullptr, 0 };
2291 VkFence fence;
2292 err = vkCreateFence(m_device->device(), &fci, nullptr, &fence);
2293
Ian Elliott1c32c772016-04-28 14:47:13 -06002294 // Try to acquire an image:
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002295 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
Chris Forbeseb7d5502016-09-13 18:19:21 +12002296 err = vkAcquireNextImageKHR(m_device->device(), swapchain, 0, VK_NULL_HANDLE, fence, &image_index);
Ian Elliott1c32c772016-04-28 14:47:13 -06002297 pass = (err != VK_SUCCESS);
2298 ASSERT_TRUE(pass);
2299 m_errorMonitor->VerifyFound();
2300
Chris Forbeseb7d5502016-09-13 18:19:21 +12002301 vkDestroyFence(m_device->device(), fence, nullptr);
2302
Ian Elliott1c32c772016-04-28 14:47:13 -06002303 // Try to present an image:
Ian Elliott2c1daf52016-05-12 09:41:46 -06002304 //
2305 // NOTE: Currently can't test this because a real swapchain is needed (as
2306 // opposed to the fake one we created) in order for the layer to lookup the
2307 // VkDevice used to enable the extension:
Ian Elliott1c32c772016-04-28 14:47:13 -06002308
2309 // Destroy the swapchain:
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002310 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
Ian Elliott1c32c772016-04-28 14:47:13 -06002311 vkDestroySwapchainKHR(m_device->device(), swapchain, NULL);
2312 m_errorMonitor->VerifyFound();
2313}
2314
Ian Elliott2c1daf52016-05-12 09:41:46 -06002315TEST_F(VkWsiEnabledLayerTest, TestEnabledWsi) {
Ian Elliott2c1daf52016-05-12 09:41:46 -06002316
Dustin Graves6c6d8982016-05-17 10:09:21 -06002317#if defined(VK_USE_PLATFORM_XCB_KHR)
Ian Elliott2c1daf52016-05-12 09:41:46 -06002318 VkSurfaceKHR surface = VK_NULL_HANDLE;
Mark Lobodzinski085d27a2016-05-17 09:34:26 -06002319
Mark Lobodzinski085d27a2016-05-17 09:34:26 -06002320 VkResult err;
2321 bool pass;
Ian Elliott2c1daf52016-05-12 09:41:46 -06002322 VkSwapchainKHR swapchain = VK_NULL_HANDLE;
2323 VkSwapchainCreateInfoKHR swapchain_create_info = {};
Mark Lobodzinski085d27a2016-05-17 09:34:26 -06002324 // uint32_t swapchain_image_count = 0;
2325 // VkImage swapchain_images[1] = {VK_NULL_HANDLE};
2326 // uint32_t image_index = 0;
2327 // VkPresentInfoKHR present_info = {};
Ian Elliott2c1daf52016-05-12 09:41:46 -06002328
2329 ASSERT_NO_FATAL_FAILURE(InitState());
2330
2331 // Use the create function from one of the VK_KHR_*_surface extension in
2332 // order to create a surface, testing all known errors in the process,
2333 // before successfully creating a surface:
2334 // First, try to create a surface without a VkXcbSurfaceCreateInfoKHR:
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002335 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "required parameter pCreateInfo specified as NULL");
Ian Elliott2c1daf52016-05-12 09:41:46 -06002336 err = vkCreateXcbSurfaceKHR(instance(), NULL, NULL, &surface);
2337 pass = (err != VK_SUCCESS);
2338 ASSERT_TRUE(pass);
2339 m_errorMonitor->VerifyFound();
2340
2341 // Next, try to create a surface with the wrong
2342 // VkXcbSurfaceCreateInfoKHR::sType:
2343 VkXcbSurfaceCreateInfoKHR xcb_create_info = {};
2344 xcb_create_info.sType = VK_STRUCTURE_TYPE_APPLICATION_INFO;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002345 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "parameter pCreateInfo->sType must be");
Ian Elliott2c1daf52016-05-12 09:41:46 -06002346 err = vkCreateXcbSurfaceKHR(instance(), &xcb_create_info, NULL, &surface);
2347 pass = (err != VK_SUCCESS);
2348 ASSERT_TRUE(pass);
2349 m_errorMonitor->VerifyFound();
2350
Ian Elliott2c1daf52016-05-12 09:41:46 -06002351 // Create a native window, and then correctly create a surface:
2352 xcb_connection_t *connection;
2353 xcb_screen_t *screen;
2354 xcb_window_t xcb_window;
2355 xcb_intern_atom_reply_t *atom_wm_delete_window;
2356
2357 const xcb_setup_t *setup;
2358 xcb_screen_iterator_t iter;
2359 int scr;
2360 uint32_t value_mask, value_list[32];
2361 int width = 1;
2362 int height = 1;
2363
2364 connection = xcb_connect(NULL, &scr);
2365 ASSERT_TRUE(connection != NULL);
2366 setup = xcb_get_setup(connection);
2367 iter = xcb_setup_roots_iterator(setup);
2368 while (scr-- > 0)
2369 xcb_screen_next(&iter);
2370 screen = iter.data;
2371
2372 xcb_window = xcb_generate_id(connection);
2373
2374 value_mask = XCB_CW_BACK_PIXEL | XCB_CW_EVENT_MASK;
2375 value_list[0] = screen->black_pixel;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002376 value_list[1] = XCB_EVENT_MASK_KEY_RELEASE | XCB_EVENT_MASK_EXPOSURE | XCB_EVENT_MASK_STRUCTURE_NOTIFY;
Ian Elliott2c1daf52016-05-12 09:41:46 -06002377
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002378 xcb_create_window(connection, XCB_COPY_FROM_PARENT, xcb_window, screen->root, 0, 0, width, height, 0,
2379 XCB_WINDOW_CLASS_INPUT_OUTPUT, screen->root_visual, value_mask, value_list);
Ian Elliott2c1daf52016-05-12 09:41:46 -06002380
2381 /* Magic code that will send notification when window is destroyed */
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002382 xcb_intern_atom_cookie_t cookie = xcb_intern_atom(connection, 1, 12, "WM_PROTOCOLS");
2383 xcb_intern_atom_reply_t *reply = xcb_intern_atom_reply(connection, cookie, 0);
Ian Elliott2c1daf52016-05-12 09:41:46 -06002384
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002385 xcb_intern_atom_cookie_t cookie2 = xcb_intern_atom(connection, 0, 16, "WM_DELETE_WINDOW");
Mark Lobodzinski085d27a2016-05-17 09:34:26 -06002386 atom_wm_delete_window = xcb_intern_atom_reply(connection, cookie2, 0);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002387 xcb_change_property(connection, XCB_PROP_MODE_REPLACE, xcb_window, (*reply).atom, 4, 32, 1, &(*atom_wm_delete_window).atom);
Ian Elliott2c1daf52016-05-12 09:41:46 -06002388 free(reply);
2389
2390 xcb_map_window(connection, xcb_window);
2391
2392 // Force the x/y coordinates to 100,100 results are identical in consecutive
2393 // runs
2394 const uint32_t coords[] = {100, 100};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002395 xcb_configure_window(connection, xcb_window, XCB_CONFIG_WINDOW_X | XCB_CONFIG_WINDOW_Y, coords);
Ian Elliott2c1daf52016-05-12 09:41:46 -06002396
Ian Elliott2c1daf52016-05-12 09:41:46 -06002397 // Finally, try to correctly create a surface:
2398 xcb_create_info.sType = VK_STRUCTURE_TYPE_XCB_SURFACE_CREATE_INFO_KHR;
2399 xcb_create_info.pNext = NULL;
2400 xcb_create_info.flags = 0;
2401 xcb_create_info.connection = connection;
2402 xcb_create_info.window = xcb_window;
2403 err = vkCreateXcbSurfaceKHR(instance(), &xcb_create_info, NULL, &surface);
2404 pass = (err == VK_SUCCESS);
2405 ASSERT_TRUE(pass);
2406
Ian Elliott2c1daf52016-05-12 09:41:46 -06002407 // Check if surface supports presentation:
2408
2409 // 1st, do so without having queried the queue families:
2410 VkBool32 supported = false;
2411 // TODO: Get the following error to come out:
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002412 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
2413 "called before calling the vkGetPhysicalDeviceQueueFamilyProperties "
2414 "function");
Ian Elliott2c1daf52016-05-12 09:41:46 -06002415 err = vkGetPhysicalDeviceSurfaceSupportKHR(gpu(), 0, surface, &supported);
2416 pass = (err != VK_SUCCESS);
Mark Lobodzinski085d27a2016-05-17 09:34:26 -06002417 // ASSERT_TRUE(pass);
2418 // m_errorMonitor->VerifyFound();
Ian Elliott2c1daf52016-05-12 09:41:46 -06002419
2420 // Next, query a queue family index that's too large:
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002421 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "called with a queueFamilyIndex that is too large");
2422 err = vkGetPhysicalDeviceSurfaceSupportKHR(gpu(), 100000, surface, &supported);
Ian Elliott2c1daf52016-05-12 09:41:46 -06002423 pass = (err != VK_SUCCESS);
2424 ASSERT_TRUE(pass);
2425 m_errorMonitor->VerifyFound();
2426
2427 // Finally, do so correctly:
Mark Lobodzinski085d27a2016-05-17 09:34:26 -06002428 // FIXME: THIS ISN'T CORRECT--MUST QUERY UNTIL WE FIND A QUEUE FAMILY THAT'S
2429 // SUPPORTED
Ian Elliott2c1daf52016-05-12 09:41:46 -06002430 err = vkGetPhysicalDeviceSurfaceSupportKHR(gpu(), 0, surface, &supported);
2431 pass = (err == VK_SUCCESS);
2432 ASSERT_TRUE(pass);
2433
Ian Elliott2c1daf52016-05-12 09:41:46 -06002434 // Before proceeding, try to create a swapchain without having called
2435 // vkGetPhysicalDeviceSurfaceCapabilitiesKHR():
2436 swapchain_create_info.sType = VK_STRUCTURE_TYPE_SWAPCHAIN_CREATE_INFO_KHR;
2437 swapchain_create_info.pNext = NULL;
2438 swapchain_create_info.flags = 0;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002439 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
2440 "called before calling vkGetPhysicalDeviceSurfaceCapabilitiesKHR().");
2441 err = vkCreateSwapchainKHR(m_device->device(), &swapchain_create_info, NULL, &swapchain);
Ian Elliott2c1daf52016-05-12 09:41:46 -06002442 pass = (err != VK_SUCCESS);
2443 ASSERT_TRUE(pass);
2444 m_errorMonitor->VerifyFound();
2445
Ian Elliott2c1daf52016-05-12 09:41:46 -06002446 // Get the surface capabilities:
2447 VkSurfaceCapabilitiesKHR surface_capabilities;
2448
2449 // Do so correctly (only error logged by this entrypoint is if the
2450 // extension isn't enabled):
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002451 err = vkGetPhysicalDeviceSurfaceCapabilitiesKHR(gpu(), surface, &surface_capabilities);
Ian Elliott2c1daf52016-05-12 09:41:46 -06002452 pass = (err == VK_SUCCESS);
2453 ASSERT_TRUE(pass);
2454
Ian Elliott2c1daf52016-05-12 09:41:46 -06002455 // Get the surface formats:
2456 uint32_t surface_format_count;
2457
2458 // First, try without a pointer to surface_format_count:
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002459 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "required parameter pSurfaceFormatCount "
2460 "specified as NULL");
Ian Elliott2c1daf52016-05-12 09:41:46 -06002461 vkGetPhysicalDeviceSurfaceFormatsKHR(gpu(), surface, NULL, NULL);
2462 pass = (err == VK_SUCCESS);
2463 ASSERT_TRUE(pass);
2464 m_errorMonitor->VerifyFound();
2465
2466 // Next, call with a non-NULL pSurfaceFormats, even though we haven't
2467 // correctly done a 1st try (to get the count):
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002468 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT, "but no prior positive value has been seen for");
Ian Elliott2c1daf52016-05-12 09:41:46 -06002469 surface_format_count = 0;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002470 vkGetPhysicalDeviceSurfaceFormatsKHR(gpu(), surface, &surface_format_count, (VkSurfaceFormatKHR *)&surface_format_count);
Ian Elliott2c1daf52016-05-12 09:41:46 -06002471 pass = (err == VK_SUCCESS);
2472 ASSERT_TRUE(pass);
2473 m_errorMonitor->VerifyFound();
2474
2475 // Next, correctly do a 1st try (with a NULL pointer to surface_formats):
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002476 vkGetPhysicalDeviceSurfaceFormatsKHR(gpu(), surface, &surface_format_count, NULL);
Ian Elliott2c1daf52016-05-12 09:41:46 -06002477 pass = (err == VK_SUCCESS);
2478 ASSERT_TRUE(pass);
2479
2480 // Allocate memory for the correct number of VkSurfaceFormatKHR's:
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002481 VkSurfaceFormatKHR *surface_formats = (VkSurfaceFormatKHR *)malloc(surface_format_count * sizeof(VkSurfaceFormatKHR));
Ian Elliott2c1daf52016-05-12 09:41:46 -06002482
2483 // Next, do a 2nd try with surface_format_count being set too high:
2484 surface_format_count += 5;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002485 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "that is greater than the value");
2486 vkGetPhysicalDeviceSurfaceFormatsKHR(gpu(), surface, &surface_format_count, surface_formats);
Ian Elliott2c1daf52016-05-12 09:41:46 -06002487 pass = (err == VK_SUCCESS);
2488 ASSERT_TRUE(pass);
2489 m_errorMonitor->VerifyFound();
2490
2491 // Finally, do a correct 1st and 2nd try:
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002492 vkGetPhysicalDeviceSurfaceFormatsKHR(gpu(), surface, &surface_format_count, NULL);
Ian Elliott2c1daf52016-05-12 09:41:46 -06002493 pass = (err == VK_SUCCESS);
2494 ASSERT_TRUE(pass);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002495 vkGetPhysicalDeviceSurfaceFormatsKHR(gpu(), surface, &surface_format_count, surface_formats);
Ian Elliott2c1daf52016-05-12 09:41:46 -06002496 pass = (err == VK_SUCCESS);
2497 ASSERT_TRUE(pass);
2498
Ian Elliott2c1daf52016-05-12 09:41:46 -06002499 // Get the surface present modes:
2500 uint32_t surface_present_mode_count;
2501
2502 // First, try without a pointer to surface_format_count:
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002503 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "required parameter pPresentModeCount "
2504 "specified as NULL");
Mark Lobodzinskib02ea642016-08-17 13:03:57 -06002505
Ian Elliott2c1daf52016-05-12 09:41:46 -06002506 vkGetPhysicalDeviceSurfacePresentModesKHR(gpu(), surface, NULL, NULL);
2507 pass = (err == VK_SUCCESS);
2508 ASSERT_TRUE(pass);
2509 m_errorMonitor->VerifyFound();
2510
2511 // Next, call with a non-NULL VkPresentModeKHR, even though we haven't
2512 // correctly done a 1st try (to get the count):
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002513 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT, "but no prior positive value has been seen for");
Ian Elliott2c1daf52016-05-12 09:41:46 -06002514 surface_present_mode_count = 0;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002515 vkGetPhysicalDeviceSurfacePresentModesKHR(gpu(), surface, &surface_present_mode_count,
2516 (VkPresentModeKHR *)&surface_present_mode_count);
Ian Elliott2c1daf52016-05-12 09:41:46 -06002517 pass = (err == VK_SUCCESS);
2518 ASSERT_TRUE(pass);
2519 m_errorMonitor->VerifyFound();
2520
2521 // Next, correctly do a 1st try (with a NULL pointer to surface_formats):
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002522 vkGetPhysicalDeviceSurfacePresentModesKHR(gpu(), surface, &surface_present_mode_count, NULL);
Ian Elliott2c1daf52016-05-12 09:41:46 -06002523 pass = (err == VK_SUCCESS);
2524 ASSERT_TRUE(pass);
2525
2526 // Allocate memory for the correct number of VkSurfaceFormatKHR's:
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002527 VkPresentModeKHR *surface_present_modes = (VkPresentModeKHR *)malloc(surface_present_mode_count * sizeof(VkPresentModeKHR));
Ian Elliott2c1daf52016-05-12 09:41:46 -06002528
2529 // Next, do a 2nd try with surface_format_count being set too high:
2530 surface_present_mode_count += 5;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002531 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "that is greater than the value");
2532 vkGetPhysicalDeviceSurfacePresentModesKHR(gpu(), surface, &surface_present_mode_count, surface_present_modes);
Ian Elliott2c1daf52016-05-12 09:41:46 -06002533 pass = (err == VK_SUCCESS);
2534 ASSERT_TRUE(pass);
2535 m_errorMonitor->VerifyFound();
2536
2537 // Finally, do a correct 1st and 2nd try:
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002538 vkGetPhysicalDeviceSurfacePresentModesKHR(gpu(), surface, &surface_present_mode_count, NULL);
Ian Elliott2c1daf52016-05-12 09:41:46 -06002539 pass = (err == VK_SUCCESS);
2540 ASSERT_TRUE(pass);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002541 vkGetPhysicalDeviceSurfacePresentModesKHR(gpu(), surface, &surface_present_mode_count, surface_present_modes);
Ian Elliott2c1daf52016-05-12 09:41:46 -06002542 pass = (err == VK_SUCCESS);
2543 ASSERT_TRUE(pass);
2544
Ian Elliott2c1daf52016-05-12 09:41:46 -06002545 // Create a swapchain:
2546
2547 // First, try without a pointer to swapchain_create_info:
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002548 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "required parameter pCreateInfo "
2549 "specified as NULL");
Mark Lobodzinskib02ea642016-08-17 13:03:57 -06002550
Ian Elliott2c1daf52016-05-12 09:41:46 -06002551 err = vkCreateSwapchainKHR(m_device->device(), NULL, NULL, &swapchain);
2552 pass = (err != VK_SUCCESS);
2553 ASSERT_TRUE(pass);
2554 m_errorMonitor->VerifyFound();
2555
2556 // Next, call with a non-NULL swapchain_create_info, that has the wrong
2557 // sType:
2558 swapchain_create_info.sType = VK_STRUCTURE_TYPE_APPLICATION_INFO;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002559 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "parameter pCreateInfo->sType must be");
Mark Lobodzinskib02ea642016-08-17 13:03:57 -06002560
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002561 err = vkCreateSwapchainKHR(m_device->device(), &swapchain_create_info, NULL, &swapchain);
Ian Elliott2c1daf52016-05-12 09:41:46 -06002562 pass = (err != VK_SUCCESS);
2563 ASSERT_TRUE(pass);
2564 m_errorMonitor->VerifyFound();
2565
2566 // Next, call with a NULL swapchain pointer:
2567 swapchain_create_info.sType = VK_STRUCTURE_TYPE_SWAPCHAIN_CREATE_INFO_KHR;
2568 swapchain_create_info.pNext = NULL;
2569 swapchain_create_info.flags = 0;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002570 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "required parameter pSwapchain "
2571 "specified as NULL");
Mark Lobodzinskib02ea642016-08-17 13:03:57 -06002572
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002573 err = vkCreateSwapchainKHR(m_device->device(), &swapchain_create_info, NULL, NULL);
Ian Elliott2c1daf52016-05-12 09:41:46 -06002574 pass = (err != VK_SUCCESS);
2575 ASSERT_TRUE(pass);
2576 m_errorMonitor->VerifyFound();
2577
Mark Lobodzinski085d27a2016-05-17 09:34:26 -06002578 // TODO: Enhance swapchain layer so that
2579 // swapchain_create_info.queueFamilyIndexCount is checked against something?
Ian Elliott2c1daf52016-05-12 09:41:46 -06002580
2581 // Next, call with a queue family index that's too large:
2582 uint32_t queueFamilyIndex[2] = {100000, 0};
2583 swapchain_create_info.imageSharingMode = VK_SHARING_MODE_CONCURRENT;
2584 swapchain_create_info.queueFamilyIndexCount = 2;
2585 swapchain_create_info.pQueueFamilyIndices = queueFamilyIndex;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002586 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "called with a queueFamilyIndex that is too large");
2587 err = vkCreateSwapchainKHR(m_device->device(), &swapchain_create_info, NULL, &swapchain);
Ian Elliott2c1daf52016-05-12 09:41:46 -06002588 pass = (err != VK_SUCCESS);
2589 ASSERT_TRUE(pass);
2590 m_errorMonitor->VerifyFound();
2591
2592 // Next, call a queueFamilyIndexCount that's too small for CONCURRENT:
2593 swapchain_create_info.imageSharingMode = VK_SHARING_MODE_CONCURRENT;
2594 swapchain_create_info.queueFamilyIndexCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002595 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
2596 "but with a bad value(s) for pCreateInfo->queueFamilyIndexCount or "
2597 "pCreateInfo->pQueueFamilyIndices).");
2598 err = vkCreateSwapchainKHR(m_device->device(), &swapchain_create_info, NULL, &swapchain);
Ian Elliott2c1daf52016-05-12 09:41:46 -06002599 pass = (err != VK_SUCCESS);
2600 ASSERT_TRUE(pass);
2601 m_errorMonitor->VerifyFound();
2602
2603 // Next, call with an invalid imageSharingMode:
2604 swapchain_create_info.imageSharingMode = VK_SHARING_MODE_MAX_ENUM;
2605 swapchain_create_info.queueFamilyIndexCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002606 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
2607 "called with a non-supported pCreateInfo->imageSharingMode (i.e.");
2608 err = vkCreateSwapchainKHR(m_device->device(), &swapchain_create_info, NULL, &swapchain);
Ian Elliott2c1daf52016-05-12 09:41:46 -06002609 pass = (err != VK_SUCCESS);
2610 ASSERT_TRUE(pass);
2611 m_errorMonitor->VerifyFound();
2612 // Fix for the future:
Mark Lobodzinski085d27a2016-05-17 09:34:26 -06002613 // FIXME: THIS ISN'T CORRECT--MUST QUERY UNTIL WE FIND A QUEUE FAMILY THAT'S
2614 // SUPPORTED
Ian Elliott2c1daf52016-05-12 09:41:46 -06002615 swapchain_create_info.queueFamilyIndexCount = 0;
2616 queueFamilyIndex[0] = 0;
2617 swapchain_create_info.imageSharingMode = VK_SHARING_MODE_EXCLUSIVE;
2618
Mark Lobodzinski085d27a2016-05-17 09:34:26 -06002619 // TODO: CONTINUE TESTING VALIDATION OF vkCreateSwapchainKHR() ...
Ian Elliott2c1daf52016-05-12 09:41:46 -06002620 // Get the images from a swapchain:
Ian Elliott2c1daf52016-05-12 09:41:46 -06002621 // Acquire an image from a swapchain:
Ian Elliott2c1daf52016-05-12 09:41:46 -06002622 // Present an image to a swapchain:
Ian Elliott2c1daf52016-05-12 09:41:46 -06002623 // Destroy the swapchain:
2624
Mark Lobodzinski085d27a2016-05-17 09:34:26 -06002625 // TODOs:
2626 //
2627 // - Try destroying the device without first destroying the swapchain
2628 //
2629 // - Try destroying the device without first destroying the surface
2630 //
2631 // - Try destroying the surface without first destroying the swapchain
Ian Elliott2c1daf52016-05-12 09:41:46 -06002632
2633 // Destroy the surface:
2634 vkDestroySurfaceKHR(instance(), surface, NULL);
2635
Ian Elliott2c1daf52016-05-12 09:41:46 -06002636 // Tear down the window:
2637 xcb_destroy_window(connection, xcb_window);
2638 xcb_disconnect(connection);
2639
2640#else // VK_USE_PLATFORM_XCB_KHR
Mark Lobodzinski085d27a2016-05-17 09:34:26 -06002641 return;
Ian Elliott2c1daf52016-05-12 09:41:46 -06002642#endif // VK_USE_PLATFORM_XCB_KHR
2643}
2644
Karl Schultz6addd812016-02-02 17:17:23 -07002645TEST_F(VkLayerTest, MapMemWithoutHostVisibleBit) {
2646 VkResult err;
2647 bool pass;
Mark Lobodzinski3780e142015-05-14 15:08:13 -05002648
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002649 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
2650 "Mapping Memory without VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06002651
Mark Lobodzinski3780e142015-05-14 15:08:13 -05002652 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinski3780e142015-05-14 15:08:13 -05002653
2654 // Create an image, allocate memory, free it, and then try to bind it
Karl Schultz6addd812016-02-02 17:17:23 -07002655 VkImage image;
2656 VkDeviceMemory mem;
2657 VkMemoryRequirements mem_reqs;
Mark Lobodzinski3780e142015-05-14 15:08:13 -05002658
Karl Schultz6addd812016-02-02 17:17:23 -07002659 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
2660 const int32_t tex_width = 32;
2661 const int32_t tex_height = 32;
Mark Lobodzinski3780e142015-05-14 15:08:13 -05002662
Tony Barboureb254902015-07-15 12:50:33 -06002663 VkImageCreateInfo image_create_info = {};
2664 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
Karl Schultz6addd812016-02-02 17:17:23 -07002665 image_create_info.pNext = NULL;
2666 image_create_info.imageType = VK_IMAGE_TYPE_2D;
2667 image_create_info.format = tex_format;
2668 image_create_info.extent.width = tex_width;
2669 image_create_info.extent.height = tex_height;
2670 image_create_info.extent.depth = 1;
2671 image_create_info.mipLevels = 1;
2672 image_create_info.arrayLayers = 1;
2673 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
2674 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
2675 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
2676 image_create_info.flags = 0;
Chris Forbese65e4d02016-09-13 17:39:18 +12002677 image_create_info.initialLayout = VK_IMAGE_LAYOUT_PREINITIALIZED;
Mark Lobodzinski5fcc4212015-09-14 17:43:42 -06002678
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002679 VkMemoryAllocateInfo mem_alloc = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08002680 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
Karl Schultz6addd812016-02-02 17:17:23 -07002681 mem_alloc.pNext = NULL;
2682 mem_alloc.allocationSize = 0;
Mark Lobodzinski3780e142015-05-14 15:08:13 -05002683
Chia-I Wuf7458c52015-10-26 21:10:41 +08002684 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
Mark Lobodzinski3780e142015-05-14 15:08:13 -05002685 ASSERT_VK_SUCCESS(err);
2686
Karl Schultz6addd812016-02-02 17:17:23 -07002687 vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs);
Mark Lobodzinski3780e142015-05-14 15:08:13 -05002688
Mark Lobodzinski23065352015-05-29 09:32:35 -05002689 mem_alloc.allocationSize = mem_reqs.size;
Mark Lobodzinski3780e142015-05-14 15:08:13 -05002690
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002691 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0, VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT);
Karl Schultz6addd812016-02-02 17:17:23 -07002692 if (!pass) { // If we can't find any unmappable memory this test doesn't
2693 // make sense
Chia-I Wuf7458c52015-10-26 21:10:41 +08002694 vkDestroyImage(m_device->device(), image, NULL);
Tony Barbour02fdc7d2015-08-04 16:13:01 -06002695 return;
Mike Stroyand1c84a52015-08-18 14:40:24 -06002696 }
Mike Stroyan713b2d72015-08-04 10:49:29 -06002697
Mark Lobodzinski3780e142015-05-14 15:08:13 -05002698 // allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002699 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem);
Mark Lobodzinski3780e142015-05-14 15:08:13 -05002700 ASSERT_VK_SUCCESS(err);
2701
2702 // Try to bind free memory that has been freed
Tony Barbour67e99152015-07-10 14:10:27 -06002703 err = vkBindImageMemory(m_device->device(), image, mem, 0);
Mark Lobodzinski3780e142015-05-14 15:08:13 -05002704 ASSERT_VK_SUCCESS(err);
2705
2706 // Map memory as if to initialize the image
2707 void *mappedAddress = NULL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002708 err = vkMapMemory(m_device->device(), mem, 0, VK_WHOLE_SIZE, 0, &mappedAddress);
Mark Lobodzinski3780e142015-05-14 15:08:13 -05002709
Chris Forbes8f36a8a2016-04-07 13:21:07 +12002710 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06002711
Chia-I Wuf7458c52015-10-26 21:10:41 +08002712 vkDestroyImage(m_device->device(), image, NULL);
Tony Barbourdf4c0042016-06-01 15:55:43 -06002713 vkFreeMemory(m_device->device(), mem, NULL);
Mark Lobodzinski3780e142015-05-14 15:08:13 -05002714}
2715
Karl Schultz6addd812016-02-02 17:17:23 -07002716TEST_F(VkLayerTest, RebindMemory) {
2717 VkResult err;
2718 bool pass;
Mark Lobodzinski944aab12015-06-05 13:59:04 -05002719
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002720 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "which has already been bound to mem object");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06002721
Mark Lobodzinski944aab12015-06-05 13:59:04 -05002722 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinski944aab12015-06-05 13:59:04 -05002723
2724 // Create an image, allocate memory, free it, and then try to bind it
Karl Schultz6addd812016-02-02 17:17:23 -07002725 VkImage image;
2726 VkDeviceMemory mem1;
2727 VkDeviceMemory mem2;
2728 VkMemoryRequirements mem_reqs;
Mark Lobodzinski944aab12015-06-05 13:59:04 -05002729
Karl Schultz6addd812016-02-02 17:17:23 -07002730 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
2731 const int32_t tex_width = 32;
2732 const int32_t tex_height = 32;
Mark Lobodzinski944aab12015-06-05 13:59:04 -05002733
Tony Barboureb254902015-07-15 12:50:33 -06002734 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -07002735 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
2736 image_create_info.pNext = NULL;
2737 image_create_info.imageType = VK_IMAGE_TYPE_2D;
2738 image_create_info.format = tex_format;
2739 image_create_info.extent.width = tex_width;
2740 image_create_info.extent.height = tex_height;
2741 image_create_info.extent.depth = 1;
2742 image_create_info.mipLevels = 1;
2743 image_create_info.arrayLayers = 1;
2744 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
2745 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
2746 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
2747 image_create_info.flags = 0;
Mark Lobodzinski944aab12015-06-05 13:59:04 -05002748
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002749 VkMemoryAllocateInfo mem_alloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -07002750 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
2751 mem_alloc.pNext = NULL;
2752 mem_alloc.allocationSize = 0;
2753 mem_alloc.memoryTypeIndex = 0;
Tony Barboureb254902015-07-15 12:50:33 -06002754
Karl Schultz6addd812016-02-02 17:17:23 -07002755 // Introduce failure, do NOT set memProps to
2756 // VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT
Tony Barboureb254902015-07-15 12:50:33 -06002757 mem_alloc.memoryTypeIndex = 1;
Chia-I Wuf7458c52015-10-26 21:10:41 +08002758 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
Mark Lobodzinski944aab12015-06-05 13:59:04 -05002759 ASSERT_VK_SUCCESS(err);
2760
Karl Schultz6addd812016-02-02 17:17:23 -07002761 vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs);
Mark Lobodzinski944aab12015-06-05 13:59:04 -05002762
2763 mem_alloc.allocationSize = mem_reqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002764 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -06002765 ASSERT_TRUE(pass);
Mark Lobodzinski944aab12015-06-05 13:59:04 -05002766
2767 // allocate 2 memory objects
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002768 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem1);
Mark Lobodzinski944aab12015-06-05 13:59:04 -05002769 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002770 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem2);
Mark Lobodzinski944aab12015-06-05 13:59:04 -05002771 ASSERT_VK_SUCCESS(err);
2772
2773 // Bind first memory object to Image object
Tony Barbour67e99152015-07-10 14:10:27 -06002774 err = vkBindImageMemory(m_device->device(), image, mem1, 0);
Mark Lobodzinski944aab12015-06-05 13:59:04 -05002775 ASSERT_VK_SUCCESS(err);
2776
Karl Schultz6addd812016-02-02 17:17:23 -07002777 // Introduce validation failure, try to bind a different memory object to
2778 // the same image object
Tony Barbour67e99152015-07-10 14:10:27 -06002779 err = vkBindImageMemory(m_device->device(), image, mem2, 0);
Mark Lobodzinski944aab12015-06-05 13:59:04 -05002780
Chris Forbes8f36a8a2016-04-07 13:21:07 +12002781 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06002782
Chia-I Wuf7458c52015-10-26 21:10:41 +08002783 vkDestroyImage(m_device->device(), image, NULL);
2784 vkFreeMemory(m_device->device(), mem1, NULL);
2785 vkFreeMemory(m_device->device(), mem2, NULL);
Mark Lobodzinski944aab12015-06-05 13:59:04 -05002786}
Mark Lobodzinski3780e142015-05-14 15:08:13 -05002787
Karl Schultz6addd812016-02-02 17:17:23 -07002788TEST_F(VkLayerTest, SubmitSignaledFence) {
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06002789 vk_testing::Fence testFence;
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06002790
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002791 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "submitted in SIGNALED state. Fences "
2792 "must be reset before being submitted");
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06002793
2794 VkFenceCreateInfo fenceInfo = {};
Tony Barbour0b4d9562015-04-09 10:48:04 -06002795 fenceInfo.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
2796 fenceInfo.pNext = NULL;
2797 fenceInfo.flags = VK_FENCE_CREATE_SIGNALED_BIT;
Tony Barbour300a6082015-04-07 13:44:53 -06002798
Tony Barbour300a6082015-04-07 13:44:53 -06002799 ASSERT_NO_FATAL_FAILURE(InitState());
2800 ASSERT_NO_FATAL_FAILURE(InitViewport());
2801 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
2802
Tony Barbourfe3351b2015-07-28 10:17:20 -06002803 BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002804 m_commandBuffer->ClearAllBuffers(m_clear_color, m_depth_clear_color, m_stencil_clear_color, NULL);
Tony Barbourfe3351b2015-07-28 10:17:20 -06002805 EndCommandBuffer();
Tony Barbour300a6082015-04-07 13:44:53 -06002806
2807 testFence.init(*m_device, fenceInfo);
Mark Lobodzinski5fcc4212015-09-14 17:43:42 -06002808
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06002809 VkSubmitInfo submit_info;
Chia-I Wuf9be13c2015-10-26 20:37:06 +08002810 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
2811 submit_info.pNext = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08002812 submit_info.waitSemaphoreCount = 0;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06002813 submit_info.pWaitSemaphores = NULL;
Jon Ashburn7f9716c2015-12-30 16:42:50 -07002814 submit_info.pWaitDstStageMask = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08002815 submit_info.commandBufferCount = 1;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002816 submit_info.pCommandBuffers = &m_commandBuffer->handle();
Chia-I Wud50a7d72015-10-26 20:48:51 +08002817 submit_info.signalSemaphoreCount = 0;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06002818 submit_info.pSignalSemaphores = NULL;
Courtney Goeltzenleuchter646b9072015-10-20 18:04:07 -06002819
2820 vkQueueSubmit(m_device->m_queue, 1, &submit_info, testFence.handle());
Karl Schultz6addd812016-02-02 17:17:23 -07002821 vkQueueWaitIdle(m_device->m_queue);
Mark Lobodzinski5fcc4212015-09-14 17:43:42 -06002822
Chris Forbes8f36a8a2016-04-07 13:21:07 +12002823 m_errorMonitor->VerifyFound();
Tony Barbour0b4d9562015-04-09 10:48:04 -06002824}
Tobin Ehlisaff7ae92016-04-18 15:45:20 -06002825// This is a positive test. We used to expect error in this case but spec now
2826// allows it
Karl Schultz6addd812016-02-02 17:17:23 -07002827TEST_F(VkLayerTest, ResetUnsignaledFence) {
Tobin Ehlisaff7ae92016-04-18 15:45:20 -06002828 m_errorMonitor->ExpectSuccess();
Tony Barbour0b4d9562015-04-09 10:48:04 -06002829 vk_testing::Fence testFence;
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06002830 VkFenceCreateInfo fenceInfo = {};
Tony Barbour0b4d9562015-04-09 10:48:04 -06002831 fenceInfo.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
2832 fenceInfo.pNext = NULL;
2833
Tony Barbour0b4d9562015-04-09 10:48:04 -06002834 ASSERT_NO_FATAL_FAILURE(InitState());
2835 testFence.init(*m_device, fenceInfo);
Chia-I Wud9e8e822015-07-03 11:45:55 +08002836 VkFence fences[1] = {testFence.handle()};
Tobin Ehlisaff7ae92016-04-18 15:45:20 -06002837 VkResult result = vkResetFences(m_device->device(), 1, fences);
2838 ASSERT_VK_SUCCESS(result);
Tony Barbour300a6082015-04-07 13:44:53 -06002839
Tobin Ehlisaff7ae92016-04-18 15:45:20 -06002840 m_errorMonitor->VerifyNotFound();
Tony Barbour300a6082015-04-07 13:44:53 -06002841}
Tobin Ehlis56ab9022016-08-17 17:59:31 -06002842#if 0 // A few devices have issues with this test so disabling for now
Chris Forbese70b7d32016-06-15 15:49:12 +12002843TEST_F(VkLayerTest, LongFenceChain)
2844{
2845 m_errorMonitor->ExpectSuccess();
2846
2847 ASSERT_NO_FATAL_FAILURE(InitState());
2848 VkResult err;
2849
2850 std::vector<VkFence> fences;
2851
2852 const int chainLength = 32768;
2853
2854 for (int i = 0; i < chainLength; i++) {
2855 VkFenceCreateInfo fci = { VK_STRUCTURE_TYPE_FENCE_CREATE_INFO, nullptr, 0 };
2856 VkFence fence;
2857 err = vkCreateFence(m_device->device(), &fci, nullptr, &fence);
2858 ASSERT_VK_SUCCESS(err);
2859
2860 fences.push_back(fence);
2861
2862 VkSubmitInfo si = { VK_STRUCTURE_TYPE_SUBMIT_INFO, nullptr, 0, nullptr, nullptr,
2863 0, nullptr, 0, nullptr };
2864 err = vkQueueSubmit(m_device->m_queue, 1, &si, fence);
2865 ASSERT_VK_SUCCESS(err);
2866
2867 }
2868
2869 // BOOM, stack overflow.
2870 vkWaitForFences(m_device->device(), 1, &fences.back(), VK_TRUE, UINT64_MAX);
2871
2872 for (auto fence : fences)
2873 vkDestroyFence(m_device->device(), fence, nullptr);
2874
2875 m_errorMonitor->VerifyNotFound();
2876}
Tobin Ehlis56ab9022016-08-17 17:59:31 -06002877#endif
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002878TEST_F(VkLayerTest, CommandBufferSimultaneousUseSync) {
Chris Forbes18127d12016-06-08 16:52:28 +12002879 m_errorMonitor->ExpectSuccess();
2880
2881 ASSERT_NO_FATAL_FAILURE(InitState());
2882 VkResult err;
2883
2884 // Record (empty!) command buffer that can be submitted multiple times
2885 // simultaneously.
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002886 VkCommandBufferBeginInfo cbbi = {VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO, nullptr,
2887 VK_COMMAND_BUFFER_USAGE_SIMULTANEOUS_USE_BIT, nullptr};
Chris Forbes18127d12016-06-08 16:52:28 +12002888 m_commandBuffer->BeginCommandBuffer(&cbbi);
2889 m_commandBuffer->EndCommandBuffer();
2890
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002891 VkFenceCreateInfo fci = {VK_STRUCTURE_TYPE_FENCE_CREATE_INFO, nullptr, 0};
Chris Forbes18127d12016-06-08 16:52:28 +12002892 VkFence fence;
2893 err = vkCreateFence(m_device->device(), &fci, nullptr, &fence);
2894 ASSERT_VK_SUCCESS(err);
2895
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002896 VkSemaphoreCreateInfo sci = {VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO, nullptr, 0};
Chris Forbes18127d12016-06-08 16:52:28 +12002897 VkSemaphore s1, s2;
2898 err = vkCreateSemaphore(m_device->device(), &sci, nullptr, &s1);
2899 ASSERT_VK_SUCCESS(err);
2900 err = vkCreateSemaphore(m_device->device(), &sci, nullptr, &s2);
2901 ASSERT_VK_SUCCESS(err);
2902
2903 // Submit CB once signaling s1, with fence so we can roll forward to its retirement.
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002904 VkSubmitInfo si = {VK_STRUCTURE_TYPE_SUBMIT_INFO, nullptr, 0, nullptr, nullptr, 1, &m_commandBuffer->handle(), 1, &s1};
Chris Forbes18127d12016-06-08 16:52:28 +12002905 err = vkQueueSubmit(m_device->m_queue, 1, &si, fence);
2906 ASSERT_VK_SUCCESS(err);
2907
2908 // Submit CB again, signaling s2.
2909 si.pSignalSemaphores = &s2;
2910 err = vkQueueSubmit(m_device->m_queue, 1, &si, VK_NULL_HANDLE);
2911 ASSERT_VK_SUCCESS(err);
2912
2913 // Wait for fence.
2914 err = vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
2915 ASSERT_VK_SUCCESS(err);
2916
2917 // CB is still in flight from second submission, but semaphore s1 is no
2918 // longer in flight. delete it.
2919 vkDestroySemaphore(m_device->device(), s1, nullptr);
2920
2921 m_errorMonitor->VerifyNotFound();
2922
2923 // Force device idle and clean up remaining objects
2924 vkDeviceWaitIdle(m_device->device());
2925 vkDestroySemaphore(m_device->device(), s2, nullptr);
2926 vkDestroyFence(m_device->device(), fence, nullptr);
2927}
2928
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002929TEST_F(VkLayerTest, FenceCreateSignaledWaitHandling) {
Chris Forbes4e44c912016-06-16 10:20:00 +12002930 m_errorMonitor->ExpectSuccess();
2931
2932 ASSERT_NO_FATAL_FAILURE(InitState());
2933 VkResult err;
2934
2935 // A fence created signaled
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002936 VkFenceCreateInfo fci1 = {VK_STRUCTURE_TYPE_FENCE_CREATE_INFO, nullptr, VK_FENCE_CREATE_SIGNALED_BIT};
Chris Forbes4e44c912016-06-16 10:20:00 +12002937 VkFence f1;
2938 err = vkCreateFence(m_device->device(), &fci1, nullptr, &f1);
2939 ASSERT_VK_SUCCESS(err);
2940
2941 // A fence created not
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002942 VkFenceCreateInfo fci2 = {VK_STRUCTURE_TYPE_FENCE_CREATE_INFO, nullptr, 0};
Chris Forbes4e44c912016-06-16 10:20:00 +12002943 VkFence f2;
2944 err = vkCreateFence(m_device->device(), &fci2, nullptr, &f2);
2945 ASSERT_VK_SUCCESS(err);
2946
2947 // Submit the unsignaled fence
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002948 VkSubmitInfo si = {VK_STRUCTURE_TYPE_SUBMIT_INFO, nullptr, 0, nullptr, nullptr, 0, nullptr, 0, nullptr};
Chris Forbes4e44c912016-06-16 10:20:00 +12002949 err = vkQueueSubmit(m_device->m_queue, 1, &si, f2);
2950
2951 // Wait on both fences, with signaled first.
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002952 VkFence fences[] = {f1, f2};
Chris Forbes4e44c912016-06-16 10:20:00 +12002953 vkWaitForFences(m_device->device(), 2, fences, VK_TRUE, UINT64_MAX);
2954
2955 // Should have both retired!
2956 vkDestroyFence(m_device->device(), f1, nullptr);
2957 vkDestroyFence(m_device->device(), f2, nullptr);
2958
2959 m_errorMonitor->VerifyNotFound();
2960}
2961
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002962TEST_F(VkLayerTest, InvalidUsageBits) {
2963 TEST_DESCRIPTION("Specify wrong usage for image then create conflicting view of image "
2964 "Initialize buffer with wrong usage then perform copy expecting errors "
2965 "from both the image and the buffer (2 calls)");
2966 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Invalid usage flag for image ");
Tobin Ehlis41376e12015-07-03 08:45:14 -06002967
2968 ASSERT_NO_FATAL_FAILURE(InitState());
Tony Barbourf92621a2016-05-02 14:28:12 -06002969 VkImageObj image(m_device);
Tony Barbour75d79f02016-08-30 09:39:07 -06002970 // Initialize image with USAGE_TRANSIENT_ATTACHMENT
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002971 image.init(128, 128, VK_FORMAT_D24_UNORM_S8_UINT, VK_IMAGE_USAGE_TRANSIENT_ATTACHMENT_BIT, VK_IMAGE_TILING_OPTIMAL, 0);
Karl Schultzb5bc11e2016-05-04 08:36:08 -06002972 ASSERT_TRUE(image.initialized());
Tobin Ehlis41376e12015-07-03 08:45:14 -06002973
Tony Barbourf92621a2016-05-02 14:28:12 -06002974 VkImageView dsv;
2975 VkImageViewCreateInfo dsvci = {};
2976 dsvci.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
2977 dsvci.image = image.handle();
2978 dsvci.viewType = VK_IMAGE_VIEW_TYPE_2D;
2979 dsvci.format = VK_FORMAT_D32_SFLOAT_S8_UINT;
2980 dsvci.subresourceRange.layerCount = 1;
2981 dsvci.subresourceRange.baseMipLevel = 0;
2982 dsvci.subresourceRange.levelCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002983 dsvci.subresourceRange.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT;
Tobin Ehlis41376e12015-07-03 08:45:14 -06002984
Tony Barbourf92621a2016-05-02 14:28:12 -06002985 // Create a view with depth / stencil aspect for image with different usage
2986 vkCreateImageView(m_device->device(), &dsvci, NULL, &dsv);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06002987
Chris Forbes8f36a8a2016-04-07 13:21:07 +12002988 m_errorMonitor->VerifyFound();
Tony Barbourf92621a2016-05-02 14:28:12 -06002989
2990 // Initialize buffer with TRANSFER_DST usage
2991 vk_testing::Buffer buffer;
2992 VkMemoryPropertyFlags reqs = 0;
2993 buffer.init_as_dst(*m_device, 128 * 128, reqs);
2994 VkBufferImageCopy region = {};
2995 region.bufferRowLength = 128;
2996 region.bufferImageHeight = 128;
2997 region.imageSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
2998 region.imageSubresource.layerCount = 1;
2999 region.imageExtent.height = 16;
3000 region.imageExtent.width = 16;
3001 region.imageExtent.depth = 1;
3002
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003003 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Invalid usage flag for buffer ");
Tony Barbourf92621a2016-05-02 14:28:12 -06003004 // Buffer usage not set to TRANSFER_SRC and image usage not set to
3005 // TRANSFER_DST
3006 BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003007 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer.handle(), image.handle(),
3008 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, &region);
Tony Barbourf92621a2016-05-02 14:28:12 -06003009 m_errorMonitor->VerifyFound();
3010
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003011 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Invalid usage flag for image ");
3012 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer.handle(), image.handle(),
3013 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, &region);
Tony Barbourf92621a2016-05-02 14:28:12 -06003014 m_errorMonitor->VerifyFound();
Tobin Ehlis41376e12015-07-03 08:45:14 -06003015}
Tony Barbour75d79f02016-08-30 09:39:07 -06003016
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003017TEST_F(VkLayerTest, ValidUsage) {
3018 TEST_DESCRIPTION("Verify that creating an image view from an image with valid usage "
3019 "doesn't generate validation errors");
Tony Barbour75d79f02016-08-30 09:39:07 -06003020
3021 ASSERT_NO_FATAL_FAILURE(InitState());
3022
3023 m_errorMonitor->ExpectSuccess();
3024 // Verify that we can create a view with usage INPUT_ATTACHMENT
3025 VkImageObj image(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003026 image.init(128, 128, VK_FORMAT_R8G8B8A8_UNORM, VK_IMAGE_USAGE_INPUT_ATTACHMENT_BIT, VK_IMAGE_TILING_OPTIMAL, 0);
Tony Barbour75d79f02016-08-30 09:39:07 -06003027 ASSERT_TRUE(image.initialized());
3028 VkImageView imageView;
3029 VkImageViewCreateInfo ivci = {};
3030 ivci.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
3031 ivci.image = image.handle();
3032 ivci.viewType = VK_IMAGE_VIEW_TYPE_2D;
3033 ivci.format = VK_FORMAT_R8G8B8A8_UNORM;
3034 ivci.subresourceRange.layerCount = 1;
3035 ivci.subresourceRange.baseMipLevel = 0;
3036 ivci.subresourceRange.levelCount = 1;
3037 ivci.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
3038
3039 vkCreateImageView(m_device->device(), &ivci, NULL, &imageView);
3040 m_errorMonitor->VerifyNotFound();
3041 vkDestroyImageView(m_device->device(), imageView, NULL);
3042}
Mark Lobodzinski209b5292015-09-17 09:44:05 -06003043#endif // MEM_TRACKER_TESTS
3044
Tobin Ehlis4bf96d12015-06-25 11:58:41 -06003045#if OBJ_TRACKER_TESTS
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06003046
3047TEST_F(VkLayerTest, LeakAnObject) {
3048 VkResult err;
3049
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003050 TEST_DESCRIPTION("Create a fence and destroy its device without first destroying the fence.");
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06003051
3052 // Note that we have to create a new device since destroying the
3053 // framework's device causes Teardown() to fail and just calling Teardown
3054 // will destroy the errorMonitor.
3055
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003056 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "has not been destroyed.");
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06003057
3058 ASSERT_NO_FATAL_FAILURE(InitState());
3059
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003060 const std::vector<VkQueueFamilyProperties> queue_props = m_device->queue_props;
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06003061 std::vector<VkDeviceQueueCreateInfo> queue_info;
3062 queue_info.reserve(queue_props.size());
3063 std::vector<std::vector<float>> queue_priorities;
3064 for (uint32_t i = 0; i < (uint32_t)queue_props.size(); i++) {
3065 VkDeviceQueueCreateInfo qi = {};
3066 qi.sType = VK_STRUCTURE_TYPE_DEVICE_QUEUE_CREATE_INFO;
3067 qi.pNext = NULL;
3068 qi.queueFamilyIndex = i;
3069 qi.queueCount = queue_props[i].queueCount;
3070 queue_priorities.emplace_back(qi.queueCount, 0.0f);
3071 qi.pQueuePriorities = queue_priorities[i].data();
3072 queue_info.push_back(qi);
3073 }
3074
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06003075 std::vector<const char *> device_extension_names;
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06003076
3077 // The sacrificial device object
3078 VkDevice testDevice;
3079 VkDeviceCreateInfo device_create_info = {};
3080 auto features = m_device->phy().features();
3081 device_create_info.sType = VK_STRUCTURE_TYPE_DEVICE_CREATE_INFO;
3082 device_create_info.pNext = NULL;
3083 device_create_info.queueCreateInfoCount = queue_info.size();
3084 device_create_info.pQueueCreateInfos = queue_info.data();
Tony Barbour4c70d102016-08-08 16:06:56 -06003085 device_create_info.enabledLayerCount = 0;
3086 device_create_info.ppEnabledLayerNames = NULL;
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06003087 device_create_info.pEnabledFeatures = &features;
3088 err = vkCreateDevice(gpu(), &device_create_info, NULL, &testDevice);
3089 ASSERT_VK_SUCCESS(err);
3090
3091 VkFence fence;
3092 VkFenceCreateInfo fence_create_info = {};
3093 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
3094 fence_create_info.pNext = NULL;
3095 fence_create_info.flags = 0;
3096 err = vkCreateFence(testDevice, &fence_create_info, NULL, &fence);
3097 ASSERT_VK_SUCCESS(err);
3098
3099 // Induce failure by not calling vkDestroyFence
3100 vkDestroyDevice(testDevice, NULL);
3101 m_errorMonitor->VerifyFound();
3102}
3103
3104TEST_F(VkLayerTest, InvalidCommandPoolConsistency) {
3105
3106 TEST_DESCRIPTION("Allocate command buffers from one command pool and "
3107 "attempt to delete them from another.");
3108
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003109 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "FreeCommandBuffers is attempting to free Command Buffer");
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06003110
Cody Northropc31a84f2016-08-22 10:41:47 -06003111 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06003112 VkCommandPool command_pool_one;
3113 VkCommandPool command_pool_two;
3114
3115 VkCommandPoolCreateInfo pool_create_info{};
3116 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
3117 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
3118 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
3119
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003120 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool_one);
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06003121
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003122 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool_two);
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06003123
3124 VkCommandBuffer command_buffer[9];
3125 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003126 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06003127 command_buffer_allocate_info.commandPool = command_pool_one;
3128 command_buffer_allocate_info.commandBufferCount = 9;
3129 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003130 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, command_buffer);
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06003131
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003132 vkFreeCommandBuffers(m_device->device(), command_pool_two, 4, &command_buffer[3]);
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06003133
3134 m_errorMonitor->VerifyFound();
3135
3136 vkDestroyCommandPool(m_device->device(), command_pool_one, NULL);
3137 vkDestroyCommandPool(m_device->device(), command_pool_two, NULL);
3138}
3139
3140TEST_F(VkLayerTest, InvalidDescriptorPoolConsistency) {
3141 VkResult err;
3142
3143 TEST_DESCRIPTION("Allocate descriptor sets from one DS pool and "
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003144 "attempt to delete them from another.");
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06003145
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003146 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "FreeDescriptorSets is attempting to free descriptorSet");
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06003147
3148 ASSERT_NO_FATAL_FAILURE(InitState());
3149 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
3150
3151 VkDescriptorPoolSize ds_type_count = {};
3152 ds_type_count.type = VK_DESCRIPTOR_TYPE_SAMPLER;
3153 ds_type_count.descriptorCount = 1;
3154
3155 VkDescriptorPoolCreateInfo ds_pool_ci = {};
3156 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
3157 ds_pool_ci.pNext = NULL;
3158 ds_pool_ci.flags = 0;
3159 ds_pool_ci.maxSets = 1;
3160 ds_pool_ci.poolSizeCount = 1;
3161 ds_pool_ci.pPoolSizes = &ds_type_count;
3162
3163 VkDescriptorPool ds_pool_one;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003164 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool_one);
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06003165 ASSERT_VK_SUCCESS(err);
3166
3167 // Create a second descriptor pool
3168 VkDescriptorPool ds_pool_two;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003169 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool_two);
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06003170 ASSERT_VK_SUCCESS(err);
3171
3172 VkDescriptorSetLayoutBinding dsl_binding = {};
3173 dsl_binding.binding = 0;
3174 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
3175 dsl_binding.descriptorCount = 1;
3176 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
3177 dsl_binding.pImmutableSamplers = NULL;
3178
3179 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
3180 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
3181 ds_layout_ci.pNext = NULL;
3182 ds_layout_ci.bindingCount = 1;
3183 ds_layout_ci.pBindings = &dsl_binding;
3184
3185 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003186 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06003187 ASSERT_VK_SUCCESS(err);
3188
3189 VkDescriptorSet descriptorSet;
3190 VkDescriptorSetAllocateInfo alloc_info = {};
3191 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
3192 alloc_info.descriptorSetCount = 1;
3193 alloc_info.descriptorPool = ds_pool_one;
3194 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003195 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06003196 ASSERT_VK_SUCCESS(err);
3197
3198 err = vkFreeDescriptorSets(m_device->device(), ds_pool_two, 1, &descriptorSet);
3199
3200 m_errorMonitor->VerifyFound();
3201
3202 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
3203 vkDestroyDescriptorPool(m_device->device(), ds_pool_one, NULL);
3204 vkDestroyDescriptorPool(m_device->device(), ds_pool_two, NULL);
3205}
3206
3207TEST_F(VkLayerTest, CreateUnknownObject) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003208 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Invalid Image Object ");
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06003209
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003210 TEST_DESCRIPTION("Pass an invalid image object handle into a Vulkan API call.");
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06003211
3212 ASSERT_NO_FATAL_FAILURE(InitState());
3213
3214 // Pass bogus handle into GetImageMemoryRequirements
3215 VkMemoryRequirements mem_reqs;
3216 uint64_t fakeImageHandle = 0xCADECADE;
3217 VkImage fauxImage = reinterpret_cast<VkImage &>(fakeImageHandle);
3218
3219 vkGetImageMemoryRequirements(m_device->device(), fauxImage, &mem_reqs);
3220
3221 m_errorMonitor->VerifyFound();
3222}
3223
Karl Schultz6addd812016-02-02 17:17:23 -07003224TEST_F(VkLayerTest, PipelineNotBound) {
3225 VkResult err;
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06003226
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003227 TEST_DESCRIPTION("Pass in an invalid pipeline object handle into a Vulkan API call.");
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06003228
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003229 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Invalid Pipeline Object ");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06003230
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06003231 ASSERT_NO_FATAL_FAILURE(InitState());
3232 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06003233
Chia-I Wu1b99bb22015-10-27 19:25:11 +08003234 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07003235 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
3236 ds_type_count.descriptorCount = 1;
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06003237
3238 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07003239 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
3240 ds_pool_ci.pNext = NULL;
3241 ds_pool_ci.maxSets = 1;
3242 ds_pool_ci.poolSizeCount = 1;
3243 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06003244
3245 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003246 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06003247 ASSERT_VK_SUCCESS(err);
3248
3249 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07003250 dsl_binding.binding = 0;
3251 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
3252 dsl_binding.descriptorCount = 1;
3253 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
3254 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06003255
3256 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07003257 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
3258 ds_layout_ci.pNext = NULL;
3259 ds_layout_ci.bindingCount = 1;
3260 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06003261
3262 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003263 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06003264 ASSERT_VK_SUCCESS(err);
3265
3266 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08003267 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08003268 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07003269 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06003270 alloc_info.descriptorPool = ds_pool;
3271 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003272 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06003273 ASSERT_VK_SUCCESS(err);
3274
3275 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07003276 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
3277 pipeline_layout_ci.pNext = NULL;
3278 pipeline_layout_ci.setLayoutCount = 1;
3279 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06003280
3281 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003282 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06003283 ASSERT_VK_SUCCESS(err);
3284
Mark Youngad779052016-01-06 14:26:04 -07003285 VkPipeline badPipeline = (VkPipeline)((size_t)0xbaadb1be);
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06003286
3287 BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003288 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, badPipeline);
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06003289
Chris Forbes8f36a8a2016-04-07 13:21:07 +12003290 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06003291
Chia-I Wuf7458c52015-10-26 21:10:41 +08003292 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
3293 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
3294 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlisec598302015-09-15 15:02:17 -06003295}
Mike Stroyan80fc6c32016-06-20 15:42:29 -06003296
Mark Lobodzinskibc185762016-06-15 16:28:53 -06003297TEST_F(VkLayerTest, BindImageInvalidMemoryType) {
3298 VkResult err;
3299
3300 TEST_DESCRIPTION("Test validation check for an invalid memory type index "
3301 "during bind[Buffer|Image]Memory time");
3302
Mark Lobodzinskibc185762016-06-15 16:28:53 -06003303 ASSERT_NO_FATAL_FAILURE(InitState());
3304
3305 // Create an image, allocate memory, set a bad typeIndex and then try to
3306 // bind it
3307 VkImage image;
3308 VkDeviceMemory mem;
3309 VkMemoryRequirements mem_reqs;
3310 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
3311 const int32_t tex_width = 32;
3312 const int32_t tex_height = 32;
3313
3314 VkImageCreateInfo image_create_info = {};
3315 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
3316 image_create_info.pNext = NULL;
3317 image_create_info.imageType = VK_IMAGE_TYPE_2D;
3318 image_create_info.format = tex_format;
3319 image_create_info.extent.width = tex_width;
3320 image_create_info.extent.height = tex_height;
3321 image_create_info.extent.depth = 1;
3322 image_create_info.mipLevels = 1;
3323 image_create_info.arrayLayers = 1;
3324 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
3325 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
3326 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
3327 image_create_info.flags = 0;
3328
3329 VkMemoryAllocateInfo mem_alloc = {};
3330 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
3331 mem_alloc.pNext = NULL;
3332 mem_alloc.allocationSize = 0;
3333 mem_alloc.memoryTypeIndex = 0;
3334
3335 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
3336 ASSERT_VK_SUCCESS(err);
3337
3338 vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs);
3339 mem_alloc.allocationSize = mem_reqs.size;
Mike Stroyan80fc6c32016-06-20 15:42:29 -06003340
3341 // Introduce Failure, select invalid TypeIndex
3342 VkPhysicalDeviceMemoryProperties memory_info;
3343
3344 vkGetPhysicalDeviceMemoryProperties(gpu(), &memory_info);
3345 unsigned int i;
3346 for (i = 0; i < memory_info.memoryTypeCount; i++) {
3347 if ((mem_reqs.memoryTypeBits & (1 << i)) == 0) {
3348 mem_alloc.memoryTypeIndex = i;
3349 break;
3350 }
3351 }
3352 if (i >= memory_info.memoryTypeCount) {
3353 printf("No invalid memory type index could be found; skipped.\n");
3354 vkDestroyImage(m_device->device(), image, NULL);
3355 return;
3356 }
3357
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003358 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "for this object type are not compatible with the memory");
Mark Lobodzinskibc185762016-06-15 16:28:53 -06003359
3360 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem);
3361 ASSERT_VK_SUCCESS(err);
3362
3363 err = vkBindImageMemory(m_device->device(), image, mem, 0);
3364 (void)err;
3365
3366 m_errorMonitor->VerifyFound();
3367
3368 vkDestroyImage(m_device->device(), image, NULL);
3369 vkFreeMemory(m_device->device(), mem, NULL);
3370}
Mike Stroyan80fc6c32016-06-20 15:42:29 -06003371
Karl Schultz6addd812016-02-02 17:17:23 -07003372TEST_F(VkLayerTest, BindInvalidMemory) {
3373 VkResult err;
3374 bool pass;
Tobin Ehlisec598302015-09-15 15:02:17 -06003375
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003376 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Invalid Device Memory Object ");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06003377
Tobin Ehlisec598302015-09-15 15:02:17 -06003378 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisec598302015-09-15 15:02:17 -06003379
3380 // Create an image, allocate memory, free it, and then try to bind it
Karl Schultz6addd812016-02-02 17:17:23 -07003381 VkImage image;
3382 VkDeviceMemory mem;
3383 VkMemoryRequirements mem_reqs;
Tobin Ehlisec598302015-09-15 15:02:17 -06003384
Karl Schultz6addd812016-02-02 17:17:23 -07003385 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
3386 const int32_t tex_width = 32;
3387 const int32_t tex_height = 32;
Tobin Ehlisec598302015-09-15 15:02:17 -06003388
3389 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -07003390 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
3391 image_create_info.pNext = NULL;
3392 image_create_info.imageType = VK_IMAGE_TYPE_2D;
3393 image_create_info.format = tex_format;
3394 image_create_info.extent.width = tex_width;
3395 image_create_info.extent.height = tex_height;
3396 image_create_info.extent.depth = 1;
3397 image_create_info.mipLevels = 1;
3398 image_create_info.arrayLayers = 1;
3399 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
3400 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
3401 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
3402 image_create_info.flags = 0;
Tobin Ehlisec598302015-09-15 15:02:17 -06003403
Chia-I Wu3432a0c2015-10-27 18:04:07 +08003404 VkMemoryAllocateInfo mem_alloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -07003405 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
3406 mem_alloc.pNext = NULL;
3407 mem_alloc.allocationSize = 0;
3408 mem_alloc.memoryTypeIndex = 0;
Tobin Ehlisec598302015-09-15 15:02:17 -06003409
Chia-I Wuf7458c52015-10-26 21:10:41 +08003410 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
Tobin Ehlisec598302015-09-15 15:02:17 -06003411 ASSERT_VK_SUCCESS(err);
3412
Karl Schultz6addd812016-02-02 17:17:23 -07003413 vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs);
Tobin Ehlisec598302015-09-15 15:02:17 -06003414
3415 mem_alloc.allocationSize = mem_reqs.size;
3416
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003417 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -06003418 ASSERT_TRUE(pass);
Tobin Ehlisec598302015-09-15 15:02:17 -06003419
3420 // allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +08003421 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem);
Tobin Ehlisec598302015-09-15 15:02:17 -06003422 ASSERT_VK_SUCCESS(err);
3423
3424 // Introduce validation failure, free memory before binding
Chia-I Wuf7458c52015-10-26 21:10:41 +08003425 vkFreeMemory(m_device->device(), mem, NULL);
Tobin Ehlisec598302015-09-15 15:02:17 -06003426
3427 // Try to bind free memory that has been freed
3428 err = vkBindImageMemory(m_device->device(), image, mem, 0);
3429 // This may very well return an error.
3430 (void)err;
3431
Chris Forbes8f36a8a2016-04-07 13:21:07 +12003432 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06003433
Chia-I Wuf7458c52015-10-26 21:10:41 +08003434 vkDestroyImage(m_device->device(), image, NULL);
Tobin Ehlisec598302015-09-15 15:02:17 -06003435}
3436
Karl Schultz6addd812016-02-02 17:17:23 -07003437TEST_F(VkLayerTest, BindMemoryToDestroyedObject) {
3438 VkResult err;
3439 bool pass;
Tobin Ehlisec598302015-09-15 15:02:17 -06003440
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003441 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Invalid Image Object ");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06003442
Tobin Ehlisec598302015-09-15 15:02:17 -06003443 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisec598302015-09-15 15:02:17 -06003444
Karl Schultz6addd812016-02-02 17:17:23 -07003445 // Create an image object, allocate memory, destroy the object and then try
3446 // to bind it
3447 VkImage image;
3448 VkDeviceMemory mem;
3449 VkMemoryRequirements mem_reqs;
Tobin Ehlisec598302015-09-15 15:02:17 -06003450
Karl Schultz6addd812016-02-02 17:17:23 -07003451 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
3452 const int32_t tex_width = 32;
3453 const int32_t tex_height = 32;
Tobin Ehlisec598302015-09-15 15:02:17 -06003454
3455 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -07003456 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
3457 image_create_info.pNext = NULL;
3458 image_create_info.imageType = VK_IMAGE_TYPE_2D;
3459 image_create_info.format = tex_format;
3460 image_create_info.extent.width = tex_width;
3461 image_create_info.extent.height = tex_height;
3462 image_create_info.extent.depth = 1;
3463 image_create_info.mipLevels = 1;
3464 image_create_info.arrayLayers = 1;
3465 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
3466 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
3467 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
3468 image_create_info.flags = 0;
Tobin Ehlisec598302015-09-15 15:02:17 -06003469
Chia-I Wu3432a0c2015-10-27 18:04:07 +08003470 VkMemoryAllocateInfo mem_alloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -07003471 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
3472 mem_alloc.pNext = NULL;
3473 mem_alloc.allocationSize = 0;
3474 mem_alloc.memoryTypeIndex = 0;
Tobin Ehlisec598302015-09-15 15:02:17 -06003475
Chia-I Wuf7458c52015-10-26 21:10:41 +08003476 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
Tobin Ehlisec598302015-09-15 15:02:17 -06003477 ASSERT_VK_SUCCESS(err);
3478
Karl Schultz6addd812016-02-02 17:17:23 -07003479 vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs);
Tobin Ehlisec598302015-09-15 15:02:17 -06003480
3481 mem_alloc.allocationSize = mem_reqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003482 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -06003483 ASSERT_TRUE(pass);
Tobin Ehlisec598302015-09-15 15:02:17 -06003484
3485 // Allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +08003486 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem);
Tobin Ehlisec598302015-09-15 15:02:17 -06003487 ASSERT_VK_SUCCESS(err);
3488
3489 // Introduce validation failure, destroy Image object before binding
Chia-I Wuf7458c52015-10-26 21:10:41 +08003490 vkDestroyImage(m_device->device(), image, NULL);
Tobin Ehlisec598302015-09-15 15:02:17 -06003491 ASSERT_VK_SUCCESS(err);
3492
3493 // Now Try to bind memory to this destroyed object
3494 err = vkBindImageMemory(m_device->device(), image, mem, 0);
3495 // This may very well return an error.
Karl Schultz6addd812016-02-02 17:17:23 -07003496 (void)err;
Tobin Ehlisec598302015-09-15 15:02:17 -06003497
Chris Forbes8f36a8a2016-04-07 13:21:07 +12003498 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06003499
Chia-I Wuf7458c52015-10-26 21:10:41 +08003500 vkFreeMemory(m_device->device(), mem, NULL);
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06003501}
Tobin Ehlisa1c28562015-10-23 16:00:08 -06003502
Mark Lobodzinski209b5292015-09-17 09:44:05 -06003503#endif // OBJ_TRACKER_TESTS
3504
Tobin Ehlis0788f522015-05-26 16:11:58 -06003505#if DRAW_STATE_TESTS
Mark Lobodzinskic808d442016-04-14 10:57:23 -06003506
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06003507TEST_F(VkLayerTest, ImageSampleCounts) {
3508
3509 TEST_DESCRIPTION("Use bad sample counts in image transfer calls to trigger "
3510 "validation errors.");
3511 ASSERT_NO_FATAL_FAILURE(InitState());
3512
3513 VkMemoryPropertyFlags reqs = 0;
3514 VkImageCreateInfo image_create_info = {};
3515 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
3516 image_create_info.pNext = NULL;
3517 image_create_info.imageType = VK_IMAGE_TYPE_2D;
3518 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
3519 image_create_info.extent.width = 256;
3520 image_create_info.extent.height = 256;
3521 image_create_info.extent.depth = 1;
3522 image_create_info.mipLevels = 1;
3523 image_create_info.arrayLayers = 1;
3524 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
3525 image_create_info.flags = 0;
3526
3527 VkImageBlit blit_region = {};
3528 blit_region.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
3529 blit_region.srcSubresource.baseArrayLayer = 0;
3530 blit_region.srcSubresource.layerCount = 1;
3531 blit_region.srcSubresource.mipLevel = 0;
3532 blit_region.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
3533 blit_region.dstSubresource.baseArrayLayer = 0;
3534 blit_region.dstSubresource.layerCount = 1;
3535 blit_region.dstSubresource.mipLevel = 0;
3536
3537 // Create two images, the source with sampleCount = 2, and attempt to blit
3538 // between them
3539 {
3540 image_create_info.samples = VK_SAMPLE_COUNT_2_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003541 image_create_info.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06003542 vk_testing::Image src_image;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003543 src_image.init(*m_device, (const VkImageCreateInfo &)image_create_info, reqs);
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06003544 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003545 image_create_info.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT;
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06003546 vk_testing::Image dst_image;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003547 dst_image.init(*m_device, (const VkImageCreateInfo &)image_create_info, reqs);
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06003548 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003549 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "was created with a sample count "
3550 "of VK_SAMPLE_COUNT_2_BIT but "
3551 "must be VK_SAMPLE_COUNT_1_BIT");
3552 vkCmdBlitImage(m_commandBuffer->GetBufferHandle(), src_image.handle(), VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
3553 dst_image.handle(), VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL, 1, &blit_region, VK_FILTER_NEAREST);
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06003554 m_errorMonitor->VerifyFound();
3555 m_commandBuffer->EndCommandBuffer();
3556 }
3557
3558 // Create two images, the dest with sampleCount = 4, and attempt to blit
3559 // between them
3560 {
3561 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003562 image_create_info.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06003563 vk_testing::Image src_image;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003564 src_image.init(*m_device, (const VkImageCreateInfo &)image_create_info, reqs);
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06003565 image_create_info.samples = VK_SAMPLE_COUNT_4_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003566 image_create_info.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT;
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06003567 vk_testing::Image dst_image;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003568 dst_image.init(*m_device, (const VkImageCreateInfo &)image_create_info, reqs);
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06003569 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003570 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "was created with a sample count "
3571 "of VK_SAMPLE_COUNT_4_BIT but "
3572 "must be VK_SAMPLE_COUNT_1_BIT");
3573 vkCmdBlitImage(m_commandBuffer->GetBufferHandle(), src_image.handle(), VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
3574 dst_image.handle(), VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL, 1, &blit_region, VK_FILTER_NEAREST);
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06003575 m_errorMonitor->VerifyFound();
3576 m_commandBuffer->EndCommandBuffer();
3577 }
3578
3579 VkBufferImageCopy copy_region = {};
3580 copy_region.bufferRowLength = 128;
3581 copy_region.bufferImageHeight = 128;
3582 copy_region.imageSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
3583 copy_region.imageSubresource.layerCount = 1;
3584 copy_region.imageExtent.height = 64;
3585 copy_region.imageExtent.width = 64;
3586 copy_region.imageExtent.depth = 1;
3587
3588 // Create src buffer and dst image with sampleCount = 4 and attempt to copy
3589 // buffer to image
3590 {
3591 vk_testing::Buffer src_buffer;
3592 VkMemoryPropertyFlags reqs = 0;
3593 src_buffer.init_as_src(*m_device, 128 * 128 * 4, reqs);
3594 image_create_info.samples = VK_SAMPLE_COUNT_8_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003595 image_create_info.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT;
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06003596 vk_testing::Image dst_image;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003597 dst_image.init(*m_device, (const VkImageCreateInfo &)image_create_info, reqs);
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06003598 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003599 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "was created with a sample count "
3600 "of VK_SAMPLE_COUNT_8_BIT but "
3601 "must be VK_SAMPLE_COUNT_1_BIT");
3602 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), src_buffer.handle(), dst_image.handle(),
3603 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, &copy_region);
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06003604 m_errorMonitor->VerifyFound();
3605 m_commandBuffer->EndCommandBuffer();
3606 }
3607
3608 // Create dst buffer and src image with sampleCount = 2 and attempt to copy
3609 // image to buffer
3610 {
3611 vk_testing::Buffer dst_buffer;
3612 dst_buffer.init_as_dst(*m_device, 128 * 128 * 4, reqs);
3613 image_create_info.samples = VK_SAMPLE_COUNT_2_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003614 image_create_info.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06003615 vk_testing::Image src_image;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003616 src_image.init(*m_device, (const VkImageCreateInfo &)image_create_info, reqs);
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06003617 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003618 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "was created with a sample count "
3619 "of VK_SAMPLE_COUNT_2_BIT but "
3620 "must be VK_SAMPLE_COUNT_1_BIT");
3621 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), src_image.handle(), VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL,
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06003622 dst_buffer.handle(), 1, &copy_region);
3623 m_errorMonitor->VerifyFound();
3624 m_commandBuffer->EndCommandBuffer();
3625 }
3626}
3627
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06003628TEST_F(VkLayerTest, DSImageTransferGranularityTests) {
3629 VkResult err;
3630 bool pass;
3631
3632 TEST_DESCRIPTION("Tests for validaiton of Queue Family property minImageTransferGranularity.");
3633 ASSERT_NO_FATAL_FAILURE(InitState());
3634
3635 // If w/d/h granularity is 1, test is not meaningful
3636 // TODO: When virtual device limits are available, create a set of limits for this test that
3637 // will always have a granularity of > 1 for w, h, and d
3638 auto index = m_device->graphics_queue_node_index_;
3639 auto queue_family_properties = m_device->phy().queue_properties();
3640
3641 if ((queue_family_properties[index].minImageTransferGranularity.depth < 4) ||
3642 (queue_family_properties[index].minImageTransferGranularity.width < 4) ||
3643 (queue_family_properties[index].minImageTransferGranularity.height < 4)) {
3644 return;
3645 }
3646
3647 // Create two images of different types and try to copy between them
3648 VkImage srcImage;
3649 VkImage dstImage;
3650 VkDeviceMemory srcMem;
3651 VkDeviceMemory destMem;
3652 VkMemoryRequirements memReqs;
3653
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06003654 VkImageCreateInfo image_create_info = {};
3655 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
3656 image_create_info.pNext = NULL;
3657 image_create_info.imageType = VK_IMAGE_TYPE_2D;
3658 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
3659 image_create_info.extent.width = 32;
3660 image_create_info.extent.height = 32;
3661 image_create_info.extent.depth = 1;
3662 image_create_info.mipLevels = 1;
3663 image_create_info.arrayLayers = 4;
3664 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
3665 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
3666 image_create_info.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT;
3667 image_create_info.flags = 0;
3668
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003669 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06003670 ASSERT_VK_SUCCESS(err);
3671
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003672 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06003673 ASSERT_VK_SUCCESS(err);
3674
3675 // Allocate memory
3676 VkMemoryAllocateInfo memAlloc = {};
3677 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
3678 memAlloc.pNext = NULL;
3679 memAlloc.allocationSize = 0;
3680 memAlloc.memoryTypeIndex = 0;
3681
3682 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
3683 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003684 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06003685 ASSERT_TRUE(pass);
3686 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
3687 ASSERT_VK_SUCCESS(err);
3688
3689 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
3690 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003691 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06003692 ASSERT_VK_SUCCESS(err);
3693 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
3694 ASSERT_VK_SUCCESS(err);
3695
3696 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
3697 ASSERT_VK_SUCCESS(err);
3698 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
3699 ASSERT_VK_SUCCESS(err);
3700
3701 BeginCommandBuffer();
3702 VkImageCopy copyRegion;
3703 copyRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
3704 copyRegion.srcSubresource.mipLevel = 0;
3705 copyRegion.srcSubresource.baseArrayLayer = 0;
3706 copyRegion.srcSubresource.layerCount = 1;
3707 copyRegion.srcOffset.x = 0;
3708 copyRegion.srcOffset.y = 0;
3709 copyRegion.srcOffset.z = 0;
3710 copyRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
3711 copyRegion.dstSubresource.mipLevel = 0;
3712 copyRegion.dstSubresource.baseArrayLayer = 0;
3713 copyRegion.dstSubresource.layerCount = 1;
3714 copyRegion.dstOffset.x = 0;
3715 copyRegion.dstOffset.y = 0;
3716 copyRegion.dstOffset.z = 0;
3717 copyRegion.extent.width = 1;
3718 copyRegion.extent.height = 1;
3719 copyRegion.extent.depth = 1;
3720
3721 // Introduce failure by setting srcOffset to a bad granularity value
3722 copyRegion.srcOffset.y = 3;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003723 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "queue family image transfer granularity");
3724 m_commandBuffer->CopyImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, VK_IMAGE_LAYOUT_GENERAL, 1, &copyRegion);
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06003725 m_errorMonitor->VerifyFound();
3726
3727 // Introduce failure by setting extent to a bad granularity value
3728 copyRegion.srcOffset.y = 0;
3729 copyRegion.extent.width = 3;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003730 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "queue family image transfer granularity");
3731 m_commandBuffer->CopyImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, VK_IMAGE_LAYOUT_GENERAL, 1, &copyRegion);
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06003732 m_errorMonitor->VerifyFound();
3733
3734 // Now do some buffer/image copies
3735 vk_testing::Buffer buffer;
3736 VkMemoryPropertyFlags reqs = 0;
3737 buffer.init_as_dst(*m_device, 128 * 128, reqs);
3738 VkBufferImageCopy region = {};
3739 region.bufferOffset = 0;
3740 region.bufferRowLength = 3;
3741 region.bufferImageHeight = 128;
3742 region.imageSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
3743 region.imageSubresource.layerCount = 1;
3744 region.imageExtent.height = 16;
3745 region.imageExtent.width = 16;
3746 region.imageExtent.depth = 1;
3747 region.imageOffset.x = 0;
3748 region.imageOffset.y = 0;
3749 region.imageOffset.z = 0;
3750
3751 // Introduce failure by setting bufferRowLength to a bad granularity value
3752 region.bufferRowLength = 3;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003753 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "queue family image transfer granularity");
3754 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer.handle(), srcImage, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1,
3755 &region);
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06003756 m_errorMonitor->VerifyFound();
3757 region.bufferRowLength = 128;
3758
3759 // Introduce failure by setting bufferOffset to a bad granularity value
3760 region.bufferOffset = 3;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003761 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "queue family image transfer granularity");
3762 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), srcImage, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, buffer.handle(), 1,
3763 &region);
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06003764 m_errorMonitor->VerifyFound();
3765 region.bufferOffset = 0;
3766
3767 // Introduce failure by setting bufferImageHeight to a bad granularity value
3768 region.bufferImageHeight = 3;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003769 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "queue family image transfer granularity");
3770 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), srcImage, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, buffer.handle(), 1,
3771 &region);
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06003772 m_errorMonitor->VerifyFound();
3773 region.bufferImageHeight = 128;
3774
3775 // Introduce failure by setting imageExtent to a bad granularity value
3776 region.imageExtent.width = 3;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003777 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "queue family image transfer granularity");
3778 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), srcImage, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, buffer.handle(), 1,
3779 &region);
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06003780 m_errorMonitor->VerifyFound();
3781 region.imageExtent.width = 16;
3782
3783 // Introduce failure by setting imageOffset to a bad granularity value
3784 region.imageOffset.z = 3;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003785 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "queue family image transfer granularity");
3786 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer.handle(), srcImage, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1,
3787 &region);
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06003788 m_errorMonitor->VerifyFound();
3789
3790 EndCommandBuffer();
3791
3792 vkDestroyImage(m_device->device(), srcImage, NULL);
3793 vkDestroyImage(m_device->device(), dstImage, NULL);
3794 vkFreeMemory(m_device->device(), srcMem, NULL);
3795 vkFreeMemory(m_device->device(), destMem, NULL);
3796}
3797
Mark Lobodzinski570efc62016-08-09 16:43:19 -06003798TEST_F(VkLayerTest, MismatchedQueueFamiliesOnSubmit) {
Mark Lobodzinski570efc62016-08-09 16:43:19 -06003799 TEST_DESCRIPTION("Submit command buffer created using one queue family and "
3800 "attempt to submit them on a queue created in a different "
3801 "queue family.");
3802
Cody Northropc31a84f2016-08-22 10:41:47 -06003803 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinski570efc62016-08-09 16:43:19 -06003804 // This test is meaningless unless we have multiple queue families
3805 auto queue_family_properties = m_device->phy().queue_properties();
3806 if (queue_family_properties.size() < 2) {
3807 return;
3808 }
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003809 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " is being submitted on queue ");
Mark Lobodzinski570efc62016-08-09 16:43:19 -06003810 // Get safe index of another queue family
3811 uint32_t other_queue_family = (m_device->graphics_queue_node_index_ == 0) ? 1 : 0;
3812 ASSERT_NO_FATAL_FAILURE(InitState());
3813 // Create a second queue using a different queue family
3814 VkQueue other_queue;
3815 vkGetDeviceQueue(m_device->device(), other_queue_family, 0, &other_queue);
3816
3817 // Record an empty cmd buffer
3818 VkCommandBufferBeginInfo cmdBufBeginDesc = {};
3819 cmdBufBeginDesc.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
3820 vkBeginCommandBuffer(m_commandBuffer->handle(), &cmdBufBeginDesc);
3821 vkEndCommandBuffer(m_commandBuffer->handle());
3822
3823 // And submit on the wrong queue
3824 VkSubmitInfo submit_info = {};
3825 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
3826 submit_info.commandBufferCount = 1;
3827 submit_info.pCommandBuffers = &m_commandBuffer->handle();
Tobin Ehlisfd213ea2016-08-10 17:10:46 -06003828 vkQueueSubmit(other_queue, 1, &submit_info, VK_NULL_HANDLE);
Mark Lobodzinski570efc62016-08-09 16:43:19 -06003829
3830 m_errorMonitor->VerifyFound();
Mark Lobodzinski570efc62016-08-09 16:43:19 -06003831}
3832
Chris Forbes48a53902016-06-30 11:46:27 +12003833TEST_F(VkLayerTest, RenderPassInitialLayoutUndefined) {
3834 TEST_DESCRIPTION("Ensure that CmdBeginRenderPass with an attachment's "
3835 "initialLayout of VK_IMAGE_LAYOUT_UNDEFINED works when "
3836 "the command buffer has prior knowledge of that "
3837 "attachment's layout.");
3838
3839 m_errorMonitor->ExpectSuccess();
3840
3841 ASSERT_NO_FATAL_FAILURE(InitState());
3842
3843 // A renderpass with one color attachment.
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003844 VkAttachmentDescription attachment = {0,
3845 VK_FORMAT_R8G8B8A8_UNORM,
3846 VK_SAMPLE_COUNT_1_BIT,
3847 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
3848 VK_ATTACHMENT_STORE_OP_STORE,
3849 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
3850 VK_ATTACHMENT_STORE_OP_DONT_CARE,
3851 VK_IMAGE_LAYOUT_UNDEFINED,
3852 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL};
Chris Forbes48a53902016-06-30 11:46:27 +12003853
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003854 VkAttachmentReference att_ref = {0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL};
Chris Forbes48a53902016-06-30 11:46:27 +12003855
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003856 VkSubpassDescription subpass = {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 1, &att_ref, nullptr, nullptr, 0, nullptr};
Chris Forbes48a53902016-06-30 11:46:27 +12003857
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003858 VkRenderPassCreateInfo rpci = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 1, &attachment, 1, &subpass, 0, nullptr};
Chris Forbes48a53902016-06-30 11:46:27 +12003859
3860 VkRenderPass rp;
3861 VkResult err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
3862 ASSERT_VK_SUCCESS(err);
3863
3864 // A compatible framebuffer.
3865 VkImageObj image(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003866 image.init(32, 32, VK_FORMAT_R8G8B8A8_UNORM, VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT, VK_IMAGE_TILING_OPTIMAL, 0);
Chris Forbes48a53902016-06-30 11:46:27 +12003867 ASSERT_TRUE(image.initialized());
3868
3869 VkImageViewCreateInfo ivci = {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003870 VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO,
3871 nullptr,
3872 0,
3873 image.handle(),
3874 VK_IMAGE_VIEW_TYPE_2D,
3875 VK_FORMAT_R8G8B8A8_UNORM,
3876 {VK_COMPONENT_SWIZZLE_IDENTITY, VK_COMPONENT_SWIZZLE_IDENTITY, VK_COMPONENT_SWIZZLE_IDENTITY,
3877 VK_COMPONENT_SWIZZLE_IDENTITY},
3878 {VK_IMAGE_ASPECT_COLOR_BIT, 0, 1, 0, 1},
Chris Forbes48a53902016-06-30 11:46:27 +12003879 };
3880 VkImageView view;
3881 err = vkCreateImageView(m_device->device(), &ivci, nullptr, &view);
3882 ASSERT_VK_SUCCESS(err);
3883
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003884 VkFramebufferCreateInfo fci = {VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr, 0, rp, 1, &view, 32, 32, 1};
Chris Forbes48a53902016-06-30 11:46:27 +12003885 VkFramebuffer fb;
3886 err = vkCreateFramebuffer(m_device->device(), &fci, nullptr, &fb);
3887 ASSERT_VK_SUCCESS(err);
3888
3889 // Record a single command buffer which uses this renderpass twice. The
3890 // bug is triggered at the beginning of the second renderpass, when the
3891 // command buffer already has a layout recorded for the attachment.
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003892 VkRenderPassBeginInfo rpbi = {VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO, nullptr, rp, fb, {{0, 0}, {32, 32}}, 0, nullptr};
Chris Forbes48a53902016-06-30 11:46:27 +12003893 BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003894 vkCmdBeginRenderPass(m_commandBuffer->handle(), &rpbi, VK_SUBPASS_CONTENTS_INLINE);
Chris Forbes48a53902016-06-30 11:46:27 +12003895 vkCmdEndRenderPass(m_commandBuffer->handle());
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003896 vkCmdBeginRenderPass(m_commandBuffer->handle(), &rpbi, VK_SUBPASS_CONTENTS_INLINE);
Chris Forbes48a53902016-06-30 11:46:27 +12003897
3898 m_errorMonitor->VerifyNotFound();
3899
3900 vkCmdEndRenderPass(m_commandBuffer->handle());
3901 EndCommandBuffer();
3902
3903 vkDestroyFramebuffer(m_device->device(), fb, nullptr);
3904 vkDestroyRenderPass(m_device->device(), rp, nullptr);
3905 vkDestroyImageView(m_device->device(), view, nullptr);
3906}
3907
Tobin Ehlis75ac37b2016-07-29 10:55:41 -06003908TEST_F(VkLayerTest, FramebufferBindingDestroyCommandPool) {
3909 TEST_DESCRIPTION("This test should pass. Create a Framebuffer and "
3910 "command buffer, bind them together, then destroy "
3911 "command pool and framebuffer and verify there are no "
3912 "errors.");
3913
3914 m_errorMonitor->ExpectSuccess();
3915
3916 ASSERT_NO_FATAL_FAILURE(InitState());
3917
3918 // A renderpass with one color attachment.
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003919 VkAttachmentDescription attachment = {0,
3920 VK_FORMAT_R8G8B8A8_UNORM,
3921 VK_SAMPLE_COUNT_1_BIT,
3922 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
3923 VK_ATTACHMENT_STORE_OP_STORE,
3924 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
3925 VK_ATTACHMENT_STORE_OP_DONT_CARE,
3926 VK_IMAGE_LAYOUT_UNDEFINED,
3927 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL};
Tobin Ehlis75ac37b2016-07-29 10:55:41 -06003928
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003929 VkAttachmentReference att_ref = {0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL};
Tobin Ehlis75ac37b2016-07-29 10:55:41 -06003930
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003931 VkSubpassDescription subpass = {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 1, &att_ref, nullptr, nullptr, 0, nullptr};
Tobin Ehlis75ac37b2016-07-29 10:55:41 -06003932
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003933 VkRenderPassCreateInfo rpci = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 1, &attachment, 1, &subpass, 0, nullptr};
Tobin Ehlis75ac37b2016-07-29 10:55:41 -06003934
3935 VkRenderPass rp;
3936 VkResult err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
3937 ASSERT_VK_SUCCESS(err);
3938
3939 // A compatible framebuffer.
3940 VkImageObj image(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003941 image.init(32, 32, VK_FORMAT_R8G8B8A8_UNORM, VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT, VK_IMAGE_TILING_OPTIMAL, 0);
Tobin Ehlis75ac37b2016-07-29 10:55:41 -06003942 ASSERT_TRUE(image.initialized());
3943
3944 VkImageViewCreateInfo ivci = {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003945 VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO,
3946 nullptr,
3947 0,
3948 image.handle(),
3949 VK_IMAGE_VIEW_TYPE_2D,
3950 VK_FORMAT_R8G8B8A8_UNORM,
3951 {VK_COMPONENT_SWIZZLE_IDENTITY, VK_COMPONENT_SWIZZLE_IDENTITY, VK_COMPONENT_SWIZZLE_IDENTITY,
3952 VK_COMPONENT_SWIZZLE_IDENTITY},
3953 {VK_IMAGE_ASPECT_COLOR_BIT, 0, 1, 0, 1},
Tobin Ehlis75ac37b2016-07-29 10:55:41 -06003954 };
3955 VkImageView view;
3956 err = vkCreateImageView(m_device->device(), &ivci, nullptr, &view);
3957 ASSERT_VK_SUCCESS(err);
3958
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003959 VkFramebufferCreateInfo fci = {VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr, 0, rp, 1, &view, 32, 32, 1};
Tobin Ehlis75ac37b2016-07-29 10:55:41 -06003960 VkFramebuffer fb;
3961 err = vkCreateFramebuffer(m_device->device(), &fci, nullptr, &fb);
3962 ASSERT_VK_SUCCESS(err);
3963
3964 // Explicitly create a command buffer to bind the FB to so that we can then
3965 // destroy the command pool in order to implicitly free command buffer
3966 VkCommandPool command_pool;
3967 VkCommandPoolCreateInfo pool_create_info{};
3968 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
3969 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
3970 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003971 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
Tobin Ehlis75ac37b2016-07-29 10:55:41 -06003972
3973 VkCommandBuffer command_buffer;
3974 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003975 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
Tobin Ehlis75ac37b2016-07-29 10:55:41 -06003976 command_buffer_allocate_info.commandPool = command_pool;
3977 command_buffer_allocate_info.commandBufferCount = 1;
3978 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003979 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, &command_buffer);
Tobin Ehlis75ac37b2016-07-29 10:55:41 -06003980
3981 // Begin our cmd buffer with renderpass using our framebuffer
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003982 VkRenderPassBeginInfo rpbi = {VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO, nullptr, rp, fb, {{0, 0}, {32, 32}}, 0, nullptr};
Tobin Ehlis75ac37b2016-07-29 10:55:41 -06003983 VkCommandBufferBeginInfo begin_info{};
3984 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
3985 vkBeginCommandBuffer(command_buffer, &begin_info);
3986
3987 vkCmdBeginRenderPass(command_buffer, &rpbi, VK_SUBPASS_CONTENTS_INLINE);
3988 vkCmdEndRenderPass(command_buffer);
3989 vkEndCommandBuffer(command_buffer);
Mark Lobodzinski7d10a822016-08-03 14:08:40 -06003990 vkDestroyImageView(m_device->device(), view, nullptr);
Tobin Ehlis75ac37b2016-07-29 10:55:41 -06003991 // Destroy command pool to implicitly free command buffer
3992 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
3993 vkDestroyFramebuffer(m_device->device(), fb, nullptr);
3994 vkDestroyRenderPass(m_device->device(), rp, nullptr);
3995 m_errorMonitor->VerifyNotFound();
3996}
3997
Chris Forbes51bf7c92016-06-30 15:22:08 +12003998TEST_F(VkLayerTest, RenderPassSubpassZeroTransitionsApplied) {
3999 TEST_DESCRIPTION("Ensure that CmdBeginRenderPass applies the layout "
4000 "transitions for the first subpass");
4001
4002 m_errorMonitor->ExpectSuccess();
4003
4004 ASSERT_NO_FATAL_FAILURE(InitState());
4005
4006 // A renderpass with one color attachment.
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004007 VkAttachmentDescription attachment = {0,
4008 VK_FORMAT_R8G8B8A8_UNORM,
4009 VK_SAMPLE_COUNT_1_BIT,
4010 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
4011 VK_ATTACHMENT_STORE_OP_STORE,
4012 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
4013 VK_ATTACHMENT_STORE_OP_DONT_CARE,
4014 VK_IMAGE_LAYOUT_UNDEFINED,
4015 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL};
Chris Forbes51bf7c92016-06-30 15:22:08 +12004016
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004017 VkAttachmentReference att_ref = {0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL};
Chris Forbes51bf7c92016-06-30 15:22:08 +12004018
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004019 VkSubpassDescription subpass = {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 1, &att_ref, nullptr, nullptr, 0, nullptr};
Chris Forbes51bf7c92016-06-30 15:22:08 +12004020
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004021 VkSubpassDependency dep = {0,
4022 0,
4023 VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT,
4024 VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT,
4025 VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT,
4026 VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT,
4027 VK_DEPENDENCY_BY_REGION_BIT};
Chris Forbes51bf7c92016-06-30 15:22:08 +12004028
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004029 VkRenderPassCreateInfo rpci = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 1, &attachment, 1, &subpass, 1, &dep};
Chris Forbes51bf7c92016-06-30 15:22:08 +12004030
4031 VkResult err;
4032 VkRenderPass rp;
4033 err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
4034 ASSERT_VK_SUCCESS(err);
4035
4036 // A compatible framebuffer.
4037 VkImageObj image(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004038 image.init(32, 32, VK_FORMAT_R8G8B8A8_UNORM, VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT, VK_IMAGE_TILING_OPTIMAL, 0);
Chris Forbes51bf7c92016-06-30 15:22:08 +12004039 ASSERT_TRUE(image.initialized());
4040
4041 VkImageViewCreateInfo ivci = {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004042 VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO,
4043 nullptr,
4044 0,
4045 image.handle(),
4046 VK_IMAGE_VIEW_TYPE_2D,
4047 VK_FORMAT_R8G8B8A8_UNORM,
4048 {VK_COMPONENT_SWIZZLE_IDENTITY, VK_COMPONENT_SWIZZLE_IDENTITY, VK_COMPONENT_SWIZZLE_IDENTITY,
4049 VK_COMPONENT_SWIZZLE_IDENTITY},
4050 {VK_IMAGE_ASPECT_COLOR_BIT, 0, 1, 0, 1},
Chris Forbes51bf7c92016-06-30 15:22:08 +12004051 };
4052 VkImageView view;
4053 err = vkCreateImageView(m_device->device(), &ivci, nullptr, &view);
4054 ASSERT_VK_SUCCESS(err);
4055
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004056 VkFramebufferCreateInfo fci = {VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr, 0, rp, 1, &view, 32, 32, 1};
Chris Forbes51bf7c92016-06-30 15:22:08 +12004057 VkFramebuffer fb;
4058 err = vkCreateFramebuffer(m_device->device(), &fci, nullptr, &fb);
4059 ASSERT_VK_SUCCESS(err);
4060
4061 // Record a single command buffer which issues a pipeline barrier w/
4062 // image memory barrier for the attachment. This detects the previously
4063 // missing tracking of the subpass layout by throwing a validation error
4064 // if it doesn't occur.
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004065 VkRenderPassBeginInfo rpbi = {VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO, nullptr, rp, fb, {{0, 0}, {32, 32}}, 0, nullptr};
Chris Forbes51bf7c92016-06-30 15:22:08 +12004066 BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004067 vkCmdBeginRenderPass(m_commandBuffer->handle(), &rpbi, VK_SUBPASS_CONTENTS_INLINE);
Chris Forbes51bf7c92016-06-30 15:22:08 +12004068
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004069 VkImageMemoryBarrier imb = {VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER,
4070 nullptr,
4071 VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT,
4072 VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT,
4073 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
4074 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
4075 VK_QUEUE_FAMILY_IGNORED,
4076 VK_QUEUE_FAMILY_IGNORED,
4077 image.handle(),
4078 {VK_IMAGE_ASPECT_COLOR_BIT, 0, 1, 0, 1}};
4079 vkCmdPipelineBarrier(m_commandBuffer->handle(), VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT,
4080 VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT, VK_DEPENDENCY_BY_REGION_BIT, 0, nullptr, 0, nullptr, 1,
4081 &imb);
Chris Forbes51bf7c92016-06-30 15:22:08 +12004082
4083 vkCmdEndRenderPass(m_commandBuffer->handle());
4084 m_errorMonitor->VerifyNotFound();
4085 EndCommandBuffer();
4086
4087 vkDestroyFramebuffer(m_device->device(), fb, nullptr);
4088 vkDestroyRenderPass(m_device->device(), rp, nullptr);
4089 vkDestroyImageView(m_device->device(), view, nullptr);
4090}
4091
Mark Lobodzinski77a5d6f2016-08-05 09:38:18 -06004092TEST_F(VkLayerTest, DepthStencilLayoutTransitionForDepthOnlyImageview) {
4093 TEST_DESCRIPTION("Validate that when an imageView of a depth/stencil image "
4094 "is used as a depth/stencil framebuffer attachment, the "
4095 "aspectMask is ignored and both depth and stencil image "
4096 "subresources are used.");
4097
4098 VkFormatProperties format_properties;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004099 vkGetPhysicalDeviceFormatProperties(gpu(), VK_FORMAT_D32_SFLOAT_S8_UINT, &format_properties);
4100 if (!(format_properties.optimalTilingFeatures & VK_FORMAT_FEATURE_SAMPLED_IMAGE_BIT)) {
Mark Lobodzinski77a5d6f2016-08-05 09:38:18 -06004101 return;
4102 }
4103
4104 m_errorMonitor->ExpectSuccess();
4105
4106 ASSERT_NO_FATAL_FAILURE(InitState());
4107
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004108 VkAttachmentDescription attachment = {0,
4109 VK_FORMAT_D32_SFLOAT_S8_UINT,
4110 VK_SAMPLE_COUNT_1_BIT,
4111 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
4112 VK_ATTACHMENT_STORE_OP_STORE,
4113 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
4114 VK_ATTACHMENT_STORE_OP_DONT_CARE,
4115 VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL,
4116 VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL};
Mark Lobodzinski77a5d6f2016-08-05 09:38:18 -06004117
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004118 VkAttachmentReference att_ref = {0, VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL};
Mark Lobodzinski77a5d6f2016-08-05 09:38:18 -06004119
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004120 VkSubpassDescription subpass = {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 0, nullptr, nullptr, &att_ref, 0, nullptr};
Mark Lobodzinski77a5d6f2016-08-05 09:38:18 -06004121
4122 VkSubpassDependency dep = {0,
4123 0,
4124 VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT,
4125 VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT,
4126 VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT,
4127 VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT,
4128 VK_DEPENDENCY_BY_REGION_BIT};
4129
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004130 VkRenderPassCreateInfo rpci = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 1, &attachment, 1, &subpass, 1, &dep};
Mark Lobodzinski77a5d6f2016-08-05 09:38:18 -06004131
4132 VkResult err;
4133 VkRenderPass rp;
4134 err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
4135 ASSERT_VK_SUCCESS(err);
4136
4137 VkImageObj image(m_device);
4138 image.init_no_layout(32, 32, VK_FORMAT_D32_SFLOAT_S8_UINT,
4139 0x26, // usage
4140 VK_IMAGE_TILING_OPTIMAL, 0);
4141 ASSERT_TRUE(image.initialized());
4142 image.SetLayout(0x6, VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL);
4143
4144 VkImageViewCreateInfo ivci = {
4145 VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO,
4146 nullptr,
4147 0,
4148 image.handle(),
4149 VK_IMAGE_VIEW_TYPE_2D,
4150 VK_FORMAT_D32_SFLOAT_S8_UINT,
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004151 {VK_COMPONENT_SWIZZLE_R, VK_COMPONENT_SWIZZLE_G, VK_COMPONENT_SWIZZLE_B, VK_COMPONENT_SWIZZLE_A},
Mark Lobodzinski77a5d6f2016-08-05 09:38:18 -06004152 {0x2, 0, 1, 0, 1},
4153 };
4154 VkImageView view;
4155 err = vkCreateImageView(m_device->device(), &ivci, nullptr, &view);
4156 ASSERT_VK_SUCCESS(err);
4157
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004158 VkFramebufferCreateInfo fci = {VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr, 0, rp, 1, &view, 32, 32, 1};
Mark Lobodzinski77a5d6f2016-08-05 09:38:18 -06004159 VkFramebuffer fb;
4160 err = vkCreateFramebuffer(m_device->device(), &fci, nullptr, &fb);
4161 ASSERT_VK_SUCCESS(err);
4162
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004163 VkRenderPassBeginInfo rpbi = {VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO, nullptr, rp, fb, {{0, 0}, {32, 32}}, 0, nullptr};
Mark Lobodzinski77a5d6f2016-08-05 09:38:18 -06004164 BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004165 vkCmdBeginRenderPass(m_commandBuffer->handle(), &rpbi, VK_SUBPASS_CONTENTS_INLINE);
Mark Lobodzinski77a5d6f2016-08-05 09:38:18 -06004166
4167 VkImageMemoryBarrier imb = {};
4168 imb.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
4169 imb.pNext = nullptr;
4170 imb.srcAccessMask = VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_WRITE_BIT;
4171 imb.dstAccessMask = VK_ACCESS_SHADER_READ_BIT;
4172 imb.oldLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
4173 imb.newLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
4174 imb.srcQueueFamilyIndex = 0;
4175 imb.dstQueueFamilyIndex = 0;
4176 imb.image = image.handle();
4177 imb.subresourceRange.aspectMask = 0x6;
4178 imb.subresourceRange.baseMipLevel = 0;
4179 imb.subresourceRange.levelCount = 0x1;
4180 imb.subresourceRange.baseArrayLayer = 0;
4181 imb.subresourceRange.layerCount = 0x1;
4182
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004183 vkCmdPipelineBarrier(m_commandBuffer->handle(), VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT,
4184 VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT, VK_DEPENDENCY_BY_REGION_BIT, 0, nullptr, 0, nullptr, 1,
Mark Lobodzinski77a5d6f2016-08-05 09:38:18 -06004185 &imb);
4186
4187 vkCmdEndRenderPass(m_commandBuffer->handle());
4188 EndCommandBuffer();
4189 QueueCommandBuffer(false);
4190 m_errorMonitor->VerifyNotFound();
4191
4192 vkDestroyFramebuffer(m_device->device(), fb, nullptr);
4193 vkDestroyRenderPass(m_device->device(), rp, nullptr);
4194 vkDestroyImageView(m_device->device(), view, nullptr);
4195}
Tony Barbourd5f7b822016-08-02 15:39:33 -06004196
Tony Barbour4e919972016-08-09 13:27:40 -06004197TEST_F(VkLayerTest, RenderPassInvalidRenderArea) {
4198 TEST_DESCRIPTION("Generate INVALID_RENDER_AREA error by beginning renderpass"
4199 "with extent outside of framebuffer");
4200 ASSERT_NO_FATAL_FAILURE(InitState());
4201 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
4202
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004203 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Cannot execute a render pass with renderArea "
4204 "not within the bound of the framebuffer.");
Tony Barbour4e919972016-08-09 13:27:40 -06004205
4206 // Framebuffer for render target is 256x256, exceed that for INVALID_RENDER_AREA
4207 m_renderPassBeginInfo.renderArea.extent.width = 257;
4208 m_renderPassBeginInfo.renderArea.extent.height = 257;
4209 BeginCommandBuffer();
4210 m_errorMonitor->VerifyFound();
4211}
4212
4213TEST_F(VkLayerTest, DisabledIndependentBlend) {
4214 TEST_DESCRIPTION("Generate INDEPENDENT_BLEND by disabling independent "
4215 "blend and then specifying different blend states for two "
4216 "attachements");
Cody Northrop5703cc72016-08-19 09:57:10 -06004217 VkPhysicalDeviceFeatures features = {};
4218 features.independentBlend = VK_FALSE;
Cody Northropc31a84f2016-08-22 10:41:47 -06004219 ASSERT_NO_FATAL_FAILURE(InitState(&features));
Tony Barbour4e919972016-08-09 13:27:40 -06004220
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004221 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
4222 "Invalid Pipeline CreateInfo: If independent blend feature not "
4223 "enabled, all elements of pAttachments must be identical");
Tony Barbour4e919972016-08-09 13:27:40 -06004224
Cody Northropc31a84f2016-08-22 10:41:47 -06004225 VkDescriptorSetObj descriptorSet(m_device);
4226 descriptorSet.AppendDummy();
4227 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Tony Barbour4e919972016-08-09 13:27:40 -06004228
Cody Northropc31a84f2016-08-22 10:41:47 -06004229 VkPipelineObj pipeline(m_device);
4230 VkRenderpassObj renderpass(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004231 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
Cody Northropc31a84f2016-08-22 10:41:47 -06004232 pipeline.AddShader(&vs);
Cody Northrop5703cc72016-08-19 09:57:10 -06004233
Cody Northropc31a84f2016-08-22 10:41:47 -06004234 VkPipelineColorBlendAttachmentState att_state1 = {}, att_state2 = {};
4235 att_state1.dstAlphaBlendFactor = VK_BLEND_FACTOR_CONSTANT_COLOR;
4236 att_state1.blendEnable = VK_TRUE;
4237 att_state2.dstAlphaBlendFactor = VK_BLEND_FACTOR_CONSTANT_COLOR;
4238 att_state2.blendEnable = VK_FALSE;
4239 pipeline.AddColorAttachment(0, &att_state1);
4240 pipeline.AddColorAttachment(1, &att_state2);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004241 pipeline.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderpass.handle());
Cody Northropc31a84f2016-08-22 10:41:47 -06004242 m_errorMonitor->VerifyFound();
Tony Barbour4e919972016-08-09 13:27:40 -06004243}
4244
4245TEST_F(VkLayerTest, RenderPassDepthStencilAttachmentUnused) {
4246 TEST_DESCRIPTION("Specify no depth attachement in renderpass then specify "
4247 "depth attachments in subpass");
Cody Northropc31a84f2016-08-22 10:41:47 -06004248 ASSERT_NO_FATAL_FAILURE(InitState());
Tony Barbour4e919972016-08-09 13:27:40 -06004249
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004250 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
4251 "vkCreateRenderPass has no depth/stencil attachment, yet subpass");
Tony Barbour4e919972016-08-09 13:27:40 -06004252
4253 // Create a renderPass with a single color attachment
4254 VkAttachmentReference attach = {};
4255 attach.layout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
4256 VkSubpassDescription subpass = {};
4257 VkRenderPassCreateInfo rpci = {};
4258 rpci.subpassCount = 1;
4259 rpci.pSubpasses = &subpass;
4260 rpci.attachmentCount = 1;
4261 VkAttachmentDescription attach_desc = {};
4262 attach_desc.format = VK_FORMAT_B8G8R8A8_UNORM;
4263 attach_desc.samples = VK_SAMPLE_COUNT_1_BIT;
4264 rpci.pAttachments = &attach_desc;
4265 rpci.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
4266 VkRenderPass rp;
4267 subpass.pDepthStencilAttachment = &attach;
4268 subpass.pColorAttachments = NULL;
4269 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
4270 m_errorMonitor->VerifyFound();
4271}
4272
Chris Forbes6b3d3f42016-06-30 16:09:47 +12004273TEST_F(VkLayerTest, RenderPassTransitionsAttachmentUnused) {
4274 TEST_DESCRIPTION("Ensure that layout transitions work correctly without "
4275 "errors, when an attachment reference is "
4276 "VK_ATTACHMENT_UNUSED");
4277
4278 m_errorMonitor->ExpectSuccess();
4279
4280 ASSERT_NO_FATAL_FAILURE(InitState());
4281
4282 // A renderpass with no attachments
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004283 VkAttachmentReference att_ref = {VK_ATTACHMENT_UNUSED, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL};
Chris Forbes6b3d3f42016-06-30 16:09:47 +12004284
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004285 VkSubpassDescription subpass = {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 1, &att_ref, nullptr, nullptr, 0, nullptr};
Chris Forbes6b3d3f42016-06-30 16:09:47 +12004286
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004287 VkRenderPassCreateInfo rpci = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 0, nullptr, 1, &subpass, 0, nullptr};
Chris Forbes6b3d3f42016-06-30 16:09:47 +12004288
4289 VkRenderPass rp;
4290 VkResult err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
4291 ASSERT_VK_SUCCESS(err);
4292
4293 // A compatible framebuffer.
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004294 VkFramebufferCreateInfo fci = {VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr, 0, rp, 0, nullptr, 32, 32, 1};
Chris Forbes6b3d3f42016-06-30 16:09:47 +12004295 VkFramebuffer fb;
4296 err = vkCreateFramebuffer(m_device->device(), &fci, nullptr, &fb);
4297 ASSERT_VK_SUCCESS(err);
4298
4299 // Record a command buffer which just begins and ends the renderpass. The
4300 // bug manifests in BeginRenderPass.
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004301 VkRenderPassBeginInfo rpbi = {VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO, nullptr, rp, fb, {{0, 0}, {32, 32}}, 0, nullptr};
Chris Forbes6b3d3f42016-06-30 16:09:47 +12004302 BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004303 vkCmdBeginRenderPass(m_commandBuffer->handle(), &rpbi, VK_SUBPASS_CONTENTS_INLINE);
Chris Forbes6b3d3f42016-06-30 16:09:47 +12004304 vkCmdEndRenderPass(m_commandBuffer->handle());
4305 m_errorMonitor->VerifyNotFound();
4306 EndCommandBuffer();
4307
4308 vkDestroyFramebuffer(m_device->device(), fb, nullptr);
4309 vkDestroyRenderPass(m_device->device(), rp, nullptr);
4310}
4311
Mark Lobodzinskice7eee72016-06-14 16:33:29 -06004312// This is a positive test. No errors are expected.
4313TEST_F(VkLayerTest, StencilLoadOp) {
4314 TEST_DESCRIPTION("Create a stencil-only attachment with a LOAD_OP set to "
4315 "CLEAR. stencil[Load|Store]Op used to be ignored.");
4316 VkResult result = VK_SUCCESS;
4317 VkImageFormatProperties formatProps;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004318 vkGetPhysicalDeviceImageFormatProperties(gpu(), VK_FORMAT_D24_UNORM_S8_UINT, VK_IMAGE_TYPE_2D, VK_IMAGE_TILING_OPTIMAL,
4319 VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_SRC_BIT, 0,
4320 &formatProps);
Mark Lobodzinskice7eee72016-06-14 16:33:29 -06004321 if (formatProps.maxExtent.width < 100 || formatProps.maxExtent.height < 100) {
4322 return;
4323 }
4324
4325 ASSERT_NO_FATAL_FAILURE(InitState());
4326 VkFormat depth_stencil_fmt = VK_FORMAT_D24_UNORM_S8_UINT;
4327 m_depthStencil->Init(m_device, 100, 100, depth_stencil_fmt,
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004328 VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_SRC_BIT);
Mark Lobodzinskice7eee72016-06-14 16:33:29 -06004329 VkAttachmentDescription att = {};
4330 VkAttachmentReference ref = {};
4331 att.format = depth_stencil_fmt;
4332 att.loadOp = VK_ATTACHMENT_LOAD_OP_DONT_CARE;
4333 att.storeOp = VK_ATTACHMENT_STORE_OP_DONT_CARE;
4334 att.stencilLoadOp = VK_ATTACHMENT_LOAD_OP_CLEAR;
4335 att.stencilStoreOp = VK_ATTACHMENT_STORE_OP_STORE;
4336 att.initialLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
4337 att.finalLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
4338
4339 VkClearValue clear;
4340 clear.depthStencil.depth = 1.0;
4341 clear.depthStencil.stencil = 0;
4342 ref.attachment = 0;
4343 ref.layout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
4344
4345 VkSubpassDescription subpass = {};
4346 subpass.pipelineBindPoint = VK_PIPELINE_BIND_POINT_GRAPHICS;
4347 subpass.flags = 0;
4348 subpass.inputAttachmentCount = 0;
4349 subpass.pInputAttachments = NULL;
4350 subpass.colorAttachmentCount = 0;
4351 subpass.pColorAttachments = NULL;
4352 subpass.pResolveAttachments = NULL;
4353 subpass.pDepthStencilAttachment = &ref;
4354 subpass.preserveAttachmentCount = 0;
4355 subpass.pPreserveAttachments = NULL;
4356
4357 VkRenderPass rp;
4358 VkRenderPassCreateInfo rp_info = {};
4359 rp_info.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
4360 rp_info.attachmentCount = 1;
4361 rp_info.pAttachments = &att;
4362 rp_info.subpassCount = 1;
4363 rp_info.pSubpasses = &subpass;
4364 result = vkCreateRenderPass(device(), &rp_info, NULL, &rp);
4365 ASSERT_VK_SUCCESS(result);
4366
4367 VkImageView *depthView = m_depthStencil->BindInfo();
4368 VkFramebufferCreateInfo fb_info = {};
4369 fb_info.sType = VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO;
4370 fb_info.pNext = NULL;
4371 fb_info.renderPass = rp;
4372 fb_info.attachmentCount = 1;
4373 fb_info.pAttachments = depthView;
4374 fb_info.width = 100;
4375 fb_info.height = 100;
4376 fb_info.layers = 1;
4377 VkFramebuffer fb;
4378 result = vkCreateFramebuffer(device(), &fb_info, NULL, &fb);
4379 ASSERT_VK_SUCCESS(result);
4380
Mark Lobodzinskice7eee72016-06-14 16:33:29 -06004381 VkRenderPassBeginInfo rpbinfo = {};
4382 rpbinfo.clearValueCount = 1;
4383 rpbinfo.pClearValues = &clear;
4384 rpbinfo.pNext = NULL;
4385 rpbinfo.renderPass = rp;
4386 rpbinfo.sType = VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO;
4387 rpbinfo.renderArea.extent.width = 100;
4388 rpbinfo.renderArea.extent.height = 100;
4389 rpbinfo.renderArea.offset.x = 0;
4390 rpbinfo.renderArea.offset.y = 0;
4391 rpbinfo.framebuffer = fb;
4392
4393 VkFence fence = {};
4394 VkFenceCreateInfo fence_ci = {};
4395 fence_ci.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
4396 fence_ci.pNext = nullptr;
4397 fence_ci.flags = 0;
4398 result = vkCreateFence(m_device->device(), &fence_ci, nullptr, &fence);
4399 ASSERT_VK_SUCCESS(result);
4400
Mark Lobodzinskice7eee72016-06-14 16:33:29 -06004401 m_commandBuffer->BeginCommandBuffer();
4402 m_commandBuffer->BeginRenderPass(rpbinfo);
4403 m_commandBuffer->EndRenderPass();
4404 m_commandBuffer->EndCommandBuffer();
4405 m_commandBuffer->QueueCommandBuffer(fence);
4406
4407 VkImageObj destImage(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004408 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 -06004409 VK_IMAGE_TILING_OPTIMAL, 0);
4410 VkImageMemoryBarrier barrier = {};
4411 VkImageSubresourceRange range;
4412 barrier.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004413 barrier.srcAccessMask = VK_ACCESS_TRANSFER_WRITE_BIT | VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_WRITE_BIT;
4414 barrier.dstAccessMask = VK_ACCESS_TRANSFER_READ_BIT | VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_READ_BIT;
Mark Lobodzinskice7eee72016-06-14 16:33:29 -06004415 barrier.oldLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
4416 barrier.newLayout = VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL;
4417 barrier.image = m_depthStencil->handle();
4418 range.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT;
4419 range.baseMipLevel = 0;
4420 range.levelCount = 1;
4421 range.baseArrayLayer = 0;
4422 range.layerCount = 1;
4423 barrier.subresourceRange = range;
4424 vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
4425 VkCommandBufferObj cmdbuf(m_device, m_commandPool);
4426 cmdbuf.BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004427 cmdbuf.PipelineBarrier(VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0, nullptr, 0, nullptr, 1,
4428 &barrier);
Mark Lobodzinskice7eee72016-06-14 16:33:29 -06004429 barrier.srcAccessMask = 0;
4430 barrier.oldLayout = VK_IMAGE_LAYOUT_UNDEFINED;
4431 barrier.newLayout = VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL;
4432 barrier.image = destImage.handle();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004433 barrier.dstAccessMask = VK_ACCESS_TRANSFER_WRITE_BIT | VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_WRITE_BIT;
4434 cmdbuf.PipelineBarrier(VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0, nullptr, 0, nullptr, 1,
4435 &barrier);
Mark Lobodzinskice7eee72016-06-14 16:33:29 -06004436 VkImageCopy cregion;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004437 cregion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT;
Mark Lobodzinskice7eee72016-06-14 16:33:29 -06004438 cregion.srcSubresource.mipLevel = 0;
4439 cregion.srcSubresource.baseArrayLayer = 0;
4440 cregion.srcSubresource.layerCount = 1;
4441 cregion.srcOffset.x = 0;
4442 cregion.srcOffset.y = 0;
4443 cregion.srcOffset.z = 0;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004444 cregion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT;
Mark Lobodzinskice7eee72016-06-14 16:33:29 -06004445 cregion.dstSubresource.mipLevel = 0;
4446 cregion.dstSubresource.baseArrayLayer = 0;
4447 cregion.dstSubresource.layerCount = 1;
4448 cregion.dstOffset.x = 0;
4449 cregion.dstOffset.y = 0;
4450 cregion.dstOffset.z = 0;
4451 cregion.extent.width = 100;
4452 cregion.extent.height = 100;
4453 cregion.extent.depth = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004454 cmdbuf.CopyImage(m_depthStencil->handle(), VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL, destImage.handle(),
Mark Lobodzinskice7eee72016-06-14 16:33:29 -06004455 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, &cregion);
4456 cmdbuf.EndCommandBuffer();
4457
4458 VkSubmitInfo submit_info;
4459 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
4460 submit_info.pNext = NULL;
4461 submit_info.waitSemaphoreCount = 0;
4462 submit_info.pWaitSemaphores = NULL;
4463 submit_info.pWaitDstStageMask = NULL;
4464 submit_info.commandBufferCount = 1;
4465 submit_info.pCommandBuffers = &cmdbuf.handle();
4466 submit_info.signalSemaphoreCount = 0;
4467 submit_info.pSignalSemaphores = NULL;
4468
4469 m_errorMonitor->ExpectSuccess();
4470 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
4471 m_errorMonitor->VerifyNotFound();
4472
Mark Lobodzinskid0440da2016-06-17 15:10:03 -06004473 vkQueueWaitIdle(m_device->m_queue);
Mark Lobodzinskice7eee72016-06-14 16:33:29 -06004474 vkDestroyFence(m_device->device(), fence, nullptr);
4475 vkDestroyRenderPass(m_device->device(), rp, nullptr);
4476 vkDestroyFramebuffer(m_device->device(), fb, nullptr);
4477}
4478
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06004479TEST_F(VkLayerTest, UnusedPreserveAttachment) {
4480 TEST_DESCRIPTION("Create a framebuffer where a subpass has a preserve "
4481 "attachment reference of VK_ATTACHMENT_UNUSED");
4482
4483 ASSERT_NO_FATAL_FAILURE(InitState());
4484 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
4485
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004486 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "must not be VK_ATTACHMENT_UNUSED");
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06004487
4488 VkAttachmentReference color_attach = {};
4489 color_attach.layout = VK_IMAGE_LAYOUT_GENERAL;
4490 color_attach.attachment = 0;
4491 uint32_t preserve_attachment = VK_ATTACHMENT_UNUSED;
4492 VkSubpassDescription subpass = {};
4493 subpass.colorAttachmentCount = 1;
4494 subpass.pColorAttachments = &color_attach;
4495 subpass.preserveAttachmentCount = 1;
4496 subpass.pPreserveAttachments = &preserve_attachment;
4497
4498 VkRenderPassCreateInfo rpci = {};
4499 rpci.subpassCount = 1;
4500 rpci.pSubpasses = &subpass;
4501 rpci.attachmentCount = 1;
4502 VkAttachmentDescription attach_desc = {};
4503 attach_desc.format = VK_FORMAT_UNDEFINED;
4504 rpci.pAttachments = &attach_desc;
4505 rpci.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
4506 VkRenderPass rp;
Mark Lobodzinskia4feeeb2016-06-17 12:00:46 -06004507 VkResult result = vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06004508
4509 m_errorMonitor->VerifyFound();
4510
Mark Lobodzinskia4feeeb2016-06-17 12:00:46 -06004511 if (result == VK_SUCCESS) {
4512 vkDestroyRenderPass(m_device->device(), rp, NULL);
4513 }
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06004514}
4515
Chris Forbesc5389742016-06-29 11:49:23 +12004516TEST_F(VkLayerTest, CreateRenderPassResolveRequiresColorMsaa) {
Chris Forbes6655bb32016-07-01 18:27:30 +12004517 TEST_DESCRIPTION("Ensure that CreateRenderPass produces a validation error "
4518 "when the source of a subpass multisample resolve "
4519 "does not have multiple samples.");
4520
Chris Forbesc5389742016-06-29 11:49:23 +12004521 ASSERT_NO_FATAL_FAILURE(InitState());
4522
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004523 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
4524 "Subpass 0 requests multisample resolve from attachment 0 which has "
4525 "VK_SAMPLE_COUNT_1_BIT");
Chris Forbesc5389742016-06-29 11:49:23 +12004526
4527 VkAttachmentDescription attachments[] = {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004528 {0, VK_FORMAT_R8G8B8A8_UNORM, VK_SAMPLE_COUNT_1_BIT, VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE,
4529 VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
4530 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL},
4531 {0, VK_FORMAT_R8G8B8A8_UNORM, VK_SAMPLE_COUNT_1_BIT, VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE,
4532 VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
4533 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL},
Chris Forbesc5389742016-06-29 11:49:23 +12004534 };
4535
4536 VkAttachmentReference color = {
4537 0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
4538 };
4539
4540 VkAttachmentReference resolve = {
4541 0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
4542 };
4543
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004544 VkSubpassDescription subpass = {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 1, &color, &resolve, nullptr, 0, nullptr};
Chris Forbesc5389742016-06-29 11:49:23 +12004545
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004546 VkRenderPassCreateInfo rpci = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 2, attachments, 1, &subpass, 0, nullptr};
Chris Forbesc5389742016-06-29 11:49:23 +12004547
4548 VkRenderPass rp;
4549 VkResult err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
4550
4551 m_errorMonitor->VerifyFound();
4552
4553 if (err == VK_SUCCESS)
4554 vkDestroyRenderPass(m_device->device(), rp, nullptr);
4555}
4556
4557TEST_F(VkLayerTest, CreateRenderPassResolveRequiresSingleSampleDest) {
Chris Forbes6655bb32016-07-01 18:27:30 +12004558 TEST_DESCRIPTION("Ensure CreateRenderPass produces a validation error "
4559 "when a subpass multisample resolve operation is "
4560 "requested, and the destination of that resolve has "
4561 "multiple samples.");
4562
Chris Forbesc5389742016-06-29 11:49:23 +12004563 ASSERT_NO_FATAL_FAILURE(InitState());
4564
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004565 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
4566 "Subpass 0 requests multisample resolve into attachment 1, which "
4567 "must have VK_SAMPLE_COUNT_1_BIT but has VK_SAMPLE_COUNT_4_BIT");
Chris Forbesc5389742016-06-29 11:49:23 +12004568
4569 VkAttachmentDescription attachments[] = {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004570 {0, VK_FORMAT_R8G8B8A8_UNORM, VK_SAMPLE_COUNT_4_BIT, VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE,
4571 VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
4572 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL},
4573 {0, VK_FORMAT_R8G8B8A8_UNORM, VK_SAMPLE_COUNT_4_BIT, VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE,
4574 VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
4575 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL},
Chris Forbesc5389742016-06-29 11:49:23 +12004576 };
4577
4578 VkAttachmentReference color = {
4579 0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
4580 };
4581
4582 VkAttachmentReference resolve = {
4583 1, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
4584 };
4585
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004586 VkSubpassDescription subpass = {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 1, &color, &resolve, nullptr, 0, nullptr};
Chris Forbesc5389742016-06-29 11:49:23 +12004587
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004588 VkRenderPassCreateInfo rpci = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 2, attachments, 1, &subpass, 0, nullptr};
Chris Forbesc5389742016-06-29 11:49:23 +12004589
4590 VkRenderPass rp;
4591 VkResult err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
4592
4593 m_errorMonitor->VerifyFound();
4594
4595 if (err == VK_SUCCESS)
4596 vkDestroyRenderPass(m_device->device(), rp, nullptr);
4597}
4598
Chris Forbes3f128ef2016-06-29 14:58:53 +12004599TEST_F(VkLayerTest, CreateRenderPassSubpassSampleCountConsistency) {
Chris Forbes6655bb32016-07-01 18:27:30 +12004600 TEST_DESCRIPTION("Ensure CreateRenderPass produces a validation error "
4601 "when the color and depth attachments used by a subpass "
4602 "have inconsistent sample counts");
4603
Chris Forbes3f128ef2016-06-29 14:58:53 +12004604 ASSERT_NO_FATAL_FAILURE(InitState());
4605
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004606 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
4607 "Subpass 0 attempts to render to attachments with inconsistent sample counts");
Chris Forbes3f128ef2016-06-29 14:58:53 +12004608
4609 VkAttachmentDescription attachments[] = {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004610 {0, VK_FORMAT_R8G8B8A8_UNORM, VK_SAMPLE_COUNT_1_BIT, VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE,
4611 VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
4612 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL},
4613 {0, VK_FORMAT_R8G8B8A8_UNORM, VK_SAMPLE_COUNT_4_BIT, VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE,
4614 VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
4615 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL},
Chris Forbes3f128ef2016-06-29 14:58:53 +12004616 };
4617
4618 VkAttachmentReference color[] = {
4619 {
4620 0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
4621 },
4622 {
4623 1, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
4624 },
4625 };
4626
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004627 VkSubpassDescription subpass = {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 2, color, nullptr, nullptr, 0, nullptr};
Chris Forbes3f128ef2016-06-29 14:58:53 +12004628
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004629 VkRenderPassCreateInfo rpci = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 2, attachments, 1, &subpass, 0, nullptr};
Chris Forbes3f128ef2016-06-29 14:58:53 +12004630
4631 VkRenderPass rp;
4632 VkResult err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
4633
4634 m_errorMonitor->VerifyFound();
4635
4636 if (err == VK_SUCCESS)
4637 vkDestroyRenderPass(m_device->device(), rp, nullptr);
4638}
4639
Tobin Ehlis2545e6f2016-06-22 10:42:19 -06004640TEST_F(VkLayerTest, FramebufferCreateErrors) {
4641 TEST_DESCRIPTION("Hit errors when attempting to create a framebuffer :\n"
4642 " 1. Mismatch between fb & renderPass attachmentCount\n"
Tobin Ehlisd3bb23a2016-06-22 13:34:46 -06004643 " 2. Use a color image as depthStencil attachment\n"
Tobin Ehlis77d717c2016-06-22 14:19:19 -06004644 " 3. Mismatch fb & renderPass attachment formats\n"
Tobin Ehlis6cfda642016-06-22 16:12:58 -06004645 " 4. Mismatch fb & renderPass attachment #samples\n"
Tobin Ehlis27f2ae82016-06-23 07:36:57 -06004646 " 5. FB attachment w/ non-1 mip-levels\n"
Tobin Ehlisb1f303b2016-06-23 08:19:55 -06004647 " 6. FB attachment where dimensions don't match\n"
Tobin Ehlis08d4b5e2016-06-23 08:52:39 -06004648 " 7. FB attachment w/o identity swizzle\n"
4649 " 8. FB dimensions exceed physical device limits\n");
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06004650
4651 ASSERT_NO_FATAL_FAILURE(InitState());
4652 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
4653
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004654 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
4655 "vkCreateFramebuffer(): VkFramebufferCreateInfo attachmentCount of 2 "
4656 "does not match attachmentCount of 1 of ");
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06004657
Tobin Ehlis2545e6f2016-06-22 10:42:19 -06004658 // Create a renderPass with a single color attachment
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06004659 VkAttachmentReference attach = {};
4660 attach.layout = VK_IMAGE_LAYOUT_GENERAL;
4661 VkSubpassDescription subpass = {};
Tobin Ehlis2545e6f2016-06-22 10:42:19 -06004662 subpass.pColorAttachments = &attach;
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06004663 VkRenderPassCreateInfo rpci = {};
4664 rpci.subpassCount = 1;
4665 rpci.pSubpasses = &subpass;
4666 rpci.attachmentCount = 1;
4667 VkAttachmentDescription attach_desc = {};
Tobin Ehlisd3bb23a2016-06-22 13:34:46 -06004668 attach_desc.format = VK_FORMAT_B8G8R8A8_UNORM;
Tobin Ehlis77d717c2016-06-22 14:19:19 -06004669 attach_desc.samples = VK_SAMPLE_COUNT_1_BIT;
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06004670 rpci.pAttachments = &attach_desc;
4671 rpci.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
4672 VkRenderPass rp;
4673 VkResult err = vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
4674 ASSERT_VK_SUCCESS(err);
4675
Tobin Ehlis2545e6f2016-06-22 10:42:19 -06004676 VkImageView ivs[2];
4677 ivs[0] = m_renderTargets[0]->targetView(VK_FORMAT_B8G8R8A8_UNORM);
4678 ivs[1] = m_renderTargets[0]->targetView(VK_FORMAT_B8G8R8A8_UNORM);
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06004679 VkFramebufferCreateInfo fb_info = {};
4680 fb_info.sType = VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO;
4681 fb_info.pNext = NULL;
4682 fb_info.renderPass = rp;
Tobin Ehlis2545e6f2016-06-22 10:42:19 -06004683 // Set mis-matching attachmentCount
4684 fb_info.attachmentCount = 2;
4685 fb_info.pAttachments = ivs;
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06004686 fb_info.width = 100;
4687 fb_info.height = 100;
4688 fb_info.layers = 1;
4689
4690 VkFramebuffer fb;
4691 err = vkCreateFramebuffer(device(), &fb_info, NULL, &fb);
4692
4693 m_errorMonitor->VerifyFound();
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06004694 if (err == VK_SUCCESS) {
4695 vkDestroyFramebuffer(m_device->device(), fb, NULL);
4696 }
4697 vkDestroyRenderPass(m_device->device(), rp, NULL);
Tobin Ehlis2545e6f2016-06-22 10:42:19 -06004698
4699 // Create a renderPass with a depth-stencil attachment created with
4700 // IMAGE_USAGE_COLOR_ATTACHMENT
4701 // Add our color attachment to pDepthStencilAttachment
4702 subpass.pDepthStencilAttachment = &attach;
4703 subpass.pColorAttachments = NULL;
4704 VkRenderPass rp_ds;
4705 err = vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp_ds);
4706 ASSERT_VK_SUCCESS(err);
4707 // Set correct attachment count, but attachment has COLOR usage bit set
4708 fb_info.attachmentCount = 1;
4709 fb_info.renderPass = rp_ds;
4710
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004711 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " conflicts with the image's IMAGE_USAGE flags ");
Tobin Ehlis2545e6f2016-06-22 10:42:19 -06004712 err = vkCreateFramebuffer(device(), &fb_info, NULL, &fb);
4713
4714 m_errorMonitor->VerifyFound();
4715 if (err == VK_SUCCESS) {
4716 vkDestroyFramebuffer(m_device->device(), fb, NULL);
4717 }
4718 vkDestroyRenderPass(m_device->device(), rp_ds, NULL);
Tobin Ehlisd3bb23a2016-06-22 13:34:46 -06004719
4720 // Create new renderpass with alternate attachment format from fb
4721 attach_desc.format = VK_FORMAT_R8G8B8A8_UNORM;
4722 subpass.pDepthStencilAttachment = NULL;
4723 subpass.pColorAttachments = &attach;
4724 err = vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
4725 ASSERT_VK_SUCCESS(err);
4726
4727 // Cause error due to mis-matched formats between rp & fb
4728 // rp attachment 0 now has RGBA8 but corresponding fb attach is BGRA8
4729 fb_info.renderPass = rp;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004730 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
4731 " has format of VK_FORMAT_B8G8R8A8_UNORM that does not match ");
Tobin Ehlisd3bb23a2016-06-22 13:34:46 -06004732 err = vkCreateFramebuffer(device(), &fb_info, NULL, &fb);
4733
4734 m_errorMonitor->VerifyFound();
4735 if (err == VK_SUCCESS) {
4736 vkDestroyFramebuffer(m_device->device(), fb, NULL);
4737 }
Tobin Ehlis77d717c2016-06-22 14:19:19 -06004738 vkDestroyRenderPass(m_device->device(), rp, NULL);
4739
4740 // Create new renderpass with alternate sample count from fb
4741 attach_desc.format = VK_FORMAT_B8G8R8A8_UNORM;
4742 attach_desc.samples = VK_SAMPLE_COUNT_4_BIT;
4743 err = vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
4744 ASSERT_VK_SUCCESS(err);
4745
4746 // Cause error due to mis-matched sample count between rp & fb
4747 fb_info.renderPass = rp;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004748 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " has VK_SAMPLE_COUNT_1_BIT samples "
4749 "that do not match the "
4750 "VK_SAMPLE_COUNT_4_BIT ");
Tobin Ehlis77d717c2016-06-22 14:19:19 -06004751 err = vkCreateFramebuffer(device(), &fb_info, NULL, &fb);
4752
4753 m_errorMonitor->VerifyFound();
4754 if (err == VK_SUCCESS) {
4755 vkDestroyFramebuffer(m_device->device(), fb, NULL);
4756 }
Tobin Ehlisd3bb23a2016-06-22 13:34:46 -06004757
4758 vkDestroyRenderPass(m_device->device(), rp, NULL);
Tobin Ehlis6cfda642016-06-22 16:12:58 -06004759
4760 // Create a custom imageView with non-1 mip levels
4761 VkImageObj image(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004762 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 -06004763 ASSERT_TRUE(image.initialized());
4764
4765 VkImageView view;
4766 VkImageViewCreateInfo ivci = {};
4767 ivci.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
4768 ivci.image = image.handle();
4769 ivci.viewType = VK_IMAGE_VIEW_TYPE_2D;
4770 ivci.format = VK_FORMAT_B8G8R8A8_UNORM;
4771 ivci.subresourceRange.layerCount = 1;
4772 ivci.subresourceRange.baseMipLevel = 0;
4773 // Set level count 2 (only 1 is allowed for FB attachment)
4774 ivci.subresourceRange.levelCount = 2;
4775 ivci.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
4776 err = vkCreateImageView(m_device->device(), &ivci, NULL, &view);
4777 ASSERT_VK_SUCCESS(err);
4778 // Re-create renderpass to have matching sample count
4779 attach_desc.samples = VK_SAMPLE_COUNT_1_BIT;
4780 err = vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
4781 ASSERT_VK_SUCCESS(err);
4782
4783 fb_info.renderPass = rp;
4784 fb_info.pAttachments = &view;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004785 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " has mip levelCount of 2 but only ");
Tobin Ehlis6cfda642016-06-22 16:12:58 -06004786 err = vkCreateFramebuffer(device(), &fb_info, NULL, &fb);
4787
4788 m_errorMonitor->VerifyFound();
4789 if (err == VK_SUCCESS) {
4790 vkDestroyFramebuffer(m_device->device(), fb, NULL);
4791 }
Tobin Ehlis6cfda642016-06-22 16:12:58 -06004792 vkDestroyImageView(m_device->device(), view, NULL);
Tobin Ehlis27f2ae82016-06-23 07:36:57 -06004793 // Update view to original color buffer and grow FB dimensions too big
4794 fb_info.pAttachments = ivs;
4795 fb_info.height = 1024;
4796 fb_info.width = 1024;
4797 fb_info.layers = 2;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004798 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " Attachment dimensions must be at "
4799 "least as large. ");
Tobin Ehlis27f2ae82016-06-23 07:36:57 -06004800 err = vkCreateFramebuffer(device(), &fb_info, NULL, &fb);
4801
4802 m_errorMonitor->VerifyFound();
4803 if (err == VK_SUCCESS) {
4804 vkDestroyFramebuffer(m_device->device(), fb, NULL);
4805 }
Tobin Ehlisb1f303b2016-06-23 08:19:55 -06004806 // Create view attachment with non-identity swizzle
4807 ivci.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
4808 ivci.image = image.handle();
4809 ivci.viewType = VK_IMAGE_VIEW_TYPE_2D;
4810 ivci.format = VK_FORMAT_B8G8R8A8_UNORM;
4811 ivci.subresourceRange.layerCount = 1;
4812 ivci.subresourceRange.baseMipLevel = 0;
4813 ivci.subresourceRange.levelCount = 1;
4814 ivci.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
4815 ivci.components.r = VK_COMPONENT_SWIZZLE_G;
4816 ivci.components.g = VK_COMPONENT_SWIZZLE_R;
4817 ivci.components.b = VK_COMPONENT_SWIZZLE_A;
4818 ivci.components.a = VK_COMPONENT_SWIZZLE_B;
4819 err = vkCreateImageView(m_device->device(), &ivci, NULL, &view);
4820 ASSERT_VK_SUCCESS(err);
4821
4822 fb_info.pAttachments = &view;
4823 fb_info.height = 100;
4824 fb_info.width = 100;
4825 fb_info.layers = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004826 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " has non-identy swizzle. All "
4827 "framebuffer attachments must have "
4828 "been created with the identity "
4829 "swizzle. ");
Tobin Ehlisb1f303b2016-06-23 08:19:55 -06004830 err = vkCreateFramebuffer(device(), &fb_info, NULL, &fb);
4831
4832 m_errorMonitor->VerifyFound();
4833 if (err == VK_SUCCESS) {
4834 vkDestroyFramebuffer(m_device->device(), fb, NULL);
4835 }
4836 vkDestroyImageView(m_device->device(), view, NULL);
Tobin Ehlis08d4b5e2016-06-23 08:52:39 -06004837 // Request fb that exceeds max dimensions
4838 // reset attachment to color attachment
4839 fb_info.pAttachments = ivs;
4840 fb_info.width = m_device->props.limits.maxFramebufferWidth + 1;
4841 fb_info.height = m_device->props.limits.maxFramebufferHeight + 1;
4842 fb_info.layers = m_device->props.limits.maxFramebufferLayers + 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004843 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " Requested VkFramebufferCreateInfo "
4844 "dimensions exceed physical device "
4845 "limits. ");
Tobin Ehlis08d4b5e2016-06-23 08:52:39 -06004846 err = vkCreateFramebuffer(device(), &fb_info, NULL, &fb);
4847
4848 m_errorMonitor->VerifyFound();
4849 if (err == VK_SUCCESS) {
4850 vkDestroyFramebuffer(m_device->device(), fb, NULL);
4851 }
Tobin Ehlis27f2ae82016-06-23 07:36:57 -06004852
Tobin Ehlis6cfda642016-06-22 16:12:58 -06004853 vkDestroyRenderPass(m_device->device(), rp, NULL);
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06004854}
4855
Mark Lobodzinskic808d442016-04-14 10:57:23 -06004856// This is a positive test. No errors should be generated.
Michael Lentine860b0fe2016-05-20 10:14:00 -05004857TEST_F(VkLayerTest, WaitEventThenSet) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004858 TEST_DESCRIPTION("Wait on a event then set it after the wait has been submitted.");
Michael Lentine860b0fe2016-05-20 10:14:00 -05004859
Michael Lentine860b0fe2016-05-20 10:14:00 -05004860 m_errorMonitor->ExpectSuccess();
Cody Northropc31a84f2016-08-22 10:41:47 -06004861 ASSERT_NO_FATAL_FAILURE(InitState());
Michael Lentine860b0fe2016-05-20 10:14:00 -05004862
4863 VkEvent event;
4864 VkEventCreateInfo event_create_info{};
4865 event_create_info.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO;
4866 vkCreateEvent(m_device->device(), &event_create_info, nullptr, &event);
4867
4868 VkCommandPool command_pool;
4869 VkCommandPoolCreateInfo pool_create_info{};
4870 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
4871 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
4872 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004873 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
Michael Lentine860b0fe2016-05-20 10:14:00 -05004874
4875 VkCommandBuffer command_buffer;
4876 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004877 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
Michael Lentine860b0fe2016-05-20 10:14:00 -05004878 command_buffer_allocate_info.commandPool = command_pool;
4879 command_buffer_allocate_info.commandBufferCount = 1;
4880 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004881 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, &command_buffer);
Michael Lentine860b0fe2016-05-20 10:14:00 -05004882
4883 VkQueue queue = VK_NULL_HANDLE;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004884 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 0, &queue);
Michael Lentine860b0fe2016-05-20 10:14:00 -05004885
4886 {
4887 VkCommandBufferBeginInfo begin_info{};
4888 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
4889 vkBeginCommandBuffer(command_buffer, &begin_info);
4890
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004891 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 -05004892 nullptr, 0, nullptr);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004893 vkCmdResetEvent(command_buffer, event, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT);
Michael Lentine860b0fe2016-05-20 10:14:00 -05004894 vkEndCommandBuffer(command_buffer);
4895 }
4896 {
4897 VkSubmitInfo submit_info{};
4898 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
4899 submit_info.commandBufferCount = 1;
4900 submit_info.pCommandBuffers = &command_buffer;
4901 submit_info.signalSemaphoreCount = 0;
4902 submit_info.pSignalSemaphores = nullptr;
4903 vkQueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE);
4904 }
4905 { vkSetEvent(m_device->device(), event); }
4906
4907 vkQueueWaitIdle(queue);
4908
4909 vkDestroyEvent(m_device->device(), event, nullptr);
4910 vkFreeCommandBuffers(m_device->device(), command_pool, 1, &command_buffer);
4911 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
4912
4913 m_errorMonitor->VerifyNotFound();
4914}
Michael Lentine5627e692016-05-20 17:45:02 -05004915// This is a positive test. No errors should be generated.
Michael Lentinef01fb382016-07-21 17:24:56 -05004916TEST_F(VkLayerTest, QueryAndCopySecondaryCommandBuffers) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004917 TEST_DESCRIPTION("Issue a query on a secondary command buffery and copy it on a primary.");
Michael Lentinef01fb382016-07-21 17:24:56 -05004918
Cody Northropc31a84f2016-08-22 10:41:47 -06004919 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004920 if ((m_device->queue_props.empty()) || (m_device->queue_props[0].queueCount < 2))
Michael Lentinef01fb382016-07-21 17:24:56 -05004921 return;
4922
4923 m_errorMonitor->ExpectSuccess();
4924
4925 VkQueryPool query_pool;
4926 VkQueryPoolCreateInfo query_pool_create_info{};
4927 query_pool_create_info.sType = VK_STRUCTURE_TYPE_QUERY_POOL_CREATE_INFO;
4928 query_pool_create_info.queryType = VK_QUERY_TYPE_TIMESTAMP;
4929 query_pool_create_info.queryCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004930 vkCreateQueryPool(m_device->device(), &query_pool_create_info, nullptr, &query_pool);
Michael Lentinef01fb382016-07-21 17:24:56 -05004931
4932 VkCommandPool command_pool;
4933 VkCommandPoolCreateInfo pool_create_info{};
4934 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
4935 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
4936 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004937 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
Michael Lentinef01fb382016-07-21 17:24:56 -05004938
4939 VkCommandBuffer command_buffer;
4940 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004941 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
Michael Lentinef01fb382016-07-21 17:24:56 -05004942 command_buffer_allocate_info.commandPool = command_pool;
4943 command_buffer_allocate_info.commandBufferCount = 1;
4944 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004945 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, &command_buffer);
Michael Lentinef01fb382016-07-21 17:24:56 -05004946
4947 VkCommandBuffer secondary_command_buffer;
4948 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_SECONDARY;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004949 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, &secondary_command_buffer);
Michael Lentinef01fb382016-07-21 17:24:56 -05004950
4951 VkQueue queue = VK_NULL_HANDLE;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004952 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 1, &queue);
Michael Lentinef01fb382016-07-21 17:24:56 -05004953
4954 uint32_t qfi = 0;
4955 VkBufferCreateInfo buff_create_info = {};
4956 buff_create_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
4957 buff_create_info.size = 1024;
4958 buff_create_info.usage = VK_BUFFER_USAGE_TRANSFER_DST_BIT;
4959 buff_create_info.queueFamilyIndexCount = 1;
4960 buff_create_info.pQueueFamilyIndices = &qfi;
4961
4962 VkResult err;
4963 VkBuffer buffer;
4964 err = vkCreateBuffer(m_device->device(), &buff_create_info, NULL, &buffer);
4965 ASSERT_VK_SUCCESS(err);
4966 VkMemoryAllocateInfo mem_alloc = {};
4967 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
4968 mem_alloc.pNext = NULL;
4969 mem_alloc.allocationSize = 1024;
4970 mem_alloc.memoryTypeIndex = 0;
4971
4972 VkMemoryRequirements memReqs;
4973 vkGetBufferMemoryRequirements(m_device->device(), buffer, &memReqs);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004974 bool pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &mem_alloc, 0);
Michael Lentinef01fb382016-07-21 17:24:56 -05004975 if (!pass) {
4976 vkDestroyBuffer(m_device->device(), buffer, NULL);
4977 return;
4978 }
4979
4980 VkDeviceMemory mem;
4981 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem);
4982 ASSERT_VK_SUCCESS(err);
4983 err = vkBindBufferMemory(m_device->device(), buffer, mem, 0);
4984 ASSERT_VK_SUCCESS(err);
4985
4986 VkCommandBufferInheritanceInfo hinfo = {};
4987 hinfo.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_INHERITANCE_INFO;
4988 hinfo.renderPass = VK_NULL_HANDLE;
4989 hinfo.subpass = 0;
4990 hinfo.framebuffer = VK_NULL_HANDLE;
4991 hinfo.occlusionQueryEnable = VK_FALSE;
4992 hinfo.queryFlags = 0;
4993 hinfo.pipelineStatistics = 0;
4994
4995 {
4996 VkCommandBufferBeginInfo begin_info{};
4997 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
4998 begin_info.pInheritanceInfo = &hinfo;
4999 vkBeginCommandBuffer(secondary_command_buffer, &begin_info);
5000
5001 vkCmdResetQueryPool(secondary_command_buffer, query_pool, 0, 1);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005002 vkCmdWriteTimestamp(secondary_command_buffer, VK_PIPELINE_STAGE_ALL_GRAPHICS_BIT, query_pool, 0);
Michael Lentinef01fb382016-07-21 17:24:56 -05005003
5004 vkEndCommandBuffer(secondary_command_buffer);
5005
5006 begin_info.pInheritanceInfo = nullptr;
5007 vkBeginCommandBuffer(command_buffer, &begin_info);
5008
5009 vkCmdExecuteCommands(command_buffer, 1, &secondary_command_buffer);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005010 vkCmdCopyQueryPoolResults(command_buffer, query_pool, 0, 1, buffer, 0, 0, 0);
Michael Lentinef01fb382016-07-21 17:24:56 -05005011
5012 vkEndCommandBuffer(command_buffer);
5013 }
5014 {
5015 VkSubmitInfo submit_info{};
5016 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
5017 submit_info.commandBufferCount = 1;
5018 submit_info.pCommandBuffers = &command_buffer;
5019 submit_info.signalSemaphoreCount = 0;
5020 submit_info.pSignalSemaphores = nullptr;
5021 vkQueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE);
5022 }
5023
5024 vkQueueWaitIdle(queue);
5025
5026 vkDestroyQueryPool(m_device->device(), query_pool, nullptr);
5027 vkFreeCommandBuffers(m_device->device(), command_pool, 1, &command_buffer);
5028 vkFreeCommandBuffers(m_device->device(), command_pool, 1, &secondary_command_buffer);
5029 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
5030 vkDestroyBuffer(m_device->device(), buffer, NULL);
5031 vkFreeMemory(m_device->device(), mem, NULL);
5032
5033 m_errorMonitor->VerifyNotFound();
5034}
5035
5036// This is a positive test. No errors should be generated.
Michael Lentine5627e692016-05-20 17:45:02 -05005037TEST_F(VkLayerTest, QueryAndCopyMultipleCommandBuffers) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005038 TEST_DESCRIPTION("Issue a query and copy from it on a second command buffer.");
Michael Lentine5627e692016-05-20 17:45:02 -05005039
Cody Northropc31a84f2016-08-22 10:41:47 -06005040 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005041 if ((m_device->queue_props.empty()) || (m_device->queue_props[0].queueCount < 2))
Michael Lentine5627e692016-05-20 17:45:02 -05005042 return;
5043
5044 m_errorMonitor->ExpectSuccess();
5045
5046 VkQueryPool query_pool;
5047 VkQueryPoolCreateInfo query_pool_create_info{};
5048 query_pool_create_info.sType = VK_STRUCTURE_TYPE_QUERY_POOL_CREATE_INFO;
5049 query_pool_create_info.queryType = VK_QUERY_TYPE_TIMESTAMP;
5050 query_pool_create_info.queryCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005051 vkCreateQueryPool(m_device->device(), &query_pool_create_info, nullptr, &query_pool);
Michael Lentine5627e692016-05-20 17:45:02 -05005052
5053 VkCommandPool command_pool;
5054 VkCommandPoolCreateInfo pool_create_info{};
5055 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
5056 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
5057 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005058 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
Michael Lentine5627e692016-05-20 17:45:02 -05005059
5060 VkCommandBuffer command_buffer[2];
5061 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005062 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
Michael Lentine5627e692016-05-20 17:45:02 -05005063 command_buffer_allocate_info.commandPool = command_pool;
5064 command_buffer_allocate_info.commandBufferCount = 2;
5065 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005066 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, command_buffer);
Michael Lentine5627e692016-05-20 17:45:02 -05005067
5068 VkQueue queue = VK_NULL_HANDLE;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005069 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 1, &queue);
Michael Lentine5627e692016-05-20 17:45:02 -05005070
5071 uint32_t qfi = 0;
5072 VkBufferCreateInfo buff_create_info = {};
5073 buff_create_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
5074 buff_create_info.size = 1024;
5075 buff_create_info.usage = VK_BUFFER_USAGE_TRANSFER_DST_BIT;
5076 buff_create_info.queueFamilyIndexCount = 1;
5077 buff_create_info.pQueueFamilyIndices = &qfi;
5078
5079 VkResult err;
5080 VkBuffer buffer;
5081 err = vkCreateBuffer(m_device->device(), &buff_create_info, NULL, &buffer);
5082 ASSERT_VK_SUCCESS(err);
5083 VkMemoryAllocateInfo mem_alloc = {};
5084 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
5085 mem_alloc.pNext = NULL;
5086 mem_alloc.allocationSize = 1024;
5087 mem_alloc.memoryTypeIndex = 0;
5088
5089 VkMemoryRequirements memReqs;
5090 vkGetBufferMemoryRequirements(m_device->device(), buffer, &memReqs);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005091 bool pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &mem_alloc, 0);
Michael Lentine5627e692016-05-20 17:45:02 -05005092 if (!pass) {
5093 vkDestroyBuffer(m_device->device(), buffer, NULL);
5094 return;
5095 }
5096
5097 VkDeviceMemory mem;
5098 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem);
5099 ASSERT_VK_SUCCESS(err);
5100 err = vkBindBufferMemory(m_device->device(), buffer, mem, 0);
5101 ASSERT_VK_SUCCESS(err);
5102
5103 {
5104 VkCommandBufferBeginInfo begin_info{};
5105 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
5106 vkBeginCommandBuffer(command_buffer[0], &begin_info);
5107
5108 vkCmdResetQueryPool(command_buffer[0], query_pool, 0, 1);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005109 vkCmdWriteTimestamp(command_buffer[0], VK_PIPELINE_STAGE_ALL_GRAPHICS_BIT, query_pool, 0);
Michael Lentine5627e692016-05-20 17:45:02 -05005110
5111 vkEndCommandBuffer(command_buffer[0]);
5112
5113 vkBeginCommandBuffer(command_buffer[1], &begin_info);
5114
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005115 vkCmdCopyQueryPoolResults(command_buffer[1], query_pool, 0, 1, buffer, 0, 0, 0);
Michael Lentine5627e692016-05-20 17:45:02 -05005116
5117 vkEndCommandBuffer(command_buffer[1]);
5118 }
5119 {
5120 VkSubmitInfo submit_info{};
5121 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
5122 submit_info.commandBufferCount = 2;
5123 submit_info.pCommandBuffers = command_buffer;
5124 submit_info.signalSemaphoreCount = 0;
5125 submit_info.pSignalSemaphores = nullptr;
5126 vkQueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE);
5127 }
5128
5129 vkQueueWaitIdle(queue);
5130
5131 vkDestroyQueryPool(m_device->device(), query_pool, nullptr);
5132 vkFreeCommandBuffers(m_device->device(), command_pool, 2, command_buffer);
5133 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
Tony Barbourdf4c0042016-06-01 15:55:43 -06005134 vkDestroyBuffer(m_device->device(), buffer, NULL);
5135 vkFreeMemory(m_device->device(), mem, NULL);
Michael Lentine5627e692016-05-20 17:45:02 -05005136
5137 m_errorMonitor->VerifyNotFound();
5138}
Michael Lentine860b0fe2016-05-20 10:14:00 -05005139
5140TEST_F(VkLayerTest, ResetEventThenSet) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005141 TEST_DESCRIPTION("Reset an event then set it after the reset has been submitted.");
Michael Lentine860b0fe2016-05-20 10:14:00 -05005142
Michael Lentine860b0fe2016-05-20 10:14:00 -05005143 m_errorMonitor->ExpectSuccess();
5144
Cody Northropc31a84f2016-08-22 10:41:47 -06005145 ASSERT_NO_FATAL_FAILURE(InitState());
Michael Lentine860b0fe2016-05-20 10:14:00 -05005146 VkEvent event;
5147 VkEventCreateInfo event_create_info{};
5148 event_create_info.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO;
5149 vkCreateEvent(m_device->device(), &event_create_info, nullptr, &event);
5150
5151 VkCommandPool command_pool;
5152 VkCommandPoolCreateInfo pool_create_info{};
5153 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
5154 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
5155 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005156 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
Michael Lentine860b0fe2016-05-20 10:14:00 -05005157
5158 VkCommandBuffer command_buffer;
5159 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005160 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
Michael Lentine860b0fe2016-05-20 10:14:00 -05005161 command_buffer_allocate_info.commandPool = command_pool;
5162 command_buffer_allocate_info.commandBufferCount = 1;
5163 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005164 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, &command_buffer);
Michael Lentine860b0fe2016-05-20 10:14:00 -05005165
5166 VkQueue queue = VK_NULL_HANDLE;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005167 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 0, &queue);
Michael Lentine860b0fe2016-05-20 10:14:00 -05005168
5169 {
5170 VkCommandBufferBeginInfo begin_info{};
5171 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
5172 vkBeginCommandBuffer(command_buffer, &begin_info);
5173
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005174 vkCmdResetEvent(command_buffer, event, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT);
5175 vkCmdWaitEvents(command_buffer, 1, &event, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0,
5176 nullptr, 0, nullptr, 0, nullptr);
Michael Lentine860b0fe2016-05-20 10:14:00 -05005177 vkEndCommandBuffer(command_buffer);
5178 }
5179 {
5180 VkSubmitInfo submit_info{};
5181 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
5182 submit_info.commandBufferCount = 1;
5183 submit_info.pCommandBuffers = &command_buffer;
5184 submit_info.signalSemaphoreCount = 0;
5185 submit_info.pSignalSemaphores = nullptr;
5186 vkQueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE);
5187 }
5188 {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005189 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "that is already in use by a "
5190 "command buffer.");
Michael Lentine860b0fe2016-05-20 10:14:00 -05005191 vkSetEvent(m_device->device(), event);
5192 m_errorMonitor->VerifyFound();
5193 }
5194
5195 vkQueueWaitIdle(queue);
5196
5197 vkDestroyEvent(m_device->device(), event, nullptr);
5198 vkFreeCommandBuffers(m_device->device(), command_pool, 1, &command_buffer);
5199 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
5200}
5201
5202// This is a positive test. No errors should be generated.
Tobin Ehlis0bb263b2016-05-10 12:13:02 -06005203TEST_F(VkLayerTest, TwoFencesThreeFrames) {
5204 TEST_DESCRIPTION("Two command buffers with two separate fences are each "
5205 "run through a Submit & WaitForFences cycle 3 times. This "
5206 "previously revealed a bug so running this positive test "
5207 "to prevent a regression.");
5208 m_errorMonitor->ExpectSuccess();
5209
5210 ASSERT_NO_FATAL_FAILURE(InitState());
5211 VkQueue queue = VK_NULL_HANDLE;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005212 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 0, &queue);
Tobin Ehlis0bb263b2016-05-10 12:13:02 -06005213
5214 static const uint32_t NUM_OBJECTS = 2;
5215 static const uint32_t NUM_FRAMES = 3;
5216 VkCommandBuffer cmd_buffers[NUM_OBJECTS] = {};
5217 VkFence fences[NUM_OBJECTS] = {};
5218
5219 VkCommandPool cmd_pool;
5220 VkCommandPoolCreateInfo cmd_pool_ci = {};
5221 cmd_pool_ci.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
5222 cmd_pool_ci.queueFamilyIndex = m_device->graphics_queue_node_index_;
5223 cmd_pool_ci.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005224 VkResult err = vkCreateCommandPool(m_device->device(), &cmd_pool_ci, nullptr, &cmd_pool);
Tobin Ehlis0bb263b2016-05-10 12:13:02 -06005225 ASSERT_VK_SUCCESS(err);
5226
5227 VkCommandBufferAllocateInfo cmd_buf_info = {};
5228 cmd_buf_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
5229 cmd_buf_info.commandPool = cmd_pool;
5230 cmd_buf_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
5231 cmd_buf_info.commandBufferCount = 1;
5232
5233 VkFenceCreateInfo fence_ci = {};
5234 fence_ci.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
5235 fence_ci.pNext = nullptr;
5236 fence_ci.flags = 0;
5237
5238 for (uint32_t i = 0; i < NUM_OBJECTS; ++i) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005239 err = vkAllocateCommandBuffers(m_device->device(), &cmd_buf_info, &cmd_buffers[i]);
Tobin Ehlis0bb263b2016-05-10 12:13:02 -06005240 ASSERT_VK_SUCCESS(err);
5241 err = vkCreateFence(m_device->device(), &fence_ci, nullptr, &fences[i]);
5242 ASSERT_VK_SUCCESS(err);
5243 }
5244
5245 for (uint32_t frame = 0; frame < NUM_FRAMES; ++frame) {
Tobin Ehlisf9025162016-05-26 06:55:21 -06005246 for (uint32_t obj = 0; obj < NUM_OBJECTS; ++obj) {
5247 // Create empty cmd buffer
5248 VkCommandBufferBeginInfo cmdBufBeginDesc = {};
5249 cmdBufBeginDesc.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
Tobin Ehlis0bb263b2016-05-10 12:13:02 -06005250
Tobin Ehlisf9025162016-05-26 06:55:21 -06005251 err = vkBeginCommandBuffer(cmd_buffers[obj], &cmdBufBeginDesc);
5252 ASSERT_VK_SUCCESS(err);
5253 err = vkEndCommandBuffer(cmd_buffers[obj]);
5254 ASSERT_VK_SUCCESS(err);
Tobin Ehlis0bb263b2016-05-10 12:13:02 -06005255
Tobin Ehlisf9025162016-05-26 06:55:21 -06005256 VkSubmitInfo submit_info = {};
5257 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
5258 submit_info.commandBufferCount = 1;
5259 submit_info.pCommandBuffers = &cmd_buffers[obj];
5260 // Submit cmd buffer and wait for fence
5261 err = vkQueueSubmit(queue, 1, &submit_info, fences[obj]);
5262 ASSERT_VK_SUCCESS(err);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005263 err = vkWaitForFences(m_device->device(), 1, &fences[obj], VK_TRUE, UINT64_MAX);
Tobin Ehlisf9025162016-05-26 06:55:21 -06005264 ASSERT_VK_SUCCESS(err);
5265 err = vkResetFences(m_device->device(), 1, &fences[obj]);
5266 ASSERT_VK_SUCCESS(err);
5267 }
Tobin Ehlis0bb263b2016-05-10 12:13:02 -06005268 }
5269 m_errorMonitor->VerifyNotFound();
Tony Barbourdf4c0042016-06-01 15:55:43 -06005270 vkDestroyCommandPool(m_device->device(), cmd_pool, NULL);
5271 for (uint32_t i = 0; i < NUM_OBJECTS; ++i) {
5272 vkDestroyFence(m_device->device(), fences[i], nullptr);
5273 }
Tobin Ehlis0bb263b2016-05-10 12:13:02 -06005274}
5275// This is a positive test. No errors should be generated.
Mark Lobodzinskic808d442016-04-14 10:57:23 -06005276TEST_F(VkLayerTest, TwoQueueSubmitsSeparateQueuesWithSemaphoreAndOneFenceQWI) {
5277
5278 TEST_DESCRIPTION("Two command buffers, each in a separate QueueSubmit call "
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005279 "submitted on separate queues followed by a QueueWaitIdle.");
Mark Lobodzinskic808d442016-04-14 10:57:23 -06005280
Cody Northropc31a84f2016-08-22 10:41:47 -06005281 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005282 if ((m_device->queue_props.empty()) || (m_device->queue_props[0].queueCount < 2))
Tony Barbourdc18b262016-04-22 14:49:48 -06005283 return;
5284
Mark Lobodzinskic808d442016-04-14 10:57:23 -06005285 m_errorMonitor->ExpectSuccess();
5286
5287 VkSemaphore semaphore;
5288 VkSemaphoreCreateInfo semaphore_create_info{};
5289 semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005290 vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr, &semaphore);
Mark Lobodzinskic808d442016-04-14 10:57:23 -06005291
5292 VkCommandPool command_pool;
5293 VkCommandPoolCreateInfo pool_create_info{};
5294 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
5295 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
5296 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005297 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
Mark Lobodzinskic808d442016-04-14 10:57:23 -06005298
5299 VkCommandBuffer command_buffer[2];
5300 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005301 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
Mark Lobodzinskic808d442016-04-14 10:57:23 -06005302 command_buffer_allocate_info.commandPool = command_pool;
5303 command_buffer_allocate_info.commandBufferCount = 2;
5304 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005305 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, command_buffer);
Mark Lobodzinskic808d442016-04-14 10:57:23 -06005306
5307 VkQueue queue = VK_NULL_HANDLE;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005308 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 1, &queue);
Mark Lobodzinskic808d442016-04-14 10:57:23 -06005309
5310 {
5311 VkCommandBufferBeginInfo begin_info{};
5312 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
5313 vkBeginCommandBuffer(command_buffer[0], &begin_info);
5314
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005315 vkCmdPipelineBarrier(command_buffer[0], VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0,
5316 nullptr, 0, nullptr, 0, nullptr);
Mark Lobodzinskic808d442016-04-14 10:57:23 -06005317
5318 VkViewport viewport{};
5319 viewport.maxDepth = 1.0f;
5320 viewport.minDepth = 0.0f;
5321 viewport.width = 512;
5322 viewport.height = 512;
5323 viewport.x = 0;
5324 viewport.y = 0;
5325 vkCmdSetViewport(command_buffer[0], 0, 1, &viewport);
5326 vkEndCommandBuffer(command_buffer[0]);
5327 }
5328 {
5329 VkCommandBufferBeginInfo begin_info{};
5330 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
5331 vkBeginCommandBuffer(command_buffer[1], &begin_info);
5332
5333 VkViewport viewport{};
5334 viewport.maxDepth = 1.0f;
5335 viewport.minDepth = 0.0f;
5336 viewport.width = 512;
5337 viewport.height = 512;
5338 viewport.x = 0;
5339 viewport.y = 0;
5340 vkCmdSetViewport(command_buffer[1], 0, 1, &viewport);
5341 vkEndCommandBuffer(command_buffer[1]);
5342 }
5343 {
5344 VkSubmitInfo submit_info{};
5345 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
5346 submit_info.commandBufferCount = 1;
5347 submit_info.pCommandBuffers = &command_buffer[0];
5348 submit_info.signalSemaphoreCount = 1;
5349 submit_info.pSignalSemaphores = &semaphore;
5350 vkQueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE);
5351 }
5352 {
5353 VkPipelineStageFlags flags[]{VK_PIPELINE_STAGE_ALL_COMMANDS_BIT};
5354 VkSubmitInfo submit_info{};
5355 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
5356 submit_info.commandBufferCount = 1;
5357 submit_info.pCommandBuffers = &command_buffer[1];
5358 submit_info.waitSemaphoreCount = 1;
5359 submit_info.pWaitSemaphores = &semaphore;
5360 submit_info.pWaitDstStageMask = flags;
5361 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
5362 }
5363
5364 vkQueueWaitIdle(m_device->m_queue);
5365
5366 vkDestroySemaphore(m_device->device(), semaphore, nullptr);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005367 vkFreeCommandBuffers(m_device->device(), command_pool, 2, &command_buffer[0]);
Mark Lobodzinskic808d442016-04-14 10:57:23 -06005368 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
5369
5370 m_errorMonitor->VerifyNotFound();
5371}
5372
5373// This is a positive test. No errors should be generated.
5374TEST_F(VkLayerTest, TwoQueueSubmitsSeparateQueuesWithSemaphoreAndOneFenceQWIFence) {
5375
5376 TEST_DESCRIPTION("Two command buffers, each in a separate QueueSubmit call "
5377 "submitted on separate queues, the second having a fence"
5378 "followed by a QueueWaitIdle.");
5379
Cody Northropc31a84f2016-08-22 10:41:47 -06005380 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005381 if ((m_device->queue_props.empty()) || (m_device->queue_props[0].queueCount < 2))
Tony Barbourdc18b262016-04-22 14:49:48 -06005382 return;
5383
Mark Lobodzinskic808d442016-04-14 10:57:23 -06005384 m_errorMonitor->ExpectSuccess();
5385
5386 VkFence fence;
5387 VkFenceCreateInfo fence_create_info{};
5388 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
5389 vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence);
5390
5391 VkSemaphore semaphore;
5392 VkSemaphoreCreateInfo semaphore_create_info{};
5393 semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005394 vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr, &semaphore);
Mark Lobodzinskic808d442016-04-14 10:57:23 -06005395
5396 VkCommandPool command_pool;
5397 VkCommandPoolCreateInfo pool_create_info{};
5398 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
5399 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
5400 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005401 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
Mark Lobodzinskic808d442016-04-14 10:57:23 -06005402
5403 VkCommandBuffer command_buffer[2];
5404 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005405 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
Mark Lobodzinskic808d442016-04-14 10:57:23 -06005406 command_buffer_allocate_info.commandPool = command_pool;
5407 command_buffer_allocate_info.commandBufferCount = 2;
5408 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005409 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, command_buffer);
Mark Lobodzinskic808d442016-04-14 10:57:23 -06005410
5411 VkQueue queue = VK_NULL_HANDLE;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005412 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 1, &queue);
Mark Lobodzinskic808d442016-04-14 10:57:23 -06005413
5414 {
5415 VkCommandBufferBeginInfo begin_info{};
5416 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
5417 vkBeginCommandBuffer(command_buffer[0], &begin_info);
5418
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005419 vkCmdPipelineBarrier(command_buffer[0], VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0,
5420 nullptr, 0, nullptr, 0, nullptr);
Mark Lobodzinskic808d442016-04-14 10:57:23 -06005421
5422 VkViewport viewport{};
5423 viewport.maxDepth = 1.0f;
5424 viewport.minDepth = 0.0f;
5425 viewport.width = 512;
5426 viewport.height = 512;
5427 viewport.x = 0;
5428 viewport.y = 0;
5429 vkCmdSetViewport(command_buffer[0], 0, 1, &viewport);
5430 vkEndCommandBuffer(command_buffer[0]);
5431 }
5432 {
5433 VkCommandBufferBeginInfo begin_info{};
5434 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
5435 vkBeginCommandBuffer(command_buffer[1], &begin_info);
5436
5437 VkViewport viewport{};
5438 viewport.maxDepth = 1.0f;
5439 viewport.minDepth = 0.0f;
5440 viewport.width = 512;
5441 viewport.height = 512;
5442 viewport.x = 0;
5443 viewport.y = 0;
5444 vkCmdSetViewport(command_buffer[1], 0, 1, &viewport);
5445 vkEndCommandBuffer(command_buffer[1]);
5446 }
5447 {
5448 VkSubmitInfo submit_info{};
5449 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
5450 submit_info.commandBufferCount = 1;
5451 submit_info.pCommandBuffers = &command_buffer[0];
5452 submit_info.signalSemaphoreCount = 1;
5453 submit_info.pSignalSemaphores = &semaphore;
5454 vkQueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE);
5455 }
5456 {
5457 VkPipelineStageFlags flags[]{VK_PIPELINE_STAGE_ALL_COMMANDS_BIT};
5458 VkSubmitInfo submit_info{};
5459 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
5460 submit_info.commandBufferCount = 1;
5461 submit_info.pCommandBuffers = &command_buffer[1];
5462 submit_info.waitSemaphoreCount = 1;
5463 submit_info.pWaitSemaphores = &semaphore;
5464 submit_info.pWaitDstStageMask = flags;
5465 vkQueueSubmit(m_device->m_queue, 1, &submit_info, fence);
5466 }
5467
5468 vkQueueWaitIdle(m_device->m_queue);
5469
5470 vkDestroyFence(m_device->device(), fence, nullptr);
5471 vkDestroySemaphore(m_device->device(), semaphore, nullptr);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005472 vkFreeCommandBuffers(m_device->device(), command_pool, 2, &command_buffer[0]);
Mark Lobodzinskic808d442016-04-14 10:57:23 -06005473 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
5474
5475 m_errorMonitor->VerifyNotFound();
5476}
5477
5478// This is a positive test. No errors should be generated.
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005479TEST_F(VkLayerTest, TwoQueueSubmitsSeparateQueuesWithSemaphoreAndOneFenceTwoWFF) {
Mark Lobodzinskic808d442016-04-14 10:57:23 -06005480
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005481 TEST_DESCRIPTION("Two command buffers, each in a separate QueueSubmit call "
5482 "submitted on separate queues, the second having a fence"
5483 "followed by two consecutive WaitForFences calls on the same fence.");
Mark Lobodzinskic808d442016-04-14 10:57:23 -06005484
Cody Northropc31a84f2016-08-22 10:41:47 -06005485 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005486 if ((m_device->queue_props.empty()) || (m_device->queue_props[0].queueCount < 2))
Tony Barbourdc18b262016-04-22 14:49:48 -06005487 return;
5488
Mark Lobodzinskic808d442016-04-14 10:57:23 -06005489 m_errorMonitor->ExpectSuccess();
5490
5491 VkFence fence;
5492 VkFenceCreateInfo fence_create_info{};
5493 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
5494 vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence);
5495
5496 VkSemaphore semaphore;
5497 VkSemaphoreCreateInfo semaphore_create_info{};
5498 semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005499 vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr, &semaphore);
Mark Lobodzinskic808d442016-04-14 10:57:23 -06005500
5501 VkCommandPool command_pool;
5502 VkCommandPoolCreateInfo pool_create_info{};
5503 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
5504 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
5505 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005506 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
Mark Lobodzinskic808d442016-04-14 10:57:23 -06005507
5508 VkCommandBuffer command_buffer[2];
5509 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005510 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
Mark Lobodzinskic808d442016-04-14 10:57:23 -06005511 command_buffer_allocate_info.commandPool = command_pool;
5512 command_buffer_allocate_info.commandBufferCount = 2;
5513 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005514 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, command_buffer);
Mark Lobodzinskic808d442016-04-14 10:57:23 -06005515
5516 VkQueue queue = VK_NULL_HANDLE;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005517 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 1, &queue);
Mark Lobodzinskic808d442016-04-14 10:57:23 -06005518
5519 {
5520 VkCommandBufferBeginInfo begin_info{};
5521 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
5522 vkBeginCommandBuffer(command_buffer[0], &begin_info);
5523
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005524 vkCmdPipelineBarrier(command_buffer[0], VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0,
5525 nullptr, 0, nullptr, 0, nullptr);
Mark Lobodzinskic808d442016-04-14 10:57:23 -06005526
5527 VkViewport viewport{};
5528 viewport.maxDepth = 1.0f;
5529 viewport.minDepth = 0.0f;
5530 viewport.width = 512;
5531 viewport.height = 512;
5532 viewport.x = 0;
5533 viewport.y = 0;
5534 vkCmdSetViewport(command_buffer[0], 0, 1, &viewport);
5535 vkEndCommandBuffer(command_buffer[0]);
5536 }
5537 {
5538 VkCommandBufferBeginInfo begin_info{};
5539 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
5540 vkBeginCommandBuffer(command_buffer[1], &begin_info);
5541
5542 VkViewport viewport{};
5543 viewport.maxDepth = 1.0f;
5544 viewport.minDepth = 0.0f;
5545 viewport.width = 512;
5546 viewport.height = 512;
5547 viewport.x = 0;
5548 viewport.y = 0;
5549 vkCmdSetViewport(command_buffer[1], 0, 1, &viewport);
5550 vkEndCommandBuffer(command_buffer[1]);
5551 }
5552 {
5553 VkSubmitInfo submit_info{};
5554 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
5555 submit_info.commandBufferCount = 1;
5556 submit_info.pCommandBuffers = &command_buffer[0];
5557 submit_info.signalSemaphoreCount = 1;
5558 submit_info.pSignalSemaphores = &semaphore;
5559 vkQueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE);
5560 }
5561 {
5562 VkPipelineStageFlags flags[]{VK_PIPELINE_STAGE_ALL_COMMANDS_BIT};
5563 VkSubmitInfo submit_info{};
5564 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
5565 submit_info.commandBufferCount = 1;
5566 submit_info.pCommandBuffers = &command_buffer[1];
5567 submit_info.waitSemaphoreCount = 1;
5568 submit_info.pWaitSemaphores = &semaphore;
5569 submit_info.pWaitDstStageMask = flags;
5570 vkQueueSubmit(m_device->m_queue, 1, &submit_info, fence);
5571 }
5572
5573 vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
5574 vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
5575
5576 vkDestroyFence(m_device->device(), fence, nullptr);
5577 vkDestroySemaphore(m_device->device(), semaphore, nullptr);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005578 vkFreeCommandBuffers(m_device->device(), command_pool, 2, &command_buffer[0]);
Mark Lobodzinskic808d442016-04-14 10:57:23 -06005579 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
5580
5581 m_errorMonitor->VerifyNotFound();
5582}
5583
Chris Forbes0f8126b2016-06-20 17:48:22 +12005584TEST_F(VkLayerTest, TwoQueuesEnsureCorrectRetirementWithWorkStolen) {
Cody Northropc31a84f2016-08-22 10:41:47 -06005585
5586 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005587 if ((m_device->queue_props.empty()) || (m_device->queue_props[0].queueCount < 2)) {
Chris Forbes0f8126b2016-06-20 17:48:22 +12005588 printf("Test requires two queues, skipping\n");
5589 return;
5590 }
5591
5592 VkResult err;
5593
5594 m_errorMonitor->ExpectSuccess();
5595
5596 VkQueue q0 = m_device->m_queue;
5597 VkQueue q1 = nullptr;
5598 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 1, &q1);
5599 ASSERT_NE(q1, nullptr);
5600
5601 // An (empty) command buffer. We must have work in the first submission --
5602 // the layer treats unfenced work differently from fenced work.
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005603 VkCommandPoolCreateInfo cpci = {VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO, nullptr, 0, 0};
Chris Forbes0f8126b2016-06-20 17:48:22 +12005604 VkCommandPool pool;
5605 err = vkCreateCommandPool(m_device->device(), &cpci, nullptr, &pool);
5606 ASSERT_VK_SUCCESS(err);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005607 VkCommandBufferAllocateInfo cbai = {VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO, nullptr, pool,
5608 VK_COMMAND_BUFFER_LEVEL_PRIMARY, 1};
Chris Forbes0f8126b2016-06-20 17:48:22 +12005609 VkCommandBuffer cb;
5610 err = vkAllocateCommandBuffers(m_device->device(), &cbai, &cb);
5611 ASSERT_VK_SUCCESS(err);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005612 VkCommandBufferBeginInfo cbbi = {VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO, nullptr, 0, nullptr};
Chris Forbes0f8126b2016-06-20 17:48:22 +12005613 err = vkBeginCommandBuffer(cb, &cbbi);
5614 ASSERT_VK_SUCCESS(err);
5615 err = vkEndCommandBuffer(cb);
5616 ASSERT_VK_SUCCESS(err);
5617
5618 // A semaphore
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005619 VkSemaphoreCreateInfo sci = {VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO, nullptr, 0};
Chris Forbes0f8126b2016-06-20 17:48:22 +12005620 VkSemaphore s;
5621 err = vkCreateSemaphore(m_device->device(), &sci, nullptr, &s);
5622 ASSERT_VK_SUCCESS(err);
5623
5624 // First submission, to q0
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005625 VkSubmitInfo s0 = {VK_STRUCTURE_TYPE_SUBMIT_INFO, nullptr, 0, nullptr, nullptr, 1, &cb, 1, &s};
Chris Forbes0f8126b2016-06-20 17:48:22 +12005626
5627 err = vkQueueSubmit(q0, 1, &s0, VK_NULL_HANDLE);
5628 ASSERT_VK_SUCCESS(err);
5629
5630 // Second submission, to q1, waiting on s
5631 VkFlags waitmask = VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT; // doesn't really matter what this value is.
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005632 VkSubmitInfo s1 = {VK_STRUCTURE_TYPE_SUBMIT_INFO, nullptr, 1, &s, &waitmask, 0, nullptr, 0, nullptr};
Chris Forbes0f8126b2016-06-20 17:48:22 +12005633
5634 err = vkQueueSubmit(q1, 1, &s1, VK_NULL_HANDLE);
5635 ASSERT_VK_SUCCESS(err);
5636
5637 // Wait for q0 idle
5638 err = vkQueueWaitIdle(q0);
5639 ASSERT_VK_SUCCESS(err);
5640
5641 // Command buffer should have been completed (it was on q0); reset the pool.
5642 vkFreeCommandBuffers(m_device->device(), pool, 1, &cb);
5643
5644 m_errorMonitor->VerifyNotFound();
5645
5646 // Force device completely idle and clean up resources
5647 vkDeviceWaitIdle(m_device->device());
5648 vkDestroyCommandPool(m_device->device(), pool, nullptr);
5649 vkDestroySemaphore(m_device->device(), s, nullptr);
5650}
Chris Forbes0f8126b2016-06-20 17:48:22 +12005651
Mark Lobodzinskic808d442016-04-14 10:57:23 -06005652// This is a positive test. No errors should be generated.
5653TEST_F(VkLayerTest, TwoQueueSubmitsSeparateQueuesWithSemaphoreAndOneFence) {
5654
5655 TEST_DESCRIPTION("Two command buffers, each in a separate QueueSubmit call "
5656 "submitted on separate queues, the second having a fence, "
5657 "followed by a WaitForFences call.");
5658
Cody Northropc31a84f2016-08-22 10:41:47 -06005659 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005660 if ((m_device->queue_props.empty()) || (m_device->queue_props[0].queueCount < 2))
Tony Barbourdc18b262016-04-22 14:49:48 -06005661 return;
5662
Mark Lobodzinskic808d442016-04-14 10:57:23 -06005663 m_errorMonitor->ExpectSuccess();
5664
Cody Northropc31a84f2016-08-22 10:41:47 -06005665 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinskic808d442016-04-14 10:57:23 -06005666 VkFence fence;
5667 VkFenceCreateInfo fence_create_info{};
5668 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
5669 vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence);
5670
5671 VkSemaphore semaphore;
5672 VkSemaphoreCreateInfo semaphore_create_info{};
5673 semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005674 vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr, &semaphore);
Mark Lobodzinskic808d442016-04-14 10:57:23 -06005675
5676 VkCommandPool command_pool;
5677 VkCommandPoolCreateInfo pool_create_info{};
5678 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
5679 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
5680 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005681 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
Mark Lobodzinskic808d442016-04-14 10:57:23 -06005682
5683 VkCommandBuffer command_buffer[2];
5684 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005685 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
Mark Lobodzinskic808d442016-04-14 10:57:23 -06005686 command_buffer_allocate_info.commandPool = command_pool;
5687 command_buffer_allocate_info.commandBufferCount = 2;
5688 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005689 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, command_buffer);
Mark Lobodzinskic808d442016-04-14 10:57:23 -06005690
5691 VkQueue queue = VK_NULL_HANDLE;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005692 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 1, &queue);
Mark Lobodzinskic808d442016-04-14 10:57:23 -06005693
5694 {
5695 VkCommandBufferBeginInfo begin_info{};
5696 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
5697 vkBeginCommandBuffer(command_buffer[0], &begin_info);
5698
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005699 vkCmdPipelineBarrier(command_buffer[0], VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0,
5700 nullptr, 0, nullptr, 0, nullptr);
Mark Lobodzinskic808d442016-04-14 10:57:23 -06005701
5702 VkViewport viewport{};
5703 viewport.maxDepth = 1.0f;
5704 viewport.minDepth = 0.0f;
5705 viewport.width = 512;
5706 viewport.height = 512;
5707 viewport.x = 0;
5708 viewport.y = 0;
5709 vkCmdSetViewport(command_buffer[0], 0, 1, &viewport);
5710 vkEndCommandBuffer(command_buffer[0]);
5711 }
5712 {
5713 VkCommandBufferBeginInfo begin_info{};
5714 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
5715 vkBeginCommandBuffer(command_buffer[1], &begin_info);
5716
5717 VkViewport viewport{};
5718 viewport.maxDepth = 1.0f;
5719 viewport.minDepth = 0.0f;
5720 viewport.width = 512;
5721 viewport.height = 512;
5722 viewport.x = 0;
5723 viewport.y = 0;
5724 vkCmdSetViewport(command_buffer[1], 0, 1, &viewport);
5725 vkEndCommandBuffer(command_buffer[1]);
5726 }
5727 {
5728 VkSubmitInfo submit_info{};
5729 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
5730 submit_info.commandBufferCount = 1;
5731 submit_info.pCommandBuffers = &command_buffer[0];
5732 submit_info.signalSemaphoreCount = 1;
5733 submit_info.pSignalSemaphores = &semaphore;
5734 vkQueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE);
5735 }
5736 {
5737 VkPipelineStageFlags flags[]{VK_PIPELINE_STAGE_ALL_COMMANDS_BIT};
5738 VkSubmitInfo submit_info{};
5739 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
5740 submit_info.commandBufferCount = 1;
5741 submit_info.pCommandBuffers = &command_buffer[1];
5742 submit_info.waitSemaphoreCount = 1;
5743 submit_info.pWaitSemaphores = &semaphore;
5744 submit_info.pWaitDstStageMask = flags;
5745 vkQueueSubmit(m_device->m_queue, 1, &submit_info, fence);
5746 }
5747
5748 vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
5749
5750 vkDestroyFence(m_device->device(), fence, nullptr);
5751 vkDestroySemaphore(m_device->device(), semaphore, nullptr);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005752 vkFreeCommandBuffers(m_device->device(), command_pool, 2, &command_buffer[0]);
Mark Lobodzinskic808d442016-04-14 10:57:23 -06005753 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
5754
5755 m_errorMonitor->VerifyNotFound();
5756}
5757
5758// This is a positive test. No errors should be generated.
5759TEST_F(VkLayerTest, TwoQueueSubmitsOneQueueWithSemaphoreAndOneFence) {
5760
5761 TEST_DESCRIPTION("Two command buffers, each in a separate QueueSubmit call "
5762 "on the same queue, sharing a signal/wait semaphore, the "
5763 "second having a fence, "
5764 "followed by a WaitForFences call.");
5765
5766 m_errorMonitor->ExpectSuccess();
5767
Cody Northropc31a84f2016-08-22 10:41:47 -06005768 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinskic808d442016-04-14 10:57:23 -06005769 VkFence fence;
5770 VkFenceCreateInfo fence_create_info{};
5771 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
5772 vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence);
5773
5774 VkSemaphore semaphore;
5775 VkSemaphoreCreateInfo semaphore_create_info{};
5776 semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005777 vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr, &semaphore);
Mark Lobodzinskic808d442016-04-14 10:57:23 -06005778
5779 VkCommandPool command_pool;
5780 VkCommandPoolCreateInfo pool_create_info{};
5781 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
5782 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
5783 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005784 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
Mark Lobodzinskic808d442016-04-14 10:57:23 -06005785
5786 VkCommandBuffer command_buffer[2];
5787 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005788 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
Mark Lobodzinskic808d442016-04-14 10:57:23 -06005789 command_buffer_allocate_info.commandPool = command_pool;
5790 command_buffer_allocate_info.commandBufferCount = 2;
5791 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005792 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, command_buffer);
Mark Lobodzinskic808d442016-04-14 10:57:23 -06005793
5794 {
5795 VkCommandBufferBeginInfo begin_info{};
5796 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
5797 vkBeginCommandBuffer(command_buffer[0], &begin_info);
5798
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005799 vkCmdPipelineBarrier(command_buffer[0], VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0,
5800 nullptr, 0, nullptr, 0, nullptr);
Mark Lobodzinskic808d442016-04-14 10:57:23 -06005801
5802 VkViewport viewport{};
5803 viewport.maxDepth = 1.0f;
5804 viewport.minDepth = 0.0f;
5805 viewport.width = 512;
5806 viewport.height = 512;
5807 viewport.x = 0;
5808 viewport.y = 0;
5809 vkCmdSetViewport(command_buffer[0], 0, 1, &viewport);
5810 vkEndCommandBuffer(command_buffer[0]);
5811 }
5812 {
5813 VkCommandBufferBeginInfo begin_info{};
5814 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
5815 vkBeginCommandBuffer(command_buffer[1], &begin_info);
5816
5817 VkViewport viewport{};
5818 viewport.maxDepth = 1.0f;
5819 viewport.minDepth = 0.0f;
5820 viewport.width = 512;
5821 viewport.height = 512;
5822 viewport.x = 0;
5823 viewport.y = 0;
5824 vkCmdSetViewport(command_buffer[1], 0, 1, &viewport);
5825 vkEndCommandBuffer(command_buffer[1]);
5826 }
5827 {
5828 VkSubmitInfo submit_info{};
5829 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
5830 submit_info.commandBufferCount = 1;
5831 submit_info.pCommandBuffers = &command_buffer[0];
5832 submit_info.signalSemaphoreCount = 1;
5833 submit_info.pSignalSemaphores = &semaphore;
5834 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
5835 }
5836 {
5837 VkPipelineStageFlags flags[]{VK_PIPELINE_STAGE_ALL_COMMANDS_BIT};
5838 VkSubmitInfo submit_info{};
5839 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
5840 submit_info.commandBufferCount = 1;
5841 submit_info.pCommandBuffers = &command_buffer[1];
5842 submit_info.waitSemaphoreCount = 1;
5843 submit_info.pWaitSemaphores = &semaphore;
5844 submit_info.pWaitDstStageMask = flags;
5845 vkQueueSubmit(m_device->m_queue, 1, &submit_info, fence);
5846 }
5847
5848 vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
5849
5850 vkDestroyFence(m_device->device(), fence, nullptr);
5851 vkDestroySemaphore(m_device->device(), semaphore, nullptr);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005852 vkFreeCommandBuffers(m_device->device(), command_pool, 2, &command_buffer[0]);
Mark Lobodzinskic808d442016-04-14 10:57:23 -06005853 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
5854
5855 m_errorMonitor->VerifyNotFound();
5856}
5857
5858// This is a positive test. No errors should be generated.
5859TEST_F(VkLayerTest, TwoQueueSubmitsOneQueueNullQueueSubmitWithFence) {
5860
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005861 TEST_DESCRIPTION("Two command buffers, each in a separate QueueSubmit call "
5862 "on the same queue, no fences, followed by a third QueueSubmit with NO "
5863 "SubmitInfos but with a fence, followed by a WaitForFences call.");
Mark Lobodzinskic808d442016-04-14 10:57:23 -06005864
5865 m_errorMonitor->ExpectSuccess();
5866
Cody Northropc31a84f2016-08-22 10:41:47 -06005867 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinskic808d442016-04-14 10:57:23 -06005868 VkFence fence;
5869 VkFenceCreateInfo fence_create_info{};
5870 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
5871 vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence);
5872
5873 VkCommandPool command_pool;
5874 VkCommandPoolCreateInfo pool_create_info{};
5875 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
5876 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
5877 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005878 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
Mark Lobodzinskic808d442016-04-14 10:57:23 -06005879
5880 VkCommandBuffer command_buffer[2];
5881 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005882 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
Mark Lobodzinskic808d442016-04-14 10:57:23 -06005883 command_buffer_allocate_info.commandPool = command_pool;
5884 command_buffer_allocate_info.commandBufferCount = 2;
5885 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005886 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, command_buffer);
Mark Lobodzinskic808d442016-04-14 10:57:23 -06005887
5888 {
5889 VkCommandBufferBeginInfo begin_info{};
5890 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
5891 vkBeginCommandBuffer(command_buffer[0], &begin_info);
5892
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005893 vkCmdPipelineBarrier(command_buffer[0], VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0,
5894 nullptr, 0, nullptr, 0, nullptr);
Mark Lobodzinskic808d442016-04-14 10:57:23 -06005895
5896 VkViewport viewport{};
5897 viewport.maxDepth = 1.0f;
5898 viewport.minDepth = 0.0f;
5899 viewport.width = 512;
5900 viewport.height = 512;
5901 viewport.x = 0;
5902 viewport.y = 0;
5903 vkCmdSetViewport(command_buffer[0], 0, 1, &viewport);
5904 vkEndCommandBuffer(command_buffer[0]);
5905 }
5906 {
5907 VkCommandBufferBeginInfo begin_info{};
5908 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
5909 vkBeginCommandBuffer(command_buffer[1], &begin_info);
5910
5911 VkViewport viewport{};
5912 viewport.maxDepth = 1.0f;
5913 viewport.minDepth = 0.0f;
5914 viewport.width = 512;
5915 viewport.height = 512;
5916 viewport.x = 0;
5917 viewport.y = 0;
5918 vkCmdSetViewport(command_buffer[1], 0, 1, &viewport);
5919 vkEndCommandBuffer(command_buffer[1]);
5920 }
5921 {
5922 VkSubmitInfo submit_info{};
5923 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
5924 submit_info.commandBufferCount = 1;
5925 submit_info.pCommandBuffers = &command_buffer[0];
5926 submit_info.signalSemaphoreCount = 0;
5927 submit_info.pSignalSemaphores = VK_NULL_HANDLE;
5928 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
5929 }
5930 {
5931 VkPipelineStageFlags flags[]{VK_PIPELINE_STAGE_ALL_COMMANDS_BIT};
5932 VkSubmitInfo submit_info{};
5933 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
5934 submit_info.commandBufferCount = 1;
5935 submit_info.pCommandBuffers = &command_buffer[1];
5936 submit_info.waitSemaphoreCount = 0;
5937 submit_info.pWaitSemaphores = VK_NULL_HANDLE;
5938 submit_info.pWaitDstStageMask = flags;
5939 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
5940 }
5941
5942 vkQueueSubmit(m_device->m_queue, 0, NULL, fence);
5943
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005944 VkResult err = vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
Mike Stroyancd1c3e52016-06-21 09:20:01 -06005945 ASSERT_VK_SUCCESS(err);
Mark Lobodzinskic808d442016-04-14 10:57:23 -06005946
5947 vkDestroyFence(m_device->device(), fence, nullptr);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005948 vkFreeCommandBuffers(m_device->device(), command_pool, 2, &command_buffer[0]);
Mark Lobodzinskic808d442016-04-14 10:57:23 -06005949 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
5950
5951 m_errorMonitor->VerifyNotFound();
5952}
5953
5954// This is a positive test. No errors should be generated.
5955TEST_F(VkLayerTest, TwoQueueSubmitsOneQueueOneFence) {
5956
5957 TEST_DESCRIPTION("Two command buffers, each in a separate QueueSubmit call "
5958 "on the same queue, the second having a fence, followed "
5959 "by a WaitForFences call.");
5960
5961 m_errorMonitor->ExpectSuccess();
5962
Cody Northropc31a84f2016-08-22 10:41:47 -06005963 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinskic808d442016-04-14 10:57:23 -06005964 VkFence fence;
5965 VkFenceCreateInfo fence_create_info{};
5966 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
5967 vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence);
5968
5969 VkCommandPool command_pool;
5970 VkCommandPoolCreateInfo pool_create_info{};
5971 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
5972 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
5973 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005974 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
Mark Lobodzinskic808d442016-04-14 10:57:23 -06005975
5976 VkCommandBuffer command_buffer[2];
5977 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005978 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
Mark Lobodzinskic808d442016-04-14 10:57:23 -06005979 command_buffer_allocate_info.commandPool = command_pool;
5980 command_buffer_allocate_info.commandBufferCount = 2;
5981 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005982 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, command_buffer);
Mark Lobodzinskic808d442016-04-14 10:57:23 -06005983
5984 {
5985 VkCommandBufferBeginInfo begin_info{};
5986 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
5987 vkBeginCommandBuffer(command_buffer[0], &begin_info);
5988
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005989 vkCmdPipelineBarrier(command_buffer[0], VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0,
5990 nullptr, 0, nullptr, 0, nullptr);
Mark Lobodzinskic808d442016-04-14 10:57:23 -06005991
5992 VkViewport viewport{};
5993 viewport.maxDepth = 1.0f;
5994 viewport.minDepth = 0.0f;
5995 viewport.width = 512;
5996 viewport.height = 512;
5997 viewport.x = 0;
5998 viewport.y = 0;
5999 vkCmdSetViewport(command_buffer[0], 0, 1, &viewport);
6000 vkEndCommandBuffer(command_buffer[0]);
6001 }
6002 {
6003 VkCommandBufferBeginInfo begin_info{};
6004 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
6005 vkBeginCommandBuffer(command_buffer[1], &begin_info);
6006
6007 VkViewport viewport{};
6008 viewport.maxDepth = 1.0f;
6009 viewport.minDepth = 0.0f;
6010 viewport.width = 512;
6011 viewport.height = 512;
6012 viewport.x = 0;
6013 viewport.y = 0;
6014 vkCmdSetViewport(command_buffer[1], 0, 1, &viewport);
6015 vkEndCommandBuffer(command_buffer[1]);
6016 }
6017 {
6018 VkSubmitInfo submit_info{};
6019 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
6020 submit_info.commandBufferCount = 1;
6021 submit_info.pCommandBuffers = &command_buffer[0];
6022 submit_info.signalSemaphoreCount = 0;
6023 submit_info.pSignalSemaphores = VK_NULL_HANDLE;
6024 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
6025 }
6026 {
6027 VkPipelineStageFlags flags[]{VK_PIPELINE_STAGE_ALL_COMMANDS_BIT};
6028 VkSubmitInfo submit_info{};
6029 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
6030 submit_info.commandBufferCount = 1;
6031 submit_info.pCommandBuffers = &command_buffer[1];
6032 submit_info.waitSemaphoreCount = 0;
6033 submit_info.pWaitSemaphores = VK_NULL_HANDLE;
6034 submit_info.pWaitDstStageMask = flags;
6035 vkQueueSubmit(m_device->m_queue, 1, &submit_info, fence);
6036 }
6037
6038 vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
6039
6040 vkDestroyFence(m_device->device(), fence, nullptr);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006041 vkFreeCommandBuffers(m_device->device(), command_pool, 2, &command_buffer[0]);
Mark Lobodzinskic808d442016-04-14 10:57:23 -06006042 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
6043
6044 m_errorMonitor->VerifyNotFound();
6045}
6046
6047// This is a positive test. No errors should be generated.
6048TEST_F(VkLayerTest, TwoSubmitInfosWithSemaphoreOneQueueSubmitsOneFence) {
6049
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006050 TEST_DESCRIPTION("Two command buffers each in a separate SubmitInfo sent in a single "
6051 "QueueSubmit call followed by a WaitForFences call.");
Cody Northropc31a84f2016-08-22 10:41:47 -06006052 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinskic808d442016-04-14 10:57:23 -06006053
6054 m_errorMonitor->ExpectSuccess();
6055
6056 VkFence fence;
6057 VkFenceCreateInfo fence_create_info{};
6058 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
6059 vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence);
6060
6061 VkSemaphore semaphore;
6062 VkSemaphoreCreateInfo semaphore_create_info{};
6063 semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006064 vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr, &semaphore);
Mark Lobodzinskic808d442016-04-14 10:57:23 -06006065
6066 VkCommandPool command_pool;
6067 VkCommandPoolCreateInfo pool_create_info{};
6068 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
6069 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
6070 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006071 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
Mark Lobodzinskic808d442016-04-14 10:57:23 -06006072
6073 VkCommandBuffer command_buffer[2];
6074 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006075 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
Mark Lobodzinskic808d442016-04-14 10:57:23 -06006076 command_buffer_allocate_info.commandPool = command_pool;
6077 command_buffer_allocate_info.commandBufferCount = 2;
6078 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006079 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, command_buffer);
Mark Lobodzinskic808d442016-04-14 10:57:23 -06006080
6081 {
6082 VkCommandBufferBeginInfo begin_info{};
6083 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
6084 vkBeginCommandBuffer(command_buffer[0], &begin_info);
6085
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006086 vkCmdPipelineBarrier(command_buffer[0], VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0,
6087 nullptr, 0, nullptr, 0, nullptr);
Mark Lobodzinskic808d442016-04-14 10:57:23 -06006088
6089 VkViewport viewport{};
6090 viewport.maxDepth = 1.0f;
6091 viewport.minDepth = 0.0f;
6092 viewport.width = 512;
6093 viewport.height = 512;
6094 viewport.x = 0;
6095 viewport.y = 0;
6096 vkCmdSetViewport(command_buffer[0], 0, 1, &viewport);
6097 vkEndCommandBuffer(command_buffer[0]);
6098 }
6099 {
6100 VkCommandBufferBeginInfo begin_info{};
6101 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
6102 vkBeginCommandBuffer(command_buffer[1], &begin_info);
6103
6104 VkViewport viewport{};
6105 viewport.maxDepth = 1.0f;
6106 viewport.minDepth = 0.0f;
6107 viewport.width = 512;
6108 viewport.height = 512;
6109 viewport.x = 0;
6110 viewport.y = 0;
6111 vkCmdSetViewport(command_buffer[1], 0, 1, &viewport);
6112 vkEndCommandBuffer(command_buffer[1]);
6113 }
6114 {
6115 VkSubmitInfo submit_info[2];
6116 VkPipelineStageFlags flags[]{VK_PIPELINE_STAGE_ALL_COMMANDS_BIT};
6117
6118 submit_info[0].sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
6119 submit_info[0].pNext = NULL;
6120 submit_info[0].commandBufferCount = 1;
6121 submit_info[0].pCommandBuffers = &command_buffer[0];
6122 submit_info[0].signalSemaphoreCount = 1;
6123 submit_info[0].pSignalSemaphores = &semaphore;
6124 submit_info[0].waitSemaphoreCount = 0;
6125 submit_info[0].pWaitSemaphores = NULL;
6126 submit_info[0].pWaitDstStageMask = 0;
6127
6128 submit_info[1].sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
6129 submit_info[1].pNext = NULL;
6130 submit_info[1].commandBufferCount = 1;
6131 submit_info[1].pCommandBuffers = &command_buffer[1];
6132 submit_info[1].waitSemaphoreCount = 1;
6133 submit_info[1].pWaitSemaphores = &semaphore;
6134 submit_info[1].pWaitDstStageMask = flags;
6135 submit_info[1].signalSemaphoreCount = 0;
6136 submit_info[1].pSignalSemaphores = NULL;
6137 vkQueueSubmit(m_device->m_queue, 2, &submit_info[0], fence);
6138 }
6139
6140 vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
6141
6142 vkDestroyFence(m_device->device(), fence, nullptr);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006143 vkFreeCommandBuffers(m_device->device(), command_pool, 2, &command_buffer[0]);
Mark Lobodzinskic808d442016-04-14 10:57:23 -06006144 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
Tony Barbourdf4c0042016-06-01 15:55:43 -06006145 vkDestroySemaphore(m_device->device(), semaphore, nullptr);
Mark Lobodzinskic808d442016-04-14 10:57:23 -06006146
6147 m_errorMonitor->VerifyNotFound();
6148}
6149
Tobin Ehlisb1a87992016-05-25 16:42:47 -06006150TEST_F(VkLayerTest, DynamicDepthBiasNotBound) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006151 TEST_DESCRIPTION("Run a simple draw calls to validate failure when Depth Bias dynamic "
6152 "state is required but not correctly bound.");
Tobin Ehlisb1a87992016-05-25 16:42:47 -06006153
Cody Northropc31a84f2016-08-22 10:41:47 -06006154 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisb1a87992016-05-25 16:42:47 -06006155 // Dynamic depth bias
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006156 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Dynamic depth bias state not set for this command buffer");
6157 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailDepthBias);
Tobin Ehlisb1a87992016-05-25 16:42:47 -06006158 m_errorMonitor->VerifyFound();
6159}
6160
6161TEST_F(VkLayerTest, DynamicLineWidthNotBound) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006162 TEST_DESCRIPTION("Run a simple draw calls to validate failure when Line Width dynamic "
6163 "state is required but not correctly bound.");
Tobin Ehlisa5200ef2016-05-03 10:34:08 -06006164
Cody Northropc31a84f2016-08-22 10:41:47 -06006165 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisa5200ef2016-05-03 10:34:08 -06006166 // Dynamic line width
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006167 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Dynamic line width state not set for this command buffer");
6168 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailLineWidth);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006169 m_errorMonitor->VerifyFound();
Tobin Ehlisb1a87992016-05-25 16:42:47 -06006170}
6171
6172TEST_F(VkLayerTest, DynamicViewportNotBound) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006173 TEST_DESCRIPTION("Run a simple draw calls to validate failure when Viewport dynamic "
6174 "state is required but not correctly bound.");
Tobin Ehlisb1a87992016-05-25 16:42:47 -06006175
Cody Northropc31a84f2016-08-22 10:41:47 -06006176 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisa5200ef2016-05-03 10:34:08 -06006177 // Dynamic viewport state
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006178 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Dynamic viewport state not set for this command buffer");
6179 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailViewport);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006180 m_errorMonitor->VerifyFound();
Tobin Ehlisb1a87992016-05-25 16:42:47 -06006181}
6182
6183TEST_F(VkLayerTest, DynamicScissorNotBound) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006184 TEST_DESCRIPTION("Run a simple draw calls to validate failure when Scissor dynamic "
6185 "state is required but not correctly bound.");
Tobin Ehlisb1a87992016-05-25 16:42:47 -06006186
Cody Northropc31a84f2016-08-22 10:41:47 -06006187 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisa5200ef2016-05-03 10:34:08 -06006188 // Dynamic scissor state
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006189 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Dynamic scissor state not set for this command buffer");
6190 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailScissor);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006191 m_errorMonitor->VerifyFound();
Tobin Ehlisb1a87992016-05-25 16:42:47 -06006192}
6193
Cortd713fe82016-07-27 09:51:27 -07006194TEST_F(VkLayerTest, DynamicBlendConstantsNotBound) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006195 TEST_DESCRIPTION("Run a simple draw calls to validate failure when Blend Constants "
6196 "dynamic state is required but not correctly bound.");
Cody Northropc31a84f2016-08-22 10:41:47 -06006197
6198 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlis21c88352016-05-26 06:15:45 -06006199 // Dynamic blend constant state
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006200 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
6201 "Dynamic blend constants state not set for this command buffer");
6202 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailBlend);
Tobin Ehlis21c88352016-05-26 06:15:45 -06006203 m_errorMonitor->VerifyFound();
6204}
6205
6206TEST_F(VkLayerTest, DynamicDepthBoundsNotBound) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006207 TEST_DESCRIPTION("Run a simple draw calls to validate failure when Depth Bounds dynamic "
6208 "state is required but not correctly bound.");
Cody Northropc31a84f2016-08-22 10:41:47 -06006209
6210 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlis21c88352016-05-26 06:15:45 -06006211 if (!m_device->phy().features().depthBounds) {
6212 printf("Device does not support depthBounds test; skipped.\n");
6213 return;
6214 }
6215 // Dynamic depth bounds
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006216 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
6217 "Dynamic depth bounds state not set for this command buffer");
6218 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailDepthBounds);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006219 m_errorMonitor->VerifyFound();
Tobin Ehlisb1a87992016-05-25 16:42:47 -06006220}
6221
6222TEST_F(VkLayerTest, DynamicStencilReadNotBound) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006223 TEST_DESCRIPTION("Run a simple draw calls to validate failure when Stencil Read dynamic "
6224 "state is required but not correctly bound.");
Cody Northropc31a84f2016-08-22 10:41:47 -06006225
6226 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisa5200ef2016-05-03 10:34:08 -06006227 // Dynamic stencil read mask
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006228 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
6229 "Dynamic stencil read mask state not set for this command buffer");
6230 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailStencilReadMask);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006231 m_errorMonitor->VerifyFound();
Tobin Ehlisb1a87992016-05-25 16:42:47 -06006232}
6233
6234TEST_F(VkLayerTest, DynamicStencilWriteNotBound) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006235 TEST_DESCRIPTION("Run a simple draw calls to validate failure when Stencil Write dynamic"
6236 " state is required but not correctly bound.");
Cody Northropc31a84f2016-08-22 10:41:47 -06006237
6238 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisa5200ef2016-05-03 10:34:08 -06006239 // Dynamic stencil write mask
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006240 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
6241 "Dynamic stencil write mask state not set for this command buffer");
6242 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailStencilWriteMask);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006243 m_errorMonitor->VerifyFound();
Tobin Ehlisb1a87992016-05-25 16:42:47 -06006244}
6245
6246TEST_F(VkLayerTest, DynamicStencilRefNotBound) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006247 TEST_DESCRIPTION("Run a simple draw calls to validate failure when Stencil Ref dynamic "
6248 "state is required but not correctly bound.");
Cody Northropc31a84f2016-08-22 10:41:47 -06006249
6250 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisa5200ef2016-05-03 10:34:08 -06006251 // Dynamic stencil reference
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006252 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
6253 "Dynamic stencil reference state not set for this command buffer");
6254 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailStencilReference);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006255 m_errorMonitor->VerifyFound();
Tobin Ehlis963a4042015-09-29 08:18:34 -06006256}
6257
Tobin Ehlis379ba3b2016-07-19 11:22:29 -06006258TEST_F(VkLayerTest, IndexBufferNotBound) {
6259 TEST_DESCRIPTION("Run an indexed draw call without an index buffer bound.");
Cody Northropc31a84f2016-08-22 10:41:47 -06006260
6261 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006262 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
6263 "Index buffer object not bound to this command buffer when Indexed ");
6264 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailIndexBuffer);
Tobin Ehlis379ba3b2016-07-19 11:22:29 -06006265 m_errorMonitor->VerifyFound();
6266}
6267
Karl Schultz6addd812016-02-02 17:17:23 -07006268TEST_F(VkLayerTest, CommandBufferTwoSubmits) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006269 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
6270 "was begun w/ VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT set, but has "
6271 "been submitted");
Tobin Ehlis59278bf2015-08-18 07:10:58 -06006272
Tobin Ehlis59278bf2015-08-18 07:10:58 -06006273 ASSERT_NO_FATAL_FAILURE(InitState());
6274 ASSERT_NO_FATAL_FAILURE(InitViewport());
6275 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
6276
Karl Schultz6addd812016-02-02 17:17:23 -07006277 // We luck out b/c by default the framework creates CB w/ the
6278 // VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT set
Tobin Ehlis59278bf2015-08-18 07:10:58 -06006279 BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006280 m_commandBuffer->ClearAllBuffers(m_clear_color, m_depth_clear_color, m_stencil_clear_color, NULL);
Tobin Ehlis59278bf2015-08-18 07:10:58 -06006281 EndCommandBuffer();
6282
Tobin Ehlis59278bf2015-08-18 07:10:58 -06006283 // Bypass framework since it does the waits automatically
6284 VkResult err = VK_SUCCESS;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06006285 VkSubmitInfo submit_info;
Chia-I Wuf9be13c2015-10-26 20:37:06 +08006286 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
6287 submit_info.pNext = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08006288 submit_info.waitSemaphoreCount = 0;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06006289 submit_info.pWaitSemaphores = NULL;
Jon Ashburn7f9716c2015-12-30 16:42:50 -07006290 submit_info.pWaitDstStageMask = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08006291 submit_info.commandBufferCount = 1;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08006292 submit_info.pCommandBuffers = &m_commandBuffer->handle();
Chia-I Wud50a7d72015-10-26 20:48:51 +08006293 submit_info.signalSemaphoreCount = 0;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06006294 submit_info.pSignalSemaphores = NULL;
6295
Chris Forbes40028e22016-06-13 09:59:34 +12006296 err = vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
Karl Schultz6addd812016-02-02 17:17:23 -07006297 ASSERT_VK_SUCCESS(err);
Tobin Ehlis59278bf2015-08-18 07:10:58 -06006298
Karl Schultz6addd812016-02-02 17:17:23 -07006299 // Cause validation error by re-submitting cmd buffer that should only be
6300 // submitted once
Chris Forbes40028e22016-06-13 09:59:34 +12006301 err = vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
Tobin Ehlis59278bf2015-08-18 07:10:58 -06006302
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006303 m_errorMonitor->VerifyFound();
Tobin Ehlis59278bf2015-08-18 07:10:58 -06006304}
6305
Karl Schultz6addd812016-02-02 17:17:23 -07006306TEST_F(VkLayerTest, AllocDescriptorFromEmptyPool) {
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06006307 // Initiate Draw w/o a PSO bound
Karl Schultz6addd812016-02-02 17:17:23 -07006308 VkResult err;
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06006309
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006310 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Unable to allocate 1 descriptors of "
6311 "type "
6312 "VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER ");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06006313
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06006314 ASSERT_NO_FATAL_FAILURE(InitState());
6315 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06006316
Karl Schultz6addd812016-02-02 17:17:23 -07006317 // Create Pool w/ 1 Sampler descriptor, but try to alloc Uniform Buffer
6318 // descriptor from it
Chia-I Wu1b99bb22015-10-27 19:25:11 +08006319 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006320 ds_type_count.type = VK_DESCRIPTOR_TYPE_SAMPLER;
6321 ds_type_count.descriptorCount = 1;
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06006322
6323 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006324 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
6325 ds_pool_ci.pNext = NULL;
6326 ds_pool_ci.flags = 0;
6327 ds_pool_ci.maxSets = 1;
6328 ds_pool_ci.poolSizeCount = 1;
6329 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06006330
6331 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006332 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06006333 ASSERT_VK_SUCCESS(err);
6334
6335 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006336 dsl_binding.binding = 0;
6337 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
6338 dsl_binding.descriptorCount = 1;
6339 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
6340 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06006341
6342 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006343 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
6344 ds_layout_ci.pNext = NULL;
6345 ds_layout_ci.bindingCount = 1;
6346 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06006347
6348 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006349 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06006350 ASSERT_VK_SUCCESS(err);
6351
6352 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08006353 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08006354 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07006355 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06006356 alloc_info.descriptorPool = ds_pool;
6357 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006358 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06006359
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006360 m_errorMonitor->VerifyFound();
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06006361
Chia-I Wuf7458c52015-10-26 21:10:41 +08006362 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
6363 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06006364}
6365
Karl Schultz6addd812016-02-02 17:17:23 -07006366TEST_F(VkLayerTest, FreeDescriptorFromOneShotPool) {
6367 VkResult err;
Tobin Ehlise735c692015-10-08 13:13:50 -06006368
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006369 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
6370 "It is invalid to call vkFreeDescriptorSets() with a pool created "
6371 "without setting VK_DESCRIPTOR_POOL_CREATE_FREE_DESCRIPTOR_SET_BIT.");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06006372
Tobin Ehlise735c692015-10-08 13:13:50 -06006373 ASSERT_NO_FATAL_FAILURE(InitState());
6374 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlise735c692015-10-08 13:13:50 -06006375
Chia-I Wu1b99bb22015-10-27 19:25:11 +08006376 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006377 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
6378 ds_type_count.descriptorCount = 1;
Tobin Ehlise735c692015-10-08 13:13:50 -06006379
6380 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006381 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
6382 ds_pool_ci.pNext = NULL;
6383 ds_pool_ci.maxSets = 1;
6384 ds_pool_ci.poolSizeCount = 1;
6385 ds_pool_ci.flags = 0;
6386 // Not specifying VK_DESCRIPTOR_POOL_CREATE_FREE_DESCRIPTOR_SET_BIT means
6387 // app can only call vkResetDescriptorPool on this pool.;
6388 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlise735c692015-10-08 13:13:50 -06006389
6390 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006391 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlise735c692015-10-08 13:13:50 -06006392 ASSERT_VK_SUCCESS(err);
6393
6394 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006395 dsl_binding.binding = 0;
6396 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
6397 dsl_binding.descriptorCount = 1;
6398 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
6399 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlise735c692015-10-08 13:13:50 -06006400
6401 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006402 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
6403 ds_layout_ci.pNext = NULL;
6404 ds_layout_ci.bindingCount = 1;
6405 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlise735c692015-10-08 13:13:50 -06006406
6407 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006408 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlise735c692015-10-08 13:13:50 -06006409 ASSERT_VK_SUCCESS(err);
6410
6411 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08006412 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08006413 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07006414 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06006415 alloc_info.descriptorPool = ds_pool;
6416 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006417 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlise735c692015-10-08 13:13:50 -06006418 ASSERT_VK_SUCCESS(err);
6419
6420 err = vkFreeDescriptorSets(m_device->device(), ds_pool, 1, &descriptorSet);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006421 m_errorMonitor->VerifyFound();
Tobin Ehlise735c692015-10-08 13:13:50 -06006422
Chia-I Wuf7458c52015-10-26 21:10:41 +08006423 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
6424 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlise735c692015-10-08 13:13:50 -06006425}
6426
Karl Schultz6addd812016-02-02 17:17:23 -07006427TEST_F(VkLayerTest, InvalidDescriptorPool) {
Karl Schultzbdb75952016-04-19 11:36:49 -06006428 // Attempt to clear Descriptor Pool with bad object.
6429 // ObjectTracker should catch this.
Cody Northropc31a84f2016-08-22 10:41:47 -06006430
6431 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006432 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Invalid Descriptor Pool Object 0xbaad6001");
Mark Lobodzinski02bf89d2016-05-10 14:45:13 -06006433 uint64_t fake_pool_handle = 0xbaad6001;
6434 VkDescriptorPool bad_pool = reinterpret_cast<VkDescriptorPool &>(fake_pool_handle);
6435 vkResetDescriptorPool(device(), bad_pool, 0);
Karl Schultzbdb75952016-04-19 11:36:49 -06006436 m_errorMonitor->VerifyFound();
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06006437}
6438
Karl Schultz6addd812016-02-02 17:17:23 -07006439TEST_F(VkLayerTest, InvalidDescriptorSet) {
Karl Schultzbdb75952016-04-19 11:36:49 -06006440 // Attempt to bind an invalid Descriptor Set to a valid Command Buffer
6441 // ObjectTracker should catch this.
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06006442 // Create a valid cmd buffer
Karl Schultzbdb75952016-04-19 11:36:49 -06006443 // call vkCmdBindDescriptorSets w/ false Descriptor Set
Mark Lobodzinski02bf89d2016-05-10 14:45:13 -06006444
6445 uint64_t fake_set_handle = 0xbaad6001;
6446 VkDescriptorSet bad_set = reinterpret_cast<VkDescriptorSet &>(fake_set_handle);
Karl Schultzbdb75952016-04-19 11:36:49 -06006447 VkResult err;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006448 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Invalid Descriptor Set Object 0xbaad6001");
Karl Schultzbdb75952016-04-19 11:36:49 -06006449
6450 ASSERT_NO_FATAL_FAILURE(InitState());
6451
6452 VkDescriptorSetLayoutBinding layout_bindings[1] = {};
6453 layout_bindings[0].binding = 0;
6454 layout_bindings[0].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
6455 layout_bindings[0].descriptorCount = 1;
6456 layout_bindings[0].stageFlags = VK_SHADER_STAGE_VERTEX_BIT;
6457 layout_bindings[0].pImmutableSamplers = NULL;
6458
6459 VkDescriptorSetLayout descriptor_set_layout;
6460 VkDescriptorSetLayoutCreateInfo dslci = {};
6461 dslci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
6462 dslci.pNext = NULL;
6463 dslci.bindingCount = 1;
6464 dslci.pBindings = layout_bindings;
6465 err = vkCreateDescriptorSetLayout(device(), &dslci, NULL, &descriptor_set_layout);
Karl Schultz5cb21112016-04-21 17:17:40 -06006466 ASSERT_VK_SUCCESS(err);
Karl Schultzbdb75952016-04-19 11:36:49 -06006467
6468 VkPipelineLayout pipeline_layout;
6469 VkPipelineLayoutCreateInfo plci = {};
6470 plci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
6471 plci.pNext = NULL;
6472 plci.setLayoutCount = 1;
6473 plci.pSetLayouts = &descriptor_set_layout;
6474 err = vkCreatePipelineLayout(device(), &plci, NULL, &pipeline_layout);
Karl Schultz5cb21112016-04-21 17:17:40 -06006475 ASSERT_VK_SUCCESS(err);
Karl Schultzbdb75952016-04-19 11:36:49 -06006476
6477 BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006478 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1, &bad_set, 0,
6479 NULL);
Karl Schultzbdb75952016-04-19 11:36:49 -06006480 m_errorMonitor->VerifyFound();
6481 EndCommandBuffer();
6482 vkDestroyPipelineLayout(device(), pipeline_layout, NULL);
6483 vkDestroyDescriptorSetLayout(device(), descriptor_set_layout, NULL);
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06006484}
6485
Karl Schultz6addd812016-02-02 17:17:23 -07006486TEST_F(VkLayerTest, InvalidDescriptorSetLayout) {
Karl Schultzbdb75952016-04-19 11:36:49 -06006487 // Attempt to create a Pipeline Layout with an invalid Descriptor Set Layout.
6488 // ObjectTracker should catch this.
Mark Lobodzinski02bf89d2016-05-10 14:45:13 -06006489 uint64_t fake_layout_handle = 0xbaad6001;
6490 VkDescriptorSetLayout bad_layout = reinterpret_cast<VkDescriptorSetLayout &>(fake_layout_handle);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006491 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Invalid Descriptor Set Layout Object 0xbaad6001");
Cody Northropc31a84f2016-08-22 10:41:47 -06006492 ASSERT_NO_FATAL_FAILURE(InitState());
Karl Schultzbdb75952016-04-19 11:36:49 -06006493 VkPipelineLayout pipeline_layout;
6494 VkPipelineLayoutCreateInfo plci = {};
6495 plci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
6496 plci.pNext = NULL;
6497 plci.setLayoutCount = 1;
6498 plci.pSetLayouts = &bad_layout;
6499 vkCreatePipelineLayout(device(), &plci, NULL, &pipeline_layout);
6500
6501 m_errorMonitor->VerifyFound();
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06006502}
6503
Mark Muellerd4914412016-06-13 17:52:06 -06006504TEST_F(VkLayerTest, WriteDescriptorSetIntegrityCheck) {
6505 TEST_DESCRIPTION("This test verifies some requirements of chapter 13.2.3 of the Vulkan Spec "
6506 "1) A uniform buffer update must have a valid buffer index."
6507 "2) When using an array of descriptors in a single WriteDescriptor,"
6508 " the descriptor types and stageflags must all be the same."
6509 "3) Immutable Sampler state must match across descriptors");
6510
6511 const char *invalid_BufferInfo_ErrorMessage =
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006512 "vkUpdateDescriptorSets: if pDescriptorWrites[0].descriptorType is VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, "
6513 "VK_DESCRIPTOR_TYPE_STORAGE_BUFFER, VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC or "
6514 "VK_DESCRIPTOR_TYPE_STORAGE_BUFFER_DYNAMIC, pDescriptorWrites[0].pBufferInfo must not be NULL";
6515 const char *stateFlag_ErrorMessage = "Attempting write update to descriptor set ";
6516 const char *immutable_ErrorMessage = "Attempting write update to descriptor set ";
Mark Muellerd4914412016-06-13 17:52:06 -06006517
Mark Muellerd4914412016-06-13 17:52:06 -06006518 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, invalid_BufferInfo_ErrorMessage);
6519
6520 ASSERT_NO_FATAL_FAILURE(InitState());
6521 VkDescriptorPoolSize ds_type_count[4] = {};
6522 ds_type_count[0].type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
6523 ds_type_count[0].descriptorCount = 1;
6524 ds_type_count[1].type = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
6525 ds_type_count[1].descriptorCount = 1;
6526 ds_type_count[2].type = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
6527 ds_type_count[2].descriptorCount = 1;
6528 ds_type_count[3].type = VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT;
6529 ds_type_count[3].descriptorCount = 1;
6530
6531 VkDescriptorPoolCreateInfo ds_pool_ci = {};
6532 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
6533 ds_pool_ci.maxSets = 1;
6534 ds_pool_ci.poolSizeCount = sizeof(ds_type_count) / sizeof(VkDescriptorPoolSize);
6535 ds_pool_ci.pPoolSizes = ds_type_count;
6536
6537 VkDescriptorPool ds_pool;
6538 VkResult err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
6539 ASSERT_VK_SUCCESS(err);
6540
Mark Muellerb9896722016-06-16 09:54:29 -06006541 VkDescriptorSetLayoutBinding layout_binding[3] = {};
Mark Muellerd4914412016-06-13 17:52:06 -06006542 layout_binding[0].binding = 0;
6543 layout_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
6544 layout_binding[0].descriptorCount = 1;
6545 layout_binding[0].stageFlags = VK_SHADER_STAGE_ALL;
6546 layout_binding[0].pImmutableSamplers = NULL;
6547
6548 layout_binding[1].binding = 1;
6549 layout_binding[1].descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
6550 layout_binding[1].descriptorCount = 1;
6551 layout_binding[1].stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
6552 layout_binding[1].pImmutableSamplers = NULL;
6553
6554 VkSamplerCreateInfo sampler_ci = {};
6555 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
6556 sampler_ci.pNext = NULL;
6557 sampler_ci.magFilter = VK_FILTER_NEAREST;
6558 sampler_ci.minFilter = VK_FILTER_NEAREST;
6559 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
6560 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
6561 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
6562 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
6563 sampler_ci.mipLodBias = 1.0;
6564 sampler_ci.anisotropyEnable = VK_FALSE;
6565 sampler_ci.maxAnisotropy = 1;
6566 sampler_ci.compareEnable = VK_FALSE;
6567 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
6568 sampler_ci.minLod = 1.0;
6569 sampler_ci.maxLod = 1.0;
6570 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
6571 sampler_ci.unnormalizedCoordinates = VK_FALSE;
6572 VkSampler sampler;
6573
6574 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
6575 ASSERT_VK_SUCCESS(err);
6576
6577 layout_binding[2].binding = 2;
6578 layout_binding[2].descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
6579 layout_binding[2].descriptorCount = 1;
6580 layout_binding[2].stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
6581 layout_binding[2].pImmutableSamplers = static_cast<VkSampler *>(&sampler);
6582
Mark Muellerd4914412016-06-13 17:52:06 -06006583 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
6584 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
6585 ds_layout_ci.bindingCount = sizeof(layout_binding) / sizeof(VkDescriptorSetLayoutBinding);
6586 ds_layout_ci.pBindings = layout_binding;
6587 VkDescriptorSetLayout ds_layout;
6588 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
6589 ASSERT_VK_SUCCESS(err);
6590
6591 VkDescriptorSetAllocateInfo alloc_info = {};
6592 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
6593 alloc_info.descriptorSetCount = 1;
6594 alloc_info.descriptorPool = ds_pool;
6595 alloc_info.pSetLayouts = &ds_layout;
6596 VkDescriptorSet descriptorSet;
6597 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
6598 ASSERT_VK_SUCCESS(err);
6599
6600 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
6601 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
6602 pipeline_layout_ci.pNext = NULL;
6603 pipeline_layout_ci.setLayoutCount = 1;
6604 pipeline_layout_ci.pSetLayouts = &ds_layout;
6605
6606 VkPipelineLayout pipeline_layout;
6607 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
6608 ASSERT_VK_SUCCESS(err);
6609
Mark Mueller5c838ce2016-06-16 09:54:29 -06006610 VkWriteDescriptorSet descriptor_write = {};
Mark Muellerd4914412016-06-13 17:52:06 -06006611 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
6612 descriptor_write.dstSet = descriptorSet;
6613 descriptor_write.dstBinding = 0;
6614 descriptor_write.descriptorCount = 1;
6615 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
6616
Mark Mueller5c838ce2016-06-16 09:54:29 -06006617 // 1) The uniform buffer is intentionally invalid here
Mark Muellerd4914412016-06-13 17:52:06 -06006618 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
6619 m_errorMonitor->VerifyFound();
6620
6621 // Create a buffer to update the descriptor with
6622 uint32_t qfi = 0;
6623 VkBufferCreateInfo buffCI = {};
6624 buffCI.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
6625 buffCI.size = 1024;
6626 buffCI.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
6627 buffCI.queueFamilyIndexCount = 1;
6628 buffCI.pQueueFamilyIndices = &qfi;
6629
6630 VkBuffer dyub;
6631 err = vkCreateBuffer(m_device->device(), &buffCI, NULL, &dyub);
6632 ASSERT_VK_SUCCESS(err);
6633 VkDescriptorBufferInfo buffInfo = {};
6634 buffInfo.buffer = dyub;
6635 buffInfo.offset = 0;
6636 buffInfo.range = 1024;
6637
6638 descriptor_write.pBufferInfo = &buffInfo;
6639 descriptor_write.descriptorCount = 2;
6640
Mark Mueller5c838ce2016-06-16 09:54:29 -06006641 // 2) The stateFlags don't match between the first and second descriptor
Mark Muellerd4914412016-06-13 17:52:06 -06006642 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, stateFlag_ErrorMessage);
6643 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
6644 m_errorMonitor->VerifyFound();
6645
Mark Mueller5c838ce2016-06-16 09:54:29 -06006646 // 3) The second descriptor has a null_ptr pImmutableSamplers and
6647 // the third descriptor contains an immutable sampler
Mark Muellerd4914412016-06-13 17:52:06 -06006648 descriptor_write.dstBinding = 1;
6649 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
Mark Mueller5c838ce2016-06-16 09:54:29 -06006650
Mark Mueller5c838ce2016-06-16 09:54:29 -06006651 // Make pImageInfo index non-null to avoid complaints of it missing
6652 VkDescriptorImageInfo imageInfo = {};
6653 imageInfo.imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
6654 descriptor_write.pImageInfo = &imageInfo;
Mark Muellerd4914412016-06-13 17:52:06 -06006655 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, immutable_ErrorMessage);
6656 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
6657 m_errorMonitor->VerifyFound();
6658
Mark Muellerd4914412016-06-13 17:52:06 -06006659 vkDestroyBuffer(m_device->device(), dyub, NULL);
6660 vkDestroySampler(m_device->device(), sampler, NULL);
6661 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
6662 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
6663 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
6664}
6665
Tobin Ehlis0283c4d2016-06-28 17:57:07 -06006666TEST_F(VkLayerTest, InvalidCmdBufferBufferDestroyed) {
6667 TEST_DESCRIPTION("Attempt to draw with a command buffer that is invalid "
6668 "due to a buffer dependency being destroyed.");
6669 ASSERT_NO_FATAL_FAILURE(InitState());
6670
6671 VkImageObj image(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006672 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 -06006673 VK_IMAGE_TILING_OPTIMAL, 0);
6674 ASSERT_TRUE(image.initialized());
6675
6676 VkBuffer buffer;
6677 VkDeviceMemory mem;
6678 VkMemoryRequirements mem_reqs;
6679
6680 VkBufferCreateInfo buf_info = {};
6681 buf_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
6682 buf_info.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
6683 buf_info.size = 256;
6684 buf_info.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
6685 VkResult err = vkCreateBuffer(m_device->device(), &buf_info, NULL, &buffer);
6686 ASSERT_VK_SUCCESS(err);
6687
6688 vkGetBufferMemoryRequirements(m_device->device(), buffer, &mem_reqs);
6689
6690 VkMemoryAllocateInfo alloc_info = {};
6691 alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
6692 alloc_info.allocationSize = 256;
6693 bool pass = false;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006694 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 -06006695 if (!pass) {
6696 vkDestroyBuffer(m_device->device(), buffer, NULL);
6697 return;
6698 }
6699 err = vkAllocateMemory(m_device->device(), &alloc_info, NULL, &mem);
6700 ASSERT_VK_SUCCESS(err);
6701
6702 err = vkBindBufferMemory(m_device->device(), buffer, mem, 0);
6703 ASSERT_VK_SUCCESS(err);
6704
6705 VkBufferImageCopy region = {};
6706 region.bufferRowLength = 128;
6707 region.bufferImageHeight = 128;
6708 region.imageSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
6709
6710 region.imageSubresource.layerCount = 1;
6711 region.imageExtent.height = 4;
6712 region.imageExtent.width = 4;
6713 region.imageExtent.depth = 1;
6714 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006715 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer, image.handle(), VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1,
6716 &region);
Tobin Ehlis0283c4d2016-06-28 17:57:07 -06006717 m_commandBuffer->EndCommandBuffer();
6718
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006719 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " that is invalid because bound buffer ");
Tobin Ehlis0283c4d2016-06-28 17:57:07 -06006720 // Destroy buffer dependency prior to submit to cause ERROR
6721 vkDestroyBuffer(m_device->device(), buffer, NULL);
6722
6723 VkSubmitInfo submit_info = {};
6724 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
6725 submit_info.commandBufferCount = 1;
6726 submit_info.pCommandBuffers = &m_commandBuffer->handle();
6727 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
6728
6729 m_errorMonitor->VerifyFound();
6730 vkFreeMemory(m_device->handle(), mem, NULL);
6731}
6732
Tobin Ehlis11c8cea2016-06-28 17:44:21 -06006733TEST_F(VkLayerTest, InvalidCmdBufferImageDestroyed) {
6734 TEST_DESCRIPTION("Attempt to draw with a command buffer that is invalid "
6735 "due to an image dependency being destroyed.");
6736 ASSERT_NO_FATAL_FAILURE(InitState());
6737
6738 VkImage image;
6739 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
6740 VkImageCreateInfo image_create_info = {};
6741 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
6742 image_create_info.pNext = NULL;
6743 image_create_info.imageType = VK_IMAGE_TYPE_2D;
6744 image_create_info.format = tex_format;
6745 image_create_info.extent.width = 32;
6746 image_create_info.extent.height = 32;
6747 image_create_info.extent.depth = 1;
6748 image_create_info.mipLevels = 1;
6749 image_create_info.arrayLayers = 1;
6750 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
6751 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006752 image_create_info.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT;
Tobin Ehlis11c8cea2016-06-28 17:44:21 -06006753 image_create_info.flags = 0;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006754 VkResult err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
Tobin Ehlis11c8cea2016-06-28 17:44:21 -06006755 ASSERT_VK_SUCCESS(err);
Tobin Ehlis3d09fd52016-07-06 08:12:56 -06006756 // Have to bind memory to image before recording cmd in cmd buffer using it
6757 VkMemoryRequirements mem_reqs;
6758 VkDeviceMemory image_mem;
6759 bool pass;
6760 VkMemoryAllocateInfo mem_alloc = {};
6761 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
6762 mem_alloc.pNext = NULL;
6763 mem_alloc.memoryTypeIndex = 0;
6764 vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs);
6765 mem_alloc.allocationSize = mem_reqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006766 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0);
Tobin Ehlis3d09fd52016-07-06 08:12:56 -06006767 ASSERT_TRUE(pass);
6768 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &image_mem);
6769 ASSERT_VK_SUCCESS(err);
6770 err = vkBindImageMemory(m_device->device(), image, image_mem, 0);
6771 ASSERT_VK_SUCCESS(err);
Tobin Ehlis11c8cea2016-06-28 17:44:21 -06006772
Tobin Ehlis11c8cea2016-06-28 17:44:21 -06006773 m_commandBuffer->BeginCommandBuffer();
Tobin Ehlis764d7072016-07-01 12:54:29 -06006774 VkClearColorValue ccv;
6775 ccv.float32[0] = 1.0f;
6776 ccv.float32[1] = 1.0f;
6777 ccv.float32[2] = 1.0f;
6778 ccv.float32[3] = 1.0f;
6779 VkImageSubresourceRange isr = {};
6780 isr.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Tobin Ehlis3d09fd52016-07-06 08:12:56 -06006781 isr.baseArrayLayer = 0;
6782 isr.baseMipLevel = 0;
Tobin Ehlis764d7072016-07-01 12:54:29 -06006783 isr.layerCount = 1;
6784 isr.levelCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006785 vkCmdClearColorImage(m_commandBuffer->GetBufferHandle(), image, VK_IMAGE_LAYOUT_GENERAL, &ccv, 1, &isr);
Tobin Ehlis11c8cea2016-06-28 17:44:21 -06006786 m_commandBuffer->EndCommandBuffer();
6787
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006788 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " that is invalid because bound image ");
Tobin Ehlis11c8cea2016-06-28 17:44:21 -06006789 // Destroy image dependency prior to submit to cause ERROR
6790 vkDestroyImage(m_device->device(), image, NULL);
6791
6792 VkSubmitInfo submit_info = {};
6793 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
6794 submit_info.commandBufferCount = 1;
6795 submit_info.pCommandBuffers = &m_commandBuffer->handle();
6796 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
6797
6798 m_errorMonitor->VerifyFound();
Tobin Ehlis3d09fd52016-07-06 08:12:56 -06006799 vkFreeMemory(m_device->device(), image_mem, nullptr);
Tobin Ehlis11c8cea2016-06-28 17:44:21 -06006800}
6801
Tobin Ehlis59f68ab2016-09-06 21:59:07 -06006802TEST_F(VkLayerTest, InvalidCmdBufferFramebufferImageDestroyed) {
6803 TEST_DESCRIPTION("Attempt to draw with a command buffer that is invalid "
6804 "due to a framebuffer image dependency being destroyed.");
6805 VkFormatProperties format_properties;
6806 VkResult err = VK_SUCCESS;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006807 vkGetPhysicalDeviceFormatProperties(gpu(), VK_FORMAT_B8G8R8A8_UNORM, &format_properties);
6808 if (!(format_properties.optimalTilingFeatures & VK_FORMAT_FEATURE_SAMPLED_IMAGE_BIT)) {
Tobin Ehlis59f68ab2016-09-06 21:59:07 -06006809 return;
6810 }
6811
6812 ASSERT_NO_FATAL_FAILURE(InitState());
6813 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
6814
6815 VkImageCreateInfo image_ci = {};
6816 image_ci.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
6817 image_ci.pNext = NULL;
6818 image_ci.imageType = VK_IMAGE_TYPE_2D;
6819 image_ci.format = VK_FORMAT_B8G8R8A8_UNORM;
6820 image_ci.extent.width = 32;
6821 image_ci.extent.height = 32;
6822 image_ci.extent.depth = 1;
6823 image_ci.mipLevels = 1;
6824 image_ci.arrayLayers = 1;
6825 image_ci.samples = VK_SAMPLE_COUNT_1_BIT;
6826 image_ci.tiling = VK_IMAGE_TILING_OPTIMAL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006827 image_ci.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_SAMPLED_BIT;
Tobin Ehlis59f68ab2016-09-06 21:59:07 -06006828 image_ci.initialLayout = VK_IMAGE_LAYOUT_UNDEFINED;
6829 image_ci.flags = 0;
6830 VkImage image;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006831 ASSERT_VK_SUCCESS(vkCreateImage(m_device->handle(), &image_ci, NULL, &image));
Tobin Ehlis59f68ab2016-09-06 21:59:07 -06006832
6833 VkMemoryRequirements memory_reqs;
6834 VkDeviceMemory image_memory;
6835 bool pass;
6836 VkMemoryAllocateInfo memory_info = {};
6837 memory_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
6838 memory_info.pNext = NULL;
6839 memory_info.allocationSize = 0;
6840 memory_info.memoryTypeIndex = 0;
6841 vkGetImageMemoryRequirements(m_device->device(), image, &memory_reqs);
6842 memory_info.allocationSize = memory_reqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006843 pass = m_device->phy().set_memory_type(memory_reqs.memoryTypeBits, &memory_info, 0);
Tobin Ehlis59f68ab2016-09-06 21:59:07 -06006844 ASSERT_TRUE(pass);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006845 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &image_memory);
Tobin Ehlis59f68ab2016-09-06 21:59:07 -06006846 ASSERT_VK_SUCCESS(err);
6847 err = vkBindImageMemory(m_device->device(), image, image_memory, 0);
6848 ASSERT_VK_SUCCESS(err);
6849
6850 VkImageViewCreateInfo ivci = {
6851 VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO,
6852 nullptr,
6853 0,
6854 image,
6855 VK_IMAGE_VIEW_TYPE_2D,
6856 VK_FORMAT_B8G8R8A8_UNORM,
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006857 {VK_COMPONENT_SWIZZLE_R, VK_COMPONENT_SWIZZLE_G, VK_COMPONENT_SWIZZLE_B, VK_COMPONENT_SWIZZLE_A},
Tobin Ehlis59f68ab2016-09-06 21:59:07 -06006858 {VK_IMAGE_ASPECT_COLOR_BIT, 0, 1, 0, 1},
6859 };
6860 VkImageView view;
6861 err = vkCreateImageView(m_device->device(), &ivci, nullptr, &view);
6862 ASSERT_VK_SUCCESS(err);
6863
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006864 VkFramebufferCreateInfo fci = {VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr, 0, m_renderPass, 1, &view, 32, 32, 1};
Tobin Ehlis59f68ab2016-09-06 21:59:07 -06006865 VkFramebuffer fb;
6866 err = vkCreateFramebuffer(m_device->device(), &fci, nullptr, &fb);
6867 ASSERT_VK_SUCCESS(err);
6868
6869 // Just use default renderpass with our framebuffer
6870 m_renderPassBeginInfo.framebuffer = fb;
6871 // Create Null cmd buffer for submit
6872 BeginCommandBuffer();
6873 EndCommandBuffer();
6874 // Destroy image attached to framebuffer to invalidate cmd buffer
6875 vkDestroyImage(m_device->device(), image, NULL);
6876 // Now attempt to submit cmd buffer and verify error
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006877 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " that is invalid because bound image ");
Tobin Ehlis59f68ab2016-09-06 21:59:07 -06006878 QueueCommandBuffer(false);
6879 m_errorMonitor->VerifyFound();
6880
6881 vkDestroyFramebuffer(m_device->device(), fb, nullptr);
6882 vkDestroyImageView(m_device->device(), view, nullptr);
6883 vkFreeMemory(m_device->device(), image_memory, nullptr);
6884}
6885
Mark Lobodzinskia4df3632016-07-14 09:57:41 -06006886TEST_F(VkLayerTest, ImageMemoryNotBound) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006887 TEST_DESCRIPTION("Attempt to draw with an image which has not had memory bound to it.");
Mark Lobodzinskia4df3632016-07-14 09:57:41 -06006888 ASSERT_NO_FATAL_FAILURE(InitState());
6889
6890 VkImage image;
6891 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
6892 VkImageCreateInfo image_create_info = {};
6893 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
6894 image_create_info.pNext = NULL;
6895 image_create_info.imageType = VK_IMAGE_TYPE_2D;
6896 image_create_info.format = tex_format;
6897 image_create_info.extent.width = 32;
6898 image_create_info.extent.height = 32;
6899 image_create_info.extent.depth = 1;
6900 image_create_info.mipLevels = 1;
6901 image_create_info.arrayLayers = 1;
6902 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
6903 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006904 image_create_info.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT;
Mark Lobodzinskia4df3632016-07-14 09:57:41 -06006905 image_create_info.flags = 0;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006906 VkResult err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
Mark Lobodzinskia4df3632016-07-14 09:57:41 -06006907 ASSERT_VK_SUCCESS(err);
6908 // Have to bind memory to image before recording cmd in cmd buffer using it
6909 VkMemoryRequirements mem_reqs;
6910 VkDeviceMemory image_mem;
6911 bool pass;
6912 VkMemoryAllocateInfo mem_alloc = {};
6913 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
6914 mem_alloc.pNext = NULL;
6915 mem_alloc.memoryTypeIndex = 0;
6916 vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs);
6917 mem_alloc.allocationSize = mem_reqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006918 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0);
Mark Lobodzinskia4df3632016-07-14 09:57:41 -06006919 ASSERT_TRUE(pass);
6920 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &image_mem);
6921 ASSERT_VK_SUCCESS(err);
6922
6923 // Introduce error, do not call vkBindImageMemory(m_device->device(), image,
6924 // image_mem, 0);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006925 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "used without first calling vkBindImageMemory");
Mark Lobodzinskia4df3632016-07-14 09:57:41 -06006926
6927 m_commandBuffer->BeginCommandBuffer();
6928 VkClearColorValue ccv;
6929 ccv.float32[0] = 1.0f;
6930 ccv.float32[1] = 1.0f;
6931 ccv.float32[2] = 1.0f;
6932 ccv.float32[3] = 1.0f;
6933 VkImageSubresourceRange isr = {};
6934 isr.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
6935 isr.baseArrayLayer = 0;
6936 isr.baseMipLevel = 0;
6937 isr.layerCount = 1;
6938 isr.levelCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006939 vkCmdClearColorImage(m_commandBuffer->GetBufferHandle(), image, VK_IMAGE_LAYOUT_GENERAL, &ccv, 1, &isr);
Mark Lobodzinskia4df3632016-07-14 09:57:41 -06006940 m_commandBuffer->EndCommandBuffer();
6941
6942 m_errorMonitor->VerifyFound();
6943 vkDestroyImage(m_device->device(), image, NULL);
6944 vkFreeMemory(m_device->device(), image_mem, nullptr);
6945}
6946
6947TEST_F(VkLayerTest, BufferMemoryNotBound) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006948 TEST_DESCRIPTION("Attempt to copy from a buffer which has not had memory bound to it.");
Mark Lobodzinskia4df3632016-07-14 09:57:41 -06006949 ASSERT_NO_FATAL_FAILURE(InitState());
6950
6951 VkImageObj image(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006952 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 -06006953 VK_IMAGE_TILING_OPTIMAL, 0);
6954 ASSERT_TRUE(image.initialized());
6955
6956 VkBuffer buffer;
6957 VkDeviceMemory mem;
6958 VkMemoryRequirements mem_reqs;
6959
6960 VkBufferCreateInfo buf_info = {};
6961 buf_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
6962 buf_info.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
6963 buf_info.size = 256;
6964 buf_info.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
6965 VkResult err = vkCreateBuffer(m_device->device(), &buf_info, NULL, &buffer);
6966 ASSERT_VK_SUCCESS(err);
6967
6968 vkGetBufferMemoryRequirements(m_device->device(), buffer, &mem_reqs);
6969
6970 VkMemoryAllocateInfo alloc_info = {};
6971 alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
6972 alloc_info.allocationSize = 256;
6973 bool pass = false;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006974 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 -06006975 if (!pass) {
6976 vkDestroyBuffer(m_device->device(), buffer, NULL);
6977 return;
6978 }
6979 err = vkAllocateMemory(m_device->device(), &alloc_info, NULL, &mem);
6980 ASSERT_VK_SUCCESS(err);
6981
6982 // Introduce failure by not calling vkBindBufferMemory(m_device->device(),
6983 // buffer, mem, 0);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006984 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "used without first calling vkBindBufferMemory");
Mark Lobodzinskia4df3632016-07-14 09:57:41 -06006985 VkBufferImageCopy region = {};
6986 region.bufferRowLength = 128;
6987 region.bufferImageHeight = 128;
6988 region.imageSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
6989
6990 region.imageSubresource.layerCount = 1;
6991 region.imageExtent.height = 4;
6992 region.imageExtent.width = 4;
6993 region.imageExtent.depth = 1;
6994 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006995 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer, image.handle(), VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1,
6996 &region);
Mark Lobodzinskia4df3632016-07-14 09:57:41 -06006997 m_commandBuffer->EndCommandBuffer();
6998
6999 m_errorMonitor->VerifyFound();
7000
7001 vkDestroyBuffer(m_device->device(), buffer, NULL);
7002 vkFreeMemory(m_device->handle(), mem, NULL);
7003}
7004
Tobin Ehlis85940f52016-07-07 16:57:21 -06007005TEST_F(VkLayerTest, InvalidCmdBufferEventDestroyed) {
7006 TEST_DESCRIPTION("Attempt to draw with a command buffer that is invalid "
7007 "due to an event dependency being destroyed.");
7008 ASSERT_NO_FATAL_FAILURE(InitState());
7009
7010 VkEvent event;
7011 VkEventCreateInfo evci = {};
7012 evci.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO;
7013 VkResult result = vkCreateEvent(m_device->device(), &evci, NULL, &event);
7014 ASSERT_VK_SUCCESS(result);
7015
7016 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007017 vkCmdSetEvent(m_commandBuffer->GetBufferHandle(), event, VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT);
Tobin Ehlis85940f52016-07-07 16:57:21 -06007018 m_commandBuffer->EndCommandBuffer();
7019
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007020 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " that is invalid because bound event ");
Tobin Ehlis85940f52016-07-07 16:57:21 -06007021 // Destroy event dependency prior to submit to cause ERROR
7022 vkDestroyEvent(m_device->device(), event, NULL);
7023
7024 VkSubmitInfo submit_info = {};
7025 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
7026 submit_info.commandBufferCount = 1;
7027 submit_info.pCommandBuffers = &m_commandBuffer->handle();
7028 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
7029
7030 m_errorMonitor->VerifyFound();
7031}
7032
Tobin Ehlisdbea7552016-07-08 14:33:31 -06007033TEST_F(VkLayerTest, InvalidCmdBufferQueryPoolDestroyed) {
7034 TEST_DESCRIPTION("Attempt to draw with a command buffer that is invalid "
7035 "due to a query pool dependency being destroyed.");
7036 ASSERT_NO_FATAL_FAILURE(InitState());
7037
7038 VkQueryPool query_pool;
7039 VkQueryPoolCreateInfo qpci{};
7040 qpci.sType = VK_STRUCTURE_TYPE_QUERY_POOL_CREATE_INFO;
7041 qpci.queryType = VK_QUERY_TYPE_TIMESTAMP;
7042 qpci.queryCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007043 VkResult result = vkCreateQueryPool(m_device->device(), &qpci, nullptr, &query_pool);
Tobin Ehlisdbea7552016-07-08 14:33:31 -06007044 ASSERT_VK_SUCCESS(result);
7045
7046 m_commandBuffer->BeginCommandBuffer();
7047 vkCmdResetQueryPool(m_commandBuffer->GetBufferHandle(), query_pool, 0, 1);
7048 m_commandBuffer->EndCommandBuffer();
7049
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007050 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " that is invalid because bound query pool ");
Tobin Ehlisdbea7552016-07-08 14:33:31 -06007051 // Destroy query pool dependency prior to submit to cause ERROR
7052 vkDestroyQueryPool(m_device->device(), query_pool, NULL);
7053
7054 VkSubmitInfo submit_info = {};
7055 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
7056 submit_info.commandBufferCount = 1;
7057 submit_info.pCommandBuffers = &m_commandBuffer->handle();
7058 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
7059
7060 m_errorMonitor->VerifyFound();
7061}
7062
Tobin Ehlis24130d92016-07-08 15:50:53 -06007063TEST_F(VkLayerTest, InvalidCmdBufferPipelineDestroyed) {
7064 TEST_DESCRIPTION("Attempt to draw with a command buffer that is invalid "
7065 "due to a pipeline dependency being destroyed.");
7066 ASSERT_NO_FATAL_FAILURE(InitState());
7067 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
7068
7069 VkResult err;
7070
7071 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
7072 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
7073
7074 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007075 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis24130d92016-07-08 15:50:53 -06007076 ASSERT_VK_SUCCESS(err);
7077
7078 VkPipelineViewportStateCreateInfo vp_state_ci = {};
7079 vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
7080 vp_state_ci.viewportCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007081 VkViewport vp = {}; // Just need dummy vp to point to
Tobin Ehlis52b504f2016-07-19 13:25:12 -06007082 vp_state_ci.pViewports = &vp;
Tobin Ehlis24130d92016-07-08 15:50:53 -06007083 vp_state_ci.scissorCount = 1;
7084 VkRect2D scissors = {}; // Dummy scissors to point to
7085 vp_state_ci.pScissors = &scissors;
7086 // No dynamic state
7087 VkPipelineDynamicStateCreateInfo dyn_state_ci = {};
7088 dyn_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_DYNAMIC_STATE_CREATE_INFO;
7089
7090 VkPipelineShaderStageCreateInfo shaderStages[2];
7091 memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo));
7092
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007093 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
7094 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this); // We shouldn't need a fragment shader
7095 // but add it to be able to run on more devices
Tobin Ehlis24130d92016-07-08 15:50:53 -06007096 shaderStages[0] = vs.GetStageCreateInfo();
7097 shaderStages[1] = fs.GetStageCreateInfo();
7098
7099 VkPipelineVertexInputStateCreateInfo vi_ci = {};
7100 vi_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
7101
7102 VkPipelineInputAssemblyStateCreateInfo ia_ci = {};
7103 ia_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
7104 ia_ci.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP;
7105
7106 VkPipelineRasterizationStateCreateInfo rs_ci = {};
7107 rs_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
7108
7109 VkPipelineColorBlendAttachmentState att = {};
7110 att.blendEnable = VK_FALSE;
7111 att.colorWriteMask = 0xf;
7112
7113 VkPipelineColorBlendStateCreateInfo cb_ci = {};
7114 cb_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO;
7115 cb_ci.attachmentCount = 1;
7116 cb_ci.pAttachments = &att;
7117
7118 VkGraphicsPipelineCreateInfo gp_ci = {};
7119 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
7120 gp_ci.stageCount = 2;
7121 gp_ci.pStages = shaderStages;
7122 gp_ci.pVertexInputState = &vi_ci;
7123 gp_ci.pInputAssemblyState = &ia_ci;
7124 gp_ci.pViewportState = &vp_state_ci;
7125 gp_ci.pRasterizationState = &rs_ci;
7126 gp_ci.pColorBlendState = &cb_ci;
7127 gp_ci.pDynamicState = &dyn_state_ci;
7128 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
7129 gp_ci.layout = pipeline_layout;
7130 gp_ci.renderPass = renderPass();
7131
7132 VkPipelineCacheCreateInfo pc_ci = {};
7133 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
7134
7135 VkPipeline pipeline;
7136 VkPipelineCache pipelineCache;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007137 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Tobin Ehlis24130d92016-07-08 15:50:53 -06007138 ASSERT_VK_SUCCESS(err);
7139
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007140 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Tobin Ehlis24130d92016-07-08 15:50:53 -06007141 ASSERT_VK_SUCCESS(err);
7142
7143 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007144 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline);
Tobin Ehlis24130d92016-07-08 15:50:53 -06007145 m_commandBuffer->EndCommandBuffer();
7146 // Now destroy pipeline in order to cause error when submitting
7147 vkDestroyPipeline(m_device->device(), pipeline, nullptr);
7148
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007149 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " that is invalid because bound pipeline ");
Tobin Ehlis24130d92016-07-08 15:50:53 -06007150
7151 VkSubmitInfo submit_info = {};
7152 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
7153 submit_info.commandBufferCount = 1;
7154 submit_info.pCommandBuffers = &m_commandBuffer->handle();
7155 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
7156
7157 m_errorMonitor->VerifyFound();
7158 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
7159 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
7160}
7161
Tobin Ehlis31289162016-08-17 14:57:58 -06007162TEST_F(VkLayerTest, InvalidCmdBufferDescriptorSetBufferDestroyed) {
7163 TEST_DESCRIPTION("Attempt to draw with a command buffer that is invalid "
7164 "due to a bound descriptor set with a buffer dependency "
7165 "being destroyed.");
7166 ASSERT_NO_FATAL_FAILURE(InitState());
7167 ASSERT_NO_FATAL_FAILURE(InitViewport());
7168 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
7169
7170 VkDescriptorPoolSize ds_type_count = {};
7171 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
7172 ds_type_count.descriptorCount = 1;
7173
7174 VkDescriptorPoolCreateInfo ds_pool_ci = {};
7175 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
7176 ds_pool_ci.pNext = NULL;
7177 ds_pool_ci.maxSets = 1;
7178 ds_pool_ci.poolSizeCount = 1;
7179 ds_pool_ci.pPoolSizes = &ds_type_count;
7180
7181 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007182 VkResult err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis31289162016-08-17 14:57:58 -06007183 ASSERT_VK_SUCCESS(err);
7184
7185 VkDescriptorSetLayoutBinding dsl_binding = {};
7186 dsl_binding.binding = 0;
7187 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
7188 dsl_binding.descriptorCount = 1;
7189 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
7190 dsl_binding.pImmutableSamplers = NULL;
7191
7192 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
7193 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
7194 ds_layout_ci.pNext = NULL;
7195 ds_layout_ci.bindingCount = 1;
7196 ds_layout_ci.pBindings = &dsl_binding;
7197 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007198 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis31289162016-08-17 14:57:58 -06007199 ASSERT_VK_SUCCESS(err);
7200
7201 VkDescriptorSet descriptorSet;
7202 VkDescriptorSetAllocateInfo alloc_info = {};
7203 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
7204 alloc_info.descriptorSetCount = 1;
7205 alloc_info.descriptorPool = ds_pool;
7206 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007207 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis31289162016-08-17 14:57:58 -06007208 ASSERT_VK_SUCCESS(err);
7209
7210 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
7211 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
7212 pipeline_layout_ci.pNext = NULL;
7213 pipeline_layout_ci.setLayoutCount = 1;
7214 pipeline_layout_ci.pSetLayouts = &ds_layout;
7215
7216 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007217 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis31289162016-08-17 14:57:58 -06007218 ASSERT_VK_SUCCESS(err);
7219
7220 // Create a buffer to update the descriptor with
7221 uint32_t qfi = 0;
7222 VkBufferCreateInfo buffCI = {};
7223 buffCI.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
7224 buffCI.size = 1024;
7225 buffCI.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
7226 buffCI.queueFamilyIndexCount = 1;
7227 buffCI.pQueueFamilyIndices = &qfi;
7228
7229 VkBuffer buffer;
7230 err = vkCreateBuffer(m_device->device(), &buffCI, NULL, &buffer);
7231 ASSERT_VK_SUCCESS(err);
7232 // Allocate memory and bind to buffer so we can make it to the appropriate
7233 // error
7234 VkMemoryAllocateInfo mem_alloc = {};
7235 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
7236 mem_alloc.pNext = NULL;
7237 mem_alloc.allocationSize = 1024;
7238 mem_alloc.memoryTypeIndex = 0;
7239
7240 VkMemoryRequirements memReqs;
7241 vkGetBufferMemoryRequirements(m_device->device(), buffer, &memReqs);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007242 bool pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &mem_alloc, 0);
Tobin Ehlis31289162016-08-17 14:57:58 -06007243 if (!pass) {
7244 vkDestroyBuffer(m_device->device(), buffer, NULL);
7245 return;
7246 }
7247
7248 VkDeviceMemory mem;
7249 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem);
7250 ASSERT_VK_SUCCESS(err);
7251 err = vkBindBufferMemory(m_device->device(), buffer, mem, 0);
7252 ASSERT_VK_SUCCESS(err);
7253 // Correctly update descriptor to avoid "NOT_UPDATED" error
7254 VkDescriptorBufferInfo buffInfo = {};
7255 buffInfo.buffer = buffer;
7256 buffInfo.offset = 0;
7257 buffInfo.range = 1024;
7258
7259 VkWriteDescriptorSet descriptor_write;
7260 memset(&descriptor_write, 0, sizeof(descriptor_write));
7261 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
7262 descriptor_write.dstSet = descriptorSet;
7263 descriptor_write.dstBinding = 0;
7264 descriptor_write.descriptorCount = 1;
7265 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
7266 descriptor_write.pBufferInfo = &buffInfo;
7267
7268 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
7269
7270 // Create PSO to be used for draw-time errors below
7271 char const *vsSource = "#version 450\n"
7272 "\n"
7273 "out gl_PerVertex { \n"
7274 " vec4 gl_Position;\n"
7275 "};\n"
7276 "void main(){\n"
7277 " gl_Position = vec4(1);\n"
7278 "}\n";
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007279 char const *fsSource = "#version 450\n"
7280 "\n"
7281 "layout(location=0) out vec4 x;\n"
7282 "layout(set=0) layout(binding=0) uniform foo { int x; int y; } bar;\n"
7283 "void main(){\n"
7284 " x = vec4(bar.y);\n"
7285 "}\n";
Tobin Ehlis31289162016-08-17 14:57:58 -06007286 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
7287 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
7288 VkPipelineObj pipe(m_device);
7289 pipe.AddShader(&vs);
7290 pipe.AddShader(&fs);
7291 pipe.AddColorAttachment();
7292 pipe.CreateVKPipeline(pipeline_layout, renderPass());
7293
7294 BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007295 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
7296 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
7297 &descriptorSet, 0, NULL);
Tobin Ehlis31289162016-08-17 14:57:58 -06007298 Draw(1, 0, 0, 0);
7299 EndCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007300 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " that is invalid because bound buffer ");
Tobin Ehlis31289162016-08-17 14:57:58 -06007301 // Destroy buffer should invalidate the cmd buffer, causing error on submit
7302 vkDestroyBuffer(m_device->device(), buffer, NULL);
7303 // Attempt to submit cmd buffer
7304 VkSubmitInfo submit_info = {};
7305 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
7306 submit_info.commandBufferCount = 1;
7307 submit_info.pCommandBuffers = &m_commandBuffer->handle();
7308 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
7309 m_errorMonitor->VerifyFound();
7310 // Cleanup
7311 vkFreeMemory(m_device->device(), mem, NULL);
7312
7313 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
7314 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
7315 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
7316}
7317
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06007318TEST_F(VkLayerTest, InvalidCmdBufferDescriptorSetImageSamplerDestroyed) {
7319 TEST_DESCRIPTION("Attempt to draw with a command buffer that is invalid "
7320 "due to a bound descriptor sets with a combined image "
7321 "sampler having their image, sampler, and descriptor set "
7322 "each respectively destroyed and then attempting to "
Mark Mueller917f6bc2016-08-30 10:57:19 -06007323 "submit associated cmd buffers. Attempt to destroy a "
7324 "DescriptorSet that is in use.");
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06007325 ASSERT_NO_FATAL_FAILURE(InitState());
7326 ASSERT_NO_FATAL_FAILURE(InitViewport());
7327 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
7328
7329 VkDescriptorPoolSize ds_type_count = {};
7330 ds_type_count.type = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
7331 ds_type_count.descriptorCount = 1;
7332
7333 VkDescriptorPoolCreateInfo ds_pool_ci = {};
7334 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
7335 ds_pool_ci.pNext = NULL;
7336 ds_pool_ci.maxSets = 1;
7337 ds_pool_ci.poolSizeCount = 1;
7338 ds_pool_ci.pPoolSizes = &ds_type_count;
7339
7340 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007341 VkResult err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06007342 ASSERT_VK_SUCCESS(err);
7343
7344 VkDescriptorSetLayoutBinding dsl_binding = {};
7345 dsl_binding.binding = 0;
7346 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
7347 dsl_binding.descriptorCount = 1;
7348 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
7349 dsl_binding.pImmutableSamplers = NULL;
7350
7351 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
7352 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
7353 ds_layout_ci.pNext = NULL;
7354 ds_layout_ci.bindingCount = 1;
7355 ds_layout_ci.pBindings = &dsl_binding;
7356 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007357 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06007358 ASSERT_VK_SUCCESS(err);
7359
7360 VkDescriptorSet descriptorSet;
7361 VkDescriptorSetAllocateInfo alloc_info = {};
7362 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
7363 alloc_info.descriptorSetCount = 1;
7364 alloc_info.descriptorPool = ds_pool;
7365 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007366 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06007367 ASSERT_VK_SUCCESS(err);
7368
7369 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
7370 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
7371 pipeline_layout_ci.pNext = NULL;
7372 pipeline_layout_ci.setLayoutCount = 1;
7373 pipeline_layout_ci.pSetLayouts = &ds_layout;
7374
7375 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007376 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06007377 ASSERT_VK_SUCCESS(err);
7378
7379 // Create images to update the descriptor with
7380 VkImage image;
7381 VkImage image2;
7382 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
7383 const int32_t tex_width = 32;
7384 const int32_t tex_height = 32;
7385 VkImageCreateInfo image_create_info = {};
7386 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
7387 image_create_info.pNext = NULL;
7388 image_create_info.imageType = VK_IMAGE_TYPE_2D;
7389 image_create_info.format = tex_format;
7390 image_create_info.extent.width = tex_width;
7391 image_create_info.extent.height = tex_height;
7392 image_create_info.extent.depth = 1;
7393 image_create_info.mipLevels = 1;
7394 image_create_info.arrayLayers = 1;
7395 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
7396 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
7397 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
7398 image_create_info.flags = 0;
7399 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
7400 ASSERT_VK_SUCCESS(err);
7401 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image2);
7402 ASSERT_VK_SUCCESS(err);
7403
7404 VkMemoryRequirements memory_reqs;
7405 VkDeviceMemory image_memory;
7406 bool pass;
7407 VkMemoryAllocateInfo memory_info = {};
7408 memory_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
7409 memory_info.pNext = NULL;
7410 memory_info.allocationSize = 0;
7411 memory_info.memoryTypeIndex = 0;
7412 vkGetImageMemoryRequirements(m_device->device(), image, &memory_reqs);
7413 // Allocate enough memory for both images
7414 memory_info.allocationSize = memory_reqs.size * 2;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007415 pass = m_device->phy().set_memory_type(memory_reqs.memoryTypeBits, &memory_info, 0);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06007416 ASSERT_TRUE(pass);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007417 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &image_memory);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06007418 ASSERT_VK_SUCCESS(err);
7419 err = vkBindImageMemory(m_device->device(), image, image_memory, 0);
7420 ASSERT_VK_SUCCESS(err);
7421 // Bind second image to memory right after first image
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007422 err = vkBindImageMemory(m_device->device(), image2, image_memory, memory_reqs.size);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06007423 ASSERT_VK_SUCCESS(err);
7424
7425 VkImageViewCreateInfo image_view_create_info = {};
7426 image_view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
7427 image_view_create_info.image = image;
7428 image_view_create_info.viewType = VK_IMAGE_VIEW_TYPE_2D;
7429 image_view_create_info.format = tex_format;
7430 image_view_create_info.subresourceRange.layerCount = 1;
7431 image_view_create_info.subresourceRange.baseMipLevel = 0;
7432 image_view_create_info.subresourceRange.levelCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007433 image_view_create_info.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06007434
7435 VkImageView view;
7436 VkImageView view2;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007437 err = vkCreateImageView(m_device->device(), &image_view_create_info, NULL, &view);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06007438 ASSERT_VK_SUCCESS(err);
7439 image_view_create_info.image = image2;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007440 err = vkCreateImageView(m_device->device(), &image_view_create_info, NULL, &view2);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06007441 ASSERT_VK_SUCCESS(err);
7442 // Create Samplers
7443 VkSamplerCreateInfo sampler_ci = {};
7444 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
7445 sampler_ci.pNext = NULL;
7446 sampler_ci.magFilter = VK_FILTER_NEAREST;
7447 sampler_ci.minFilter = VK_FILTER_NEAREST;
7448 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
7449 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
7450 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
7451 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
7452 sampler_ci.mipLodBias = 1.0;
7453 sampler_ci.anisotropyEnable = VK_FALSE;
7454 sampler_ci.maxAnisotropy = 1;
7455 sampler_ci.compareEnable = VK_FALSE;
7456 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
7457 sampler_ci.minLod = 1.0;
7458 sampler_ci.maxLod = 1.0;
7459 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
7460 sampler_ci.unnormalizedCoordinates = VK_FALSE;
7461 VkSampler sampler;
7462 VkSampler sampler2;
7463 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
7464 ASSERT_VK_SUCCESS(err);
7465 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler2);
7466 ASSERT_VK_SUCCESS(err);
7467 // Update descriptor with image and sampler
7468 VkDescriptorImageInfo img_info = {};
7469 img_info.sampler = sampler;
7470 img_info.imageView = view;
7471 img_info.imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
7472
7473 VkWriteDescriptorSet descriptor_write;
7474 memset(&descriptor_write, 0, sizeof(descriptor_write));
7475 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
7476 descriptor_write.dstSet = descriptorSet;
7477 descriptor_write.dstBinding = 0;
7478 descriptor_write.descriptorCount = 1;
7479 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
7480 descriptor_write.pImageInfo = &img_info;
7481
7482 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
7483
7484 // Create PSO to be used for draw-time errors below
7485 char const *vsSource = "#version 450\n"
7486 "\n"
7487 "out gl_PerVertex { \n"
7488 " vec4 gl_Position;\n"
7489 "};\n"
7490 "void main(){\n"
7491 " gl_Position = vec4(1);\n"
7492 "}\n";
7493 char const *fsSource = "#version 450\n"
7494 "\n"
7495 "layout(set=0, binding=0) uniform sampler2D s;\n"
7496 "layout(location=0) out vec4 x;\n"
7497 "void main(){\n"
7498 " x = texture(s, vec2(1));\n"
7499 "}\n";
7500 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
7501 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
7502 VkPipelineObj pipe(m_device);
7503 pipe.AddShader(&vs);
7504 pipe.AddShader(&fs);
7505 pipe.AddColorAttachment();
7506 pipe.CreateVKPipeline(pipeline_layout, renderPass());
7507
7508 // First error case is destroying sampler prior to cmd buffer submission
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007509 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Cannot submit cmd buffer using deleted sampler ");
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06007510 BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007511 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
7512 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
7513 &descriptorSet, 0, NULL);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06007514 Draw(1, 0, 0, 0);
7515 EndCommandBuffer();
7516 // Destroy sampler invalidates the cmd buffer, causing error on submit
7517 vkDestroySampler(m_device->device(), sampler, NULL);
7518 // Attempt to submit cmd buffer
7519 VkSubmitInfo submit_info = {};
7520 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
7521 submit_info.commandBufferCount = 1;
7522 submit_info.pCommandBuffers = &m_commandBuffer->handle();
7523 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
7524 m_errorMonitor->VerifyFound();
7525 // Now re-update descriptor with valid sampler and delete image
7526 img_info.sampler = sampler2;
7527 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007528 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " that is invalid because bound image ");
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06007529 BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007530 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
7531 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
7532 &descriptorSet, 0, NULL);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06007533 Draw(1, 0, 0, 0);
7534 EndCommandBuffer();
7535 // Destroy image invalidates the cmd buffer, causing error on submit
7536 vkDestroyImage(m_device->device(), image, NULL);
7537 // Attempt to submit cmd buffer
7538 submit_info = {};
7539 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
7540 submit_info.commandBufferCount = 1;
7541 submit_info.pCommandBuffers = &m_commandBuffer->handle();
7542 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
7543 m_errorMonitor->VerifyFound();
7544 // Now update descriptor to be valid, but then free descriptor
7545 img_info.imageView = view2;
7546 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007547 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " that is invalid because bound descriptor set ");
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06007548 BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007549 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
7550 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
7551 &descriptorSet, 0, NULL);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06007552 Draw(1, 0, 0, 0);
7553 EndCommandBuffer();
7554 // Destroy descriptor set invalidates the cb, causing error on submit
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007555 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Cannot call vkFreeDescriptorSets() on descriptor set 0x");
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06007556 vkFreeDescriptorSets(m_device->device(), ds_pool, 1, &descriptorSet);
Mark Mueller917f6bc2016-08-30 10:57:19 -06007557 m_errorMonitor->VerifyFound();
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06007558 // Attempt to submit cmd buffer
7559 submit_info = {};
7560 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
7561 submit_info.commandBufferCount = 1;
7562 submit_info.pCommandBuffers = &m_commandBuffer->handle();
7563 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
7564 m_errorMonitor->VerifyFound();
7565 // Cleanup
7566 vkFreeMemory(m_device->device(), image_memory, NULL);
7567 vkDestroySampler(m_device->device(), sampler2, NULL);
7568 vkDestroyImage(m_device->device(), image2, NULL);
7569 vkDestroyImageView(m_device->device(), view, NULL);
7570 vkDestroyImageView(m_device->device(), view2, NULL);
7571 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
7572 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
7573 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
7574}
7575
Karl Schultz6addd812016-02-02 17:17:23 -07007576TEST_F(VkLayerTest, InvalidPipeline) {
Karl Schultzbdb75952016-04-19 11:36:49 -06007577 // Attempt to bind an invalid Pipeline to a valid Command Buffer
7578 // ObjectTracker should catch this.
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06007579 // Create a valid cmd buffer
7580 // call vkCmdBindPipeline w/ false Pipeline
Mark Lobodzinski02bf89d2016-05-10 14:45:13 -06007581 uint64_t fake_pipeline_handle = 0xbaad6001;
7582 VkPipeline bad_pipeline = reinterpret_cast<VkPipeline &>(fake_pipeline_handle);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007583 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Invalid Pipeline Object 0xbaad6001");
Karl Schultzbdb75952016-04-19 11:36:49 -06007584 ASSERT_NO_FATAL_FAILURE(InitState());
7585 BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007586 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, bad_pipeline);
Karl Schultzbdb75952016-04-19 11:36:49 -06007587 m_errorMonitor->VerifyFound();
Tobin Ehlisb8b6b272016-05-02 13:26:06 -06007588 // Now issue a draw call with no pipeline bound
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007589 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 -06007590
Tobin Ehlisb8b6b272016-05-02 13:26:06 -06007591 BeginCommandBuffer();
7592 Draw(1, 0, 0, 0);
7593 m_errorMonitor->VerifyFound();
7594 // Finally same check once more but with Dispatch/Compute
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007595 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 -06007596 BeginCommandBuffer();
7597 vkCmdDispatch(m_commandBuffer->GetBufferHandle(), 0, 0, 0);
7598 m_errorMonitor->VerifyFound();
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06007599}
7600
Karl Schultz6addd812016-02-02 17:17:23 -07007601TEST_F(VkLayerTest, DescriptorSetNotUpdated) {
Tobin Ehlis5a5f5ef2016-08-17 13:56:55 -06007602 TEST_DESCRIPTION("Bind a descriptor set that hasn't been updated.");
Karl Schultz6addd812016-02-02 17:17:23 -07007603 VkResult err;
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06007604
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007605 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT, " bound but it was never updated. ");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06007606
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06007607 ASSERT_NO_FATAL_FAILURE(InitState());
Mike Stroyan713b2d72015-08-04 10:49:29 -06007608 ASSERT_NO_FATAL_FAILURE(InitViewport());
7609 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chia-I Wu1b99bb22015-10-27 19:25:11 +08007610 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007611 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
7612 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -06007613
7614 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007615 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
7616 ds_pool_ci.pNext = NULL;
7617 ds_pool_ci.maxSets = 1;
7618 ds_pool_ci.poolSizeCount = 1;
7619 ds_pool_ci.pPoolSizes = &ds_type_count;
Mike Stroyan713b2d72015-08-04 10:49:29 -06007620
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06007621 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007622 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06007623 ASSERT_VK_SUCCESS(err);
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06007624
Tony Barboureb254902015-07-15 12:50:33 -06007625 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007626 dsl_binding.binding = 0;
7627 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
7628 dsl_binding.descriptorCount = 1;
7629 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
7630 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06007631
Tony Barboureb254902015-07-15 12:50:33 -06007632 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007633 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
7634 ds_layout_ci.pNext = NULL;
7635 ds_layout_ci.bindingCount = 1;
7636 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06007637 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007638 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06007639 ASSERT_VK_SUCCESS(err);
7640
7641 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08007642 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08007643 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07007644 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06007645 alloc_info.descriptorPool = ds_pool;
7646 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007647 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06007648 ASSERT_VK_SUCCESS(err);
7649
Tony Barboureb254902015-07-15 12:50:33 -06007650 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007651 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
7652 pipeline_layout_ci.pNext = NULL;
7653 pipeline_layout_ci.setLayoutCount = 1;
7654 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06007655
7656 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007657 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06007658 ASSERT_VK_SUCCESS(err);
7659
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007660 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
Karl Schultzbdb75952016-04-19 11:36:49 -06007661 // We shouldn't need a fragment shader but add it to be able to run
Karl Schultz6addd812016-02-02 17:17:23 -07007662 // on more devices
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007663 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06007664
Tony Barbourc95e4ac2015-08-04 17:05:26 -06007665 VkPipelineObj pipe(m_device);
7666 pipe.AddShader(&vs);
Tony Barbour1c94d372015-08-06 11:21:08 -06007667 pipe.AddShader(&fs);
Mark Youngc89c6312016-03-31 16:03:20 -06007668 pipe.AddColorAttachment();
Tony Barbourc95e4ac2015-08-04 17:05:26 -06007669 pipe.CreateVKPipeline(pipeline_layout, renderPass());
Tony Barbourfe3351b2015-07-28 10:17:20 -06007670
7671 BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007672 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
7673 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
7674 &descriptorSet, 0, NULL);
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06007675
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007676 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06007677
Chia-I Wuf7458c52015-10-26 21:10:41 +08007678 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
7679 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
7680 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06007681}
7682
Karl Schultz6addd812016-02-02 17:17:23 -07007683TEST_F(VkLayerTest, InvalidBufferViewObject) {
Tobin Ehlisba31cab2015-11-02 15:24:32 -07007684 // Create a single TEXEL_BUFFER descriptor and send it an invalid bufferView
Karl Schultz6addd812016-02-02 17:17:23 -07007685 VkResult err;
Tobin Ehlisba31cab2015-11-02 15:24:32 -07007686
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007687 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Attempted write update to texel buffer "
7688 "descriptor with invalid buffer view");
Tobin Ehlisba31cab2015-11-02 15:24:32 -07007689
7690 ASSERT_NO_FATAL_FAILURE(InitState());
7691 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007692 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER;
7693 ds_type_count.descriptorCount = 1;
Tobin Ehlisba31cab2015-11-02 15:24:32 -07007694
7695 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007696 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
7697 ds_pool_ci.pNext = NULL;
7698 ds_pool_ci.maxSets = 1;
7699 ds_pool_ci.poolSizeCount = 1;
7700 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlisba31cab2015-11-02 15:24:32 -07007701
7702 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007703 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlisba31cab2015-11-02 15:24:32 -07007704 ASSERT_VK_SUCCESS(err);
7705
7706 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007707 dsl_binding.binding = 0;
7708 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER;
7709 dsl_binding.descriptorCount = 1;
7710 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
7711 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlisba31cab2015-11-02 15:24:32 -07007712
7713 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007714 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
7715 ds_layout_ci.pNext = NULL;
7716 ds_layout_ci.bindingCount = 1;
7717 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlisba31cab2015-11-02 15:24:32 -07007718 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007719 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlisba31cab2015-11-02 15:24:32 -07007720 ASSERT_VK_SUCCESS(err);
7721
7722 VkDescriptorSet descriptorSet;
7723 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08007724 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07007725 alloc_info.descriptorSetCount = 1;
Tobin Ehlisba31cab2015-11-02 15:24:32 -07007726 alloc_info.descriptorPool = ds_pool;
7727 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007728 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlisba31cab2015-11-02 15:24:32 -07007729 ASSERT_VK_SUCCESS(err);
7730
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007731 VkBufferView view = (VkBufferView)((size_t)0xbaadbeef); // invalid bufferView object
Tobin Ehlisba31cab2015-11-02 15:24:32 -07007732 VkWriteDescriptorSet descriptor_write;
7733 memset(&descriptor_write, 0, sizeof(descriptor_write));
7734 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
7735 descriptor_write.dstSet = descriptorSet;
7736 descriptor_write.dstBinding = 0;
7737 descriptor_write.descriptorCount = 1;
7738 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER;
7739 descriptor_write.pTexelBufferView = &view;
7740
7741 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
7742
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007743 m_errorMonitor->VerifyFound();
Tobin Ehlisba31cab2015-11-02 15:24:32 -07007744
7745 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
7746 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
7747}
7748
Mark Youngd339ba32016-05-30 13:28:35 -06007749TEST_F(VkLayerTest, CreateBufferViewNoMemoryBoundToBuffer) {
7750 TEST_DESCRIPTION("Attempt to create a buffer view with a buffer that has"
7751 " no memory bound to it.");
7752
7753 VkResult err;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007754 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "used without first calling vkBindBufferMemory");
Mark Youngd339ba32016-05-30 13:28:35 -06007755
7756 ASSERT_NO_FATAL_FAILURE(InitState());
7757
7758 // Create a buffer with no bound memory and then attempt to create
7759 // a buffer view.
7760 VkBufferCreateInfo buff_ci = {};
7761 buff_ci.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
Chris Forbes4538d242016-09-13 18:13:58 +12007762 buff_ci.usage = VK_BUFFER_USAGE_UNIFORM_TEXEL_BUFFER_BIT;
Mark Youngd339ba32016-05-30 13:28:35 -06007763 buff_ci.size = 256;
7764 buff_ci.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
7765 VkBuffer buffer;
7766 err = vkCreateBuffer(m_device->device(), &buff_ci, NULL, &buffer);
7767 ASSERT_VK_SUCCESS(err);
7768
7769 VkBufferViewCreateInfo buff_view_ci = {};
7770 buff_view_ci.sType = VK_STRUCTURE_TYPE_BUFFER_VIEW_CREATE_INFO;
7771 buff_view_ci.buffer = buffer;
7772 buff_view_ci.format = VK_FORMAT_R8_UNORM;
7773 buff_view_ci.range = VK_WHOLE_SIZE;
7774 VkBufferView buff_view;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007775 err = vkCreateBufferView(m_device->device(), &buff_view_ci, NULL, &buff_view);
Mark Youngd339ba32016-05-30 13:28:35 -06007776
7777 m_errorMonitor->VerifyFound();
7778 vkDestroyBuffer(m_device->device(), buffer, NULL);
7779 // If last error is success, it still created the view, so delete it.
7780 if (err == VK_SUCCESS) {
7781 vkDestroyBufferView(m_device->device(), buff_view, NULL);
7782 }
7783}
7784
Karl Schultz6addd812016-02-02 17:17:23 -07007785TEST_F(VkLayerTest, InvalidDynamicOffsetCases) {
7786 // Create a descriptorSet w/ dynamic descriptor and then hit 3 offset error
7787 // cases:
Tobin Ehlisf6585052015-12-17 11:48:42 -07007788 // 1. No dynamicOffset supplied
7789 // 2. Too many dynamicOffsets supplied
7790 // 3. Dynamic offset oversteps buffer being updated
Karl Schultz6addd812016-02-02 17:17:23 -07007791 VkResult err;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007792 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " requires 1 dynamicOffsets, but only "
7793 "0 dynamicOffsets are left in "
7794 "pDynamicOffsets ");
Tobin Ehlis49f903e2015-11-04 13:30:34 -07007795
7796 ASSERT_NO_FATAL_FAILURE(InitState());
7797 ASSERT_NO_FATAL_FAILURE(InitViewport());
7798 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
7799
7800 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007801 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
7802 ds_type_count.descriptorCount = 1;
Tobin Ehlis49f903e2015-11-04 13:30:34 -07007803
7804 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007805 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
7806 ds_pool_ci.pNext = NULL;
7807 ds_pool_ci.maxSets = 1;
7808 ds_pool_ci.poolSizeCount = 1;
7809 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlis49f903e2015-11-04 13:30:34 -07007810
7811 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007812 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis49f903e2015-11-04 13:30:34 -07007813 ASSERT_VK_SUCCESS(err);
7814
7815 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007816 dsl_binding.binding = 0;
7817 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
7818 dsl_binding.descriptorCount = 1;
7819 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
7820 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis49f903e2015-11-04 13:30:34 -07007821
7822 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007823 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
7824 ds_layout_ci.pNext = NULL;
7825 ds_layout_ci.bindingCount = 1;
7826 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlis49f903e2015-11-04 13:30:34 -07007827 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007828 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis49f903e2015-11-04 13:30:34 -07007829 ASSERT_VK_SUCCESS(err);
7830
7831 VkDescriptorSet descriptorSet;
7832 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08007833 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07007834 alloc_info.descriptorSetCount = 1;
Tobin Ehlis49f903e2015-11-04 13:30:34 -07007835 alloc_info.descriptorPool = ds_pool;
7836 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007837 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis49f903e2015-11-04 13:30:34 -07007838 ASSERT_VK_SUCCESS(err);
7839
7840 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007841 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
7842 pipeline_layout_ci.pNext = NULL;
7843 pipeline_layout_ci.setLayoutCount = 1;
7844 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlis49f903e2015-11-04 13:30:34 -07007845
7846 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007847 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis49f903e2015-11-04 13:30:34 -07007848 ASSERT_VK_SUCCESS(err);
7849
7850 // Create a buffer to update the descriptor with
7851 uint32_t qfi = 0;
7852 VkBufferCreateInfo buffCI = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007853 buffCI.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
7854 buffCI.size = 1024;
7855 buffCI.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
7856 buffCI.queueFamilyIndexCount = 1;
7857 buffCI.pQueueFamilyIndices = &qfi;
Tobin Ehlis49f903e2015-11-04 13:30:34 -07007858
7859 VkBuffer dyub;
7860 err = vkCreateBuffer(m_device->device(), &buffCI, NULL, &dyub);
7861 ASSERT_VK_SUCCESS(err);
Tobin Ehlis0a43bde2016-05-03 08:31:08 -06007862 // Allocate memory and bind to buffer so we can make it to the appropriate
7863 // error
7864 VkMemoryAllocateInfo mem_alloc = {};
7865 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
7866 mem_alloc.pNext = NULL;
7867 mem_alloc.allocationSize = 1024;
Chris Forbesb6116cc2016-05-08 11:39:59 +12007868 mem_alloc.memoryTypeIndex = 0;
7869
7870 VkMemoryRequirements memReqs;
7871 vkGetBufferMemoryRequirements(m_device->device(), dyub, &memReqs);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007872 bool pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &mem_alloc, 0);
Chris Forbesb6116cc2016-05-08 11:39:59 +12007873 if (!pass) {
7874 vkDestroyBuffer(m_device->device(), dyub, NULL);
7875 return;
7876 }
7877
Tobin Ehlis0a43bde2016-05-03 08:31:08 -06007878 VkDeviceMemory mem;
7879 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem);
7880 ASSERT_VK_SUCCESS(err);
7881 err = vkBindBufferMemory(m_device->device(), dyub, mem, 0);
7882 ASSERT_VK_SUCCESS(err);
Tobin Ehlis49f903e2015-11-04 13:30:34 -07007883 // Correctly update descriptor to avoid "NOT_UPDATED" error
7884 VkDescriptorBufferInfo buffInfo = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007885 buffInfo.buffer = dyub;
7886 buffInfo.offset = 0;
7887 buffInfo.range = 1024;
Tobin Ehlis49f903e2015-11-04 13:30:34 -07007888
7889 VkWriteDescriptorSet descriptor_write;
7890 memset(&descriptor_write, 0, sizeof(descriptor_write));
7891 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
7892 descriptor_write.dstSet = descriptorSet;
7893 descriptor_write.dstBinding = 0;
7894 descriptor_write.descriptorCount = 1;
7895 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
7896 descriptor_write.pBufferInfo = &buffInfo;
7897
7898 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
7899
7900 BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007901 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
7902 &descriptorSet, 0, NULL);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007903 m_errorMonitor->VerifyFound();
Tobin Ehlisf6585052015-12-17 11:48:42 -07007904 uint32_t pDynOff[2] = {512, 756};
7905 // Now cause error b/c too many dynOffsets in array for # of dyn descriptors
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007906 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
7907 "Attempting to bind 1 descriptorSets with 1 dynamic descriptors, but ");
7908 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
7909 &descriptorSet, 2, pDynOff);
Chris Forbes7b342802016-04-07 13:20:10 +12007910 m_errorMonitor->VerifyFound();
Tobin Ehlisf6585052015-12-17 11:48:42 -07007911 // Finally cause error due to dynamicOffset being too big
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007912 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " dynamic offset 512 combined with "
7913 "offset 0 and range 1024 that "
7914 "oversteps the buffer size of 1024");
Tobin Ehlisf6585052015-12-17 11:48:42 -07007915 // Create PSO to be used for draw-time errors below
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007916 char const *vsSource = "#version 450\n"
7917 "\n"
7918 "out gl_PerVertex { \n"
7919 " vec4 gl_Position;\n"
7920 "};\n"
7921 "void main(){\n"
7922 " gl_Position = vec4(1);\n"
7923 "}\n";
7924 char const *fsSource = "#version 450\n"
7925 "\n"
7926 "layout(location=0) out vec4 x;\n"
7927 "layout(set=0) layout(binding=0) uniform foo { int x; int y; } bar;\n"
7928 "void main(){\n"
7929 " x = vec4(bar.y);\n"
7930 "}\n";
Tobin Ehlisf6585052015-12-17 11:48:42 -07007931 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
7932 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
7933 VkPipelineObj pipe(m_device);
7934 pipe.AddShader(&vs);
7935 pipe.AddShader(&fs);
7936 pipe.AddColorAttachment();
7937 pipe.CreateVKPipeline(pipeline_layout, renderPass());
7938
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007939 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Karl Schultz6addd812016-02-02 17:17:23 -07007940 // This update should succeed, but offset size of 512 will overstep buffer
7941 // /w range 1024 & size 1024
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007942 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
7943 &descriptorSet, 1, pDynOff);
Tobin Ehlisf6585052015-12-17 11:48:42 -07007944 Draw(1, 0, 0, 0);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007945 m_errorMonitor->VerifyFound();
Tobin Ehlis49f903e2015-11-04 13:30:34 -07007946
Tobin Ehlis0a43bde2016-05-03 08:31:08 -06007947 vkDestroyBuffer(m_device->device(), dyub, NULL);
Tobin Ehlis512098e2016-05-05 09:06:12 -06007948 vkFreeMemory(m_device->device(), mem, NULL);
Tobin Ehlis0a43bde2016-05-03 08:31:08 -06007949
Tobin Ehlis49f903e2015-11-04 13:30:34 -07007950 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
Tony Barbourdf4c0042016-06-01 15:55:43 -06007951 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
Tobin Ehlis49f903e2015-11-04 13:30:34 -07007952 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
7953}
7954
Tobin Ehlis8ef479c2016-07-20 16:14:49 -06007955TEST_F(VkLayerTest, DescriptorBufferUpdateNoMemoryBound) {
7956 TEST_DESCRIPTION("Attempt to update a descriptor with a non-sparse buffer "
7957 "that doesn't have memory bound");
7958 VkResult err;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007959 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " used without first calling vkBindBufferMemory.");
Tobin Ehlis8ef479c2016-07-20 16:14:49 -06007960
7961 ASSERT_NO_FATAL_FAILURE(InitState());
7962 ASSERT_NO_FATAL_FAILURE(InitViewport());
7963 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
7964
7965 VkDescriptorPoolSize ds_type_count = {};
7966 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
7967 ds_type_count.descriptorCount = 1;
7968
7969 VkDescriptorPoolCreateInfo ds_pool_ci = {};
7970 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
7971 ds_pool_ci.pNext = NULL;
7972 ds_pool_ci.maxSets = 1;
7973 ds_pool_ci.poolSizeCount = 1;
7974 ds_pool_ci.pPoolSizes = &ds_type_count;
7975
7976 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007977 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis8ef479c2016-07-20 16:14:49 -06007978 ASSERT_VK_SUCCESS(err);
7979
7980 VkDescriptorSetLayoutBinding dsl_binding = {};
7981 dsl_binding.binding = 0;
7982 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
7983 dsl_binding.descriptorCount = 1;
7984 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
7985 dsl_binding.pImmutableSamplers = NULL;
7986
7987 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
7988 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
7989 ds_layout_ci.pNext = NULL;
7990 ds_layout_ci.bindingCount = 1;
7991 ds_layout_ci.pBindings = &dsl_binding;
7992 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007993 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis8ef479c2016-07-20 16:14:49 -06007994 ASSERT_VK_SUCCESS(err);
7995
7996 VkDescriptorSet descriptorSet;
7997 VkDescriptorSetAllocateInfo alloc_info = {};
7998 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
7999 alloc_info.descriptorSetCount = 1;
8000 alloc_info.descriptorPool = ds_pool;
8001 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008002 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis8ef479c2016-07-20 16:14:49 -06008003 ASSERT_VK_SUCCESS(err);
8004
8005 // Create a buffer to update the descriptor with
8006 uint32_t qfi = 0;
8007 VkBufferCreateInfo buffCI = {};
8008 buffCI.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
8009 buffCI.size = 1024;
8010 buffCI.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
8011 buffCI.queueFamilyIndexCount = 1;
8012 buffCI.pQueueFamilyIndices = &qfi;
8013
8014 VkBuffer dyub;
8015 err = vkCreateBuffer(m_device->device(), &buffCI, NULL, &dyub);
8016 ASSERT_VK_SUCCESS(err);
8017
8018 // Attempt to update descriptor without binding memory to it
8019 VkDescriptorBufferInfo buffInfo = {};
8020 buffInfo.buffer = dyub;
8021 buffInfo.offset = 0;
8022 buffInfo.range = 1024;
8023
8024 VkWriteDescriptorSet descriptor_write;
8025 memset(&descriptor_write, 0, sizeof(descriptor_write));
8026 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
8027 descriptor_write.dstSet = descriptorSet;
8028 descriptor_write.dstBinding = 0;
8029 descriptor_write.descriptorCount = 1;
8030 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
8031 descriptor_write.pBufferInfo = &buffInfo;
8032
8033 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
8034 m_errorMonitor->VerifyFound();
8035
8036 vkDestroyBuffer(m_device->device(), dyub, NULL);
8037 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
8038 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
8039}
8040
Tobin Ehlis3a23b6a2016-02-17 10:35:18 -07008041TEST_F(VkLayerTest, InvalidPushConstants) {
Tobin Ehlis3a23b6a2016-02-17 10:35:18 -07008042 VkResult err;
Tobin Ehlis3a23b6a2016-02-17 10:35:18 -07008043 ASSERT_NO_FATAL_FAILURE(InitState());
8044 ASSERT_NO_FATAL_FAILURE(InitViewport());
8045 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
8046
Karl Schultzfc8eaf12016-05-06 13:56:42 -06008047 VkPipelineLayout pipeline_layout;
Tobin Ehlis3a23b6a2016-02-17 10:35:18 -07008048 VkPushConstantRange pc_range = {};
Tobin Ehlis3a23b6a2016-02-17 10:35:18 -07008049 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
8050 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
8051 pipeline_layout_ci.pushConstantRangeCount = 1;
8052 pipeline_layout_ci.pPushConstantRanges = &pc_range;
8053
Karl Schultzfc8eaf12016-05-06 13:56:42 -06008054 //
8055 // Check for invalid push constant ranges in pipeline layouts.
8056 //
8057 struct PipelineLayoutTestCase {
Karl Schultzc81037d2016-05-12 08:11:23 -06008058 VkPushConstantRange const range;
Karl Schultzfc8eaf12016-05-06 13:56:42 -06008059 char const *msg;
8060 };
Tobin Ehlis3a23b6a2016-02-17 10:35:18 -07008061
Karl Schultzc81037d2016-05-12 08:11:23 -06008062 const uint32_t too_big = m_device->props.limits.maxPushConstantsSize + 0x4;
8063 const std::array<PipelineLayoutTestCase, 10> range_tests = {{
8064 {{VK_SHADER_STAGE_VERTEX_BIT, 0, 0},
8065 "vkCreatePipelineLayout() call has push constants index 0 with "
8066 "size 0."},
8067 {{VK_SHADER_STAGE_VERTEX_BIT, 0, 1},
8068 "vkCreatePipelineLayout() call has push constants index 0 with "
8069 "size 1."},
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06008070 {{VK_SHADER_STAGE_VERTEX_BIT, 4, 1},
Karl Schultzc81037d2016-05-12 08:11:23 -06008071 "vkCreatePipelineLayout() call has push constants index 0 with "
8072 "size 1."},
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06008073 {{VK_SHADER_STAGE_VERTEX_BIT, 4, 0},
Karl Schultzc81037d2016-05-12 08:11:23 -06008074 "vkCreatePipelineLayout() call has push constants index 0 with "
8075 "size 0."},
8076 {{VK_SHADER_STAGE_VERTEX_BIT, 1, 4},
8077 "vkCreatePipelineLayout() call has push constants index 0 with "
8078 "offset 1. Offset must"},
8079 {{VK_SHADER_STAGE_VERTEX_BIT, 0, too_big},
8080 "vkCreatePipelineLayout() call has push constants index 0 "
8081 "with offset "},
8082 {{VK_SHADER_STAGE_VERTEX_BIT, too_big, too_big},
8083 "vkCreatePipelineLayout() call has push constants "
8084 "index 0 with offset "},
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06008085 {{VK_SHADER_STAGE_VERTEX_BIT, too_big, 4},
Karl Schultzc81037d2016-05-12 08:11:23 -06008086 "vkCreatePipelineLayout() call has push constants index 0 "
8087 "with offset "},
8088 {{VK_SHADER_STAGE_VERTEX_BIT, 0xFFFFFFF0, 0x00000020},
8089 "vkCreatePipelineLayout() call has push "
8090 "constants index 0 with offset "},
8091 {{VK_SHADER_STAGE_VERTEX_BIT, 0x00000020, 0xFFFFFFF0},
8092 "vkCreatePipelineLayout() call has push "
8093 "constants index 0 with offset "},
Karl Schultzfc8eaf12016-05-06 13:56:42 -06008094 }};
8095
8096 // Check for invalid offset and size
Karl Schultzc81037d2016-05-12 08:11:23 -06008097 for (const auto &iter : range_tests) {
8098 pc_range = iter.range;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008099 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, iter.msg);
8100 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Karl Schultzfc8eaf12016-05-06 13:56:42 -06008101 m_errorMonitor->VerifyFound();
8102 if (VK_SUCCESS == err) {
8103 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
8104 }
8105 }
8106
8107 // Check for invalid stage flag
8108 pc_range.offset = 0;
8109 pc_range.size = 16;
8110 pc_range.stageFlags = 0;
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06008111 m_errorMonitor->SetDesiredFailureMsg(
8112 VK_DEBUG_REPORT_ERROR_BIT_EXT,
8113 "vkCreatePipelineLayout: value of pCreateInfo->pPushConstantRanges[0].stageFlags must not be 0");
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008114 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008115 m_errorMonitor->VerifyFound();
Karl Schultzfc8eaf12016-05-06 13:56:42 -06008116 if (VK_SUCCESS == err) {
8117 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
8118 }
8119
8120 // Check for overlapping ranges
Karl Schultzc81037d2016-05-12 08:11:23 -06008121 const uint32_t ranges_per_test = 5;
Karl Schultzfc8eaf12016-05-06 13:56:42 -06008122 struct OverlappingRangeTestCase {
Karl Schultzc81037d2016-05-12 08:11:23 -06008123 VkPushConstantRange const ranges[ranges_per_test];
Karl Schultzfc8eaf12016-05-06 13:56:42 -06008124 char const *msg;
8125 };
8126
Karl Schultzc81037d2016-05-12 08:11:23 -06008127 const std::array<OverlappingRangeTestCase, 5> overlapping_range_tests = {
Karl Schultzfc8eaf12016-05-06 13:56:42 -06008128 {{{{VK_SHADER_STAGE_VERTEX_BIT, 0, 4},
8129 {VK_SHADER_STAGE_VERTEX_BIT, 0, 4},
8130 {VK_SHADER_STAGE_VERTEX_BIT, 0, 4},
8131 {VK_SHADER_STAGE_VERTEX_BIT, 0, 4},
8132 {VK_SHADER_STAGE_VERTEX_BIT, 0, 4}},
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06008133 "vkCreatePipelineLayout() call has push constants with overlapping ranges:"},
Karl Schultzfc8eaf12016-05-06 13:56:42 -06008134 {
8135 {{VK_SHADER_STAGE_VERTEX_BIT, 0, 4},
8136 {VK_SHADER_STAGE_VERTEX_BIT, 4, 4},
8137 {VK_SHADER_STAGE_VERTEX_BIT, 8, 4},
8138 {VK_SHADER_STAGE_VERTEX_BIT, 12, 8},
8139 {VK_SHADER_STAGE_VERTEX_BIT, 16, 4}},
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06008140 "vkCreatePipelineLayout() call has push constants with overlapping ranges: 3:[12, 20), 4:[16, 20)",
Karl Schultzfc8eaf12016-05-06 13:56:42 -06008141 },
8142 {
8143 {{VK_SHADER_STAGE_VERTEX_BIT, 16, 4},
8144 {VK_SHADER_STAGE_VERTEX_BIT, 12, 8},
8145 {VK_SHADER_STAGE_VERTEX_BIT, 8, 4},
8146 {VK_SHADER_STAGE_VERTEX_BIT, 4, 4},
8147 {VK_SHADER_STAGE_VERTEX_BIT, 0, 4}},
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06008148 "vkCreatePipelineLayout() call has push constants with overlapping ranges: 0:[16, 20), 1:[12, 20)",
Karl Schultzfc8eaf12016-05-06 13:56:42 -06008149 },
8150 {
8151 {{VK_SHADER_STAGE_VERTEX_BIT, 16, 4},
8152 {VK_SHADER_STAGE_VERTEX_BIT, 8, 4},
8153 {VK_SHADER_STAGE_VERTEX_BIT, 4, 4},
8154 {VK_SHADER_STAGE_VERTEX_BIT, 12, 8},
8155 {VK_SHADER_STAGE_VERTEX_BIT, 0, 4}},
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06008156 "vkCreatePipelineLayout() call has push constants with overlapping ranges: 0:[16, 20), 3:[12, 20)",
Karl Schultzfc8eaf12016-05-06 13:56:42 -06008157 },
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}},
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06008164 "vkCreatePipelineLayout() call has push constants with overlapping ranges:",
Karl Schultzfc8eaf12016-05-06 13:56:42 -06008165 }}};
Karl Schultzfc8eaf12016-05-06 13:56:42 -06008166
Karl Schultzc81037d2016-05-12 08:11:23 -06008167 for (const auto &iter : overlapping_range_tests) {
Karl Schultzfc8eaf12016-05-06 13:56:42 -06008168 pipeline_layout_ci.pPushConstantRanges = iter.ranges;
Karl Schultzc81037d2016-05-12 08:11:23 -06008169 pipeline_layout_ci.pushConstantRangeCount = ranges_per_test;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008170 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT, iter.msg);
8171 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Karl Schultzfc8eaf12016-05-06 13:56:42 -06008172 m_errorMonitor->VerifyFound();
8173 if (VK_SUCCESS == err) {
8174 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
8175 }
8176 }
8177
8178 // Run some positive tests to make sure overlap checking in the layer is OK
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008179 const std::array<OverlappingRangeTestCase, 2> overlapping_range_tests_pos = {{{{{VK_SHADER_STAGE_VERTEX_BIT, 0, 4},
8180 {VK_SHADER_STAGE_VERTEX_BIT, 4, 4},
8181 {VK_SHADER_STAGE_VERTEX_BIT, 8, 4},
8182 {VK_SHADER_STAGE_VERTEX_BIT, 12, 4},
8183 {VK_SHADER_STAGE_VERTEX_BIT, 16, 4}},
8184 ""},
8185 {{{VK_SHADER_STAGE_VERTEX_BIT, 92, 24},
8186 {VK_SHADER_STAGE_VERTEX_BIT, 80, 4},
8187 {VK_SHADER_STAGE_VERTEX_BIT, 64, 8},
8188 {VK_SHADER_STAGE_VERTEX_BIT, 4, 16},
8189 {VK_SHADER_STAGE_VERTEX_BIT, 0, 4}},
8190 ""}}};
Karl Schultzc81037d2016-05-12 08:11:23 -06008191 for (const auto &iter : overlapping_range_tests_pos) {
Karl Schultzfc8eaf12016-05-06 13:56:42 -06008192 pipeline_layout_ci.pPushConstantRanges = iter.ranges;
8193 m_errorMonitor->ExpectSuccess();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008194 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Karl Schultzfc8eaf12016-05-06 13:56:42 -06008195 m_errorMonitor->VerifyNotFound();
8196 if (VK_SUCCESS == err) {
8197 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
8198 }
8199 }
8200
8201 //
8202 // CmdPushConstants tests
8203 //
Karl Schultzc81037d2016-05-12 08:11:23 -06008204 const uint8_t dummy_values[100] = {};
Karl Schultzfc8eaf12016-05-06 13:56:42 -06008205
8206 // Check for invalid offset and size and if range is within layout range(s)
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06008207 const std::array<PipelineLayoutTestCase, 11> cmd_range_tests = {{
8208 {{VK_SHADER_STAGE_VERTEX_BIT, 0, 0}, "vkCmdPushConstants: parameter size must be greater than 0"},
Karl Schultzc81037d2016-05-12 08:11:23 -06008209 {{VK_SHADER_STAGE_VERTEX_BIT, 0, 1},
8210 "vkCmdPushConstants() call has push constants with size 1. Size "
8211 "must be greater than zero and a multiple of 4."},
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06008212 {{VK_SHADER_STAGE_VERTEX_BIT, 4, 1},
Karl Schultzc81037d2016-05-12 08:11:23 -06008213 "vkCmdPushConstants() call has push constants with size 1. Size "
8214 "must be greater than zero and a multiple of 4."},
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06008215 {{VK_SHADER_STAGE_VERTEX_BIT, 1, 4},
Karl Schultzc81037d2016-05-12 08:11:23 -06008216 "vkCmdPushConstants() call has push constants with offset 1. "
8217 "Offset must be a multiple of 4."},
8218 {{VK_SHADER_STAGE_VERTEX_BIT, 1, 4},
8219 "vkCmdPushConstants() call has push constants with offset 1. "
8220 "Offset must be a multiple of 4."},
8221 {{VK_SHADER_STAGE_VERTEX_BIT, 0, 20},
8222 "vkCmdPushConstants() Push constant range [0, 20) with stageFlags = "
8223 "0x1 not within flag-matching ranges in pipeline layout"},
8224 {{VK_SHADER_STAGE_VERTEX_BIT, 60, 8},
8225 "vkCmdPushConstants() Push constant range [60, 68) with stageFlags = "
8226 "0x1 not within flag-matching ranges in pipeline layout"},
8227 {{VK_SHADER_STAGE_VERTEX_BIT, 76, 8},
8228 "vkCmdPushConstants() Push constant range [76, 84) with stageFlags = "
8229 "0x1 not within flag-matching ranges in pipeline layout"},
8230 {{VK_SHADER_STAGE_VERTEX_BIT, 0, 80},
8231 "vkCmdPushConstants() Push constant range [0, 80) with stageFlags = "
8232 "0x1 not within flag-matching ranges in pipeline layout"},
8233 {{VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT, 0, 4},
8234 "vkCmdPushConstants() stageFlags = 0x2 do not match the stageFlags in "
8235 "any of the ranges in pipeline layout"},
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008236 {{VK_SHADER_STAGE_VERTEX_BIT | VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT, 0, 16},
Karl Schultzc81037d2016-05-12 08:11:23 -06008237 "vkCmdPushConstants() stageFlags = 0x3 do not match the stageFlags in "
8238 "any of the ranges in pipeline layout"},
Karl Schultzfc8eaf12016-05-06 13:56:42 -06008239 }};
8240
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06008241 BeginCommandBuffer();
8242
8243 // Setup ranges: [0,16) [64,80)
Karl Schultzc81037d2016-05-12 08:11:23 -06008244 const VkPushConstantRange pc_range2[] = {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008245 {VK_SHADER_STAGE_VERTEX_BIT, 64, 16}, {VK_SHADER_STAGE_VERTEX_BIT, 0, 16},
Karl Schultzfc8eaf12016-05-06 13:56:42 -06008246 };
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008247 pipeline_layout_ci.pushConstantRangeCount = sizeof(pc_range2) / sizeof(VkPushConstantRange);
Karl Schultzfc8eaf12016-05-06 13:56:42 -06008248 pipeline_layout_ci.pPushConstantRanges = pc_range2;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008249 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis3a23b6a2016-02-17 10:35:18 -07008250 ASSERT_VK_SUCCESS(err);
Karl Schultzc81037d2016-05-12 08:11:23 -06008251 for (const auto &iter : cmd_range_tests) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008252 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, iter.msg);
8253 vkCmdPushConstants(m_commandBuffer->GetBufferHandle(), pipeline_layout, iter.range.stageFlags, iter.range.offset,
Karl Schultzc81037d2016-05-12 08:11:23 -06008254 iter.range.size, dummy_values);
Karl Schultzfc8eaf12016-05-06 13:56:42 -06008255 m_errorMonitor->VerifyFound();
8256 }
8257
8258 // Check for invalid stage flag
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06008259 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "vkCmdPushConstants: value of stageFlags must not be 0");
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008260 vkCmdPushConstants(m_commandBuffer->GetBufferHandle(), pipeline_layout, 0, 0, 16, dummy_values);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008261 m_errorMonitor->VerifyFound();
Karl Schultzc81037d2016-05-12 08:11:23 -06008262 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
Karl Schultzfc8eaf12016-05-06 13:56:42 -06008263
Karl Schultzc81037d2016-05-12 08:11:23 -06008264 // overlapping range tests with cmd
8265 const std::array<PipelineLayoutTestCase, 3> cmd_overlap_tests = {{
8266 {{VK_SHADER_STAGE_VERTEX_BIT, 0, 20},
8267 "vkCmdPushConstants() Push constant range [0, 20) with stageFlags = "
8268 "0x1 not within flag-matching ranges in pipeline layout"},
8269 {{VK_SHADER_STAGE_VERTEX_BIT, 16, 4},
8270 "vkCmdPushConstants() Push constant range [16, 20) with stageFlags = "
8271 "0x1 not within flag-matching ranges in pipeline layout"},
8272 {{VK_SHADER_STAGE_VERTEX_BIT, 40, 16},
8273 "vkCmdPushConstants() Push constant range [40, 56) with stageFlags = "
8274 "0x1 not within flag-matching ranges in pipeline layout"},
8275 }};
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06008276 // Setup ranges: [0,16), [20,36), [36,44), [44,52), [80,92)
Karl Schultzc81037d2016-05-12 08:11:23 -06008277 const VkPushConstantRange pc_range3[] = {
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06008278 {VK_SHADER_STAGE_VERTEX_BIT, 20, 16}, {VK_SHADER_STAGE_VERTEX_BIT, 0, 16}, {VK_SHADER_STAGE_VERTEX_BIT, 44, 8},
8279 {VK_SHADER_STAGE_VERTEX_BIT, 80, 12}, {VK_SHADER_STAGE_VERTEX_BIT, 36, 8},
Karl Schultzc81037d2016-05-12 08:11:23 -06008280 };
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008281 pipeline_layout_ci.pushConstantRangeCount = sizeof(pc_range3) / sizeof(VkPushConstantRange);
Karl Schultzc81037d2016-05-12 08:11:23 -06008282 pipeline_layout_ci.pPushConstantRanges = pc_range3;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008283 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Karl Schultzc81037d2016-05-12 08:11:23 -06008284 ASSERT_VK_SUCCESS(err);
Karl Schultzc81037d2016-05-12 08:11:23 -06008285 for (const auto &iter : cmd_overlap_tests) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008286 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, iter.msg);
8287 vkCmdPushConstants(m_commandBuffer->GetBufferHandle(), pipeline_layout, iter.range.stageFlags, iter.range.offset,
Karl Schultzc81037d2016-05-12 08:11:23 -06008288 iter.range.size, dummy_values);
8289 m_errorMonitor->VerifyFound();
8290 }
Karl Schultzc81037d2016-05-12 08:11:23 -06008291 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
8292
8293 // positive overlapping range tests with cmd
8294 const std::array<PipelineLayoutTestCase, 4> cmd_overlap_tests_pos = {{
8295 {{VK_SHADER_STAGE_VERTEX_BIT, 0, 16}, ""},
8296 {{VK_SHADER_STAGE_VERTEX_BIT, 0, 4}, ""},
8297 {{VK_SHADER_STAGE_VERTEX_BIT, 20, 12}, ""},
8298 {{VK_SHADER_STAGE_VERTEX_BIT, 56, 36}, ""},
8299 }};
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06008300 // Setup ranges: [0,16) [20,36) [36,44) [44,52) [56,80) [80,92)
Karl Schultzc81037d2016-05-12 08:11:23 -06008301 const VkPushConstantRange pc_range4[] = {
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06008302 {VK_SHADER_STAGE_VERTEX_BIT, 20, 16}, {VK_SHADER_STAGE_VERTEX_BIT, 0, 16}, {VK_SHADER_STAGE_VERTEX_BIT, 44, 8},
8303 {VK_SHADER_STAGE_VERTEX_BIT, 80, 12}, {VK_SHADER_STAGE_VERTEX_BIT, 36, 8}, {VK_SHADER_STAGE_VERTEX_BIT, 56, 24},
Karl Schultzc81037d2016-05-12 08:11:23 -06008304 };
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008305 pipeline_layout_ci.pushConstantRangeCount = sizeof(pc_range4) / sizeof(VkPushConstantRange);
Karl Schultzc81037d2016-05-12 08:11:23 -06008306 pipeline_layout_ci.pPushConstantRanges = pc_range4;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008307 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Karl Schultzc81037d2016-05-12 08:11:23 -06008308 ASSERT_VK_SUCCESS(err);
Karl Schultzc81037d2016-05-12 08:11:23 -06008309 for (const auto &iter : cmd_overlap_tests_pos) {
8310 m_errorMonitor->ExpectSuccess();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008311 vkCmdPushConstants(m_commandBuffer->GetBufferHandle(), pipeline_layout, iter.range.stageFlags, iter.range.offset,
Karl Schultzc81037d2016-05-12 08:11:23 -06008312 iter.range.size, dummy_values);
8313 m_errorMonitor->VerifyNotFound();
8314 }
Tobin Ehlis3a23b6a2016-02-17 10:35:18 -07008315 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06008316
8317 EndCommandBuffer();
Tobin Ehlis3a23b6a2016-02-17 10:35:18 -07008318}
8319
Karl Schultz6addd812016-02-02 17:17:23 -07008320TEST_F(VkLayerTest, DescriptorSetCompatibility) {
Tobin Ehlis559c6382015-11-05 09:52:49 -07008321 // Test various desriptorSet errors with bad binding combinations
Karl Schultz6addd812016-02-02 17:17:23 -07008322 VkResult err;
Tobin Ehlis559c6382015-11-05 09:52:49 -07008323
8324 ASSERT_NO_FATAL_FAILURE(InitState());
8325 ASSERT_NO_FATAL_FAILURE(InitViewport());
8326 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
8327
Mike Stroyanb8a61002016-06-20 16:00:28 -06008328 const VkFormat tex_format = VK_FORMAT_R8G8B8A8_UNORM;
8329 VkImageTiling tiling;
8330 VkFormatProperties format_properties;
8331 vkGetPhysicalDeviceFormatProperties(gpu(), tex_format, &format_properties);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008332 if (format_properties.linearTilingFeatures & VK_FORMAT_FEATURE_STORAGE_IMAGE_BIT) {
Mike Stroyanb8a61002016-06-20 16:00:28 -06008333 tiling = VK_IMAGE_TILING_LINEAR;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008334 } else if (format_properties.optimalTilingFeatures & VK_FORMAT_FEATURE_STORAGE_IMAGE_BIT) {
Mike Stroyanb8a61002016-06-20 16:00:28 -06008335 tiling = VK_IMAGE_TILING_OPTIMAL;
8336 } else {
8337 printf("Device does not support VK_FORMAT_FEATURE_STORAGE_IMAGE_BIT; "
8338 "skipped.\n");
8339 return;
8340 }
8341
Tobin Ehlis559c6382015-11-05 09:52:49 -07008342 static const uint32_t NUM_DESCRIPTOR_TYPES = 5;
8343 VkDescriptorPoolSize ds_type_count[NUM_DESCRIPTOR_TYPES] = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008344 ds_type_count[0].type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
8345 ds_type_count[0].descriptorCount = 10;
8346 ds_type_count[1].type = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE;
8347 ds_type_count[1].descriptorCount = 2;
8348 ds_type_count[2].type = VK_DESCRIPTOR_TYPE_STORAGE_IMAGE;
8349 ds_type_count[2].descriptorCount = 2;
8350 ds_type_count[3].type = VK_DESCRIPTOR_TYPE_SAMPLER;
8351 ds_type_count[3].descriptorCount = 5;
8352 // TODO : LunarG ILO driver currently asserts in desc.c w/ INPUT_ATTACHMENT
8353 // type
8354 // ds_type_count[4].type = VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT;
8355 ds_type_count[4].type = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
8356 ds_type_count[4].descriptorCount = 2;
Tobin Ehlis559c6382015-11-05 09:52:49 -07008357
8358 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008359 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
8360 ds_pool_ci.pNext = NULL;
8361 ds_pool_ci.maxSets = 5;
8362 ds_pool_ci.poolSizeCount = NUM_DESCRIPTOR_TYPES;
8363 ds_pool_ci.pPoolSizes = ds_type_count;
Tobin Ehlis559c6382015-11-05 09:52:49 -07008364
8365 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008366 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis559c6382015-11-05 09:52:49 -07008367 ASSERT_VK_SUCCESS(err);
8368
8369 static const uint32_t MAX_DS_TYPES_IN_LAYOUT = 2;
8370 VkDescriptorSetLayoutBinding dsl_binding[MAX_DS_TYPES_IN_LAYOUT] = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008371 dsl_binding[0].binding = 0;
8372 dsl_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
8373 dsl_binding[0].descriptorCount = 5;
8374 dsl_binding[0].stageFlags = VK_SHADER_STAGE_ALL;
8375 dsl_binding[0].pImmutableSamplers = NULL;
Tobin Ehlis559c6382015-11-05 09:52:49 -07008376
Tobin Ehlis8fab6562015-12-01 09:57:09 -07008377 // Create layout identical to set0 layout but w/ different stageFlags
8378 VkDescriptorSetLayoutBinding dsl_fs_stage_only = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008379 dsl_fs_stage_only.binding = 0;
8380 dsl_fs_stage_only.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
8381 dsl_fs_stage_only.descriptorCount = 5;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008382 dsl_fs_stage_only.stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT; // Different stageFlags to cause error at
8383 // bind time
Karl Schultz6addd812016-02-02 17:17:23 -07008384 dsl_fs_stage_only.pImmutableSamplers = NULL;
Tobin Ehlis559c6382015-11-05 09:52:49 -07008385 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008386 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
8387 ds_layout_ci.pNext = NULL;
8388 ds_layout_ci.bindingCount = 1;
8389 ds_layout_ci.pBindings = dsl_binding;
Tobin Ehlis559c6382015-11-05 09:52:49 -07008390 static const uint32_t NUM_LAYOUTS = 4;
8391 VkDescriptorSetLayout ds_layout[NUM_LAYOUTS] = {};
Tobin Ehlis8fab6562015-12-01 09:57:09 -07008392 VkDescriptorSetLayout ds_layout_fs_only = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008393 // Create 4 unique layouts for full pipelineLayout, and 1 special fs-only
8394 // layout for error case
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008395 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout[0]);
Tobin Ehlis559c6382015-11-05 09:52:49 -07008396 ASSERT_VK_SUCCESS(err);
Jon Ashburn6e23c1f2015-12-30 18:01:16 -07008397 ds_layout_ci.pBindings = &dsl_fs_stage_only;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008398 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout_fs_only);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07008399 ASSERT_VK_SUCCESS(err);
Tobin Ehlis559c6382015-11-05 09:52:49 -07008400 dsl_binding[0].binding = 0;
8401 dsl_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE;
Tobin Ehlis8fab6562015-12-01 09:57:09 -07008402 dsl_binding[0].descriptorCount = 2;
Mike Stroyan9c70cdb2016-01-06 14:14:17 -07008403 dsl_binding[1].binding = 1;
8404 dsl_binding[1].descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_IMAGE;
8405 dsl_binding[1].descriptorCount = 2;
8406 dsl_binding[1].stageFlags = VK_SHADER_STAGE_ALL;
8407 dsl_binding[1].pImmutableSamplers = NULL;
Jon Ashburn6e23c1f2015-12-30 18:01:16 -07008408 ds_layout_ci.pBindings = dsl_binding;
Tobin Ehlis559c6382015-11-05 09:52:49 -07008409 ds_layout_ci.bindingCount = 2;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008410 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout[1]);
Tobin Ehlis559c6382015-11-05 09:52:49 -07008411 ASSERT_VK_SUCCESS(err);
8412 dsl_binding[0].binding = 0;
8413 dsl_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
Tobin Ehlis8fab6562015-12-01 09:57:09 -07008414 dsl_binding[0].descriptorCount = 5;
Tobin Ehlis559c6382015-11-05 09:52:49 -07008415 ds_layout_ci.bindingCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008416 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout[2]);
Tobin Ehlis559c6382015-11-05 09:52:49 -07008417 ASSERT_VK_SUCCESS(err);
8418 dsl_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
Tobin Ehlis8fab6562015-12-01 09:57:09 -07008419 dsl_binding[0].descriptorCount = 2;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008420 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout[3]);
Tobin Ehlis559c6382015-11-05 09:52:49 -07008421 ASSERT_VK_SUCCESS(err);
8422
8423 static const uint32_t NUM_SETS = 4;
8424 VkDescriptorSet descriptorSet[NUM_SETS] = {};
8425 VkDescriptorSetAllocateInfo alloc_info = {};
Tobin Ehlis8fab6562015-12-01 09:57:09 -07008426 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07008427 alloc_info.descriptorSetCount = NUM_LAYOUTS;
Tobin Ehlis559c6382015-11-05 09:52:49 -07008428 alloc_info.descriptorPool = ds_pool;
8429 alloc_info.pSetLayouts = ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008430 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, descriptorSet);
Tobin Ehlis559c6382015-11-05 09:52:49 -07008431 ASSERT_VK_SUCCESS(err);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07008432 VkDescriptorSet ds0_fs_only = {};
Jon Ashburnf19916e2016-01-11 13:12:43 -07008433 alloc_info.descriptorSetCount = 1;
Tobin Ehlis8fab6562015-12-01 09:57:09 -07008434 alloc_info.pSetLayouts = &ds_layout_fs_only;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008435 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &ds0_fs_only);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07008436 ASSERT_VK_SUCCESS(err);
Tobin Ehlis559c6382015-11-05 09:52:49 -07008437
8438 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008439 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
8440 pipeline_layout_ci.pNext = NULL;
8441 pipeline_layout_ci.setLayoutCount = NUM_LAYOUTS;
8442 pipeline_layout_ci.pSetLayouts = ds_layout;
Tobin Ehlis559c6382015-11-05 09:52:49 -07008443
8444 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008445 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis559c6382015-11-05 09:52:49 -07008446 ASSERT_VK_SUCCESS(err);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07008447 // Create pipelineLayout with only one setLayout
8448 pipeline_layout_ci.setLayoutCount = 1;
8449 VkPipelineLayout single_pipe_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008450 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &single_pipe_layout);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07008451 ASSERT_VK_SUCCESS(err);
8452 // Create pipelineLayout with 2 descriptor setLayout at index 0
8453 pipeline_layout_ci.pSetLayouts = &ds_layout[3];
8454 VkPipelineLayout pipe_layout_one_desc;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008455 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipe_layout_one_desc);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07008456 ASSERT_VK_SUCCESS(err);
8457 // Create pipelineLayout with 5 SAMPLER descriptor setLayout at index 0
8458 pipeline_layout_ci.pSetLayouts = &ds_layout[2];
8459 VkPipelineLayout pipe_layout_five_samp;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008460 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipe_layout_five_samp);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07008461 ASSERT_VK_SUCCESS(err);
8462 // Create pipelineLayout with UB type, but stageFlags for FS only
8463 pipeline_layout_ci.pSetLayouts = &ds_layout_fs_only;
8464 VkPipelineLayout pipe_layout_fs_only;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008465 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipe_layout_fs_only);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07008466 ASSERT_VK_SUCCESS(err);
8467 // Create pipelineLayout w/ incompatible set0 layout, but set1 is fine
8468 VkDescriptorSetLayout pl_bad_s0[2] = {};
8469 pl_bad_s0[0] = ds_layout_fs_only;
8470 pl_bad_s0[1] = ds_layout[1];
8471 pipeline_layout_ci.setLayoutCount = 2;
8472 pipeline_layout_ci.pSetLayouts = pl_bad_s0;
8473 VkPipelineLayout pipe_layout_bad_set0;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008474 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipe_layout_bad_set0);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07008475 ASSERT_VK_SUCCESS(err);
Tobin Ehlis559c6382015-11-05 09:52:49 -07008476
8477 // Create a buffer to update the descriptor with
8478 uint32_t qfi = 0;
8479 VkBufferCreateInfo buffCI = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008480 buffCI.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
8481 buffCI.size = 1024;
8482 buffCI.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
8483 buffCI.queueFamilyIndexCount = 1;
8484 buffCI.pQueueFamilyIndices = &qfi;
Tobin Ehlis559c6382015-11-05 09:52:49 -07008485
8486 VkBuffer dyub;
8487 err = vkCreateBuffer(m_device->device(), &buffCI, NULL, &dyub);
8488 ASSERT_VK_SUCCESS(err);
8489 // Correctly update descriptor to avoid "NOT_UPDATED" error
8490 static const uint32_t NUM_BUFFS = 5;
8491 VkDescriptorBufferInfo buffInfo[NUM_BUFFS] = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008492 for (uint32_t i = 0; i < NUM_BUFFS; ++i) {
Tobin Ehlis559c6382015-11-05 09:52:49 -07008493 buffInfo[i].buffer = dyub;
8494 buffInfo[i].offset = 0;
8495 buffInfo[i].range = 1024;
8496 }
Karl Schultz6addd812016-02-02 17:17:23 -07008497 VkImage image;
Karl Schultz6addd812016-02-02 17:17:23 -07008498 const int32_t tex_width = 32;
8499 const int32_t tex_height = 32;
Tobin Ehlis8fab6562015-12-01 09:57:09 -07008500 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008501 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
8502 image_create_info.pNext = NULL;
8503 image_create_info.imageType = VK_IMAGE_TYPE_2D;
8504 image_create_info.format = tex_format;
8505 image_create_info.extent.width = tex_width;
8506 image_create_info.extent.height = tex_height;
8507 image_create_info.extent.depth = 1;
8508 image_create_info.mipLevels = 1;
8509 image_create_info.arrayLayers = 1;
8510 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
Mike Stroyanb8a61002016-06-20 16:00:28 -06008511 image_create_info.tiling = tiling;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008512 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT | VK_IMAGE_USAGE_STORAGE_BIT;
Karl Schultz6addd812016-02-02 17:17:23 -07008513 image_create_info.flags = 0;
Tobin Ehlis8fab6562015-12-01 09:57:09 -07008514 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
8515 ASSERT_VK_SUCCESS(err);
Tobin Ehlis559c6382015-11-05 09:52:49 -07008516
Karl Schultz6addd812016-02-02 17:17:23 -07008517 VkMemoryRequirements memReqs;
8518 VkDeviceMemory imageMem;
8519 bool pass;
Mike Stroyan9c70cdb2016-01-06 14:14:17 -07008520 VkMemoryAllocateInfo memAlloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008521 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
8522 memAlloc.pNext = NULL;
8523 memAlloc.allocationSize = 0;
8524 memAlloc.memoryTypeIndex = 0;
Mike Stroyan9c70cdb2016-01-06 14:14:17 -07008525 vkGetImageMemoryRequirements(m_device->device(), image, &memReqs);
8526 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008527 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Mike Stroyan9c70cdb2016-01-06 14:14:17 -07008528 ASSERT_TRUE(pass);
8529 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &imageMem);
8530 ASSERT_VK_SUCCESS(err);
8531 err = vkBindImageMemory(m_device->device(), image, imageMem, 0);
8532 ASSERT_VK_SUCCESS(err);
8533
Tobin Ehlis8fab6562015-12-01 09:57:09 -07008534 VkImageViewCreateInfo image_view_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008535 image_view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
8536 image_view_create_info.image = image;
8537 image_view_create_info.viewType = VK_IMAGE_VIEW_TYPE_2D;
8538 image_view_create_info.format = tex_format;
8539 image_view_create_info.subresourceRange.layerCount = 1;
8540 image_view_create_info.subresourceRange.baseMipLevel = 0;
8541 image_view_create_info.subresourceRange.levelCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008542 image_view_create_info.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Tobin Ehlis559c6382015-11-05 09:52:49 -07008543
Tobin Ehlis8fab6562015-12-01 09:57:09 -07008544 VkImageView view;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008545 err = vkCreateImageView(m_device->device(), &image_view_create_info, NULL, &view);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07008546 ASSERT_VK_SUCCESS(err);
Tobin Ehlis991d45a2016-01-06 08:48:41 -07008547 VkDescriptorImageInfo imageInfo[4] = {};
Tobin Ehlis8fab6562015-12-01 09:57:09 -07008548 imageInfo[0].imageView = view;
8549 imageInfo[0].imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
8550 imageInfo[1].imageView = view;
8551 imageInfo[1].imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
Tobin Ehlis991d45a2016-01-06 08:48:41 -07008552 imageInfo[2].imageView = view;
8553 imageInfo[2].imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
8554 imageInfo[3].imageView = view;
8555 imageInfo[3].imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
Tobin Ehlis8fab6562015-12-01 09:57:09 -07008556
8557 static const uint32_t NUM_SET_UPDATES = 3;
8558 VkWriteDescriptorSet descriptor_write[NUM_SET_UPDATES] = {};
8559 descriptor_write[0].sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
8560 descriptor_write[0].dstSet = descriptorSet[0];
8561 descriptor_write[0].dstBinding = 0;
8562 descriptor_write[0].descriptorCount = 5;
8563 descriptor_write[0].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
8564 descriptor_write[0].pBufferInfo = buffInfo;
8565 descriptor_write[1].sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
8566 descriptor_write[1].dstSet = descriptorSet[1];
8567 descriptor_write[1].dstBinding = 0;
8568 descriptor_write[1].descriptorCount = 2;
8569 descriptor_write[1].descriptorType = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE;
8570 descriptor_write[1].pImageInfo = imageInfo;
8571 descriptor_write[2].sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
8572 descriptor_write[2].dstSet = descriptorSet[1];
8573 descriptor_write[2].dstBinding = 1;
8574 descriptor_write[2].descriptorCount = 2;
8575 descriptor_write[2].descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_IMAGE;
Tobin Ehlis991d45a2016-01-06 08:48:41 -07008576 descriptor_write[2].pImageInfo = &imageInfo[2];
Tobin Ehlis8fab6562015-12-01 09:57:09 -07008577
8578 vkUpdateDescriptorSets(m_device->device(), 3, descriptor_write, 0, NULL);
Tobin Ehlis559c6382015-11-05 09:52:49 -07008579
Tobin Ehlis88452832015-12-03 09:40:56 -07008580 // Create PSO to be used for draw-time errors below
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008581 char const *vsSource = "#version 450\n"
8582 "\n"
8583 "out gl_PerVertex {\n"
8584 " vec4 gl_Position;\n"
8585 "};\n"
8586 "void main(){\n"
8587 " gl_Position = vec4(1);\n"
8588 "}\n";
8589 char const *fsSource = "#version 450\n"
8590 "\n"
8591 "layout(location=0) out vec4 x;\n"
8592 "layout(set=0) layout(binding=0) uniform foo { int x; int y; } bar;\n"
8593 "void main(){\n"
8594 " x = vec4(bar.y);\n"
8595 "}\n";
Tobin Ehlis88452832015-12-03 09:40:56 -07008596 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
8597 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Tobin Ehlis559c6382015-11-05 09:52:49 -07008598 VkPipelineObj pipe(m_device);
8599 pipe.AddShader(&vs);
8600 pipe.AddShader(&fs);
Tobin Ehlis88452832015-12-03 09:40:56 -07008601 pipe.AddColorAttachment();
8602 pipe.CreateVKPipeline(pipe_layout_fs_only, renderPass());
Tobin Ehlis559c6382015-11-05 09:52:49 -07008603
8604 BeginCommandBuffer();
Tobin Ehlis88452832015-12-03 09:40:56 -07008605
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008606 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Karl Schultz6addd812016-02-02 17:17:23 -07008607 // NOTE : I believe LunarG ilo driver has bug (LX#189) that requires binding
8608 // of PSO
8609 // here before binding DSs. Otherwise we assert in cmd_copy_dset_data() of
8610 // cmd_pipeline.c
8611 // due to the fact that cmd_alloc_dset_data() has not been called in
8612 // cmd_bind_graphics_pipeline()
8613 // TODO : Want to cause various binding incompatibility issues here to test
8614 // DrawState
Tobin Ehlis559c6382015-11-05 09:52:49 -07008615 // First cause various verify_layout_compatibility() fails
8616 // Second disturb early and late sets and verify INFO msgs
Tobin Ehlis8fab6562015-12-01 09:57:09 -07008617 // verify_set_layout_compatibility fail cases:
8618 // 1. invalid VkPipelineLayout (layout) passed into vkCmdBindDescriptorSets
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008619 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Invalid Pipeline Layout Object ");
8620 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS,
8621 (VkPipelineLayout)((size_t)0xbaadb1be), 0, 1, &descriptorSet[0], 0, NULL);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008622 m_errorMonitor->VerifyFound();
8623
Tobin Ehlis8fab6562015-12-01 09:57:09 -07008624 // 2. layoutIndex exceeds # of layouts in layout
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008625 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " attempting to bind set to index 1");
8626 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, single_pipe_layout, 0, 2,
8627 &descriptorSet[0], 0, NULL);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008628 m_errorMonitor->VerifyFound();
8629
Tobin Ehlis8fab6562015-12-01 09:57:09 -07008630 vkDestroyPipelineLayout(m_device->device(), single_pipe_layout, NULL);
Karl Schultz6addd812016-02-02 17:17:23 -07008631 // 3. Pipeline setLayout[0] has 2 descriptors, but set being bound has 5
8632 // descriptors
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008633 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " has 2 descriptors, but DescriptorSetLayout ");
8634 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe_layout_one_desc, 0, 1,
8635 &descriptorSet[0], 0, NULL);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008636 m_errorMonitor->VerifyFound();
8637
Tobin Ehlis8fab6562015-12-01 09:57:09 -07008638 vkDestroyPipelineLayout(m_device->device(), pipe_layout_one_desc, NULL);
8639 // 4. same # of descriptors but mismatch in type
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008640 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " is type 'VK_DESCRIPTOR_TYPE_SAMPLER' but binding ");
8641 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe_layout_five_samp, 0, 1,
8642 &descriptorSet[0], 0, NULL);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008643 m_errorMonitor->VerifyFound();
8644
Tobin Ehlis8fab6562015-12-01 09:57:09 -07008645 vkDestroyPipelineLayout(m_device->device(), pipe_layout_five_samp, NULL);
8646 // 5. same # of descriptors but mismatch in stageFlags
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008647 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
8648 " has stageFlags 16 but binding 0 for DescriptorSetLayout ");
8649 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe_layout_fs_only, 0, 1,
8650 &descriptorSet[0], 0, NULL);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008651 m_errorMonitor->VerifyFound();
8652
Tobin Ehlis8fab6562015-12-01 09:57:09 -07008653 // Cause INFO messages due to disturbing previously bound Sets
8654 // First bind sets 0 & 1
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008655 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 2,
8656 &descriptorSet[0], 0, NULL);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07008657 // 1. Disturb bound set0 by re-binding set1 w/ updated pipelineLayout
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008658 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT, " previously bound as set #0 was disturbed ");
8659 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe_layout_bad_set0, 1, 1,
8660 &descriptorSet[1], 0, NULL);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008661 m_errorMonitor->VerifyFound();
8662
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008663 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 2,
8664 &descriptorSet[0], 0, NULL);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07008665 // 2. Disturb set after last bound set
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008666 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT, " newly bound as set #0 so set #1 and "
8667 "any subsequent sets were disturbed ");
8668 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe_layout_fs_only, 0, 1,
8669 &ds0_fs_only, 0, NULL);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008670 m_errorMonitor->VerifyFound();
8671
Tobin Ehlis10fad692016-07-07 12:00:36 -06008672 // Now that we're done actively using the pipelineLayout that gfx pipeline
8673 // was created with, we should be able to delete it. Do that now to verify
8674 // that validation obeys pipelineLayout lifetime
8675 vkDestroyPipelineLayout(m_device->device(), pipe_layout_fs_only, NULL);
8676
Tobin Ehlis88452832015-12-03 09:40:56 -07008677 // Cause draw-time errors due to PSO incompatibilities
Karl Schultz6addd812016-02-02 17:17:23 -07008678 // 1. Error due to not binding required set (we actually use same code as
8679 // above to disturb set0)
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008680 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 2,
8681 &descriptorSet[0], 0, NULL);
8682 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe_layout_bad_set0, 1, 1,
8683 &descriptorSet[1], 0, NULL);
8684 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 -07008685 Draw(1, 0, 0, 0);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008686 m_errorMonitor->VerifyFound();
8687
Tobin Ehlis991d45a2016-01-06 08:48:41 -07008688 vkDestroyPipelineLayout(m_device->device(), pipe_layout_bad_set0, NULL);
Karl Schultz6addd812016-02-02 17:17:23 -07008689 // 2. Error due to bound set not being compatible with PSO's
8690 // VkPipelineLayout (diff stageFlags in this case)
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008691 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 2,
8692 &descriptorSet[0], 0, NULL);
8693 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " bound as set #0 is not compatible with ");
Tobin Ehlis88452832015-12-03 09:40:56 -07008694 Draw(1, 0, 0, 0);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008695 m_errorMonitor->VerifyFound();
8696
Tobin Ehlis8fab6562015-12-01 09:57:09 -07008697 // Remaining clean-up
Karl Schultz6addd812016-02-02 17:17:23 -07008698 for (uint32_t i = 0; i < NUM_LAYOUTS; ++i) {
Tobin Ehlis8fab6562015-12-01 09:57:09 -07008699 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout[i], NULL);
8700 }
8701 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout_fs_only, NULL);
Tobin Ehlis9bfd4492016-05-05 15:09:11 -06008702 vkFreeDescriptorSets(m_device->device(), ds_pool, 1, &ds0_fs_only);
8703 vkFreeDescriptorSets(m_device->device(), ds_pool, NUM_SETS, descriptorSet);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07008704 vkDestroyBuffer(m_device->device(), dyub, NULL);
Tobin Ehlis559c6382015-11-05 09:52:49 -07008705 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
8706 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tony Barbourdf4c0042016-06-01 15:55:43 -06008707 vkFreeMemory(m_device->device(), imageMem, NULL);
8708 vkDestroyImage(m_device->device(), image, NULL);
8709 vkDestroyImageView(m_device->device(), view, NULL);
Tobin Ehlis559c6382015-11-05 09:52:49 -07008710}
Tobin Ehlis559c6382015-11-05 09:52:49 -07008711
Karl Schultz6addd812016-02-02 17:17:23 -07008712TEST_F(VkLayerTest, NoBeginCommandBuffer) {
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06008713
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008714 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
8715 "You must call vkBeginCommandBuffer() before this call to ");
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06008716
8717 ASSERT_NO_FATAL_FAILURE(InitState());
Chia-I Wu3432a0c2015-10-27 18:04:07 +08008718 VkCommandBufferObj commandBuffer(m_device, m_commandPool);
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06008719 // Call EndCommandBuffer() w/o calling BeginCommandBuffer()
Chia-I Wu3432a0c2015-10-27 18:04:07 +08008720 vkEndCommandBuffer(commandBuffer.GetBufferHandle());
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06008721
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008722 m_errorMonitor->VerifyFound();
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06008723}
8724
Karl Schultz6addd812016-02-02 17:17:23 -07008725TEST_F(VkLayerTest, SecondaryCommandBufferNullRenderpass) {
8726 VkResult err;
8727 VkCommandBuffer draw_cmd;
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06008728
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008729 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " must specify a valid renderpass parameter.");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06008730
Mark Lobodzinskid9139a62015-08-04 16:24:20 -06008731 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinskid9139a62015-08-04 16:24:20 -06008732
Chia-I Wu3432a0c2015-10-27 18:04:07 +08008733 VkCommandBufferAllocateInfo cmd = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08008734 cmd.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
Cody Northropb4569702015-08-04 17:35:57 -06008735 cmd.pNext = NULL;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08008736 cmd.commandPool = m_commandPool;
8737 cmd.level = VK_COMMAND_BUFFER_LEVEL_SECONDARY;
Jon Ashburnf19916e2016-01-11 13:12:43 -07008738 cmd.commandBufferCount = 1;
Cody Northropb4569702015-08-04 17:35:57 -06008739
Chia-I Wu3432a0c2015-10-27 18:04:07 +08008740 err = vkAllocateCommandBuffers(m_device->device(), &cmd, &draw_cmd);
Mike Stroyand1c84a52015-08-18 14:40:24 -06008741 ASSERT_VK_SUCCESS(err);
Mark Lobodzinskid9139a62015-08-04 16:24:20 -06008742
8743 // Force the failure by not setting the Renderpass and Framebuffer fields
Chia-I Wu3432a0c2015-10-27 18:04:07 +08008744 VkCommandBufferBeginInfo cmd_buf_info = {};
Jon Ashburnf19916e2016-01-11 13:12:43 -07008745 VkCommandBufferInheritanceInfo cmd_buf_hinfo = {};
Chia-I Wu3432a0c2015-10-27 18:04:07 +08008746 cmd_buf_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
Cody Northropb4569702015-08-04 17:35:57 -06008747 cmd_buf_info.pNext = NULL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008748 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 -07008749 cmd_buf_info.pInheritanceInfo = &cmd_buf_hinfo;
Mark Lobodzinskid9139a62015-08-04 16:24:20 -06008750
8751 // The error should be caught by validation of the BeginCommandBuffer call
8752 vkBeginCommandBuffer(draw_cmd, &cmd_buf_info);
8753
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008754 m_errorMonitor->VerifyFound();
Chia-I Wu3432a0c2015-10-27 18:04:07 +08008755 vkFreeCommandBuffers(m_device->device(), m_commandPool, 1, &draw_cmd);
Mark Lobodzinskid9139a62015-08-04 16:24:20 -06008756}
8757
Karl Schultz6addd812016-02-02 17:17:23 -07008758TEST_F(VkLayerTest, CommandBufferResetErrors) {
Tobin Ehlisac0ef842015-12-14 13:46:38 -07008759 // Cause error due to Begin while recording CB
8760 // Then cause 2 errors for attempting to reset CB w/o having
8761 // VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT set for the pool from
8762 // which CBs were allocated. Note that this bit is off by default.
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008763 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Cannot call Begin on CB");
Tobin Ehlisac0ef842015-12-14 13:46:38 -07008764
8765 ASSERT_NO_FATAL_FAILURE(InitState());
8766
8767 // Calls AllocateCommandBuffers
8768 VkCommandBufferObj commandBuffer(m_device, m_commandPool);
8769
Karl Schultz6addd812016-02-02 17:17:23 -07008770 // Force the failure by setting the Renderpass and Framebuffer fields with
8771 // (fake) data
Tobin Ehlisac0ef842015-12-14 13:46:38 -07008772 VkCommandBufferBeginInfo cmd_buf_info = {};
Jon Ashburnf19916e2016-01-11 13:12:43 -07008773 VkCommandBufferInheritanceInfo cmd_buf_hinfo = {};
Tobin Ehlisac0ef842015-12-14 13:46:38 -07008774 cmd_buf_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
8775 cmd_buf_info.pNext = NULL;
8776 cmd_buf_info.flags = VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT;
Jon Ashburnf19916e2016-01-11 13:12:43 -07008777 cmd_buf_info.pInheritanceInfo = &cmd_buf_hinfo;
Tobin Ehlisac0ef842015-12-14 13:46:38 -07008778
8779 // Begin CB to transition to recording state
8780 vkBeginCommandBuffer(commandBuffer.GetBufferHandle(), &cmd_buf_info);
8781 // Can't re-begin. This should trigger error
8782 vkBeginCommandBuffer(commandBuffer.GetBufferHandle(), &cmd_buf_info);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008783 m_errorMonitor->VerifyFound();
8784
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008785 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Attempt to reset command buffer ");
Tobin Ehlisac0ef842015-12-14 13:46:38 -07008786 VkCommandBufferResetFlags flags = 0; // Don't care about flags for this test
8787 // Reset attempt will trigger error due to incorrect CommandPool state
8788 vkResetCommandBuffer(commandBuffer.GetBufferHandle(), flags);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008789 m_errorMonitor->VerifyFound();
8790
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008791 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " attempts to implicitly reset cmdBuffer created from ");
Tobin Ehlisac0ef842015-12-14 13:46:38 -07008792 // Transition CB to RECORDED state
8793 vkEndCommandBuffer(commandBuffer.GetBufferHandle());
8794 // Now attempting to Begin will implicitly reset, which triggers error
8795 vkBeginCommandBuffer(commandBuffer.GetBufferHandle(), &cmd_buf_info);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008796 m_errorMonitor->VerifyFound();
Tobin Ehlisac0ef842015-12-14 13:46:38 -07008797}
8798
Karl Schultz6addd812016-02-02 17:17:23 -07008799TEST_F(VkLayerTest, InvalidPipelineCreateState) {
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06008800 // Attempt to Create Gfx Pipeline w/o a VS
Karl Schultz6addd812016-02-02 17:17:23 -07008801 VkResult err;
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06008802
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008803 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Invalid Pipeline CreateInfo State: Vtx Shader required");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06008804
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06008805 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06008806 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Mark Lobodzinski209b5292015-09-17 09:44:05 -06008807
Chia-I Wu1b99bb22015-10-27 19:25:11 +08008808 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008809 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
8810 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -06008811
8812 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008813 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
8814 ds_pool_ci.pNext = NULL;
8815 ds_pool_ci.maxSets = 1;
8816 ds_pool_ci.poolSizeCount = 1;
8817 ds_pool_ci.pPoolSizes = &ds_type_count;
Mark Lobodzinski209b5292015-09-17 09:44:05 -06008818
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06008819 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008820 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06008821 ASSERT_VK_SUCCESS(err);
8822
Tony Barboureb254902015-07-15 12:50:33 -06008823 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008824 dsl_binding.binding = 0;
8825 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
8826 dsl_binding.descriptorCount = 1;
8827 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
8828 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06008829
Tony Barboureb254902015-07-15 12:50:33 -06008830 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008831 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
8832 ds_layout_ci.pNext = NULL;
8833 ds_layout_ci.bindingCount = 1;
8834 ds_layout_ci.pBindings = &dsl_binding;
Tony Barboureb254902015-07-15 12:50:33 -06008835
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06008836 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008837 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06008838 ASSERT_VK_SUCCESS(err);
8839
8840 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08008841 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08008842 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07008843 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06008844 alloc_info.descriptorPool = ds_pool;
8845 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008846 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06008847 ASSERT_VK_SUCCESS(err);
8848
Tony Barboureb254902015-07-15 12:50:33 -06008849 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008850 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
8851 pipeline_layout_ci.setLayoutCount = 1;
8852 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06008853
8854 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008855 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06008856 ASSERT_VK_SUCCESS(err);
8857
Tobin Ehlise68360f2015-10-01 11:15:13 -06008858 VkViewport vp = {}; // Just need dummy vp to point to
Karl Schultz6addd812016-02-02 17:17:23 -07008859 VkRect2D sc = {}; // dummy scissor to point to
Tobin Ehlise68360f2015-10-01 11:15:13 -06008860
8861 VkPipelineViewportStateCreateInfo vp_state_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008862 vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
8863 vp_state_ci.scissorCount = 1;
8864 vp_state_ci.pScissors = &sc;
8865 vp_state_ci.viewportCount = 1;
8866 vp_state_ci.pViewports = &vp;
Tobin Ehlise68360f2015-10-01 11:15:13 -06008867
Karl Schultzdfdb8d42016-03-08 10:30:21 -07008868 VkPipelineRasterizationStateCreateInfo rs_state_ci = {};
8869 rs_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
8870 rs_state_ci.polygonMode = VK_POLYGON_MODE_FILL;
8871 rs_state_ci.cullMode = VK_CULL_MODE_BACK_BIT;
8872 rs_state_ci.frontFace = VK_FRONT_FACE_COUNTER_CLOCKWISE;
8873 rs_state_ci.depthClampEnable = VK_FALSE;
8874 rs_state_ci.rasterizerDiscardEnable = VK_FALSE;
8875 rs_state_ci.depthBiasEnable = VK_FALSE;
8876
Tony Barboureb254902015-07-15 12:50:33 -06008877 VkGraphicsPipelineCreateInfo gp_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008878 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
8879 gp_ci.pViewportState = &vp_state_ci;
Karl Schultzdfdb8d42016-03-08 10:30:21 -07008880 gp_ci.pRasterizationState = &rs_state_ci;
Karl Schultz6addd812016-02-02 17:17:23 -07008881 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
8882 gp_ci.layout = pipeline_layout;
8883 gp_ci.renderPass = renderPass();
Tony Barboureb254902015-07-15 12:50:33 -06008884
8885 VkPipelineCacheCreateInfo pc_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008886 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
8887 pc_ci.initialDataSize = 0;
8888 pc_ci.pInitialData = 0;
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06008889
8890 VkPipeline pipeline;
Jon Ashburnc669cc62015-07-09 15:02:25 -06008891 VkPipelineCache pipelineCache;
8892
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008893 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Jon Ashburnc669cc62015-07-09 15:02:25 -06008894 ASSERT_VK_SUCCESS(err);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008895 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06008896
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008897 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06008898
Chia-I Wuf7458c52015-10-26 21:10:41 +08008899 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
8900 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
8901 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
8902 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06008903}
Tobin Ehlis912df022015-09-17 08:46:18 -06008904/*// TODO : This test should be good, but needs Tess support in compiler to run
8905TEST_F(VkLayerTest, InvalidPatchControlPoints)
8906{
8907 // Attempt to Create Gfx Pipeline w/o a VS
Tobin Ehlis912df022015-09-17 08:46:18 -06008908 VkResult err;
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06008909
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07008910 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Karl Schultz6addd812016-02-02 17:17:23 -07008911 "Invalid Pipeline CreateInfo State: VK_PRIMITIVE_TOPOLOGY_PATCH
8912primitive ");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06008913
Tobin Ehlis912df022015-09-17 08:46:18 -06008914 ASSERT_NO_FATAL_FAILURE(InitState());
8915 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlis912df022015-09-17 08:46:18 -06008916
Chia-I Wu1b99bb22015-10-27 19:25:11 +08008917 VkDescriptorPoolSize ds_type_count = {};
Tobin Ehlis912df022015-09-17 08:46:18 -06008918 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Chia-I Wud50a7d72015-10-26 20:48:51 +08008919 ds_type_count.descriptorCount = 1;
Tobin Ehlis912df022015-09-17 08:46:18 -06008920
8921 VkDescriptorPoolCreateInfo ds_pool_ci = {};
8922 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
8923 ds_pool_ci.pNext = NULL;
Chia-I Wu1b99bb22015-10-27 19:25:11 +08008924 ds_pool_ci.poolSizeCount = 1;
8925 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlis912df022015-09-17 08:46:18 -06008926
8927 VkDescriptorPool ds_pool;
Karl Schultz6addd812016-02-02 17:17:23 -07008928 err = vkCreateDescriptorPool(m_device->device(),
8929VK_DESCRIPTOR_POOL_USAGE_NON_FREE, 1, &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis912df022015-09-17 08:46:18 -06008930 ASSERT_VK_SUCCESS(err);
8931
8932 VkDescriptorSetLayoutBinding dsl_binding = {};
Chia-I Wud46e6ae2015-10-31 00:31:16 +08008933 dsl_binding.binding = 0;
Tobin Ehlis912df022015-09-17 08:46:18 -06008934 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Chia-I Wu02124482015-11-06 06:42:02 +08008935 dsl_binding.descriptorCount = 1;
Tobin Ehlis912df022015-09-17 08:46:18 -06008936 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
8937 dsl_binding.pImmutableSamplers = NULL;
8938
8939 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008940 ds_layout_ci.sType =
8941VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
Tobin Ehlis912df022015-09-17 08:46:18 -06008942 ds_layout_ci.pNext = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08008943 ds_layout_ci.bindingCount = 1;
Jon Ashburn6e23c1f2015-12-30 18:01:16 -07008944 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlis912df022015-09-17 08:46:18 -06008945
8946 VkDescriptorSetLayout ds_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07008947 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL,
8948&ds_layout);
Tobin Ehlis912df022015-09-17 08:46:18 -06008949 ASSERT_VK_SUCCESS(err);
8950
8951 VkDescriptorSet descriptorSet;
Karl Schultz6addd812016-02-02 17:17:23 -07008952 err = vkAllocateDescriptorSets(m_device->device(), ds_pool,
8953VK_DESCRIPTOR_SET_USAGE_NON_FREE, 1, &ds_layout, &descriptorSet);
Tobin Ehlis912df022015-09-17 08:46:18 -06008954 ASSERT_VK_SUCCESS(err);
8955
8956 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008957 pipeline_layout_ci.sType =
8958VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
Tobin Ehlis912df022015-09-17 08:46:18 -06008959 pipeline_layout_ci.pNext = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08008960 pipeline_layout_ci.setLayoutCount = 1;
Tobin Ehlis912df022015-09-17 08:46:18 -06008961 pipeline_layout_ci.pSetLayouts = &ds_layout;
8962
8963 VkPipelineLayout pipeline_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07008964 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL,
8965&pipeline_layout);
Tobin Ehlis912df022015-09-17 08:46:18 -06008966 ASSERT_VK_SUCCESS(err);
8967
8968 VkPipelineShaderStageCreateInfo shaderStages[3];
8969 memset(&shaderStages, 0, 3 * sizeof(VkPipelineShaderStageCreateInfo));
8970
Karl Schultz6addd812016-02-02 17:17:23 -07008971 VkShaderObj vs(m_device,bindStateVertShaderText,VK_SHADER_STAGE_VERTEX_BIT,
8972this);
Tobin Ehlis912df022015-09-17 08:46:18 -06008973 // Just using VS txt for Tess shaders as we don't care about functionality
Karl Schultz6addd812016-02-02 17:17:23 -07008974 VkShaderObj
8975tc(m_device,bindStateVertShaderText,VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT,
8976this);
8977 VkShaderObj
8978te(m_device,bindStateVertShaderText,VK_SHADER_STAGE_TESSELLATION_EVALUATION_BIT,
8979this);
Tobin Ehlis912df022015-09-17 08:46:18 -06008980
Karl Schultz6addd812016-02-02 17:17:23 -07008981 shaderStages[0].sType =
8982VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO;
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -06008983 shaderStages[0].stage = VK_SHADER_STAGE_VERTEX_BIT;
Tobin Ehlis912df022015-09-17 08:46:18 -06008984 shaderStages[0].shader = vs.handle();
Karl Schultz6addd812016-02-02 17:17:23 -07008985 shaderStages[1].sType =
8986VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO;
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -06008987 shaderStages[1].stage = VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT;
Tobin Ehlis912df022015-09-17 08:46:18 -06008988 shaderStages[1].shader = tc.handle();
Karl Schultz6addd812016-02-02 17:17:23 -07008989 shaderStages[2].sType =
8990VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO;
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -06008991 shaderStages[2].stage = VK_SHADER_STAGE_TESSELLATION_EVALUATION_BIT;
Tobin Ehlis912df022015-09-17 08:46:18 -06008992 shaderStages[2].shader = te.handle();
8993
8994 VkPipelineInputAssemblyStateCreateInfo iaCI = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008995 iaCI.sType =
8996VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
Chia-I Wu515eb8f2015-10-31 00:31:16 +08008997 iaCI.topology = VK_PRIMITIVE_TOPOLOGY_PATCH_LIST;
Tobin Ehlis912df022015-09-17 08:46:18 -06008998
8999 VkPipelineTessellationStateCreateInfo tsCI = {};
9000 tsCI.sType = VK_STRUCTURE_TYPE_PIPELINE_TESSELLATION_STATE_CREATE_INFO;
9001 tsCI.patchControlPoints = 0; // This will cause an error
9002
9003 VkGraphicsPipelineCreateInfo gp_ci = {};
9004 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
9005 gp_ci.pNext = NULL;
9006 gp_ci.stageCount = 3;
9007 gp_ci.pStages = shaderStages;
9008 gp_ci.pVertexInputState = NULL;
9009 gp_ci.pInputAssemblyState = &iaCI;
9010 gp_ci.pTessellationState = &tsCI;
9011 gp_ci.pViewportState = NULL;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009012 gp_ci.pRasterizationState = NULL;
Tobin Ehlis912df022015-09-17 08:46:18 -06009013 gp_ci.pMultisampleState = NULL;
9014 gp_ci.pDepthStencilState = NULL;
9015 gp_ci.pColorBlendState = NULL;
9016 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
9017 gp_ci.layout = pipeline_layout;
9018 gp_ci.renderPass = renderPass();
9019
9020 VkPipelineCacheCreateInfo pc_ci = {};
9021 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
9022 pc_ci.pNext = NULL;
9023 pc_ci.initialSize = 0;
9024 pc_ci.initialData = 0;
9025 pc_ci.maxSize = 0;
9026
9027 VkPipeline pipeline;
9028 VkPipelineCache pipelineCache;
9029
Karl Schultz6addd812016-02-02 17:17:23 -07009030 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL,
9031&pipelineCache);
Tobin Ehlis912df022015-09-17 08:46:18 -06009032 ASSERT_VK_SUCCESS(err);
Karl Schultz6addd812016-02-02 17:17:23 -07009033 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1,
9034&gp_ci, NULL, &pipeline);
Tobin Ehlis912df022015-09-17 08:46:18 -06009035
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009036 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06009037
Chia-I Wuf7458c52015-10-26 21:10:41 +08009038 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
9039 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
9040 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
9041 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis912df022015-09-17 08:46:18 -06009042}
9043*/
Tobin Ehlise68360f2015-10-01 11:15:13 -06009044// Set scissor and viewport counts to different numbers
Karl Schultz6addd812016-02-02 17:17:23 -07009045TEST_F(VkLayerTest, PSOViewportScissorCountMismatch) {
Karl Schultz6addd812016-02-02 17:17:23 -07009046 VkResult err;
Tobin Ehlise68360f2015-10-01 11:15:13 -06009047
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009048 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
9049 "Gfx Pipeline viewport count (1) must match scissor count (0).");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06009050
Tobin Ehlise68360f2015-10-01 11:15:13 -06009051 ASSERT_NO_FATAL_FAILURE(InitState());
9052 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlise68360f2015-10-01 11:15:13 -06009053
Chia-I Wu1b99bb22015-10-27 19:25:11 +08009054 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009055 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
9056 ds_type_count.descriptorCount = 1;
Tobin Ehlise68360f2015-10-01 11:15:13 -06009057
9058 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009059 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
9060 ds_pool_ci.maxSets = 1;
9061 ds_pool_ci.poolSizeCount = 1;
9062 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlise68360f2015-10-01 11:15:13 -06009063
9064 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009065 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlise68360f2015-10-01 11:15:13 -06009066 ASSERT_VK_SUCCESS(err);
9067
9068 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009069 dsl_binding.binding = 0;
9070 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
9071 dsl_binding.descriptorCount = 1;
9072 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
Tobin Ehlise68360f2015-10-01 11:15:13 -06009073
9074 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009075 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
9076 ds_layout_ci.bindingCount = 1;
9077 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlise68360f2015-10-01 11:15:13 -06009078
9079 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009080 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlise68360f2015-10-01 11:15:13 -06009081 ASSERT_VK_SUCCESS(err);
9082
9083 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009084 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08009085 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07009086 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06009087 alloc_info.descriptorPool = ds_pool;
9088 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009089 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlise68360f2015-10-01 11:15:13 -06009090 ASSERT_VK_SUCCESS(err);
9091
9092 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009093 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
9094 pipeline_layout_ci.setLayoutCount = 1;
9095 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlise68360f2015-10-01 11:15:13 -06009096
9097 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009098 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlise68360f2015-10-01 11:15:13 -06009099 ASSERT_VK_SUCCESS(err);
9100
9101 VkViewport vp = {}; // Just need dummy vp to point to
9102
9103 VkPipelineViewportStateCreateInfo vp_state_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009104 vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
9105 vp_state_ci.scissorCount = 0;
9106 vp_state_ci.viewportCount = 1; // Count mismatch should cause error
9107 vp_state_ci.pViewports = &vp;
Tobin Ehlise68360f2015-10-01 11:15:13 -06009108
Karl Schultzdfdb8d42016-03-08 10:30:21 -07009109 VkPipelineRasterizationStateCreateInfo rs_state_ci = {};
9110 rs_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
9111 rs_state_ci.polygonMode = VK_POLYGON_MODE_FILL;
9112 rs_state_ci.cullMode = VK_CULL_MODE_BACK_BIT;
9113 rs_state_ci.frontFace = VK_FRONT_FACE_COUNTER_CLOCKWISE;
9114 rs_state_ci.depthClampEnable = VK_FALSE;
9115 rs_state_ci.rasterizerDiscardEnable = VK_FALSE;
9116 rs_state_ci.depthBiasEnable = VK_FALSE;
9117
Cody Northropeb3a6c12015-10-05 14:44:45 -06009118 VkPipelineShaderStageCreateInfo shaderStages[2];
Karl Schultz6addd812016-02-02 17:17:23 -07009119 memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo));
Tobin Ehlise68360f2015-10-01 11:15:13 -06009120
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009121 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
9122 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this); // We shouldn't need a fragment shader
9123 // but add it to be able to run on more devices
Chia-I Wu28e06912015-10-31 00:31:16 +08009124 shaderStages[0] = vs.GetStageCreateInfo();
9125 shaderStages[1] = fs.GetStageCreateInfo();
Tobin Ehlise68360f2015-10-01 11:15:13 -06009126
9127 VkGraphicsPipelineCreateInfo gp_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009128 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
9129 gp_ci.stageCount = 2;
9130 gp_ci.pStages = shaderStages;
9131 gp_ci.pViewportState = &vp_state_ci;
Karl Schultzdfdb8d42016-03-08 10:30:21 -07009132 gp_ci.pRasterizationState = &rs_state_ci;
Karl Schultz6addd812016-02-02 17:17:23 -07009133 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
9134 gp_ci.layout = pipeline_layout;
9135 gp_ci.renderPass = renderPass();
Tobin Ehlise68360f2015-10-01 11:15:13 -06009136
9137 VkPipelineCacheCreateInfo pc_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009138 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
Tobin Ehlise68360f2015-10-01 11:15:13 -06009139
9140 VkPipeline pipeline;
9141 VkPipelineCache pipelineCache;
9142
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009143 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Tobin Ehlise68360f2015-10-01 11:15:13 -06009144 ASSERT_VK_SUCCESS(err);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009145 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Tobin Ehlise68360f2015-10-01 11:15:13 -06009146
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009147 m_errorMonitor->VerifyFound();
Tobin Ehlise68360f2015-10-01 11:15:13 -06009148
Chia-I Wuf7458c52015-10-26 21:10:41 +08009149 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
9150 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
9151 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
9152 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlise68360f2015-10-01 11:15:13 -06009153}
Karl Schultz6addd812016-02-02 17:17:23 -07009154// Don't set viewport state in PSO. This is an error b/c we always need this
9155// state
Tobin Ehlisd332f282015-10-02 11:00:56 -06009156// for the counts even if the data is going to be set dynamically.
Karl Schultz6addd812016-02-02 17:17:23 -07009157TEST_F(VkLayerTest, PSOViewportStateNotSet) {
Tobin Ehlise68360f2015-10-01 11:15:13 -06009158 // Attempt to Create Gfx Pipeline w/o a VS
Karl Schultz6addd812016-02-02 17:17:23 -07009159 VkResult err;
Tobin Ehlise68360f2015-10-01 11:15:13 -06009160
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009161 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Gfx Pipeline pViewportState is null. Even if ");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06009162
Tobin Ehlise68360f2015-10-01 11:15:13 -06009163 ASSERT_NO_FATAL_FAILURE(InitState());
9164 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlise68360f2015-10-01 11:15:13 -06009165
Chia-I Wu1b99bb22015-10-27 19:25:11 +08009166 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009167 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
9168 ds_type_count.descriptorCount = 1;
Tobin Ehlise68360f2015-10-01 11:15:13 -06009169
9170 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009171 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
9172 ds_pool_ci.maxSets = 1;
9173 ds_pool_ci.poolSizeCount = 1;
9174 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlise68360f2015-10-01 11:15:13 -06009175
9176 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009177 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlise68360f2015-10-01 11:15:13 -06009178 ASSERT_VK_SUCCESS(err);
9179
9180 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009181 dsl_binding.binding = 0;
9182 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
9183 dsl_binding.descriptorCount = 1;
9184 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
Tobin Ehlise68360f2015-10-01 11:15:13 -06009185
9186 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009187 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
9188 ds_layout_ci.bindingCount = 1;
9189 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlise68360f2015-10-01 11:15:13 -06009190
9191 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009192 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlise68360f2015-10-01 11:15:13 -06009193 ASSERT_VK_SUCCESS(err);
9194
9195 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009196 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08009197 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07009198 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06009199 alloc_info.descriptorPool = ds_pool;
9200 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009201 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlise68360f2015-10-01 11:15:13 -06009202 ASSERT_VK_SUCCESS(err);
9203
9204 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009205 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
9206 pipeline_layout_ci.setLayoutCount = 1;
9207 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlise68360f2015-10-01 11:15:13 -06009208
9209 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009210 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlise68360f2015-10-01 11:15:13 -06009211 ASSERT_VK_SUCCESS(err);
9212
9213 VkDynamicState sc_state = VK_DYNAMIC_STATE_SCISSOR;
9214 // Set scissor as dynamic to avoid second error
9215 VkPipelineDynamicStateCreateInfo dyn_state_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009216 dyn_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_DYNAMIC_STATE_CREATE_INFO;
9217 dyn_state_ci.dynamicStateCount = 1;
9218 dyn_state_ci.pDynamicStates = &sc_state;
Tobin Ehlise68360f2015-10-01 11:15:13 -06009219
Cody Northropeb3a6c12015-10-05 14:44:45 -06009220 VkPipelineShaderStageCreateInfo shaderStages[2];
Karl Schultz6addd812016-02-02 17:17:23 -07009221 memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo));
Tobin Ehlise68360f2015-10-01 11:15:13 -06009222
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009223 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
9224 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this); // We shouldn't need a fragment shader
9225 // but add it to be able to run on more devices
Chia-I Wu28e06912015-10-31 00:31:16 +08009226 shaderStages[0] = vs.GetStageCreateInfo();
9227 shaderStages[1] = fs.GetStageCreateInfo();
Tobin Ehlise68360f2015-10-01 11:15:13 -06009228
Karl Schultzdfdb8d42016-03-08 10:30:21 -07009229 VkPipelineRasterizationStateCreateInfo rs_state_ci = {};
9230 rs_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
9231 rs_state_ci.polygonMode = VK_POLYGON_MODE_FILL;
9232 rs_state_ci.cullMode = VK_CULL_MODE_BACK_BIT;
9233 rs_state_ci.frontFace = VK_FRONT_FACE_COUNTER_CLOCKWISE;
9234 rs_state_ci.depthClampEnable = VK_FALSE;
9235 rs_state_ci.rasterizerDiscardEnable = VK_FALSE;
9236 rs_state_ci.depthBiasEnable = VK_FALSE;
9237
Tobin Ehlise68360f2015-10-01 11:15:13 -06009238 VkGraphicsPipelineCreateInfo gp_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009239 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
9240 gp_ci.stageCount = 2;
9241 gp_ci.pStages = shaderStages;
Karl Schultzdfdb8d42016-03-08 10:30:21 -07009242 gp_ci.pRasterizationState = &rs_state_ci;
Karl Schultz6addd812016-02-02 17:17:23 -07009243 gp_ci.pViewportState = NULL; // Not setting VP state w/o dynamic vp state
9244 // should cause validation error
9245 gp_ci.pDynamicState = &dyn_state_ci;
9246 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
9247 gp_ci.layout = pipeline_layout;
9248 gp_ci.renderPass = renderPass();
Tobin Ehlise68360f2015-10-01 11:15:13 -06009249
9250 VkPipelineCacheCreateInfo pc_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009251 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
Tobin Ehlise68360f2015-10-01 11:15:13 -06009252
9253 VkPipeline pipeline;
9254 VkPipelineCache pipelineCache;
9255
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009256 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Tobin Ehlise68360f2015-10-01 11:15:13 -06009257 ASSERT_VK_SUCCESS(err);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009258 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Tobin Ehlise68360f2015-10-01 11:15:13 -06009259
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009260 m_errorMonitor->VerifyFound();
Tobin Ehlise68360f2015-10-01 11:15:13 -06009261
Chia-I Wuf7458c52015-10-26 21:10:41 +08009262 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
9263 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
9264 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
9265 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlise68360f2015-10-01 11:15:13 -06009266}
9267// Create PSO w/o non-zero viewportCount but no viewport data
Karl Schultz6addd812016-02-02 17:17:23 -07009268// Then run second test where dynamic scissor count doesn't match PSO scissor
9269// count
9270TEST_F(VkLayerTest, PSOViewportCountWithoutDataAndDynScissorMismatch) {
9271 VkResult err;
Tobin Ehlise68360f2015-10-01 11:15:13 -06009272
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009273 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
9274 "Gfx Pipeline viewportCount is 1, but pViewports is NULL. ");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06009275
Tobin Ehlise68360f2015-10-01 11:15:13 -06009276 ASSERT_NO_FATAL_FAILURE(InitState());
Chris Forbesc08a6ca2016-07-28 14:14:07 +12009277
9278 if (!m_device->phy().features().multiViewport) {
9279 printf("Device does not support multiple viewports/scissors; skipped.\n");
9280 return;
9281 }
9282
Tobin Ehlise68360f2015-10-01 11:15:13 -06009283 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlise68360f2015-10-01 11:15:13 -06009284
Chia-I Wu1b99bb22015-10-27 19:25:11 +08009285 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009286 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
9287 ds_type_count.descriptorCount = 1;
Tobin Ehlise68360f2015-10-01 11:15:13 -06009288
9289 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009290 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
9291 ds_pool_ci.maxSets = 1;
9292 ds_pool_ci.poolSizeCount = 1;
9293 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlise68360f2015-10-01 11:15:13 -06009294
9295 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009296 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlise68360f2015-10-01 11:15:13 -06009297 ASSERT_VK_SUCCESS(err);
9298
9299 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009300 dsl_binding.binding = 0;
9301 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
9302 dsl_binding.descriptorCount = 1;
9303 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
Tobin Ehlise68360f2015-10-01 11:15:13 -06009304
9305 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009306 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
9307 ds_layout_ci.bindingCount = 1;
9308 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlise68360f2015-10-01 11:15:13 -06009309
9310 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009311 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlise68360f2015-10-01 11:15:13 -06009312 ASSERT_VK_SUCCESS(err);
9313
9314 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009315 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08009316 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07009317 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06009318 alloc_info.descriptorPool = ds_pool;
9319 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009320 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlise68360f2015-10-01 11:15:13 -06009321 ASSERT_VK_SUCCESS(err);
9322
9323 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009324 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
9325 pipeline_layout_ci.setLayoutCount = 1;
9326 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlise68360f2015-10-01 11:15:13 -06009327
9328 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009329 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlise68360f2015-10-01 11:15:13 -06009330 ASSERT_VK_SUCCESS(err);
9331
9332 VkPipelineViewportStateCreateInfo vp_state_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009333 vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
9334 vp_state_ci.viewportCount = 1;
9335 vp_state_ci.pViewports = NULL; // Null vp w/ count of 1 should cause error
9336 vp_state_ci.scissorCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009337 vp_state_ci.pScissors = NULL; // Scissor is dynamic (below) so this won't cause error
Tobin Ehlise68360f2015-10-01 11:15:13 -06009338
9339 VkDynamicState sc_state = VK_DYNAMIC_STATE_SCISSOR;
9340 // Set scissor as dynamic to avoid that error
9341 VkPipelineDynamicStateCreateInfo dyn_state_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009342 dyn_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_DYNAMIC_STATE_CREATE_INFO;
9343 dyn_state_ci.dynamicStateCount = 1;
9344 dyn_state_ci.pDynamicStates = &sc_state;
Tobin Ehlise68360f2015-10-01 11:15:13 -06009345
Cody Northropeb3a6c12015-10-05 14:44:45 -06009346 VkPipelineShaderStageCreateInfo shaderStages[2];
Karl Schultz6addd812016-02-02 17:17:23 -07009347 memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo));
Tobin Ehlise68360f2015-10-01 11:15:13 -06009348
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009349 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
9350 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this); // We shouldn't need a fragment shader
9351 // but add it to be able to run on more devices
Chia-I Wu28e06912015-10-31 00:31:16 +08009352 shaderStages[0] = vs.GetStageCreateInfo();
9353 shaderStages[1] = fs.GetStageCreateInfo();
Tobin Ehlise68360f2015-10-01 11:15:13 -06009354
Cody Northropf6622dc2015-10-06 10:33:21 -06009355 VkPipelineVertexInputStateCreateInfo vi_ci = {};
9356 vi_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
9357 vi_ci.pNext = nullptr;
Chia-I Wud50a7d72015-10-26 20:48:51 +08009358 vi_ci.vertexBindingDescriptionCount = 0;
Cody Northropf6622dc2015-10-06 10:33:21 -06009359 vi_ci.pVertexBindingDescriptions = nullptr;
Chia-I Wud50a7d72015-10-26 20:48:51 +08009360 vi_ci.vertexAttributeDescriptionCount = 0;
Cody Northropf6622dc2015-10-06 10:33:21 -06009361 vi_ci.pVertexAttributeDescriptions = nullptr;
9362
9363 VkPipelineInputAssemblyStateCreateInfo ia_ci = {};
9364 ia_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
9365 ia_ci.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP;
9366
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009367 VkPipelineRasterizationStateCreateInfo rs_ci = {};
Chia-I Wu1b99bb22015-10-27 19:25:11 +08009368 rs_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
Cody Northropf6622dc2015-10-06 10:33:21 -06009369 rs_ci.pNext = nullptr;
9370
Mark Youngc89c6312016-03-31 16:03:20 -06009371 VkPipelineColorBlendAttachmentState att = {};
9372 att.blendEnable = VK_FALSE;
9373 att.colorWriteMask = 0xf;
9374
Cody Northropf6622dc2015-10-06 10:33:21 -06009375 VkPipelineColorBlendStateCreateInfo cb_ci = {};
9376 cb_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO;
9377 cb_ci.pNext = nullptr;
Mark Youngc89c6312016-03-31 16:03:20 -06009378 cb_ci.attachmentCount = 1;
9379 cb_ci.pAttachments = &att;
Cody Northropf6622dc2015-10-06 10:33:21 -06009380
Tobin Ehlise68360f2015-10-01 11:15:13 -06009381 VkGraphicsPipelineCreateInfo gp_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009382 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
9383 gp_ci.stageCount = 2;
9384 gp_ci.pStages = shaderStages;
9385 gp_ci.pVertexInputState = &vi_ci;
9386 gp_ci.pInputAssemblyState = &ia_ci;
9387 gp_ci.pViewportState = &vp_state_ci;
9388 gp_ci.pRasterizationState = &rs_ci;
9389 gp_ci.pColorBlendState = &cb_ci;
9390 gp_ci.pDynamicState = &dyn_state_ci;
9391 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
9392 gp_ci.layout = pipeline_layout;
9393 gp_ci.renderPass = renderPass();
Tobin Ehlise68360f2015-10-01 11:15:13 -06009394
9395 VkPipelineCacheCreateInfo pc_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009396 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
Tobin Ehlise68360f2015-10-01 11:15:13 -06009397
9398 VkPipeline pipeline;
9399 VkPipelineCache pipelineCache;
9400
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009401 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Tobin Ehlise68360f2015-10-01 11:15:13 -06009402 ASSERT_VK_SUCCESS(err);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009403 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Tobin Ehlise68360f2015-10-01 11:15:13 -06009404
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009405 m_errorMonitor->VerifyFound();
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06009406
Tobin Ehlisd332f282015-10-02 11:00:56 -06009407 // Now hit second fail case where we set scissor w/ different count than PSO
Karl Schultz6addd812016-02-02 17:17:23 -07009408 // First need to successfully create the PSO from above by setting
9409 // pViewports
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009410 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Dynamic scissor(s) 0 are used by PSO, ");
Karl Schultz6addd812016-02-02 17:17:23 -07009411
9412 VkViewport vp = {}; // Just need dummy vp to point to
9413 vp_state_ci.pViewports = &vp;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009414 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Karl Schultz6addd812016-02-02 17:17:23 -07009415 ASSERT_VK_SUCCESS(err);
9416 BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009417 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline);
Chris Forbesc08a6ca2016-07-28 14:14:07 +12009418 VkRect2D scissors[1] = {}; // don't care about data
Karl Schultz6addd812016-02-02 17:17:23 -07009419 // Count of 2 doesn't match PSO count of 1
Chris Forbesc08a6ca2016-07-28 14:14:07 +12009420 vkCmdSetScissor(m_commandBuffer->GetBufferHandle(), 1, 1, scissors);
Karl Schultz6addd812016-02-02 17:17:23 -07009421 Draw(1, 0, 0, 0);
9422
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009423 m_errorMonitor->VerifyFound();
Karl Schultz6addd812016-02-02 17:17:23 -07009424
9425 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
9426 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
9427 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
9428 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tony Barbourdf4c0042016-06-01 15:55:43 -06009429 vkDestroyPipeline(m_device->device(), pipeline, NULL);
Karl Schultz6addd812016-02-02 17:17:23 -07009430}
9431// Create PSO w/o non-zero scissorCount but no scissor data
9432// Then run second test where dynamic viewportCount doesn't match PSO
9433// viewportCount
9434TEST_F(VkLayerTest, PSOScissorCountWithoutDataAndDynViewportMismatch) {
9435 VkResult err;
9436
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009437 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 -07009438
9439 ASSERT_NO_FATAL_FAILURE(InitState());
Chris Forbesc08a6ca2016-07-28 14:14:07 +12009440
9441 if (!m_device->phy().features().multiViewport) {
9442 printf("Device does not support multiple viewports/scissors; skipped.\n");
9443 return;
9444 }
9445
Karl Schultz6addd812016-02-02 17:17:23 -07009446 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
9447
9448 VkDescriptorPoolSize ds_type_count = {};
9449 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
9450 ds_type_count.descriptorCount = 1;
9451
9452 VkDescriptorPoolCreateInfo ds_pool_ci = {};
9453 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
9454 ds_pool_ci.maxSets = 1;
9455 ds_pool_ci.poolSizeCount = 1;
9456 ds_pool_ci.pPoolSizes = &ds_type_count;
9457
9458 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009459 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Karl Schultz6addd812016-02-02 17:17:23 -07009460 ASSERT_VK_SUCCESS(err);
9461
9462 VkDescriptorSetLayoutBinding dsl_binding = {};
9463 dsl_binding.binding = 0;
9464 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
9465 dsl_binding.descriptorCount = 1;
9466 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
9467
9468 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
9469 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
9470 ds_layout_ci.bindingCount = 1;
9471 ds_layout_ci.pBindings = &dsl_binding;
9472
9473 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009474 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Karl Schultz6addd812016-02-02 17:17:23 -07009475 ASSERT_VK_SUCCESS(err);
9476
9477 VkDescriptorSet descriptorSet;
9478 VkDescriptorSetAllocateInfo alloc_info = {};
9479 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
9480 alloc_info.descriptorSetCount = 1;
9481 alloc_info.descriptorPool = ds_pool;
9482 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009483 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Karl Schultz6addd812016-02-02 17:17:23 -07009484 ASSERT_VK_SUCCESS(err);
9485
9486 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
9487 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
9488 pipeline_layout_ci.setLayoutCount = 1;
9489 pipeline_layout_ci.pSetLayouts = &ds_layout;
9490
9491 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009492 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Karl Schultz6addd812016-02-02 17:17:23 -07009493 ASSERT_VK_SUCCESS(err);
9494
9495 VkPipelineViewportStateCreateInfo vp_state_ci = {};
9496 vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
9497 vp_state_ci.scissorCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009498 vp_state_ci.pScissors = NULL; // Null scissor w/ count of 1 should cause error
Karl Schultz6addd812016-02-02 17:17:23 -07009499 vp_state_ci.viewportCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009500 vp_state_ci.pViewports = NULL; // vp is dynamic (below) so this won't cause error
Karl Schultz6addd812016-02-02 17:17:23 -07009501
9502 VkDynamicState vp_state = VK_DYNAMIC_STATE_VIEWPORT;
9503 // Set scissor as dynamic to avoid that error
9504 VkPipelineDynamicStateCreateInfo dyn_state_ci = {};
9505 dyn_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_DYNAMIC_STATE_CREATE_INFO;
9506 dyn_state_ci.dynamicStateCount = 1;
9507 dyn_state_ci.pDynamicStates = &vp_state;
9508
9509 VkPipelineShaderStageCreateInfo shaderStages[2];
9510 memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo));
9511
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009512 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
9513 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this); // We shouldn't need a fragment shader
9514 // but add it to be able to run on more devices
Karl Schultz6addd812016-02-02 17:17:23 -07009515 shaderStages[0] = vs.GetStageCreateInfo();
9516 shaderStages[1] = fs.GetStageCreateInfo();
9517
9518 VkPipelineVertexInputStateCreateInfo vi_ci = {};
9519 vi_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
9520 vi_ci.pNext = nullptr;
9521 vi_ci.vertexBindingDescriptionCount = 0;
9522 vi_ci.pVertexBindingDescriptions = nullptr;
9523 vi_ci.vertexAttributeDescriptionCount = 0;
9524 vi_ci.pVertexAttributeDescriptions = nullptr;
9525
9526 VkPipelineInputAssemblyStateCreateInfo ia_ci = {};
9527 ia_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
9528 ia_ci.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP;
9529
9530 VkPipelineRasterizationStateCreateInfo rs_ci = {};
9531 rs_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
9532 rs_ci.pNext = nullptr;
9533
Mark Youngc89c6312016-03-31 16:03:20 -06009534 VkPipelineColorBlendAttachmentState att = {};
9535 att.blendEnable = VK_FALSE;
9536 att.colorWriteMask = 0xf;
9537
Karl Schultz6addd812016-02-02 17:17:23 -07009538 VkPipelineColorBlendStateCreateInfo cb_ci = {};
9539 cb_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO;
9540 cb_ci.pNext = nullptr;
Mark Youngc89c6312016-03-31 16:03:20 -06009541 cb_ci.attachmentCount = 1;
9542 cb_ci.pAttachments = &att;
Karl Schultz6addd812016-02-02 17:17:23 -07009543
9544 VkGraphicsPipelineCreateInfo gp_ci = {};
9545 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
9546 gp_ci.stageCount = 2;
9547 gp_ci.pStages = shaderStages;
9548 gp_ci.pVertexInputState = &vi_ci;
9549 gp_ci.pInputAssemblyState = &ia_ci;
9550 gp_ci.pViewportState = &vp_state_ci;
9551 gp_ci.pRasterizationState = &rs_ci;
9552 gp_ci.pColorBlendState = &cb_ci;
9553 gp_ci.pDynamicState = &dyn_state_ci;
9554 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
9555 gp_ci.layout = pipeline_layout;
9556 gp_ci.renderPass = renderPass();
9557
9558 VkPipelineCacheCreateInfo pc_ci = {};
9559 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
9560
9561 VkPipeline pipeline;
9562 VkPipelineCache pipelineCache;
9563
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009564 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Karl Schultz6addd812016-02-02 17:17:23 -07009565 ASSERT_VK_SUCCESS(err);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009566 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Karl Schultz6addd812016-02-02 17:17:23 -07009567
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009568 m_errorMonitor->VerifyFound();
Karl Schultz6addd812016-02-02 17:17:23 -07009569
9570 // Now hit second fail case where we set scissor w/ different count than PSO
9571 // First need to successfully create the PSO from above by setting
9572 // pViewports
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009573 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Dynamic viewport(s) 0 are used by PSO, ");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06009574
Tobin Ehlisd332f282015-10-02 11:00:56 -06009575 VkRect2D sc = {}; // Just need dummy vp to point to
9576 vp_state_ci.pScissors = &sc;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009577 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Tobin Ehlisd332f282015-10-02 11:00:56 -06009578 ASSERT_VK_SUCCESS(err);
9579 BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009580 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline);
Chris Forbesc08a6ca2016-07-28 14:14:07 +12009581 VkViewport viewports[1] = {}; // don't care about data
Tobin Ehlisd332f282015-10-02 11:00:56 -06009582 // Count of 2 doesn't match PSO count of 1
Chris Forbesc08a6ca2016-07-28 14:14:07 +12009583 vkCmdSetViewport(m_commandBuffer->GetBufferHandle(), 1, 1, viewports);
Tobin Ehlisd332f282015-10-02 11:00:56 -06009584 Draw(1, 0, 0, 0);
9585
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009586 m_errorMonitor->VerifyFound();
Tobin Ehlise68360f2015-10-01 11:15:13 -06009587
Chia-I Wuf7458c52015-10-26 21:10:41 +08009588 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
9589 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
9590 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
9591 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tony Barbourdf4c0042016-06-01 15:55:43 -06009592 vkDestroyPipeline(m_device->device(), pipeline, NULL);
Tobin Ehlise68360f2015-10-01 11:15:13 -06009593}
9594
Mark Young7394fdd2016-03-31 14:56:43 -06009595TEST_F(VkLayerTest, PSOLineWidthInvalid) {
9596 VkResult err;
9597
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009598 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Attempt to set lineWidth to -1");
Mark Young7394fdd2016-03-31 14:56:43 -06009599
9600 ASSERT_NO_FATAL_FAILURE(InitState());
9601 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
9602
9603 VkDescriptorPoolSize ds_type_count = {};
9604 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
9605 ds_type_count.descriptorCount = 1;
9606
9607 VkDescriptorPoolCreateInfo ds_pool_ci = {};
9608 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
9609 ds_pool_ci.maxSets = 1;
9610 ds_pool_ci.poolSizeCount = 1;
9611 ds_pool_ci.pPoolSizes = &ds_type_count;
9612
9613 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009614 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Mark Young7394fdd2016-03-31 14:56:43 -06009615 ASSERT_VK_SUCCESS(err);
9616
9617 VkDescriptorSetLayoutBinding dsl_binding = {};
9618 dsl_binding.binding = 0;
9619 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
9620 dsl_binding.descriptorCount = 1;
9621 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
9622
9623 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
9624 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
9625 ds_layout_ci.bindingCount = 1;
9626 ds_layout_ci.pBindings = &dsl_binding;
9627
9628 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009629 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Mark Young7394fdd2016-03-31 14:56:43 -06009630 ASSERT_VK_SUCCESS(err);
9631
9632 VkDescriptorSet descriptorSet;
9633 VkDescriptorSetAllocateInfo alloc_info = {};
9634 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
9635 alloc_info.descriptorSetCount = 1;
9636 alloc_info.descriptorPool = ds_pool;
9637 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009638 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Mark Young7394fdd2016-03-31 14:56:43 -06009639 ASSERT_VK_SUCCESS(err);
9640
9641 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
9642 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
9643 pipeline_layout_ci.setLayoutCount = 1;
9644 pipeline_layout_ci.pSetLayouts = &ds_layout;
9645
9646 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009647 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Mark Young7394fdd2016-03-31 14:56:43 -06009648 ASSERT_VK_SUCCESS(err);
9649
9650 VkPipelineViewportStateCreateInfo vp_state_ci = {};
9651 vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
9652 vp_state_ci.scissorCount = 1;
9653 vp_state_ci.pScissors = NULL;
9654 vp_state_ci.viewportCount = 1;
9655 vp_state_ci.pViewports = NULL;
9656
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009657 VkDynamicState dynamic_states[3] = {VK_DYNAMIC_STATE_VIEWPORT, VK_DYNAMIC_STATE_SCISSOR, VK_DYNAMIC_STATE_LINE_WIDTH};
Mark Young7394fdd2016-03-31 14:56:43 -06009658 // Set scissor as dynamic to avoid that error
9659 VkPipelineDynamicStateCreateInfo dyn_state_ci = {};
9660 dyn_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_DYNAMIC_STATE_CREATE_INFO;
9661 dyn_state_ci.dynamicStateCount = 2;
9662 dyn_state_ci.pDynamicStates = dynamic_states;
9663
9664 VkPipelineShaderStageCreateInfo shaderStages[2];
9665 memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo));
9666
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009667 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
9668 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT,
Mark Young7394fdd2016-03-31 14:56:43 -06009669 this); // TODO - We shouldn't need a fragment shader
9670 // but add it to be able to run on more devices
9671 shaderStages[0] = vs.GetStageCreateInfo();
9672 shaderStages[1] = fs.GetStageCreateInfo();
9673
9674 VkPipelineVertexInputStateCreateInfo vi_ci = {};
9675 vi_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
9676 vi_ci.pNext = nullptr;
9677 vi_ci.vertexBindingDescriptionCount = 0;
9678 vi_ci.pVertexBindingDescriptions = nullptr;
9679 vi_ci.vertexAttributeDescriptionCount = 0;
9680 vi_ci.pVertexAttributeDescriptions = nullptr;
9681
9682 VkPipelineInputAssemblyStateCreateInfo ia_ci = {};
9683 ia_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
9684 ia_ci.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP;
9685
9686 VkPipelineRasterizationStateCreateInfo rs_ci = {};
9687 rs_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
9688 rs_ci.pNext = nullptr;
9689
Mark Young47107952016-05-02 15:59:55 -06009690 // Check too low (line width of -1.0f).
9691 rs_ci.lineWidth = -1.0f;
Mark Young7394fdd2016-03-31 14:56:43 -06009692
9693 VkPipelineColorBlendAttachmentState att = {};
9694 att.blendEnable = VK_FALSE;
9695 att.colorWriteMask = 0xf;
9696
9697 VkPipelineColorBlendStateCreateInfo cb_ci = {};
9698 cb_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO;
9699 cb_ci.pNext = nullptr;
9700 cb_ci.attachmentCount = 1;
9701 cb_ci.pAttachments = &att;
9702
9703 VkGraphicsPipelineCreateInfo gp_ci = {};
9704 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
9705 gp_ci.stageCount = 2;
9706 gp_ci.pStages = shaderStages;
9707 gp_ci.pVertexInputState = &vi_ci;
9708 gp_ci.pInputAssemblyState = &ia_ci;
9709 gp_ci.pViewportState = &vp_state_ci;
9710 gp_ci.pRasterizationState = &rs_ci;
9711 gp_ci.pColorBlendState = &cb_ci;
9712 gp_ci.pDynamicState = &dyn_state_ci;
9713 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
9714 gp_ci.layout = pipeline_layout;
9715 gp_ci.renderPass = renderPass();
9716
9717 VkPipelineCacheCreateInfo pc_ci = {};
9718 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
9719
9720 VkPipeline pipeline;
9721 VkPipelineCache pipelineCache;
9722
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009723 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Mark Young7394fdd2016-03-31 14:56:43 -06009724 ASSERT_VK_SUCCESS(err);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009725 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Mark Young7394fdd2016-03-31 14:56:43 -06009726
9727 m_errorMonitor->VerifyFound();
Tony Barbourdf4c0042016-06-01 15:55:43 -06009728 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
Mark Young7394fdd2016-03-31 14:56:43 -06009729
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009730 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Attempt to set lineWidth to 65536");
Mark Young7394fdd2016-03-31 14:56:43 -06009731
9732 // Check too high (line width of 65536.0f).
9733 rs_ci.lineWidth = 65536.0f;
9734
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009735 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Mark Young7394fdd2016-03-31 14:56:43 -06009736 ASSERT_VK_SUCCESS(err);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009737 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Mark Young7394fdd2016-03-31 14:56:43 -06009738
9739 m_errorMonitor->VerifyFound();
Tony Barbourdf4c0042016-06-01 15:55:43 -06009740 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
Mark Young7394fdd2016-03-31 14:56:43 -06009741
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009742 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Attempt to set lineWidth to -1");
Mark Young7394fdd2016-03-31 14:56:43 -06009743
9744 dyn_state_ci.dynamicStateCount = 3;
9745
9746 rs_ci.lineWidth = 1.0f;
9747
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009748 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Mark Young7394fdd2016-03-31 14:56:43 -06009749 ASSERT_VK_SUCCESS(err);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009750 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Mark Young7394fdd2016-03-31 14:56:43 -06009751 BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009752 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline);
Mark Young7394fdd2016-03-31 14:56:43 -06009753
9754 // Check too low with dynamic setting.
Mark Young47107952016-05-02 15:59:55 -06009755 vkCmdSetLineWidth(m_commandBuffer->GetBufferHandle(), -1.0f);
Mark Young7394fdd2016-03-31 14:56:43 -06009756 m_errorMonitor->VerifyFound();
9757
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009758 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Attempt to set lineWidth to 65536");
Mark Young7394fdd2016-03-31 14:56:43 -06009759
9760 // Check too high with dynamic setting.
9761 vkCmdSetLineWidth(m_commandBuffer->GetBufferHandle(), 65536.0f);
9762 m_errorMonitor->VerifyFound();
9763 EndCommandBuffer();
9764
9765 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
9766 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
9767 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
9768 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tony Barbourdf4c0042016-06-01 15:55:43 -06009769 vkDestroyPipeline(m_device->device(), pipeline, NULL);
Mark Young7394fdd2016-03-31 14:56:43 -06009770}
9771
Karl Schultz6addd812016-02-02 17:17:23 -07009772TEST_F(VkLayerTest, NullRenderPass) {
Tobin Ehlis98aa0ed2015-06-25 16:27:19 -06009773 // Bind a NULL RenderPass
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009774 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
9775 "You cannot use a NULL RenderPass object in vkCmdBeginRenderPass()");
Tobin Ehlis98aa0ed2015-06-25 16:27:19 -06009776
9777 ASSERT_NO_FATAL_FAILURE(InitState());
9778 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlis98aa0ed2015-06-25 16:27:19 -06009779
Tony Barbourfe3351b2015-07-28 10:17:20 -06009780 BeginCommandBuffer();
Karl Schultz6addd812016-02-02 17:17:23 -07009781 // Don't care about RenderPass handle b/c error should be flagged before
9782 // that
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009783 vkCmdBeginRenderPass(m_commandBuffer->GetBufferHandle(), NULL, VK_SUBPASS_CONTENTS_INLINE);
Tobin Ehlis98aa0ed2015-06-25 16:27:19 -06009784
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009785 m_errorMonitor->VerifyFound();
Tobin Ehlis98aa0ed2015-06-25 16:27:19 -06009786}
9787
Karl Schultz6addd812016-02-02 17:17:23 -07009788TEST_F(VkLayerTest, RenderPassWithinRenderPass) {
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06009789 // Bind a BeginRenderPass within an active RenderPass
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009790 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
9791 "It is invalid to issue this call inside an active render pass");
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06009792
9793 ASSERT_NO_FATAL_FAILURE(InitState());
9794 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06009795
Tony Barbourfe3351b2015-07-28 10:17:20 -06009796 BeginCommandBuffer();
Karl Schultz6addd812016-02-02 17:17:23 -07009797 // Just create a dummy Renderpass that's non-NULL so we can get to the
9798 // proper error
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009799 vkCmdBeginRenderPass(m_commandBuffer->GetBufferHandle(), &m_renderPassBeginInfo, VK_SUBPASS_CONTENTS_INLINE);
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06009800
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009801 m_errorMonitor->VerifyFound();
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06009802}
9803
Chris Forbes2eeabe32016-06-21 20:52:34 +12009804TEST_F(VkLayerTest, RenderPassSecondaryCommandBuffersMultipleTimes) {
9805 m_errorMonitor->ExpectSuccess();
9806
9807 ASSERT_NO_FATAL_FAILURE(InitState());
9808 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
9809
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009810 BeginCommandBuffer(); // framework implicitly begins the renderpass.
Chris Forbes2eeabe32016-06-21 20:52:34 +12009811 vkCmdEndRenderPass(m_commandBuffer->GetBufferHandle()); // end implicit.
9812
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009813 vkCmdBeginRenderPass(m_commandBuffer->GetBufferHandle(), &m_renderPassBeginInfo, VK_SUBPASS_CONTENTS_SECONDARY_COMMAND_BUFFERS);
Chris Forbes2eeabe32016-06-21 20:52:34 +12009814 vkCmdEndRenderPass(m_commandBuffer->GetBufferHandle());
9815 m_errorMonitor->VerifyNotFound();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009816 vkCmdBeginRenderPass(m_commandBuffer->GetBufferHandle(), &m_renderPassBeginInfo, VK_SUBPASS_CONTENTS_INLINE);
Chris Forbes2eeabe32016-06-21 20:52:34 +12009817 m_errorMonitor->VerifyNotFound();
9818 vkCmdEndRenderPass(m_commandBuffer->GetBufferHandle());
9819 m_errorMonitor->VerifyNotFound();
9820
9821 m_commandBuffer->EndCommandBuffer();
9822 m_errorMonitor->VerifyNotFound();
9823}
9824
Tobin Ehlis5a1c0332016-05-31 13:59:26 -06009825TEST_F(VkLayerTest, RenderPassClearOpMismatch) {
9826 TEST_DESCRIPTION("Begin a renderPass where clearValueCount is less than"
9827 "the number of renderPass attachments that use loadOp"
9828 "VK_ATTACHMENT_LOAD_OP_CLEAR.");
9829
9830 ASSERT_NO_FATAL_FAILURE(InitState());
9831 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
9832
9833 // Create a renderPass with a single attachment that uses loadOp CLEAR
9834 VkAttachmentReference attach = {};
9835 attach.layout = VK_IMAGE_LAYOUT_GENERAL;
9836 VkSubpassDescription subpass = {};
9837 subpass.inputAttachmentCount = 1;
9838 subpass.pInputAttachments = &attach;
9839 VkRenderPassCreateInfo rpci = {};
9840 rpci.subpassCount = 1;
9841 rpci.pSubpasses = &subpass;
9842 rpci.attachmentCount = 1;
9843 VkAttachmentDescription attach_desc = {};
9844 attach_desc.format = VK_FORMAT_UNDEFINED;
9845 // Set loadOp to CLEAR
9846 attach_desc.loadOp = VK_ATTACHMENT_LOAD_OP_CLEAR;
9847 rpci.pAttachments = &attach_desc;
9848 rpci.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
9849 VkRenderPass rp;
9850 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
9851
9852 VkCommandBufferInheritanceInfo hinfo = {};
9853 hinfo.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_INHERITANCE_INFO;
9854 hinfo.renderPass = VK_NULL_HANDLE;
9855 hinfo.subpass = 0;
9856 hinfo.framebuffer = VK_NULL_HANDLE;
9857 hinfo.occlusionQueryEnable = VK_FALSE;
9858 hinfo.queryFlags = 0;
9859 hinfo.pipelineStatistics = 0;
9860 VkCommandBufferBeginInfo info = {};
9861 info.flags = VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT;
9862 info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
9863 info.pInheritanceInfo = &hinfo;
9864
9865 vkBeginCommandBuffer(m_commandBuffer->handle(), &info);
9866 VkRenderPassBeginInfo rp_begin = {};
9867 rp_begin.sType = VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO;
9868 rp_begin.pNext = NULL;
9869 rp_begin.renderPass = renderPass();
9870 rp_begin.framebuffer = framebuffer();
9871 rp_begin.clearValueCount = 0; // Should be 1
9872
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009873 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " has a clearValueCount of 0 but "
9874 "there must be at least 1 entries in "
9875 "pClearValues array to account for ");
Tobin Ehlis5a1c0332016-05-31 13:59:26 -06009876
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009877 vkCmdBeginRenderPass(m_commandBuffer->GetBufferHandle(), &rp_begin, VK_SUBPASS_CONTENTS_INLINE);
Tobin Ehlis5a1c0332016-05-31 13:59:26 -06009878
9879 m_errorMonitor->VerifyFound();
Mark Lobodzinski5c70ebd2016-06-09 13:45:00 -06009880
9881 vkDestroyRenderPass(m_device->device(), rp, NULL);
Tobin Ehlis5a1c0332016-05-31 13:59:26 -06009882}
9883
Cody Northrop3bb4d962016-05-09 16:15:57 -06009884TEST_F(VkLayerTest, EndCommandBufferWithinRenderPass) {
9885
9886 TEST_DESCRIPTION("End a command buffer with an active render pass");
9887
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009888 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
9889 "It is invalid to issue this call inside an active render pass");
Cody Northrop3bb4d962016-05-09 16:15:57 -06009890
9891 ASSERT_NO_FATAL_FAILURE(InitState());
9892 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
9893
9894 // The framework's BeginCommandBuffer calls CreateRenderPass
9895 BeginCommandBuffer();
9896
9897 // Call directly into vkEndCommandBuffer instead of the
9898 // the framework's EndCommandBuffer, which inserts a
9899 // vkEndRenderPass
9900 vkEndCommandBuffer(m_commandBuffer->GetBufferHandle());
9901
9902 m_errorMonitor->VerifyFound();
9903
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009904 // TODO: Add test for VK_COMMAND_BUFFER_LEVEL_SECONDARY
9905 // TODO: Add test for VK_COMMAND_BUFFER_USAGE_RENDER_PASS_CONTINUE_BIT
Cody Northrop3bb4d962016-05-09 16:15:57 -06009906}
9907
Karl Schultz6addd812016-02-02 17:17:23 -07009908TEST_F(VkLayerTest, FillBufferWithinRenderPass) {
Mark Lobodzinskid5639502015-09-24 09:51:47 -06009909 // Call CmdFillBuffer within an active renderpass
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009910 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
9911 "It is invalid to issue this call inside an active render pass");
Mark Lobodzinskid5639502015-09-24 09:51:47 -06009912
9913 ASSERT_NO_FATAL_FAILURE(InitState());
9914 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Mark Lobodzinskid5639502015-09-24 09:51:47 -06009915
9916 // Renderpass is started here
9917 BeginCommandBuffer();
9918
9919 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009920 vk_testing::Buffer dstBuffer;
9921 dstBuffer.init_as_dst(*m_device, (VkDeviceSize)1024, reqs);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06009922
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009923 m_commandBuffer->FillBuffer(dstBuffer.handle(), 0, 4, 0x11111111);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06009924
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009925 m_errorMonitor->VerifyFound();
Mark Lobodzinskid5639502015-09-24 09:51:47 -06009926}
9927
Karl Schultz6addd812016-02-02 17:17:23 -07009928TEST_F(VkLayerTest, UpdateBufferWithinRenderPass) {
Mark Lobodzinskid5639502015-09-24 09:51:47 -06009929 // Call CmdUpdateBuffer within an active renderpass
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009930 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
9931 "It is invalid to issue this call inside an active render pass");
Mark Lobodzinskid5639502015-09-24 09:51:47 -06009932
9933 ASSERT_NO_FATAL_FAILURE(InitState());
9934 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Mark Lobodzinskid5639502015-09-24 09:51:47 -06009935
9936 // Renderpass is started here
9937 BeginCommandBuffer();
9938
9939 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009940 vk_testing::Buffer dstBuffer;
9941 dstBuffer.init_as_dst(*m_device, (VkDeviceSize)1024, reqs);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06009942
Karl Schultz6addd812016-02-02 17:17:23 -07009943 VkDeviceSize dstOffset = 0;
9944 VkDeviceSize dataSize = 1024;
Karl Schultzee344492016-07-11 15:09:57 -06009945 const void *pData = NULL;
Mark Lobodzinskid5639502015-09-24 09:51:47 -06009946
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009947 vkCmdUpdateBuffer(m_commandBuffer->GetBufferHandle(), dstBuffer.handle(), dstOffset, dataSize, pData);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06009948
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009949 m_errorMonitor->VerifyFound();
Mark Lobodzinskid5639502015-09-24 09:51:47 -06009950}
9951
Karl Schultz6addd812016-02-02 17:17:23 -07009952TEST_F(VkLayerTest, ClearColorImageWithinRenderPass) {
Mark Lobodzinskid5639502015-09-24 09:51:47 -06009953 // Call CmdClearColorImage within an active RenderPass
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009954 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
9955 "It is invalid to issue this call inside an active render pass");
Mark Lobodzinskid5639502015-09-24 09:51:47 -06009956
9957 ASSERT_NO_FATAL_FAILURE(InitState());
9958 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Mark Lobodzinskid5639502015-09-24 09:51:47 -06009959
9960 // Renderpass is started here
9961 BeginCommandBuffer();
9962
Michael Lentine0a369f62016-02-03 16:51:46 -06009963 VkClearColorValue clear_color;
9964 memset(clear_color.uint32, 0, sizeof(uint32_t) * 4);
Karl Schultz6addd812016-02-02 17:17:23 -07009965 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
9966 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
9967 const int32_t tex_width = 32;
9968 const int32_t tex_height = 32;
9969 VkImageCreateInfo image_create_info = {};
9970 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
9971 image_create_info.pNext = NULL;
9972 image_create_info.imageType = VK_IMAGE_TYPE_2D;
9973 image_create_info.format = tex_format;
9974 image_create_info.extent.width = tex_width;
9975 image_create_info.extent.height = tex_height;
9976 image_create_info.extent.depth = 1;
9977 image_create_info.mipLevels = 1;
9978 image_create_info.arrayLayers = 1;
9979 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
9980 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
9981 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
Mark Lobodzinskid5639502015-09-24 09:51:47 -06009982
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009983 vk_testing::Image dstImage;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009984 dstImage.init(*m_device, (const VkImageCreateInfo &)image_create_info, reqs);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06009985
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009986 const VkImageSubresourceRange range = vk_testing::Image::subresource_range(image_create_info, VK_IMAGE_ASPECT_COLOR_BIT);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06009987
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009988 vkCmdClearColorImage(m_commandBuffer->GetBufferHandle(), dstImage.handle(), VK_IMAGE_LAYOUT_GENERAL, &clear_color, 1, &range);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06009989
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009990 m_errorMonitor->VerifyFound();
Mark Lobodzinskid5639502015-09-24 09:51:47 -06009991}
9992
Karl Schultz6addd812016-02-02 17:17:23 -07009993TEST_F(VkLayerTest, ClearDepthStencilImageWithinRenderPass) {
Mark Lobodzinskid5639502015-09-24 09:51:47 -06009994 // Call CmdClearDepthStencilImage within an active RenderPass
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009995 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
9996 "It is invalid to issue this call inside an active render pass");
Mark Lobodzinskid5639502015-09-24 09:51:47 -06009997
9998 ASSERT_NO_FATAL_FAILURE(InitState());
9999 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Mark Lobodzinskid5639502015-09-24 09:51:47 -060010000
10001 // Renderpass is started here
10002 BeginCommandBuffer();
10003
10004 VkClearDepthStencilValue clear_value = {0};
Dustin Gravesa2e5c942016-02-11 18:28:06 -070010005 VkMemoryPropertyFlags reqs = 0;
Karl Schultz6addd812016-02-02 17:17:23 -070010006 VkImageCreateInfo image_create_info = vk_testing::Image::create_info();
10007 image_create_info.imageType = VK_IMAGE_TYPE_2D;
10008 image_create_info.format = VK_FORMAT_D24_UNORM_S8_UINT;
10009 image_create_info.extent.width = 64;
10010 image_create_info.extent.height = 64;
10011 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
10012 image_create_info.usage = VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT;
Mark Lobodzinskid5639502015-09-24 09:51:47 -060010013
Chia-I Wu3432a0c2015-10-27 18:04:07 +080010014 vk_testing::Image dstImage;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010015 dstImage.init(*m_device, (const VkImageCreateInfo &)image_create_info, reqs);
Mark Lobodzinskid5639502015-09-24 09:51:47 -060010016
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010017 const VkImageSubresourceRange range = vk_testing::Image::subresource_range(image_create_info, VK_IMAGE_ASPECT_DEPTH_BIT);
Mark Lobodzinskid5639502015-09-24 09:51:47 -060010018
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010019 vkCmdClearDepthStencilImage(m_commandBuffer->GetBufferHandle(), dstImage.handle(),
10020 VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL, &clear_value, 1, &range);
Mark Lobodzinskid5639502015-09-24 09:51:47 -060010021
Chris Forbes8f36a8a2016-04-07 13:21:07 +120010022 m_errorMonitor->VerifyFound();
Mark Lobodzinskid5639502015-09-24 09:51:47 -060010023}
10024
Karl Schultz6addd812016-02-02 17:17:23 -070010025TEST_F(VkLayerTest, ClearColorAttachmentsOutsideRenderPass) {
Courtney Goeltzenleuchterc9323e02015-10-15 16:51:05 -060010026 // Call CmdClearAttachmentss outside of an active RenderPass
Karl Schultz6addd812016-02-02 17:17:23 -070010027 VkResult err;
Mark Lobodzinskid5639502015-09-24 09:51:47 -060010028
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010029 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "vkCmdClearAttachments(): This call "
10030 "must be issued inside an active "
10031 "render pass");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060010032
Mark Lobodzinskid5639502015-09-24 09:51:47 -060010033 ASSERT_NO_FATAL_FAILURE(InitState());
10034 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Mark Lobodzinskid5639502015-09-24 09:51:47 -060010035
10036 // Start no RenderPass
Chia-I Wu3432a0c2015-10-27 18:04:07 +080010037 err = m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskid5639502015-09-24 09:51:47 -060010038 ASSERT_VK_SUCCESS(err);
10039
Courtney Goeltzenleuchterc9323e02015-10-15 16:51:05 -060010040 VkClearAttachment color_attachment;
10041 color_attachment.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
10042 color_attachment.clearValue.color.float32[0] = 0;
10043 color_attachment.clearValue.color.float32[1] = 0;
10044 color_attachment.clearValue.color.float32[2] = 0;
10045 color_attachment.clearValue.color.float32[3] = 0;
10046 color_attachment.colorAttachment = 0;
Karl Schultz6addd812016-02-02 17:17:23 -070010047 VkClearRect clear_rect = {{{0, 0}, {32, 32}}};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010048 vkCmdClearAttachments(m_commandBuffer->GetBufferHandle(), 1, &color_attachment, 1, &clear_rect);
Mark Lobodzinskid5639502015-09-24 09:51:47 -060010049
Chris Forbes8f36a8a2016-04-07 13:21:07 +120010050 m_errorMonitor->VerifyFound();
Mark Lobodzinskid5639502015-09-24 09:51:47 -060010051}
10052
Chris Forbes3b97e932016-09-07 11:29:24 +120010053TEST_F(VkLayerTest, RenderPassExcessiveNextSubpass) {
10054 TEST_DESCRIPTION("Test that an error is produced when CmdNextSubpass is "
10055 "called too many times in a renderpass instance");
10056
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010057 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "vkCmdNextSubpass(): Attempted to advance "
10058 "beyond final subpass");
Chris Forbes3b97e932016-09-07 11:29:24 +120010059
10060 ASSERT_NO_FATAL_FAILURE(InitState());
10061 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
10062
10063 BeginCommandBuffer();
10064
10065 // error here.
10066 vkCmdNextSubpass(m_commandBuffer->GetBufferHandle(), VK_SUBPASS_CONTENTS_INLINE);
10067 m_errorMonitor->VerifyFound();
10068
10069 EndCommandBuffer();
10070}
10071
Chris Forbes6d624702016-09-07 13:57:05 +120010072TEST_F(VkLayerTest, RenderPassEndedBeforeFinalSubpass) {
10073 TEST_DESCRIPTION("Test that an error is produced when CmdEndRenderPass is "
10074 "called before the final subpass has been reached");
10075
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010076 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "vkCmdEndRenderPass(): Called before reaching "
10077 "final subpass");
Chris Forbes6d624702016-09-07 13:57:05 +120010078
10079 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010080 VkSubpassDescription sd[2] = {{0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 0, nullptr, nullptr, nullptr, 0, nullptr},
10081 {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 0, nullptr, nullptr, nullptr, 0, nullptr}};
Chris Forbes6d624702016-09-07 13:57:05 +120010082
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010083 VkRenderPassCreateInfo rcpi = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 0, nullptr, 2, sd, 0, nullptr};
Chris Forbes6d624702016-09-07 13:57:05 +120010084
10085 VkRenderPass rp;
10086 VkResult err = vkCreateRenderPass(m_device->device(), &rcpi, nullptr, &rp);
10087 ASSERT_VK_SUCCESS(err);
10088
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010089 VkFramebufferCreateInfo fbci = {VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr, 0, rp, 0, nullptr, 16, 16, 1};
Chris Forbes6d624702016-09-07 13:57:05 +120010090
10091 VkFramebuffer fb;
10092 err = vkCreateFramebuffer(m_device->device(), &fbci, nullptr, &fb);
10093 ASSERT_VK_SUCCESS(err);
10094
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010095 m_commandBuffer->BeginCommandBuffer(); // no implicit RP begin
Chris Forbes6d624702016-09-07 13:57:05 +120010096
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010097 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 +120010098
10099 vkCmdBeginRenderPass(m_commandBuffer->GetBufferHandle(), &rpbi, VK_SUBPASS_CONTENTS_INLINE);
10100
10101 // Error here.
10102 vkCmdEndRenderPass(m_commandBuffer->GetBufferHandle());
10103 m_errorMonitor->VerifyFound();
10104
10105 // Clean up.
10106 vkDestroyFramebuffer(m_device->device(), fb, nullptr);
10107 vkDestroyRenderPass(m_device->device(), rp, nullptr);
10108}
10109
Karl Schultz9e66a292016-04-21 15:57:51 -060010110TEST_F(VkLayerTest, BufferMemoryBarrierNoBuffer) {
10111 // Try to add a buffer memory barrier with no buffer.
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010112 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
10113 "required parameter pBufferMemoryBarriers[0].buffer specified as VK_NULL_HANDLE");
Karl Schultz9e66a292016-04-21 15:57:51 -060010114
10115 ASSERT_NO_FATAL_FAILURE(InitState());
10116 BeginCommandBuffer();
10117
10118 VkBufferMemoryBarrier buf_barrier = {};
10119 buf_barrier.sType = VK_STRUCTURE_TYPE_BUFFER_MEMORY_BARRIER;
10120 buf_barrier.srcAccessMask = VK_ACCESS_HOST_WRITE_BIT;
10121 buf_barrier.dstAccessMask = VK_ACCESS_SHADER_READ_BIT;
10122 buf_barrier.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
10123 buf_barrier.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
10124 buf_barrier.buffer = VK_NULL_HANDLE;
10125 buf_barrier.offset = 0;
10126 buf_barrier.size = VK_WHOLE_SIZE;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010127 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
10128 nullptr, 1, &buf_barrier, 0, nullptr);
Karl Schultz9e66a292016-04-21 15:57:51 -060010129
10130 m_errorMonitor->VerifyFound();
10131}
10132
Tony Barbour7fd5c0f2016-05-03 16:11:53 -060010133TEST_F(VkLayerTest, InvalidBarriers) {
10134 TEST_DESCRIPTION("A variety of ways to get VK_INVALID_BARRIER ");
10135
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010136 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Barriers cannot be set during subpass");
Tony Barbour7fd5c0f2016-05-03 16:11:53 -060010137
10138 ASSERT_NO_FATAL_FAILURE(InitState());
10139 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
10140
10141 VkMemoryBarrier mem_barrier = {};
10142 mem_barrier.sType = VK_STRUCTURE_TYPE_MEMORY_BARRIER;
10143 mem_barrier.pNext = NULL;
10144 mem_barrier.srcAccessMask = VK_ACCESS_HOST_WRITE_BIT;
10145 mem_barrier.dstAccessMask = VK_ACCESS_SHADER_READ_BIT;
10146 BeginCommandBuffer();
10147 // BeginCommandBuffer() starts a render pass
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010148 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 1,
Tony Barbour7fd5c0f2016-05-03 16:11:53 -060010149 &mem_barrier, 0, nullptr, 0, nullptr);
10150 m_errorMonitor->VerifyFound();
10151
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010152 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Image Layout cannot be transitioned to UNDEFINED");
Tony Barbour7fd5c0f2016-05-03 16:11:53 -060010153 VkImageObj image(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010154 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 -060010155 ASSERT_TRUE(image.initialized());
10156 VkImageMemoryBarrier img_barrier = {};
10157 img_barrier.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
10158 img_barrier.pNext = NULL;
10159 img_barrier.srcAccessMask = VK_ACCESS_HOST_WRITE_BIT;
10160 img_barrier.dstAccessMask = VK_ACCESS_SHADER_READ_BIT;
10161 img_barrier.oldLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
10162 // New layout can't be UNDEFINED
10163 img_barrier.newLayout = VK_IMAGE_LAYOUT_UNDEFINED;
10164 img_barrier.image = image.handle();
10165 img_barrier.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
10166 img_barrier.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
10167 img_barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
10168 img_barrier.subresourceRange.baseArrayLayer = 0;
10169 img_barrier.subresourceRange.baseMipLevel = 0;
10170 img_barrier.subresourceRange.layerCount = 1;
10171 img_barrier.subresourceRange.levelCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010172 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
10173 nullptr, 0, nullptr, 1, &img_barrier);
Tony Barbour7fd5c0f2016-05-03 16:11:53 -060010174 m_errorMonitor->VerifyFound();
10175 img_barrier.newLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
10176
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010177 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Subresource must have the sum of the "
10178 "baseArrayLayer");
Tony Barbour7fd5c0f2016-05-03 16:11:53 -060010179 // baseArrayLayer + layerCount must be <= image's arrayLayers
10180 img_barrier.subresourceRange.baseArrayLayer = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010181 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
10182 nullptr, 0, nullptr, 1, &img_barrier);
Tony Barbour7fd5c0f2016-05-03 16:11:53 -060010183 m_errorMonitor->VerifyFound();
10184 img_barrier.subresourceRange.baseArrayLayer = 0;
10185
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010186 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Subresource must have the sum of the baseMipLevel");
Tony Barbour7fd5c0f2016-05-03 16:11:53 -060010187 // baseMipLevel + levelCount must be <= image's mipLevels
10188 img_barrier.subresourceRange.baseMipLevel = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010189 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
10190 nullptr, 0, nullptr, 1, &img_barrier);
Tony Barbour7fd5c0f2016-05-03 16:11:53 -060010191 m_errorMonitor->VerifyFound();
10192 img_barrier.subresourceRange.baseMipLevel = 0;
10193
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010194 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 -060010195 vk_testing::Buffer buffer;
10196 buffer.init(*m_device, 256);
10197 VkBufferMemoryBarrier buf_barrier = {};
10198 buf_barrier.sType = VK_STRUCTURE_TYPE_BUFFER_MEMORY_BARRIER;
10199 buf_barrier.pNext = NULL;
10200 buf_barrier.srcAccessMask = VK_ACCESS_HOST_WRITE_BIT;
10201 buf_barrier.dstAccessMask = VK_ACCESS_SHADER_READ_BIT;
10202 buf_barrier.buffer = buffer.handle();
10203 buf_barrier.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
10204 buf_barrier.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
10205 buf_barrier.offset = 0;
10206 buf_barrier.size = VK_WHOLE_SIZE;
10207 // Can't send buffer barrier during a render pass
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010208 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
10209 nullptr, 1, &buf_barrier, 0, nullptr);
Tony Barbour7fd5c0f2016-05-03 16:11:53 -060010210 m_errorMonitor->VerifyFound();
10211 vkCmdEndRenderPass(m_commandBuffer->GetBufferHandle());
10212
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010213 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "which is not less than total size");
Tony Barbour7fd5c0f2016-05-03 16:11:53 -060010214 buf_barrier.offset = 257;
10215 // Offset greater than total size
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010216 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
10217 nullptr, 1, &buf_barrier, 0, nullptr);
Tony Barbour7fd5c0f2016-05-03 16:11:53 -060010218 m_errorMonitor->VerifyFound();
10219 buf_barrier.offset = 0;
10220
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010221 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "whose sum is greater than total size");
Tony Barbour7fd5c0f2016-05-03 16:11:53 -060010222 buf_barrier.size = 257;
10223 // Size greater than total size
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010224 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
10225 nullptr, 1, &buf_barrier, 0, nullptr);
Tony Barbour7fd5c0f2016-05-03 16:11:53 -060010226 m_errorMonitor->VerifyFound();
Tony Barbour7fd5c0f2016-05-03 16:11:53 -060010227
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -060010228 // Now exercise barrier aspect bit errors, first DS
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010229 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Image is a depth and stencil format and thus must "
10230 "have either one or both of VK_IMAGE_ASPECT_DEPTH_BIT and "
10231 "VK_IMAGE_ASPECT_STENCIL_BIT set.");
Tony Barbour7fd5c0f2016-05-03 16:11:53 -060010232 VkDepthStencilObj ds_image(m_device);
10233 ds_image.Init(m_device, 128, 128, VK_FORMAT_D24_UNORM_S8_UINT);
10234 ASSERT_TRUE(ds_image.initialized());
Tobin Ehlis15684a02016-07-21 14:55:26 -060010235 img_barrier.oldLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
10236 img_barrier.newLayout = VK_IMAGE_LAYOUT_GENERAL;
Tony Barbour7fd5c0f2016-05-03 16:11:53 -060010237 img_barrier.image = ds_image.handle();
Tobin Ehlis15684a02016-07-21 14:55:26 -060010238 // Use of COLOR aspect on DS image is error
10239 img_barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010240 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
10241 nullptr, 0, nullptr, 1, &img_barrier);
Tony Barbour7fd5c0f2016-05-03 16:11:53 -060010242 m_errorMonitor->VerifyFound();
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -060010243 // Now test depth-only
10244 VkFormatProperties format_props;
10245
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010246 vkGetPhysicalDeviceFormatProperties(m_device->phy().handle(), VK_FORMAT_D16_UNORM, &format_props);
10247 if (format_props.optimalTilingFeatures & VK_FORMAT_FEATURE_DEPTH_STENCIL_ATTACHMENT_BIT) {
10248 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Image is a depth-only format and thus must "
10249 "have VK_IMAGE_ASPECT_DEPTH_BIT set.");
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -060010250 VkDepthStencilObj d_image(m_device);
10251 d_image.Init(m_device, 128, 128, VK_FORMAT_D16_UNORM);
10252 ASSERT_TRUE(d_image.initialized());
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010253 img_barrier.oldLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
Tobin Ehlis15684a02016-07-21 14:55:26 -060010254 img_barrier.newLayout = VK_IMAGE_LAYOUT_GENERAL;
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -060010255 img_barrier.image = d_image.handle();
Tobin Ehlis15684a02016-07-21 14:55:26 -060010256 // Use of COLOR aspect on depth image is error
10257 img_barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010258 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0,
10259 0, nullptr, 0, nullptr, 1, &img_barrier);
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -060010260 m_errorMonitor->VerifyFound();
10261 }
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010262 vkGetPhysicalDeviceFormatProperties(m_device->phy().handle(), VK_FORMAT_S8_UINT, &format_props);
10263 if (format_props.optimalTilingFeatures & VK_FORMAT_FEATURE_DEPTH_STENCIL_ATTACHMENT_BIT) {
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -060010264 // Now test stencil-only
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010265 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Image is a stencil-only format and thus must "
10266 "have VK_IMAGE_ASPECT_STENCIL_BIT set.");
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -060010267 VkDepthStencilObj s_image(m_device);
10268 s_image.Init(m_device, 128, 128, VK_FORMAT_S8_UINT);
10269 ASSERT_TRUE(s_image.initialized());
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010270 img_barrier.oldLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
Tobin Ehlis15684a02016-07-21 14:55:26 -060010271 img_barrier.newLayout = VK_IMAGE_LAYOUT_GENERAL;
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -060010272 img_barrier.image = s_image.handle();
Tobin Ehlis15684a02016-07-21 14:55:26 -060010273 // Use of COLOR aspect on depth image is error
10274 img_barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010275 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0,
10276 0, nullptr, 0, nullptr, 1, &img_barrier);
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -060010277 m_errorMonitor->VerifyFound();
10278 }
10279 // Finally test color
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010280 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Image is a color format and thus must "
10281 "have VK_IMAGE_ASPECT_COLOR_BIT set.");
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -060010282 VkImageObj c_image(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010283 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 -060010284 ASSERT_TRUE(c_image.initialized());
10285 img_barrier.oldLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
10286 img_barrier.newLayout = VK_IMAGE_LAYOUT_GENERAL;
10287 img_barrier.image = c_image.handle();
10288 // Set aspect to depth (non-color)
10289 img_barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010290 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
10291 nullptr, 0, nullptr, 1, &img_barrier);
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -060010292 m_errorMonitor->VerifyFound();
Tony Barbour7fd5c0f2016-05-03 16:11:53 -060010293}
10294
Karl Schultz6addd812016-02-02 17:17:23 -070010295TEST_F(VkLayerTest, IdxBufferAlignmentError) {
Tobin Ehlisc4c23182015-09-17 12:24:13 -060010296 // Bind a BeginRenderPass within an active RenderPass
Karl Schultz6addd812016-02-02 17:17:23 -070010297 VkResult err;
Tobin Ehlisc4c23182015-09-17 12:24:13 -060010298
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010299 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "vkCmdBindIndexBuffer() offset (0x7) does not fall on ");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060010300
Tobin Ehlisc4c23182015-09-17 12:24:13 -060010301 ASSERT_NO_FATAL_FAILURE(InitState());
10302 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlisc4c23182015-09-17 12:24:13 -060010303 uint32_t qfi = 0;
10304 VkBufferCreateInfo buffCI = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010305 buffCI.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
10306 buffCI.size = 1024;
10307 buffCI.usage = VK_BUFFER_USAGE_INDEX_BUFFER_BIT;
10308 buffCI.queueFamilyIndexCount = 1;
10309 buffCI.pQueueFamilyIndices = &qfi;
Tobin Ehlisc4c23182015-09-17 12:24:13 -060010310
10311 VkBuffer ib;
Chia-I Wuf7458c52015-10-26 21:10:41 +080010312 err = vkCreateBuffer(m_device->device(), &buffCI, NULL, &ib);
Tobin Ehlisc4c23182015-09-17 12:24:13 -060010313 ASSERT_VK_SUCCESS(err);
10314
10315 BeginCommandBuffer();
10316 ASSERT_VK_SUCCESS(err);
Karl Schultz6addd812016-02-02 17:17:23 -070010317 // vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(),
10318 // VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Tobin Ehlisc4c23182015-09-17 12:24:13 -060010319 // Should error before calling to driver so don't care about actual data
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010320 vkCmdBindIndexBuffer(m_commandBuffer->GetBufferHandle(), ib, 7, VK_INDEX_TYPE_UINT16);
Tobin Ehlisc4c23182015-09-17 12:24:13 -060010321
Chris Forbes8f36a8a2016-04-07 13:21:07 +120010322 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -060010323
Chia-I Wuf7458c52015-10-26 21:10:41 +080010324 vkDestroyBuffer(m_device->device(), ib, NULL);
Tobin Ehlisc4c23182015-09-17 12:24:13 -060010325}
10326
Mark Lobodzinski52a6e7d2016-02-25 15:09:52 -070010327TEST_F(VkLayerTest, InvalidQueueFamilyIndex) {
10328 // Create an out-of-range queueFamilyIndex
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010329 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
10330 "vkCreateBuffer: pCreateInfo->pQueueFamilyIndices[0] (777) must be one "
10331 "of the indices specified when the device was created, via the "
10332 "VkDeviceQueueCreateInfo structure.");
Mark Lobodzinski52a6e7d2016-02-25 15:09:52 -070010333
10334 ASSERT_NO_FATAL_FAILURE(InitState());
10335 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
10336 VkBufferCreateInfo buffCI = {};
10337 buffCI.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
10338 buffCI.size = 1024;
10339 buffCI.usage = VK_BUFFER_USAGE_INDEX_BUFFER_BIT;
10340 buffCI.queueFamilyIndexCount = 1;
10341 // Introduce failure by specifying invalid queue_family_index
10342 uint32_t qfi = 777;
10343 buffCI.pQueueFamilyIndices = &qfi;
Tobin Ehlis24aab042016-03-24 10:54:18 -060010344 buffCI.sharingMode = VK_SHARING_MODE_CONCURRENT; // qfi only matters in CONCURRENT mode
Mark Lobodzinski52a6e7d2016-02-25 15:09:52 -070010345
10346 VkBuffer ib;
10347 vkCreateBuffer(m_device->device(), &buffCI, NULL, &ib);
10348
Chris Forbes8f36a8a2016-04-07 13:21:07 +120010349 m_errorMonitor->VerifyFound();
Tony Barbourdf4c0042016-06-01 15:55:43 -060010350 vkDestroyBuffer(m_device->device(), ib, NULL);
Mark Lobodzinski52a6e7d2016-02-25 15:09:52 -070010351}
10352
Karl Schultz6addd812016-02-02 17:17:23 -070010353TEST_F(VkLayerTest, ExecuteCommandsPrimaryCB) {
Tobin Ehlis0c94db02016-07-19 10:49:32 -060010354 TEST_DESCRIPTION("Attempt vkCmdExecuteCommands w/ a primary cmd buffer"
10355 " (should only be secondary)");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060010356
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010357 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "vkCmdExecuteCommands() called w/ Primary Cmd Buffer ");
Tobin Ehlis4b34ddc2015-09-17 14:18:16 -060010358
10359 ASSERT_NO_FATAL_FAILURE(InitState());
10360 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlis4b34ddc2015-09-17 14:18:16 -060010361
10362 BeginCommandBuffer();
Tobin Ehlis0c94db02016-07-19 10:49:32 -060010363
Chia-I Wu3432a0c2015-10-27 18:04:07 +080010364 VkCommandBuffer primCB = m_commandBuffer->GetBufferHandle();
10365 vkCmdExecuteCommands(m_commandBuffer->GetBufferHandle(), 1, &primCB);
Tobin Ehlis4b34ddc2015-09-17 14:18:16 -060010366
Chris Forbes8f36a8a2016-04-07 13:21:07 +120010367 m_errorMonitor->VerifyFound();
Tobin Ehlis4b34ddc2015-09-17 14:18:16 -060010368}
10369
Tobin Ehlis17826bd2016-05-25 11:12:50 -060010370TEST_F(VkLayerTest, DSUsageBitsErrors) {
10371 TEST_DESCRIPTION("Attempt to update descriptor sets for images and buffers "
10372 "that do not have correct usage bits sets.");
10373 VkResult err;
10374
10375 ASSERT_NO_FATAL_FAILURE(InitState());
10376 VkDescriptorPoolSize ds_type_count[VK_DESCRIPTOR_TYPE_RANGE_SIZE] = {};
10377 for (uint32_t i = 0; i < VK_DESCRIPTOR_TYPE_RANGE_SIZE; ++i) {
10378 ds_type_count[i].type = VkDescriptorType(i);
10379 ds_type_count[i].descriptorCount = 1;
10380 }
10381 VkDescriptorPoolCreateInfo ds_pool_ci = {};
10382 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
10383 ds_pool_ci.pNext = NULL;
10384 ds_pool_ci.maxSets = VK_DESCRIPTOR_TYPE_RANGE_SIZE;
10385 ds_pool_ci.poolSizeCount = VK_DESCRIPTOR_TYPE_RANGE_SIZE;
10386 ds_pool_ci.pPoolSizes = ds_type_count;
10387
10388 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010389 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis17826bd2016-05-25 11:12:50 -060010390 ASSERT_VK_SUCCESS(err);
10391
10392 // Create 10 layouts where each has a single descriptor of different type
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010393 VkDescriptorSetLayoutBinding dsl_binding[VK_DESCRIPTOR_TYPE_RANGE_SIZE] = {};
Tobin Ehlis17826bd2016-05-25 11:12:50 -060010394 for (uint32_t i = 0; i < VK_DESCRIPTOR_TYPE_RANGE_SIZE; ++i) {
10395 dsl_binding[i].binding = 0;
10396 dsl_binding[i].descriptorType = VkDescriptorType(i);
10397 dsl_binding[i].descriptorCount = 1;
10398 dsl_binding[i].stageFlags = VK_SHADER_STAGE_ALL;
10399 dsl_binding[i].pImmutableSamplers = NULL;
10400 }
10401
10402 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
10403 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
10404 ds_layout_ci.pNext = NULL;
10405 ds_layout_ci.bindingCount = 1;
10406 VkDescriptorSetLayout ds_layouts[VK_DESCRIPTOR_TYPE_RANGE_SIZE];
10407 for (uint32_t i = 0; i < VK_DESCRIPTOR_TYPE_RANGE_SIZE; ++i) {
10408 ds_layout_ci.pBindings = dsl_binding + i;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010409 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, ds_layouts + i);
Tobin Ehlis17826bd2016-05-25 11:12:50 -060010410 ASSERT_VK_SUCCESS(err);
10411 }
10412 VkDescriptorSet descriptor_sets[VK_DESCRIPTOR_TYPE_RANGE_SIZE] = {};
10413 VkDescriptorSetAllocateInfo alloc_info = {};
10414 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
10415 alloc_info.descriptorSetCount = VK_DESCRIPTOR_TYPE_RANGE_SIZE;
10416 alloc_info.descriptorPool = ds_pool;
10417 alloc_info.pSetLayouts = ds_layouts;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010418 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, descriptor_sets);
Tobin Ehlis17826bd2016-05-25 11:12:50 -060010419 ASSERT_VK_SUCCESS(err);
10420
10421 // Create a buffer & bufferView to be used for invalid updates
10422 VkBufferCreateInfo buff_ci = {};
10423 buff_ci.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
10424 // This usage is not valid for any descriptor type
10425 buff_ci.usage = VK_BUFFER_USAGE_TRANSFER_SRC_BIT;
10426 buff_ci.size = 256;
10427 buff_ci.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
10428 VkBuffer buffer;
10429 err = vkCreateBuffer(m_device->device(), &buff_ci, NULL, &buffer);
10430 ASSERT_VK_SUCCESS(err);
10431
10432 VkBufferViewCreateInfo buff_view_ci = {};
10433 buff_view_ci.sType = VK_STRUCTURE_TYPE_BUFFER_VIEW_CREATE_INFO;
10434 buff_view_ci.buffer = buffer;
10435 buff_view_ci.format = VK_FORMAT_R8_UNORM;
10436 buff_view_ci.range = VK_WHOLE_SIZE;
10437 VkBufferView buff_view;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010438 err = vkCreateBufferView(m_device->device(), &buff_view_ci, NULL, &buff_view);
Tobin Ehlis17826bd2016-05-25 11:12:50 -060010439 ASSERT_VK_SUCCESS(err);
10440
10441 // Create an image to be used for invalid updates
10442 VkImageCreateInfo image_ci = {};
10443 image_ci.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
10444 image_ci.imageType = VK_IMAGE_TYPE_2D;
10445 image_ci.format = VK_FORMAT_R8G8B8A8_UNORM;
10446 image_ci.extent.width = 64;
10447 image_ci.extent.height = 64;
10448 image_ci.extent.depth = 1;
10449 image_ci.mipLevels = 1;
10450 image_ci.arrayLayers = 1;
10451 image_ci.samples = VK_SAMPLE_COUNT_1_BIT;
10452 image_ci.tiling = VK_IMAGE_TILING_LINEAR;
10453 image_ci.initialLayout = VK_IMAGE_LAYOUT_PREINITIALIZED;
10454 // This usage is not valid for any descriptor type
10455 image_ci.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
10456 image_ci.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
10457 VkImage image;
10458 err = vkCreateImage(m_device->device(), &image_ci, NULL, &image);
10459 ASSERT_VK_SUCCESS(err);
10460 // Bind memory to image
10461 VkMemoryRequirements mem_reqs;
10462 VkDeviceMemory image_mem;
10463 bool pass;
10464 VkMemoryAllocateInfo mem_alloc = {};
10465 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
10466 mem_alloc.pNext = NULL;
10467 mem_alloc.allocationSize = 0;
10468 mem_alloc.memoryTypeIndex = 0;
10469 vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs);
10470 mem_alloc.allocationSize = mem_reqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010471 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0);
Tobin Ehlis17826bd2016-05-25 11:12:50 -060010472 ASSERT_TRUE(pass);
10473 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &image_mem);
10474 ASSERT_VK_SUCCESS(err);
10475 err = vkBindImageMemory(m_device->device(), image, image_mem, 0);
10476 ASSERT_VK_SUCCESS(err);
10477 // Now create view for image
10478 VkImageViewCreateInfo image_view_ci = {};
10479 image_view_ci.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
10480 image_view_ci.image = image;
10481 image_view_ci.format = VK_FORMAT_R8G8B8A8_UNORM;
10482 image_view_ci.viewType = VK_IMAGE_VIEW_TYPE_2D;
10483 image_view_ci.subresourceRange.layerCount = 1;
10484 image_view_ci.subresourceRange.baseArrayLayer = 0;
10485 image_view_ci.subresourceRange.levelCount = 1;
10486 image_view_ci.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
10487 VkImageView image_view;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010488 err = vkCreateImageView(m_device->device(), &image_view_ci, NULL, &image_view);
Tobin Ehlis17826bd2016-05-25 11:12:50 -060010489 ASSERT_VK_SUCCESS(err);
10490
10491 VkDescriptorBufferInfo buff_info = {};
10492 buff_info.buffer = buffer;
10493 VkDescriptorImageInfo img_info = {};
10494 img_info.imageView = image_view;
10495 VkWriteDescriptorSet descriptor_write = {};
10496 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
10497 descriptor_write.dstBinding = 0;
10498 descriptor_write.descriptorCount = 1;
10499 descriptor_write.pTexelBufferView = &buff_view;
10500 descriptor_write.pBufferInfo = &buff_info;
10501 descriptor_write.pImageInfo = &img_info;
10502
10503 // These error messages align with VkDescriptorType struct
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010504 const char *error_msgs[] = {"", // placeholder, no error for SAMPLER descriptor
10505 " does not have VK_IMAGE_USAGE_SAMPLED_BIT set.",
10506 " does not have VK_IMAGE_USAGE_SAMPLED_BIT set.",
10507 " does not have VK_IMAGE_USAGE_STORAGE_BIT set.",
10508 " does not have VK_BUFFER_USAGE_UNIFORM_TEXEL_BUFFER_BIT set.",
10509 " does not have VK_BUFFER_USAGE_STORAGE_TEXEL_BUFFER_BIT set.",
10510 " does not have VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT set.",
10511 " does not have VK_BUFFER_USAGE_STORAGE_BUFFER_BIT set.",
10512 " does not have VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT set.",
10513 " does not have VK_BUFFER_USAGE_STORAGE_BUFFER_BIT set.",
10514 " does not have VK_IMAGE_USAGE_INPUT_ATTACHMENT_BIT set."};
Tobin Ehlis17826bd2016-05-25 11:12:50 -060010515 // Start loop at 1 as SAMPLER desc type has no usage bit error
10516 for (uint32_t i = 1; i < VK_DESCRIPTOR_TYPE_RANGE_SIZE; ++i) {
10517 descriptor_write.descriptorType = VkDescriptorType(i);
10518 descriptor_write.dstSet = descriptor_sets[i];
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010519 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, error_msgs[i]);
Tobin Ehlis17826bd2016-05-25 11:12:50 -060010520
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010521 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
Tobin Ehlis17826bd2016-05-25 11:12:50 -060010522
10523 m_errorMonitor->VerifyFound();
10524 vkDestroyDescriptorSetLayout(m_device->device(), ds_layouts[i], NULL);
10525 }
10526 vkDestroyDescriptorSetLayout(m_device->device(), ds_layouts[0], NULL);
10527 vkDestroyImage(m_device->device(), image, NULL);
Tony Barbourdf4c0042016-06-01 15:55:43 -060010528 vkFreeMemory(m_device->device(), image_mem, NULL);
Tobin Ehlis17826bd2016-05-25 11:12:50 -060010529 vkDestroyImageView(m_device->device(), image_view, NULL);
10530 vkDestroyBuffer(m_device->device(), buffer, NULL);
10531 vkDestroyBufferView(m_device->device(), buff_view, NULL);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010532 vkFreeDescriptorSets(m_device->device(), ds_pool, VK_DESCRIPTOR_TYPE_RANGE_SIZE, descriptor_sets);
Tobin Ehlis17826bd2016-05-25 11:12:50 -060010533 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
10534}
10535
Tobin Ehlis585f66d2016-07-01 18:23:58 -060010536TEST_F(VkLayerTest, DSBufferInfoErrors) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010537 TEST_DESCRIPTION("Attempt to update buffer descriptor set that has incorrect "
10538 "parameters in VkDescriptorBufferInfo struct. This includes:\n"
10539 "1. offset value greater than buffer size\n"
10540 "2. range value of 0\n"
10541 "3. range value greater than buffer (size - offset)");
Tobin Ehlis585f66d2016-07-01 18:23:58 -060010542 VkResult err;
10543
10544 ASSERT_NO_FATAL_FAILURE(InitState());
10545 VkDescriptorPoolSize ds_type_count = {};
10546 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
10547 ds_type_count.descriptorCount = 1;
10548
10549 VkDescriptorPoolCreateInfo ds_pool_ci = {};
10550 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
10551 ds_pool_ci.pNext = NULL;
10552 ds_pool_ci.maxSets = 1;
10553 ds_pool_ci.poolSizeCount = 1;
10554 ds_pool_ci.pPoolSizes = &ds_type_count;
10555
10556 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010557 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis585f66d2016-07-01 18:23:58 -060010558 ASSERT_VK_SUCCESS(err);
10559
10560 // Create layout with single uniform buffer descriptor
10561 VkDescriptorSetLayoutBinding dsl_binding = {};
10562 dsl_binding.binding = 0;
10563 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
10564 dsl_binding.descriptorCount = 1;
10565 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
10566 dsl_binding.pImmutableSamplers = NULL;
10567
10568 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
10569 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
10570 ds_layout_ci.pNext = NULL;
10571 ds_layout_ci.bindingCount = 1;
10572 ds_layout_ci.pBindings = &dsl_binding;
10573 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010574 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis585f66d2016-07-01 18:23:58 -060010575 ASSERT_VK_SUCCESS(err);
10576
10577 VkDescriptorSet descriptor_set = {};
10578 VkDescriptorSetAllocateInfo alloc_info = {};
10579 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
10580 alloc_info.descriptorSetCount = 1;
10581 alloc_info.descriptorPool = ds_pool;
10582 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010583 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
Tobin Ehlis585f66d2016-07-01 18:23:58 -060010584 ASSERT_VK_SUCCESS(err);
10585
10586 // Create a buffer to be used for invalid updates
10587 VkBufferCreateInfo buff_ci = {};
10588 buff_ci.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
10589 buff_ci.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
10590 buff_ci.size = 256;
10591 buff_ci.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
10592 VkBuffer buffer;
10593 err = vkCreateBuffer(m_device->device(), &buff_ci, NULL, &buffer);
10594 ASSERT_VK_SUCCESS(err);
10595 // Have to bind memory to buffer before descriptor update
10596 VkMemoryAllocateInfo mem_alloc = {};
10597 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
10598 mem_alloc.pNext = NULL;
10599 mem_alloc.allocationSize = 256;
10600 mem_alloc.memoryTypeIndex = 0;
10601
10602 VkMemoryRequirements mem_reqs;
10603 vkGetBufferMemoryRequirements(m_device->device(), buffer, &mem_reqs);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010604 bool pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0);
Tobin Ehlis585f66d2016-07-01 18:23:58 -060010605 if (!pass) {
10606 vkDestroyBuffer(m_device->device(), buffer, NULL);
10607 return;
10608 }
10609
10610 VkDeviceMemory mem;
10611 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem);
10612 ASSERT_VK_SUCCESS(err);
10613 err = vkBindBufferMemory(m_device->device(), buffer, mem, 0);
10614 ASSERT_VK_SUCCESS(err);
10615
10616 VkDescriptorBufferInfo buff_info = {};
10617 buff_info.buffer = buffer;
10618 // First make offset 1 larger than buffer size
10619 buff_info.offset = 257;
10620 buff_info.range = VK_WHOLE_SIZE;
10621 VkWriteDescriptorSet descriptor_write = {};
10622 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
10623 descriptor_write.dstBinding = 0;
10624 descriptor_write.descriptorCount = 1;
10625 descriptor_write.pTexelBufferView = nullptr;
10626 descriptor_write.pBufferInfo = &buff_info;
10627 descriptor_write.pImageInfo = nullptr;
10628
10629 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
10630 descriptor_write.dstSet = descriptor_set;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010631 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " offset of 257 is greater than buffer ");
Tobin Ehlis585f66d2016-07-01 18:23:58 -060010632
10633 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
10634
10635 m_errorMonitor->VerifyFound();
10636 // Now cause error due to range of 0
10637 buff_info.offset = 0;
10638 buff_info.range = 0;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010639 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
10640 " range is not VK_WHOLE_SIZE and is zero, which is not allowed.");
Tobin Ehlis585f66d2016-07-01 18:23:58 -060010641
10642 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
10643
10644 m_errorMonitor->VerifyFound();
10645 // Now cause error due to range exceeding buffer size - offset
10646 buff_info.offset = 128;
10647 buff_info.range = 200;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010648 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 -060010649
10650 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
10651
10652 m_errorMonitor->VerifyFound();
Mark Lobodzinski4bb54092016-07-06 14:27:19 -060010653 vkFreeMemory(m_device->device(), mem, NULL);
Tobin Ehlis585f66d2016-07-01 18:23:58 -060010654 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
10655 vkDestroyBuffer(m_device->device(), buffer, NULL);
10656 vkFreeDescriptorSets(m_device->device(), ds_pool, 1, &descriptor_set);
10657 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
10658}
10659
Tobin Ehlis2fc296b2016-06-15 14:05:27 -060010660TEST_F(VkLayerTest, DSAspectBitsErrors) {
10661 // TODO : Initially only catching case where DEPTH & STENCIL aspect bits
10662 // are set, but could expand this test to hit more cases.
10663 TEST_DESCRIPTION("Attempt to update descriptor sets for images "
10664 "that do not have correct aspect bits sets.");
10665 VkResult err;
10666
10667 ASSERT_NO_FATAL_FAILURE(InitState());
10668 VkDescriptorPoolSize ds_type_count = {};
10669 ds_type_count.type = VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT;
10670 ds_type_count.descriptorCount = 1;
10671
10672 VkDescriptorPoolCreateInfo ds_pool_ci = {};
10673 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
10674 ds_pool_ci.pNext = NULL;
10675 ds_pool_ci.maxSets = 5;
10676 ds_pool_ci.poolSizeCount = 1;
10677 ds_pool_ci.pPoolSizes = &ds_type_count;
10678
10679 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010680 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis2fc296b2016-06-15 14:05:27 -060010681 ASSERT_VK_SUCCESS(err);
10682
10683 VkDescriptorSetLayoutBinding dsl_binding = {};
10684 dsl_binding.binding = 0;
10685 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT;
10686 dsl_binding.descriptorCount = 1;
10687 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
10688 dsl_binding.pImmutableSamplers = NULL;
10689
10690 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
10691 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
10692 ds_layout_ci.pNext = NULL;
10693 ds_layout_ci.bindingCount = 1;
10694 ds_layout_ci.pBindings = &dsl_binding;
10695 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010696 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis2fc296b2016-06-15 14:05:27 -060010697 ASSERT_VK_SUCCESS(err);
10698
10699 VkDescriptorSet descriptor_set = {};
10700 VkDescriptorSetAllocateInfo alloc_info = {};
10701 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
10702 alloc_info.descriptorSetCount = 1;
10703 alloc_info.descriptorPool = ds_pool;
10704 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010705 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
Tobin Ehlis2fc296b2016-06-15 14:05:27 -060010706 ASSERT_VK_SUCCESS(err);
10707
10708 // Create an image to be used for invalid updates
10709 VkImageCreateInfo image_ci = {};
10710 image_ci.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
10711 image_ci.imageType = VK_IMAGE_TYPE_2D;
10712 image_ci.format = VK_FORMAT_D24_UNORM_S8_UINT;
10713 image_ci.extent.width = 64;
10714 image_ci.extent.height = 64;
10715 image_ci.extent.depth = 1;
10716 image_ci.mipLevels = 1;
10717 image_ci.arrayLayers = 1;
10718 image_ci.samples = VK_SAMPLE_COUNT_1_BIT;
10719 image_ci.tiling = VK_IMAGE_TILING_LINEAR;
10720 image_ci.initialLayout = VK_IMAGE_LAYOUT_PREINITIALIZED;
10721 image_ci.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
10722 image_ci.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
10723 VkImage image;
10724 err = vkCreateImage(m_device->device(), &image_ci, NULL, &image);
10725 ASSERT_VK_SUCCESS(err);
10726 // Bind memory to image
10727 VkMemoryRequirements mem_reqs;
10728 VkDeviceMemory image_mem;
10729 bool pass;
10730 VkMemoryAllocateInfo mem_alloc = {};
10731 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
10732 mem_alloc.pNext = NULL;
10733 mem_alloc.allocationSize = 0;
10734 mem_alloc.memoryTypeIndex = 0;
10735 vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs);
10736 mem_alloc.allocationSize = mem_reqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010737 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0);
Tobin Ehlis2fc296b2016-06-15 14:05:27 -060010738 ASSERT_TRUE(pass);
10739 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &image_mem);
10740 ASSERT_VK_SUCCESS(err);
10741 err = vkBindImageMemory(m_device->device(), image, image_mem, 0);
10742 ASSERT_VK_SUCCESS(err);
10743 // Now create view for image
10744 VkImageViewCreateInfo image_view_ci = {};
10745 image_view_ci.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
10746 image_view_ci.image = image;
10747 image_view_ci.format = VK_FORMAT_D24_UNORM_S8_UINT;
10748 image_view_ci.viewType = VK_IMAGE_VIEW_TYPE_2D;
10749 image_view_ci.subresourceRange.layerCount = 1;
10750 image_view_ci.subresourceRange.baseArrayLayer = 0;
10751 image_view_ci.subresourceRange.levelCount = 1;
10752 // Setting both depth & stencil aspect bits is illegal for descriptor
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010753 image_view_ci.subresourceRange.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT;
Tobin Ehlis2fc296b2016-06-15 14:05:27 -060010754
10755 VkImageView image_view;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010756 err = vkCreateImageView(m_device->device(), &image_view_ci, NULL, &image_view);
Tobin Ehlis2fc296b2016-06-15 14:05:27 -060010757 ASSERT_VK_SUCCESS(err);
10758
10759 VkDescriptorImageInfo img_info = {};
10760 img_info.imageView = image_view;
10761 VkWriteDescriptorSet descriptor_write = {};
10762 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
10763 descriptor_write.dstBinding = 0;
10764 descriptor_write.descriptorCount = 1;
10765 descriptor_write.pTexelBufferView = NULL;
10766 descriptor_write.pBufferInfo = NULL;
10767 descriptor_write.pImageInfo = &img_info;
10768 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT;
10769 descriptor_write.dstSet = descriptor_set;
10770 const char *error_msg = " please only set either VK_IMAGE_ASPECT_DEPTH_BIT "
10771 "or VK_IMAGE_ASPECT_STENCIL_BIT ";
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010772 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, error_msg);
Tobin Ehlis2fc296b2016-06-15 14:05:27 -060010773
10774 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
10775
10776 m_errorMonitor->VerifyFound();
10777 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
10778 vkDestroyImage(m_device->device(), image, NULL);
10779 vkFreeMemory(m_device->device(), image_mem, NULL);
10780 vkDestroyImageView(m_device->device(), image_view, NULL);
10781 vkFreeDescriptorSets(m_device->device(), ds_pool, 1, &descriptor_set);
10782 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
10783}
10784
Karl Schultz6addd812016-02-02 17:17:23 -070010785TEST_F(VkLayerTest, DSTypeMismatch) {
Tobin Ehlis49eb23d2015-05-22 12:38:55 -060010786 // Create DS w/ layout of one type and attempt Update w/ mis-matched type
Karl Schultz6addd812016-02-02 17:17:23 -070010787 VkResult err;
Tobin Ehlis3b780662015-05-28 12:11:26 -060010788
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010789 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
10790 " binding #0 with type VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER but update "
10791 "type is VK_DESCRIPTOR_TYPE_SAMPLER");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060010792
Tobin Ehlis3b780662015-05-28 12:11:26 -060010793 ASSERT_NO_FATAL_FAILURE(InitState());
Karl Schultz6addd812016-02-02 17:17:23 -070010794 // VkDescriptorSetObj descriptorSet(m_device);
Chia-I Wu1b99bb22015-10-27 19:25:11 +080010795 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010796 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
10797 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -060010798
10799 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010800 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
10801 ds_pool_ci.pNext = NULL;
10802 ds_pool_ci.maxSets = 1;
10803 ds_pool_ci.poolSizeCount = 1;
10804 ds_pool_ci.pPoolSizes = &ds_type_count;
Tony Barboureb254902015-07-15 12:50:33 -060010805
Tobin Ehlis3b780662015-05-28 12:11:26 -060010806 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010807 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis3b780662015-05-28 12:11:26 -060010808 ASSERT_VK_SUCCESS(err);
Tony Barboureb254902015-07-15 12:50:33 -060010809 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010810 dsl_binding.binding = 0;
10811 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
10812 dsl_binding.descriptorCount = 1;
10813 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
10814 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis3b780662015-05-28 12:11:26 -060010815
Tony Barboureb254902015-07-15 12:50:33 -060010816 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010817 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
10818 ds_layout_ci.pNext = NULL;
10819 ds_layout_ci.bindingCount = 1;
10820 ds_layout_ci.pBindings = &dsl_binding;
Tony Barboureb254902015-07-15 12:50:33 -060010821
Tobin Ehlis3b780662015-05-28 12:11:26 -060010822 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010823 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis3b780662015-05-28 12:11:26 -060010824 ASSERT_VK_SUCCESS(err);
10825
10826 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080010827 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +080010828 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -070010829 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -060010830 alloc_info.descriptorPool = ds_pool;
10831 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010832 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis3b780662015-05-28 12:11:26 -060010833 ASSERT_VK_SUCCESS(err);
Tobin Ehlis3b780662015-05-28 12:11:26 -060010834
Tobin Ehlis30db8f82016-05-05 08:19:48 -060010835 VkSamplerCreateInfo sampler_ci = {};
10836 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
10837 sampler_ci.pNext = NULL;
10838 sampler_ci.magFilter = VK_FILTER_NEAREST;
10839 sampler_ci.minFilter = VK_FILTER_NEAREST;
10840 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
10841 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
10842 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
10843 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
10844 sampler_ci.mipLodBias = 1.0;
10845 sampler_ci.anisotropyEnable = VK_FALSE;
10846 sampler_ci.maxAnisotropy = 1;
10847 sampler_ci.compareEnable = VK_FALSE;
10848 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
10849 sampler_ci.minLod = 1.0;
10850 sampler_ci.maxLod = 1.0;
10851 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
10852 sampler_ci.unnormalizedCoordinates = VK_FALSE;
10853 VkSampler sampler;
10854 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
10855 ASSERT_VK_SUCCESS(err);
10856
10857 VkDescriptorImageInfo info = {};
10858 info.sampler = sampler;
Chia-I Wu9d00ed72015-05-25 16:27:55 +080010859
10860 VkWriteDescriptorSet descriptor_write;
10861 memset(&descriptor_write, 0, sizeof(descriptor_write));
10862 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080010863 descriptor_write.dstSet = descriptorSet;
Chia-I Wud50a7d72015-10-26 20:48:51 +080010864 descriptor_write.descriptorCount = 1;
Tobin Ehlis3b780662015-05-28 12:11:26 -060010865 // This is a mismatched type for the layout which expects BUFFER
Chia-I Wu9d00ed72015-05-25 16:27:55 +080010866 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
Courtney Goeltzenleuchter4cb6d922015-10-23 13:38:14 -060010867 descriptor_write.pImageInfo = &info;
Chia-I Wu9d00ed72015-05-25 16:27:55 +080010868
10869 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
10870
Chris Forbes8f36a8a2016-04-07 13:21:07 +120010871 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -060010872
Chia-I Wuf7458c52015-10-26 21:10:41 +080010873 vkDestroySampler(m_device->device(), sampler, NULL);
10874 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
10875 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis49eb23d2015-05-22 12:38:55 -060010876}
10877
Karl Schultz6addd812016-02-02 17:17:23 -070010878TEST_F(VkLayerTest, DSUpdateOutOfBounds) {
Tobin Ehlis49eb23d2015-05-22 12:38:55 -060010879 // For overlapping Update, have arrayIndex exceed that of layout
Karl Schultz6addd812016-02-02 17:17:23 -070010880 VkResult err;
Tobin Ehlis3b780662015-05-28 12:11:26 -060010881
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010882 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
10883 " binding #0 with 1 total descriptors but update of 1 descriptors "
10884 "starting at binding offset of 0 combined with update array element "
10885 "offset of 1 oversteps the size of this descriptor set.");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060010886
Tobin Ehlis3b780662015-05-28 12:11:26 -060010887 ASSERT_NO_FATAL_FAILURE(InitState());
Karl Schultz6addd812016-02-02 17:17:23 -070010888 // VkDescriptorSetObj descriptorSet(m_device);
Chia-I Wu1b99bb22015-10-27 19:25:11 +080010889 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010890 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
10891 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -060010892
10893 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010894 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
10895 ds_pool_ci.pNext = NULL;
10896 ds_pool_ci.maxSets = 1;
10897 ds_pool_ci.poolSizeCount = 1;
10898 ds_pool_ci.pPoolSizes = &ds_type_count;
Tony Barboureb254902015-07-15 12:50:33 -060010899
Tobin Ehlis3b780662015-05-28 12:11:26 -060010900 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010901 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis3b780662015-05-28 12:11:26 -060010902 ASSERT_VK_SUCCESS(err);
Tobin Ehlis3b780662015-05-28 12:11:26 -060010903
Tony Barboureb254902015-07-15 12:50:33 -060010904 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010905 dsl_binding.binding = 0;
10906 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
10907 dsl_binding.descriptorCount = 1;
10908 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
10909 dsl_binding.pImmutableSamplers = NULL;
Tony Barboureb254902015-07-15 12:50:33 -060010910
10911 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010912 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
10913 ds_layout_ci.pNext = NULL;
10914 ds_layout_ci.bindingCount = 1;
10915 ds_layout_ci.pBindings = &dsl_binding;
Tony Barboureb254902015-07-15 12:50:33 -060010916
Tobin Ehlis3b780662015-05-28 12:11:26 -060010917 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010918 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis3b780662015-05-28 12:11:26 -060010919 ASSERT_VK_SUCCESS(err);
10920
10921 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080010922 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +080010923 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -070010924 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -060010925 alloc_info.descriptorPool = ds_pool;
10926 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010927 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis3b780662015-05-28 12:11:26 -060010928 ASSERT_VK_SUCCESS(err);
Tobin Ehlis3b780662015-05-28 12:11:26 -060010929
Tobin Ehlis30db8f82016-05-05 08:19:48 -060010930 // Correctly update descriptor to avoid "NOT_UPDATED" error
10931 VkDescriptorBufferInfo buff_info = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010932 buff_info.buffer = VkBuffer(0); // Don't care about buffer handle for this test
Tobin Ehlis30db8f82016-05-05 08:19:48 -060010933 buff_info.offset = 0;
10934 buff_info.range = 1024;
Chia-I Wu9d00ed72015-05-25 16:27:55 +080010935
10936 VkWriteDescriptorSet descriptor_write;
10937 memset(&descriptor_write, 0, sizeof(descriptor_write));
10938 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080010939 descriptor_write.dstSet = descriptorSet;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010940 descriptor_write.dstArrayElement = 1; /* This index out of bounds for the update */
Chia-I Wud50a7d72015-10-26 20:48:51 +080010941 descriptor_write.descriptorCount = 1;
Tobin Ehlis0a43bde2016-05-03 08:31:08 -060010942 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
10943 descriptor_write.pBufferInfo = &buff_info;
Chia-I Wu9d00ed72015-05-25 16:27:55 +080010944
10945 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
10946
Chris Forbes8f36a8a2016-04-07 13:21:07 +120010947 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -060010948
Chia-I Wuf7458c52015-10-26 21:10:41 +080010949 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
10950 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis49eb23d2015-05-22 12:38:55 -060010951}
10952
Karl Schultz6addd812016-02-02 17:17:23 -070010953TEST_F(VkLayerTest, InvalidDSUpdateIndex) {
10954 // Create layout w/ count of 1 and attempt update to that layout w/ binding
10955 // index 2
10956 VkResult err;
Tobin Ehlis3b780662015-05-28 12:11:26 -060010957
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010958 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " does not have binding 2.");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060010959
Tobin Ehlis3b780662015-05-28 12:11:26 -060010960 ASSERT_NO_FATAL_FAILURE(InitState());
Karl Schultz6addd812016-02-02 17:17:23 -070010961 // VkDescriptorSetObj descriptorSet(m_device);
Chia-I Wu1b99bb22015-10-27 19:25:11 +080010962 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010963 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
10964 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -060010965
10966 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010967 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
10968 ds_pool_ci.pNext = NULL;
10969 ds_pool_ci.maxSets = 1;
10970 ds_pool_ci.poolSizeCount = 1;
10971 ds_pool_ci.pPoolSizes = &ds_type_count;
Courtney Goeltzenleuchterfe908d32015-09-16 16:12:45 -060010972
Tobin Ehlis3b780662015-05-28 12:11:26 -060010973 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010974 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis3b780662015-05-28 12:11:26 -060010975 ASSERT_VK_SUCCESS(err);
Tobin Ehlis3b780662015-05-28 12:11:26 -060010976
Tony Barboureb254902015-07-15 12:50:33 -060010977 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010978 dsl_binding.binding = 0;
10979 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
10980 dsl_binding.descriptorCount = 1;
10981 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
10982 dsl_binding.pImmutableSamplers = NULL;
Tony Barboureb254902015-07-15 12:50:33 -060010983
10984 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010985 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
10986 ds_layout_ci.pNext = NULL;
10987 ds_layout_ci.bindingCount = 1;
10988 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlis3b780662015-05-28 12:11:26 -060010989 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010990 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis3b780662015-05-28 12:11:26 -060010991 ASSERT_VK_SUCCESS(err);
10992
10993 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080010994 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +080010995 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -070010996 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -060010997 alloc_info.descriptorPool = ds_pool;
10998 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010999 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis3b780662015-05-28 12:11:26 -060011000 ASSERT_VK_SUCCESS(err);
Tobin Ehlis3b780662015-05-28 12:11:26 -060011001
Tony Barboureb254902015-07-15 12:50:33 -060011002 VkSamplerCreateInfo sampler_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011003 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
11004 sampler_ci.pNext = NULL;
11005 sampler_ci.magFilter = VK_FILTER_NEAREST;
11006 sampler_ci.minFilter = VK_FILTER_NEAREST;
11007 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
11008 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
11009 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
11010 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
11011 sampler_ci.mipLodBias = 1.0;
11012 sampler_ci.anisotropyEnable = VK_FALSE;
11013 sampler_ci.maxAnisotropy = 1;
11014 sampler_ci.compareEnable = VK_FALSE;
11015 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
11016 sampler_ci.minLod = 1.0;
11017 sampler_ci.maxLod = 1.0;
11018 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
11019 sampler_ci.unnormalizedCoordinates = VK_FALSE;
Tony Barboureb254902015-07-15 12:50:33 -060011020
Tobin Ehlis3b780662015-05-28 12:11:26 -060011021 VkSampler sampler;
Chia-I Wuf7458c52015-10-26 21:10:41 +080011022 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
Tobin Ehlis3b780662015-05-28 12:11:26 -060011023 ASSERT_VK_SUCCESS(err);
Chia-I Wu9d00ed72015-05-25 16:27:55 +080011024
Courtney Goeltzenleuchter4cb6d922015-10-23 13:38:14 -060011025 VkDescriptorImageInfo info = {};
11026 info.sampler = sampler;
Chia-I Wu9d00ed72015-05-25 16:27:55 +080011027
11028 VkWriteDescriptorSet descriptor_write;
11029 memset(&descriptor_write, 0, sizeof(descriptor_write));
11030 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080011031 descriptor_write.dstSet = descriptorSet;
11032 descriptor_write.dstBinding = 2;
Chia-I Wud50a7d72015-10-26 20:48:51 +080011033 descriptor_write.descriptorCount = 1;
Tobin Ehlis3b780662015-05-28 12:11:26 -060011034 // This is the wrong type, but out of bounds will be flagged first
Chia-I Wu9d00ed72015-05-25 16:27:55 +080011035 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
Courtney Goeltzenleuchter4cb6d922015-10-23 13:38:14 -060011036 descriptor_write.pImageInfo = &info;
Chia-I Wu9d00ed72015-05-25 16:27:55 +080011037
11038 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
11039
Chris Forbes8f36a8a2016-04-07 13:21:07 +120011040 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -060011041
Chia-I Wuf7458c52015-10-26 21:10:41 +080011042 vkDestroySampler(m_device->device(), sampler, NULL);
11043 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
11044 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis49eb23d2015-05-22 12:38:55 -060011045}
11046
Karl Schultz6addd812016-02-02 17:17:23 -070011047TEST_F(VkLayerTest, InvalidDSUpdateStruct) {
11048 // Call UpdateDS w/ struct type other than valid VK_STRUCTUR_TYPE_UPDATE_*
11049 // types
11050 VkResult err;
Tobin Ehlis3b780662015-05-28 12:11:26 -060011051
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011052 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 -060011053
Tobin Ehlis3b780662015-05-28 12:11:26 -060011054 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinski209b5292015-09-17 09:44:05 -060011055
Chia-I Wu1b99bb22015-10-27 19:25:11 +080011056 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011057 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
11058 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -060011059
11060 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011061 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
11062 ds_pool_ci.pNext = NULL;
11063 ds_pool_ci.maxSets = 1;
11064 ds_pool_ci.poolSizeCount = 1;
11065 ds_pool_ci.pPoolSizes = &ds_type_count;
Courtney Goeltzenleuchterfe908d32015-09-16 16:12:45 -060011066
Tobin Ehlis3b780662015-05-28 12:11:26 -060011067 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011068 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis3b780662015-05-28 12:11:26 -060011069 ASSERT_VK_SUCCESS(err);
Tony Barboureb254902015-07-15 12:50:33 -060011070 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011071 dsl_binding.binding = 0;
11072 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
11073 dsl_binding.descriptorCount = 1;
11074 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
11075 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis3b780662015-05-28 12:11:26 -060011076
Tony Barboureb254902015-07-15 12:50:33 -060011077 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011078 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
11079 ds_layout_ci.pNext = NULL;
11080 ds_layout_ci.bindingCount = 1;
11081 ds_layout_ci.pBindings = &dsl_binding;
Tony Barboureb254902015-07-15 12:50:33 -060011082
Tobin Ehlis3b780662015-05-28 12:11:26 -060011083 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011084 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis3b780662015-05-28 12:11:26 -060011085 ASSERT_VK_SUCCESS(err);
11086
11087 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080011088 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +080011089 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -070011090 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -060011091 alloc_info.descriptorPool = ds_pool;
11092 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011093 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis3b780662015-05-28 12:11:26 -060011094 ASSERT_VK_SUCCESS(err);
Tobin Ehlis3b780662015-05-28 12:11:26 -060011095
Tony Barboureb254902015-07-15 12:50:33 -060011096 VkSamplerCreateInfo sampler_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011097 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
11098 sampler_ci.pNext = NULL;
11099 sampler_ci.magFilter = VK_FILTER_NEAREST;
11100 sampler_ci.minFilter = VK_FILTER_NEAREST;
11101 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
11102 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
11103 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
11104 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
11105 sampler_ci.mipLodBias = 1.0;
11106 sampler_ci.anisotropyEnable = VK_FALSE;
11107 sampler_ci.maxAnisotropy = 1;
11108 sampler_ci.compareEnable = VK_FALSE;
11109 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
11110 sampler_ci.minLod = 1.0;
11111 sampler_ci.maxLod = 1.0;
11112 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
11113 sampler_ci.unnormalizedCoordinates = VK_FALSE;
Tobin Ehlis3b780662015-05-28 12:11:26 -060011114 VkSampler sampler;
Chia-I Wuf7458c52015-10-26 21:10:41 +080011115 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
Tobin Ehlis3b780662015-05-28 12:11:26 -060011116 ASSERT_VK_SUCCESS(err);
Chia-I Wu9d00ed72015-05-25 16:27:55 +080011117
Courtney Goeltzenleuchter4cb6d922015-10-23 13:38:14 -060011118 VkDescriptorImageInfo info = {};
11119 info.sampler = sampler;
Chia-I Wu9d00ed72015-05-25 16:27:55 +080011120
11121 VkWriteDescriptorSet descriptor_write;
11122 memset(&descriptor_write, 0, sizeof(descriptor_write));
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011123 descriptor_write.sType = (VkStructureType)0x99999999; /* Intentionally broken struct type */
Chia-I Wu3432a0c2015-10-27 18:04:07 +080011124 descriptor_write.dstSet = descriptorSet;
Chia-I Wud50a7d72015-10-26 20:48:51 +080011125 descriptor_write.descriptorCount = 1;
Tobin Ehlis3b780662015-05-28 12:11:26 -060011126 // This is the wrong type, but out of bounds will be flagged first
Chia-I Wu9d00ed72015-05-25 16:27:55 +080011127 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
Courtney Goeltzenleuchter4cb6d922015-10-23 13:38:14 -060011128 descriptor_write.pImageInfo = &info;
Chia-I Wu9d00ed72015-05-25 16:27:55 +080011129
11130 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
11131
Chris Forbes8f36a8a2016-04-07 13:21:07 +120011132 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -060011133
Chia-I Wuf7458c52015-10-26 21:10:41 +080011134 vkDestroySampler(m_device->device(), sampler, NULL);
11135 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
11136 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis49eb23d2015-05-22 12:38:55 -060011137}
11138
Karl Schultz6addd812016-02-02 17:17:23 -070011139TEST_F(VkLayerTest, SampleDescriptorUpdateError) {
Tobin Ehlisa1c28562015-10-23 16:00:08 -060011140 // Create a single Sampler descriptor and send it an invalid Sampler
Karl Schultz6addd812016-02-02 17:17:23 -070011141 VkResult err;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060011142
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011143 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
11144 "Attempted write update to sampler descriptor with invalid sampler");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060011145
Tobin Ehlisa1c28562015-10-23 16:00:08 -060011146 ASSERT_NO_FATAL_FAILURE(InitState());
Karl Schultz6addd812016-02-02 17:17:23 -070011147 // TODO : Farm Descriptor setup code to helper function(s) to reduce copied
11148 // code
Chia-I Wu1b99bb22015-10-27 19:25:11 +080011149 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011150 ds_type_count.type = VK_DESCRIPTOR_TYPE_SAMPLER;
11151 ds_type_count.descriptorCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060011152
11153 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011154 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
11155 ds_pool_ci.pNext = NULL;
11156 ds_pool_ci.maxSets = 1;
11157 ds_pool_ci.poolSizeCount = 1;
11158 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060011159
11160 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011161 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060011162 ASSERT_VK_SUCCESS(err);
11163
11164 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011165 dsl_binding.binding = 0;
11166 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
11167 dsl_binding.descriptorCount = 1;
11168 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
11169 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060011170
11171 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011172 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
11173 ds_layout_ci.pNext = NULL;
11174 ds_layout_ci.bindingCount = 1;
11175 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060011176 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011177 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060011178 ASSERT_VK_SUCCESS(err);
11179
11180 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080011181 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +080011182 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -070011183 alloc_info.descriptorSetCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060011184 alloc_info.descriptorPool = ds_pool;
11185 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011186 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060011187 ASSERT_VK_SUCCESS(err);
11188
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011189 VkSampler sampler = (VkSampler)((size_t)0xbaadbeef); // Sampler with invalid handle
Tobin Ehlisa1c28562015-10-23 16:00:08 -060011190
11191 VkDescriptorImageInfo descriptor_info;
11192 memset(&descriptor_info, 0, sizeof(VkDescriptorImageInfo));
11193 descriptor_info.sampler = sampler;
11194
11195 VkWriteDescriptorSet descriptor_write;
11196 memset(&descriptor_write, 0, sizeof(descriptor_write));
11197 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080011198 descriptor_write.dstSet = descriptorSet;
11199 descriptor_write.dstBinding = 0;
Chia-I Wud50a7d72015-10-26 20:48:51 +080011200 descriptor_write.descriptorCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060011201 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
11202 descriptor_write.pImageInfo = &descriptor_info;
11203
11204 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
11205
Chris Forbes8f36a8a2016-04-07 13:21:07 +120011206 m_errorMonitor->VerifyFound();
Tobin Ehlisa1c28562015-10-23 16:00:08 -060011207
Chia-I Wuf7458c52015-10-26 21:10:41 +080011208 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
11209 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060011210}
11211
Karl Schultz6addd812016-02-02 17:17:23 -070011212TEST_F(VkLayerTest, ImageViewDescriptorUpdateError) {
11213 // Create a single combined Image/Sampler descriptor and send it an invalid
11214 // imageView
11215 VkResult err;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060011216
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011217 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Attempted write update to combined "
11218 "image sampler descriptor failed due "
11219 "to: Invalid VkImageView:");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060011220
Tobin Ehlisa1c28562015-10-23 16:00:08 -060011221 ASSERT_NO_FATAL_FAILURE(InitState());
Chia-I Wu1b99bb22015-10-27 19:25:11 +080011222 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011223 ds_type_count.type = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
11224 ds_type_count.descriptorCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060011225
11226 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011227 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
11228 ds_pool_ci.pNext = NULL;
11229 ds_pool_ci.maxSets = 1;
11230 ds_pool_ci.poolSizeCount = 1;
11231 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060011232
11233 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011234 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060011235 ASSERT_VK_SUCCESS(err);
11236
11237 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011238 dsl_binding.binding = 0;
11239 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
11240 dsl_binding.descriptorCount = 1;
11241 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
11242 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060011243
11244 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011245 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
11246 ds_layout_ci.pNext = NULL;
11247 ds_layout_ci.bindingCount = 1;
11248 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060011249 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011250 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060011251 ASSERT_VK_SUCCESS(err);
11252
11253 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080011254 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +080011255 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -070011256 alloc_info.descriptorSetCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060011257 alloc_info.descriptorPool = ds_pool;
11258 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011259 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060011260 ASSERT_VK_SUCCESS(err);
11261
11262 VkSamplerCreateInfo sampler_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011263 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
11264 sampler_ci.pNext = NULL;
11265 sampler_ci.magFilter = VK_FILTER_NEAREST;
11266 sampler_ci.minFilter = VK_FILTER_NEAREST;
11267 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
11268 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
11269 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
11270 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
11271 sampler_ci.mipLodBias = 1.0;
11272 sampler_ci.anisotropyEnable = VK_FALSE;
11273 sampler_ci.maxAnisotropy = 1;
11274 sampler_ci.compareEnable = VK_FALSE;
11275 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
11276 sampler_ci.minLod = 1.0;
11277 sampler_ci.maxLod = 1.0;
11278 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
11279 sampler_ci.unnormalizedCoordinates = VK_FALSE;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060011280
11281 VkSampler sampler;
Chia-I Wuf7458c52015-10-26 21:10:41 +080011282 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060011283 ASSERT_VK_SUCCESS(err);
11284
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011285 VkImageView view = (VkImageView)((size_t)0xbaadbeef); // invalid imageView object
Tobin Ehlisa1c28562015-10-23 16:00:08 -060011286
11287 VkDescriptorImageInfo descriptor_info;
11288 memset(&descriptor_info, 0, sizeof(VkDescriptorImageInfo));
11289 descriptor_info.sampler = sampler;
11290 descriptor_info.imageView = view;
11291
11292 VkWriteDescriptorSet descriptor_write;
11293 memset(&descriptor_write, 0, sizeof(descriptor_write));
11294 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080011295 descriptor_write.dstSet = descriptorSet;
11296 descriptor_write.dstBinding = 0;
Chia-I Wud50a7d72015-10-26 20:48:51 +080011297 descriptor_write.descriptorCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060011298 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
11299 descriptor_write.pImageInfo = &descriptor_info;
11300
11301 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
11302
Chris Forbes8f36a8a2016-04-07 13:21:07 +120011303 m_errorMonitor->VerifyFound();
Tobin Ehlisa1c28562015-10-23 16:00:08 -060011304
Chia-I Wuf7458c52015-10-26 21:10:41 +080011305 vkDestroySampler(m_device->device(), sampler, NULL);
11306 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
11307 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060011308}
11309
Karl Schultz6addd812016-02-02 17:17:23 -070011310TEST_F(VkLayerTest, CopyDescriptorUpdateErrors) {
11311 // Create DS w/ layout of 2 types, write update 1 and attempt to copy-update
11312 // into the other
11313 VkResult err;
Tobin Ehlis04356f92015-10-27 16:35:27 -060011314
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011315 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " binding #1 with type "
11316 "VK_DESCRIPTOR_TYPE_SAMPLER. Types do "
11317 "not match.");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060011318
Tobin Ehlis04356f92015-10-27 16:35:27 -060011319 ASSERT_NO_FATAL_FAILURE(InitState());
Karl Schultz6addd812016-02-02 17:17:23 -070011320 // VkDescriptorSetObj descriptorSet(m_device);
Chia-I Wu1b99bb22015-10-27 19:25:11 +080011321 VkDescriptorPoolSize ds_type_count[2] = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011322 ds_type_count[0].type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
11323 ds_type_count[0].descriptorCount = 1;
11324 ds_type_count[1].type = VK_DESCRIPTOR_TYPE_SAMPLER;
11325 ds_type_count[1].descriptorCount = 1;
Tobin Ehlis04356f92015-10-27 16:35:27 -060011326
11327 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011328 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
11329 ds_pool_ci.pNext = NULL;
11330 ds_pool_ci.maxSets = 1;
11331 ds_pool_ci.poolSizeCount = 2;
11332 ds_pool_ci.pPoolSizes = ds_type_count;
Tobin Ehlis04356f92015-10-27 16:35:27 -060011333
11334 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011335 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis04356f92015-10-27 16:35:27 -060011336 ASSERT_VK_SUCCESS(err);
11337 VkDescriptorSetLayoutBinding dsl_binding[2] = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011338 dsl_binding[0].binding = 0;
11339 dsl_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
11340 dsl_binding[0].descriptorCount = 1;
11341 dsl_binding[0].stageFlags = VK_SHADER_STAGE_ALL;
11342 dsl_binding[0].pImmutableSamplers = NULL;
11343 dsl_binding[1].binding = 1;
11344 dsl_binding[1].descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
11345 dsl_binding[1].descriptorCount = 1;
11346 dsl_binding[1].stageFlags = VK_SHADER_STAGE_ALL;
11347 dsl_binding[1].pImmutableSamplers = NULL;
Tobin Ehlis04356f92015-10-27 16:35:27 -060011348
11349 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011350 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
11351 ds_layout_ci.pNext = NULL;
11352 ds_layout_ci.bindingCount = 2;
11353 ds_layout_ci.pBindings = dsl_binding;
Tobin Ehlis04356f92015-10-27 16:35:27 -060011354
11355 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011356 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis04356f92015-10-27 16:35:27 -060011357 ASSERT_VK_SUCCESS(err);
11358
11359 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080011360 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +080011361 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -070011362 alloc_info.descriptorSetCount = 1;
Tobin Ehlis04356f92015-10-27 16:35:27 -060011363 alloc_info.descriptorPool = ds_pool;
11364 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011365 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis04356f92015-10-27 16:35:27 -060011366 ASSERT_VK_SUCCESS(err);
11367
11368 VkSamplerCreateInfo sampler_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011369 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
11370 sampler_ci.pNext = NULL;
11371 sampler_ci.magFilter = VK_FILTER_NEAREST;
11372 sampler_ci.minFilter = VK_FILTER_NEAREST;
11373 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
11374 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
11375 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
11376 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
11377 sampler_ci.mipLodBias = 1.0;
11378 sampler_ci.anisotropyEnable = VK_FALSE;
11379 sampler_ci.maxAnisotropy = 1;
11380 sampler_ci.compareEnable = VK_FALSE;
11381 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
11382 sampler_ci.minLod = 1.0;
11383 sampler_ci.maxLod = 1.0;
11384 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
11385 sampler_ci.unnormalizedCoordinates = VK_FALSE;
Tobin Ehlis04356f92015-10-27 16:35:27 -060011386
11387 VkSampler sampler;
Chia-I Wuf7458c52015-10-26 21:10:41 +080011388 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
Tobin Ehlis04356f92015-10-27 16:35:27 -060011389 ASSERT_VK_SUCCESS(err);
11390
11391 VkDescriptorImageInfo info = {};
11392 info.sampler = sampler;
11393
11394 VkWriteDescriptorSet descriptor_write;
11395 memset(&descriptor_write, 0, sizeof(VkWriteDescriptorSet));
11396 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080011397 descriptor_write.dstSet = descriptorSet;
11398 descriptor_write.dstBinding = 1; // SAMPLER binding from layout above
Chia-I Wud50a7d72015-10-26 20:48:51 +080011399 descriptor_write.descriptorCount = 1;
Tobin Ehlis04356f92015-10-27 16:35:27 -060011400 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
11401 descriptor_write.pImageInfo = &info;
11402 // This write update should succeed
11403 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
11404 // Now perform a copy update that fails due to type mismatch
11405 VkCopyDescriptorSet copy_ds_update;
11406 memset(&copy_ds_update, 0, sizeof(VkCopyDescriptorSet));
11407 copy_ds_update.sType = VK_STRUCTURE_TYPE_COPY_DESCRIPTOR_SET;
11408 copy_ds_update.srcSet = descriptorSet;
Mark Young29927482016-05-04 14:38:51 -060011409 copy_ds_update.srcBinding = 1; // Copy from SAMPLER binding
Chia-I Wu3432a0c2015-10-27 18:04:07 +080011410 copy_ds_update.dstSet = descriptorSet;
Karl Schultz6addd812016-02-02 17:17:23 -070011411 copy_ds_update.dstBinding = 0; // ERROR : copy to UNIFORM binding
Chia-I Wud50a7d72015-10-26 20:48:51 +080011412 copy_ds_update.descriptorCount = 1; // copy 1 descriptor
Tobin Ehlis04356f92015-10-27 16:35:27 -060011413 vkUpdateDescriptorSets(m_device->device(), 0, NULL, 1, &copy_ds_update);
11414
Chris Forbes8f36a8a2016-04-07 13:21:07 +120011415 m_errorMonitor->VerifyFound();
Tobin Ehlis04356f92015-10-27 16:35:27 -060011416 // Now perform a copy update that fails due to binding out of bounds
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011417 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 -060011418 memset(&copy_ds_update, 0, sizeof(VkCopyDescriptorSet));
11419 copy_ds_update.sType = VK_STRUCTURE_TYPE_COPY_DESCRIPTOR_SET;
11420 copy_ds_update.srcSet = descriptorSet;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011421 copy_ds_update.srcBinding = 3; // ERROR : Invalid binding for matching layout
Chia-I Wu3432a0c2015-10-27 18:04:07 +080011422 copy_ds_update.dstSet = descriptorSet;
11423 copy_ds_update.dstBinding = 0;
Mark Young29927482016-05-04 14:38:51 -060011424 copy_ds_update.descriptorCount = 1; // Copy 1 descriptor
Tobin Ehlis04356f92015-10-27 16:35:27 -060011425 vkUpdateDescriptorSets(m_device->device(), 0, NULL, 1, &copy_ds_update);
11426
Chris Forbes8f36a8a2016-04-07 13:21:07 +120011427 m_errorMonitor->VerifyFound();
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060011428
Tobin Ehlis04356f92015-10-27 16:35:27 -060011429 // Now perform a copy update that fails due to binding out of bounds
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011430 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " binding#1 with offset index of 1 plus "
11431 "update array offset of 0 and update of "
11432 "5 descriptors oversteps total number "
11433 "of descriptors in set: 2.");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060011434
Tobin Ehlis04356f92015-10-27 16:35:27 -060011435 memset(&copy_ds_update, 0, sizeof(VkCopyDescriptorSet));
11436 copy_ds_update.sType = VK_STRUCTURE_TYPE_COPY_DESCRIPTOR_SET;
11437 copy_ds_update.srcSet = descriptorSet;
11438 copy_ds_update.srcBinding = 1;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080011439 copy_ds_update.dstSet = descriptorSet;
11440 copy_ds_update.dstBinding = 0;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011441 copy_ds_update.descriptorCount = 5; // ERROR copy 5 descriptors (out of bounds for layout)
Tobin Ehlis04356f92015-10-27 16:35:27 -060011442 vkUpdateDescriptorSets(m_device->device(), 0, NULL, 1, &copy_ds_update);
11443
Chris Forbes8f36a8a2016-04-07 13:21:07 +120011444 m_errorMonitor->VerifyFound();
Tobin Ehlis04356f92015-10-27 16:35:27 -060011445
Chia-I Wuf7458c52015-10-26 21:10:41 +080011446 vkDestroySampler(m_device->device(), sampler, NULL);
11447 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
11448 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis04356f92015-10-27 16:35:27 -060011449}
11450
Karl Schultz6addd812016-02-02 17:17:23 -070011451TEST_F(VkLayerTest, NumSamplesMismatch) {
11452 // Create CommandBuffer where MSAA samples doesn't match RenderPass
11453 // sampleCount
11454 VkResult err;
Tobin Ehlis3b780662015-05-28 12:11:26 -060011455
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011456 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Num samples mismatch! ");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060011457
Tobin Ehlis3b780662015-05-28 12:11:26 -060011458 ASSERT_NO_FATAL_FAILURE(InitState());
11459 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chia-I Wu1b99bb22015-10-27 19:25:11 +080011460 VkDescriptorPoolSize ds_type_count = {};
Tony Barboureb254902015-07-15 12:50:33 -060011461 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Chia-I Wud50a7d72015-10-26 20:48:51 +080011462 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -060011463
11464 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011465 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
11466 ds_pool_ci.pNext = NULL;
11467 ds_pool_ci.maxSets = 1;
11468 ds_pool_ci.poolSizeCount = 1;
11469 ds_pool_ci.pPoolSizes = &ds_type_count;
Courtney Goeltzenleuchterfe908d32015-09-16 16:12:45 -060011470
Tobin Ehlis3b780662015-05-28 12:11:26 -060011471 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011472 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis3b780662015-05-28 12:11:26 -060011473 ASSERT_VK_SUCCESS(err);
Tobin Ehlis3b780662015-05-28 12:11:26 -060011474
Tony Barboureb254902015-07-15 12:50:33 -060011475 VkDescriptorSetLayoutBinding dsl_binding = {};
Chia-I Wud46e6ae2015-10-31 00:31:16 +080011476 dsl_binding.binding = 0;
Tony Barboureb254902015-07-15 12:50:33 -060011477 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Chia-I Wu02124482015-11-06 06:42:02 +080011478 dsl_binding.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -060011479 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
11480 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis3b780662015-05-28 12:11:26 -060011481
Tony Barboureb254902015-07-15 12:50:33 -060011482 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
11483 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
11484 ds_layout_ci.pNext = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +080011485 ds_layout_ci.bindingCount = 1;
Jon Ashburn6e23c1f2015-12-30 18:01:16 -070011486 ds_layout_ci.pBindings = &dsl_binding;
Tony Barboureb254902015-07-15 12:50:33 -060011487
Tobin Ehlis3b780662015-05-28 12:11:26 -060011488 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011489 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis3b780662015-05-28 12:11:26 -060011490 ASSERT_VK_SUCCESS(err);
11491
11492 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080011493 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +080011494 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -070011495 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -060011496 alloc_info.descriptorPool = ds_pool;
11497 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011498 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis3b780662015-05-28 12:11:26 -060011499 ASSERT_VK_SUCCESS(err);
11500
Tony Barboureb254902015-07-15 12:50:33 -060011501 VkPipelineMultisampleStateCreateInfo pipe_ms_state_ci = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011502 pipe_ms_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
Karl Schultz6addd812016-02-02 17:17:23 -070011503 pipe_ms_state_ci.pNext = NULL;
11504 pipe_ms_state_ci.rasterizationSamples = VK_SAMPLE_COUNT_4_BIT;
11505 pipe_ms_state_ci.sampleShadingEnable = 0;
11506 pipe_ms_state_ci.minSampleShading = 1.0;
11507 pipe_ms_state_ci.pSampleMask = NULL;
Tobin Ehlis3b780662015-05-28 12:11:26 -060011508
Tony Barboureb254902015-07-15 12:50:33 -060011509 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011510 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
11511 pipeline_layout_ci.pNext = NULL;
11512 pipeline_layout_ci.setLayoutCount = 1;
11513 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlis3b780662015-05-28 12:11:26 -060011514
11515 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011516 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis3b780662015-05-28 12:11:26 -060011517 ASSERT_VK_SUCCESS(err);
11518
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011519 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
11520 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this); // We shouldn't need a fragment shader
11521 // but add it to be able to run on more devices
Tony Barbour62e1a5b2015-08-06 10:16:07 -060011522 VkPipelineObj pipe(m_device);
11523 pipe.AddShader(&vs);
Tony Barbour1c94d372015-08-06 11:21:08 -060011524 pipe.AddShader(&fs);
Mark Youngc89c6312016-03-31 16:03:20 -060011525 pipe.AddColorAttachment();
Tony Barbour62e1a5b2015-08-06 10:16:07 -060011526 pipe.SetMSAA(&pipe_ms_state_ci);
11527 pipe.CreateVKPipeline(pipeline_layout, renderPass());
Tobin Ehlis3b780662015-05-28 12:11:26 -060011528
Tony Barbourfe3351b2015-07-28 10:17:20 -060011529 BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011530 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Tobin Ehlis3b780662015-05-28 12:11:26 -060011531
Mark Young29927482016-05-04 14:38:51 -060011532 // Render triangle (the error should trigger on the attempt to draw).
11533 Draw(3, 1, 0, 0);
11534
11535 // Finalize recording of the command buffer
11536 EndCommandBuffer();
11537
Chris Forbes8f36a8a2016-04-07 13:21:07 +120011538 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -060011539
Chia-I Wuf7458c52015-10-26 21:10:41 +080011540 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
11541 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
11542 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis49eb23d2015-05-22 12:38:55 -060011543}
Mark Young29927482016-05-04 14:38:51 -060011544
Tobin Ehlis85aa15a2016-06-15 10:52:37 -060011545TEST_F(VkLayerTest, RenderPassIncompatible) {
11546 TEST_DESCRIPTION("Hit RenderPass incompatible cases. "
11547 "Initial case is drawing with an active renderpass that's "
11548 "not compatible with the bound PSO's creation renderpass");
11549 VkResult err;
11550
11551 ASSERT_NO_FATAL_FAILURE(InitState());
11552 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
11553
11554 VkDescriptorSetLayoutBinding dsl_binding = {};
11555 dsl_binding.binding = 0;
11556 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
11557 dsl_binding.descriptorCount = 1;
11558 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
11559 dsl_binding.pImmutableSamplers = NULL;
11560
11561 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
11562 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
11563 ds_layout_ci.pNext = NULL;
11564 ds_layout_ci.bindingCount = 1;
11565 ds_layout_ci.pBindings = &dsl_binding;
11566
11567 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011568 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis85aa15a2016-06-15 10:52:37 -060011569 ASSERT_VK_SUCCESS(err);
11570
11571 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
11572 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
11573 pipeline_layout_ci.pNext = NULL;
11574 pipeline_layout_ci.setLayoutCount = 1;
11575 pipeline_layout_ci.pSetLayouts = &ds_layout;
11576
11577 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011578 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis85aa15a2016-06-15 10:52:37 -060011579 ASSERT_VK_SUCCESS(err);
11580
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011581 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
11582 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this); // We shouldn't need a fragment shader
11583 // but add it to be able to run on more devices
Tobin Ehlis85aa15a2016-06-15 10:52:37 -060011584 // Create a renderpass that will be incompatible with default renderpass
11585 VkAttachmentReference attach = {};
11586 attach.layout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
11587 VkAttachmentReference color_att = {};
11588 color_att.layout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
11589 VkSubpassDescription subpass = {};
11590 subpass.inputAttachmentCount = 1;
11591 subpass.pInputAttachments = &attach;
11592 subpass.colorAttachmentCount = 1;
11593 subpass.pColorAttachments = &color_att;
11594 VkRenderPassCreateInfo rpci = {};
11595 rpci.subpassCount = 1;
11596 rpci.pSubpasses = &subpass;
11597 rpci.attachmentCount = 1;
11598 VkAttachmentDescription attach_desc = {};
11599 attach_desc.samples = VK_SAMPLE_COUNT_1_BIT;
Cody Northropbd16af12016-06-21 09:25:48 -060011600 // Format incompatible with PSO RP color attach format B8G8R8A8_UNORM
11601 attach_desc.format = VK_FORMAT_R8G8B8A8_UNORM;
Tobin Ehlis85aa15a2016-06-15 10:52:37 -060011602 rpci.pAttachments = &attach_desc;
11603 rpci.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
11604 VkRenderPass rp;
11605 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
11606 VkPipelineObj pipe(m_device);
11607 pipe.AddShader(&vs);
11608 pipe.AddShader(&fs);
11609 pipe.AddColorAttachment();
11610 VkViewport view_port = {};
11611 m_viewports.push_back(view_port);
11612 pipe.SetViewport(m_viewports);
11613 VkRect2D rect = {};
11614 m_scissors.push_back(rect);
11615 pipe.SetScissor(m_scissors);
11616 pipe.CreateVKPipeline(pipeline_layout, renderPass());
11617
11618 VkCommandBufferInheritanceInfo cbii = {};
11619 cbii.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_INHERITANCE_INFO;
11620 cbii.renderPass = rp;
11621 cbii.subpass = 0;
11622 VkCommandBufferBeginInfo cbbi = {};
11623 cbbi.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
11624 cbbi.pInheritanceInfo = &cbii;
11625 vkBeginCommandBuffer(m_commandBuffer->handle(), &cbbi);
11626 VkRenderPassBeginInfo rpbi = {};
11627 rpbi.sType = VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO;
11628 rpbi.framebuffer = m_framebuffer;
11629 rpbi.renderPass = rp;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011630 vkCmdBeginRenderPass(m_commandBuffer->GetBufferHandle(), &rpbi, VK_SUBPASS_CONTENTS_INLINE);
11631 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Tobin Ehlis85aa15a2016-06-15 10:52:37 -060011632
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011633 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " is incompatible w/ gfx pipeline ");
Tobin Ehlis85aa15a2016-06-15 10:52:37 -060011634 // Render triangle (the error should trigger on the attempt to draw).
11635 Draw(3, 1, 0, 0);
11636
11637 // Finalize recording of the command buffer
11638 EndCommandBuffer();
11639
11640 m_errorMonitor->VerifyFound();
11641
11642 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
11643 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
11644 vkDestroyRenderPass(m_device->device(), rp, NULL);
11645}
11646
Mark Youngc89c6312016-03-31 16:03:20 -060011647TEST_F(VkLayerTest, NumBlendAttachMismatch) {
11648 // Create Pipeline where the number of blend attachments doesn't match the
11649 // number of color attachments. In this case, we don't add any color
11650 // blend attachments even though we have a color attachment.
11651 VkResult err;
11652
11653 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011654 "Render pass subpass 0 mismatch with blending state defined and blend state attachment");
Mark Youngc89c6312016-03-31 16:03:20 -060011655
11656 ASSERT_NO_FATAL_FAILURE(InitState());
11657 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
11658 VkDescriptorPoolSize ds_type_count = {};
11659 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
11660 ds_type_count.descriptorCount = 1;
11661
11662 VkDescriptorPoolCreateInfo ds_pool_ci = {};
11663 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
11664 ds_pool_ci.pNext = NULL;
11665 ds_pool_ci.maxSets = 1;
11666 ds_pool_ci.poolSizeCount = 1;
11667 ds_pool_ci.pPoolSizes = &ds_type_count;
11668
11669 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011670 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Mark Youngc89c6312016-03-31 16:03:20 -060011671 ASSERT_VK_SUCCESS(err);
11672
11673 VkDescriptorSetLayoutBinding dsl_binding = {};
11674 dsl_binding.binding = 0;
11675 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
11676 dsl_binding.descriptorCount = 1;
11677 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
11678 dsl_binding.pImmutableSamplers = NULL;
11679
11680 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
11681 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
11682 ds_layout_ci.pNext = NULL;
11683 ds_layout_ci.bindingCount = 1;
11684 ds_layout_ci.pBindings = &dsl_binding;
11685
11686 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011687 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Mark Youngc89c6312016-03-31 16:03:20 -060011688 ASSERT_VK_SUCCESS(err);
11689
11690 VkDescriptorSet descriptorSet;
11691 VkDescriptorSetAllocateInfo alloc_info = {};
11692 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
11693 alloc_info.descriptorSetCount = 1;
11694 alloc_info.descriptorPool = ds_pool;
11695 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011696 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Mark Youngc89c6312016-03-31 16:03:20 -060011697 ASSERT_VK_SUCCESS(err);
11698
11699 VkPipelineMultisampleStateCreateInfo pipe_ms_state_ci = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011700 pipe_ms_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
Mark Youngc89c6312016-03-31 16:03:20 -060011701 pipe_ms_state_ci.pNext = NULL;
11702 pipe_ms_state_ci.rasterizationSamples = VK_SAMPLE_COUNT_1_BIT;
11703 pipe_ms_state_ci.sampleShadingEnable = 0;
11704 pipe_ms_state_ci.minSampleShading = 1.0;
11705 pipe_ms_state_ci.pSampleMask = NULL;
11706
11707 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
11708 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
11709 pipeline_layout_ci.pNext = NULL;
11710 pipeline_layout_ci.setLayoutCount = 1;
11711 pipeline_layout_ci.pSetLayouts = &ds_layout;
11712
11713 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011714 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Mark Youngc89c6312016-03-31 16:03:20 -060011715 ASSERT_VK_SUCCESS(err);
11716
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011717 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
11718 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this); // We shouldn't need a fragment shader
11719 // but add it to be able to run on more devices
Mark Youngc89c6312016-03-31 16:03:20 -060011720 VkPipelineObj pipe(m_device);
11721 pipe.AddShader(&vs);
11722 pipe.AddShader(&fs);
11723 pipe.SetMSAA(&pipe_ms_state_ci);
11724 pipe.CreateVKPipeline(pipeline_layout, renderPass());
11725
11726 BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011727 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Mark Youngc89c6312016-03-31 16:03:20 -060011728
Mark Young29927482016-05-04 14:38:51 -060011729 // Render triangle (the error should trigger on the attempt to draw).
11730 Draw(3, 1, 0, 0);
11731
11732 // Finalize recording of the command buffer
11733 EndCommandBuffer();
11734
Chris Forbes8f36a8a2016-04-07 13:21:07 +120011735 m_errorMonitor->VerifyFound();
Mark Youngc89c6312016-03-31 16:03:20 -060011736
11737 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
11738 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
11739 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
11740}
Mark Young29927482016-05-04 14:38:51 -060011741
Mark Muellerd4914412016-06-13 17:52:06 -060011742TEST_F(VkLayerTest, MissingClearAttachment) {
11743 TEST_DESCRIPTION("Points to a wrong colorAttachment index in a VkClearAttachment "
11744 "structure passed to vkCmdClearAttachments");
Cody Northropc31a84f2016-08-22 10:41:47 -060011745 ASSERT_NO_FATAL_FAILURE(InitState());
Chris Forbesda6ae6f2016-09-09 14:36:33 +120011746 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Chris Forbesef5e2842016-09-08 15:25:24 +120011747 "vkCmdClearAttachments() color attachment index 1 out of range for active subpass 0; ignored");
Mark Muellerd4914412016-06-13 17:52:06 -060011748
11749 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailCmdClearAttachments);
11750 m_errorMonitor->VerifyFound();
11751}
11752
Karl Schultz6addd812016-02-02 17:17:23 -070011753TEST_F(VkLayerTest, ClearCmdNoDraw) {
11754 // Create CommandBuffer where we add ClearCmd for FB Color attachment prior
11755 // to issuing a Draw
11756 VkResult err;
Tobin Ehlis53eddda2015-07-01 16:46:13 -060011757
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011758 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
11759 "vkCmdClearAttachments() issued on CB object ");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060011760
Tobin Ehlis53eddda2015-07-01 16:46:13 -060011761 ASSERT_NO_FATAL_FAILURE(InitState());
11762 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barboureb254902015-07-15 12:50:33 -060011763
Chia-I Wu1b99bb22015-10-27 19:25:11 +080011764 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011765 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
11766 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -060011767
11768 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011769 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
11770 ds_pool_ci.pNext = NULL;
11771 ds_pool_ci.maxSets = 1;
11772 ds_pool_ci.poolSizeCount = 1;
11773 ds_pool_ci.pPoolSizes = &ds_type_count;
Tony Barboureb254902015-07-15 12:50:33 -060011774
Tobin Ehlis53eddda2015-07-01 16:46:13 -060011775 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011776 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis53eddda2015-07-01 16:46:13 -060011777 ASSERT_VK_SUCCESS(err);
11778
Tony Barboureb254902015-07-15 12:50:33 -060011779 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011780 dsl_binding.binding = 0;
11781 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
11782 dsl_binding.descriptorCount = 1;
11783 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
11784 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis53eddda2015-07-01 16:46:13 -060011785
Tony Barboureb254902015-07-15 12:50:33 -060011786 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011787 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
11788 ds_layout_ci.pNext = NULL;
11789 ds_layout_ci.bindingCount = 1;
11790 ds_layout_ci.pBindings = &dsl_binding;
Mark Lobodzinski209b5292015-09-17 09:44:05 -060011791
Tobin Ehlis53eddda2015-07-01 16:46:13 -060011792 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011793 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis53eddda2015-07-01 16:46:13 -060011794 ASSERT_VK_SUCCESS(err);
11795
11796 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080011797 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +080011798 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -070011799 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -060011800 alloc_info.descriptorPool = ds_pool;
11801 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011802 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis53eddda2015-07-01 16:46:13 -060011803 ASSERT_VK_SUCCESS(err);
11804
Tony Barboureb254902015-07-15 12:50:33 -060011805 VkPipelineMultisampleStateCreateInfo pipe_ms_state_ci = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011806 pipe_ms_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
Karl Schultz6addd812016-02-02 17:17:23 -070011807 pipe_ms_state_ci.pNext = NULL;
11808 pipe_ms_state_ci.rasterizationSamples = VK_SAMPLE_COUNT_4_BIT;
11809 pipe_ms_state_ci.sampleShadingEnable = 0;
11810 pipe_ms_state_ci.minSampleShading = 1.0;
11811 pipe_ms_state_ci.pSampleMask = NULL;
Tobin Ehlis53eddda2015-07-01 16:46:13 -060011812
Tony Barboureb254902015-07-15 12:50:33 -060011813 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011814 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
11815 pipeline_layout_ci.pNext = NULL;
11816 pipeline_layout_ci.setLayoutCount = 1;
11817 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlis53eddda2015-07-01 16:46:13 -060011818
11819 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011820 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis53eddda2015-07-01 16:46:13 -060011821 ASSERT_VK_SUCCESS(err);
Mark Lobodzinski209b5292015-09-17 09:44:05 -060011822
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011823 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
Karl Schultzbdb75952016-04-19 11:36:49 -060011824 // We shouldn't need a fragment shader but add it to be able to run
Karl Schultz6addd812016-02-02 17:17:23 -070011825 // on more devices
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011826 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060011827
Tony Barbour62e1a5b2015-08-06 10:16:07 -060011828 VkPipelineObj pipe(m_device);
11829 pipe.AddShader(&vs);
Tony Barbour1c94d372015-08-06 11:21:08 -060011830 pipe.AddShader(&fs);
Tony Barbour62e1a5b2015-08-06 10:16:07 -060011831 pipe.SetMSAA(&pipe_ms_state_ci);
11832 pipe.CreateVKPipeline(pipeline_layout, renderPass());
Tony Barbourfe3351b2015-07-28 10:17:20 -060011833
11834 BeginCommandBuffer();
Tobin Ehlis53eddda2015-07-01 16:46:13 -060011835
Karl Schultz6addd812016-02-02 17:17:23 -070011836 // Main thing we care about for this test is that the VkImage obj we're
11837 // clearing matches Color Attachment of FB
Tobin Ehlis53eddda2015-07-01 16:46:13 -060011838 // Also pass down other dummy params to keep driver and paramchecker happy
Courtney Goeltzenleuchterc9323e02015-10-15 16:51:05 -060011839 VkClearAttachment color_attachment;
11840 color_attachment.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
11841 color_attachment.clearValue.color.float32[0] = 1.0;
11842 color_attachment.clearValue.color.float32[1] = 1.0;
11843 color_attachment.clearValue.color.float32[2] = 1.0;
11844 color_attachment.clearValue.color.float32[3] = 1.0;
11845 color_attachment.colorAttachment = 0;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011846 VkClearRect clear_rect = {{{0, 0}, {(uint32_t)m_width, (uint32_t)m_height}}};
Tobin Ehlis53eddda2015-07-01 16:46:13 -060011847
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011848 vkCmdClearAttachments(m_commandBuffer->GetBufferHandle(), 1, &color_attachment, 1, &clear_rect);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060011849
Chris Forbes8f36a8a2016-04-07 13:21:07 +120011850 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -060011851
Chia-I Wuf7458c52015-10-26 21:10:41 +080011852 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
11853 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
11854 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis53eddda2015-07-01 16:46:13 -060011855}
11856
Karl Schultz6addd812016-02-02 17:17:23 -070011857TEST_F(VkLayerTest, VtxBufferBadIndex) {
11858 VkResult err;
Tobin Ehlis502480b2015-06-24 15:53:07 -060011859
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011860 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
11861 "but no vertex buffers are attached to this Pipeline State Object");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060011862
Tobin Ehlis502480b2015-06-24 15:53:07 -060011863 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisd332f282015-10-02 11:00:56 -060011864 ASSERT_NO_FATAL_FAILURE(InitViewport());
Tobin Ehlis502480b2015-06-24 15:53:07 -060011865 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barboureb254902015-07-15 12:50:33 -060011866
Chia-I Wu1b99bb22015-10-27 19:25:11 +080011867 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011868 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
11869 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -060011870
11871 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011872 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
11873 ds_pool_ci.pNext = NULL;
11874 ds_pool_ci.maxSets = 1;
11875 ds_pool_ci.poolSizeCount = 1;
11876 ds_pool_ci.pPoolSizes = &ds_type_count;
Tony Barboureb254902015-07-15 12:50:33 -060011877
Courtney Goeltzenleuchterfe908d32015-09-16 16:12:45 -060011878 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011879 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis502480b2015-06-24 15:53:07 -060011880 ASSERT_VK_SUCCESS(err);
11881
Tony Barboureb254902015-07-15 12:50:33 -060011882 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011883 dsl_binding.binding = 0;
11884 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
11885 dsl_binding.descriptorCount = 1;
11886 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
11887 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis502480b2015-06-24 15:53:07 -060011888
Tony Barboureb254902015-07-15 12:50:33 -060011889 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011890 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
11891 ds_layout_ci.pNext = NULL;
11892 ds_layout_ci.bindingCount = 1;
11893 ds_layout_ci.pBindings = &dsl_binding;
Tony Barboureb254902015-07-15 12:50:33 -060011894
Tobin Ehlis502480b2015-06-24 15:53:07 -060011895 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011896 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis502480b2015-06-24 15:53:07 -060011897 ASSERT_VK_SUCCESS(err);
11898
11899 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080011900 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +080011901 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -070011902 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -060011903 alloc_info.descriptorPool = ds_pool;
11904 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011905 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis502480b2015-06-24 15:53:07 -060011906 ASSERT_VK_SUCCESS(err);
11907
Tony Barboureb254902015-07-15 12:50:33 -060011908 VkPipelineMultisampleStateCreateInfo pipe_ms_state_ci = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011909 pipe_ms_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
Karl Schultz6addd812016-02-02 17:17:23 -070011910 pipe_ms_state_ci.pNext = NULL;
11911 pipe_ms_state_ci.rasterizationSamples = VK_SAMPLE_COUNT_1_BIT;
11912 pipe_ms_state_ci.sampleShadingEnable = 0;
11913 pipe_ms_state_ci.minSampleShading = 1.0;
11914 pipe_ms_state_ci.pSampleMask = NULL;
Tobin Ehlis502480b2015-06-24 15:53:07 -060011915
Tony Barboureb254902015-07-15 12:50:33 -060011916 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011917 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
11918 pipeline_layout_ci.pNext = NULL;
11919 pipeline_layout_ci.setLayoutCount = 1;
11920 pipeline_layout_ci.pSetLayouts = &ds_layout;
11921 VkPipelineLayout pipeline_layout;
Tobin Ehlis502480b2015-06-24 15:53:07 -060011922
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011923 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis502480b2015-06-24 15:53:07 -060011924 ASSERT_VK_SUCCESS(err);
11925
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011926 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
11927 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this); // We shouldn't need a fragment shader
11928 // but add it to be able to run on more devices
Tony Barbour62e1a5b2015-08-06 10:16:07 -060011929 VkPipelineObj pipe(m_device);
11930 pipe.AddShader(&vs);
Tony Barbour1c94d372015-08-06 11:21:08 -060011931 pipe.AddShader(&fs);
Mark Youngc89c6312016-03-31 16:03:20 -060011932 pipe.AddColorAttachment();
Tony Barbour62e1a5b2015-08-06 10:16:07 -060011933 pipe.SetMSAA(&pipe_ms_state_ci);
Tobin Ehlisd332f282015-10-02 11:00:56 -060011934 pipe.SetViewport(m_viewports);
11935 pipe.SetScissor(m_scissors);
Tony Barbour62e1a5b2015-08-06 10:16:07 -060011936 pipe.CreateVKPipeline(pipeline_layout, renderPass());
Tony Barbourfe3351b2015-07-28 10:17:20 -060011937
11938 BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011939 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Tobin Ehlisf7bf4502015-09-09 15:12:35 -060011940 // Don't care about actual data, just need to get to draw to flag error
11941 static const float vbo_data[3] = {1.f, 0.f, 1.f};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011942 VkConstantBufferObj vbo(m_device, sizeof(vbo_data), sizeof(float), (const void *)&vbo_data);
Tobin Ehlisf7bf4502015-09-09 15:12:35 -060011943 BindVertexBuffer(&vbo, (VkDeviceSize)0, 1); // VBO idx 1, but no VBO in PSO
Courtney Goeltzenleuchter08c26372015-09-23 12:31:50 -060011944 Draw(1, 0, 0, 0);
Tobin Ehlis502480b2015-06-24 15:53:07 -060011945
Chris Forbes8f36a8a2016-04-07 13:21:07 +120011946 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -060011947
Chia-I Wuf7458c52015-10-26 21:10:41 +080011948 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
11949 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
11950 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis502480b2015-06-24 15:53:07 -060011951}
Mark Muellerdfe37552016-07-07 14:47:42 -060011952
Mark Mueller2ee294f2016-08-04 12:59:48 -060011953TEST_F(VkLayerTest, MismatchCountQueueCreateRequestedFeature) {
11954 TEST_DESCRIPTION("Use an invalid count in a vkEnumeratePhysicalDevices call."
11955 "Use invalid Queue Family Index in vkCreateDevice");
Cody Northropc31a84f2016-08-22 10:41:47 -060011956 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Mueller2ee294f2016-08-04 12:59:48 -060011957
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011958 const char *mismatch_count_message = "Call to vkEnumeratePhysicalDevices() "
11959 "w/ pPhysicalDeviceCount value ";
Mark Mueller2ee294f2016-08-04 12:59:48 -060011960
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011961 const char *invalid_queueFamilyIndex_message = "Invalid queue create request in vkCreateDevice(). Invalid "
11962 "queueFamilyIndex ";
Mark Mueller2ee294f2016-08-04 12:59:48 -060011963
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011964 const char *unavailable_feature_message = "While calling vkCreateDevice(), requesting feature #";
Mark Mueller2ee294f2016-08-04 12:59:48 -060011965
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011966 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT, mismatch_count_message);
Mark Mueller880fce52016-08-17 15:23:23 -060011967 // The following test fails with recent NVidia drivers.
11968 // By the time core_validation is reached, the NVidia
11969 // driver has sanitized the invalid condition and core_validation
11970 // is not introduced to the failure condition. This is not the case
11971 // with AMD and Mesa drivers. Futher investigation is required
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011972 // uint32_t count = static_cast<uint32_t>(~0);
11973 // VkPhysicalDevice physical_device;
11974 // vkEnumeratePhysicalDevices(instance(), &count, &physical_device);
11975 // m_errorMonitor->VerifyFound();
Mark Mueller2ee294f2016-08-04 12:59:48 -060011976
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011977 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, invalid_queueFamilyIndex_message);
Mark Mueller2ee294f2016-08-04 12:59:48 -060011978 float queue_priority = 0.0;
11979
11980 VkDeviceQueueCreateInfo queue_create_info = {};
11981 queue_create_info.sType = VK_STRUCTURE_TYPE_DEVICE_QUEUE_CREATE_INFO;
11982 queue_create_info.queueCount = 1;
11983 queue_create_info.pQueuePriorities = &queue_priority;
11984 queue_create_info.queueFamilyIndex = static_cast<uint32_t>(~0);
11985
11986 VkPhysicalDeviceFeatures features = m_device->phy().features();
11987 VkDevice testDevice;
11988 VkDeviceCreateInfo device_create_info = {};
11989 device_create_info.sType = VK_STRUCTURE_TYPE_DEVICE_CREATE_INFO;
11990 device_create_info.queueCreateInfoCount = 1;
11991 device_create_info.pQueueCreateInfos = &queue_create_info;
11992 device_create_info.pEnabledFeatures = &features;
11993 vkCreateDevice(gpu(), &device_create_info, nullptr, &testDevice);
11994 m_errorMonitor->VerifyFound();
11995
11996 queue_create_info.queueFamilyIndex = 1;
11997
11998 unsigned feature_count = sizeof(VkPhysicalDeviceFeatures) / sizeof(VkBool32);
11999 VkBool32 *feature_array = reinterpret_cast<VkBool32 *>(&features);
12000 for (unsigned i = 0; i < feature_count; i++) {
12001 if (VK_FALSE == feature_array[i]) {
12002 feature_array[i] = VK_TRUE;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012003 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, unavailable_feature_message);
Mark Mueller2ee294f2016-08-04 12:59:48 -060012004 device_create_info.pEnabledFeatures = &features;
12005 vkCreateDevice(gpu(), &device_create_info, nullptr, &testDevice);
12006 m_errorMonitor->VerifyFound();
12007 break;
12008 }
12009 }
12010}
12011
12012TEST_F(VkLayerTest, InvalidQueueIndexInvalidQuery) {
12013 TEST_DESCRIPTION("Use an invalid queue index in a vkCmdWaitEvents call."
12014 "End a command buffer with a query still in progress.");
12015
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012016 const char *invalid_queue_index = "was created with sharingMode of VK_SHARING_MODE_EXCLUSIVE. If one "
12017 "of src- or dstQueueFamilyIndex is VK_QUEUE_FAMILY_IGNORED, both "
12018 "must be.";
Mark Mueller2ee294f2016-08-04 12:59:48 -060012019
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012020 const char *invalid_query = "Ending command buffer with in progress query: queryPool 0x";
Mark Mueller2ee294f2016-08-04 12:59:48 -060012021
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012022 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, invalid_queue_index);
Mark Mueller2ee294f2016-08-04 12:59:48 -060012023
12024 ASSERT_NO_FATAL_FAILURE(InitState());
12025
12026 VkEvent event;
12027 VkEventCreateInfo event_create_info{};
12028 event_create_info.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO;
12029 vkCreateEvent(m_device->device(), &event_create_info, nullptr, &event);
12030
Mark Mueller2ee294f2016-08-04 12:59:48 -060012031 VkQueue queue = VK_NULL_HANDLE;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012032 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 0, &queue);
Mark Mueller2ee294f2016-08-04 12:59:48 -060012033
12034 BeginCommandBuffer();
12035
12036 VkImageObj image(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012037 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 -060012038 ASSERT_TRUE(image.initialized());
12039 VkImageMemoryBarrier img_barrier = {};
12040 img_barrier.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
12041 img_barrier.pNext = NULL;
12042 img_barrier.srcAccessMask = VK_ACCESS_HOST_WRITE_BIT;
12043 img_barrier.dstAccessMask = VK_ACCESS_SHADER_READ_BIT;
12044 img_barrier.oldLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
12045 img_barrier.newLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
12046 img_barrier.image = image.handle();
12047 img_barrier.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
Mark Lobodzinski2a74c5c2016-08-17 13:26:28 -060012048
12049 // QueueFamilyIndex must be VK_QUEUE_FAMILY_IGNORED, this verifies
12050 // that layer validation catches the case when it is not.
12051 img_barrier.dstQueueFamilyIndex = 0;
Mark Mueller2ee294f2016-08-04 12:59:48 -060012052 img_barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
12053 img_barrier.subresourceRange.baseArrayLayer = 0;
12054 img_barrier.subresourceRange.baseMipLevel = 0;
12055 img_barrier.subresourceRange.layerCount = 1;
12056 img_barrier.subresourceRange.levelCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012057 vkCmdWaitEvents(m_commandBuffer->handle(), 1, &event, VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0,
12058 nullptr, 0, nullptr, 1, &img_barrier);
Mark Mueller2ee294f2016-08-04 12:59:48 -060012059 m_errorMonitor->VerifyFound();
12060
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012061 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, invalid_query);
Mark Mueller2ee294f2016-08-04 12:59:48 -060012062
12063 VkQueryPool query_pool;
12064 VkQueryPoolCreateInfo query_pool_create_info = {};
12065 query_pool_create_info.sType = VK_STRUCTURE_TYPE_QUERY_POOL_CREATE_INFO;
12066 query_pool_create_info.queryType = VK_QUERY_TYPE_OCCLUSION;
12067 query_pool_create_info.queryCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012068 vkCreateQueryPool(m_device->device(), &query_pool_create_info, nullptr, &query_pool);
Mark Mueller2ee294f2016-08-04 12:59:48 -060012069
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012070 vkCmdResetQueryPool(m_commandBuffer->handle(), query_pool, 0 /*startQuery*/, 1 /*queryCount*/);
Mark Mueller2ee294f2016-08-04 12:59:48 -060012071 vkCmdBeginQuery(m_commandBuffer->handle(), query_pool, 0, 0);
12072
12073 vkEndCommandBuffer(m_commandBuffer->handle());
12074 m_errorMonitor->VerifyFound();
12075
12076 vkDestroyQueryPool(m_device->device(), query_pool, nullptr);
12077 vkDestroyEvent(m_device->device(), event, nullptr);
12078}
12079
Mark Muellerdfe37552016-07-07 14:47:42 -060012080TEST_F(VkLayerTest, VertexBufferInvalid) {
12081 TEST_DESCRIPTION("Submit a command buffer using deleted vertex buffer, "
12082 "delete a buffer twice, use an invalid offset for each "
12083 "buffer type, and attempt to bind a null buffer");
12084
12085 const char *deleted_buffer_in_command_buffer = "Cannot submit cmd buffer "
12086 "using deleted buffer ";
12087 const char *double_destroy_message = "Cannot free buffer 0x";
12088 const char *invalid_offset_message = "vkBindBufferMemory(): "
12089 "memoryOffset is 0x";
12090 const char *invalid_storage_buffer_offset_message = "vkBindBufferMemory(): "
12091 "storage memoryOffset "
12092 "is 0x";
12093 const char *invalid_texel_buffer_offset_message = "vkBindBufferMemory(): "
12094 "texel memoryOffset "
12095 "is 0x";
12096 const char *invalid_uniform_buffer_offset_message = "vkBindBufferMemory(): "
12097 "uniform memoryOffset "
12098 "is 0x";
12099 const char *bind_null_buffer_message = "In vkBindBufferMemory, attempting"
12100 " to Bind Obj(0x";
12101 const char *free_invalid_buffer_message = "Request to delete memory "
12102 "object 0x";
12103
12104 ASSERT_NO_FATAL_FAILURE(InitState());
12105 ASSERT_NO_FATAL_FAILURE(InitViewport());
12106 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12107
12108 VkPipelineMultisampleStateCreateInfo pipe_ms_state_ci = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012109 pipe_ms_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
Mark Muellerdfe37552016-07-07 14:47:42 -060012110 pipe_ms_state_ci.pNext = NULL;
12111 pipe_ms_state_ci.rasterizationSamples = VK_SAMPLE_COUNT_1_BIT;
12112 pipe_ms_state_ci.sampleShadingEnable = 0;
12113 pipe_ms_state_ci.minSampleShading = 1.0;
12114 pipe_ms_state_ci.pSampleMask = nullptr;
12115
12116 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
12117 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
12118 VkPipelineLayout pipeline_layout;
12119
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012120 VkResult err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, nullptr, &pipeline_layout);
Mark Muellerdfe37552016-07-07 14:47:42 -060012121 ASSERT_VK_SUCCESS(err);
12122
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012123 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
12124 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Mark Muellerdfe37552016-07-07 14:47:42 -060012125 VkPipelineObj pipe(m_device);
12126 pipe.AddShader(&vs);
12127 pipe.AddShader(&fs);
12128 pipe.AddColorAttachment();
12129 pipe.SetMSAA(&pipe_ms_state_ci);
12130 pipe.SetViewport(m_viewports);
12131 pipe.SetScissor(m_scissors);
12132 pipe.CreateVKPipeline(pipeline_layout, renderPass());
12133
12134 BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012135 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Mark Muellerdfe37552016-07-07 14:47:42 -060012136
12137 {
12138 // Create and bind a vertex buffer in a reduced scope, which will cause
12139 // it to be deleted upon leaving this scope
12140 const float vbo_data[3] = {1.f, 0.f, 1.f};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012141 VkVerticesObj draw_verticies(m_device, 1, 1, sizeof(vbo_data), 3, vbo_data);
Mark Muellerdfe37552016-07-07 14:47:42 -060012142 draw_verticies.BindVertexBuffers(m_commandBuffer->handle());
12143 draw_verticies.AddVertexInputToPipe(pipe);
12144 }
12145
12146 Draw(1, 0, 0, 0);
12147
12148 EndCommandBuffer();
12149
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012150 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, deleted_buffer_in_command_buffer);
Mark Muellerdfe37552016-07-07 14:47:42 -060012151 QueueCommandBuffer(false);
12152 m_errorMonitor->VerifyFound();
12153
12154 {
12155 // Create and bind a vertex buffer in a reduced scope, and delete it
12156 // twice, the second through the destructor
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012157 VkBufferTest buffer_test(m_device, VK_BUFFER_USAGE_STORAGE_BUFFER_BIT, VkBufferTest::eDoubleDelete);
12158 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, double_destroy_message);
Mark Muellerdfe37552016-07-07 14:47:42 -060012159 buffer_test.TestDoubleDestroy();
12160 }
12161 m_errorMonitor->VerifyFound();
12162
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012163 if (VkBufferTest::GetTestConditionValid(m_device, VkBufferTest::eInvalidMemoryOffset)) {
Mark Muellerdfe37552016-07-07 14:47:42 -060012164 // Create and bind a memory buffer with an invalid offset.
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012165 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, invalid_offset_message);
12166 VkBufferTest buffer_test(m_device, VK_BUFFER_USAGE_UNIFORM_TEXEL_BUFFER_BIT, VkBufferTest::eInvalidMemoryOffset);
12167 (void)buffer_test;
Mark Muellerdfe37552016-07-07 14:47:42 -060012168 m_errorMonitor->VerifyFound();
12169 }
12170
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012171 if (VkBufferTest::GetTestConditionValid(m_device, VkBufferTest::eInvalidDeviceOffset,
12172 VK_BUFFER_USAGE_UNIFORM_TEXEL_BUFFER_BIT)) {
Mark Muellerdfe37552016-07-07 14:47:42 -060012173 // Create and bind a memory buffer with an invalid offset again,
12174 // but look for a texel buffer message.
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012175 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, invalid_texel_buffer_offset_message);
12176 VkBufferTest buffer_test(m_device, VK_BUFFER_USAGE_UNIFORM_TEXEL_BUFFER_BIT, VkBufferTest::eInvalidDeviceOffset);
12177 (void)buffer_test;
Mark Muellerdfe37552016-07-07 14:47:42 -060012178 m_errorMonitor->VerifyFound();
12179 }
12180
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012181 if (VkBufferTest::GetTestConditionValid(m_device, VkBufferTest::eInvalidDeviceOffset, VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT)) {
Mark Muellerdfe37552016-07-07 14:47:42 -060012182 // Create and bind a memory buffer with an invalid offset again, but
12183 // look for a uniform buffer message.
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012184 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, invalid_uniform_buffer_offset_message);
12185 VkBufferTest buffer_test(m_device, VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT, VkBufferTest::eInvalidDeviceOffset);
12186 (void)buffer_test;
Mark Muellerdfe37552016-07-07 14:47:42 -060012187 m_errorMonitor->VerifyFound();
12188 }
12189
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012190 if (VkBufferTest::GetTestConditionValid(m_device, VkBufferTest::eInvalidDeviceOffset, VK_BUFFER_USAGE_STORAGE_BUFFER_BIT)) {
Mark Muellerdfe37552016-07-07 14:47:42 -060012191 // Create and bind a memory buffer with an invalid offset again, but
12192 // look for a storage buffer message.
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012193 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, invalid_storage_buffer_offset_message);
12194 VkBufferTest buffer_test(m_device, VK_BUFFER_USAGE_STORAGE_BUFFER_BIT, VkBufferTest::eInvalidDeviceOffset);
12195 (void)buffer_test;
Mark Muellerdfe37552016-07-07 14:47:42 -060012196 m_errorMonitor->VerifyFound();
12197 }
12198
12199 {
12200 // Attempt to bind a null buffer.
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012201 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, bind_null_buffer_message);
12202 VkBufferTest buffer_test(m_device, VK_BUFFER_USAGE_STORAGE_BUFFER_BIT, VkBufferTest::eBindNullBuffer);
12203 (void)buffer_test;
Mark Muellerdfe37552016-07-07 14:47:42 -060012204 m_errorMonitor->VerifyFound();
12205 }
12206
12207 {
12208 // Attempt to use an invalid handle to delete a buffer.
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012209 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, free_invalid_buffer_message);
12210 VkBufferTest buffer_test(m_device, VK_BUFFER_USAGE_STORAGE_BUFFER_BIT, VkBufferTest::eFreeInvalidHandle);
12211 (void)buffer_test;
Mark Muellerdfe37552016-07-07 14:47:42 -060012212 }
12213 m_errorMonitor->VerifyFound();
12214
12215 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
12216}
12217
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060012218// INVALID_IMAGE_LAYOUT tests (one other case is hit by MapMemWithoutHostVisibleBit and not here)
12219TEST_F(VkLayerTest, InvalidImageLayout) {
12220 TEST_DESCRIPTION("Hit all possible validation checks associated with the "
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012221 "DRAWSTATE_INVALID_IMAGE_LAYOUT enum. Generally these involve having"
12222 "images in the wrong layout when they're copied or transitioned.");
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060012223 // 3 in ValidateCmdBufImageLayouts
12224 // * -1 Attempt to submit cmd buf w/ deleted image
12225 // * -2 Cmd buf submit of image w/ layout not matching first use w/ subresource
12226 // * -3 Cmd buf submit of image w/ layout not matching first use w/o subresource
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012227 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
12228 "Layout for input image should be TRANSFER_SRC_OPTIMAL instead of GENERAL.");
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060012229
12230 ASSERT_NO_FATAL_FAILURE(InitState());
12231 // Create src & dst images to use for copy operations
12232 VkImage src_image;
12233 VkImage dst_image;
12234
12235 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
12236 const int32_t tex_width = 32;
12237 const int32_t tex_height = 32;
12238
12239 VkImageCreateInfo image_create_info = {};
12240 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
12241 image_create_info.pNext = NULL;
12242 image_create_info.imageType = VK_IMAGE_TYPE_2D;
12243 image_create_info.format = tex_format;
12244 image_create_info.extent.width = tex_width;
12245 image_create_info.extent.height = tex_height;
12246 image_create_info.extent.depth = 1;
12247 image_create_info.mipLevels = 1;
12248 image_create_info.arrayLayers = 4;
12249 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
12250 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
12251 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
12252 image_create_info.flags = 0;
12253
12254 VkResult err = vkCreateImage(m_device->device(), &image_create_info, NULL, &src_image);
12255 ASSERT_VK_SUCCESS(err);
12256 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &dst_image);
12257 ASSERT_VK_SUCCESS(err);
12258
12259 BeginCommandBuffer();
12260 VkImageCopy copyRegion;
12261 copyRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
12262 copyRegion.srcSubresource.mipLevel = 0;
12263 copyRegion.srcSubresource.baseArrayLayer = 0;
12264 copyRegion.srcSubresource.layerCount = 1;
12265 copyRegion.srcOffset.x = 0;
12266 copyRegion.srcOffset.y = 0;
12267 copyRegion.srcOffset.z = 0;
12268 copyRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
12269 copyRegion.dstSubresource.mipLevel = 0;
12270 copyRegion.dstSubresource.baseArrayLayer = 0;
12271 copyRegion.dstSubresource.layerCount = 1;
12272 copyRegion.dstOffset.x = 0;
12273 copyRegion.dstOffset.y = 0;
12274 copyRegion.dstOffset.z = 0;
12275 copyRegion.extent.width = 1;
12276 copyRegion.extent.height = 1;
12277 copyRegion.extent.depth = 1;
12278 m_commandBuffer->CopyImage(src_image, VK_IMAGE_LAYOUT_GENERAL, dst_image, VK_IMAGE_LAYOUT_GENERAL, 1, &copyRegion);
12279 m_errorMonitor->VerifyFound();
12280 // Now cause error due to src image layout changing
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012281 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Cannot copy from an image whose source layout is "
12282 "VK_IMAGE_LAYOUT_UNDEFINED and doesn't match the current "
12283 "layout VK_IMAGE_LAYOUT_GENERAL.");
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060012284 m_commandBuffer->CopyImage(src_image, VK_IMAGE_LAYOUT_UNDEFINED, dst_image, VK_IMAGE_LAYOUT_GENERAL, 1, &copyRegion);
12285 m_errorMonitor->VerifyFound();
12286 // Final src error is due to bad layout type
12287 m_errorMonitor->SetDesiredFailureMsg(
12288 VK_DEBUG_REPORT_ERROR_BIT_EXT,
12289 "Layout for input image is VK_IMAGE_LAYOUT_UNDEFINED but can only be TRANSFER_SRC_OPTIMAL or GENERAL.");
12290 m_commandBuffer->CopyImage(src_image, VK_IMAGE_LAYOUT_UNDEFINED, dst_image, VK_IMAGE_LAYOUT_GENERAL, 1, &copyRegion);
12291 m_errorMonitor->VerifyFound();
12292 // Now verify same checks for dst
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012293 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
12294 "Layout for output image should be TRANSFER_DST_OPTIMAL instead of GENERAL.");
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060012295 m_commandBuffer->CopyImage(src_image, VK_IMAGE_LAYOUT_GENERAL, dst_image, VK_IMAGE_LAYOUT_GENERAL, 1, &copyRegion);
12296 m_errorMonitor->VerifyFound();
12297 // Now cause error due to src image layout changing
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012298 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Cannot copy from an image whose dest layout is "
12299 "VK_IMAGE_LAYOUT_UNDEFINED and doesn't match the current "
12300 "layout VK_IMAGE_LAYOUT_GENERAL.");
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060012301 m_commandBuffer->CopyImage(src_image, VK_IMAGE_LAYOUT_GENERAL, dst_image, VK_IMAGE_LAYOUT_UNDEFINED, 1, &copyRegion);
12302 m_errorMonitor->VerifyFound();
12303 m_errorMonitor->SetDesiredFailureMsg(
12304 VK_DEBUG_REPORT_ERROR_BIT_EXT,
12305 "Layout for output image is VK_IMAGE_LAYOUT_UNDEFINED but can only be TRANSFER_DST_OPTIMAL or GENERAL.");
12306 m_commandBuffer->CopyImage(src_image, VK_IMAGE_LAYOUT_GENERAL, dst_image, VK_IMAGE_LAYOUT_UNDEFINED, 1, &copyRegion);
12307 m_errorMonitor->VerifyFound();
12308 // Now cause error due to bad image layout transition in PipelineBarrier
12309 VkImageMemoryBarrier image_barrier[1] = {};
12310 image_barrier[0].oldLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL;
12311 image_barrier[0].image = src_image;
12312 image_barrier[0].subresourceRange.layerCount = 2;
12313 image_barrier[0].subresourceRange.levelCount = 2;
12314 image_barrier[0].subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012315 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "You cannot transition the layout from "
12316 "VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL when "
12317 "current layout is VK_IMAGE_LAYOUT_GENERAL.");
12318 vkCmdPipelineBarrier(m_commandBuffer->handle(), VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0,
12319 NULL, 0, NULL, 1, image_barrier);
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060012320 m_errorMonitor->VerifyFound();
12321
12322 // Finally some layout errors at RenderPass create time
12323 // Just hacking in specific state to get to the errors we want so don't copy this unless you know what you're doing.
12324 VkAttachmentReference attach = {};
12325 // perf warning for GENERAL layout w/ non-DS input attachment
12326 attach.layout = VK_IMAGE_LAYOUT_GENERAL;
12327 VkSubpassDescription subpass = {};
12328 subpass.inputAttachmentCount = 1;
12329 subpass.pInputAttachments = &attach;
12330 VkRenderPassCreateInfo rpci = {};
12331 rpci.subpassCount = 1;
12332 rpci.pSubpasses = &subpass;
12333 rpci.attachmentCount = 1;
12334 VkAttachmentDescription attach_desc = {};
12335 attach_desc.format = VK_FORMAT_UNDEFINED;
12336 rpci.pAttachments = &attach_desc;
Tobin Ehlis1efce022016-05-11 10:40:34 -060012337 rpci.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060012338 VkRenderPass rp;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012339 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
12340 "Layout for input attachment is GENERAL but should be READ_ONLY_OPTIMAL.");
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060012341 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
12342 m_errorMonitor->VerifyFound();
12343 // error w/ non-general layout
12344 attach.layout = VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL;
12345
12346 m_errorMonitor->SetDesiredFailureMsg(
12347 VK_DEBUG_REPORT_ERROR_BIT_EXT,
12348 "Layout for input attachment is VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL but can only be READ_ONLY_OPTIMAL or GENERAL.");
12349 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
12350 m_errorMonitor->VerifyFound();
12351 subpass.inputAttachmentCount = 0;
12352 subpass.colorAttachmentCount = 1;
12353 subpass.pColorAttachments = &attach;
12354 attach.layout = VK_IMAGE_LAYOUT_GENERAL;
12355 // perf warning for GENERAL layout on color attachment
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012356 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
12357 "Layout for color attachment is GENERAL but should be COLOR_ATTACHMENT_OPTIMAL.");
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060012358 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
12359 m_errorMonitor->VerifyFound();
12360 // error w/ non-color opt or GENERAL layout for color attachment
12361 attach.layout = VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL;
12362 m_errorMonitor->SetDesiredFailureMsg(
12363 VK_DEBUG_REPORT_ERROR_BIT_EXT,
12364 "Layout for color attachment is VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL but can only be COLOR_ATTACHMENT_OPTIMAL or GENERAL.");
12365 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
12366 m_errorMonitor->VerifyFound();
12367 subpass.colorAttachmentCount = 0;
12368 subpass.pDepthStencilAttachment = &attach;
12369 attach.layout = VK_IMAGE_LAYOUT_GENERAL;
12370 // perf warning for GENERAL layout on DS attachment
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012371 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
12372 "GENERAL layout for depth attachment may not give optimal performance.");
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060012373 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
12374 m_errorMonitor->VerifyFound();
12375 // error w/ non-ds opt or GENERAL layout for color attachment
12376 attach.layout = VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012377 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
12378 "Layout for depth attachment is VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL but can only be "
12379 "DEPTH_STENCIL_ATTACHMENT_OPTIMAL, DEPTH_STENCIL_READ_ONLY_OPTIMAL or GENERAL.");
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060012380 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
12381 m_errorMonitor->VerifyFound();
Tobin Ehlis1efce022016-05-11 10:40:34 -060012382 // For this error we need a valid renderpass so create default one
12383 attach.layout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL;
12384 attach.attachment = 0;
12385 attach_desc.format = VK_FORMAT_D24_UNORM_S8_UINT;
12386 attach_desc.samples = VK_SAMPLE_COUNT_1_BIT;
12387 attach_desc.storeOp = VK_ATTACHMENT_STORE_OP_STORE;
12388 attach_desc.stencilLoadOp = VK_ATTACHMENT_LOAD_OP_DONT_CARE;
12389 attach_desc.stencilStoreOp = VK_ATTACHMENT_STORE_OP_DONT_CARE;
12390 // Can't do a CLEAR load on READ_ONLY initialLayout
12391 attach_desc.loadOp = VK_ATTACHMENT_LOAD_OP_CLEAR;
12392 attach_desc.initialLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL;
12393 attach_desc.finalLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012394 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " with invalid first layout "
12395 "VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_"
12396 "ONLY_OPTIMAL");
Tobin Ehlis1efce022016-05-11 10:40:34 -060012397 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
12398 m_errorMonitor->VerifyFound();
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060012399
12400 vkDestroyImage(m_device->device(), src_image, NULL);
12401 vkDestroyImage(m_device->device(), dst_image, NULL);
12402}
Tobin Ehlisd8d89182016-07-18 20:13:11 -060012403
12404TEST_F(VkLayerTest, ValidRenderPassAttachmentLayoutWithLoadOp) {
12405 TEST_DESCRIPTION("Positive test where we create a renderpass with an "
12406 "attachment that uses LOAD_OP_CLEAR, the first subpass "
12407 "has a valid layout, and a second subpass then uses a "
12408 "valid *READ_ONLY* layout.");
12409 m_errorMonitor->ExpectSuccess();
12410 ASSERT_NO_FATAL_FAILURE(InitState());
12411
12412 VkAttachmentReference attach[2] = {};
12413 attach[0].attachment = 0;
12414 attach[0].layout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
12415 attach[1].attachment = 0;
12416 attach[1].layout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL;
12417 VkSubpassDescription subpasses[2] = {};
12418 // First subpass clears DS attach on load
12419 subpasses[0].pDepthStencilAttachment = &attach[0];
12420 // 2nd subpass reads in DS as input attachment
12421 subpasses[1].inputAttachmentCount = 1;
12422 subpasses[1].pInputAttachments = &attach[1];
12423 VkAttachmentDescription attach_desc = {};
12424 attach_desc.format = VK_FORMAT_D24_UNORM_S8_UINT;
12425 attach_desc.samples = VK_SAMPLE_COUNT_1_BIT;
12426 attach_desc.storeOp = VK_ATTACHMENT_STORE_OP_STORE;
12427 attach_desc.stencilStoreOp = VK_ATTACHMENT_STORE_OP_DONT_CARE;
12428 attach_desc.loadOp = VK_ATTACHMENT_LOAD_OP_CLEAR;
12429 attach_desc.stencilLoadOp = VK_ATTACHMENT_LOAD_OP_CLEAR;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012430 attach_desc.initialLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
Tobin Ehlisd8d89182016-07-18 20:13:11 -060012431 attach_desc.finalLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL;
12432 VkRenderPassCreateInfo rpci = {};
12433 rpci.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
12434 rpci.attachmentCount = 1;
12435 rpci.pAttachments = &attach_desc;
12436 rpci.subpassCount = 2;
12437 rpci.pSubpasses = subpasses;
12438
12439 // Now create RenderPass and verify no errors
12440 VkRenderPass rp;
12441 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
12442 m_errorMonitor->VerifyNotFound();
12443
12444 vkDestroyRenderPass(m_device->device(), rp, NULL);
12445}
Tobin Ehlis4af23302016-07-19 10:50:30 -060012446
Mark Mueller93b938f2016-08-18 10:27:40 -060012447TEST_F(VkLayerTest, SimultaneousUse) {
12448 TEST_DESCRIPTION("Use vkCmdExecuteCommands with invalid state "
12449 "in primary and secondary command buffers.");
12450
12451 ASSERT_NO_FATAL_FAILURE(InitState());
12452 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12453
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012454 const char *simultaneous_use_message1 = "w/o VK_COMMAND_BUFFER_USAGE_SIMULTANEOUS_USE_BIT set!";
12455 const char *simultaneous_use_message2 = "does not have VK_COMMAND_BUFFER_USAGE_SIMULTANEOUS_USE_BIT set and "
12456 "will cause primary command buffer";
Mark Mueller93b938f2016-08-18 10:27:40 -060012457
12458 VkCommandBufferAllocateInfo command_buffer_allocate_info = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012459 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
Mark Mueller93b938f2016-08-18 10:27:40 -060012460 command_buffer_allocate_info.commandPool = m_commandPool;
12461 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_SECONDARY;
12462 command_buffer_allocate_info.commandBufferCount = 1;
12463
12464 VkCommandBuffer secondary_command_buffer;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012465 ASSERT_VK_SUCCESS(vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, &secondary_command_buffer));
Mark Mueller93b938f2016-08-18 10:27:40 -060012466 VkCommandBufferBeginInfo command_buffer_begin_info = {};
12467 VkCommandBufferInheritanceInfo command_buffer_inheritance_info = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012468 command_buffer_inheritance_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_INHERITANCE_INFO;
Mark Mueller93b938f2016-08-18 10:27:40 -060012469 command_buffer_inheritance_info.renderPass = m_renderPass;
12470 command_buffer_inheritance_info.framebuffer = m_framebuffer;
12471 command_buffer_begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012472 command_buffer_begin_info.flags =
12473 VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT | VK_COMMAND_BUFFER_USAGE_RENDER_PASS_CONTINUE_BIT;
Mark Mueller93b938f2016-08-18 10:27:40 -060012474 command_buffer_begin_info.pInheritanceInfo = &command_buffer_inheritance_info;
12475
12476 vkBeginCommandBuffer(secondary_command_buffer, &command_buffer_begin_info);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012477 vkCmdBeginRenderPass(m_commandBuffer->handle(), &renderPassBeginInfo(), VK_SUBPASS_CONTENTS_SECONDARY_COMMAND_BUFFERS);
12478 vkCmdExecuteCommands(m_commandBuffer->handle(), 1, &secondary_command_buffer);
Mark Mueller4042b652016-09-05 22:52:21 -060012479 vkCmdEndRenderPass(m_commandBuffer->GetBufferHandle());
Mark Mueller93b938f2016-08-18 10:27:40 -060012480 vkEndCommandBuffer(secondary_command_buffer);
12481
Mark Mueller93b938f2016-08-18 10:27:40 -060012482 VkSubmitInfo submit_info = {};
12483 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
12484 submit_info.commandBufferCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012485 submit_info.pCommandBuffers = &m_commandBuffer->handle();
Mark Mueller4042b652016-09-05 22:52:21 -060012486 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
Mark Mueller93b938f2016-08-18 10:27:40 -060012487
Mark Mueller4042b652016-09-05 22:52:21 -060012488 vkBeginCommandBuffer(m_commandBuffer->handle(), &command_buffer_begin_info);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012489 vkCmdBeginRenderPass(m_commandBuffer->handle(), &renderPassBeginInfo(), VK_SUBPASS_CONTENTS_SECONDARY_COMMAND_BUFFERS);
12490 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, simultaneous_use_message1);
12491 vkCmdExecuteCommands(m_commandBuffer->handle(), 1, &secondary_command_buffer);
Mark Mueller93b938f2016-08-18 10:27:40 -060012492 m_errorMonitor->VerifyFound();
Mark Mueller4042b652016-09-05 22:52:21 -060012493 vkCmdEndRenderPass(m_commandBuffer->GetBufferHandle());
12494 vkEndCommandBuffer(m_commandBuffer->handle());
Mark Mueller93b938f2016-08-18 10:27:40 -060012495
12496 m_errorMonitor->SetDesiredFailureMsg(0, "");
Mark Mueller93b938f2016-08-18 10:27:40 -060012497 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
12498
Mark Mueller4042b652016-09-05 22:52:21 -060012499 command_buffer_begin_info.flags = VK_COMMAND_BUFFER_USAGE_SIMULTANEOUS_USE_BIT;
Mark Mueller93b938f2016-08-18 10:27:40 -060012500 vkBeginCommandBuffer(m_commandBuffer->handle(), &command_buffer_begin_info);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012501 vkCmdBeginRenderPass(m_commandBuffer->handle(), &renderPassBeginInfo(), VK_SUBPASS_CONTENTS_SECONDARY_COMMAND_BUFFERS);
Mark Mueller4042b652016-09-05 22:52:21 -060012502
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012503 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT, simultaneous_use_message2);
12504 vkCmdExecuteCommands(m_commandBuffer->handle(), 1, &secondary_command_buffer);
Mark Mueller93b938f2016-08-18 10:27:40 -060012505 m_errorMonitor->VerifyFound();
Mark Mueller4042b652016-09-05 22:52:21 -060012506 vkCmdEndRenderPass(m_commandBuffer->GetBufferHandle());
12507 vkEndCommandBuffer(m_commandBuffer->handle());
Mark Mueller93b938f2016-08-18 10:27:40 -060012508}
12509
Mark Mueller917f6bc2016-08-30 10:57:19 -060012510TEST_F(VkLayerTest, InUseDestroyedSignaled) {
12511 TEST_DESCRIPTION("Use vkCmdExecuteCommands with invalid state "
12512 "in primary and secondary command buffers. "
Mark Muellerc8d441e2016-08-23 17:36:00 -060012513 "Delete objects that are inuse. Call VkQueueSubmit "
12514 "with an event that has been deleted.");
Mark Mueller917f6bc2016-08-30 10:57:19 -060012515
12516 ASSERT_NO_FATAL_FAILURE(InitState());
12517 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12518
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012519 const char *submit_with_deleted_event_message = "Cannot submit cmd buffer using deleted event 0x";
12520 const char *cannot_delete_event_message = "Cannot delete event 0x";
12521 const char *cannot_delete_semaphore_message = "Cannot delete semaphore 0x";
12522 const char *cannot_destroy_fence_message = "Fence 0x";
Mark Mueller917f6bc2016-08-30 10:57:19 -060012523
12524 BeginCommandBuffer();
12525
12526 VkEvent event;
12527 VkEventCreateInfo event_create_info = {};
12528 event_create_info.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO;
12529 vkCreateEvent(m_device->device(), &event_create_info, nullptr, &event);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012530 vkCmdSetEvent(m_commandBuffer->handle(), event, VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT);
Mark Mueller917f6bc2016-08-30 10:57:19 -060012531
Mark Muellerc8d441e2016-08-23 17:36:00 -060012532 EndCommandBuffer();
12533 vkDestroyEvent(m_device->device(), event, nullptr);
12534
12535 VkSubmitInfo submit_info = {};
12536 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
12537 submit_info.commandBufferCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012538 submit_info.pCommandBuffers = &m_commandBuffer->handle();
12539 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, submit_with_deleted_event_message);
Mark Muellerc8d441e2016-08-23 17:36:00 -060012540 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
12541 m_errorMonitor->VerifyFound();
12542
12543 m_errorMonitor->SetDesiredFailureMsg(0, "");
12544 vkResetCommandBuffer(m_commandBuffer->handle(), 0);
12545
12546 vkCreateEvent(m_device->device(), &event_create_info, nullptr, &event);
12547
Mark Mueller917f6bc2016-08-30 10:57:19 -060012548 VkSemaphoreCreateInfo semaphore_create_info = {};
12549 semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
12550 VkSemaphore semaphore;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012551 ASSERT_VK_SUCCESS(vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr, &semaphore));
Mark Mueller917f6bc2016-08-30 10:57:19 -060012552 VkFenceCreateInfo fence_create_info = {};
12553 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
12554 VkFence fence;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012555 ASSERT_VK_SUCCESS(vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence));
Mark Mueller917f6bc2016-08-30 10:57:19 -060012556
12557 VkDescriptorPoolSize descriptor_pool_type_count = {};
Mark Mueller4042b652016-09-05 22:52:21 -060012558 descriptor_pool_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Mark Mueller917f6bc2016-08-30 10:57:19 -060012559 descriptor_pool_type_count.descriptorCount = 1;
12560
12561 VkDescriptorPoolCreateInfo descriptor_pool_create_info = {};
12562 descriptor_pool_create_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
12563 descriptor_pool_create_info.maxSets = 1;
12564 descriptor_pool_create_info.poolSizeCount = 1;
12565 descriptor_pool_create_info.pPoolSizes = &descriptor_pool_type_count;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012566 descriptor_pool_create_info.flags = VK_DESCRIPTOR_POOL_CREATE_FREE_DESCRIPTOR_SET_BIT;
Mark Mueller917f6bc2016-08-30 10:57:19 -060012567
12568 VkDescriptorPool descriptorset_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012569 ASSERT_VK_SUCCESS(vkCreateDescriptorPool(m_device->device(), &descriptor_pool_create_info, nullptr, &descriptorset_pool));
Mark Mueller917f6bc2016-08-30 10:57:19 -060012570
12571 VkDescriptorSetLayoutBinding descriptorset_layout_binding = {};
Mark Mueller4042b652016-09-05 22:52:21 -060012572 descriptorset_layout_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Mark Mueller917f6bc2016-08-30 10:57:19 -060012573 descriptorset_layout_binding.descriptorCount = 1;
12574 descriptorset_layout_binding.stageFlags = VK_SHADER_STAGE_ALL;
12575
12576 VkDescriptorSetLayoutCreateInfo descriptorset_layout_create_info = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012577 descriptorset_layout_create_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
Mark Mueller917f6bc2016-08-30 10:57:19 -060012578 descriptorset_layout_create_info.bindingCount = 1;
12579 descriptorset_layout_create_info.pBindings = &descriptorset_layout_binding;
12580
12581 VkDescriptorSetLayout descriptorset_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012582 ASSERT_VK_SUCCESS(
12583 vkCreateDescriptorSetLayout(m_device->device(), &descriptorset_layout_create_info, nullptr, &descriptorset_layout));
Mark Mueller917f6bc2016-08-30 10:57:19 -060012584
12585 VkDescriptorSet descriptorset;
12586 VkDescriptorSetAllocateInfo descriptorset_allocate_info = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012587 descriptorset_allocate_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Mark Mueller917f6bc2016-08-30 10:57:19 -060012588 descriptorset_allocate_info.descriptorSetCount = 1;
12589 descriptorset_allocate_info.descriptorPool = descriptorset_pool;
12590 descriptorset_allocate_info.pSetLayouts = &descriptorset_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012591 ASSERT_VK_SUCCESS(vkAllocateDescriptorSets(m_device->device(), &descriptorset_allocate_info, &descriptorset));
Mark Mueller917f6bc2016-08-30 10:57:19 -060012592
Mark Mueller4042b652016-09-05 22:52:21 -060012593 VkBufferTest buffer_test(m_device, VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT);
12594
12595 VkDescriptorBufferInfo buffer_info = {};
12596 buffer_info.buffer = buffer_test.GetBuffer();
12597 buffer_info.offset = 0;
12598 buffer_info.range = 1024;
12599
12600 VkWriteDescriptorSet write_descriptor_set = {};
12601 write_descriptor_set.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
12602 write_descriptor_set.dstSet = descriptorset;
12603 write_descriptor_set.descriptorCount = 1;
12604 write_descriptor_set.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
12605 write_descriptor_set.pBufferInfo = &buffer_info;
12606
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012607 vkUpdateDescriptorSets(m_device->device(), 1, &write_descriptor_set, 0, nullptr);
Mark Mueller4042b652016-09-05 22:52:21 -060012608
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012609 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
12610 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Mark Mueller917f6bc2016-08-30 10:57:19 -060012611
12612 VkPipelineObj pipe(m_device);
12613 pipe.AddColorAttachment();
12614 pipe.AddShader(&vs);
12615 pipe.AddShader(&fs);
12616
12617 VkPipelineLayoutCreateInfo pipeline_layout_create_info = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012618 pipeline_layout_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
Mark Mueller917f6bc2016-08-30 10:57:19 -060012619 pipeline_layout_create_info.setLayoutCount = 1;
12620 pipeline_layout_create_info.pSetLayouts = &descriptorset_layout;
12621
12622 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012623 ASSERT_VK_SUCCESS(vkCreatePipelineLayout(m_device->device(), &pipeline_layout_create_info, nullptr, &pipeline_layout));
Mark Mueller917f6bc2016-08-30 10:57:19 -060012624
12625 pipe.CreateVKPipeline(pipeline_layout, m_renderPass);
12626
Mark Muellerc8d441e2016-08-23 17:36:00 -060012627 BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012628 vkCmdSetEvent(m_commandBuffer->handle(), event, VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT);
Mark Muellerc8d441e2016-08-23 17:36:00 -060012629
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012630 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
12631 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
12632 &descriptorset, 0, NULL);
Mark Mueller917f6bc2016-08-30 10:57:19 -060012633
Mark Muellerc8d441e2016-08-23 17:36:00 -060012634 EndCommandBuffer();
Mark Mueller917f6bc2016-08-30 10:57:19 -060012635
Mark Mueller917f6bc2016-08-30 10:57:19 -060012636 submit_info.signalSemaphoreCount = 1;
12637 submit_info.pSignalSemaphores = &semaphore;
12638 vkQueueSubmit(m_device->m_queue, 1, &submit_info, fence);
Mark Muellerc8d441e2016-08-23 17:36:00 -060012639
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012640 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, cannot_delete_event_message);
Mark Mueller917f6bc2016-08-30 10:57:19 -060012641 vkDestroyEvent(m_device->device(), event, nullptr);
12642 m_errorMonitor->VerifyFound();
12643
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012644 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, cannot_delete_semaphore_message);
Mark Mueller917f6bc2016-08-30 10:57:19 -060012645 vkDestroySemaphore(m_device->device(), semaphore, nullptr);
12646 m_errorMonitor->VerifyFound();
12647
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012648 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, cannot_destroy_fence_message);
Mark Mueller917f6bc2016-08-30 10:57:19 -060012649 vkDestroyFence(m_device->device(), fence, nullptr);
12650 m_errorMonitor->VerifyFound();
12651
Tobin Ehlis122207b2016-09-01 08:50:06 -070012652 vkQueueWaitIdle(m_device->m_queue);
Mark Mueller917f6bc2016-08-30 10:57:19 -060012653 vkDestroySemaphore(m_device->device(), semaphore, nullptr);
12654 vkDestroyFence(m_device->device(), fence, nullptr);
12655 vkDestroyEvent(m_device->device(), event, nullptr);
12656 vkDestroyDescriptorPool(m_device->device(), descriptorset_pool, nullptr);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012657 vkDestroyDescriptorSetLayout(m_device->device(), descriptorset_layout, nullptr);
Mark Mueller917f6bc2016-08-30 10:57:19 -060012658 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, nullptr);
12659}
12660
Tobin Ehlis2adda372016-09-01 08:51:06 -070012661TEST_F(VkLayerTest, QueryPoolInUseDestroyedSignaled) {
12662 TEST_DESCRIPTION("Delete in-use query pool.");
12663
12664 ASSERT_NO_FATAL_FAILURE(InitState());
12665 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12666
12667 VkQueryPool query_pool;
12668 VkQueryPoolCreateInfo query_pool_ci{};
12669 query_pool_ci.sType = VK_STRUCTURE_TYPE_QUERY_POOL_CREATE_INFO;
12670 query_pool_ci.queryType = VK_QUERY_TYPE_TIMESTAMP;
12671 query_pool_ci.queryCount = 1;
12672 vkCreateQueryPool(m_device->device(), &query_pool_ci, nullptr, &query_pool);
12673 BeginCommandBuffer();
12674 // Reset query pool to create binding with cmd buffer
12675 vkCmdResetQueryPool(m_commandBuffer->handle(), query_pool, 0, 1);
12676
12677 EndCommandBuffer();
12678
12679 VkSubmitInfo submit_info = {};
12680 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
12681 submit_info.commandBufferCount = 1;
12682 submit_info.pCommandBuffers = &m_commandBuffer->handle();
12683 // Submit cmd buffer and then destroy query pool while in-flight
12684 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
12685
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012686 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Cannot delete query pool 0x");
Tobin Ehlis2adda372016-09-01 08:51:06 -070012687 vkDestroyQueryPool(m_device->handle(), query_pool, NULL);
12688 m_errorMonitor->VerifyFound();
12689
12690 vkQueueWaitIdle(m_device->m_queue);
12691 // Now that cmd buffer done we can safely destroy query_pool
12692 vkDestroyQueryPool(m_device->handle(), query_pool, NULL);
12693}
12694
Tobin Ehlisfafab2d2016-09-07 13:51:24 -060012695TEST_F(VkLayerTest, PipelineInUseDestroyedSignaled) {
12696 TEST_DESCRIPTION("Delete in-use pipeline.");
12697
12698 ASSERT_NO_FATAL_FAILURE(InitState());
12699 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12700
12701 // Empty pipeline layout used for binding PSO
12702 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
12703 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
12704 pipeline_layout_ci.setLayoutCount = 0;
12705 pipeline_layout_ci.pSetLayouts = NULL;
12706
12707 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012708 VkResult err = vkCreatePipelineLayout(m_device->handle(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlisfafab2d2016-09-07 13:51:24 -060012709 ASSERT_VK_SUCCESS(err);
12710
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012711 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Cannot delete pipeline 0x");
Tobin Ehlisfafab2d2016-09-07 13:51:24 -060012712 // Create PSO to be used for draw-time errors below
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012713 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
12714 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Tobin Ehlisfafab2d2016-09-07 13:51:24 -060012715 // Store pipeline handle so we can actually delete it before test finishes
12716 VkPipeline delete_this_pipeline;
12717 { // Scope pipeline so it will be auto-deleted
12718 VkPipelineObj pipe(m_device);
12719 pipe.AddShader(&vs);
12720 pipe.AddShader(&fs);
12721 pipe.AddColorAttachment();
12722 pipe.CreateVKPipeline(pipeline_layout, renderPass());
12723 delete_this_pipeline = pipe.handle();
12724
12725 BeginCommandBuffer();
12726 // Bind pipeline to cmd buffer
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012727 vkCmdBindPipeline(m_commandBuffer->handle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Tobin Ehlisfafab2d2016-09-07 13:51:24 -060012728
12729 EndCommandBuffer();
12730
12731 VkSubmitInfo submit_info = {};
12732 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
12733 submit_info.commandBufferCount = 1;
12734 submit_info.pCommandBuffers = &m_commandBuffer->handle();
12735 // Submit cmd buffer and then pipeline destroyed while in-flight
12736 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
12737 } // Pipeline deletion triggered here
12738 m_errorMonitor->VerifyFound();
12739 // Make sure queue finished and then actually delete pipeline
12740 vkQueueWaitIdle(m_device->m_queue);
12741 vkDestroyPipeline(m_device->handle(), delete_this_pipeline, nullptr);
12742 vkDestroyPipelineLayout(m_device->handle(), pipeline_layout, nullptr);
12743}
12744
Tobin Ehlis209532e2016-09-07 13:52:18 -060012745TEST_F(VkLayerTest, SamplerInUseDestroyedSignaled) {
12746 TEST_DESCRIPTION("Delete in-use sampler.");
12747
12748 ASSERT_NO_FATAL_FAILURE(InitState());
12749 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12750
12751 VkDescriptorPoolSize ds_type_count;
12752 ds_type_count.type = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
12753 ds_type_count.descriptorCount = 1;
12754
12755 VkDescriptorPoolCreateInfo ds_pool_ci = {};
12756 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
12757 ds_pool_ci.maxSets = 1;
12758 ds_pool_ci.poolSizeCount = 1;
12759 ds_pool_ci.pPoolSizes = &ds_type_count;
12760
12761 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012762 VkResult err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis209532e2016-09-07 13:52:18 -060012763 ASSERT_VK_SUCCESS(err);
12764
12765 VkSamplerCreateInfo sampler_ci = {};
12766 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
12767 sampler_ci.pNext = NULL;
12768 sampler_ci.magFilter = VK_FILTER_NEAREST;
12769 sampler_ci.minFilter = VK_FILTER_NEAREST;
12770 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
12771 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
12772 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
12773 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
12774 sampler_ci.mipLodBias = 1.0;
12775 sampler_ci.anisotropyEnable = VK_FALSE;
12776 sampler_ci.maxAnisotropy = 1;
12777 sampler_ci.compareEnable = VK_FALSE;
12778 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
12779 sampler_ci.minLod = 1.0;
12780 sampler_ci.maxLod = 1.0;
12781 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
12782 sampler_ci.unnormalizedCoordinates = VK_FALSE;
12783 VkSampler sampler;
12784
12785 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
12786 ASSERT_VK_SUCCESS(err);
12787
12788 VkDescriptorSetLayoutBinding layout_binding;
12789 layout_binding.binding = 0;
12790 layout_binding.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
12791 layout_binding.descriptorCount = 1;
12792 layout_binding.stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
12793 layout_binding.pImmutableSamplers = NULL;
12794
12795 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
12796 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
12797 ds_layout_ci.bindingCount = 1;
12798 ds_layout_ci.pBindings = &layout_binding;
12799 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012800 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis209532e2016-09-07 13:52:18 -060012801 ASSERT_VK_SUCCESS(err);
12802
12803 VkDescriptorSetAllocateInfo alloc_info = {};
12804 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
12805 alloc_info.descriptorSetCount = 1;
12806 alloc_info.descriptorPool = ds_pool;
12807 alloc_info.pSetLayouts = &ds_layout;
12808 VkDescriptorSet descriptor_set;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012809 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
Tobin Ehlis209532e2016-09-07 13:52:18 -060012810 ASSERT_VK_SUCCESS(err);
12811
12812 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
12813 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
12814 pipeline_layout_ci.pNext = NULL;
12815 pipeline_layout_ci.setLayoutCount = 1;
12816 pipeline_layout_ci.pSetLayouts = &ds_layout;
12817
12818 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012819 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis209532e2016-09-07 13:52:18 -060012820 ASSERT_VK_SUCCESS(err);
12821
12822 VkImageObj image(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012823 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 -060012824 ASSERT_TRUE(image.initialized());
12825
12826 VkImageView view;
12827 VkImageViewCreateInfo ivci = {};
12828 ivci.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
12829 ivci.image = image.handle();
12830 ivci.viewType = VK_IMAGE_VIEW_TYPE_2D;
12831 ivci.format = VK_FORMAT_R8G8B8A8_UNORM;
12832 ivci.subresourceRange.layerCount = 1;
12833 ivci.subresourceRange.baseMipLevel = 0;
12834 ivci.subresourceRange.levelCount = 1;
12835 ivci.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
12836
12837 err = vkCreateImageView(m_device->device(), &ivci, NULL, &view);
12838 ASSERT_VK_SUCCESS(err);
12839
12840 VkDescriptorImageInfo image_info{};
12841 image_info.imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
12842 image_info.imageView = view;
12843 image_info.sampler = sampler;
12844
12845 VkWriteDescriptorSet descriptor_write = {};
12846 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
12847 descriptor_write.dstSet = descriptor_set;
12848 descriptor_write.dstBinding = 0;
12849 descriptor_write.descriptorCount = 1;
12850 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
12851 descriptor_write.pImageInfo = &image_info;
12852
12853 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
12854
12855 // Create PSO to use the sampler
12856 char const *vsSource = "#version 450\n"
12857 "\n"
12858 "out gl_PerVertex { \n"
12859 " vec4 gl_Position;\n"
12860 "};\n"
12861 "void main(){\n"
12862 " gl_Position = vec4(1);\n"
12863 "}\n";
12864 char const *fsSource = "#version 450\n"
12865 "\n"
12866 "layout(set=0, binding=0) uniform sampler2D s;\n"
12867 "layout(location=0) out vec4 x;\n"
12868 "void main(){\n"
12869 " x = texture(s, vec2(1));\n"
12870 "}\n";
12871 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
12872 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
12873 VkPipelineObj pipe(m_device);
12874 pipe.AddShader(&vs);
12875 pipe.AddShader(&fs);
12876 pipe.AddColorAttachment();
12877 pipe.CreateVKPipeline(pipeline_layout, renderPass());
12878
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012879 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Cannot delete sampler 0x");
Tobin Ehlis209532e2016-09-07 13:52:18 -060012880
12881 BeginCommandBuffer();
12882 // Bind pipeline to cmd buffer
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012883 vkCmdBindPipeline(m_commandBuffer->handle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
12884 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
12885 &descriptor_set, 0, nullptr);
Tobin Ehlis209532e2016-09-07 13:52:18 -060012886 Draw(1, 0, 0, 0);
12887 EndCommandBuffer();
12888 // Submit cmd buffer then destroy sampler
12889 VkSubmitInfo submit_info = {};
12890 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
12891 submit_info.commandBufferCount = 1;
12892 submit_info.pCommandBuffers = &m_commandBuffer->handle();
12893 // Submit cmd buffer and then destroy sampler while in-flight
12894 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
12895
12896 vkDestroySampler(m_device->device(), sampler, nullptr);
12897 m_errorMonitor->VerifyFound();
12898 vkQueueWaitIdle(m_device->m_queue);
12899 // Now we can actually destroy sampler
12900 vkDestroySampler(m_device->device(), sampler, nullptr);
12901 vkDestroyImageView(m_device->device(), view, NULL);
12902 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
12903 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
12904 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
12905}
12906
Mark Mueller1cd9f412016-08-25 13:23:52 -060012907TEST_F(VkLayerTest, QueueForwardProgressFenceWait) {
Mark Mueller96a56d52016-08-24 10:28:05 -060012908 TEST_DESCRIPTION("Call VkQueueSubmit with a semaphore that is already "
Mark Mueller1cd9f412016-08-25 13:23:52 -060012909 "signaled but not waited on by the queue. Wait on a "
12910 "fence that has not yet been submitted to a queue.");
Mark Mueller96a56d52016-08-24 10:28:05 -060012911
12912 ASSERT_NO_FATAL_FAILURE(InitState());
12913 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12914
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012915 const char *queue_forward_progress_message = " that has already been signaled but not waited on by queue 0x";
12916 const char *invalid_fence_wait_message = " which has not been submitted on a Queue or during "
12917 "acquire next image.";
Mark Mueller96a56d52016-08-24 10:28:05 -060012918
12919 BeginCommandBuffer();
12920 EndCommandBuffer();
12921
12922 VkSemaphoreCreateInfo semaphore_create_info = {};
12923 semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
12924 VkSemaphore semaphore;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012925 ASSERT_VK_SUCCESS(vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr, &semaphore));
Mark Mueller96a56d52016-08-24 10:28:05 -060012926 VkSubmitInfo submit_info = {};
12927 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
12928 submit_info.commandBufferCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012929 submit_info.pCommandBuffers = &m_commandBuffer->handle();
Mark Mueller96a56d52016-08-24 10:28:05 -060012930 submit_info.signalSemaphoreCount = 1;
12931 submit_info.pSignalSemaphores = &semaphore;
12932 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
12933 m_errorMonitor->SetDesiredFailureMsg(0, "");
12934 vkResetCommandBuffer(m_commandBuffer->handle(), 0);
12935 BeginCommandBuffer();
12936 EndCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012937 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, queue_forward_progress_message);
Mark Mueller96a56d52016-08-24 10:28:05 -060012938 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
12939 m_errorMonitor->VerifyFound();
12940
Mark Mueller1cd9f412016-08-25 13:23:52 -060012941 VkFenceCreateInfo fence_create_info = {};
12942 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
12943 VkFence fence;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012944 ASSERT_VK_SUCCESS(vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence));
Mark Mueller1cd9f412016-08-25 13:23:52 -060012945
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012946 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT, invalid_fence_wait_message);
Mark Mueller1cd9f412016-08-25 13:23:52 -060012947 vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
12948 m_errorMonitor->VerifyFound();
12949
Mark Mueller4042b652016-09-05 22:52:21 -060012950 vkDeviceWaitIdle(m_device->device());
Mark Mueller1cd9f412016-08-25 13:23:52 -060012951 vkDestroyFence(m_device->device(), fence, nullptr);
Mark Mueller96a56d52016-08-24 10:28:05 -060012952 vkDestroySemaphore(m_device->device(), semaphore, nullptr);
12953}
12954
Tobin Ehlis4af23302016-07-19 10:50:30 -060012955TEST_F(VkLayerTest, FramebufferIncompatible) {
12956 TEST_DESCRIPTION("Bind a secondary command buffer with with a framebuffer "
12957 "that does not match the framebuffer for the active "
12958 "renderpass.");
12959 ASSERT_NO_FATAL_FAILURE(InitState());
12960 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12961
12962 // A renderpass with one color attachment.
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012963 VkAttachmentDescription attachment = {0,
12964 VK_FORMAT_B8G8R8A8_UNORM,
12965 VK_SAMPLE_COUNT_1_BIT,
12966 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
12967 VK_ATTACHMENT_STORE_OP_STORE,
12968 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
12969 VK_ATTACHMENT_STORE_OP_DONT_CARE,
12970 VK_IMAGE_LAYOUT_UNDEFINED,
12971 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL};
Tobin Ehlis4af23302016-07-19 10:50:30 -060012972
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012973 VkAttachmentReference att_ref = {0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL};
Tobin Ehlis4af23302016-07-19 10:50:30 -060012974
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012975 VkSubpassDescription subpass = {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 1, &att_ref, nullptr, nullptr, 0, nullptr};
Tobin Ehlis4af23302016-07-19 10:50:30 -060012976
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012977 VkRenderPassCreateInfo rpci = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 1, &attachment, 1, &subpass, 0, nullptr};
Tobin Ehlis4af23302016-07-19 10:50:30 -060012978
12979 VkRenderPass rp;
12980 VkResult err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
12981 ASSERT_VK_SUCCESS(err);
12982
12983 // A compatible framebuffer.
12984 VkImageObj image(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012985 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 -060012986 ASSERT_TRUE(image.initialized());
12987
12988 VkImageViewCreateInfo ivci = {
12989 VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO,
12990 nullptr,
12991 0,
12992 image.handle(),
12993 VK_IMAGE_VIEW_TYPE_2D,
12994 VK_FORMAT_B8G8R8A8_UNORM,
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012995 {VK_COMPONENT_SWIZZLE_IDENTITY, VK_COMPONENT_SWIZZLE_IDENTITY, VK_COMPONENT_SWIZZLE_IDENTITY,
12996 VK_COMPONENT_SWIZZLE_IDENTITY},
Tobin Ehlis4af23302016-07-19 10:50:30 -060012997 {VK_IMAGE_ASPECT_COLOR_BIT, 0, 1, 0, 1},
12998 };
12999 VkImageView view;
13000 err = vkCreateImageView(m_device->device(), &ivci, nullptr, &view);
13001 ASSERT_VK_SUCCESS(err);
13002
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013003 VkFramebufferCreateInfo fci = {VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr, 0, rp, 1, &view, 32, 32, 1};
Tobin Ehlis4af23302016-07-19 10:50:30 -060013004 VkFramebuffer fb;
13005 err = vkCreateFramebuffer(m_device->device(), &fci, nullptr, &fb);
13006 ASSERT_VK_SUCCESS(err);
13007
13008 VkCommandBufferAllocateInfo cbai = {};
13009 cbai.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
13010 cbai.commandPool = m_commandPool;
13011 cbai.level = VK_COMMAND_BUFFER_LEVEL_SECONDARY;
13012 cbai.commandBufferCount = 1;
13013
13014 VkCommandBuffer sec_cb;
13015 err = vkAllocateCommandBuffers(m_device->device(), &cbai, &sec_cb);
13016 ASSERT_VK_SUCCESS(err);
13017 VkCommandBufferBeginInfo cbbi = {};
13018 VkCommandBufferInheritanceInfo cbii = {};
13019 cbii.renderPass = renderPass();
13020 cbii.framebuffer = fb;
13021 cbbi.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
13022 cbbi.pNext = NULL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013023 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 -060013024 cbbi.pInheritanceInfo = &cbii;
13025 vkBeginCommandBuffer(sec_cb, &cbbi);
13026 vkEndCommandBuffer(sec_cb);
13027
Chris Forbes3400bc52016-09-13 18:10:34 +120013028 VkCommandBufferBeginInfo cbbi2 = {
13029 VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO, nullptr,
13030 0, nullptr
13031 };
13032 vkBeginCommandBuffer(m_commandBuffer->GetBufferHandle(), &cbbi2);
13033 vkCmdBeginRenderPass(m_commandBuffer->GetBufferHandle(), &m_renderPassBeginInfo, VK_SUBPASS_CONTENTS_SECONDARY_COMMAND_BUFFERS);
Tobin Ehlis4af23302016-07-19 10:50:30 -060013034
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013035 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
13036 " that is not the same as the primaryCB's current active framebuffer ");
Tobin Ehlis4af23302016-07-19 10:50:30 -060013037 vkCmdExecuteCommands(m_commandBuffer->GetBufferHandle(), 1, &sec_cb);
13038 m_errorMonitor->VerifyFound();
13039 // Cleanup
13040 vkDestroyImageView(m_device->device(), view, NULL);
13041 vkDestroyRenderPass(m_device->device(), rp, NULL);
13042 vkDestroyFramebuffer(m_device->device(), fb, NULL);
13043}
Tobin Ehlis52b504f2016-07-19 13:25:12 -060013044
13045TEST_F(VkLayerTest, ColorBlendLogicOpTests) {
13046 TEST_DESCRIPTION("If logicOp is available on the device, set it to an "
13047 "invalid value. If logicOp is not available, attempt to "
13048 "use it and verify that we see the correct error.");
13049 ASSERT_NO_FATAL_FAILURE(InitState());
13050 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13051
13052 auto features = m_device->phy().features();
13053 // Set the expected error depending on whether or not logicOp available
13054 if (VK_FALSE == features.logicOp) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013055 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "If logic operations feature not "
13056 "enabled, logicOpEnable must be "
13057 "VK_FALSE");
Tobin Ehlis52b504f2016-07-19 13:25:12 -060013058 } else {
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013059 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, ", logicOp must be a valid VkLogicOp value");
Tobin Ehlis52b504f2016-07-19 13:25:12 -060013060 }
13061 // Create a pipeline using logicOp
13062 VkResult err;
13063
13064 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
13065 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
13066
13067 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013068 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis52b504f2016-07-19 13:25:12 -060013069 ASSERT_VK_SUCCESS(err);
13070
13071 VkPipelineViewportStateCreateInfo vp_state_ci = {};
13072 vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
13073 vp_state_ci.viewportCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013074 VkViewport vp = {}; // Just need dummy vp to point to
Tobin Ehlis52b504f2016-07-19 13:25:12 -060013075 vp_state_ci.pViewports = &vp;
13076 vp_state_ci.scissorCount = 1;
13077 VkRect2D scissors = {}; // Dummy scissors to point to
13078 vp_state_ci.pScissors = &scissors;
13079 // No dynamic state
13080 VkPipelineDynamicStateCreateInfo dyn_state_ci = {};
13081 dyn_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_DYNAMIC_STATE_CREATE_INFO;
13082
13083 VkPipelineShaderStageCreateInfo shaderStages[2];
13084 memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo));
13085
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013086 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
13087 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Tobin Ehlis52b504f2016-07-19 13:25:12 -060013088 shaderStages[0] = vs.GetStageCreateInfo();
13089 shaderStages[1] = fs.GetStageCreateInfo();
13090
13091 VkPipelineVertexInputStateCreateInfo vi_ci = {};
13092 vi_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
13093
13094 VkPipelineInputAssemblyStateCreateInfo ia_ci = {};
13095 ia_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
13096 ia_ci.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP;
13097
13098 VkPipelineRasterizationStateCreateInfo rs_ci = {};
13099 rs_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
13100
13101 VkPipelineColorBlendAttachmentState att = {};
13102 att.blendEnable = VK_FALSE;
13103 att.colorWriteMask = 0xf;
13104
13105 VkPipelineColorBlendStateCreateInfo cb_ci = {};
13106 cb_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO;
13107 // Enable logicOp & set logicOp to value 1 beyond allowed entries
13108 cb_ci.logicOpEnable = VK_TRUE;
13109 cb_ci.logicOp = VK_LOGIC_OP_RANGE_SIZE; // This should cause an error
13110 cb_ci.attachmentCount = 1;
13111 cb_ci.pAttachments = &att;
13112
13113 VkGraphicsPipelineCreateInfo gp_ci = {};
13114 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
13115 gp_ci.stageCount = 2;
13116 gp_ci.pStages = shaderStages;
13117 gp_ci.pVertexInputState = &vi_ci;
13118 gp_ci.pInputAssemblyState = &ia_ci;
13119 gp_ci.pViewportState = &vp_state_ci;
13120 gp_ci.pRasterizationState = &rs_ci;
13121 gp_ci.pColorBlendState = &cb_ci;
13122 gp_ci.pDynamicState = &dyn_state_ci;
13123 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
13124 gp_ci.layout = pipeline_layout;
13125 gp_ci.renderPass = renderPass();
13126
13127 VkPipelineCacheCreateInfo pc_ci = {};
13128 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
13129
13130 VkPipeline pipeline;
13131 VkPipelineCache pipelineCache;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013132 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Tobin Ehlis52b504f2016-07-19 13:25:12 -060013133 ASSERT_VK_SUCCESS(err);
13134
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013135 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Tobin Ehlis52b504f2016-07-19 13:25:12 -060013136 m_errorMonitor->VerifyFound();
13137 if (VK_SUCCESS == err) {
13138 vkDestroyPipeline(m_device->device(), pipeline, NULL);
13139 }
13140 m_errorMonitor->VerifyFound();
13141 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
13142 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
13143}
Mark Lobodzinski209b5292015-09-17 09:44:05 -060013144#endif // DRAW_STATE_TESTS
13145
Tobin Ehlis0788f522015-05-26 16:11:58 -060013146#if THREADING_TESTS
Mike Stroyanaccf7692015-05-12 16:00:45 -060013147#if GTEST_IS_THREADSAFE
13148struct thread_data_struct {
Chia-I Wu3432a0c2015-10-27 18:04:07 +080013149 VkCommandBuffer commandBuffer;
Mike Stroyanaccf7692015-05-12 16:00:45 -060013150 VkEvent event;
13151 bool bailout;
13152};
13153
Karl Schultz6addd812016-02-02 17:17:23 -070013154extern "C" void *AddToCommandBuffer(void *arg) {
13155 struct thread_data_struct *data = (struct thread_data_struct *)arg;
Mike Stroyanaccf7692015-05-12 16:00:45 -060013156
Mike Stroyana6d14942016-07-13 15:10:05 -060013157 for (int i = 0; i < 80000; i++) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013158 vkCmdSetEvent(data->commandBuffer, data->event, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT);
Mike Stroyanaccf7692015-05-12 16:00:45 -060013159 if (data->bailout) {
13160 break;
13161 }
13162 }
13163 return NULL;
13164}
13165
Karl Schultz6addd812016-02-02 17:17:23 -070013166TEST_F(VkLayerTest, ThreadCommandBufferCollision) {
Mike Stroyan4268d1f2015-07-13 14:45:35 -060013167 test_platform_thread thread;
Mike Stroyanaccf7692015-05-12 16:00:45 -060013168
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013169 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "THREADING ERROR");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060013170
Mike Stroyanaccf7692015-05-12 16:00:45 -060013171 ASSERT_NO_FATAL_FAILURE(InitState());
13172 ASSERT_NO_FATAL_FAILURE(InitViewport());
13173 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13174
Chia-I Wu3432a0c2015-10-27 18:04:07 +080013175 // Calls AllocateCommandBuffers
13176 VkCommandBufferObj commandBuffer(m_device, m_commandPool);
Mark Lobodzinski5495d132015-09-30 16:19:16 -060013177
13178 // Avoid creating RenderPass
Chia-I Wu3432a0c2015-10-27 18:04:07 +080013179 commandBuffer.BeginCommandBuffer();
Mike Stroyanaccf7692015-05-12 16:00:45 -060013180
13181 VkEventCreateInfo event_info;
13182 VkEvent event;
Mike Stroyanaccf7692015-05-12 16:00:45 -060013183 VkResult err;
13184
13185 memset(&event_info, 0, sizeof(event_info));
13186 event_info.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO;
13187
Chia-I Wuf7458c52015-10-26 21:10:41 +080013188 err = vkCreateEvent(device(), &event_info, NULL, &event);
Mike Stroyanaccf7692015-05-12 16:00:45 -060013189 ASSERT_VK_SUCCESS(err);
13190
Mike Stroyanaccf7692015-05-12 16:00:45 -060013191 err = vkResetEvent(device(), event);
13192 ASSERT_VK_SUCCESS(err);
13193
13194 struct thread_data_struct data;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080013195 data.commandBuffer = commandBuffer.GetBufferHandle();
Mike Stroyanaccf7692015-05-12 16:00:45 -060013196 data.event = event;
13197 data.bailout = false;
13198 m_errorMonitor->SetBailout(&data.bailout);
Mike Stroyana6d14942016-07-13 15:10:05 -060013199
13200 // First do some correct operations using multiple threads.
13201 // Add many entries to command buffer from another thread.
13202 test_platform_thread_create(&thread, AddToCommandBuffer, (void *)&data);
13203 // Make non-conflicting calls from this thread at the same time.
13204 for (int i = 0; i < 80000; i++) {
Mike Stroyand6343902016-07-14 08:56:16 -060013205 uint32_t count;
13206 vkEnumeratePhysicalDevices(instance(), &count, NULL);
Mike Stroyana6d14942016-07-13 15:10:05 -060013207 }
13208 test_platform_thread_join(thread, NULL);
13209
13210 // Then do some incorrect operations using multiple threads.
Mike Stroyanaccf7692015-05-12 16:00:45 -060013211 // Add many entries to command buffer from another thread.
Mike Stroyan4268d1f2015-07-13 14:45:35 -060013212 test_platform_thread_create(&thread, AddToCommandBuffer, (void *)&data);
Mike Stroyanaccf7692015-05-12 16:00:45 -060013213 // Add many entries to command buffer from this thread at the same time.
13214 AddToCommandBuffer(&data);
Mark Lobodzinski5495d132015-09-30 16:19:16 -060013215
Mike Stroyan4268d1f2015-07-13 14:45:35 -060013216 test_platform_thread_join(thread, NULL);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080013217 commandBuffer.EndCommandBuffer();
Mike Stroyanaccf7692015-05-12 16:00:45 -060013218
Mike Stroyan10b8cb72016-01-22 15:22:03 -070013219 m_errorMonitor->SetBailout(NULL);
13220
Chris Forbes8f36a8a2016-04-07 13:21:07 +120013221 m_errorMonitor->VerifyFound();
Mike Stroyanaccf7692015-05-12 16:00:45 -060013222
Chia-I Wuf7458c52015-10-26 21:10:41 +080013223 vkDestroyEvent(device(), event, NULL);
Mike Stroyanaccf7692015-05-12 16:00:45 -060013224}
Mark Lobodzinski209b5292015-09-17 09:44:05 -060013225#endif // GTEST_IS_THREADSAFE
13226#endif // THREADING_TESTS
13227
Chris Forbes9f7ff632015-05-25 11:13:08 +120013228#if SHADER_CHECKER_TESTS
Karl Schultz6addd812016-02-02 17:17:23 -070013229TEST_F(VkLayerTest, InvalidSPIRVCodeSize) {
Chris Forbes1cc79542016-07-20 11:13:44 +120013230 TEST_DESCRIPTION("Test that an error is produced for a spirv module "
13231 "with an impossible code size");
13232
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013233 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Invalid SPIR-V header");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060013234
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060013235 ASSERT_NO_FATAL_FAILURE(InitState());
13236 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13237
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060013238 VkShaderModule module;
13239 VkShaderModuleCreateInfo moduleCreateInfo;
13240 struct icd_spv_header spv;
13241
13242 spv.magic = ICD_SPV_MAGIC;
13243 spv.version = ICD_SPV_VERSION;
13244 spv.gen_magic = 0;
13245
13246 moduleCreateInfo.sType = VK_STRUCTURE_TYPE_SHADER_MODULE_CREATE_INFO;
13247 moduleCreateInfo.pNext = NULL;
Karl Schultz6addd812016-02-02 17:17:23 -070013248 moduleCreateInfo.pCode = (const uint32_t *)&spv;
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060013249 moduleCreateInfo.codeSize = 4;
13250 moduleCreateInfo.flags = 0;
Chia-I Wuf7458c52015-10-26 21:10:41 +080013251 vkCreateShaderModule(m_device->device(), &moduleCreateInfo, NULL, &module);
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060013252
Chris Forbes8f36a8a2016-04-07 13:21:07 +120013253 m_errorMonitor->VerifyFound();
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060013254}
13255
Karl Schultz6addd812016-02-02 17:17:23 -070013256TEST_F(VkLayerTest, InvalidSPIRVMagic) {
Chris Forbes1cc79542016-07-20 11:13:44 +120013257 TEST_DESCRIPTION("Test that an error is produced for a spirv module "
13258 "with a bad magic number");
13259
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013260 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Invalid SPIR-V magic number");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060013261
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060013262 ASSERT_NO_FATAL_FAILURE(InitState());
13263 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13264
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060013265 VkShaderModule module;
13266 VkShaderModuleCreateInfo moduleCreateInfo;
13267 struct icd_spv_header spv;
13268
13269 spv.magic = ~ICD_SPV_MAGIC;
13270 spv.version = ICD_SPV_VERSION;
13271 spv.gen_magic = 0;
13272
13273 moduleCreateInfo.sType = VK_STRUCTURE_TYPE_SHADER_MODULE_CREATE_INFO;
13274 moduleCreateInfo.pNext = NULL;
Karl Schultz6addd812016-02-02 17:17:23 -070013275 moduleCreateInfo.pCode = (const uint32_t *)&spv;
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060013276 moduleCreateInfo.codeSize = sizeof(spv) + 10;
13277 moduleCreateInfo.flags = 0;
Chia-I Wuf7458c52015-10-26 21:10:41 +080013278 vkCreateShaderModule(m_device->device(), &moduleCreateInfo, NULL, &module);
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060013279
Chris Forbes8f36a8a2016-04-07 13:21:07 +120013280 m_errorMonitor->VerifyFound();
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060013281}
13282
Chris Forbesb4afd0f2016-04-04 10:48:35 +120013283#if 0
13284// Not currently covered by SPIRV-Tools validator
Karl Schultz6addd812016-02-02 17:17:23 -070013285TEST_F(VkLayerTest, InvalidSPIRVVersion) {
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -070013286 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Chris Forbesb4afd0f2016-04-04 10:48:35 +120013287 "Invalid SPIR-V header");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060013288
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060013289 ASSERT_NO_FATAL_FAILURE(InitState());
13290 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13291
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060013292 VkShaderModule module;
13293 VkShaderModuleCreateInfo moduleCreateInfo;
13294 struct icd_spv_header spv;
13295
13296 spv.magic = ICD_SPV_MAGIC;
13297 spv.version = ~ICD_SPV_VERSION;
13298 spv.gen_magic = 0;
13299
13300 moduleCreateInfo.sType = VK_STRUCTURE_TYPE_SHADER_MODULE_CREATE_INFO;
13301 moduleCreateInfo.pNext = NULL;
13302
Karl Schultz6addd812016-02-02 17:17:23 -070013303 moduleCreateInfo.pCode = (const uint32_t *)&spv;
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060013304 moduleCreateInfo.codeSize = sizeof(spv) + 10;
13305 moduleCreateInfo.flags = 0;
Chia-I Wuf7458c52015-10-26 21:10:41 +080013306 vkCreateShaderModule(m_device->device(), &moduleCreateInfo, NULL, &module);
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060013307
Chris Forbes8f36a8a2016-04-07 13:21:07 +120013308 m_errorMonitor->VerifyFound();
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060013309}
Chris Forbesb4afd0f2016-04-04 10:48:35 +120013310#endif
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060013311
Karl Schultz6addd812016-02-02 17:17:23 -070013312TEST_F(VkLayerTest, CreatePipelineVertexOutputNotConsumed) {
Chris Forbes1cc79542016-07-20 11:13:44 +120013313 TEST_DESCRIPTION("Test that a warning is produced for a vertex output that "
13314 "is not consumed by the fragment stage");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013315 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT, "not consumed by fragment shader");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060013316
Chris Forbes9f7ff632015-05-25 11:13:08 +120013317 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -060013318 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbes9f7ff632015-05-25 11:13:08 +120013319
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013320 char const *vsSource = "#version 450\n"
13321 "\n"
13322 "layout(location=0) out float x;\n"
13323 "out gl_PerVertex {\n"
13324 " vec4 gl_Position;\n"
13325 "};\n"
13326 "void main(){\n"
13327 " gl_Position = vec4(1);\n"
13328 " x = 0;\n"
13329 "}\n";
13330 char const *fsSource = "#version 450\n"
13331 "\n"
13332 "layout(location=0) out vec4 color;\n"
13333 "void main(){\n"
13334 " color = vec4(1);\n"
13335 "}\n";
Chris Forbes9f7ff632015-05-25 11:13:08 +120013336
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060013337 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13338 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbes9f7ff632015-05-25 11:13:08 +120013339
13340 VkPipelineObj pipe(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +080013341 pipe.AddColorAttachment();
Chris Forbes9f7ff632015-05-25 11:13:08 +120013342 pipe.AddShader(&vs);
13343 pipe.AddShader(&fs);
13344
Chris Forbes9f7ff632015-05-25 11:13:08 +120013345 VkDescriptorSetObj descriptorSet(m_device);
13346 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080013347 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbes9f7ff632015-05-25 11:13:08 +120013348
Tony Barbour5781e8f2015-08-04 16:23:11 -060013349 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbes9f7ff632015-05-25 11:13:08 +120013350
Chris Forbes8f36a8a2016-04-07 13:21:07 +120013351 m_errorMonitor->VerifyFound();
Chris Forbes9f7ff632015-05-25 11:13:08 +120013352}
Chris Forbes9f7ff632015-05-25 11:13:08 +120013353
Karl Schultz6addd812016-02-02 17:17:23 -070013354TEST_F(VkLayerTest, CreatePipelineFragmentInputNotProvided) {
Chris Forbes1cc79542016-07-20 11:13:44 +120013355 TEST_DESCRIPTION("Test that an error is produced for a fragment shader input "
13356 "which is not present in the outputs of the previous stage");
13357
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013358 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "not written by vertex shader");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060013359
Chris Forbes59cb88d2015-05-25 11:13:13 +120013360 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -060013361 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbes59cb88d2015-05-25 11:13:13 +120013362
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013363 char const *vsSource = "#version 450\n"
13364 "\n"
13365 "out gl_PerVertex {\n"
13366 " vec4 gl_Position;\n"
13367 "};\n"
13368 "void main(){\n"
13369 " gl_Position = vec4(1);\n"
13370 "}\n";
13371 char const *fsSource = "#version 450\n"
13372 "\n"
13373 "layout(location=0) in float x;\n"
13374 "layout(location=0) out vec4 color;\n"
13375 "void main(){\n"
13376 " color = vec4(x);\n"
13377 "}\n";
Chris Forbes59cb88d2015-05-25 11:13:13 +120013378
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060013379 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13380 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbes59cb88d2015-05-25 11:13:13 +120013381
13382 VkPipelineObj pipe(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +080013383 pipe.AddColorAttachment();
Chris Forbes59cb88d2015-05-25 11:13:13 +120013384 pipe.AddShader(&vs);
13385 pipe.AddShader(&fs);
13386
Chris Forbes59cb88d2015-05-25 11:13:13 +120013387 VkDescriptorSetObj descriptorSet(m_device);
13388 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080013389 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbes59cb88d2015-05-25 11:13:13 +120013390
Tony Barbour5781e8f2015-08-04 16:23:11 -060013391 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbes59cb88d2015-05-25 11:13:13 +120013392
Chris Forbes8f36a8a2016-04-07 13:21:07 +120013393 m_errorMonitor->VerifyFound();
Chris Forbes59cb88d2015-05-25 11:13:13 +120013394}
13395
Karl Schultz6addd812016-02-02 17:17:23 -070013396TEST_F(VkLayerTest, CreatePipelineFragmentInputNotProvidedInBlock) {
Chris Forbes1cc79542016-07-20 11:13:44 +120013397 TEST_DESCRIPTION("Test that an error is produced for a fragment shader input "
13398 "within an interace block, which is not present in the outputs "
13399 "of the previous stage.");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013400 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "not written by vertex shader");
Chris Forbesa3e85f62016-01-15 14:53:11 +130013401
13402 ASSERT_NO_FATAL_FAILURE(InitState());
13403 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13404
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013405 char const *vsSource = "#version 450\n"
13406 "\n"
13407 "out gl_PerVertex {\n"
13408 " vec4 gl_Position;\n"
13409 "};\n"
13410 "void main(){\n"
13411 " gl_Position = vec4(1);\n"
13412 "}\n";
13413 char const *fsSource = "#version 450\n"
13414 "\n"
13415 "in block { layout(location=0) float x; } ins;\n"
13416 "layout(location=0) out vec4 color;\n"
13417 "void main(){\n"
13418 " color = vec4(ins.x);\n"
13419 "}\n";
Chris Forbesa3e85f62016-01-15 14:53:11 +130013420
13421 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13422 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
13423
13424 VkPipelineObj pipe(m_device);
13425 pipe.AddColorAttachment();
13426 pipe.AddShader(&vs);
13427 pipe.AddShader(&fs);
13428
13429 VkDescriptorSetObj descriptorSet(m_device);
13430 descriptorSet.AppendDummy();
13431 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
13432
13433 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
13434
Chris Forbes8f36a8a2016-04-07 13:21:07 +120013435 m_errorMonitor->VerifyFound();
Chris Forbesa3e85f62016-01-15 14:53:11 +130013436}
13437
Karl Schultz6addd812016-02-02 17:17:23 -070013438TEST_F(VkLayerTest, CreatePipelineVsFsTypeMismatchArraySize) {
Chris Forbes1cc79542016-07-20 11:13:44 +120013439 TEST_DESCRIPTION("Test that an error is produced for mismatched array sizes "
13440 "across the VS->FS interface");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013441 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Type mismatch on location 0.0: 'ptr to "
13442 "output arr[2] of float32' vs 'ptr to "
13443 "input arr[3] of float32'");
Chris Forbes0036fd12016-01-26 14:19:49 +130013444
13445 ASSERT_NO_FATAL_FAILURE(InitState());
13446 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13447
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013448 char const *vsSource = "#version 450\n"
13449 "\n"
13450 "layout(location=0) out float x[2];\n"
13451 "out gl_PerVertex {\n"
13452 " vec4 gl_Position;\n"
13453 "};\n"
13454 "void main(){\n"
13455 " x[0] = 0; x[1] = 0;\n"
13456 " gl_Position = vec4(1);\n"
13457 "}\n";
13458 char const *fsSource = "#version 450\n"
13459 "\n"
13460 "layout(location=0) in float x[3];\n"
13461 "layout(location=0) out vec4 color;\n"
13462 "void main(){\n"
13463 " color = vec4(x[0] + x[1] + x[2]);\n"
13464 "}\n";
Chris Forbes0036fd12016-01-26 14:19:49 +130013465
13466 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13467 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
13468
13469 VkPipelineObj pipe(m_device);
13470 pipe.AddColorAttachment();
13471 pipe.AddShader(&vs);
13472 pipe.AddShader(&fs);
13473
13474 VkDescriptorSetObj descriptorSet(m_device);
13475 descriptorSet.AppendDummy();
13476 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
13477
13478 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
13479
Chris Forbes8f36a8a2016-04-07 13:21:07 +120013480 m_errorMonitor->VerifyFound();
Chris Forbes0036fd12016-01-26 14:19:49 +130013481}
13482
Karl Schultz6addd812016-02-02 17:17:23 -070013483TEST_F(VkLayerTest, CreatePipelineVsFsTypeMismatch) {
Chris Forbes1cc79542016-07-20 11:13:44 +120013484 TEST_DESCRIPTION("Test that an error is produced for mismatched types across "
13485 "the VS->FS interface");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013486 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Type mismatch on location 0");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060013487
Chris Forbesb56af562015-05-25 11:13:17 +120013488 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -060013489 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbesb56af562015-05-25 11:13:17 +120013490
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013491 char const *vsSource = "#version 450\n"
13492 "\n"
13493 "layout(location=0) out int x;\n"
13494 "out gl_PerVertex {\n"
13495 " vec4 gl_Position;\n"
13496 "};\n"
13497 "void main(){\n"
13498 " x = 0;\n"
13499 " gl_Position = vec4(1);\n"
13500 "}\n";
13501 char const *fsSource = "#version 450\n"
13502 "\n"
13503 "layout(location=0) in float x;\n" /* VS writes int */
13504 "layout(location=0) out vec4 color;\n"
13505 "void main(){\n"
13506 " color = vec4(x);\n"
13507 "}\n";
Chris Forbesb56af562015-05-25 11:13:17 +120013508
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060013509 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13510 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbesb56af562015-05-25 11:13:17 +120013511
13512 VkPipelineObj pipe(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +080013513 pipe.AddColorAttachment();
Chris Forbesb56af562015-05-25 11:13:17 +120013514 pipe.AddShader(&vs);
13515 pipe.AddShader(&fs);
13516
Chris Forbesb56af562015-05-25 11:13:17 +120013517 VkDescriptorSetObj descriptorSet(m_device);
13518 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080013519 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbesb56af562015-05-25 11:13:17 +120013520
Tony Barbour5781e8f2015-08-04 16:23:11 -060013521 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbesb56af562015-05-25 11:13:17 +120013522
Chris Forbes8f36a8a2016-04-07 13:21:07 +120013523 m_errorMonitor->VerifyFound();
Chris Forbesb56af562015-05-25 11:13:17 +120013524}
13525
Karl Schultz6addd812016-02-02 17:17:23 -070013526TEST_F(VkLayerTest, CreatePipelineVsFsTypeMismatchInBlock) {
Chris Forbes1cc79542016-07-20 11:13:44 +120013527 TEST_DESCRIPTION("Test that an error is produced for mismatched types across "
13528 "the VS->FS interface, when the variable is contained within "
13529 "an interface block");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013530 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Type mismatch on location 0");
Chris Forbesa3e85f62016-01-15 14:53:11 +130013531
13532 ASSERT_NO_FATAL_FAILURE(InitState());
13533 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13534
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013535 char const *vsSource = "#version 450\n"
13536 "\n"
13537 "out block { layout(location=0) int x; } outs;\n"
13538 "out gl_PerVertex {\n"
13539 " vec4 gl_Position;\n"
13540 "};\n"
13541 "void main(){\n"
13542 " outs.x = 0;\n"
13543 " gl_Position = vec4(1);\n"
13544 "}\n";
13545 char const *fsSource = "#version 450\n"
13546 "\n"
13547 "in block { layout(location=0) float x; } ins;\n" /* VS writes int */
13548 "layout(location=0) out vec4 color;\n"
13549 "void main(){\n"
13550 " color = vec4(ins.x);\n"
13551 "}\n";
Chris Forbesa3e85f62016-01-15 14:53:11 +130013552
13553 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13554 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
13555
13556 VkPipelineObj pipe(m_device);
13557 pipe.AddColorAttachment();
13558 pipe.AddShader(&vs);
13559 pipe.AddShader(&fs);
13560
13561 VkDescriptorSetObj descriptorSet(m_device);
13562 descriptorSet.AppendDummy();
13563 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
13564
13565 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
13566
Chris Forbes8f36a8a2016-04-07 13:21:07 +120013567 m_errorMonitor->VerifyFound();
Chris Forbese9928822016-02-17 14:44:52 +130013568}
13569
13570TEST_F(VkLayerTest, CreatePipelineVsFsMismatchByLocation) {
Chris Forbes1cc79542016-07-20 11:13:44 +120013571 TEST_DESCRIPTION("Test that an error is produced for location mismatches across "
13572 "the VS->FS interface; This should manifest as a not-written/not-consumed "
13573 "pair, but flushes out broken walking of the interfaces");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013574 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 +130013575
13576 ASSERT_NO_FATAL_FAILURE(InitState());
13577 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13578
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013579 char const *vsSource = "#version 450\n"
13580 "\n"
13581 "out block { layout(location=1) float x; } outs;\n"
13582 "out gl_PerVertex {\n"
13583 " vec4 gl_Position;\n"
13584 "};\n"
13585 "void main(){\n"
13586 " outs.x = 0;\n"
13587 " gl_Position = vec4(1);\n"
13588 "}\n";
13589 char const *fsSource = "#version 450\n"
13590 "\n"
13591 "in block { layout(location=0) float x; } ins;\n"
13592 "layout(location=0) out vec4 color;\n"
13593 "void main(){\n"
13594 " color = vec4(ins.x);\n"
13595 "}\n";
Chris Forbese9928822016-02-17 14:44:52 +130013596
13597 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13598 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
13599
13600 VkPipelineObj pipe(m_device);
13601 pipe.AddColorAttachment();
13602 pipe.AddShader(&vs);
13603 pipe.AddShader(&fs);
13604
13605 VkDescriptorSetObj descriptorSet(m_device);
13606 descriptorSet.AppendDummy();
13607 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
13608
13609 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
13610
Chris Forbes8f36a8a2016-04-07 13:21:07 +120013611 m_errorMonitor->VerifyFound();
Chris Forbese9928822016-02-17 14:44:52 +130013612}
13613
13614TEST_F(VkLayerTest, CreatePipelineVsFsMismatchByComponent) {
Chris Forbes1cc79542016-07-20 11:13:44 +120013615 TEST_DESCRIPTION("Test that an error is produced for component mismatches across the "
13616 "VS->FS interface. It's not enough to have the same set of locations in "
13617 "use; matching is defined in terms of spirv variables.");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013618 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 +130013619
13620 ASSERT_NO_FATAL_FAILURE(InitState());
13621 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13622
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013623 char const *vsSource = "#version 450\n"
13624 "\n"
13625 "out block { layout(location=0, component=0) float x; } outs;\n"
13626 "out gl_PerVertex {\n"
13627 " vec4 gl_Position;\n"
13628 "};\n"
13629 "void main(){\n"
13630 " outs.x = 0;\n"
13631 " gl_Position = vec4(1);\n"
13632 "}\n";
13633 char const *fsSource = "#version 450\n"
13634 "\n"
13635 "in block { layout(location=0, component=1) float x; } ins;\n"
13636 "layout(location=0) out vec4 color;\n"
13637 "void main(){\n"
13638 " color = vec4(ins.x);\n"
13639 "}\n";
Chris Forbese9928822016-02-17 14:44:52 +130013640
13641 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13642 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
13643
13644 VkPipelineObj pipe(m_device);
13645 pipe.AddColorAttachment();
13646 pipe.AddShader(&vs);
13647 pipe.AddShader(&fs);
13648
13649 VkDescriptorSetObj descriptorSet(m_device);
13650 descriptorSet.AppendDummy();
13651 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
13652
13653 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
13654
Chris Forbes8f36a8a2016-04-07 13:21:07 +120013655 m_errorMonitor->VerifyFound();
Chris Forbesa3e85f62016-01-15 14:53:11 +130013656}
13657
Karl Schultz6addd812016-02-02 17:17:23 -070013658TEST_F(VkLayerTest, CreatePipelineAttribNotConsumed) {
Chris Forbes1cc79542016-07-20 11:13:44 +120013659 TEST_DESCRIPTION("Test that a warning is produced for a vertex attribute which is "
13660 "not consumed by the vertex shader");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013661 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT, "location 0 not consumed by VS");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060013662
Chris Forbesde136e02015-05-25 11:13:28 +120013663 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -060013664 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbesde136e02015-05-25 11:13:28 +120013665
13666 VkVertexInputBindingDescription input_binding;
13667 memset(&input_binding, 0, sizeof(input_binding));
13668
13669 VkVertexInputAttributeDescription input_attrib;
13670 memset(&input_attrib, 0, sizeof(input_attrib));
13671 input_attrib.format = VK_FORMAT_R32_SFLOAT;
13672
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013673 char const *vsSource = "#version 450\n"
13674 "\n"
13675 "out gl_PerVertex {\n"
13676 " vec4 gl_Position;\n"
13677 "};\n"
13678 "void main(){\n"
13679 " gl_Position = vec4(1);\n"
13680 "}\n";
13681 char const *fsSource = "#version 450\n"
13682 "\n"
13683 "layout(location=0) out vec4 color;\n"
13684 "void main(){\n"
13685 " color = vec4(1);\n"
13686 "}\n";
Chris Forbesde136e02015-05-25 11:13:28 +120013687
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060013688 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13689 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbesde136e02015-05-25 11:13:28 +120013690
13691 VkPipelineObj pipe(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +080013692 pipe.AddColorAttachment();
Chris Forbesde136e02015-05-25 11:13:28 +120013693 pipe.AddShader(&vs);
13694 pipe.AddShader(&fs);
13695
13696 pipe.AddVertexInputBindings(&input_binding, 1);
13697 pipe.AddVertexInputAttribs(&input_attrib, 1);
13698
Chris Forbesde136e02015-05-25 11:13:28 +120013699 VkDescriptorSetObj descriptorSet(m_device);
13700 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080013701 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbesde136e02015-05-25 11:13:28 +120013702
Tony Barbour5781e8f2015-08-04 16:23:11 -060013703 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbesde136e02015-05-25 11:13:28 +120013704
Chris Forbes8f36a8a2016-04-07 13:21:07 +120013705 m_errorMonitor->VerifyFound();
Chris Forbesde136e02015-05-25 11:13:28 +120013706}
13707
Karl Schultz6addd812016-02-02 17:17:23 -070013708TEST_F(VkLayerTest, CreatePipelineAttribLocationMismatch) {
Chris Forbes1cc79542016-07-20 11:13:44 +120013709 TEST_DESCRIPTION("Test that a warning is produced for a location mismatch on "
13710 "vertex attributes. This flushes out bad behavior in the interface walker");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013711 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT, "location 0 not consumed by VS");
Chris Forbes7d83cd52016-01-15 11:32:03 +130013712
13713 ASSERT_NO_FATAL_FAILURE(InitState());
13714 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13715
13716 VkVertexInputBindingDescription input_binding;
13717 memset(&input_binding, 0, sizeof(input_binding));
13718
13719 VkVertexInputAttributeDescription input_attrib;
13720 memset(&input_attrib, 0, sizeof(input_attrib));
13721 input_attrib.format = VK_FORMAT_R32_SFLOAT;
13722
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013723 char const *vsSource = "#version 450\n"
13724 "\n"
13725 "layout(location=1) in float x;\n"
13726 "out gl_PerVertex {\n"
13727 " vec4 gl_Position;\n"
13728 "};\n"
13729 "void main(){\n"
13730 " gl_Position = vec4(x);\n"
13731 "}\n";
13732 char const *fsSource = "#version 450\n"
13733 "\n"
13734 "layout(location=0) out vec4 color;\n"
13735 "void main(){\n"
13736 " color = vec4(1);\n"
13737 "}\n";
Chris Forbes7d83cd52016-01-15 11:32:03 +130013738
13739 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13740 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
13741
13742 VkPipelineObj pipe(m_device);
13743 pipe.AddColorAttachment();
13744 pipe.AddShader(&vs);
13745 pipe.AddShader(&fs);
13746
13747 pipe.AddVertexInputBindings(&input_binding, 1);
13748 pipe.AddVertexInputAttribs(&input_attrib, 1);
13749
13750 VkDescriptorSetObj descriptorSet(m_device);
13751 descriptorSet.AppendDummy();
13752 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
13753
13754 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
13755
Chris Forbes8f36a8a2016-04-07 13:21:07 +120013756 m_errorMonitor->VerifyFound();
Chris Forbes7d83cd52016-01-15 11:32:03 +130013757}
13758
Karl Schultz6addd812016-02-02 17:17:23 -070013759TEST_F(VkLayerTest, CreatePipelineAttribNotProvided) {
Chris Forbes1cc79542016-07-20 11:13:44 +120013760 TEST_DESCRIPTION("Test that an error is produced for a VS input which is not "
13761 "provided by a vertex attribute");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013762 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 -060013763
Chris Forbes62e8e502015-05-25 11:13:29 +120013764 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -060013765 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbes62e8e502015-05-25 11:13:29 +120013766
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013767 char const *vsSource = "#version 450\n"
13768 "\n"
13769 "layout(location=0) in vec4 x;\n" /* not provided */
13770 "out gl_PerVertex {\n"
13771 " vec4 gl_Position;\n"
13772 "};\n"
13773 "void main(){\n"
13774 " gl_Position = x;\n"
13775 "}\n";
13776 char const *fsSource = "#version 450\n"
13777 "\n"
13778 "layout(location=0) out vec4 color;\n"
13779 "void main(){\n"
13780 " color = vec4(1);\n"
13781 "}\n";
Chris Forbes62e8e502015-05-25 11:13:29 +120013782
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060013783 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13784 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbes62e8e502015-05-25 11:13:29 +120013785
13786 VkPipelineObj pipe(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +080013787 pipe.AddColorAttachment();
Chris Forbes62e8e502015-05-25 11:13:29 +120013788 pipe.AddShader(&vs);
13789 pipe.AddShader(&fs);
13790
Chris Forbes62e8e502015-05-25 11:13:29 +120013791 VkDescriptorSetObj descriptorSet(m_device);
13792 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080013793 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbes62e8e502015-05-25 11:13:29 +120013794
Tony Barbour5781e8f2015-08-04 16:23:11 -060013795 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbes62e8e502015-05-25 11:13:29 +120013796
Chris Forbes8f36a8a2016-04-07 13:21:07 +120013797 m_errorMonitor->VerifyFound();
Chris Forbes62e8e502015-05-25 11:13:29 +120013798}
13799
Karl Schultz6addd812016-02-02 17:17:23 -070013800TEST_F(VkLayerTest, CreatePipelineAttribTypeMismatch) {
Chris Forbes1cc79542016-07-20 11:13:44 +120013801 TEST_DESCRIPTION("Test that an error is produced for a mismatch between the "
13802 "fundamental type (float/int/uint) of an attribute and the "
13803 "VS input that consumes it");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013804 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "location 0 does not match VS input type");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060013805
Chris Forbesc97d98e2015-05-25 11:13:31 +120013806 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -060013807 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbesc97d98e2015-05-25 11:13:31 +120013808
13809 VkVertexInputBindingDescription input_binding;
13810 memset(&input_binding, 0, sizeof(input_binding));
13811
13812 VkVertexInputAttributeDescription input_attrib;
13813 memset(&input_attrib, 0, sizeof(input_attrib));
13814 input_attrib.format = VK_FORMAT_R32_SFLOAT;
13815
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013816 char const *vsSource = "#version 450\n"
13817 "\n"
13818 "layout(location=0) in int x;\n" /* attrib provided float */
13819 "out gl_PerVertex {\n"
13820 " vec4 gl_Position;\n"
13821 "};\n"
13822 "void main(){\n"
13823 " gl_Position = vec4(x);\n"
13824 "}\n";
13825 char const *fsSource = "#version 450\n"
13826 "\n"
13827 "layout(location=0) out vec4 color;\n"
13828 "void main(){\n"
13829 " color = vec4(1);\n"
13830 "}\n";
Chris Forbesc97d98e2015-05-25 11:13:31 +120013831
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060013832 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13833 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbesc97d98e2015-05-25 11:13:31 +120013834
13835 VkPipelineObj pipe(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +080013836 pipe.AddColorAttachment();
Chris Forbesc97d98e2015-05-25 11:13:31 +120013837 pipe.AddShader(&vs);
13838 pipe.AddShader(&fs);
13839
13840 pipe.AddVertexInputBindings(&input_binding, 1);
13841 pipe.AddVertexInputAttribs(&input_attrib, 1);
13842
Chris Forbesc97d98e2015-05-25 11:13:31 +120013843 VkDescriptorSetObj descriptorSet(m_device);
13844 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080013845 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbesc97d98e2015-05-25 11:13:31 +120013846
Tony Barbour5781e8f2015-08-04 16:23:11 -060013847 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbesc97d98e2015-05-25 11:13:31 +120013848
Chris Forbes8f36a8a2016-04-07 13:21:07 +120013849 m_errorMonitor->VerifyFound();
Chris Forbesc97d98e2015-05-25 11:13:31 +120013850}
13851
Chris Forbesc68b43c2016-04-06 11:18:47 +120013852TEST_F(VkLayerTest, CreatePipelineDuplicateStage) {
Chris Forbes1cc79542016-07-20 11:13:44 +120013853 TEST_DESCRIPTION("Test that an error is produced for a pipeline containing multiple "
13854 "shaders for the same stage");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013855 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
13856 "Multiple shaders provided for stage VK_SHADER_STAGE_VERTEX_BIT");
Chris Forbesc68b43c2016-04-06 11:18:47 +120013857
13858 ASSERT_NO_FATAL_FAILURE(InitState());
13859 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13860
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013861 char const *vsSource = "#version 450\n"
13862 "\n"
13863 "out gl_PerVertex {\n"
13864 " vec4 gl_Position;\n"
13865 "};\n"
13866 "void main(){\n"
13867 " gl_Position = vec4(1);\n"
13868 "}\n";
13869 char const *fsSource = "#version 450\n"
13870 "\n"
13871 "layout(location=0) out vec4 color;\n"
13872 "void main(){\n"
13873 " color = vec4(1);\n"
13874 "}\n";
Chris Forbesc68b43c2016-04-06 11:18:47 +120013875
13876 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13877 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
13878
13879 VkPipelineObj pipe(m_device);
13880 pipe.AddColorAttachment();
13881 pipe.AddShader(&vs);
13882 pipe.AddShader(&vs);
13883 pipe.AddShader(&fs);
13884
13885 VkDescriptorSetObj descriptorSet(m_device);
13886 descriptorSet.AppendDummy();
13887 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
13888
13889 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
13890
Chris Forbes8f36a8a2016-04-07 13:21:07 +120013891 m_errorMonitor->VerifyFound();
Chris Forbesc68b43c2016-04-06 11:18:47 +120013892}
13893
Karl Schultz6addd812016-02-02 17:17:23 -070013894TEST_F(VkLayerTest, CreatePipelineAttribMatrixType) {
Chris Forbes1cc79542016-07-20 11:13:44 +120013895 TEST_DESCRIPTION("Test that pipeline validation accepts matrices passed "
13896 "as vertex attributes");
Chris Forbes8f36a8a2016-04-07 13:21:07 +120013897 m_errorMonitor->ExpectSuccess();
Chris Forbes2682b242015-11-24 11:13:14 +130013898
13899 ASSERT_NO_FATAL_FAILURE(InitState());
13900 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13901
13902 VkVertexInputBindingDescription input_binding;
13903 memset(&input_binding, 0, sizeof(input_binding));
13904
13905 VkVertexInputAttributeDescription input_attribs[2];
13906 memset(input_attribs, 0, sizeof(input_attribs));
13907
13908 for (int i = 0; i < 2; i++) {
13909 input_attribs[i].format = VK_FORMAT_R32G32B32A32_SFLOAT;
13910 input_attribs[i].location = i;
13911 }
13912
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013913 char const *vsSource = "#version 450\n"
13914 "\n"
13915 "layout(location=0) in mat2x4 x;\n"
13916 "out gl_PerVertex {\n"
13917 " vec4 gl_Position;\n"
13918 "};\n"
13919 "void main(){\n"
13920 " gl_Position = x[0] + x[1];\n"
13921 "}\n";
13922 char const *fsSource = "#version 450\n"
13923 "\n"
13924 "layout(location=0) out vec4 color;\n"
13925 "void main(){\n"
13926 " color = vec4(1);\n"
13927 "}\n";
Chris Forbes2682b242015-11-24 11:13:14 +130013928
13929 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13930 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
13931
13932 VkPipelineObj pipe(m_device);
13933 pipe.AddColorAttachment();
13934 pipe.AddShader(&vs);
13935 pipe.AddShader(&fs);
13936
13937 pipe.AddVertexInputBindings(&input_binding, 1);
13938 pipe.AddVertexInputAttribs(input_attribs, 2);
13939
13940 VkDescriptorSetObj descriptorSet(m_device);
13941 descriptorSet.AppendDummy();
13942 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
13943
13944 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
13945
13946 /* expect success */
Chris Forbes8f36a8a2016-04-07 13:21:07 +120013947 m_errorMonitor->VerifyNotFound();
Chris Forbes2682b242015-11-24 11:13:14 +130013948}
13949
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013950TEST_F(VkLayerTest, CreatePipelineAttribArrayType) {
Chris Forbes8f36a8a2016-04-07 13:21:07 +120013951 m_errorMonitor->ExpectSuccess();
Chris Forbes2682b242015-11-24 11:13:14 +130013952
13953 ASSERT_NO_FATAL_FAILURE(InitState());
13954 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13955
13956 VkVertexInputBindingDescription input_binding;
13957 memset(&input_binding, 0, sizeof(input_binding));
13958
13959 VkVertexInputAttributeDescription input_attribs[2];
13960 memset(input_attribs, 0, sizeof(input_attribs));
13961
13962 for (int i = 0; i < 2; i++) {
13963 input_attribs[i].format = VK_FORMAT_R32G32B32A32_SFLOAT;
13964 input_attribs[i].location = i;
13965 }
13966
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013967 char const *vsSource = "#version 450\n"
13968 "\n"
13969 "layout(location=0) in vec4 x[2];\n"
13970 "out gl_PerVertex {\n"
13971 " vec4 gl_Position;\n"
13972 "};\n"
13973 "void main(){\n"
13974 " gl_Position = x[0] + x[1];\n"
13975 "}\n";
13976 char const *fsSource = "#version 450\n"
13977 "\n"
13978 "layout(location=0) out vec4 color;\n"
13979 "void main(){\n"
13980 " color = vec4(1);\n"
13981 "}\n";
Chris Forbes2682b242015-11-24 11:13:14 +130013982
13983 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13984 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
13985
13986 VkPipelineObj pipe(m_device);
13987 pipe.AddColorAttachment();
13988 pipe.AddShader(&vs);
13989 pipe.AddShader(&fs);
13990
13991 pipe.AddVertexInputBindings(&input_binding, 1);
13992 pipe.AddVertexInputAttribs(input_attribs, 2);
13993
13994 VkDescriptorSetObj descriptorSet(m_device);
13995 descriptorSet.AppendDummy();
13996 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
13997
13998 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
13999
Chris Forbes8f36a8a2016-04-07 13:21:07 +120014000 m_errorMonitor->VerifyNotFound();
Chris Forbes2682b242015-11-24 11:13:14 +130014001}
Chris Forbes2682b242015-11-24 11:13:14 +130014002
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014003TEST_F(VkLayerTest, CreatePipelineAttribComponents) {
Chris Forbes1cc79542016-07-20 11:13:44 +120014004 TEST_DESCRIPTION("Test that pipeline validation accepts consuming a vertex attribute "
14005 "through multiple VS inputs, each consuming a different subset of the "
14006 "components.");
Chris Forbesbc290ce2016-07-06 12:01:49 +120014007 m_errorMonitor->ExpectSuccess();
14008
14009 ASSERT_NO_FATAL_FAILURE(InitState());
14010 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
14011
14012 VkVertexInputBindingDescription input_binding;
14013 memset(&input_binding, 0, sizeof(input_binding));
14014
14015 VkVertexInputAttributeDescription input_attribs[3];
14016 memset(input_attribs, 0, sizeof(input_attribs));
14017
14018 for (int i = 0; i < 3; i++) {
14019 input_attribs[i].format = VK_FORMAT_R32G32B32A32_SFLOAT;
14020 input_attribs[i].location = i;
14021 }
14022
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014023 char const *vsSource = "#version 450\n"
14024 "\n"
14025 "layout(location=0) in vec4 x;\n"
14026 "layout(location=1) in vec3 y1;\n"
14027 "layout(location=1, component=3) in float y2;\n"
14028 "layout(location=2) in vec4 z;\n"
14029 "out gl_PerVertex {\n"
14030 " vec4 gl_Position;\n"
14031 "};\n"
14032 "void main(){\n"
14033 " gl_Position = x + vec4(y1, y2) + z;\n"
14034 "}\n";
14035 char const *fsSource = "#version 450\n"
14036 "\n"
14037 "layout(location=0) out vec4 color;\n"
14038 "void main(){\n"
14039 " color = vec4(1);\n"
14040 "}\n";
Chris Forbesbc290ce2016-07-06 12:01:49 +120014041
14042 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
14043 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
14044
14045 VkPipelineObj pipe(m_device);
14046 pipe.AddColorAttachment();
14047 pipe.AddShader(&vs);
14048 pipe.AddShader(&fs);
14049
14050 pipe.AddVertexInputBindings(&input_binding, 1);
14051 pipe.AddVertexInputAttribs(input_attribs, 3);
14052
14053 VkDescriptorSetObj descriptorSet(m_device);
14054 descriptorSet.AppendDummy();
14055 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
14056
14057 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
14058
14059 m_errorMonitor->VerifyNotFound();
14060}
14061
Chris Forbes82ff92a2016-09-09 10:50:24 +120014062TEST_F(VkLayerTest, CreatePipelineMissingEntrypoint) {
14063 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
14064 "No entrypoint found named `foo`");
14065
14066 ASSERT_NO_FATAL_FAILURE(InitState());
14067 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
14068
14069 char const *vsSource = "#version 450\n"
14070 "out gl_PerVertex {\n"
14071 " vec4 gl_Position;\n"
14072 "};\n"
14073 "void main(){\n"
14074 " gl_Position = vec4(0);\n"
14075 "}\n";
14076 char const *fsSource = "#version 450\n"
14077 "\n"
14078 "layout(location=0) out vec4 color;\n"
14079 "void main(){\n"
14080 " color = vec4(1);\n"
14081 "}\n";
14082
14083 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
14084 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this, "foo");
14085
14086 VkPipelineObj pipe(m_device);
14087 pipe.AddColorAttachment();
14088 pipe.AddShader(&vs);
14089 pipe.AddShader(&fs);
14090
14091 VkDescriptorSetObj descriptorSet(m_device);
14092 descriptorSet.AppendDummy();
14093 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
14094
14095 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
14096
14097 m_errorMonitor->VerifyFound();
14098}
14099
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014100TEST_F(VkLayerTest, CreatePipelineSimplePositive) {
Chris Forbes8f36a8a2016-04-07 13:21:07 +120014101 m_errorMonitor->ExpectSuccess();
Chris Forbes4ea14fc2016-04-04 18:52:54 +120014102
14103 ASSERT_NO_FATAL_FAILURE(InitState());
14104 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
14105
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014106 char const *vsSource = "#version 450\n"
14107 "out gl_PerVertex {\n"
14108 " vec4 gl_Position;\n"
14109 "};\n"
14110 "void main(){\n"
14111 " gl_Position = vec4(0);\n"
14112 "}\n";
14113 char const *fsSource = "#version 450\n"
14114 "\n"
14115 "layout(location=0) out vec4 color;\n"
14116 "void main(){\n"
14117 " color = vec4(1);\n"
14118 "}\n";
Chris Forbes4ea14fc2016-04-04 18:52:54 +120014119
14120 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
14121 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
14122
14123 VkPipelineObj pipe(m_device);
14124 pipe.AddColorAttachment();
14125 pipe.AddShader(&vs);
14126 pipe.AddShader(&fs);
14127
14128 VkDescriptorSetObj descriptorSet(m_device);
14129 descriptorSet.AppendDummy();
14130 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
14131
14132 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
14133
Chris Forbes8f36a8a2016-04-07 13:21:07 +120014134 m_errorMonitor->VerifyNotFound();
Chris Forbes4ea14fc2016-04-04 18:52:54 +120014135}
14136
Chris Forbesae9d8cd2016-09-13 16:32:57 +120014137TEST_F(VkLayerTest, CreatePipelineDepthStencilRequired) {
14138 m_errorMonitor->SetDesiredFailureMsg(
14139 VK_DEBUG_REPORT_ERROR_BIT_EXT,
14140 "pDepthStencilState is NULL when rasterization is enabled and subpass "
14141 "uses a depth/stencil attachment");
14142
14143 ASSERT_NO_FATAL_FAILURE(InitState());
14144 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
14145
14146 char const *vsSource = "#version 450\n"
14147 "void main(){ gl_Position = vec4(0); }\n";
14148 char const *fsSource = "#version 450\n"
14149 "\n"
14150 "layout(location=0) out vec4 color;\n"
14151 "void main(){\n"
14152 " color = vec4(1);\n"
14153 "}\n";
14154
14155 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
14156 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
14157
14158 VkPipelineObj pipe(m_device);
14159 pipe.AddColorAttachment();
14160 pipe.AddShader(&vs);
14161 pipe.AddShader(&fs);
14162
14163 VkDescriptorSetObj descriptorSet(m_device);
14164 descriptorSet.AppendDummy();
14165 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
14166
14167 VkAttachmentDescription attachments[] = {
14168 { 0, VK_FORMAT_B8G8R8A8_UNORM, VK_SAMPLE_COUNT_1_BIT,
14169 VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE,
14170 VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE,
14171 VK_IMAGE_LAYOUT_UNDEFINED, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
14172 },
14173 { 0, VK_FORMAT_D16_UNORM, VK_SAMPLE_COUNT_1_BIT,
14174 VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE,
14175 VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE,
14176 VK_IMAGE_LAYOUT_UNDEFINED, VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL,
14177 },
14178 };
14179 VkAttachmentReference refs[] = {
14180 { 0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL },
14181 { 1, VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL },
14182 };
14183 VkSubpassDescription subpass = {
14184 0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr,
14185 1, &refs[0], nullptr, &refs[1],
14186 0, nullptr
14187 };
14188 VkRenderPassCreateInfo rpci = {
14189 VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr,
14190 0, 2, attachments, 1, &subpass, 0, nullptr
14191 };
14192 VkRenderPass rp;
14193 VkResult err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
14194 ASSERT_VK_SUCCESS(err);
14195
14196 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), rp);
14197
14198 m_errorMonitor->VerifyFound();
14199
14200 vkDestroyRenderPass(m_device->device(), rp, nullptr);
14201}
14202
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014203TEST_F(VkLayerTest, CreatePipelineRelaxedTypeMatch) {
Chris Forbes1cc79542016-07-20 11:13:44 +120014204 TEST_DESCRIPTION("Test that pipeline validation accepts the relaxed type matching rules "
14205 "set out in 14.1.3: fundamental type must match, and producer side must "
14206 "have at least as many components");
Chris Forbes8f36a8a2016-04-07 13:21:07 +120014207 m_errorMonitor->ExpectSuccess();
Chris Forbes912c9192016-04-05 17:50:35 +120014208
14209 // VK 1.0.8 Specification, 14.1.3 "Additionally,..." block
14210
14211 ASSERT_NO_FATAL_FAILURE(InitState());
14212 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
14213
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014214 char const *vsSource = "#version 450\n"
14215 "out gl_PerVertex {\n"
14216 " vec4 gl_Position;\n"
14217 "};\n"
14218 "layout(location=0) out vec3 x;\n"
14219 "layout(location=1) out ivec3 y;\n"
14220 "layout(location=2) out vec3 z;\n"
14221 "void main(){\n"
14222 " gl_Position = vec4(0);\n"
14223 " x = vec3(0); y = ivec3(0); z = vec3(0);\n"
14224 "}\n";
14225 char const *fsSource = "#version 450\n"
14226 "\n"
14227 "layout(location=0) out vec4 color;\n"
14228 "layout(location=0) in float x;\n"
14229 "layout(location=1) flat in int y;\n"
14230 "layout(location=2) in vec2 z;\n"
14231 "void main(){\n"
14232 " color = vec4(1 + x + y + z.x);\n"
14233 "}\n";
Chris Forbes912c9192016-04-05 17:50:35 +120014234
14235 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
14236 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
14237
14238 VkPipelineObj pipe(m_device);
14239 pipe.AddColorAttachment();
14240 pipe.AddShader(&vs);
14241 pipe.AddShader(&fs);
14242
14243 VkDescriptorSetObj descriptorSet(m_device);
14244 descriptorSet.AppendDummy();
14245 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
14246
Mike Stroyan255e9582016-06-24 09:49:32 -060014247 VkResult err = VK_SUCCESS;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014248 err = pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Mike Stroyan255e9582016-06-24 09:49:32 -060014249 ASSERT_VK_SUCCESS(err);
14250
Chris Forbes8f36a8a2016-04-07 13:21:07 +120014251 m_errorMonitor->VerifyNotFound();
Chris Forbes912c9192016-04-05 17:50:35 +120014252}
14253
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014254TEST_F(VkLayerTest, CreatePipelineTessPerVertex) {
Chris Forbes1cc79542016-07-20 11:13:44 +120014255 TEST_DESCRIPTION("Test that pipeline validation accepts per-vertex variables "
14256 "passed between the TCS and TES stages");
Chris Forbes8f36a8a2016-04-07 13:21:07 +120014257 m_errorMonitor->ExpectSuccess();
Chris Forbes4ea14fc2016-04-04 18:52:54 +120014258
14259 ASSERT_NO_FATAL_FAILURE(InitState());
14260 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
14261
Chris Forbesc1e852d2016-04-04 19:26:42 +120014262 if (!m_device->phy().features().tessellationShader) {
14263 printf("Device does not support tessellation shaders; skipped.\n");
14264 return;
14265 }
14266
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014267 char const *vsSource = "#version 450\n"
14268 "void main(){}\n";
14269 char const *tcsSource = "#version 450\n"
14270 "layout(location=0) out int x[];\n"
14271 "layout(vertices=3) out;\n"
14272 "void main(){\n"
14273 " gl_TessLevelOuter[0] = gl_TessLevelOuter[1] = gl_TessLevelOuter[2] = 1;\n"
14274 " gl_TessLevelInner[0] = 1;\n"
14275 " x[gl_InvocationID] = gl_InvocationID;\n"
14276 "}\n";
14277 char const *tesSource = "#version 450\n"
14278 "layout(triangles, equal_spacing, cw) in;\n"
14279 "layout(location=0) in int x[];\n"
14280 "out gl_PerVertex { vec4 gl_Position; };\n"
14281 "void main(){\n"
14282 " gl_Position.xyz = gl_TessCoord;\n"
14283 " gl_Position.w = x[0] + x[1] + x[2];\n"
14284 "}\n";
14285 char const *fsSource = "#version 450\n"
14286 "layout(location=0) out vec4 color;\n"
14287 "void main(){\n"
14288 " color = vec4(1);\n"
14289 "}\n";
Chris Forbes4ea14fc2016-04-04 18:52:54 +120014290
14291 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
14292 VkShaderObj tcs(m_device, tcsSource, VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT, this);
14293 VkShaderObj tes(m_device, tesSource, VK_SHADER_STAGE_TESSELLATION_EVALUATION_BIT, this);
14294 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
14295
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014296 VkPipelineInputAssemblyStateCreateInfo iasci{VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO, nullptr, 0,
14297 VK_PRIMITIVE_TOPOLOGY_PATCH_LIST, VK_FALSE};
Chris Forbes4ea14fc2016-04-04 18:52:54 +120014298
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014299 VkPipelineTessellationStateCreateInfo tsci{VK_STRUCTURE_TYPE_PIPELINE_TESSELLATION_STATE_CREATE_INFO, nullptr, 0, 3};
Chris Forbesb4cacb62016-04-04 19:15:00 +120014300
Chris Forbes4ea14fc2016-04-04 18:52:54 +120014301 VkPipelineObj pipe(m_device);
14302 pipe.SetInputAssembly(&iasci);
Chris Forbesb4cacb62016-04-04 19:15:00 +120014303 pipe.SetTessellation(&tsci);
Chris Forbes4ea14fc2016-04-04 18:52:54 +120014304 pipe.AddColorAttachment();
14305 pipe.AddShader(&vs);
14306 pipe.AddShader(&tcs);
14307 pipe.AddShader(&tes);
14308 pipe.AddShader(&fs);
14309
14310 VkDescriptorSetObj descriptorSet(m_device);
14311 descriptorSet.AppendDummy();
14312 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
14313
14314 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
14315
Chris Forbes8f36a8a2016-04-07 13:21:07 +120014316 m_errorMonitor->VerifyNotFound();
Chris Forbes4ea14fc2016-04-04 18:52:54 +120014317}
14318
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014319TEST_F(VkLayerTest, CreatePipelineGeometryInputBlockPositive) {
Chris Forbes1cc79542016-07-20 11:13:44 +120014320 TEST_DESCRIPTION("Test that pipeline validation accepts a user-defined "
14321 "interface block passed into the geometry shader. This "
14322 "is interesting because the 'extra' array level is not "
14323 "present on the member type, but on the block instance.");
Chris Forbesa0ab8152016-04-20 13:34:27 +120014324 m_errorMonitor->ExpectSuccess();
14325
14326 ASSERT_NO_FATAL_FAILURE(InitState());
14327 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
14328
14329 if (!m_device->phy().features().geometryShader) {
14330 printf("Device does not support geometry shaders; skipped.\n");
14331 return;
14332 }
14333
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014334 char const *vsSource = "#version 450\n"
14335 "layout(location=0) out VertexData { vec4 x; } vs_out;\n"
14336 "void main(){\n"
14337 " vs_out.x = vec4(1);\n"
14338 "}\n";
14339 char const *gsSource = "#version 450\n"
14340 "layout(triangles) in;\n"
14341 "layout(triangle_strip, max_vertices=3) out;\n"
14342 "layout(location=0) in VertexData { vec4 x; } gs_in[];\n"
14343 "out gl_PerVertex { vec4 gl_Position; };\n"
14344 "void main() {\n"
14345 " gl_Position = gs_in[0].x;\n"
14346 " EmitVertex();\n"
14347 "}\n";
14348 char const *fsSource = "#version 450\n"
14349 "layout(location=0) out vec4 color;\n"
14350 "void main(){\n"
14351 " color = vec4(1);\n"
14352 "}\n";
Chris Forbesa0ab8152016-04-20 13:34:27 +120014353
14354 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
14355 VkShaderObj gs(m_device, gsSource, VK_SHADER_STAGE_GEOMETRY_BIT, this);
14356 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
14357
14358 VkPipelineObj pipe(m_device);
14359 pipe.AddColorAttachment();
14360 pipe.AddShader(&vs);
14361 pipe.AddShader(&gs);
14362 pipe.AddShader(&fs);
14363
14364 VkDescriptorSetObj descriptorSet(m_device);
14365 descriptorSet.AppendDummy();
14366 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
14367
14368 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
14369
14370 m_errorMonitor->VerifyNotFound();
14371}
14372
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014373TEST_F(VkLayerTest, CreatePipelineTessPatchDecorationMismatch) {
Chris Forbes1cc79542016-07-20 11:13:44 +120014374 TEST_DESCRIPTION("Test that an error is produced for a variable output from "
14375 "the TCS without the patch decoration, but consumed in the TES "
14376 "with the decoration.");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014377 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "is per-vertex in tessellation control shader stage "
14378 "but per-patch in tessellation evaluation shader stage");
Chris Forbesa0193bc2016-04-04 19:19:47 +120014379
14380 ASSERT_NO_FATAL_FAILURE(InitState());
14381 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
14382
Chris Forbesc1e852d2016-04-04 19:26:42 +120014383 if (!m_device->phy().features().tessellationShader) {
14384 printf("Device does not support tessellation shaders; skipped.\n");
14385 return;
14386 }
14387
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014388 char const *vsSource = "#version 450\n"
14389 "void main(){}\n";
14390 char const *tcsSource = "#version 450\n"
14391 "layout(location=0) out int x[];\n"
14392 "layout(vertices=3) out;\n"
14393 "void main(){\n"
14394 " gl_TessLevelOuter[0] = gl_TessLevelOuter[1] = gl_TessLevelOuter[2] = 1;\n"
14395 " gl_TessLevelInner[0] = 1;\n"
14396 " x[gl_InvocationID] = gl_InvocationID;\n"
14397 "}\n";
14398 char const *tesSource = "#version 450\n"
14399 "layout(triangles, equal_spacing, cw) in;\n"
14400 "layout(location=0) patch in int x;\n"
14401 "out gl_PerVertex { vec4 gl_Position; };\n"
14402 "void main(){\n"
14403 " gl_Position.xyz = gl_TessCoord;\n"
14404 " gl_Position.w = x;\n"
14405 "}\n";
14406 char const *fsSource = "#version 450\n"
14407 "layout(location=0) out vec4 color;\n"
14408 "void main(){\n"
14409 " color = vec4(1);\n"
14410 "}\n";
Chris Forbesa0193bc2016-04-04 19:19:47 +120014411
14412 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
14413 VkShaderObj tcs(m_device, tcsSource, VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT, this);
14414 VkShaderObj tes(m_device, tesSource, VK_SHADER_STAGE_TESSELLATION_EVALUATION_BIT, this);
14415 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
14416
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014417 VkPipelineInputAssemblyStateCreateInfo iasci{VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO, nullptr, 0,
14418 VK_PRIMITIVE_TOPOLOGY_PATCH_LIST, VK_FALSE};
Chris Forbesa0193bc2016-04-04 19:19:47 +120014419
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014420 VkPipelineTessellationStateCreateInfo tsci{VK_STRUCTURE_TYPE_PIPELINE_TESSELLATION_STATE_CREATE_INFO, nullptr, 0, 3};
Chris Forbesa0193bc2016-04-04 19:19:47 +120014421
14422 VkPipelineObj pipe(m_device);
14423 pipe.SetInputAssembly(&iasci);
14424 pipe.SetTessellation(&tsci);
14425 pipe.AddColorAttachment();
14426 pipe.AddShader(&vs);
14427 pipe.AddShader(&tcs);
14428 pipe.AddShader(&tes);
14429 pipe.AddShader(&fs);
14430
14431 VkDescriptorSetObj descriptorSet(m_device);
14432 descriptorSet.AppendDummy();
14433 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
14434
14435 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
14436
Chris Forbes8f36a8a2016-04-07 13:21:07 +120014437 m_errorMonitor->VerifyFound();
Chris Forbesa0193bc2016-04-04 19:19:47 +120014438}
14439
Karl Schultz6addd812016-02-02 17:17:23 -070014440TEST_F(VkLayerTest, CreatePipelineAttribBindingConflict) {
Chris Forbes1cc79542016-07-20 11:13:44 +120014441 TEST_DESCRIPTION("Test that an error is produced for a vertex attribute setup where multiple "
14442 "bindings provide the same location");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014443 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
14444 "Duplicate vertex input binding descriptions for binding 0");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060014445
Chris Forbes280ba2c2015-06-12 11:16:41 +120014446 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -060014447 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbes280ba2c2015-06-12 11:16:41 +120014448
14449 /* Two binding descriptions for binding 0 */
14450 VkVertexInputBindingDescription input_bindings[2];
14451 memset(input_bindings, 0, sizeof(input_bindings));
14452
14453 VkVertexInputAttributeDescription input_attrib;
14454 memset(&input_attrib, 0, sizeof(input_attrib));
14455 input_attrib.format = VK_FORMAT_R32_SFLOAT;
14456
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014457 char const *vsSource = "#version 450\n"
14458 "\n"
14459 "layout(location=0) in float x;\n" /* attrib provided float */
14460 "out gl_PerVertex {\n"
14461 " vec4 gl_Position;\n"
14462 "};\n"
14463 "void main(){\n"
14464 " gl_Position = vec4(x);\n"
14465 "}\n";
14466 char const *fsSource = "#version 450\n"
14467 "\n"
14468 "layout(location=0) out vec4 color;\n"
14469 "void main(){\n"
14470 " color = vec4(1);\n"
14471 "}\n";
Chris Forbes280ba2c2015-06-12 11:16:41 +120014472
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060014473 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
14474 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbes280ba2c2015-06-12 11:16:41 +120014475
14476 VkPipelineObj pipe(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +080014477 pipe.AddColorAttachment();
Chris Forbes280ba2c2015-06-12 11:16:41 +120014478 pipe.AddShader(&vs);
14479 pipe.AddShader(&fs);
14480
14481 pipe.AddVertexInputBindings(input_bindings, 2);
14482 pipe.AddVertexInputAttribs(&input_attrib, 1);
14483
Chris Forbes280ba2c2015-06-12 11:16:41 +120014484 VkDescriptorSetObj descriptorSet(m_device);
14485 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014486 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbes280ba2c2015-06-12 11:16:41 +120014487
Tony Barbour5781e8f2015-08-04 16:23:11 -060014488 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbes280ba2c2015-06-12 11:16:41 +120014489
Chris Forbes8f36a8a2016-04-07 13:21:07 +120014490 m_errorMonitor->VerifyFound();
Chris Forbes280ba2c2015-06-12 11:16:41 +120014491}
Chris Forbes8f68b562015-05-25 11:13:32 +120014492
Chris Forbes35efec72016-04-21 14:32:08 +120014493TEST_F(VkLayerTest, CreatePipeline64BitAttributesPositive) {
Chris Forbes1cc79542016-07-20 11:13:44 +120014494 TEST_DESCRIPTION("Test that pipeline validation accepts basic use of 64bit vertex "
14495 "attributes. This is interesting because they consume multiple "
14496 "locations.");
Chris Forbes35efec72016-04-21 14:32:08 +120014497 m_errorMonitor->ExpectSuccess();
14498
14499 ASSERT_NO_FATAL_FAILURE(InitState());
14500 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
14501
Chris Forbes91cf3a82016-06-28 17:51:35 +120014502 if (!m_device->phy().features().shaderFloat64) {
Chris Forbes35efec72016-04-21 14:32:08 +120014503 printf("Device does not support 64bit vertex attributes; skipped.\n");
14504 return;
14505 }
14506
14507 VkVertexInputBindingDescription input_bindings[1];
14508 memset(input_bindings, 0, sizeof(input_bindings));
14509
14510 VkVertexInputAttributeDescription input_attribs[4];
14511 memset(input_attribs, 0, sizeof(input_attribs));
14512 input_attribs[0].location = 0;
14513 input_attribs[0].offset = 0;
14514 input_attribs[0].format = VK_FORMAT_R64G64B64A64_SFLOAT;
14515 input_attribs[1].location = 2;
14516 input_attribs[1].offset = 32;
14517 input_attribs[1].format = VK_FORMAT_R64G64B64A64_SFLOAT;
14518 input_attribs[2].location = 4;
14519 input_attribs[2].offset = 64;
14520 input_attribs[2].format = VK_FORMAT_R64G64B64A64_SFLOAT;
14521 input_attribs[3].location = 6;
14522 input_attribs[3].offset = 96;
14523 input_attribs[3].format = VK_FORMAT_R64G64B64A64_SFLOAT;
14524
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014525 char const *vsSource = "#version 450\n"
14526 "\n"
14527 "layout(location=0) in dmat4 x;\n"
14528 "out gl_PerVertex {\n"
14529 " vec4 gl_Position;\n"
14530 "};\n"
14531 "void main(){\n"
14532 " gl_Position = vec4(x[0][0]);\n"
14533 "}\n";
14534 char const *fsSource = "#version 450\n"
14535 "\n"
14536 "layout(location=0) out vec4 color;\n"
14537 "void main(){\n"
14538 " color = vec4(1);\n"
14539 "}\n";
Chris Forbes35efec72016-04-21 14:32:08 +120014540
14541 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
14542 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
14543
14544 VkPipelineObj pipe(m_device);
14545 pipe.AddColorAttachment();
14546 pipe.AddShader(&vs);
14547 pipe.AddShader(&fs);
14548
14549 pipe.AddVertexInputBindings(input_bindings, 1);
14550 pipe.AddVertexInputAttribs(input_attribs, 4);
14551
14552 VkDescriptorSetObj descriptorSet(m_device);
14553 descriptorSet.AppendDummy();
14554 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
14555
14556 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
14557
14558 m_errorMonitor->VerifyNotFound();
14559}
14560
Karl Schultz6addd812016-02-02 17:17:23 -070014561TEST_F(VkLayerTest, CreatePipelineFragmentOutputNotWritten) {
Chris Forbes1cc79542016-07-20 11:13:44 +120014562 TEST_DESCRIPTION("Test that an error is produced for a FS which does not "
14563 "provide an output for one of the pipeline's color attachments");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014564 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Attachment 0 not written by FS");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060014565
Chris Forbes4d6d1e52015-05-25 11:13:40 +120014566 ASSERT_NO_FATAL_FAILURE(InitState());
Chris Forbes4d6d1e52015-05-25 11:13:40 +120014567
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014568 char const *vsSource = "#version 450\n"
14569 "\n"
14570 "out gl_PerVertex {\n"
14571 " vec4 gl_Position;\n"
14572 "};\n"
14573 "void main(){\n"
14574 " gl_Position = vec4(1);\n"
14575 "}\n";
14576 char const *fsSource = "#version 450\n"
14577 "\n"
14578 "void main(){\n"
14579 "}\n";
Chris Forbes4d6d1e52015-05-25 11:13:40 +120014580
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060014581 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
14582 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbes4d6d1e52015-05-25 11:13:40 +120014583
14584 VkPipelineObj pipe(m_device);
14585 pipe.AddShader(&vs);
14586 pipe.AddShader(&fs);
14587
Chia-I Wu08accc62015-07-07 11:50:03 +080014588 /* set up CB 0, not written */
14589 pipe.AddColorAttachment();
14590 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbes4d6d1e52015-05-25 11:13:40 +120014591
Chris Forbes4d6d1e52015-05-25 11:13:40 +120014592 VkDescriptorSetObj descriptorSet(m_device);
14593 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014594 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbes4d6d1e52015-05-25 11:13:40 +120014595
Tony Barbour5781e8f2015-08-04 16:23:11 -060014596 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbes4d6d1e52015-05-25 11:13:40 +120014597
Chris Forbes8f36a8a2016-04-07 13:21:07 +120014598 m_errorMonitor->VerifyFound();
Chris Forbes4d6d1e52015-05-25 11:13:40 +120014599}
14600
Karl Schultz6addd812016-02-02 17:17:23 -070014601TEST_F(VkLayerTest, CreatePipelineFragmentOutputNotConsumed) {
Chris Forbes1cc79542016-07-20 11:13:44 +120014602 TEST_DESCRIPTION("Test that a warning is produced for a FS which provides a spurious "
14603 "output with no matching attachment");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014604 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT,
14605 "FS writes to output location 1 with no matching attachment");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060014606
Chris Forbesf3fffaa2015-05-25 11:13:43 +120014607 ASSERT_NO_FATAL_FAILURE(InitState());
Chris Forbesf3fffaa2015-05-25 11:13:43 +120014608
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014609 char const *vsSource = "#version 450\n"
14610 "\n"
14611 "out gl_PerVertex {\n"
14612 " vec4 gl_Position;\n"
14613 "};\n"
14614 "void main(){\n"
14615 " gl_Position = vec4(1);\n"
14616 "}\n";
14617 char const *fsSource = "#version 450\n"
14618 "\n"
14619 "layout(location=0) out vec4 x;\n"
14620 "layout(location=1) out vec4 y;\n" /* no matching attachment for this */
14621 "void main(){\n"
14622 " x = vec4(1);\n"
14623 " y = vec4(1);\n"
14624 "}\n";
Chris Forbesf3fffaa2015-05-25 11:13:43 +120014625
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060014626 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
14627 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbesf3fffaa2015-05-25 11:13:43 +120014628
14629 VkPipelineObj pipe(m_device);
14630 pipe.AddShader(&vs);
14631 pipe.AddShader(&fs);
14632
Chia-I Wu08accc62015-07-07 11:50:03 +080014633 /* set up CB 0, not written */
14634 pipe.AddColorAttachment();
14635 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbesf3fffaa2015-05-25 11:13:43 +120014636 /* FS writes CB 1, but we don't configure it */
14637
Chris Forbesf3fffaa2015-05-25 11:13:43 +120014638 VkDescriptorSetObj descriptorSet(m_device);
14639 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014640 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbesf3fffaa2015-05-25 11:13:43 +120014641
Tony Barbour5781e8f2015-08-04 16:23:11 -060014642 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbesf3fffaa2015-05-25 11:13:43 +120014643
Chris Forbes8f36a8a2016-04-07 13:21:07 +120014644 m_errorMonitor->VerifyFound();
Chris Forbesf3fffaa2015-05-25 11:13:43 +120014645}
14646
Karl Schultz6addd812016-02-02 17:17:23 -070014647TEST_F(VkLayerTest, CreatePipelineFragmentOutputTypeMismatch) {
Chris Forbes1cc79542016-07-20 11:13:44 +120014648 TEST_DESCRIPTION("Test that an error is produced for a mismatch between the fundamental "
14649 "type of an FS output variable, and the format of the corresponding attachment");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014650 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "does not match FS output type");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060014651
Chris Forbesa36d69e2015-05-25 11:13:44 +120014652 ASSERT_NO_FATAL_FAILURE(InitState());
Chris Forbesa36d69e2015-05-25 11:13:44 +120014653
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014654 char const *vsSource = "#version 450\n"
14655 "\n"
14656 "out gl_PerVertex {\n"
14657 " vec4 gl_Position;\n"
14658 "};\n"
14659 "void main(){\n"
14660 " gl_Position = vec4(1);\n"
14661 "}\n";
14662 char const *fsSource = "#version 450\n"
14663 "\n"
14664 "layout(location=0) out ivec4 x;\n" /* not UNORM */
14665 "void main(){\n"
14666 " x = ivec4(1);\n"
14667 "}\n";
Chris Forbesa36d69e2015-05-25 11:13:44 +120014668
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060014669 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
14670 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbesa36d69e2015-05-25 11:13:44 +120014671
14672 VkPipelineObj pipe(m_device);
14673 pipe.AddShader(&vs);
14674 pipe.AddShader(&fs);
14675
Chia-I Wu08accc62015-07-07 11:50:03 +080014676 /* set up CB 0; type is UNORM by default */
14677 pipe.AddColorAttachment();
14678 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbesa36d69e2015-05-25 11:13:44 +120014679
Chris Forbesa36d69e2015-05-25 11:13:44 +120014680 VkDescriptorSetObj descriptorSet(m_device);
14681 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014682 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbesa36d69e2015-05-25 11:13:44 +120014683
Tony Barbour5781e8f2015-08-04 16:23:11 -060014684 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbesa36d69e2015-05-25 11:13:44 +120014685
Chris Forbes8f36a8a2016-04-07 13:21:07 +120014686 m_errorMonitor->VerifyFound();
Chris Forbesa36d69e2015-05-25 11:13:44 +120014687}
Chris Forbes7b1b8932015-06-05 14:43:36 +120014688
Karl Schultz6addd812016-02-02 17:17:23 -070014689TEST_F(VkLayerTest, CreatePipelineUniformBlockNotProvided) {
Chris Forbes1cc79542016-07-20 11:13:44 +120014690 TEST_DESCRIPTION("Test that an error is produced for a shader consuming a uniform "
14691 "block which has no corresponding binding in the pipeline layout");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014692 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "not declared in pipeline layout");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060014693
Chris Forbes556c76c2015-08-14 12:04:59 +120014694 ASSERT_NO_FATAL_FAILURE(InitState());
Chris Forbes556c76c2015-08-14 12:04:59 +120014695
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014696 char const *vsSource = "#version 450\n"
14697 "\n"
14698 "out gl_PerVertex {\n"
14699 " vec4 gl_Position;\n"
14700 "};\n"
14701 "void main(){\n"
14702 " gl_Position = vec4(1);\n"
14703 "}\n";
14704 char const *fsSource = "#version 450\n"
14705 "\n"
14706 "layout(location=0) out vec4 x;\n"
14707 "layout(set=0) layout(binding=0) uniform foo { int x; int y; } bar;\n"
14708 "void main(){\n"
14709 " x = vec4(bar.y);\n"
14710 "}\n";
Chris Forbes556c76c2015-08-14 12:04:59 +120014711
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060014712 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
14713 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbes556c76c2015-08-14 12:04:59 +120014714
Chris Forbes556c76c2015-08-14 12:04:59 +120014715 VkPipelineObj pipe(m_device);
14716 pipe.AddShader(&vs);
14717 pipe.AddShader(&fs);
14718
14719 /* set up CB 0; type is UNORM by default */
14720 pipe.AddColorAttachment();
14721 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
14722
14723 VkDescriptorSetObj descriptorSet(m_device);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014724 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbes556c76c2015-08-14 12:04:59 +120014725
14726 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
14727
Chris Forbes8f36a8a2016-04-07 13:21:07 +120014728 m_errorMonitor->VerifyFound();
Chris Forbes556c76c2015-08-14 12:04:59 +120014729}
14730
Chris Forbes5c59e902016-02-26 16:56:09 +130014731TEST_F(VkLayerTest, CreatePipelinePushConstantsNotInLayout) {
Chris Forbes1cc79542016-07-20 11:13:44 +120014732 TEST_DESCRIPTION("Test that an error is produced for a shader consuming push constants "
14733 "which are not provided in the pipeline layout");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014734 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "not declared in layout");
Chris Forbes5c59e902016-02-26 16:56:09 +130014735
14736 ASSERT_NO_FATAL_FAILURE(InitState());
14737
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014738 char const *vsSource = "#version 450\n"
14739 "\n"
14740 "layout(push_constant, std430) uniform foo { float x; } consts;\n"
14741 "out gl_PerVertex {\n"
14742 " vec4 gl_Position;\n"
14743 "};\n"
14744 "void main(){\n"
14745 " gl_Position = vec4(consts.x);\n"
14746 "}\n";
14747 char const *fsSource = "#version 450\n"
14748 "\n"
14749 "layout(location=0) out vec4 x;\n"
14750 "void main(){\n"
14751 " x = vec4(1);\n"
14752 "}\n";
Chris Forbes5c59e902016-02-26 16:56:09 +130014753
14754 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
14755 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
14756
14757 VkPipelineObj pipe(m_device);
14758 pipe.AddShader(&vs);
14759 pipe.AddShader(&fs);
14760
14761 /* set up CB 0; type is UNORM by default */
14762 pipe.AddColorAttachment();
14763 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
14764
14765 VkDescriptorSetObj descriptorSet(m_device);
14766 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
14767
14768 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
14769
14770 /* should have generated an error -- no push constant ranges provided! */
Chris Forbes8f36a8a2016-04-07 13:21:07 +120014771 m_errorMonitor->VerifyFound();
Chris Forbes5c59e902016-02-26 16:56:09 +130014772}
14773
Chris Forbes3fb17902016-08-22 14:57:55 +120014774TEST_F(VkLayerTest, CreatePipelineInputAttachmentMissing) {
14775 TEST_DESCRIPTION("Test that an error is produced for a shader consuming an input attachment "
14776 "which is not included in the subpass description");
14777 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
14778 "consumes input attachment index 0 but not provided in subpass");
14779
14780 ASSERT_NO_FATAL_FAILURE(InitState());
14781
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014782 char const *vsSource = "#version 450\n"
14783 "\n"
14784 "out gl_PerVertex {\n"
14785 " vec4 gl_Position;\n"
14786 "};\n"
14787 "void main(){\n"
14788 " gl_Position = vec4(1);\n"
14789 "}\n";
14790 char const *fsSource = "#version 450\n"
14791 "\n"
14792 "layout(input_attachment_index=0, set=0, binding=0) uniform subpassInput x;\n"
14793 "layout(location=0) out vec4 color;\n"
14794 "void main() {\n"
14795 " color = subpassLoad(x);\n"
14796 "}\n";
Chris Forbes3fb17902016-08-22 14:57:55 +120014797
14798 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
14799 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
14800
14801 VkPipelineObj pipe(m_device);
14802 pipe.AddShader(&vs);
14803 pipe.AddShader(&fs);
14804 pipe.AddColorAttachment();
14805 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
14806
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014807 VkDescriptorSetLayoutBinding dslb = {0, VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT, 1, VK_SHADER_STAGE_FRAGMENT_BIT, nullptr};
14808 VkDescriptorSetLayoutCreateInfo dslci = {VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dslb};
Chris Forbes3fb17902016-08-22 14:57:55 +120014809 VkDescriptorSetLayout dsl;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014810 VkResult err = vkCreateDescriptorSetLayout(m_device->device(), &dslci, nullptr, &dsl);
Chris Forbes3fb17902016-08-22 14:57:55 +120014811 ASSERT_VK_SUCCESS(err);
14812
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014813 VkPipelineLayoutCreateInfo plci = {VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dsl, 0, nullptr};
Chris Forbes3fb17902016-08-22 14:57:55 +120014814 VkPipelineLayout pl;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014815 err = vkCreatePipelineLayout(m_device->device(), &plci, nullptr, &pl);
Chris Forbes3fb17902016-08-22 14:57:55 +120014816 ASSERT_VK_SUCCESS(err);
14817
14818 // error here.
14819 pipe.CreateVKPipeline(pl, renderPass());
14820
14821 m_errorMonitor->VerifyFound();
14822
14823 vkDestroyPipelineLayout(m_device->device(), pl, nullptr);
14824 vkDestroyDescriptorSetLayout(m_device->device(), dsl, nullptr);
14825}
14826
Chris Forbes663b5a82016-08-22 16:14:06 +120014827TEST_F(VkLayerTest, CreatePipelineInputAttachmentPositive) {
14828 TEST_DESCRIPTION("Positive test for a correctly matched input attachment");
14829 m_errorMonitor->ExpectSuccess();
14830
14831 ASSERT_NO_FATAL_FAILURE(InitState());
14832
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014833 char const *vsSource = "#version 450\n"
14834 "\n"
14835 "out gl_PerVertex {\n"
14836 " vec4 gl_Position;\n"
14837 "};\n"
14838 "void main(){\n"
14839 " gl_Position = vec4(1);\n"
14840 "}\n";
14841 char const *fsSource = "#version 450\n"
14842 "\n"
14843 "layout(input_attachment_index=0, set=0, binding=0) uniform subpassInput x;\n"
14844 "layout(location=0) out vec4 color;\n"
14845 "void main() {\n"
14846 " color = subpassLoad(x);\n"
14847 "}\n";
Chris Forbes663b5a82016-08-22 16:14:06 +120014848
14849 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
14850 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
14851
14852 VkPipelineObj pipe(m_device);
14853 pipe.AddShader(&vs);
14854 pipe.AddShader(&fs);
14855 pipe.AddColorAttachment();
14856 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
14857
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014858 VkDescriptorSetLayoutBinding dslb = {0, VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT, 1, VK_SHADER_STAGE_FRAGMENT_BIT, nullptr};
14859 VkDescriptorSetLayoutCreateInfo dslci = {VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dslb};
Chris Forbes663b5a82016-08-22 16:14:06 +120014860 VkDescriptorSetLayout dsl;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014861 VkResult err = vkCreateDescriptorSetLayout(m_device->device(), &dslci, nullptr, &dsl);
Chris Forbes663b5a82016-08-22 16:14:06 +120014862 ASSERT_VK_SUCCESS(err);
14863
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014864 VkPipelineLayoutCreateInfo plci = {VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dsl, 0, nullptr};
Chris Forbes663b5a82016-08-22 16:14:06 +120014865 VkPipelineLayout pl;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014866 err = vkCreatePipelineLayout(m_device->device(), &plci, nullptr, &pl);
Chris Forbes663b5a82016-08-22 16:14:06 +120014867 ASSERT_VK_SUCCESS(err);
14868
14869 VkAttachmentDescription descs[2] = {
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014870 {0, VK_FORMAT_R8G8B8A8_UNORM, VK_SAMPLE_COUNT_1_BIT, VK_ATTACHMENT_LOAD_OP_LOAD, VK_ATTACHMENT_STORE_OP_STORE,
14871 VK_ATTACHMENT_LOAD_OP_LOAD, VK_ATTACHMENT_STORE_OP_STORE, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
14872 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL},
14873 {0, VK_FORMAT_R8G8B8A8_UNORM, VK_SAMPLE_COUNT_1_BIT, VK_ATTACHMENT_LOAD_OP_LOAD, VK_ATTACHMENT_STORE_OP_STORE,
14874 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 +120014875 };
14876 VkAttachmentReference color = {
14877 0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
14878 };
14879 VkAttachmentReference input = {
14880 1, VK_IMAGE_LAYOUT_GENERAL,
14881 };
14882
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014883 VkSubpassDescription sd = {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 1, &input, 1, &color, nullptr, nullptr, 0, nullptr};
Chris Forbes663b5a82016-08-22 16:14:06 +120014884
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014885 VkRenderPassCreateInfo rpci = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 2, descs, 1, &sd, 0, nullptr};
Chris Forbes663b5a82016-08-22 16:14:06 +120014886 VkRenderPass rp;
14887 err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
14888 ASSERT_VK_SUCCESS(err);
14889
14890 // should be OK. would go wrong here if it's going to...
14891 pipe.CreateVKPipeline(pl, rp);
14892
14893 m_errorMonitor->VerifyNotFound();
14894
14895 vkDestroyRenderPass(m_device->device(), rp, nullptr);
14896 vkDestroyPipelineLayout(m_device->device(), pl, nullptr);
14897 vkDestroyDescriptorSetLayout(m_device->device(), dsl, nullptr);
14898}
14899
Chris Forbes5a9a0472016-08-22 16:02:09 +120014900TEST_F(VkLayerTest, CreatePipelineInputAttachmentTypeMismatch) {
14901 TEST_DESCRIPTION("Test that an error is produced for a shader consuming an input attachment "
14902 "with a format having a different fundamental type");
14903 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
14904 "input attachment 0 format of VK_FORMAT_R8G8B8A8_UINT does not match");
14905
14906 ASSERT_NO_FATAL_FAILURE(InitState());
14907
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014908 char const *vsSource = "#version 450\n"
14909 "\n"
14910 "out gl_PerVertex {\n"
14911 " vec4 gl_Position;\n"
14912 "};\n"
14913 "void main(){\n"
14914 " gl_Position = vec4(1);\n"
14915 "}\n";
14916 char const *fsSource = "#version 450\n"
14917 "\n"
14918 "layout(input_attachment_index=0, set=0, binding=0) uniform subpassInput x;\n"
14919 "layout(location=0) out vec4 color;\n"
14920 "void main() {\n"
14921 " color = subpassLoad(x);\n"
14922 "}\n";
Chris Forbes5a9a0472016-08-22 16:02:09 +120014923
14924 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
14925 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
14926
14927 VkPipelineObj pipe(m_device);
14928 pipe.AddShader(&vs);
14929 pipe.AddShader(&fs);
14930 pipe.AddColorAttachment();
14931 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
14932
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014933 VkDescriptorSetLayoutBinding dslb = {0, VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT, 1, VK_SHADER_STAGE_FRAGMENT_BIT, nullptr};
14934 VkDescriptorSetLayoutCreateInfo dslci = {VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dslb};
Chris Forbes5a9a0472016-08-22 16:02:09 +120014935 VkDescriptorSetLayout dsl;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014936 VkResult err = vkCreateDescriptorSetLayout(m_device->device(), &dslci, nullptr, &dsl);
Chris Forbes5a9a0472016-08-22 16:02:09 +120014937 ASSERT_VK_SUCCESS(err);
14938
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014939 VkPipelineLayoutCreateInfo plci = {VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dsl, 0, nullptr};
Chris Forbes5a9a0472016-08-22 16:02:09 +120014940 VkPipelineLayout pl;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014941 err = vkCreatePipelineLayout(m_device->device(), &plci, nullptr, &pl);
Chris Forbes5a9a0472016-08-22 16:02:09 +120014942 ASSERT_VK_SUCCESS(err);
14943
14944 VkAttachmentDescription descs[2] = {
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014945 {0, VK_FORMAT_R8G8B8A8_UNORM, VK_SAMPLE_COUNT_1_BIT, VK_ATTACHMENT_LOAD_OP_LOAD, VK_ATTACHMENT_STORE_OP_STORE,
14946 VK_ATTACHMENT_LOAD_OP_LOAD, VK_ATTACHMENT_STORE_OP_STORE, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
14947 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL},
14948 {0, VK_FORMAT_R8G8B8A8_UINT, VK_SAMPLE_COUNT_1_BIT, VK_ATTACHMENT_LOAD_OP_LOAD, VK_ATTACHMENT_STORE_OP_STORE,
14949 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 +120014950 };
14951 VkAttachmentReference color = {
14952 0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
14953 };
14954 VkAttachmentReference input = {
14955 1, VK_IMAGE_LAYOUT_GENERAL,
14956 };
14957
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014958 VkSubpassDescription sd = {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 1, &input, 1, &color, nullptr, nullptr, 0, nullptr};
Chris Forbes5a9a0472016-08-22 16:02:09 +120014959
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014960 VkRenderPassCreateInfo rpci = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 2, descs, 1, &sd, 0, nullptr};
Chris Forbes5a9a0472016-08-22 16:02:09 +120014961 VkRenderPass rp;
14962 err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
14963 ASSERT_VK_SUCCESS(err);
14964
14965 // error here.
14966 pipe.CreateVKPipeline(pl, rp);
14967
14968 m_errorMonitor->VerifyFound();
14969
14970 vkDestroyRenderPass(m_device->device(), rp, nullptr);
14971 vkDestroyPipelineLayout(m_device->device(), pl, nullptr);
14972 vkDestroyDescriptorSetLayout(m_device->device(), dsl, nullptr);
14973}
14974
Chris Forbes541f7b02016-08-22 15:30:27 +120014975TEST_F(VkLayerTest, CreatePipelineInputAttachmentMissingArray) {
14976 TEST_DESCRIPTION("Test that an error is produced for a shader consuming an input attachment "
14977 "which is not included in the subpass description -- array case");
14978 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
14979 "consumes input attachment index 1 but not provided in subpass");
14980
14981 ASSERT_NO_FATAL_FAILURE(InitState());
14982
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014983 char const *vsSource = "#version 450\n"
14984 "\n"
14985 "out gl_PerVertex {\n"
14986 " vec4 gl_Position;\n"
14987 "};\n"
14988 "void main(){\n"
14989 " gl_Position = vec4(1);\n"
14990 "}\n";
14991 char const *fsSource = "#version 450\n"
14992 "\n"
14993 "layout(input_attachment_index=0, set=0, binding=0) uniform subpassInput xs[2];\n"
14994 "layout(location=0) out vec4 color;\n"
14995 "void main() {\n"
14996 " color = subpassLoad(xs[1]);\n"
14997 "}\n";
Chris Forbes541f7b02016-08-22 15:30:27 +120014998
14999 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
15000 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
15001
15002 VkPipelineObj pipe(m_device);
15003 pipe.AddShader(&vs);
15004 pipe.AddShader(&fs);
15005 pipe.AddColorAttachment();
15006 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
15007
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015008 VkDescriptorSetLayoutBinding dslb = {0, VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT, 2, VK_SHADER_STAGE_FRAGMENT_BIT, nullptr};
15009 VkDescriptorSetLayoutCreateInfo dslci = {VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dslb};
Chris Forbes541f7b02016-08-22 15:30:27 +120015010 VkDescriptorSetLayout dsl;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015011 VkResult err = vkCreateDescriptorSetLayout(m_device->device(), &dslci, nullptr, &dsl);
Chris Forbes541f7b02016-08-22 15:30:27 +120015012 ASSERT_VK_SUCCESS(err);
15013
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015014 VkPipelineLayoutCreateInfo plci = {VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dsl, 0, nullptr};
Chris Forbes541f7b02016-08-22 15:30:27 +120015015 VkPipelineLayout pl;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015016 err = vkCreatePipelineLayout(m_device->device(), &plci, nullptr, &pl);
Chris Forbes541f7b02016-08-22 15:30:27 +120015017 ASSERT_VK_SUCCESS(err);
15018
15019 // error here.
15020 pipe.CreateVKPipeline(pl, renderPass());
15021
15022 m_errorMonitor->VerifyFound();
15023
15024 vkDestroyPipelineLayout(m_device->device(), pl, nullptr);
15025 vkDestroyDescriptorSetLayout(m_device->device(), dsl, nullptr);
15026}
15027
Chris Forbes10eb9ae2016-05-31 16:09:42 +120015028TEST_F(VkLayerTest, CreateComputePipelineMissingDescriptor) {
Chris Forbes1cc79542016-07-20 11:13:44 +120015029 TEST_DESCRIPTION("Test that an error is produced for a compute pipeline consuming a "
15030 "descriptor which is not provided in the pipeline layout");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015031 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Shader uses descriptor slot 0.0");
Chris Forbes10eb9ae2016-05-31 16:09:42 +120015032
15033 ASSERT_NO_FATAL_FAILURE(InitState());
15034
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015035 char const *csSource = "#version 450\n"
15036 "\n"
15037 "layout(local_size_x=1) in;\n"
15038 "layout(set=0, binding=0) buffer block { vec4 x; };\n"
15039 "void main(){\n"
15040 " x = vec4(1);\n"
15041 "}\n";
Chris Forbes10eb9ae2016-05-31 16:09:42 +120015042
15043 VkShaderObj cs(m_device, csSource, VK_SHADER_STAGE_COMPUTE_BIT, this);
15044
15045 VkDescriptorSetObj descriptorSet(m_device);
15046 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
15047
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015048 VkComputePipelineCreateInfo cpci = {VK_STRUCTURE_TYPE_COMPUTE_PIPELINE_CREATE_INFO,
15049 nullptr,
15050 0,
15051 {VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO, nullptr, 0,
15052 VK_SHADER_STAGE_COMPUTE_BIT, cs.handle(), "main", nullptr},
15053 descriptorSet.GetPipelineLayout(),
15054 VK_NULL_HANDLE,
15055 -1};
Chris Forbes10eb9ae2016-05-31 16:09:42 +120015056
15057 VkPipeline pipe;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015058 VkResult err = vkCreateComputePipelines(m_device->device(), VK_NULL_HANDLE, 1, &cpci, nullptr, &pipe);
Chris Forbes10eb9ae2016-05-31 16:09:42 +120015059
15060 m_errorMonitor->VerifyFound();
15061
15062 if (err == VK_SUCCESS) {
15063 vkDestroyPipeline(m_device->device(), pipe, nullptr);
15064 }
15065}
15066
15067TEST_F(VkLayerTest, CreateComputePipelineMissingDescriptorUnusedPositive) {
Chris Forbes1cc79542016-07-20 11:13:44 +120015068 TEST_DESCRIPTION("Test that pipeline validation accepts a compute pipeline which declares a "
15069 "descriptor-backed resource which is not provided, but the shader does not "
15070 "statically use it. This is interesting because it requires compute pipelines "
15071 "to have a proper descriptor use walk, which they didn't for some time.");
Chris Forbes10eb9ae2016-05-31 16:09:42 +120015072 m_errorMonitor->ExpectSuccess();
15073
15074 ASSERT_NO_FATAL_FAILURE(InitState());
15075
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015076 char const *csSource = "#version 450\n"
15077 "\n"
15078 "layout(local_size_x=1) in;\n"
15079 "layout(set=0, binding=0) buffer block { vec4 x; };\n"
15080 "void main(){\n"
15081 " // x is not used.\n"
15082 "}\n";
Chris Forbes10eb9ae2016-05-31 16:09:42 +120015083
15084 VkShaderObj cs(m_device, csSource, VK_SHADER_STAGE_COMPUTE_BIT, this);
15085
15086 VkDescriptorSetObj descriptorSet(m_device);
15087 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
15088
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015089 VkComputePipelineCreateInfo cpci = {VK_STRUCTURE_TYPE_COMPUTE_PIPELINE_CREATE_INFO,
15090 nullptr,
15091 0,
15092 {VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO, nullptr, 0,
15093 VK_SHADER_STAGE_COMPUTE_BIT, cs.handle(), "main", nullptr},
15094 descriptorSet.GetPipelineLayout(),
15095 VK_NULL_HANDLE,
15096 -1};
Chris Forbes10eb9ae2016-05-31 16:09:42 +120015097
15098 VkPipeline pipe;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015099 VkResult err = vkCreateComputePipelines(m_device->device(), VK_NULL_HANDLE, 1, &cpci, nullptr, &pipe);
Chris Forbes10eb9ae2016-05-31 16:09:42 +120015100
15101 m_errorMonitor->VerifyNotFound();
15102
15103 if (err == VK_SUCCESS) {
15104 vkDestroyPipeline(m_device->device(), pipe, nullptr);
15105 }
15106}
15107
Chris Forbes22a9b092016-07-19 14:34:05 +120015108TEST_F(VkLayerTest, CreateComputePipelineDescriptorTypeMismatch) {
Chris Forbes1cc79542016-07-20 11:13:44 +120015109 TEST_DESCRIPTION("Test that an error is produced for a pipeline consuming a "
15110 "descriptor-backed resource of a mismatched type");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015111 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
15112 "but descriptor of type VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER");
Chris Forbes22a9b092016-07-19 14:34:05 +120015113
15114 ASSERT_NO_FATAL_FAILURE(InitState());
15115
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015116 VkDescriptorSetLayoutBinding binding = {0, VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, 1, VK_SHADER_STAGE_COMPUTE_BIT, nullptr};
15117 VkDescriptorSetLayoutCreateInfo dslci = {VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO, nullptr, 0, 1, &binding};
Chris Forbes22a9b092016-07-19 14:34:05 +120015118 VkDescriptorSetLayout dsl;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015119 VkResult err = vkCreateDescriptorSetLayout(m_device->device(), &dslci, nullptr, &dsl);
Chris Forbes22a9b092016-07-19 14:34:05 +120015120 ASSERT_VK_SUCCESS(err);
15121
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015122 VkPipelineLayoutCreateInfo plci = {VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dsl, 0, nullptr};
Chris Forbes22a9b092016-07-19 14:34:05 +120015123 VkPipelineLayout pl;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015124 err = vkCreatePipelineLayout(m_device->device(), &plci, nullptr, &pl);
Chris Forbes22a9b092016-07-19 14:34:05 +120015125 ASSERT_VK_SUCCESS(err);
15126
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015127 char const *csSource = "#version 450\n"
15128 "\n"
15129 "layout(local_size_x=1) in;\n"
15130 "layout(set=0, binding=0) buffer block { vec4 x; };\n"
15131 "void main() {\n"
15132 " x.x = 1.0f;\n"
15133 "}\n";
Chris Forbes22a9b092016-07-19 14:34:05 +120015134 VkShaderObj cs(m_device, csSource, VK_SHADER_STAGE_COMPUTE_BIT, this);
15135
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015136 VkComputePipelineCreateInfo cpci = {VK_STRUCTURE_TYPE_COMPUTE_PIPELINE_CREATE_INFO,
15137 nullptr,
15138 0,
15139 {VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO, nullptr, 0,
15140 VK_SHADER_STAGE_COMPUTE_BIT, cs.handle(), "main", nullptr},
15141 pl,
15142 VK_NULL_HANDLE,
15143 -1};
Chris Forbes22a9b092016-07-19 14:34:05 +120015144
15145 VkPipeline pipe;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015146 err = vkCreateComputePipelines(m_device->device(), VK_NULL_HANDLE, 1, &cpci, nullptr, &pipe);
Chris Forbes22a9b092016-07-19 14:34:05 +120015147
15148 m_errorMonitor->VerifyFound();
15149
15150 if (err == VK_SUCCESS) {
15151 vkDestroyPipeline(m_device->device(), pipe, nullptr);
15152 }
15153
15154 vkDestroyPipelineLayout(m_device->device(), pl, nullptr);
15155 vkDestroyDescriptorSetLayout(m_device->device(), dsl, nullptr);
15156}
15157
Chris Forbese10a51f2016-07-19 14:42:51 +120015158TEST_F(VkLayerTest, CreateComputePipelineCombinedImageSamplerConsumedAsSampler) {
Chris Forbes1cc79542016-07-20 11:13:44 +120015159 TEST_DESCRIPTION("Test that pipeline validation accepts a shader consuming only the "
15160 "sampler portion of a combined image + sampler");
Chris Forbese10a51f2016-07-19 14:42:51 +120015161 m_errorMonitor->ExpectSuccess();
15162
15163 ASSERT_NO_FATAL_FAILURE(InitState());
15164
15165 VkDescriptorSetLayoutBinding bindings[] = {
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015166 {0, VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, 1, VK_SHADER_STAGE_COMPUTE_BIT, nullptr},
15167 {1, VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE, 1, VK_SHADER_STAGE_COMPUTE_BIT, nullptr},
15168 {2, VK_DESCRIPTOR_TYPE_STORAGE_BUFFER, 1, VK_SHADER_STAGE_COMPUTE_BIT, nullptr},
Chris Forbese10a51f2016-07-19 14:42:51 +120015169 };
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015170 VkDescriptorSetLayoutCreateInfo dslci = {VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO, nullptr, 0, 3, bindings};
Chris Forbese10a51f2016-07-19 14:42:51 +120015171 VkDescriptorSetLayout dsl;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015172 VkResult err = vkCreateDescriptorSetLayout(m_device->device(), &dslci, nullptr, &dsl);
Chris Forbese10a51f2016-07-19 14:42:51 +120015173 ASSERT_VK_SUCCESS(err);
15174
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015175 VkPipelineLayoutCreateInfo plci = {VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dsl, 0, nullptr};
Chris Forbese10a51f2016-07-19 14:42:51 +120015176 VkPipelineLayout pl;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015177 err = vkCreatePipelineLayout(m_device->device(), &plci, nullptr, &pl);
Chris Forbese10a51f2016-07-19 14:42:51 +120015178 ASSERT_VK_SUCCESS(err);
15179
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015180 char const *csSource = "#version 450\n"
15181 "\n"
15182 "layout(local_size_x=1) in;\n"
15183 "layout(set=0, binding=0) uniform sampler s;\n"
15184 "layout(set=0, binding=1) uniform texture2D t;\n"
15185 "layout(set=0, binding=2) buffer block { vec4 x; };\n"
15186 "void main() {\n"
15187 " x = texture(sampler2D(t, s), vec2(0));\n"
15188 "}\n";
Chris Forbese10a51f2016-07-19 14:42:51 +120015189 VkShaderObj cs(m_device, csSource, VK_SHADER_STAGE_COMPUTE_BIT, this);
15190
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015191 VkComputePipelineCreateInfo cpci = {VK_STRUCTURE_TYPE_COMPUTE_PIPELINE_CREATE_INFO,
15192 nullptr,
15193 0,
15194 {VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO, nullptr, 0,
15195 VK_SHADER_STAGE_COMPUTE_BIT, cs.handle(), "main", nullptr},
15196 pl,
15197 VK_NULL_HANDLE,
15198 -1};
Chris Forbese10a51f2016-07-19 14:42:51 +120015199
15200 VkPipeline pipe;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015201 err = vkCreateComputePipelines(m_device->device(), VK_NULL_HANDLE, 1, &cpci, nullptr, &pipe);
Chris Forbese10a51f2016-07-19 14:42:51 +120015202
15203 m_errorMonitor->VerifyNotFound();
15204
15205 if (err == VK_SUCCESS) {
15206 vkDestroyPipeline(m_device->device(), pipe, nullptr);
15207 }
15208
15209 vkDestroyPipelineLayout(m_device->device(), pl, nullptr);
15210 vkDestroyDescriptorSetLayout(m_device->device(), dsl, nullptr);
15211}
15212
Chris Forbes91c3b2a2016-07-19 14:46:38 +120015213TEST_F(VkLayerTest, CreateComputePipelineCombinedImageSamplerConsumedAsImage) {
Chris Forbes1cc79542016-07-20 11:13:44 +120015214 TEST_DESCRIPTION("Test that pipeline validation accepts a shader consuming only the "
15215 "image portion of a combined image + sampler");
Chris Forbes91c3b2a2016-07-19 14:46:38 +120015216 m_errorMonitor->ExpectSuccess();
15217
15218 ASSERT_NO_FATAL_FAILURE(InitState());
15219
15220 VkDescriptorSetLayoutBinding bindings[] = {
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015221 {0, VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, 1, VK_SHADER_STAGE_COMPUTE_BIT, nullptr},
15222 {1, VK_DESCRIPTOR_TYPE_SAMPLER, 1, VK_SHADER_STAGE_COMPUTE_BIT, nullptr},
15223 {2, VK_DESCRIPTOR_TYPE_STORAGE_BUFFER, 1, VK_SHADER_STAGE_COMPUTE_BIT, nullptr},
Chris Forbes91c3b2a2016-07-19 14:46:38 +120015224 };
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015225 VkDescriptorSetLayoutCreateInfo dslci = {VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO, nullptr, 0, 3, bindings};
Chris Forbes91c3b2a2016-07-19 14:46:38 +120015226 VkDescriptorSetLayout dsl;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015227 VkResult err = vkCreateDescriptorSetLayout(m_device->device(), &dslci, nullptr, &dsl);
Chris Forbes91c3b2a2016-07-19 14:46:38 +120015228 ASSERT_VK_SUCCESS(err);
15229
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015230 VkPipelineLayoutCreateInfo plci = {VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dsl, 0, nullptr};
Chris Forbes91c3b2a2016-07-19 14:46:38 +120015231 VkPipelineLayout pl;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015232 err = vkCreatePipelineLayout(m_device->device(), &plci, nullptr, &pl);
Chris Forbes91c3b2a2016-07-19 14:46:38 +120015233 ASSERT_VK_SUCCESS(err);
15234
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015235 char const *csSource = "#version 450\n"
15236 "\n"
15237 "layout(local_size_x=1) in;\n"
15238 "layout(set=0, binding=0) uniform texture2D t;\n"
15239 "layout(set=0, binding=1) uniform sampler s;\n"
15240 "layout(set=0, binding=2) buffer block { vec4 x; };\n"
15241 "void main() {\n"
15242 " x = texture(sampler2D(t, s), vec2(0));\n"
15243 "}\n";
Chris Forbes91c3b2a2016-07-19 14:46:38 +120015244 VkShaderObj cs(m_device, csSource, VK_SHADER_STAGE_COMPUTE_BIT, this);
15245
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015246 VkComputePipelineCreateInfo cpci = {VK_STRUCTURE_TYPE_COMPUTE_PIPELINE_CREATE_INFO,
15247 nullptr,
15248 0,
15249 {VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO, nullptr, 0,
15250 VK_SHADER_STAGE_COMPUTE_BIT, cs.handle(), "main", nullptr},
15251 pl,
15252 VK_NULL_HANDLE,
15253 -1};
Chris Forbes91c3b2a2016-07-19 14:46:38 +120015254
15255 VkPipeline pipe;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015256 err = vkCreateComputePipelines(m_device->device(), VK_NULL_HANDLE, 1, &cpci, nullptr, &pipe);
Chris Forbes91c3b2a2016-07-19 14:46:38 +120015257
15258 m_errorMonitor->VerifyNotFound();
15259
15260 if (err == VK_SUCCESS) {
15261 vkDestroyPipeline(m_device->device(), pipe, nullptr);
15262 }
15263
15264 vkDestroyPipelineLayout(m_device->device(), pl, nullptr);
15265 vkDestroyDescriptorSetLayout(m_device->device(), dsl, nullptr);
15266}
15267
Chris Forbes6a4991a2016-07-19 15:07:32 +120015268TEST_F(VkLayerTest, CreateComputePipelineCombinedImageSamplerConsumedAsBoth) {
Chris Forbes1cc79542016-07-20 11:13:44 +120015269 TEST_DESCRIPTION("Test that pipeline validation accepts a shader consuming "
15270 "both the sampler and the image of a combined image+sampler "
15271 "but via separate variables");
Chris Forbes6a4991a2016-07-19 15:07:32 +120015272 m_errorMonitor->ExpectSuccess();
15273
15274 ASSERT_NO_FATAL_FAILURE(InitState());
15275
15276 VkDescriptorSetLayoutBinding bindings[] = {
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015277 {0, VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, 1, VK_SHADER_STAGE_COMPUTE_BIT, nullptr},
15278 {1, VK_DESCRIPTOR_TYPE_STORAGE_BUFFER, 1, VK_SHADER_STAGE_COMPUTE_BIT, nullptr},
Chris Forbes6a4991a2016-07-19 15:07:32 +120015279 };
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015280 VkDescriptorSetLayoutCreateInfo dslci = {VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO, nullptr, 0, 2, bindings};
Chris Forbes6a4991a2016-07-19 15:07:32 +120015281 VkDescriptorSetLayout dsl;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015282 VkResult err = vkCreateDescriptorSetLayout(m_device->device(), &dslci, nullptr, &dsl);
Chris Forbes6a4991a2016-07-19 15:07:32 +120015283 ASSERT_VK_SUCCESS(err);
15284
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015285 VkPipelineLayoutCreateInfo plci = {VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dsl, 0, nullptr};
Chris Forbes6a4991a2016-07-19 15:07:32 +120015286 VkPipelineLayout pl;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015287 err = vkCreatePipelineLayout(m_device->device(), &plci, nullptr, &pl);
Chris Forbes6a4991a2016-07-19 15:07:32 +120015288 ASSERT_VK_SUCCESS(err);
15289
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015290 char const *csSource = "#version 450\n"
15291 "\n"
15292 "layout(local_size_x=1) in;\n"
15293 "layout(set=0, binding=0) uniform texture2D t;\n"
15294 "layout(set=0, binding=0) uniform sampler s; // both binding 0!\n"
15295 "layout(set=0, binding=1) buffer block { vec4 x; };\n"
15296 "void main() {\n"
15297 " x = texture(sampler2D(t, s), vec2(0));\n"
15298 "}\n";
Chris Forbes6a4991a2016-07-19 15:07:32 +120015299 VkShaderObj cs(m_device, csSource, VK_SHADER_STAGE_COMPUTE_BIT, this);
15300
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015301 VkComputePipelineCreateInfo cpci = {VK_STRUCTURE_TYPE_COMPUTE_PIPELINE_CREATE_INFO,
15302 nullptr,
15303 0,
15304 {VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO, nullptr, 0,
15305 VK_SHADER_STAGE_COMPUTE_BIT, cs.handle(), "main", nullptr},
15306 pl,
15307 VK_NULL_HANDLE,
15308 -1};
Chris Forbes6a4991a2016-07-19 15:07:32 +120015309
15310 VkPipeline pipe;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015311 err = vkCreateComputePipelines(m_device->device(), VK_NULL_HANDLE, 1, &cpci, nullptr, &pipe);
Chris Forbes6a4991a2016-07-19 15:07:32 +120015312
15313 m_errorMonitor->VerifyNotFound();
15314
15315 if (err == VK_SUCCESS) {
15316 vkDestroyPipeline(m_device->device(), pipe, nullptr);
15317 }
15318
15319 vkDestroyPipelineLayout(m_device->device(), pl, nullptr);
15320 vkDestroyDescriptorSetLayout(m_device->device(), dsl, nullptr);
15321}
15322
Chris Forbes50020592016-07-27 13:52:41 +120015323TEST_F(VkLayerTest, DrawTimeImageViewTypeMismatchWithPipeline) {
15324 TEST_DESCRIPTION("Test that an error is produced when an image view type "
15325 "does not match the dimensionality declared in the shader");
15326
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015327 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 +120015328
15329 ASSERT_NO_FATAL_FAILURE(InitState());
15330 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
15331
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015332 char const *vsSource = "#version 450\n"
15333 "\n"
15334 "out gl_PerVertex { vec4 gl_Position; };\n"
15335 "void main() { gl_Position = vec4(0); }\n";
15336 char const *fsSource = "#version 450\n"
15337 "\n"
15338 "layout(set=0, binding=0) uniform sampler3D s;\n"
15339 "layout(location=0) out vec4 color;\n"
15340 "void main() {\n"
15341 " color = texture(s, vec3(0));\n"
15342 "}\n";
Chris Forbes50020592016-07-27 13:52:41 +120015343 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
15344 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
15345
15346 VkPipelineObj pipe(m_device);
15347 pipe.AddShader(&vs);
15348 pipe.AddShader(&fs);
15349 pipe.AddColorAttachment();
15350
15351 VkTextureObj texture(m_device, nullptr);
15352 VkSamplerObj sampler(m_device);
15353
15354 VkDescriptorSetObj descriptorSet(m_device);
15355 descriptorSet.AppendSamplerTexture(&sampler, &texture);
15356 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
15357
15358 VkResult err = pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
15359 ASSERT_VK_SUCCESS(err);
15360
15361 BeginCommandBuffer();
15362
15363 m_commandBuffer->BindPipeline(pipe);
15364 m_commandBuffer->BindDescriptorSet(descriptorSet);
15365
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015366 VkViewport viewport = {0, 0, 16, 16, 0, 1};
Chris Forbes50020592016-07-27 13:52:41 +120015367 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015368 VkRect2D scissor = {{0, 0}, {16, 16}};
Chris Forbes50020592016-07-27 13:52:41 +120015369 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
15370
15371 // error produced here.
15372 vkCmdDraw(m_commandBuffer->handle(), 3, 1, 0, 0);
15373
15374 m_errorMonitor->VerifyFound();
15375
15376 EndCommandBuffer();
15377}
15378
Chris Forbes5533bfc2016-07-27 14:12:34 +120015379TEST_F(VkLayerTest, DrawTimeImageMultisampleMismatchWithPipeline) {
15380 TEST_DESCRIPTION("Test that an error is produced when a multisampled images "
15381 "are consumed via singlesample images types in the shader, or vice versa.");
15382
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015383 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "requires bound image to have multiple samples");
Chris Forbes5533bfc2016-07-27 14:12:34 +120015384
15385 ASSERT_NO_FATAL_FAILURE(InitState());
15386 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
15387
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015388 char const *vsSource = "#version 450\n"
15389 "\n"
15390 "out gl_PerVertex { vec4 gl_Position; };\n"
15391 "void main() { gl_Position = vec4(0); }\n";
15392 char const *fsSource = "#version 450\n"
15393 "\n"
15394 "layout(set=0, binding=0) uniform sampler2DMS s;\n"
15395 "layout(location=0) out vec4 color;\n"
15396 "void main() {\n"
15397 " color = texelFetch(s, ivec2(0), 0);\n"
15398 "}\n";
Chris Forbes5533bfc2016-07-27 14:12:34 +120015399 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
15400 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
15401
15402 VkPipelineObj pipe(m_device);
15403 pipe.AddShader(&vs);
15404 pipe.AddShader(&fs);
15405 pipe.AddColorAttachment();
15406
15407 VkTextureObj texture(m_device, nullptr);
15408 VkSamplerObj sampler(m_device);
15409
15410 VkDescriptorSetObj descriptorSet(m_device);
15411 descriptorSet.AppendSamplerTexture(&sampler, &texture);
15412 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
15413
15414 VkResult err = pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
15415 ASSERT_VK_SUCCESS(err);
15416
15417 BeginCommandBuffer();
15418
15419 m_commandBuffer->BindPipeline(pipe);
15420 m_commandBuffer->BindDescriptorSet(descriptorSet);
15421
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015422 VkViewport viewport = {0, 0, 16, 16, 0, 1};
Chris Forbes5533bfc2016-07-27 14:12:34 +120015423 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015424 VkRect2D scissor = {{0, 0}, {16, 16}};
Chris Forbes5533bfc2016-07-27 14:12:34 +120015425 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
15426
15427 // error produced here.
15428 vkCmdDraw(m_commandBuffer->handle(), 3, 1, 0, 0);
15429
15430 m_errorMonitor->VerifyFound();
15431
15432 EndCommandBuffer();
15433}
15434
Mark Lobodzinski209b5292015-09-17 09:44:05 -060015435#endif // SHADER_CHECKER_TESTS
15436
15437#if DEVICE_LIMITS_TESTS
Mark Youngc48c4c12016-04-11 14:26:49 -060015438TEST_F(VkLayerTest, CreateImageLimitsViolationMaxWidth) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015439 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "CreateImage extents exceed allowable limits for format");
Mark Lobodzinski6f2274e2015-09-22 09:33:21 -060015440
15441 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinski6f2274e2015-09-22 09:33:21 -060015442
15443 // Create an image
15444 VkImage image;
15445
Karl Schultz6addd812016-02-02 17:17:23 -070015446 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
15447 const int32_t tex_width = 32;
15448 const int32_t tex_height = 32;
Mark Lobodzinski6f2274e2015-09-22 09:33:21 -060015449
15450 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070015451 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
15452 image_create_info.pNext = NULL;
15453 image_create_info.imageType = VK_IMAGE_TYPE_2D;
15454 image_create_info.format = tex_format;
15455 image_create_info.extent.width = tex_width;
Mark Lobodzinski6f2274e2015-09-22 09:33:21 -060015456 image_create_info.extent.height = tex_height;
Karl Schultz6addd812016-02-02 17:17:23 -070015457 image_create_info.extent.depth = 1;
15458 image_create_info.mipLevels = 1;
15459 image_create_info.arrayLayers = 1;
15460 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
15461 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
15462 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
15463 image_create_info.flags = 0;
Mark Lobodzinski6f2274e2015-09-22 09:33:21 -060015464
15465 // Introduce error by sending down a bogus width extent
15466 image_create_info.extent.width = 65536;
Chia-I Wuf7458c52015-10-26 21:10:41 +080015467 vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
Mark Lobodzinski6f2274e2015-09-22 09:33:21 -060015468
Chris Forbes8f36a8a2016-04-07 13:21:07 +120015469 m_errorMonitor->VerifyFound();
Mark Lobodzinski6f2274e2015-09-22 09:33:21 -060015470}
15471
Mark Youngc48c4c12016-04-11 14:26:49 -060015472TEST_F(VkLayerTest, CreateImageLimitsViolationMinWidth) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015473 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
15474 "CreateImage extents is 0 for at least one required dimension");
Mark Youngc48c4c12016-04-11 14:26:49 -060015475
15476 ASSERT_NO_FATAL_FAILURE(InitState());
15477
15478 // Create an image
15479 VkImage image;
15480
15481 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
15482 const int32_t tex_width = 32;
15483 const int32_t tex_height = 32;
15484
15485 VkImageCreateInfo image_create_info = {};
15486 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
15487 image_create_info.pNext = NULL;
15488 image_create_info.imageType = VK_IMAGE_TYPE_2D;
15489 image_create_info.format = tex_format;
15490 image_create_info.extent.width = tex_width;
15491 image_create_info.extent.height = tex_height;
15492 image_create_info.extent.depth = 1;
15493 image_create_info.mipLevels = 1;
15494 image_create_info.arrayLayers = 1;
15495 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
15496 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
15497 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
15498 image_create_info.flags = 0;
15499
15500 // Introduce error by sending down a bogus width extent
15501 image_create_info.extent.width = 0;
15502 vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
15503
15504 m_errorMonitor->VerifyFound();
15505}
Mark Lobodzinski209b5292015-09-17 09:44:05 -060015506#endif // DEVICE_LIMITS_TESTS
Chris Forbesa36d69e2015-05-25 11:13:44 +120015507
Tobin Ehliscde08892015-09-22 10:11:37 -060015508#if IMAGE_TESTS
Mark Lobodzinskidf4c57d2016-08-05 11:47:16 -060015509TEST_F(VkLayerTest, AttachmentDescriptionUndefinedFormat) {
15510 TEST_DESCRIPTION("Create a render pass with an attachment description "
15511 "format set to VK_FORMAT_UNDEFINED");
15512
15513 ASSERT_NO_FATAL_FAILURE(InitState());
15514 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
15515
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015516 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "format is VK_FORMAT_UNDEFINED");
Mark Lobodzinskidf4c57d2016-08-05 11:47:16 -060015517
15518 VkAttachmentReference color_attach = {};
15519 color_attach.layout = VK_IMAGE_LAYOUT_GENERAL;
15520 color_attach.attachment = 0;
15521 VkSubpassDescription subpass = {};
15522 subpass.colorAttachmentCount = 1;
15523 subpass.pColorAttachments = &color_attach;
15524
15525 VkRenderPassCreateInfo rpci = {};
15526 rpci.subpassCount = 1;
15527 rpci.pSubpasses = &subpass;
15528 rpci.attachmentCount = 1;
15529 VkAttachmentDescription attach_desc = {};
15530 attach_desc.format = VK_FORMAT_UNDEFINED;
15531 rpci.pAttachments = &attach_desc;
15532 rpci.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
15533 VkRenderPass rp;
15534 VkResult result = vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
15535
15536 m_errorMonitor->VerifyFound();
15537
15538 if (result == VK_SUCCESS) {
15539 vkDestroyRenderPass(m_device->device(), rp, NULL);
15540 }
15541}
15542
Karl Schultz6addd812016-02-02 17:17:23 -070015543TEST_F(VkLayerTest, InvalidImageView) {
15544 VkResult err;
Tobin Ehliscde08892015-09-22 10:11:37 -060015545
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015546 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "vkCreateImageView called with baseMipLevel 10 ");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060015547
Tobin Ehliscde08892015-09-22 10:11:37 -060015548 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehliscde08892015-09-22 10:11:37 -060015549
Mike Stroyana3082432015-09-25 13:39:21 -060015550 // Create an image and try to create a view with bad baseMipLevel
Karl Schultz6addd812016-02-02 17:17:23 -070015551 VkImage image;
Tobin Ehliscde08892015-09-22 10:11:37 -060015552
Karl Schultz6addd812016-02-02 17:17:23 -070015553 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
15554 const int32_t tex_width = 32;
15555 const int32_t tex_height = 32;
Tobin Ehliscde08892015-09-22 10:11:37 -060015556
15557 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070015558 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
15559 image_create_info.pNext = NULL;
15560 image_create_info.imageType = VK_IMAGE_TYPE_2D;
15561 image_create_info.format = tex_format;
15562 image_create_info.extent.width = tex_width;
15563 image_create_info.extent.height = tex_height;
15564 image_create_info.extent.depth = 1;
15565 image_create_info.mipLevels = 1;
15566 image_create_info.arrayLayers = 1;
15567 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
15568 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
15569 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
15570 image_create_info.flags = 0;
Tobin Ehliscde08892015-09-22 10:11:37 -060015571
Chia-I Wuf7458c52015-10-26 21:10:41 +080015572 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
Tobin Ehliscde08892015-09-22 10:11:37 -060015573 ASSERT_VK_SUCCESS(err);
15574
15575 VkImageViewCreateInfo image_view_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070015576 image_view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
15577 image_view_create_info.image = image;
15578 image_view_create_info.viewType = VK_IMAGE_VIEW_TYPE_2D;
15579 image_view_create_info.format = tex_format;
15580 image_view_create_info.subresourceRange.layerCount = 1;
15581 image_view_create_info.subresourceRange.baseMipLevel = 10; // cause an error
15582 image_view_create_info.subresourceRange.levelCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015583 image_view_create_info.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Tobin Ehliscde08892015-09-22 10:11:37 -060015584
15585 VkImageView view;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015586 err = vkCreateImageView(m_device->device(), &image_view_create_info, NULL, &view);
Tobin Ehliscde08892015-09-22 10:11:37 -060015587
Chris Forbes8f36a8a2016-04-07 13:21:07 +120015588 m_errorMonitor->VerifyFound();
Tony Barbourdf4c0042016-06-01 15:55:43 -060015589 vkDestroyImage(m_device->device(), image, NULL);
Tobin Ehliscde08892015-09-22 10:11:37 -060015590}
Mike Stroyana3082432015-09-25 13:39:21 -060015591
Mark Youngd339ba32016-05-30 13:28:35 -060015592TEST_F(VkLayerTest, CreateImageViewNoMemoryBoundToImage) {
15593 VkResult err;
15594
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015595 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "used without first calling vkBindImageMemory");
Mark Youngd339ba32016-05-30 13:28:35 -060015596
15597 ASSERT_NO_FATAL_FAILURE(InitState());
15598
15599 // Create an image and try to create a view with no memory backing the image
15600 VkImage image;
15601
15602 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
15603 const int32_t tex_width = 32;
15604 const int32_t tex_height = 32;
15605
15606 VkImageCreateInfo image_create_info = {};
15607 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
15608 image_create_info.pNext = NULL;
15609 image_create_info.imageType = VK_IMAGE_TYPE_2D;
15610 image_create_info.format = tex_format;
15611 image_create_info.extent.width = tex_width;
15612 image_create_info.extent.height = tex_height;
15613 image_create_info.extent.depth = 1;
15614 image_create_info.mipLevels = 1;
15615 image_create_info.arrayLayers = 1;
15616 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
15617 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
15618 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
15619 image_create_info.flags = 0;
15620
15621 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
15622 ASSERT_VK_SUCCESS(err);
15623
15624 VkImageViewCreateInfo image_view_create_info = {};
15625 image_view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
15626 image_view_create_info.image = image;
15627 image_view_create_info.viewType = VK_IMAGE_VIEW_TYPE_2D;
15628 image_view_create_info.format = tex_format;
15629 image_view_create_info.subresourceRange.layerCount = 1;
15630 image_view_create_info.subresourceRange.baseMipLevel = 0;
15631 image_view_create_info.subresourceRange.levelCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015632 image_view_create_info.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mark Youngd339ba32016-05-30 13:28:35 -060015633
15634 VkImageView view;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015635 err = vkCreateImageView(m_device->device(), &image_view_create_info, NULL, &view);
Mark Youngd339ba32016-05-30 13:28:35 -060015636
15637 m_errorMonitor->VerifyFound();
15638 vkDestroyImage(m_device->device(), image, NULL);
15639 // If last error is success, it still created the view, so delete it.
15640 if (err == VK_SUCCESS) {
15641 vkDestroyImageView(m_device->device(), view, NULL);
15642 }
Mark Youngd339ba32016-05-30 13:28:35 -060015643}
15644
Karl Schultz6addd812016-02-02 17:17:23 -070015645TEST_F(VkLayerTest, InvalidImageViewAspect) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015646 TEST_DESCRIPTION("Create an image and try to create a view with an invalid aspectMask");
15647 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "vkCreateImageView: Color image "
15648 "formats must have ONLY the "
15649 "VK_IMAGE_ASPECT_COLOR_BIT set");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060015650
Mark Lobodzinskidc86b852015-10-23 14:20:31 -060015651 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinskidc86b852015-10-23 14:20:31 -060015652
Karl Schultz6addd812016-02-02 17:17:23 -070015653 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
Tobin Ehlis1f567a22016-05-25 16:15:18 -060015654 VkImageObj image(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015655 image.init(32, 32, tex_format, VK_IMAGE_USAGE_SAMPLED_BIT, VK_IMAGE_TILING_LINEAR, 0);
Tobin Ehlis1f567a22016-05-25 16:15:18 -060015656 ASSERT_TRUE(image.initialized());
Mark Lobodzinskidc86b852015-10-23 14:20:31 -060015657
15658 VkImageViewCreateInfo image_view_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070015659 image_view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
Tobin Ehlis1f567a22016-05-25 16:15:18 -060015660 image_view_create_info.image = image.handle();
Karl Schultz6addd812016-02-02 17:17:23 -070015661 image_view_create_info.viewType = VK_IMAGE_VIEW_TYPE_2D;
15662 image_view_create_info.format = tex_format;
15663 image_view_create_info.subresourceRange.baseMipLevel = 0;
15664 image_view_create_info.subresourceRange.levelCount = 1;
15665 // Cause an error by setting an invalid image aspect
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015666 image_view_create_info.subresourceRange.aspectMask = VK_IMAGE_ASPECT_METADATA_BIT;
Mark Lobodzinskidc86b852015-10-23 14:20:31 -060015667
15668 VkImageView view;
Tobin Ehlis1f567a22016-05-25 16:15:18 -060015669 vkCreateImageView(m_device->device(), &image_view_create_info, NULL, &view);
Mark Lobodzinskidc86b852015-10-23 14:20:31 -060015670
Chris Forbes8f36a8a2016-04-07 13:21:07 +120015671 m_errorMonitor->VerifyFound();
Mark Lobodzinskidc86b852015-10-23 14:20:31 -060015672}
15673
Mark Lobodzinskidb117632016-03-31 10:45:56 -060015674TEST_F(VkLayerTest, CopyImageLayerCountMismatch) {
Karl Schultz6addd812016-02-02 17:17:23 -070015675 VkResult err;
15676 bool pass;
Mike Stroyana3082432015-09-25 13:39:21 -060015677
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015678 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
15679 "vkCmdCopyImage: number of layers in source and destination subresources for pRegions");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060015680
Mike Stroyana3082432015-09-25 13:39:21 -060015681 ASSERT_NO_FATAL_FAILURE(InitState());
Mike Stroyana3082432015-09-25 13:39:21 -060015682
15683 // Create two images of different types and try to copy between them
Karl Schultz6addd812016-02-02 17:17:23 -070015684 VkImage srcImage;
15685 VkImage dstImage;
15686 VkDeviceMemory srcMem;
15687 VkDeviceMemory destMem;
15688 VkMemoryRequirements memReqs;
Mike Stroyana3082432015-09-25 13:39:21 -060015689
15690 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070015691 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
15692 image_create_info.pNext = NULL;
15693 image_create_info.imageType = VK_IMAGE_TYPE_2D;
15694 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
15695 image_create_info.extent.width = 32;
15696 image_create_info.extent.height = 32;
15697 image_create_info.extent.depth = 1;
15698 image_create_info.mipLevels = 1;
Mark Lobodzinskidb117632016-03-31 10:45:56 -060015699 image_create_info.arrayLayers = 4;
Karl Schultz6addd812016-02-02 17:17:23 -070015700 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
15701 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
15702 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
15703 image_create_info.flags = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060015704
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015705 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
Mike Stroyana3082432015-09-25 13:39:21 -060015706 ASSERT_VK_SUCCESS(err);
15707
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015708 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
Mike Stroyana3082432015-09-25 13:39:21 -060015709 ASSERT_VK_SUCCESS(err);
15710
15711 // Allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015712 VkMemoryAllocateInfo memAlloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -070015713 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
15714 memAlloc.pNext = NULL;
15715 memAlloc.allocationSize = 0;
15716 memAlloc.memoryTypeIndex = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060015717
Courtney Goeltzenleuchter06d89472015-10-20 16:40:38 -060015718 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060015719 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015720 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060015721 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015722 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
Mike Stroyana3082432015-09-25 13:39:21 -060015723 ASSERT_VK_SUCCESS(err);
15724
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015725 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060015726 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015727 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Mike Stroyana3082432015-09-25 13:39:21 -060015728 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015729 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
Mike Stroyana3082432015-09-25 13:39:21 -060015730 ASSERT_VK_SUCCESS(err);
15731
15732 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
15733 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015734 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
Mike Stroyana3082432015-09-25 13:39:21 -060015735 ASSERT_VK_SUCCESS(err);
15736
15737 BeginCommandBuffer();
15738 VkImageCopy copyRegion;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080015739 copyRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060015740 copyRegion.srcSubresource.mipLevel = 0;
Courtney Goeltzenleuchter8367ce02015-10-16 09:46:00 -060015741 copyRegion.srcSubresource.baseArrayLayer = 0;
Mark Lobodzinskidb117632016-03-31 10:45:56 -060015742 copyRegion.srcSubresource.layerCount = 1;
Mike Stroyana3082432015-09-25 13:39:21 -060015743 copyRegion.srcOffset.x = 0;
15744 copyRegion.srcOffset.y = 0;
15745 copyRegion.srcOffset.z = 0;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080015746 copyRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015747 copyRegion.dstSubresource.mipLevel = 0;
15748 copyRegion.dstSubresource.baseArrayLayer = 0;
Mark Lobodzinskidb117632016-03-31 10:45:56 -060015749 // Introduce failure by forcing the dst layerCount to differ from src
15750 copyRegion.dstSubresource.layerCount = 3;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015751 copyRegion.dstOffset.x = 0;
15752 copyRegion.dstOffset.y = 0;
15753 copyRegion.dstOffset.z = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060015754 copyRegion.extent.width = 1;
15755 copyRegion.extent.height = 1;
15756 copyRegion.extent.depth = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015757 m_commandBuffer->CopyImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, VK_IMAGE_LAYOUT_GENERAL, 1, &copyRegion);
Mike Stroyana3082432015-09-25 13:39:21 -060015758 EndCommandBuffer();
15759
Chris Forbes8f36a8a2016-04-07 13:21:07 +120015760 m_errorMonitor->VerifyFound();
Mike Stroyana3082432015-09-25 13:39:21 -060015761
Chia-I Wuf7458c52015-10-26 21:10:41 +080015762 vkDestroyImage(m_device->device(), srcImage, NULL);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015763 vkDestroyImage(m_device->device(), dstImage, NULL);
Chia-I Wuf7458c52015-10-26 21:10:41 +080015764 vkFreeMemory(m_device->device(), srcMem, NULL);
15765 vkFreeMemory(m_device->device(), destMem, NULL);
Mike Stroyana3082432015-09-25 13:39:21 -060015766}
15767
Tony Barbourd6673642016-05-05 14:46:39 -060015768TEST_F(VkLayerTest, ImageLayerUnsupportedFormat) {
15769
15770 TEST_DESCRIPTION("Creating images with unsuported formats ");
15771
15772 ASSERT_NO_FATAL_FAILURE(InitState());
15773 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
15774 VkImageObj image(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015775 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 -060015776 VK_IMAGE_TILING_OPTIMAL, 0);
15777 ASSERT_TRUE(image.initialized());
15778
Mark Lobodzinskiba5c6862016-05-17 08:14:00 -060015779 // Create image with unsupported format - Expect FORMAT_UNSUPPORTED
15780 VkImageCreateInfo image_create_info;
15781 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
15782 image_create_info.pNext = NULL;
15783 image_create_info.imageType = VK_IMAGE_TYPE_2D;
15784 image_create_info.format = VK_FORMAT_UNDEFINED;
15785 image_create_info.extent.width = 32;
15786 image_create_info.extent.height = 32;
15787 image_create_info.extent.depth = 1;
15788 image_create_info.mipLevels = 1;
15789 image_create_info.arrayLayers = 1;
15790 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
15791 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
15792 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
15793 image_create_info.flags = 0;
15794
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015795 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
15796 "vkCreateImage: VkFormat for image must not be VK_FORMAT_UNDEFINED");
Mark Lobodzinskiba5c6862016-05-17 08:14:00 -060015797
15798 VkImage localImage;
15799 vkCreateImage(m_device->handle(), &image_create_info, NULL, &localImage);
15800 m_errorMonitor->VerifyFound();
15801
Tony Barbourd6673642016-05-05 14:46:39 -060015802 VkFormat unsupported = VK_FORMAT_UNDEFINED;
Mark Lobodzinskiba5c6862016-05-17 08:14:00 -060015803 // Look for a format that is COMPLETELY unsupported with this hardware
Tony Barbourd6673642016-05-05 14:46:39 -060015804 for (int f = VK_FORMAT_BEGIN_RANGE; f <= VK_FORMAT_END_RANGE; f++) {
15805 VkFormat format = static_cast<VkFormat>(f);
15806 VkFormatProperties fProps = m_device->format_properties(format);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015807 if (format != VK_FORMAT_UNDEFINED && fProps.linearTilingFeatures == 0 && fProps.optimalTilingFeatures == 0) {
Tony Barbourd6673642016-05-05 14:46:39 -060015808 unsupported = format;
15809 break;
15810 }
15811 }
Mark Lobodzinskiba5c6862016-05-17 08:14:00 -060015812
Tony Barbourd6673642016-05-05 14:46:39 -060015813 if (unsupported != VK_FORMAT_UNDEFINED) {
Tony Barbourd6673642016-05-05 14:46:39 -060015814 image_create_info.format = unsupported;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015815 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "is an unsupported format");
Tony Barbourd6673642016-05-05 14:46:39 -060015816
Mark Lobodzinskiba5c6862016-05-17 08:14:00 -060015817 vkCreateImage(m_device->handle(), &image_create_info, NULL, &localImage);
Tony Barbourd6673642016-05-05 14:46:39 -060015818 m_errorMonitor->VerifyFound();
15819 }
15820}
15821
15822TEST_F(VkLayerTest, ImageLayerViewTests) {
15823 VkResult ret;
15824 TEST_DESCRIPTION("Passing bad parameters to CreateImageView");
15825
15826 ASSERT_NO_FATAL_FAILURE(InitState());
15827
15828 VkImageObj image(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015829 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 -060015830 VK_IMAGE_TILING_OPTIMAL, 0);
15831 ASSERT_TRUE(image.initialized());
15832
15833 VkImageView imgView;
15834 VkImageViewCreateInfo imgViewInfo = {};
15835 imgViewInfo.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
15836 imgViewInfo.image = image.handle();
15837 imgViewInfo.viewType = VK_IMAGE_VIEW_TYPE_2D;
15838 imgViewInfo.format = VK_FORMAT_B8G8R8A8_UNORM;
15839 imgViewInfo.subresourceRange.layerCount = 1;
15840 imgViewInfo.subresourceRange.baseMipLevel = 0;
15841 imgViewInfo.subresourceRange.levelCount = 1;
15842 imgViewInfo.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
15843
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015844 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "vkCreateImageView called with baseMipLevel");
Tony Barbourd6673642016-05-05 14:46:39 -060015845 // View can't have baseMipLevel >= image's mipLevels - Expect
15846 // VIEW_CREATE_ERROR
15847 imgViewInfo.subresourceRange.baseMipLevel = 1;
15848 vkCreateImageView(m_device->handle(), &imgViewInfo, NULL, &imgView);
15849 m_errorMonitor->VerifyFound();
15850 imgViewInfo.subresourceRange.baseMipLevel = 0;
15851
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015852 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "vkCreateImageView called with baseArrayLayer");
Tony Barbourd6673642016-05-05 14:46:39 -060015853 // View can't have baseArrayLayer >= image's arraySize - Expect
15854 // VIEW_CREATE_ERROR
15855 imgViewInfo.subresourceRange.baseArrayLayer = 1;
15856 vkCreateImageView(m_device->handle(), &imgViewInfo, NULL, &imgView);
15857 m_errorMonitor->VerifyFound();
15858 imgViewInfo.subresourceRange.baseArrayLayer = 0;
15859
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015860 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "vkCreateImageView called with 0 in "
15861 "pCreateInfo->subresourceRange."
15862 "levelCount");
Tony Barbourd6673642016-05-05 14:46:39 -060015863 // View's levelCount can't be 0 - Expect VIEW_CREATE_ERROR
15864 imgViewInfo.subresourceRange.levelCount = 0;
15865 vkCreateImageView(m_device->handle(), &imgViewInfo, NULL, &imgView);
15866 m_errorMonitor->VerifyFound();
15867 imgViewInfo.subresourceRange.levelCount = 1;
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 "layerCount");
Tony Barbourd6673642016-05-05 14:46:39 -060015872 // View's layerCount can't be 0 - Expect VIEW_CREATE_ERROR
15873 imgViewInfo.subresourceRange.layerCount = 0;
15874 vkCreateImageView(m_device->handle(), &imgViewInfo, NULL, &imgView);
15875 m_errorMonitor->VerifyFound();
15876 imgViewInfo.subresourceRange.layerCount = 1;
15877
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015878 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "but both must be color formats");
Tony Barbourd6673642016-05-05 14:46:39 -060015879 // Can't use depth format for view into color image - Expect INVALID_FORMAT
15880 imgViewInfo.format = VK_FORMAT_D24_UNORM_S8_UINT;
15881 vkCreateImageView(m_device->handle(), &imgViewInfo, NULL, &imgView);
15882 m_errorMonitor->VerifyFound();
15883 imgViewInfo.format = VK_FORMAT_B8G8R8A8_UNORM;
15884
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015885 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Formats MUST be IDENTICAL unless "
15886 "VK_IMAGE_CREATE_MUTABLE_FORMAT BIT "
15887 "was set on image creation.");
Tony Barbourd6673642016-05-05 14:46:39 -060015888 // Same compatibility class but no MUTABLE_FORMAT bit - Expect
15889 // VIEW_CREATE_ERROR
15890 imgViewInfo.format = VK_FORMAT_B8G8R8A8_UINT;
15891 vkCreateImageView(m_device->handle(), &imgViewInfo, NULL, &imgView);
15892 m_errorMonitor->VerifyFound();
15893 imgViewInfo.format = VK_FORMAT_B8G8R8A8_UNORM;
15894
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015895 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "can support ImageViews with "
15896 "differing formats but they must be "
15897 "in the same compatibility class.");
Tony Barbourd6673642016-05-05 14:46:39 -060015898 // Have MUTABLE_FORMAT bit but not in same compatibility class - Expect
15899 // VIEW_CREATE_ERROR
15900 VkImageCreateInfo mutImgInfo = image.create_info();
15901 VkImage mutImage;
15902 mutImgInfo.format = VK_FORMAT_R8_UINT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015903 assert(m_device->format_properties(VK_FORMAT_R8_UINT).optimalTilingFeatures & VK_FORMAT_FEATURE_COLOR_ATTACHMENT_BIT);
Tony Barbourd6673642016-05-05 14:46:39 -060015904 mutImgInfo.flags = VK_IMAGE_CREATE_MUTABLE_FORMAT_BIT;
15905 mutImgInfo.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
15906 ret = vkCreateImage(m_device->handle(), &mutImgInfo, NULL, &mutImage);
15907 ASSERT_VK_SUCCESS(ret);
15908 imgViewInfo.image = mutImage;
15909 vkCreateImageView(m_device->handle(), &imgViewInfo, NULL, &imgView);
15910 m_errorMonitor->VerifyFound();
15911 imgViewInfo.image = image.handle();
15912 vkDestroyImage(m_device->handle(), mutImage, NULL);
15913}
15914
15915TEST_F(VkLayerTest, MiscImageLayerTests) {
15916
15917 TEST_DESCRIPTION("Image layer tests that don't belong elsewhare");
15918
15919 ASSERT_NO_FATAL_FAILURE(InitState());
15920
15921 VkImageObj image(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015922 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 -060015923 VK_IMAGE_TILING_OPTIMAL, 0);
15924 ASSERT_TRUE(image.initialized());
15925
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015926 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "number of layers in image subresource is zero");
Tony Barbourd6673642016-05-05 14:46:39 -060015927 vk_testing::Buffer buffer;
15928 VkMemoryPropertyFlags reqs = 0;
15929 buffer.init_as_src(*m_device, 128 * 128 * 4, reqs);
15930 VkBufferImageCopy region = {};
15931 region.bufferRowLength = 128;
15932 region.bufferImageHeight = 128;
15933 region.imageSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
15934 // layerCount can't be 0 - Expect MISMATCHED_IMAGE_ASPECT
15935 region.imageSubresource.layerCount = 0;
15936 region.imageExtent.height = 4;
15937 region.imageExtent.width = 4;
15938 region.imageExtent.depth = 1;
15939 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015940 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer.handle(), image.handle(),
15941 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, &region);
Tony Barbourd6673642016-05-05 14:46:39 -060015942 m_errorMonitor->VerifyFound();
15943 region.imageSubresource.layerCount = 1;
15944
Mark Lobodzinski7d8cf142016-08-19 10:53:26 -060015945 // BufferOffset must be a multiple of the calling command's VkImage parameter's texel size
15946 // Introduce failure by setting bufferOffset to 1 and 1/2 texels
15947 region.bufferOffset = 6;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015948 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "must be a multiple of this format's texel size");
15949 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer.handle(), image.handle(),
15950 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, &region);
Mark Lobodzinski7d8cf142016-08-19 10:53:26 -060015951 m_errorMonitor->VerifyFound();
15952
15953 // BufferOffset must be a multiple of 4
15954 // Introduce failure by setting bufferOffset to a value not divisible by 4
15955 region.bufferOffset = 6;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015956 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "must be a multiple of 4");
15957 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer.handle(), image.handle(),
15958 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, &region);
Mark Lobodzinski7d8cf142016-08-19 10:53:26 -060015959 m_errorMonitor->VerifyFound();
15960
15961 // BufferRowLength must be 0, or greater than or equal to the width member of imageExtent
15962 region.bufferOffset = 0;
15963 region.imageExtent.height = 128;
15964 region.imageExtent.width = 128;
15965 // Introduce failure by setting bufferRowLength > 0 but less than width
15966 region.bufferRowLength = 64;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015967 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
15968 "must be zero or greater-than-or-equal-to imageExtent.width");
15969 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer.handle(), image.handle(),
15970 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, &region);
Mark Lobodzinski7d8cf142016-08-19 10:53:26 -060015971 m_errorMonitor->VerifyFound();
15972
15973 // BufferImageHeight must be 0, or greater than or equal to the height member of imageExtent
15974 region.bufferRowLength = 128;
15975 // Introduce failure by setting bufferRowHeight > 0 but less than height
15976 region.bufferImageHeight = 64;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015977 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
15978 "must be zero or greater-than-or-equal-to imageExtent.height");
15979 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer.handle(), image.handle(),
15980 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, &region);
Mark Lobodzinski7d8cf142016-08-19 10:53:26 -060015981 m_errorMonitor->VerifyFound();
15982
15983 region.bufferImageHeight = 128;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015984 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "aspectMasks for each region must "
15985 "specify only COLOR or DEPTH or "
15986 "STENCIL");
Tony Barbourd6673642016-05-05 14:46:39 -060015987 // Expect MISMATCHED_IMAGE_ASPECT
15988 region.imageSubresource.aspectMask = VK_IMAGE_ASPECT_METADATA_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015989 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer.handle(), image.handle(),
15990 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, &region);
Tony Barbourd6673642016-05-05 14:46:39 -060015991 m_errorMonitor->VerifyFound();
15992 region.imageSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
15993
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015994 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
15995 "If the format of srcImage is a depth, stencil, depth stencil or "
15996 "integer-based format then filter must be VK_FILTER_NEAREST");
Tony Barbourd6673642016-05-05 14:46:39 -060015997 // Expect INVALID_FILTER
15998 VkImageObj intImage1(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015999 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 -060016000 VkImageObj intImage2(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016001 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 -060016002 VkImageBlit blitRegion = {};
16003 blitRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
16004 blitRegion.srcSubresource.baseArrayLayer = 0;
16005 blitRegion.srcSubresource.layerCount = 1;
16006 blitRegion.srcSubresource.mipLevel = 0;
16007 blitRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
16008 blitRegion.dstSubresource.baseArrayLayer = 0;
16009 blitRegion.dstSubresource.layerCount = 1;
16010 blitRegion.dstSubresource.mipLevel = 0;
16011
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016012 vkCmdBlitImage(m_commandBuffer->GetBufferHandle(), intImage1.handle(), intImage1.layout(), intImage2.handle(),
16013 intImage2.layout(), 16, &blitRegion, VK_FILTER_LINEAR);
Tony Barbourd6673642016-05-05 14:46:39 -060016014 m_errorMonitor->VerifyFound();
16015
Mark Lobodzinskib02ea642016-08-17 13:03:57 -060016016 // Look for NULL-blit warning
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016017 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT, "Offsets specify a zero-volume area.");
16018 vkCmdBlitImage(m_commandBuffer->GetBufferHandle(), intImage1.handle(), intImage1.layout(), intImage2.handle(),
16019 intImage2.layout(), 1, &blitRegion, VK_FILTER_LINEAR);
Mark Lobodzinskib02ea642016-08-17 13:03:57 -060016020 m_errorMonitor->VerifyFound();
16021
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016022 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "called with 0 in ppMemoryBarriers");
Tony Barbourd6673642016-05-05 14:46:39 -060016023 VkImageMemoryBarrier img_barrier;
16024 img_barrier.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
16025 img_barrier.pNext = NULL;
16026 img_barrier.srcAccessMask = VK_ACCESS_HOST_WRITE_BIT;
16027 img_barrier.dstAccessMask = VK_ACCESS_SHADER_READ_BIT;
16028 img_barrier.oldLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
16029 img_barrier.newLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
16030 img_barrier.image = image.handle();
16031 img_barrier.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
16032 img_barrier.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
16033 img_barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
16034 img_barrier.subresourceRange.baseArrayLayer = 0;
16035 img_barrier.subresourceRange.baseMipLevel = 0;
16036 // layerCount should not be 0 - Expect INVALID_IMAGE_RESOURCE
16037 img_barrier.subresourceRange.layerCount = 0;
16038 img_barrier.subresourceRange.levelCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016039 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
16040 nullptr, 0, nullptr, 1, &img_barrier);
Tony Barbourd6673642016-05-05 14:46:39 -060016041 m_errorMonitor->VerifyFound();
16042 img_barrier.subresourceRange.layerCount = 1;
16043}
16044
16045TEST_F(VkLayerTest, ImageFormatLimits) {
16046
16047 TEST_DESCRIPTION("Exceed the limits of image format ");
16048
Cody Northropc31a84f2016-08-22 10:41:47 -060016049 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016050 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "CreateImage extents exceed allowable limits for format");
Tony Barbourd6673642016-05-05 14:46:39 -060016051 VkImageCreateInfo image_create_info = {};
16052 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
16053 image_create_info.pNext = NULL;
16054 image_create_info.imageType = VK_IMAGE_TYPE_2D;
16055 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
16056 image_create_info.extent.width = 32;
16057 image_create_info.extent.height = 32;
16058 image_create_info.extent.depth = 1;
16059 image_create_info.mipLevels = 1;
16060 image_create_info.arrayLayers = 1;
16061 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
16062 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
16063 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
16064 image_create_info.initialLayout = VK_IMAGE_LAYOUT_UNDEFINED;
16065 image_create_info.flags = 0;
16066
16067 VkImage nullImg;
16068 VkImageFormatProperties imgFmtProps;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016069 vkGetPhysicalDeviceImageFormatProperties(gpu(), image_create_info.format, image_create_info.imageType, image_create_info.tiling,
16070 image_create_info.usage, image_create_info.flags, &imgFmtProps);
Tony Barbourd6673642016-05-05 14:46:39 -060016071 image_create_info.extent.depth = imgFmtProps.maxExtent.depth + 1;
16072 // Expect INVALID_FORMAT_LIMITS_VIOLATION
16073 vkCreateImage(m_device->handle(), &image_create_info, NULL, &nullImg);
16074 m_errorMonitor->VerifyFound();
16075 image_create_info.extent.depth = 1;
16076
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016077 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "exceeds allowable maximum supported by format of");
Tony Barbourd6673642016-05-05 14:46:39 -060016078 image_create_info.mipLevels = imgFmtProps.maxMipLevels + 1;
16079 // Expect INVALID_FORMAT_LIMITS_VIOLATION
16080 vkCreateImage(m_device->handle(), &image_create_info, NULL, &nullImg);
16081 m_errorMonitor->VerifyFound();
16082 image_create_info.mipLevels = 1;
16083
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016084 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "exceeds allowable maximum supported by format of");
Tony Barbourd6673642016-05-05 14:46:39 -060016085 image_create_info.arrayLayers = imgFmtProps.maxArrayLayers + 1;
16086 // Expect INVALID_FORMAT_LIMITS_VIOLATION
16087 vkCreateImage(m_device->handle(), &image_create_info, NULL, &nullImg);
16088 m_errorMonitor->VerifyFound();
16089 image_create_info.arrayLayers = 1;
16090
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016091 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "is not supported by format");
Tony Barbourd6673642016-05-05 14:46:39 -060016092 int samples = imgFmtProps.sampleCounts >> 1;
16093 image_create_info.samples = (VkSampleCountFlagBits)samples;
16094 // Expect INVALID_FORMAT_LIMITS_VIOLATION
16095 vkCreateImage(m_device->handle(), &image_create_info, NULL, &nullImg);
16096 m_errorMonitor->VerifyFound();
16097 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
16098
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016099 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "pCreateInfo->initialLayout, must be "
16100 "VK_IMAGE_LAYOUT_UNDEFINED or "
16101 "VK_IMAGE_LAYOUT_PREINITIALIZED");
Tony Barbourd6673642016-05-05 14:46:39 -060016102 image_create_info.initialLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
16103 // Expect INVALID_LAYOUT
16104 vkCreateImage(m_device->handle(), &image_create_info, NULL, &nullImg);
16105 m_errorMonitor->VerifyFound();
16106 image_create_info.initialLayout = VK_IMAGE_LAYOUT_UNDEFINED;
16107}
16108
Karl Schultz6addd812016-02-02 17:17:23 -070016109TEST_F(VkLayerTest, CopyImageFormatSizeMismatch) {
Karl Schultzbdb75952016-04-19 11:36:49 -060016110 VkResult err;
16111 bool pass;
16112
16113 // Create color images with different format sizes and try to copy between them
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016114 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
16115 "vkCmdCopyImage called with unmatched source and dest image format sizes");
Karl Schultzbdb75952016-04-19 11:36:49 -060016116
16117 ASSERT_NO_FATAL_FAILURE(InitState());
16118
16119 // Create two images of different types and try to copy between them
16120 VkImage srcImage;
16121 VkImage dstImage;
16122 VkDeviceMemory srcMem;
16123 VkDeviceMemory destMem;
16124 VkMemoryRequirements memReqs;
16125
16126 VkImageCreateInfo image_create_info = {};
16127 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
16128 image_create_info.pNext = NULL;
16129 image_create_info.imageType = VK_IMAGE_TYPE_2D;
16130 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
16131 image_create_info.extent.width = 32;
16132 image_create_info.extent.height = 32;
16133 image_create_info.extent.depth = 1;
16134 image_create_info.mipLevels = 1;
16135 image_create_info.arrayLayers = 1;
16136 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
16137 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
16138 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
16139 image_create_info.flags = 0;
16140
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016141 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
Karl Schultzbdb75952016-04-19 11:36:49 -060016142 ASSERT_VK_SUCCESS(err);
16143
16144 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT;
16145 // Introduce failure by creating second image with a different-sized format.
16146 image_create_info.format = VK_FORMAT_R5G5B5A1_UNORM_PACK16;
16147
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016148 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
Karl Schultzbdb75952016-04-19 11:36:49 -060016149 ASSERT_VK_SUCCESS(err);
16150
16151 // Allocate memory
16152 VkMemoryAllocateInfo memAlloc = {};
16153 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
16154 memAlloc.pNext = NULL;
16155 memAlloc.allocationSize = 0;
16156 memAlloc.memoryTypeIndex = 0;
16157
16158 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
16159 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016160 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Karl Schultzbdb75952016-04-19 11:36:49 -060016161 ASSERT_TRUE(pass);
16162 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
16163 ASSERT_VK_SUCCESS(err);
16164
16165 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
16166 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016167 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Karl Schultzbdb75952016-04-19 11:36:49 -060016168 ASSERT_TRUE(pass);
16169 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
16170 ASSERT_VK_SUCCESS(err);
16171
16172 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
16173 ASSERT_VK_SUCCESS(err);
16174 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
16175 ASSERT_VK_SUCCESS(err);
16176
16177 BeginCommandBuffer();
16178 VkImageCopy copyRegion;
16179 copyRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
16180 copyRegion.srcSubresource.mipLevel = 0;
16181 copyRegion.srcSubresource.baseArrayLayer = 0;
16182 copyRegion.srcSubresource.layerCount = 0;
16183 copyRegion.srcOffset.x = 0;
16184 copyRegion.srcOffset.y = 0;
16185 copyRegion.srcOffset.z = 0;
16186 copyRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
16187 copyRegion.dstSubresource.mipLevel = 0;
16188 copyRegion.dstSubresource.baseArrayLayer = 0;
16189 copyRegion.dstSubresource.layerCount = 0;
16190 copyRegion.dstOffset.x = 0;
16191 copyRegion.dstOffset.y = 0;
16192 copyRegion.dstOffset.z = 0;
16193 copyRegion.extent.width = 1;
16194 copyRegion.extent.height = 1;
16195 copyRegion.extent.depth = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016196 m_commandBuffer->CopyImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, VK_IMAGE_LAYOUT_GENERAL, 1, &copyRegion);
Karl Schultzbdb75952016-04-19 11:36:49 -060016197 EndCommandBuffer();
16198
16199 m_errorMonitor->VerifyFound();
16200
16201 vkDestroyImage(m_device->device(), srcImage, NULL);
16202 vkDestroyImage(m_device->device(), dstImage, NULL);
16203 vkFreeMemory(m_device->device(), srcMem, NULL);
16204 vkFreeMemory(m_device->device(), destMem, NULL);
Mike Stroyana3082432015-09-25 13:39:21 -060016205}
16206
Karl Schultz6addd812016-02-02 17:17:23 -070016207TEST_F(VkLayerTest, CopyImageDepthStencilFormatMismatch) {
16208 VkResult err;
16209 bool pass;
Mike Stroyana3082432015-09-25 13:39:21 -060016210
Mark Lobodzinskidb117632016-03-31 10:45:56 -060016211 // Create a color image and a depth/stencil image and try to copy between them
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016212 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
16213 "vkCmdCopyImage called with unmatched source and dest image depth");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060016214
Mike Stroyana3082432015-09-25 13:39:21 -060016215 ASSERT_NO_FATAL_FAILURE(InitState());
Mike Stroyana3082432015-09-25 13:39:21 -060016216
16217 // Create two images of different types and try to copy between them
Karl Schultz6addd812016-02-02 17:17:23 -070016218 VkImage srcImage;
16219 VkImage dstImage;
16220 VkDeviceMemory srcMem;
16221 VkDeviceMemory destMem;
16222 VkMemoryRequirements memReqs;
Mike Stroyana3082432015-09-25 13:39:21 -060016223
16224 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070016225 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
16226 image_create_info.pNext = NULL;
16227 image_create_info.imageType = VK_IMAGE_TYPE_2D;
16228 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
16229 image_create_info.extent.width = 32;
16230 image_create_info.extent.height = 32;
16231 image_create_info.extent.depth = 1;
16232 image_create_info.mipLevels = 1;
16233 image_create_info.arrayLayers = 1;
16234 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
16235 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
16236 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
16237 image_create_info.flags = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060016238
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016239 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
Mike Stroyana3082432015-09-25 13:39:21 -060016240 ASSERT_VK_SUCCESS(err);
16241
Karl Schultzbdb75952016-04-19 11:36:49 -060016242 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT;
16243
Mark Lobodzinskidb117632016-03-31 10:45:56 -060016244 // Introduce failure by creating second image with a depth/stencil format
Karl Schultz6addd812016-02-02 17:17:23 -070016245 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
Mark Lobodzinskidb117632016-03-31 10:45:56 -060016246 image_create_info.format = VK_FORMAT_D24_UNORM_S8_UINT;
16247 image_create_info.usage = VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060016248
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016249 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
Mike Stroyana3082432015-09-25 13:39:21 -060016250 ASSERT_VK_SUCCESS(err);
16251
16252 // Allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016253 VkMemoryAllocateInfo memAlloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -070016254 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
16255 memAlloc.pNext = NULL;
16256 memAlloc.allocationSize = 0;
16257 memAlloc.memoryTypeIndex = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060016258
Courtney Goeltzenleuchter06d89472015-10-20 16:40:38 -060016259 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060016260 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016261 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060016262 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016263 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
Mike Stroyana3082432015-09-25 13:39:21 -060016264 ASSERT_VK_SUCCESS(err);
16265
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016266 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060016267 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016268 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060016269 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016270 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
Mike Stroyana3082432015-09-25 13:39:21 -060016271 ASSERT_VK_SUCCESS(err);
16272
16273 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
16274 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016275 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
Mike Stroyana3082432015-09-25 13:39:21 -060016276 ASSERT_VK_SUCCESS(err);
16277
16278 BeginCommandBuffer();
16279 VkImageCopy copyRegion;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080016280 copyRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060016281 copyRegion.srcSubresource.mipLevel = 0;
Courtney Goeltzenleuchter8367ce02015-10-16 09:46:00 -060016282 copyRegion.srcSubresource.baseArrayLayer = 0;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016283 copyRegion.srcSubresource.layerCount = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060016284 copyRegion.srcOffset.x = 0;
16285 copyRegion.srcOffset.y = 0;
16286 copyRegion.srcOffset.z = 0;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080016287 copyRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016288 copyRegion.dstSubresource.mipLevel = 0;
16289 copyRegion.dstSubresource.baseArrayLayer = 0;
16290 copyRegion.dstSubresource.layerCount = 0;
16291 copyRegion.dstOffset.x = 0;
16292 copyRegion.dstOffset.y = 0;
16293 copyRegion.dstOffset.z = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060016294 copyRegion.extent.width = 1;
16295 copyRegion.extent.height = 1;
16296 copyRegion.extent.depth = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016297 m_commandBuffer->CopyImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, VK_IMAGE_LAYOUT_GENERAL, 1, &copyRegion);
Mike Stroyana3082432015-09-25 13:39:21 -060016298 EndCommandBuffer();
16299
Chris Forbes8f36a8a2016-04-07 13:21:07 +120016300 m_errorMonitor->VerifyFound();
Mike Stroyana3082432015-09-25 13:39:21 -060016301
Chia-I Wuf7458c52015-10-26 21:10:41 +080016302 vkDestroyImage(m_device->device(), srcImage, NULL);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016303 vkDestroyImage(m_device->device(), dstImage, NULL);
Chia-I Wuf7458c52015-10-26 21:10:41 +080016304 vkFreeMemory(m_device->device(), srcMem, NULL);
16305 vkFreeMemory(m_device->device(), destMem, NULL);
Mike Stroyana3082432015-09-25 13:39:21 -060016306}
16307
Karl Schultz6addd812016-02-02 17:17:23 -070016308TEST_F(VkLayerTest, ResolveImageLowSampleCount) {
16309 VkResult err;
16310 bool pass;
Mike Stroyana3082432015-09-25 13:39:21 -060016311
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016312 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
16313 "vkCmdResolveImage called with source sample count less than 2.");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060016314
Mike Stroyana3082432015-09-25 13:39:21 -060016315 ASSERT_NO_FATAL_FAILURE(InitState());
Mike Stroyana3082432015-09-25 13:39:21 -060016316
16317 // Create two images of sample count 1 and try to Resolve between them
Karl Schultz6addd812016-02-02 17:17:23 -070016318 VkImage srcImage;
16319 VkImage dstImage;
16320 VkDeviceMemory srcMem;
16321 VkDeviceMemory destMem;
16322 VkMemoryRequirements memReqs;
Mike Stroyana3082432015-09-25 13:39:21 -060016323
16324 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070016325 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
16326 image_create_info.pNext = NULL;
16327 image_create_info.imageType = VK_IMAGE_TYPE_2D;
16328 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
16329 image_create_info.extent.width = 32;
16330 image_create_info.extent.height = 1;
16331 image_create_info.extent.depth = 1;
16332 image_create_info.mipLevels = 1;
16333 image_create_info.arrayLayers = 1;
16334 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
16335 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
16336 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
16337 image_create_info.flags = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060016338
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016339 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
Mike Stroyana3082432015-09-25 13:39:21 -060016340 ASSERT_VK_SUCCESS(err);
16341
Karl Schultz6addd812016-02-02 17:17:23 -070016342 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060016343
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016344 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
Mike Stroyana3082432015-09-25 13:39:21 -060016345 ASSERT_VK_SUCCESS(err);
16346
16347 // Allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016348 VkMemoryAllocateInfo memAlloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -070016349 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
16350 memAlloc.pNext = NULL;
16351 memAlloc.allocationSize = 0;
16352 memAlloc.memoryTypeIndex = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060016353
Courtney Goeltzenleuchter06d89472015-10-20 16:40:38 -060016354 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060016355 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016356 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060016357 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016358 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
Mike Stroyana3082432015-09-25 13:39:21 -060016359 ASSERT_VK_SUCCESS(err);
16360
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016361 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060016362 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016363 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060016364 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016365 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
Mike Stroyana3082432015-09-25 13:39:21 -060016366 ASSERT_VK_SUCCESS(err);
16367
16368 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
16369 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016370 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
Mike Stroyana3082432015-09-25 13:39:21 -060016371 ASSERT_VK_SUCCESS(err);
16372
16373 BeginCommandBuffer();
16374 // Need memory barrier to VK_IMAGE_LAYOUT_GENERAL for source and dest?
Karl Schultz6addd812016-02-02 17:17:23 -070016375 // VK_IMAGE_LAYOUT_UNDEFINED = 0,
16376 // VK_IMAGE_LAYOUT_GENERAL = 1,
Mike Stroyana3082432015-09-25 13:39:21 -060016377 VkImageResolve resolveRegion;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080016378 resolveRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060016379 resolveRegion.srcSubresource.mipLevel = 0;
Courtney Goeltzenleuchter8367ce02015-10-16 09:46:00 -060016380 resolveRegion.srcSubresource.baseArrayLayer = 0;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016381 resolveRegion.srcSubresource.layerCount = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060016382 resolveRegion.srcOffset.x = 0;
16383 resolveRegion.srcOffset.y = 0;
16384 resolveRegion.srcOffset.z = 0;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080016385 resolveRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016386 resolveRegion.dstSubresource.mipLevel = 0;
16387 resolveRegion.dstSubresource.baseArrayLayer = 0;
16388 resolveRegion.dstSubresource.layerCount = 0;
16389 resolveRegion.dstOffset.x = 0;
16390 resolveRegion.dstOffset.y = 0;
16391 resolveRegion.dstOffset.z = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060016392 resolveRegion.extent.width = 1;
16393 resolveRegion.extent.height = 1;
16394 resolveRegion.extent.depth = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016395 m_commandBuffer->ResolveImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, VK_IMAGE_LAYOUT_GENERAL, 1, &resolveRegion);
Mike Stroyana3082432015-09-25 13:39:21 -060016396 EndCommandBuffer();
16397
Chris Forbes8f36a8a2016-04-07 13:21:07 +120016398 m_errorMonitor->VerifyFound();
Mike Stroyana3082432015-09-25 13:39:21 -060016399
Chia-I Wuf7458c52015-10-26 21:10:41 +080016400 vkDestroyImage(m_device->device(), srcImage, NULL);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016401 vkDestroyImage(m_device->device(), dstImage, NULL);
Chia-I Wuf7458c52015-10-26 21:10:41 +080016402 vkFreeMemory(m_device->device(), srcMem, NULL);
16403 vkFreeMemory(m_device->device(), destMem, NULL);
Mike Stroyana3082432015-09-25 13:39:21 -060016404}
16405
Karl Schultz6addd812016-02-02 17:17:23 -070016406TEST_F(VkLayerTest, ResolveImageHighSampleCount) {
16407 VkResult err;
16408 bool pass;
Mike Stroyana3082432015-09-25 13:39:21 -060016409
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016410 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
16411 "vkCmdResolveImage called with dest sample count greater than 1.");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060016412
Mike Stroyana3082432015-09-25 13:39:21 -060016413 ASSERT_NO_FATAL_FAILURE(InitState());
Mike Stroyana3082432015-09-25 13:39:21 -060016414
Chris Forbesa7530692016-05-08 12:35:39 +120016415 // Create two images of sample count 4 and try to Resolve between them
Karl Schultz6addd812016-02-02 17:17:23 -070016416 VkImage srcImage;
16417 VkImage dstImage;
16418 VkDeviceMemory srcMem;
16419 VkDeviceMemory destMem;
16420 VkMemoryRequirements memReqs;
Mike Stroyana3082432015-09-25 13:39:21 -060016421
16422 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070016423 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
16424 image_create_info.pNext = NULL;
16425 image_create_info.imageType = VK_IMAGE_TYPE_2D;
16426 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
16427 image_create_info.extent.width = 32;
16428 image_create_info.extent.height = 1;
16429 image_create_info.extent.depth = 1;
16430 image_create_info.mipLevels = 1;
16431 image_create_info.arrayLayers = 1;
Chris Forbesa7530692016-05-08 12:35:39 +120016432 image_create_info.samples = VK_SAMPLE_COUNT_4_BIT;
Karl Schultz6addd812016-02-02 17:17:23 -070016433 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
16434 // Note: Some implementations expect color attachment usage for any
16435 // multisample surface
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016436 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
Karl Schultz6addd812016-02-02 17:17:23 -070016437 image_create_info.flags = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060016438
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016439 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
Mike Stroyana3082432015-09-25 13:39:21 -060016440 ASSERT_VK_SUCCESS(err);
16441
Karl Schultz6addd812016-02-02 17:17:23 -070016442 // Note: Some implementations expect color attachment usage for any
16443 // multisample surface
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016444 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060016445
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016446 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
Mike Stroyana3082432015-09-25 13:39:21 -060016447 ASSERT_VK_SUCCESS(err);
16448
16449 // Allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016450 VkMemoryAllocateInfo memAlloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -070016451 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
16452 memAlloc.pNext = NULL;
16453 memAlloc.allocationSize = 0;
16454 memAlloc.memoryTypeIndex = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060016455
Courtney Goeltzenleuchter06d89472015-10-20 16:40:38 -060016456 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060016457 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016458 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060016459 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016460 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
Mike Stroyana3082432015-09-25 13:39:21 -060016461 ASSERT_VK_SUCCESS(err);
16462
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016463 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060016464 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016465 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060016466 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016467 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
Mike Stroyana3082432015-09-25 13:39:21 -060016468 ASSERT_VK_SUCCESS(err);
16469
16470 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
16471 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016472 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
Mike Stroyana3082432015-09-25 13:39:21 -060016473 ASSERT_VK_SUCCESS(err);
16474
16475 BeginCommandBuffer();
16476 // Need memory barrier to VK_IMAGE_LAYOUT_GENERAL for source and dest?
Karl Schultz6addd812016-02-02 17:17:23 -070016477 // VK_IMAGE_LAYOUT_UNDEFINED = 0,
16478 // VK_IMAGE_LAYOUT_GENERAL = 1,
Mike Stroyana3082432015-09-25 13:39:21 -060016479 VkImageResolve resolveRegion;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080016480 resolveRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060016481 resolveRegion.srcSubresource.mipLevel = 0;
Courtney Goeltzenleuchter8367ce02015-10-16 09:46:00 -060016482 resolveRegion.srcSubresource.baseArrayLayer = 0;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016483 resolveRegion.srcSubresource.layerCount = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060016484 resolveRegion.srcOffset.x = 0;
16485 resolveRegion.srcOffset.y = 0;
16486 resolveRegion.srcOffset.z = 0;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080016487 resolveRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016488 resolveRegion.dstSubresource.mipLevel = 0;
16489 resolveRegion.dstSubresource.baseArrayLayer = 0;
16490 resolveRegion.dstSubresource.layerCount = 0;
16491 resolveRegion.dstOffset.x = 0;
16492 resolveRegion.dstOffset.y = 0;
16493 resolveRegion.dstOffset.z = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060016494 resolveRegion.extent.width = 1;
16495 resolveRegion.extent.height = 1;
16496 resolveRegion.extent.depth = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016497 m_commandBuffer->ResolveImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, VK_IMAGE_LAYOUT_GENERAL, 1, &resolveRegion);
Mike Stroyana3082432015-09-25 13:39:21 -060016498 EndCommandBuffer();
16499
Chris Forbes8f36a8a2016-04-07 13:21:07 +120016500 m_errorMonitor->VerifyFound();
Mike Stroyana3082432015-09-25 13:39:21 -060016501
Chia-I Wuf7458c52015-10-26 21:10:41 +080016502 vkDestroyImage(m_device->device(), srcImage, NULL);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016503 vkDestroyImage(m_device->device(), dstImage, NULL);
Chia-I Wuf7458c52015-10-26 21:10:41 +080016504 vkFreeMemory(m_device->device(), srcMem, NULL);
16505 vkFreeMemory(m_device->device(), destMem, NULL);
Mike Stroyana3082432015-09-25 13:39:21 -060016506}
16507
Karl Schultz6addd812016-02-02 17:17:23 -070016508TEST_F(VkLayerTest, ResolveImageFormatMismatch) {
16509 VkResult err;
16510 bool pass;
Mike Stroyana3082432015-09-25 13:39:21 -060016511
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016512 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
16513 "vkCmdResolveImage called with unmatched source and dest formats.");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060016514
Mike Stroyana3082432015-09-25 13:39:21 -060016515 ASSERT_NO_FATAL_FAILURE(InitState());
Mike Stroyana3082432015-09-25 13:39:21 -060016516
16517 // Create two images of different types and try to copy between them
Karl Schultz6addd812016-02-02 17:17:23 -070016518 VkImage srcImage;
16519 VkImage dstImage;
16520 VkDeviceMemory srcMem;
16521 VkDeviceMemory destMem;
16522 VkMemoryRequirements memReqs;
Mike Stroyana3082432015-09-25 13:39:21 -060016523
16524 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070016525 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
16526 image_create_info.pNext = NULL;
16527 image_create_info.imageType = VK_IMAGE_TYPE_2D;
16528 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
16529 image_create_info.extent.width = 32;
16530 image_create_info.extent.height = 1;
16531 image_create_info.extent.depth = 1;
16532 image_create_info.mipLevels = 1;
16533 image_create_info.arrayLayers = 1;
16534 image_create_info.samples = VK_SAMPLE_COUNT_2_BIT;
16535 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
16536 // Note: Some implementations expect color attachment usage for any
16537 // multisample surface
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016538 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
Karl Schultz6addd812016-02-02 17:17:23 -070016539 image_create_info.flags = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060016540
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016541 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
Mike Stroyana3082432015-09-25 13:39:21 -060016542 ASSERT_VK_SUCCESS(err);
16543
Karl Schultz6addd812016-02-02 17:17:23 -070016544 // Set format to something other than source image
16545 image_create_info.format = VK_FORMAT_R32_SFLOAT;
16546 // Note: Some implementations expect color attachment usage for any
16547 // multisample surface
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016548 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
Karl Schultz6addd812016-02-02 17:17:23 -070016549 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060016550
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016551 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
Mike Stroyana3082432015-09-25 13:39:21 -060016552 ASSERT_VK_SUCCESS(err);
16553
16554 // Allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016555 VkMemoryAllocateInfo memAlloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -070016556 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
16557 memAlloc.pNext = NULL;
16558 memAlloc.allocationSize = 0;
16559 memAlloc.memoryTypeIndex = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060016560
Courtney Goeltzenleuchter06d89472015-10-20 16:40:38 -060016561 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060016562 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016563 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060016564 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016565 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
Mike Stroyana3082432015-09-25 13:39:21 -060016566 ASSERT_VK_SUCCESS(err);
16567
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016568 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060016569 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016570 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060016571 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016572 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
Mike Stroyana3082432015-09-25 13:39:21 -060016573 ASSERT_VK_SUCCESS(err);
16574
16575 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
16576 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016577 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
Mike Stroyana3082432015-09-25 13:39:21 -060016578 ASSERT_VK_SUCCESS(err);
16579
16580 BeginCommandBuffer();
16581 // Need memory barrier to VK_IMAGE_LAYOUT_GENERAL for source and dest?
Karl Schultz6addd812016-02-02 17:17:23 -070016582 // VK_IMAGE_LAYOUT_UNDEFINED = 0,
16583 // VK_IMAGE_LAYOUT_GENERAL = 1,
Mike Stroyana3082432015-09-25 13:39:21 -060016584 VkImageResolve resolveRegion;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080016585 resolveRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060016586 resolveRegion.srcSubresource.mipLevel = 0;
Courtney Goeltzenleuchter8367ce02015-10-16 09:46:00 -060016587 resolveRegion.srcSubresource.baseArrayLayer = 0;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016588 resolveRegion.srcSubresource.layerCount = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060016589 resolveRegion.srcOffset.x = 0;
16590 resolveRegion.srcOffset.y = 0;
16591 resolveRegion.srcOffset.z = 0;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080016592 resolveRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016593 resolveRegion.dstSubresource.mipLevel = 0;
16594 resolveRegion.dstSubresource.baseArrayLayer = 0;
16595 resolveRegion.dstSubresource.layerCount = 0;
16596 resolveRegion.dstOffset.x = 0;
16597 resolveRegion.dstOffset.y = 0;
16598 resolveRegion.dstOffset.z = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060016599 resolveRegion.extent.width = 1;
16600 resolveRegion.extent.height = 1;
16601 resolveRegion.extent.depth = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016602 m_commandBuffer->ResolveImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, VK_IMAGE_LAYOUT_GENERAL, 1, &resolveRegion);
Mike Stroyana3082432015-09-25 13:39:21 -060016603 EndCommandBuffer();
16604
Chris Forbes8f36a8a2016-04-07 13:21:07 +120016605 m_errorMonitor->VerifyFound();
Mike Stroyana3082432015-09-25 13:39:21 -060016606
Chia-I Wuf7458c52015-10-26 21:10:41 +080016607 vkDestroyImage(m_device->device(), srcImage, NULL);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016608 vkDestroyImage(m_device->device(), dstImage, NULL);
Chia-I Wuf7458c52015-10-26 21:10:41 +080016609 vkFreeMemory(m_device->device(), srcMem, NULL);
16610 vkFreeMemory(m_device->device(), destMem, NULL);
Mike Stroyana3082432015-09-25 13:39:21 -060016611}
16612
Karl Schultz6addd812016-02-02 17:17:23 -070016613TEST_F(VkLayerTest, ResolveImageTypeMismatch) {
16614 VkResult err;
16615 bool pass;
Mike Stroyana3082432015-09-25 13:39:21 -060016616
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016617 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
16618 "vkCmdResolveImage called with unmatched source and dest image types.");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060016619
Mike Stroyana3082432015-09-25 13:39:21 -060016620 ASSERT_NO_FATAL_FAILURE(InitState());
Mike Stroyana3082432015-09-25 13:39:21 -060016621
16622 // Create two images of different types and try to copy between them
Karl Schultz6addd812016-02-02 17:17:23 -070016623 VkImage srcImage;
16624 VkImage dstImage;
16625 VkDeviceMemory srcMem;
16626 VkDeviceMemory destMem;
16627 VkMemoryRequirements memReqs;
Mike Stroyana3082432015-09-25 13:39:21 -060016628
16629 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070016630 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
16631 image_create_info.pNext = NULL;
16632 image_create_info.imageType = VK_IMAGE_TYPE_2D;
16633 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
16634 image_create_info.extent.width = 32;
16635 image_create_info.extent.height = 1;
16636 image_create_info.extent.depth = 1;
16637 image_create_info.mipLevels = 1;
16638 image_create_info.arrayLayers = 1;
16639 image_create_info.samples = VK_SAMPLE_COUNT_2_BIT;
16640 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
16641 // Note: Some implementations expect color attachment usage for any
16642 // multisample surface
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016643 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
Karl Schultz6addd812016-02-02 17:17:23 -070016644 image_create_info.flags = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060016645
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016646 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
Mike Stroyana3082432015-09-25 13:39:21 -060016647 ASSERT_VK_SUCCESS(err);
16648
Karl Schultz6addd812016-02-02 17:17:23 -070016649 image_create_info.imageType = VK_IMAGE_TYPE_1D;
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_DST_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
Karl Schultz6addd812016-02-02 17:17:23 -070016653 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
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, &dstImage);
Mike Stroyana3082432015-09-25 13:39:21 -060016656 ASSERT_VK_SUCCESS(err);
16657
16658 // Allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016659 VkMemoryAllocateInfo memAlloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -070016660 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
16661 memAlloc.pNext = NULL;
16662 memAlloc.allocationSize = 0;
16663 memAlloc.memoryTypeIndex = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060016664
Courtney Goeltzenleuchter06d89472015-10-20 16:40:38 -060016665 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060016666 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016667 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060016668 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016669 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
Mike Stroyana3082432015-09-25 13:39:21 -060016670 ASSERT_VK_SUCCESS(err);
16671
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016672 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060016673 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016674 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060016675 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016676 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
Mike Stroyana3082432015-09-25 13:39:21 -060016677 ASSERT_VK_SUCCESS(err);
16678
16679 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
16680 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016681 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
Mike Stroyana3082432015-09-25 13:39:21 -060016682 ASSERT_VK_SUCCESS(err);
16683
16684 BeginCommandBuffer();
16685 // Need memory barrier to VK_IMAGE_LAYOUT_GENERAL for source and dest?
Karl Schultz6addd812016-02-02 17:17:23 -070016686 // VK_IMAGE_LAYOUT_UNDEFINED = 0,
16687 // VK_IMAGE_LAYOUT_GENERAL = 1,
Mike Stroyana3082432015-09-25 13:39:21 -060016688 VkImageResolve resolveRegion;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080016689 resolveRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060016690 resolveRegion.srcSubresource.mipLevel = 0;
Courtney Goeltzenleuchter8367ce02015-10-16 09:46:00 -060016691 resolveRegion.srcSubresource.baseArrayLayer = 0;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016692 resolveRegion.srcSubresource.layerCount = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060016693 resolveRegion.srcOffset.x = 0;
16694 resolveRegion.srcOffset.y = 0;
16695 resolveRegion.srcOffset.z = 0;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080016696 resolveRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016697 resolveRegion.dstSubresource.mipLevel = 0;
16698 resolveRegion.dstSubresource.baseArrayLayer = 0;
16699 resolveRegion.dstSubresource.layerCount = 0;
16700 resolveRegion.dstOffset.x = 0;
16701 resolveRegion.dstOffset.y = 0;
16702 resolveRegion.dstOffset.z = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060016703 resolveRegion.extent.width = 1;
16704 resolveRegion.extent.height = 1;
16705 resolveRegion.extent.depth = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016706 m_commandBuffer->ResolveImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, VK_IMAGE_LAYOUT_GENERAL, 1, &resolveRegion);
Mike Stroyana3082432015-09-25 13:39:21 -060016707 EndCommandBuffer();
16708
Chris Forbes8f36a8a2016-04-07 13:21:07 +120016709 m_errorMonitor->VerifyFound();
Mike Stroyana3082432015-09-25 13:39:21 -060016710
Chia-I Wuf7458c52015-10-26 21:10:41 +080016711 vkDestroyImage(m_device->device(), srcImage, NULL);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016712 vkDestroyImage(m_device->device(), dstImage, NULL);
Chia-I Wuf7458c52015-10-26 21:10:41 +080016713 vkFreeMemory(m_device->device(), srcMem, NULL);
16714 vkFreeMemory(m_device->device(), destMem, NULL);
Mike Stroyana3082432015-09-25 13:39:21 -060016715}
Tobin Ehlisa1c28562015-10-23 16:00:08 -060016716
Karl Schultz6addd812016-02-02 17:17:23 -070016717TEST_F(VkLayerTest, DepthStencilImageViewWithColorAspectBitError) {
Tobin Ehlisa1c28562015-10-23 16:00:08 -060016718 // Create a single Image descriptor and cause it to first hit an error due
Karl Schultz6addd812016-02-02 17:17:23 -070016719 // to using a DS format, then cause it to hit error due to COLOR_BIT not
16720 // set in aspect
Tobin Ehlisa1c28562015-10-23 16:00:08 -060016721 // The image format check comes 2nd in validation so we trigger it first,
16722 // then when we cause aspect fail next, bad format check will be preempted
Karl Schultz6addd812016-02-02 17:17:23 -070016723 VkResult err;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060016724
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016725 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
16726 "Combination depth/stencil image formats can have only the ");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060016727
Tobin Ehlisa1c28562015-10-23 16:00:08 -060016728 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060016729
Chia-I Wu1b99bb22015-10-27 19:25:11 +080016730 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -070016731 ds_type_count.type = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE;
16732 ds_type_count.descriptorCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060016733
16734 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070016735 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
16736 ds_pool_ci.pNext = NULL;
16737 ds_pool_ci.maxSets = 1;
16738 ds_pool_ci.poolSizeCount = 1;
16739 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060016740
16741 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016742 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060016743 ASSERT_VK_SUCCESS(err);
16744
16745 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -070016746 dsl_binding.binding = 0;
16747 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE;
16748 dsl_binding.descriptorCount = 1;
16749 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
16750 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060016751
16752 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070016753 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
16754 ds_layout_ci.pNext = NULL;
16755 ds_layout_ci.bindingCount = 1;
16756 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060016757 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016758 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060016759 ASSERT_VK_SUCCESS(err);
16760
16761 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016762 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +080016763 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -070016764 alloc_info.descriptorSetCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060016765 alloc_info.descriptorPool = ds_pool;
16766 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016767 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060016768 ASSERT_VK_SUCCESS(err);
16769
Karl Schultz6addd812016-02-02 17:17:23 -070016770 VkImage image_bad;
16771 VkImage image_good;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060016772 // One bad format and one good format for Color attachment
Tobin Ehlis269f0322016-05-25 16:24:21 -060016773 const VkFormat tex_format_bad = VK_FORMAT_D24_UNORM_S8_UINT;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060016774 const VkFormat tex_format_good = VK_FORMAT_B8G8R8A8_UNORM;
Karl Schultz6addd812016-02-02 17:17:23 -070016775 const int32_t tex_width = 32;
16776 const int32_t tex_height = 32;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060016777
16778 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070016779 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
16780 image_create_info.pNext = NULL;
16781 image_create_info.imageType = VK_IMAGE_TYPE_2D;
16782 image_create_info.format = tex_format_bad;
16783 image_create_info.extent.width = tex_width;
16784 image_create_info.extent.height = tex_height;
16785 image_create_info.extent.depth = 1;
16786 image_create_info.mipLevels = 1;
16787 image_create_info.arrayLayers = 1;
16788 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
16789 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016790 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT | VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT;
Karl Schultz6addd812016-02-02 17:17:23 -070016791 image_create_info.flags = 0;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060016792
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016793 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image_bad);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060016794 ASSERT_VK_SUCCESS(err);
16795 image_create_info.format = tex_format_good;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016796 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
16797 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image_good);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060016798 ASSERT_VK_SUCCESS(err);
16799
16800 VkImageViewCreateInfo image_view_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070016801 image_view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
16802 image_view_create_info.image = image_bad;
16803 image_view_create_info.viewType = VK_IMAGE_VIEW_TYPE_2D;
16804 image_view_create_info.format = tex_format_bad;
16805 image_view_create_info.subresourceRange.baseArrayLayer = 0;
16806 image_view_create_info.subresourceRange.baseMipLevel = 0;
16807 image_view_create_info.subresourceRange.layerCount = 1;
16808 image_view_create_info.subresourceRange.levelCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016809 image_view_create_info.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060016810
16811 VkImageView view;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016812 err = vkCreateImageView(m_device->device(), &image_view_create_info, NULL, &view);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060016813
Chris Forbes8f36a8a2016-04-07 13:21:07 +120016814 m_errorMonitor->VerifyFound();
Tobin Ehlisa1c28562015-10-23 16:00:08 -060016815
Chia-I Wuf7458c52015-10-26 21:10:41 +080016816 vkDestroyImage(m_device->device(), image_bad, NULL);
16817 vkDestroyImage(m_device->device(), image_good, NULL);
Chia-I Wuf7458c52015-10-26 21:10:41 +080016818 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
16819 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060016820}
Tobin Ehlis6e23d772016-05-19 11:08:34 -060016821
16822TEST_F(VkLayerTest, ClearImageErrors) {
16823 TEST_DESCRIPTION("Call ClearColorImage w/ a depth|stencil image and "
16824 "ClearDepthStencilImage with a color image.");
16825
16826 ASSERT_NO_FATAL_FAILURE(InitState());
16827 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
16828
16829 // Renderpass is started here so end it as Clear cmds can't be in renderpass
16830 BeginCommandBuffer();
16831 m_commandBuffer->EndRenderPass();
16832
16833 // Color image
16834 VkClearColorValue clear_color;
16835 memset(clear_color.uint32, 0, sizeof(uint32_t) * 4);
16836 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
16837 const VkFormat color_format = VK_FORMAT_B8G8R8A8_UNORM;
16838 const int32_t img_width = 32;
16839 const int32_t img_height = 32;
16840 VkImageCreateInfo image_create_info = {};
16841 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
16842 image_create_info.pNext = NULL;
16843 image_create_info.imageType = VK_IMAGE_TYPE_2D;
16844 image_create_info.format = color_format;
16845 image_create_info.extent.width = img_width;
16846 image_create_info.extent.height = img_height;
16847 image_create_info.extent.depth = 1;
16848 image_create_info.mipLevels = 1;
16849 image_create_info.arrayLayers = 1;
16850 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
16851 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
16852 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
16853
16854 vk_testing::Image color_image;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016855 color_image.init(*m_device, (const VkImageCreateInfo &)image_create_info, reqs);
Tobin Ehlis6e23d772016-05-19 11:08:34 -060016856
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016857 const VkImageSubresourceRange color_range = vk_testing::Image::subresource_range(image_create_info, VK_IMAGE_ASPECT_COLOR_BIT);
Tobin Ehlis6e23d772016-05-19 11:08:34 -060016858
16859 // Depth/Stencil image
16860 VkClearDepthStencilValue clear_value = {0};
16861 reqs = 0; // don't need HOST_VISIBLE DS image
16862 VkImageCreateInfo ds_image_create_info = vk_testing::Image::create_info();
16863 ds_image_create_info.imageType = VK_IMAGE_TYPE_2D;
16864 ds_image_create_info.format = VK_FORMAT_D24_UNORM_S8_UINT;
16865 ds_image_create_info.extent.width = 64;
16866 ds_image_create_info.extent.height = 64;
16867 ds_image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
16868 ds_image_create_info.usage = VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT;
16869
16870 vk_testing::Image ds_image;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016871 ds_image.init(*m_device, (const VkImageCreateInfo &)ds_image_create_info, reqs);
Tobin Ehlis6e23d772016-05-19 11:08:34 -060016872
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016873 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 -060016874
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016875 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "vkCmdClearColorImage called with depth/stencil image.");
Tobin Ehlis6e23d772016-05-19 11:08:34 -060016876
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016877 vkCmdClearColorImage(m_commandBuffer->GetBufferHandle(), ds_image.handle(), VK_IMAGE_LAYOUT_GENERAL, &clear_color, 1,
Tobin Ehlis6e23d772016-05-19 11:08:34 -060016878 &color_range);
16879
16880 m_errorMonitor->VerifyFound();
16881
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016882 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "vkCmdClearColorImage called with "
16883 "image created without "
16884 "VK_IMAGE_USAGE_TRANSFER_DST_BIT");
Tony Barbour26434b92016-06-02 09:43:50 -060016885
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016886 vkCmdClearColorImage(m_commandBuffer->GetBufferHandle(), ds_image.handle(), VK_IMAGE_LAYOUT_GENERAL, &clear_color, 1,
Tony Barbour26434b92016-06-02 09:43:50 -060016887 &color_range);
16888
16889 m_errorMonitor->VerifyFound();
16890
Tobin Ehlis6e23d772016-05-19 11:08:34 -060016891 // Call CmdClearDepthStencilImage with color image
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016892 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
16893 "vkCmdClearDepthStencilImage called without a depth/stencil image.");
Tobin Ehlis6e23d772016-05-19 11:08:34 -060016894
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016895 vkCmdClearDepthStencilImage(m_commandBuffer->GetBufferHandle(), color_image.handle(),
16896 VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL, &clear_value, 1, &ds_range);
Tobin Ehlis6e23d772016-05-19 11:08:34 -060016897
16898 m_errorMonitor->VerifyFound();
16899}
Tobin Ehliscde08892015-09-22 10:11:37 -060016900#endif // IMAGE_TESTS
16901
Cody Northrop1242dfd2016-07-13 17:24:59 -060016902#if defined(ANDROID) && defined(VALIDATION_APK)
16903static bool initialized = false;
16904static bool active = false;
16905
16906// Convert Intents to argv
16907// Ported from Hologram sample, only difference is flexible key
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016908std::vector<std::string> get_args(android_app &app, const char *intent_extra_data_key) {
Cody Northrop1242dfd2016-07-13 17:24:59 -060016909 std::vector<std::string> args;
16910 JavaVM &vm = *app.activity->vm;
16911 JNIEnv *p_env;
16912 if (vm.AttachCurrentThread(&p_env, nullptr) != JNI_OK)
16913 return args;
16914
16915 JNIEnv &env = *p_env;
16916 jobject activity = app.activity->clazz;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016917 jmethodID get_intent_method = env.GetMethodID(env.GetObjectClass(activity), "getIntent", "()Landroid/content/Intent;");
Cody Northrop1242dfd2016-07-13 17:24:59 -060016918 jobject intent = env.CallObjectMethod(activity, get_intent_method);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016919 jmethodID get_string_extra_method =
16920 env.GetMethodID(env.GetObjectClass(intent), "getStringExtra", "(Ljava/lang/String;)Ljava/lang/String;");
Cody Northrop1242dfd2016-07-13 17:24:59 -060016921 jvalue get_string_extra_args;
16922 get_string_extra_args.l = env.NewStringUTF(intent_extra_data_key);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016923 jstring extra_str = static_cast<jstring>(env.CallObjectMethodA(intent, get_string_extra_method, &get_string_extra_args));
Cody Northrop1242dfd2016-07-13 17:24:59 -060016924
16925 std::string args_str;
16926 if (extra_str) {
16927 const char *extra_utf = env.GetStringUTFChars(extra_str, nullptr);
16928 args_str = extra_utf;
16929 env.ReleaseStringUTFChars(extra_str, extra_utf);
16930 env.DeleteLocalRef(extra_str);
16931 }
16932
16933 env.DeleteLocalRef(get_string_extra_args.l);
16934 env.DeleteLocalRef(intent);
16935 vm.DetachCurrentThread();
16936
16937 // split args_str
16938 std::stringstream ss(args_str);
16939 std::string arg;
16940 while (std::getline(ss, arg, ' ')) {
16941 if (!arg.empty())
16942 args.push_back(arg);
16943 }
16944
16945 return args;
16946}
16947
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016948static int32_t processInput(struct android_app *app, AInputEvent *event) { return 0; }
Cody Northrop1242dfd2016-07-13 17:24:59 -060016949
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016950static void processCommand(struct android_app *app, int32_t cmd) {
16951 switch (cmd) {
16952 case APP_CMD_INIT_WINDOW: {
16953 if (app->window) {
16954 initialized = true;
Cody Northrop1242dfd2016-07-13 17:24:59 -060016955 }
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016956 break;
16957 }
16958 case APP_CMD_GAINED_FOCUS: {
16959 active = true;
16960 break;
16961 }
16962 case APP_CMD_LOST_FOCUS: {
16963 active = false;
16964 break;
16965 }
Cody Northrop1242dfd2016-07-13 17:24:59 -060016966 }
16967}
16968
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016969void android_main(struct android_app *app) {
Cody Northrop1242dfd2016-07-13 17:24:59 -060016970 app_dummy();
16971
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016972 const char *appTag = "VulkanLayerValidationTests";
Cody Northrop1242dfd2016-07-13 17:24:59 -060016973
16974 int vulkanSupport = InitVulkan();
16975 if (vulkanSupport == 0) {
16976 __android_log_print(ANDROID_LOG_INFO, appTag, "==== FAILED ==== No Vulkan support found");
16977 return;
16978 }
16979
16980 app->onAppCmd = processCommand;
16981 app->onInputEvent = processInput;
16982
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016983 while (1) {
Cody Northrop1242dfd2016-07-13 17:24:59 -060016984 int events;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016985 struct android_poll_source *source;
16986 while (ALooper_pollAll(active ? 0 : -1, NULL, &events, (void **)&source) >= 0) {
Cody Northrop1242dfd2016-07-13 17:24:59 -060016987 if (source) {
16988 source->process(app, source);
16989 }
16990
16991 if (app->destroyRequested != 0) {
16992 VkTestFramework::Finish();
16993 return;
16994 }
16995 }
16996
16997 if (initialized && active) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016998 // Use the following key to send arguments to gtest, i.e.
16999 // --es args "--gtest_filter=-VkLayerTest.foo"
17000 const char key[] = "args";
17001 std::vector<std::string> args = get_args(*app, key);
Cody Northrop1242dfd2016-07-13 17:24:59 -060017002
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017003 std::string filter = "";
17004 if (args.size() > 0) {
17005 __android_log_print(ANDROID_LOG_INFO, appTag, "Intent args = %s", args[0].c_str());
17006 filter += args[0];
17007 } else {
17008 __android_log_print(ANDROID_LOG_INFO, appTag, "No Intent args detected");
17009 }
Cody Northrop1242dfd2016-07-13 17:24:59 -060017010
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017011 int argc = 2;
17012 char *argv[] = {(char *)"foo", (char *)filter.c_str()};
17013 __android_log_print(ANDROID_LOG_DEBUG, appTag, "filter = %s", argv[1]);
Cody Northrop1242dfd2016-07-13 17:24:59 -060017014
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017015 // Route output to files until we can override the gtest output
17016 freopen("/sdcard/Android/data/com.example.VulkanLayerValidationTests/files/out.txt", "w", stdout);
17017 freopen("/sdcard/Android/data/com.example.VulkanLayerValidationTests/files/err.txt", "w", stderr);
Cody Northrop1242dfd2016-07-13 17:24:59 -060017018
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017019 ::testing::InitGoogleTest(&argc, argv);
17020 VkTestFramework::InitArgs(&argc, argv);
17021 ::testing::AddGlobalTestEnvironment(new TestEnvironment);
Cody Northrop1242dfd2016-07-13 17:24:59 -060017022
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017023 int result = RUN_ALL_TESTS();
Cody Northrop1242dfd2016-07-13 17:24:59 -060017024
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017025 if (result != 0) {
17026 __android_log_print(ANDROID_LOG_INFO, appTag, "==== Tests FAILED ====");
17027 } else {
17028 __android_log_print(ANDROID_LOG_INFO, appTag, "==== Tests PASSED ====");
17029 }
Cody Northrop1242dfd2016-07-13 17:24:59 -060017030
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017031 VkTestFramework::Finish();
Cody Northrop1242dfd2016-07-13 17:24:59 -060017032
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017033 fclose(stdout);
17034 fclose(stderr);
Cody Northrop1242dfd2016-07-13 17:24:59 -060017035
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017036 ANativeActivity_finish(app->activity);
Cody Northrop1242dfd2016-07-13 17:24:59 -060017037
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017038 return;
Cody Northrop1242dfd2016-07-13 17:24:59 -060017039 }
17040 }
17041}
17042#endif
17043
Tony Barbour300a6082015-04-07 13:44:53 -060017044int main(int argc, char **argv) {
17045 int result;
17046
Cody Northrop8e54a402016-03-08 22:25:52 -070017047#ifdef ANDROID
17048 int vulkanSupport = InitVulkan();
17049 if (vulkanSupport == 0)
17050 return 1;
17051#endif
17052
Tony Barbour300a6082015-04-07 13:44:53 -060017053 ::testing::InitGoogleTest(&argc, argv);
Tony Barbour6918cd52015-04-09 12:58:51 -060017054 VkTestFramework::InitArgs(&argc, argv);
Tony Barbour300a6082015-04-07 13:44:53 -060017055
17056 ::testing::AddGlobalTestEnvironment(new TestEnvironment);
17057
17058 result = RUN_ALL_TESTS();
17059
Tony Barbour6918cd52015-04-09 12:58:51 -060017060 VkTestFramework::Finish();
Tony Barbour300a6082015-04-07 13:44:53 -060017061 return result;
17062}